Last active
May 2, 2019 03:24
-
-
Save bpmore/2bd17c16f5e6f7417b547c1f60d3df15 to your computer and use it in GitHub Desktop.
Limit access to WordPress and Genesis widgets for the Editor Role.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?PHP | |
// Allow Editors to manage Widgets and Menus | |
function sp_editor_capabilities() { | |
$editor = get_role( 'editor' ); | |
if (!$editor->has_cap( 'edit_theme_options' ) ) { | |
$editor->add_cap( 'edit_theme_options' ); | |
} | |
if (!$editor->has_cap( 'wpml_manage_string_translation' ) ) { | |
$editor->add_cap( 'wpml_manage_string_translation' ); | |
} | |
if (!$editor->has_cap( 'wpml_manage_taxonomy_translation' ) ) { | |
$editor->add_cap( 'wpml_manage_taxonomy_translation' ); | |
} | |
} | |
add_action('admin_head', 'sp_editor_capabilities'); | |
/* Unregister WordPress and Genesis widgets for Editor Role*/ | |
if( !current_user_can('update_core') ) { | |
function unregister_widgets() { | |
unregister_widget('WP_Widget_Pages'); | |
unregister_widget( 'WP_Widget_Calendar' ); | |
unregister_widget('WP_Widget_Archives'); | |
unregister_widget('WP_Widget_Links'); | |
unregister_widget('WP_Widget_Meta'); | |
unregister_widget('WP_Widget_Search'); | |
// unregister_widget('WP_Widget_Text'); | |
unregister_widget('WP_Widget_Categories'); | |
unregister_widget('WP_Widget_Custom_HTML'); | |
unregister_widget('WP_Widget_Media_Audio'); | |
unregister_widget('WP_Widget_Media_Gallery'); | |
unregister_widget('WP_Widget_Media_Image'); | |
unregister_widget('WP_Widget_Media_Video'); | |
unregister_widget('WP_Widget_Recent_Posts'); | |
unregister_widget('WP_Widget_Recent_Comments'); | |
unregister_widget('WP_Widget_RSS'); | |
unregister_widget('WP_Widget_Tag_Cloud'); | |
unregister_widget('WP_Nav_Menu_Widget'); | |
unregister_widget( 'Genesis_eNews_Updates' ); | |
unregister_widget( 'Genesis_Featured_Page' ); | |
unregister_widget( 'Genesis_Featured_Post' ); | |
unregister_widget( 'Genesis_Latest_Tweets_Widget' ); | |
unregister_widget( 'Genesis_Menu_Pages_Widget' ); | |
unregister_widget( 'Genesis_User_Profile_Widget' ); | |
unregister_widget( 'Genesis_Widget_Menu_Categories' ); | |
} | |
add_action( 'widgets_init', 'unregister_widgets', 20 ); | |
} | |
/* Unregister WordPress widgets for Editor Role*/ | |
/*if( !current_user_can('update_core') ) { | |
function unregister_default_wp_widgets() { | |
unregister_widget('WP_Widget_Pages'); | |
unregister_widget( 'WP_Widget_Calendar' ); | |
unregister_widget('WP_Widget_Archives'); | |
unregister_widget('WP_Widget_Links'); | |
unregister_widget('WP_Widget_Meta'); | |
unregister_widget('WP_Widget_Search'); | |
// unregister_widget('WP_Widget_Text'); | |
unregister_widget('WP_Widget_Categories'); | |
unregister_widget('WP_Widget_Custom_HTML'); | |
unregister_widget('WP_Widget_Media_Audio'); | |
unregister_widget('WP_Widget_Media_Gallery'); | |
unregister_widget('WP_Widget_Media_Image'); | |
unregister_widget('WP_Widget_Media_Video'); | |
unregister_widget('WP_Widget_Recent_Posts'); | |
unregister_widget('WP_Widget_Recent_Comments'); | |
unregister_widget('WP_Widget_RSS'); | |
unregister_widget('WP_Widget_Tag_Cloud'); | |
unregister_widget('WP_Nav_Menu_Widget'); | |
} | |
add_action('widgets_init', 'unregister_default_wp_widgets', 1); | |
} | |
// Unregister Genesis widgets | |
if( !current_user_can('update_core') ) { | |
function unregister_genesis_widgets() { | |
unregister_widget( 'Genesis_eNews_Updates' ); | |
unregister_widget( 'Genesis_Featured_Page' ); | |
unregister_widget( 'Genesis_Featured_Post' ); | |
unregister_widget( 'Genesis_Latest_Tweets_Widget' ); | |
unregister_widget( 'Genesis_Menu_Pages_Widget' ); | |
unregister_widget( 'Genesis_User_Profile_Widget' ); | |
unregister_widget( 'Genesis_Widget_Menu_Categories' ); | |
} | |
add_action( 'widgets_init', 'unregister_genesis_widgets', 20 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment