WordPress hiding categories view from edit posts - wordpress

I have created a edit link on my wordpress where subscribers can edit their posts. When they click this it takes them back to the admin portal to edit post. I want to make sure they can't see the categories widget on the right side how do I remove that from a user seeing this?
<?php edit_post_link(__("Edit Post"), ''); ?>
I ahve this un the function.php file but need to know how to make it just for subscribers.
function wpse60590_remove_metaboxes() { if() remove_meta_box( 'categorydiv' , 'post' , 'normal' ); remove_meta_box( 'tagsdiv-post_tag' , 'post' , 'normal' ); } add_action( 'admin_menu' , 'wpse60590_remove_metaboxes' );

You need to modify the capabilities of these users' role to prevent them from working with categories. The capability you need to disable for their role should be "manage_categories".
Just make sure all of the users you wish to limit are in the same role (e.g. "Contributor" or something).
In my experience the easiest way to manage capabilities for roles is the Members Plugin.
Once installed, go to Users -> Roles -> Select the role you wish to change. Find "manage_categories", uncheck it, and save.
If you are using a custom post type, we may have to add some settings where you register the taxonomy to specify the ability to assign a category to a post.

Related

Wordpress Client Dashboard Menu Page

I want to add a menu page on Admin as well as User Dashboard, I have developed a plugin and it is working fine on admin dashboard but it is not showing on Client/User Dashboard. May be it is due to "role" property. But I want this on client side also. Can anyone help me please,thanks in advance!
Basic purpose is that the client have to offer some products to share or download on the website form his client/user dashboard. so I need to add this functionality using a plugin and this needs to add on client dashboard to work.
function wpdocs_register_my_custom_menu_page() {
add_menu_page(
__( 'Custom Menu Title', 'oceanwp' ), 'Offers','manage_options','ump-date-updater/ump-date-updater.php', '', 'dashicons-tickets',6);
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page');
According to WP Codex the $capability parameter determines whether the menu item is shown to a user. See here for more info on roles and capabilities, and how to create custom capabilities.
// run this function on your plugin activation code
function setup_capabilities()
{
$role = get_role( 'author' ); // set this to the actual role of "User"
$role->add_cap('see_my_custom_menu_item');
}
and replace manage_options in your code with see_my_custom_menu_item

Hide or disable contact form 7 for specific role in wordpress

I have created a custom user role "faquser" in my wp site. Now I want to hide contact form 7 menu ( or disable) only for this role. How can I do that? I saw this:
http://contactform7.com/restricting-access-to-the-administration-panel/
But if I do this, then contact form only works for administrator and not for any others. I have also tried to do something like this:
remove_menu_page('admin.php?page=wpcf7');
This did not remove the menu item either.
I found the solution:
remove_menu_page('wpcf7');
In order to do this properly you need to write a function that determines which roles you need to remove the menu item for.
remove_menu_page('wpcf7'); // This is the snippet that will remove the contact form 7 menu specifically.
This is an example of a function that does the complete task.
function remove_menu_pages() {
global $user_ID;
if ( !current_user_can( 'publish_posts' ) ) {
remove_menu_page('edit-comments.php'); // Comments
remove_menu_page('edit.php?post_type=page'); // Pages
remove_menu_page('wpcf7'); // Contact Form 7 Menu
}
}
add_action( 'admin_init', 'remove_menu_pages' );
You can get a full list of capabilities of the different roles in WordPress here: https://wordpress.org/support/article/roles-and-capabilities/
I chose "publish_posts" so that all user types below author and who do not have the capability "publish_posts" will not see the contact form 7 menu, or the comments or pages menu items.
Depending on the capabilities you gave your user role "faquser" will determine which capabilities you need to call the function for.

Manipulate woocommerce product edit page

I am new to wordpress and woocommerce development and I am just wondering, how to manipulate an admin-screen in a clean, updateable way.
For example, I want to add a custom field to a product edit page (see screen):
I know, that I have to write a custom extension, but is it possible, to manipulate admin-screens of other extensions? I couldn't find any suitable tutorial? Maybe someone has a hint, where to start?
The feature of creating custom fields for products is baked right into WooCommerce, whether to implement it directly in functions.php or do the same via a plugin is left to one's sole discretion.
Remi Corson has written an excellent article detailing the same.
Here's the gist :
1.Create the fields using the woocommerce_product_options_general_product_data hook
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
// Define your fields here.
// You can create text, textarea, select, checkbox and custom fields
}
2.When product is saved save the value entered in your custom field using woocommerce_process_product_meta hook
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields_save( $_post_id ) {
//save field values
}
WooCommerce is a WordPress plugin that will help you to turn your website into an eCommerce store.
Yes, you can write an Extension ( or ADD-On) for this plugin, in fact there are already hundreds of Extension ( free and Paid ) have been made for it.
In order to create an Extension ( or ADD-ON ) for this plugin, you need to understand 2 things:
WooCommerce API
http://docs.woothemes.com/document/create-a-plugin/
WordPress API https://codex.wordpress.org/Writing_a_Plugin

hide popup maker plugin link from wordpress

I installed pop up maker and capabilities plugin in wordpress for my website. I want to create one user who is not able to see the link for pop up maker. I tried with adding user with some capability but I am not able to hide pop up maker link.
How can I achieve this? Do I need to use another capability plugin?
You can use the remove_menu_page() function called via the admin_menu action hook. If you just want to remove the link for a single user, check the current user's ID first with wp_get_current_user().
function remove_admin_menu_item_for_user() {
$user = wp_get_current_user();
// Check to see if the current user's ID is the one we want to remove the page for
if ( $user->ID == ??? ){
// Use the $menu_slug for the page you want to remove
remove_menu_page( $menu_slug );
}
}
add_action( 'admin_menu', 'remove_admin_menu_item_for_user' );
If you would prefer to use a plugin Admin Menu Editor should work as well, though you may need the Pro version.

Wordpress - remove some posts from query

I'm trying to make a plugin.
Its job is to generate and send a link to the author after a post is published by admin.
After clicking on the link will be the post actually published.
I did that after the click on the link there will be a post meta added to the post.
NOW I cant find a solution how to show only posts with the meta or ADMINS (or with some user level) posts.
I decided I need a filter bud I cant figure out how to do the ADMIN posts exceptions.
How do I filter only non-admin posts.
I think I need to remove the "bad" posts from $query but how ?
add_filter( 'pre_get_posts' , 'postsClean' );
function postsClean( $query ){
// check all posts and if the post should be not published remove it from query
}
Or is there any better way ?
If you are using wp_query you can use - for negation, e.g.
$wp_query_obj->set( 'author', '-1' );
WP_Query shows a full list of query arguments.

Resources