WordPress User Experience

About You

About Me

j

awwww

WordPress

"Decisions, not Options"

  • CPTs
  • Custom Taxonomies
  • Role
  • Additional Access Control
  • Real World Example

    Register a "Staff" custom post type

    						
    add_action( 'init', 'codex_sfaff_init' );
    /**
     * Register a book post type.
     *
     * @link http://codex.wordpress.org/Function_Reference/register_post_type
     */
    function codex_staff_init() {
    	$labels = array(
    		'name'               => _x( 'Staff Member', 'post type general name', 'your-plugin-textdomain' ),
    		'singular_name'      => _x( 'Staff Member', 'post type singular name', 'your-plugin-textdomain' ),
    		'menu_name'          => _x( 'Staff Members', 'admin menu', 'your-plugin-textdomain' ),
    		'name_admin_bar'     => _x( 'Staff Member', 'add new on admin bar', 'your-plugin-textdomain' ),
    		'add_new'            => _x( 'Add New', 'Staff Member', 'your-plugin-textdomain' ),
    		'add_new_item'       => __( 'Add New Staff Member', 'your-plugin-textdomain' ),
    		'new_item'           => __( 'New Staff Member', 'your-plugin-textdomain' ),
    		'edit_item'          => __( 'Edit Staff Member', 'your-plugin-textdomain' ),
    		'view_item'          => __( 'View Staff Member', 'your-plugin-textdomain' ),
    		'all_items'          => __( 'All Staff Members', 'your-plugin-textdomain' ),
    		'search_items'       => __( 'Search Staff Members', 'your-plugin-textdomain' ),
    		'parent_item_colon'  => __( 'Parent Staff Member:', 'your-plugin-textdomain' ),
    		'not_found'          => __( 'No books found.', 'your-plugin-textdomain' ),
    		'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' ),
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'query_var'          => true,
    		'rewrite'            => array( 'slug' => 'staff-member' ),
    		'capability_type'    => 'post',
    		'has_archive'        => true,
    		'hierarchical'       => false,
    		'menu_position'      => null,
    		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    	);
    
    	register_post_type( 'staff-member', $args );
    }
    						
    					

    "You're Gonna See Some Serious Sh*t."

    register_post_type();

    It's just a template for your custom content

    Let's start with the most obvious...

    What does a thumbtack have to do with staff members?

    http://melchoyce.github.io/dashicons/
    						
    'menu_icon' => 'dashicons_businessman'
    						
    					
    						'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    					
    'supports' => array( 'title', 'thumbnail', 'revisions' )

    Throw in some magic

    "But there are two spots to enter a "Title"..."

    						
    add_filter('gettext','custom_staff_title');
    
    function custom_staff_title( $input ) {
    
        global $post_type;
    
        if( is_admin() && 'Enter title here' == $input && 'mandr_staff' == $post_type )
            return 'Enter Staff Member's Name';
    
        return $input;
    }
    						
    					

    I didn't publish no post!

    						
    function set_messages($messages) {
    	global $post, $post_ID;
    	$post_type = get_post_type( $post_ID );
    
    	$obj = get_post_type_object($post_type);
    	$singular = $obj->labels->singular_name;
    
    	$messages[$post_type] = array(
    	0 => '', // Unused. Messages start at index 1.
    	1 => sprintf( __($singular.' updated. View '.strtolower($singular).''), esc_url( get_permalink($post_ID) ) ),
    	2 => __('Custom field updated.'),
    	3 => __('Custom field deleted.'),
    	4 => __($singular.' updated.'),
    	5 => isset($_GET['revision']) ? sprintf( __($singular.' restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    	6 => sprintf( __($singular.' published. View '.strtolower($singular).''), esc_url( get_permalink($post_ID) ) ),
    	7 => __('Page saved.'),
    	8 => sprintf( __($singular.' submitted. Preview '.strtolower($singular).''), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    	9 => sprintf( __($singular.' scheduled for: %1$s. Preview '.strtolower($singular).''), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    	10 => sprintf( __($singular.' draft updated. Preview '.strtolower($singular).''), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    	);
    
    	return $messages;
    }
    						
    					

    What have we learned?

    This is too much work and I ain't got time for this crap

    https://github.com/MandRMarketing/MandR-Core-Classes https://github.com/MandRMarketing/Slide-CPT

    Bonus things from left field

    If you style it...

    They'll probably never use it but you should still style it anyway!

    https://github.com/BeardedGinger/WP-Kitchen-Sink-Draft https://wordpress.org/plugins/monster-widget/

    Kill editing in the dashboard

    						
    define('DISALLOW_FILE_EDIT', true);
    						
    					

    No blog?

    Don't hijack the posts!

    Clean up after yourself

    http://joshmallard.com
    http://twitter.com/aBearded_Ginger
    https://github.com/BeardedGinger