Last active
November 1, 2015 12:42
-
-
Save shines/6a48ef9fb31d582458c3 to your computer and use it in GitHub Desktop.
s&j labs - WordCamp Montreal - Example Code
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 | |
// Produced for WordCamp 2015 - Customizing your WP-Admin | |
// Sarah C. Hines, shines & jecker laboratories | |
// http://shinesandjecker.com | |
// To require this file, place this file in your theme root, then insert the line below into your theme functions | |
// require_once(STYLESHEETPATH . '/admin-adjustments.php'); | |
/************* LOGIN SCREEN *****************/ | |
// register CSS. Logo/Background/Styles | |
add_action( 'login_enqueue_scripts', 'sjlabs_login_css', 10 ); | |
function sjlabs_login_css() { | |
wp_enqueue_style( | |
'sjlabs_login_css', | |
get_template_directory_uri() . '/library/css/login.css', | |
false | |
); | |
} | |
// change logo URL from wordpress.org to this site’s | |
add_filter( 'login_headerurl', 'sjlabs_login_url' ); | |
function sjlabs_login_url() { | |
return home_url(); | |
} | |
// change alt text from ‘Power by WordPress’ to Site Name | |
add_filter( 'login_headertitle', 'sjlabs_login_title' ); | |
function sjlabs_login_title() { | |
return get_option( 'blogname' ); | |
} | |
/************* DASHBOARD *****************/ | |
remove_action('welcome_panel', 'wp_welcome_panel'); | |
// remove dashboard widgets & add your own. You may need to adjust the priority | |
add_action( 'wp_dashboard_setup', 'adjust_default_dashboard_widgets', 11); | |
function adjust_default_dashboard_widgets() { | |
global $wp_meta_boxes; | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); // Right Now Widget | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']); // Activity Widget | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); // Comments Widget | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); // Incoming Links Widget | |
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); // Plugins Widget | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); // Quick Press Widget | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); // Recent Drafts Widget | |
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); // WordPress News | |
// remove plugin dashboard boxes | |
unset($wp_meta_boxes['dashboard']['normal']['core']['rg_forms_dashboard']); // Gravity Forms Plugin Widget | |
//add box | |
wp_add_dashboard_widget('admin_dashboard_box', 'Did you know?', 'sjlabs_admin_dashboard_box'); | |
} | |
function sjlabs_admin_dashboard_box() { | |
echo '<h4>Questions? Comments? Contact us: </h4> | |
<p> | |
<a href="http://www.shinesandjecker.com/contact">shines & jecker laboratories</a><br /> | |
<strong>Email:</strong> <a href="mailto:service.please@shinesandjecker.com">service.please@shinesandjecker.com</a><br /> | |
<strong>Phone:</strong> 207.518.8851 | |
</p>'; | |
} | |
/************* FOOTER *****************/ | |
add_filter( 'admin_footer_text', 'sjlabs_custom_admin_footer' ); | |
function sjlabs_custom_admin_footer() { | |
_e( 'Thank you for working with <a href="http://www.shinesandjecker.com/"><strong>shines & jecker laboratories</strong></a>. | |
<a href="http://www.shinesandjecker.com/contact/">Please contact us with any questions, feedback, or support.</a>', 'twentyfifteen' ); | |
} | |
/************* HELP DOCUMENTATION *****************/ | |
add_action('admin_head', 'sjlabs_remove_help_tabs'); | |
function sjlabs_remove_help_tabs() { | |
$screen = get_current_screen(); | |
$screen->remove_help_tabs(); | |
if ($screen->id == 'dashboard') : | |
$screen->add_help_tab( array( | |
'id' => 'Tab of Help', | |
'title' => __( 'Helpful Tab' ), | |
'content' => __( '<p>This is where you can provide tabbed help to users. Add styleguide links, formatting help, etc. You can insert HTML within for <strong>extra emphasis</strong>.</p>' ) | |
)); | |
$screen->set_help_sidebar( __('<p><strong>This is a sidebar for extra info!</strong></p>' ) ); | |
endif; | |
} | |
/************* REMOVE MENUS *****************/ | |
global $user_login; | |
get_currentuserinfo(); | |
if ($user_login !== "master-user") { | |
add_action( 'admin_menu', 'sjlabs_remove_menus', 9999 ); | |
} | |
function sjlabs_remove_menus() { | |
// remove_menu_page( 'index.php' ); //Dashboard | |
remove_submenu_page( 'index.php', 'update-core.php' ); | |
// remove_menu_page( 'edit.php' ); //Posts | |
// remove_menu_page( 'upload.php' ); //Media | |
// remove_menu_page( 'edit.php?post_type=page' ); //Pages | |
// remove_menu_page( 'edit-comments.php' ); //Comments | |
remove_menu_page( 'themes.php' ); //Appearance | |
// global $submenu; unset($submenu['themes.php'][6]); //Customizer | |
// remove_submenu_page( 'themes.php', 'widgets.php' ); //Widgets | |
// remove_submenu_page( 'themes.php', 'nav-menus.php' ); //Menus | |
// remove_submenu_page( 'themes.php', 'theme-editor.php' ); //Editor | |
remove_menu_page( 'plugins.php' ); //Plugins | |
// remove_submenu_page( 'plugins.php', 'plugin-editor.php' ); //Plugin Editor | |
// remove_menu_page( 'users.php' ); //Users | |
// remove_submenu_page( 'users.php', 'profile.php' ); //Your Profile | |
remove_menu_page( 'tools.php' ); //Tools | |
// remove_submenu_page( 'tools.php', 'import.php' ); //Import | |
// remove_submenu_page( 'tools.php', 'export.php' ); //Export | |
remove_menu_page( 'options-general.php' ); //Settings | |
// remove_submenu_page( 'options-general.php', 'options-writing.php' ); //Writing | |
// remove_submenu_page( 'options-general.php', 'options-reading.php' ); //Reading | |
// remove_submenu_page( 'options-general.php', 'options-discussion.php' ); //Discussion | |
// remove_submenu_page( 'options-general.php', 'options-media.php' ); //Media | |
// remove_submenu_page( 'options-general.php', 'options-privacy.php' ); //Privacy | |
// remove_submenu_page( 'options-general.php', 'options-permalinks.php' ); //Permalinks | |
/* Pluging Menu Removal. To remove Top Level plugin menus, you typically need to remove whatever is after 'admin.php?page=' e.g. "remove_menu_page( 'plugin');" | |
*/ | |
// remove_menu_page( 'gf_edit_forms' ); | |
remove_submenu_page( 'gf_edit_forms', 'gf_help' ); | |
remove_submenu_page( 'gf_edit_forms', 'gf_settings' ); | |
remove_submenu_page( 'gf_edit_forms', 'gf_update' ); | |
remove_submenu_page( 'gf_edit_forms', 'gf_addons' ); | |
} | |
/************* MENU ORDER *****************/ | |
add_filter('custom_menu_order', 'sjlabs_custom_menu_order'); | |
add_filter('menu_order', 'sjlabs_custom_menu_order'); | |
function sjlabs_custom_menu_order($menu_ord) { | |
if (!$menu_ord) return true; | |
return array( | |
'index.php', // Dashboard | |
'separator1', | |
'edit.php?post_type=page', // Pages | |
'edit.php', // Posts | |
'separator2', | |
'edit-comments.php', // Comments | |
'upload.php', // Media | |
// 'themes.php', // Appearance | |
// 'plugins.php', // Plugins | |
// 'users.php', // Users | |
// 'tools.php', // Tools | |
// 'options-general.php' // Settings | |
); | |
} | |
/************* ADD PAGE *****************/ | |
add_action( 'admin_menu', 'register_sjlabs_help_page' ); | |
//Use add_submenu_page for menus within top level pages | |
function register_sjlabs_help_page(){ | |
add_menu_page( | |
'Get Help', | |
'Get Help', | |
'manage_options', | |
'sjlabs_help', | |
'sjlabs_help_content', | |
'dashicons-star-filled', 100 ); | |
} | |
//Dashicons are awesome, allowing easy customized menu icons! | |
// https://developer.wordpress.org/resource/dashicons/ | |
function sjlabs_help_content(){ | |
echo "Insert Page Content Here"; | |
// Check out WP's great support for adding Admin Page Content | |
} | |
/************* ADMIN BAR *****************/ | |
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' ); | |
function remove_admin_bar_links() { | |
global $wp_admin_bar; | |
$wp_admin_bar->remove_node('wp-logo'); | |
$wp_admin_bar->remove_node('about'); | |
$wp_admin_bar->remove_node('wporg'); | |
$wp_admin_bar->remove_node('documentation'); | |
$wp_admin_bar->remove_node('support-forums'); | |
$wp_admin_bar->remove_node('feedback'); | |
// $wp_admin_bar->remove_node('view-site'); | |
$wp_admin_bar->remove_node('comments'); | |
$wp_admin_bar->remove_node('appearance'); | |
$wp_admin_bar->remove_node('customize-themes'); | |
$wp_admin_bar->remove_node('customize-widgets'); | |
$wp_admin_bar->remove_node('customize-background'); | |
$wp_admin_bar->remove_node('customize-header'); | |
$wp_admin_bar->remove_node('updates'); | |
// $wp_admin_bar->remove_node('menus'); | |
//Add a link! | |
$wp_admin_bar->add_node(array( | |
'id' => 'id-of-link', | |
'title' => 'Help Link', | |
'href' => admin_url(), | |
'parent' => 'site-name' | |
)); | |
} | |
/************* MENU COLUMNS *****************/ | |
add_action( 'manage_pages_columns', 'remove_admin_menu_comments' ); | |
function remove_admin_menu_comments( $columns ) { | |
unset( $columns[ 'comments' ] ); | |
return $columns; | |
} | |
/************* POST TAGS *****************/ | |
add_action('init', 'remove_tags'); | |
function remove_tags(){ | |
register_taxonomy('post_tag', array()); | |
} | |
/************* META BOXES *****************/ | |
add_action('admin_init','customize_meta_boxes'); | |
function customize_meta_boxes() { | |
remove_meta_box('postcustom','post','normal'); | |
remove_meta_box('commentstatusdiv','post','normal'); | |
remove_meta_box('commentsdiv','post','normal'); | |
remove_meta_box('slugdiv','post','normal'); | |
remove_meta_box('commentsdiv','post','normal'); | |
remove_meta_box('formatdiv','post','normal'); | |
remove_meta_box('postimagediv','post','side'); | |
remove_meta_box('trackbacksdiv','post','side'); | |
remove_meta_box('postcustom','page','normal'); | |
remove_meta_box('commentstatusdiv','page','normal'); | |
remove_meta_box('commentsdiv','page','normal'); | |
remove_meta_box('postimagediv','page','side'); | |
remove_meta_box('slugdiv','page','normal'); | |
remove_meta_box('authordiv','page','normal'); | |
remove_meta_box('slugdiv','testimonial','normal'); | |
} | |
/************* EDITOR ADJUSTMENTS *****************/ | |
//Images link to none | |
add_action('admin_init', 'sjlabs_imagelink_setup', 10); | |
function sjlabs_imagelink_setup() { | |
$image_set = get_option( 'image_default_link_type' ); | |
if ($image_set !== 'none') { | |
update_option('image_default_link_type', 'none'); | |
} | |
} | |
//Restrict link types with hyperlink button | |
add_filter( 'wp_link_query_args', 'sjlabs_restrict_post_types_in_url_builder' ); | |
function sjlabs_restrict_post_types_in_url_builder( $query ) { | |
$query['post_type'] = array( 'page', 'post' ); | |
return $query; | |
} | |
add_filter( 'tiny_mce_before_init', 'sjlabs_mce_init' ); | |
function sjlabs_mce_init($init) { | |
$init['toolbar1'] = 'formatselect,bold,italic,link,unlink,bullist,numlist,indent,outdent,pastetext,removeformat,charmap,undo,redo,wp_help,dfw'; | |
$init['toolbar2'] = ''; | |
$init['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Blockquote=blockquote;Pre = pre'; | |
return $init; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment