Skip to content

Instantly share code, notes, and snippets.

@not-only-code
Last active December 15, 2015 17:59
Show Gist options
  • Save not-only-code/5300078 to your computer and use it in GitHub Desktop.
Save not-only-code/5300078 to your computer and use it in GitHub Desktop.
<?php
function _register_post_type( $post_type = '', $args = array() ) {
if ( empty( $post_type ) )
return;
$singular = empty( $args['singular'] ) ? $post_type : $args['singular'];
$singular = str_replace( '_', ' ', $singular );
$singular = ucwords( $singular );
$plural = empty( $args['plural'] ) ? "{$singular}s" : $args['plural'];
$plural = ucwords( $plural );
$plural_lower = strtolower( $plural );
$args['labels'] = empty( $args['labels'] ) ? array() : $args['labels'];
$args['labels'] = wp_parse_args( $args['labels'], array(
'name' => $plural,
'singular_name' => $singular,
'add_new' => __( 'Add New', 'your_textdomain' ),
'add_new_item' => sprintf( __( 'Add New %s', 'your_textdomain' ), $singular ),
'edit_item' => sprintf( __( 'Edit %s', 'your_textdomain' ), $singular ),
'new_item' => sprintf( __( 'New %s', 'your_textdomain' ), $singular ),
'view_item' => sprintf( __( 'View %s', 'your_textdomain' ), $singular ),
'search_items' => sprintf( __( 'Search %s', 'your_textdomain' ), $plural ),
'not_found' => sprintf( __( 'No %s found', 'your_textdomain' ), $plural_lower ),
'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'your_textdomain' ), $plural_lower ),
'parent_item_colon' => null,
'all_items' => sprintf( __( 'All %s', 'your_textdomain' ), $plural ),
'menu_name' => $plural,
) );
$args = wp_parse_args( $args, array(
'public' => true,
) );
register_post_type( $post_type, $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment