- This topic has 37 replies, 3 voices, and was last updated 5 years, 1 month ago by
Arimateia Jr.
-
AuthorPosts
-
September 18, 2018 at 8:32 pm #680746
Mitchell
From what I can tell a user role has to have been granted the ‘manage_options’ capability to be able to get to Appearance > Elements and add/update/remove.
I would like to give users with a specific role the ability to do this without enabling the ‘manage_options’ capability itself because then it opens up the ability to view/modify settings for a lot of other plug-ins and such that I do not want those users to have be access to get into.
Is there a way to update/modify the capability assigned to grant access to the Elements module so I could grant access to this capability separately?
Thanks!
September 19, 2018 at 8:37 am #681292Tom
Lead DeveloperLead DeveloperHi there,
You could try something like this:
add_filter( 'register_post_type_args', function( $args, $post_type ) { if ( 'gp_elements' === $post_type ) { $args['capability_type'] = 'manage_options'; // Change to whatever. } return $args; }, 10, 2 );August 20, 2019 at 6:39 am #988799Michael
This worked for me:
add_filter( 'register_post_type_args', function( $args, $post_type ) { if ( 'gp_elements' === $post_type ) { $args['capability_type'] = 'post'; } return $args; }, 10, 2 );Now i need to show the menu on the left for editors.
How can i do it?
It’s odd that in GP editors don’t have access to this website content?
Can we had it on the next version?Thank you
August 20, 2019 at 4:58 pm #989290Tom
Lead DeveloperLead DeveloperHi there,
Just to confirm, do you mean the “Elements” link under the “Appearance” section?
Let me know 🙂
August 21, 2019 at 12:17 am #989409Michael
yes,
Appearance > Elements
my clients need to edit the content but usually i dont put them admin for security reasons 🙂
August 21, 2019 at 9:22 am #989899Tom
Lead DeveloperLead DeveloperHmm, it seems
add_submenu_page()doesn’t have a filter we can tap into, which is a shame.I’ve added a new filter to GPP 1.9:
generate_elements_admin_menu_capabilityIf you’d like to add this filter now, you can:
1. Go to
wp-content/plugins/gp-premium/elements/class-post-type.php
2. Find themenu_item()function on line 252.
3. Replacemanage_optionswithapply_filters( 'generate_elements_admin_menu_capability', 'manage_options' )Now, we can do this:
add_filter( 'generate_elements_admin_menu_capability', function() { return 'post'; } );August 26, 2019 at 3:44 am #993596Michael
Hello,
For me it doesn’t work.
When i implement your code, the “Elements” disappears in the administrators UI but “Appearance” and “Appearance > Elements” doesn’t show up in the editors UI.Thank you
August 26, 2019 at 9:15 am #993931Tom
Lead DeveloperLead DeveloperTry this instead:
add_filter( 'generate_elements_admin_menu_capability', function() { return 'edit_posts'; } );August 27, 2019 at 6:29 am #994520Michael
hello again,
The menu gets perfectly displayed now.
But when i am an editor and i click on “Appearance > Elements”, i am blocked by the wordpress admin because i don’t have the correct permission apparently for edit.php?post_type=gp_elements.Thank you
August 27, 2019 at 6:43 am #994522Michael
apparently we need to create the capabilities and map them…
http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-typesAugust 27, 2019 at 4:30 pm #995019Tom
Lead DeveloperLead DeveloperIs this being caused by this function?: https://generatepress.com/forums/topic/add-update-elements-for-specific-user-role/#post-988799
Are you able to access as an admin?
August 30, 2019 at 3:13 am #997004Michael
hello
this is my code so far :
functions.php:
add_filter( 'generate_elements_admin_menu_capability', function() { return 'edit_posts'; } ); add_filter( 'register_post_type_args', function( $args, $post_type ) { if ( 'gp_elements' === $post_type ) { $args['capability_type'] = 'post'; } return $args; }, 10, 2 );plugins/gp-premium/elements/class-post-type.php :
/** * Create our admin menu item. * * @since 1.7 */ public function menu_item() { add_submenu_page( 'themes.php', esc_html__( 'Elements', 'gp-premium' ), esc_html__( 'Elements', 'gp-premium' ), apply_filters( 'generate_elements_admin_menu_capability', 'manage_options' ), 'edit.php?post_type=gp_elements' ); }goal 1 – show menu in UI => “generate_elements_admin_menu_capability” filter
goal 2 – give permission => “register_post_type_args” filterin my tests, the two filters work separately but together not.
thank you
August 30, 2019 at 9:24 am #997345Tom
Lead DeveloperLead DeveloperSo the
register_post_type_argsfilter works as long as thegenerate_elements_admin_menu_capabilityisn’t there?Looking at the Elements post type code, it should work for editors by default, so you shouldn’t need the
register_post_type_argsfilter. Only thegenerate_elements_admin_menu_capabilityfilter should be necessary.Let me know 🙂
September 24, 2019 at 12:46 am #1017299Michael
Hello,
I just tested on a brand new wordpress last version of theme and plugin and it doesn’t work for me. “register_post_type_args” give the permissions but doesn’t show the menu in admin UI.
i think i will just pass because the wordpress documentation is not clear.thank you
September 24, 2019 at 9:15 am #1017807Tom
Lead DeveloperLead DeveloperDid that fresh install have the changes made to GP Premium I mentioned up above?: https://generatepress.com/forums/topic/add-update-elements-for-specific-user-role/#post-989899
-
AuthorPosts
- You must be logged in to reply to this topic.