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. A Simpler WordPress Admin for
    Clients
    Mark Wilkinson
    @wpmark | markwilkinson.me

    View full-size slide

  2. About Me
    Freelance WordPress Developer
    Secondary School Teacher of ICT - used to lead
    the ICT department until moving more towards
    WordPress

    View full-size slide

  3. pixeljunction.co.uk
    compass-design.co.uk
    edupress.co.uk

    View full-size slide

  4. The Problem
    Why change the WordPress Admin?

    View full-size slide

  5. Remove Unnecessary Items
    In a plugin please!
    1
    https://github.com/pixeljunction/pxlcore

    View full-size slide

  6. /***************************************************************
    * 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 );

    View full-size slide

  7. /***************************************************************
    * 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 );

    View full-size slide

  8. remove_submenu_page( $menu_slug, $submenu_slug );

    View full-size slide

  9. remove_submenu_page( $menu_slug, $submenu_slug );
    remove_submenu_page(
    'themes.php',
    'customize.php'
    );

    View full-size slide

  10. function wpmark_remove_submenu() {
    remove_submenu_page(
    'themes.php',
    'customize.php'
    );
    }
    !
    add_action( 'admin_menu', 'wpmark_remove_submenu', 99 );

    View full-size slide

  11. remove_meta_box( $id, $page, $context );

    View full-size slide

  12. remove_meta_box( $id, $page, $context );
    remove_meta_box(
    'postcustom',
    'post',
    'normal'
    );

    View full-size slide

  13. 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');

    View full-size slide

  14. unregister_widget( $widget_class );

    View full-size slide

  15. unregister_widget( $widget_class );
    unregister_widget( 'WP_Widget_Calendar' );

    View full-size slide

  16. function wpmark_remove_calendar_widget() {
    unregister_widget( 'WP_Widget_Calendar' );
    }
    !
    add_action( 'widgets_init', 'wpmark_remove_calendar_widget' );

    View full-size slide

  17. Improve / Enhance
    What WordPress already gives us
    2

    View full-size slide

  18. Additional
    Metaboxes

    View full-size slide

  19. register_post_type( 'wpmark_slide',
    array(
    'labels' => $wpmark_slide_labels,
    'public' => true,
    'menu_position' => 90,
    'supports' => array(
    'title',
    'thumbnail'
    ),
    )
    );

    View full-size slide

  20. Change a Meta Box

    View full-size slide

  21. 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' );

    View full-size slide

  22. Add Meta Box

    View full-size slide

  23. 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' );

    View full-size slide

  24. Fill Meta Box with Some Content

    View full-size slide

  25. function wpmark_metabox_html( $post ) {
    /* use nonce for verification */
    wp_nonce_field( plugin_basename( __FILE__ ), 'wpmark_nonce_name' );
    ?>




    Slide Link URL



    Enter a URL above for the slide link.




    }

    View full-size slide

  26. Save Meta Box Data

    View full-size slide

  27. 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' );

    View full-size slide

  28. Login Page
    Logo

    View full-size slide

  29. 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 '
    <br/>.login h1 a {<br/>background-image: url('.get_stylesheet_directory_uri() . '/images/login-logo.png);<br/>background-size: ' . $wpmark_sizes[ 'width' ] . 'px' . ' ' . $wpmark_sizes[ 'height' ] . 'px;<br/>height: ' . $wpmark_sizes[ 'height' ] . 'px;<br/>width: ' . $wpmark_sizes[ 'width' ] . 'px;<br/>}<br/>';
    !
    } // end if login logo present in theme
    !
    }
    !
    add_action( 'login_head', 'wpmark_login_logo' );

    View full-size slide

  30. Add Menu
    Pages

    View full-size slide

  31. add_menu_page(
    $page_title,
    $menu_title,
    $capability,
    $menu_slug,
    $function,
    $icon_url,
    $position
    );

    View full-size slide

  32. 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' );

    View full-size slide

  33. function wpmark_site_options_content() {
    ?>

    Site Options Page

    }

    View full-size slide

  34. Provide Help
    Support client right in the dashboard
    3

    View full-size slide

  35. “What happens in terms of help after my site
    goes live?”
    “Can I call you if this go wrong and I get
    stuck?”

    View full-size slide

  36. Remember
    WordPress is our tool, NOT our
    solution. Make it work best for your
    clients.

    View full-size slide

  37. ???
    Questions
    &
    thanks for listening

    View full-size slide