Last active
August 29, 2015 14:22
-
-
Save ryanshoover/632cca5d97ebfe9250f6 to your computer and use it in GitHub Desktop.
WordPress CPT Generator Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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