Skip to content

Instantly share code, notes, and snippets.

@ryanshoover
Last active August 29, 2015 14:22
Show Gist options
  • Save ryanshoover/632cca5d97ebfe9250f6 to your computer and use it in GitHub Desktop.
Save ryanshoover/632cca5d97ebfe9250f6 to your computer and use it in GitHub Desktop.
WordPress CPT Generator Class
<?php
class cptGenerator {
public static function create( $single = '', $plural = '', $args = array() ) {
if( empty( $plural ) )
$plural = $single . 's';
$labels = array(
'name' => __( ucfirst( $plural ), 'post type general name', 'tpc' ),
'singular_name' => __( ucfirst( $single ), 'post type singular name', 'tpc' ),
'add_new_item' => __( 'Add new '. ucfirst( $single ), 'post type add new', 'tpc' ),
);
$defaults = array(
'labels' => $labels,
'public' => TRUE,
'show_ui' => TRUE,
'query_var' => TRUE,
'capability_type' => 'post',
'menu_position' => 15,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
);
$args = wp_parse_args( $args, $defaults );
register_post_type( strtolower($single) , $args );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment