Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Simpler WordPress Admin for Clients

A Simpler WordPress Admin for Clients

Some tips and tricks for optimising the WordPress admin to make it easier for clients to get the most out of.

Mark Wilkinson

April 26, 2014
Tweet

More Decks by Mark Wilkinson

Other Decks in Technology

Transcript

  1. About Me Freelance WordPress Developer Secondary School Teacher of ICT

    - used to lead the ICT department until moving more towards WordPress
  2. /*************************************************************** * Function wpmark_remove_admin_menus() * Removes admin menus ***************************************************************/ function

    wpmark_remove_admin_menu() { /* remove the menu item */ remove_menu_page( ‘edit-comments.php’ ); ! } ! add_action( 'admin_menu', 'wpmark_remove_admin_menu', 999 );
  3. /*************************************************************** * Function wpmark_remove_admin_menus() * Removes admin menus ***************************************************************/ function

    wpmark_remove_multiple_admin_menus() { ! $wpmark_admin_menus = array( 'edit-comments.php', ‘tools.php', ); /* loop through each menu item to remove */ foreach( $wpmark_admin_menus as $wpmark_admin_menu ) { /* remove the menu item */ remove_menu_page( $wpmark_admin_menu ); } ! } ! add_action( 'admin_menu', 'wpmark_remove_multiple_admin_menus', 999 );
  4. function wpmark_remove_multiple_metaboxes() { $wpmark_metaboxes = apply_filters( 'wpmark_removed_metaboxes', array( array( 'id'

    => 'postcustom', 'page' => 'post', 'context' => 'normal' ), array( 'id' => 'tagsdiv-post_tag', 'page' => 'post', 'context' => 'side' ), ) ); /* loop through each meta box item to remove */ foreach( $wpmark_metaboxes as $wpmark_metabox ) { /* remove each metabox from the array */ remove_meta_box( $wpmark_metabox[ 'id' ], $wpmark_metabox[ 'page' ] , $wpmark_metabox[ 'context' ] ); } } add_action( 'do_meta_boxes', 'wpmark_remove_multiple_metaboxes');
  5. function wpmark_slide_metabox_changes() { ! remove_meta_box( 'postimagediv', 'wpmark_slide', 'side' ); !

    add_meta_box( 'postimagediv', __( 'Slide Image' ), 'post_thumbnail_meta_box', 'wpmark_slide', 'advanced', 'low' ); ! } ! add_action( 'do_meta_boxes', 'wpmark_slide_metabox_changes' );
  6. function wpmark_add_meta_box() { ! /* add meta box */ add_meta_box(

    'wpmark_slide_info', // meta box id 'Slide Information', // meta box title 'wpmark_metabox_html', // function for html output 'wpmark_slide', // post type to add it to 'normal', // context - part of page to add it to 'default' // priority ); ! } ! add_action( 'add_meta_boxes', ‘wpmark_add_meta_box' );
  7. function wpmark_metabox_html( $post ) { /* use nonce for verification

    */ wp_nonce_field( plugin_basename( __FILE__ ), 'wpmark_nonce_name' ); ?> <table class="form-table pxlsld-metabox"> <tbody> <tr> <th style="width: 18%;"> <label for="wpmark_slide_link"><strong>Slide Link URL</strong></label> </th> <td style="width: 78%;"> <input style="width: 95%;" type="text" value="<?php echo esc_attr( get_post_meta( $post- >ID, '_wpmark_slide_link', true ) ); ?>" name="wpmark_slide_link" /> <p class="pxlsld-description">Enter a URL above for the slide link.</p> </td> </tr> </tbody> </table> <?php }
  8. function wpmark_save_metabox_data( $post_id ) { ! /* check this is

    the correct post type */ if ( 'wpmark_slide' != get_post_type( $post_id ) return; ! /* check if the current user is authorised to do this action */ if( ! current_user_can( 'edit_page', $post_id ) ) return; ! /* secondly we need to check if the user intended to change this value */ if ( ! isset( $_POST[ 'wpmark_nonce_name' ] ) || ! wp_verify_nonce( $_POST[ 'wpmark_nonce_name' ], plugin_basename( __FILE__ ) ) ) return; ! /* santize the user input */ $wpmark_data = sanitize_text_field( $_POST[ 'wpmark_slide_link'] ); ! /* save the post data */ update_post_meta( $post_id, '_wpmark_slide_link', $wpmark_data ); ! } add_action( 'save_post', 'wpmark_save_metabox_data' );
  9. function wpmark_login_logo() { if( file_exists( STYLESHEETPATH . '/images/login-logo.png' ) )

    { $wpmark_sizes = apply_filters( 'wpmark_login_logo_sizes', array( 'width' => '300', 'height' => '100' ) ); ! echo ' <style> .login h1 a { background-image: url('.get_stylesheet_directory_uri() . '/images/login-logo.png); background-size: ' . $wpmark_sizes[ 'width' ] . 'px' . ' ' . $wpmark_sizes[ 'height' ] . 'px; height: ' . $wpmark_sizes[ 'height' ] . 'px; width: ' . $wpmark_sizes[ 'width' ] . 'px; } </style>'; ! } // end if login logo present in theme ! } ! add_action( 'login_head', 'wpmark_login_logo' );
  10. function wpmark_add_site_options_menu() { add_menu_page( 'Site Options', 'Site Options', 'edit_posts', 'wpmark_site_options',

    'wpmark_site_options_content', 'div', 99 ); } ! add_action( 'admin_menu', 'wpmark_add_site_options_menu' );
  11. “What happens in terms of help after my site goes

    live?” “Can I call you if this go wrong and I get stuck?”