Add own capabilites
-
Please, add kadence his own capabilities to garant Roles to edit customizer options. Now only admin can edit design and layouts in customizer.
I need garant to Shopmanager Role or a Designer Role to make changes in the customizer.
Thx!
-
manage_options is used per theme guidelines.
You can filter this on kadence_theme_customizer_capability filter.
Ben
Can you post a snippet of how I should do it? I have this code but I can’t get it to work. Thanks for your time
add_action( 'init', function() { // Only needed in the customizer if ( ! is_customize_preview() ) { $role_object = get_role( 'shop_manager' ); $role_object->remove_cap( 'manage_options'); return; } } );
This only run 1 time, after save in customizer shop_manager gets again manage options… a don´t want shop_manager manage options… only edit customizer … 🙁
function allow_shop_manager_customize( ) { if ( isset( $_REQUEST['wp_customize'] ) ) { $role_object = get_role( 'shop_manager' ); $role_object->add_cap( 'manage_options' ); } else { $role_object = get_role( 'shop_manager' ); $role_object->remove_cap( 'manage_options' ); } } add_filter( 'kadence_theme_customizer_capability', 'allow_shop_manager_customize', 10, 3 );
I think it works now, do you think this is the cleanest way or do you have another method that suits better?
I do not know if it is completely correct. What do you think?
but i have this error when open Header, Footer, page layout and customizer stop working
react-dom.min.js?ver=16.13.1:125 TypeError: Cannot read property 'setting' of undefined at new n (customizer.js?ver=1.0.21:27) at Yg (react-dom.min.js?ver=16.13.1:68) at rh (react-dom.min.js?ver=16.13.1:98) at zj (react-dom.min.js?ver=16.13.1:228) at Th (react-dom.min.js?ver=16.13.1:152) at tj (react-dom.min.js?ver=16.13.1:152) at Te (react-dom.min.js?ver=16.13.1:146) at Ja (react-dom.min.js?ver=16.13.1:224) at md (react-dom.min.js?ver=16.13.1:173) at react-dom.min.js?ver=16.13.1:175
function allow_users_who_can_edit_posts_to_customize( ) { $required_cap = 'manage_options'; if ( isset( $_REQUEST['wp_customize'] ) ) { $caps = array( $required_cap ); $role_object = get_role( 'shop_manager' ); $role_object->add_cap( $caps ); } return; } add_filter( 'kadence_theme_customizer_capability', 'allow_users_who_can_edit_posts_to_customize', 10, 3 ); add_action( 'admin_init', 'allow_users_who_can_edit_posts_to_customize');
- This reply was modified 2 years, 10 months ago by sermalefico.
- This reply was modified 2 years, 10 months ago by sermalefico.
Hi, our filter is meant to be used like this:
add_filter( 'kadence_theme_customizer_capability', 'custom_role_for_customizer', 10 ); function custom_role_for_customizer( $cap ) { $cap = 'shop_manager'; return $cap; }
Ben
I try with your snippet
but same errors when open Header, footer, page designs, options in customizer. Customizer freaze in this sections, and you can’t back to previus section.
react-dom.min.js?ver=16.13.1:125 TypeError: Cannot read property 'setting' of undefined at new n (customizer.js?ver=1.0.26:27) at Yg (react-dom.min.js?ver=16.13.1:68) at rh (react-dom.min.js?ver=16.13.1:98) at zj (react-dom.min.js?ver=16.13.1:228) at Th (react-dom.min.js?ver=16.13.1:152) at tj (react-dom.min.js?ver=16.13.1:152) at Te (react-dom.min.js?ver=16.13.1:146) at Ja (react-dom.min.js?ver=16.13.1:224) at md (react-dom.min.js?ver=16.13.1:173) at react-dom.min.js?ver=16.13.1:175 Me @ react-dom.min.js?ver=16.13.1:125 Ih.c.callback @ react-dom.min.js?ver=16.13.1:138 Wg @ react-dom.min.js?ver=16.13.1:67 oj @ react-dom.min.js?ver=16.13.1:127 Aj @ react-dom.min.js?ver=16.13.1:160 unstable_runWithPriority @ react.min.js?ver=16.13.1:25 Da @ react-dom.min.js?ver=16.13.1:60 ab @ react-dom.min.js?ver=16.13.1:154 Te @ react-dom.min.js?ver=16.13.1:146 Ja @ react-dom.min.js?ver=16.13.1:224 md @ react-dom.min.js?ver=16.13.1:173 (anonymous) @ react-dom.min.js?ver=16.13.1:175 Rh @ react-dom.min.js?ver=16.13.1:147 nd @ react-dom.min.js?ver=16.13.1:175 I.render @ react-dom.min.js?ver=16.13.1:238 renderContent @ customizer.js?ver=1.0.26:27 (anonymous) @ customizer.js?ver=1.0.26:6 v.each.v.forEach @ underscore.min.js?ver=1.8.3:2 (anonymous) @ customizer.js?ver=1.0.26:6 c @ load-scripts.php?c=1&load[chunk_0]=jquery-core,jquery-migrate&ver=5.7.2:2 fireWith @ load-scripts.php?c=1&load[chunk_0]=jquery-core,jquery-migrate&ver=5.7.2:2 set @ load-scripts.php?c=1&load[chunk_0]=heartbeat,customize-base,customize-controls,customize-widgets,thickbox,mce-view,imgareaselect&ver=5.7.2:4 i @ load-scripts.php?c=1&load[chunk_0]=jquery-core,jquery-migrate&ver=5.7.2:2 _toggleExpanded @ load-scripts.php?c=1&load[chunk_0]=heartbeat,customize-base,customize-controls,customize-widgets,thickbox,mce-view,imgareaselect&ver=5.7.2:6 expand @ load-scripts.php?c=1&load[chunk_0]=heartbeat,customize-base,customize-controls,customize-widgets,thickbox,mce-view,imgareaselect&ver=5.7.2:6 (anonymous) @ load-scripts.php?c=1&load[chunk_0]=heartbeat,customize-base,customize-controls,customize-widgets,thickbox,mce-view,imgareaselect&ver=5.7.2:6 dispatch @ load-scripts.php?c=1&load[chunk_0]=jquery-core,jquery-migrate&ver=5.7.2:2 v.handle @ load-scripts.php?c=1&load[chunk_0]=jquery-core,jquery-migrate&ver=5.7.2:2 react-dom.min.js?ver=16.13.1:161 Uncaught TypeError: Cannot read property 'setting' of undefined at new n (customizer.js?ver=1.0.26:27) at Yg (react-dom.min.js?ver=16.13.1:68) at rh (react-dom.min.js?ver=16.13.1:98) at zj (react-dom.min.js?ver=16.13.1:228) at Th (react-dom.min.js?ver=16.13.1:152) at tj (react-dom.min.js?ver=16.13.1:152) at Te (react-dom.min.js?ver=16.13.1:146) at Ja (react-dom.min.js?ver=16.13.1:224) at md (react-dom.min.js?ver=16.13.1:173) at react-dom.min.js?ver=16.13.1:175
Hi @sermalefico,
Apologies for the delay! I will get in touch with the developer and have him look into this for you as soon as he’s available. Thanks for your patience!Kindly,
HannahHi, I tested and what I sent works, if you are also wanting them to control the palette you can update to this:
add_filter( 'kadence_palette_customizer_capability', 'custom_role_for_customizer', 10 ); add_filter( 'kadence_theme_customizer_capability', 'custom_role_for_customizer', 10 ); function custom_role_for_customizer( $cap ) { $cap = 'shop_manager'; return $cap; }
Ben
- The topic ‘Add own capabilites’ is closed to new replies.