Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Midwest Dev Custom Post Type & Taxonomy Labels
- *
- * @since Midwest Dev 1.0
- * @param string $singular Singular label name
- * @param string $pluarl Plural label name or false if it's just singular with an s
- * @param string $type either Custom Post Type (cpt) or taxonomy
- * @return array $labels Label array
- */
- function mwd_get_labels( $singular, $plural = false, $type = 'cpt' ) {
- $labels = array();
- if ( !$plural ) {
- $plural = $singular . 's';
- }
- if ( $type == 'cpt' ) {
- $labels = array(
- 'name' => __( $plural ),
- 'singular_name' => __( $singular ),
- 'menu_name' => __( $plural ),
- 'name_admin_bar' => __( $singular ),
- 'add_new' => __( 'Add New' ),
- 'add_new_item' => __( 'Add New ' . $singular ),
- 'new_item' => __( 'New ' . $singular ),
- 'edit_item' => __( 'Edit ' . $singular ),
- 'view_item' => __( 'View ' . $singular ),
- 'all_items' => __( 'All ' . $plural ),
- 'search_items' => __( 'Search ' . $plural ),
- 'parent_item_colon' => __( 'Parent ' . $plural . ':' ),
- 'not_found' => __( 'No ' . strtolower( $plural ) . ' found.' ),
- 'not_found_in_trash' => __( 'No ' . strtolower( $plural ) . ' found in Trash.' )
- );
- } else if ( $type == 'taxonomy' ) {
- $labels = array(
- 'name' => _x( $plural, 'taxonomy general name' ),
- 'singular_name' => _x( $singular, 'taxonomy singular name' ),
- 'search_items' => __( 'Search ' . $plural ),
- 'popular_items' => __( 'Popular ' . $plural ),
- 'all_items' => __( 'All ' . $plural ),
- 'parent_item' => null,
- 'parent_item_colon' => null,
- 'edit_item' => __( 'Edit ' . $singular ),
- 'update_item' => __( 'Update ' . $singular ),
- 'add_new_item' => __( 'Add New ' . $singular ),
- 'new_item_name' => __( 'New ' . $singular . ' Name' ),
- 'separate_items_with_commas' => __( 'Separate ' . $plural . ' with commas' ),
- 'add_or_remove_items' => __( 'Add or remove ' . $plural ),
- 'choose_from_most_used' => __( 'Choose from the most used ' . $plural ),
- 'not_found' => __( 'No ' . $plural . ' found.' ),
- 'menu_name' => __( $plural ),
- );
- }
- return $labels;
- }
- /**
- * Midwest Dev Custom Post Types
- *
- * Creates new custom post types
- *
- * @since Midwest Dev 1.0
- * @return null
- */
- function mwd_custom_post_types() {
- // Movies (Example)
- register_post_type( 'movies',
- array(
- 'labels' => mwd_get_labels( 'Movie' ),
- 'public' => true,
- 'supports' => array( 'title', 'thumbnail', 'editor' ),
- 'menu_icon' => 'dashicons-location',
- )
- );
- }
- //add_action( 'init', 'mwd_custom_post_types' ); // Uncomment to enable custom post type creation.
- /**
- * Midwest Dev Custom Taxonomies
- *
- * Creates new taxonomies
- *
- * @since Midwest Dev 1.0
- * @return null
- */
- function mwd_custom_taxonomies() {
- $args = array(
- 'labels' => mwd_get_labels( 'Genre', false, 'taxonomy' ),
- 'hierarchical' => true, // true == Categories | false == Tags
- 'show_ui' => true, // true == Show In Admin UI | false == Hide in Admin UI
- 'show_admin_column' => true, // true == Show Column in Admin | false == Hide Column in Admin
- 'query_var' => true, //
- 'meta_box_cb' => false, // true == Show Meta Box in Admin | false == Hide Meta Box in Admin (usually added through ACF)
- 'rewrite' => array( 'slug' => 'genre' ),
- );
- register_taxonomy( 'genre', array( 'movies' ), $args );
- }
- //add_action( 'init', 'mwd_custom_taxonomies' ); // Uncomment to enable custom taxonomy creation.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement