Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created February 26, 2015 18:32
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thefuxia/270cc7f7cde8f4529bb8 to your computer and use it in GitHub Desktop.
T5 Test Types
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Test Types
* Description: Adds some custom post types and taxonomies for testing purposes.
* Plugin URI:
* Version: 2013.04.12
* Author: Thomas Scholz
* Author URI: http://toscho.de
* Licence: MIT
* License URI: http://opensource.org/licenses/MIT
*/
$T5_Test_Types = new T5_Test_Types;
add_action( 'init', array( $T5_Test_Types, 'plugin_setup' ) );
class T5_Test_Types
{
public function plugin_setup()
{
$post_types = array ( 'project', 'organization', 'place' );
$taxonomies = array ( 'topic', 'type', 'collection' );
foreach ( $post_types as $post_type )
register_post_type( $post_type, $this->cpt_args( $post_type ) );
foreach ( $taxonomies as $taxonomy )
register_taxonomy( $taxonomy, $post_types, $this->tax_args( $taxonomy ) );
}
protected function cpt_args( $post_type )
{
$u = ucfirst( $post_type );
$l = mb_strtolower( $post_type );
return array (
'can_export' => TRUE,
//'capabilities' => $this->get_capabilities(),
//'capability_type' => 'post',
//'capability_type' => 'session',
'description' => '',
'exclude_from_search' => FALSE,
'has_archive' => TRUE,
'hierarchical' => FALSE,
'labels' => array (
'add_new' => 'Add new',
'add_new_item' => "Add new $l",
'all_items' => "All {$l}s",
'edit_item' => "Edit $l",
'name' => $u . 's',
'name_admin_bar' => $u,
'new_item' => "New $l",
'not_found' => "No {$l}s found.",
'not_found_in_trash' => "No {$l}s in trash.",
'parent_item_colon' => "Parent $l:",
'search_items' => "Search {$l}s",
'singular_name' => $u,
'view_item' => "View $l"
),
//'map_meta_cap' => TRUE,
'menu_icon' => null,
'menu_position' => null,
'permalink_epmask' => EP_PERMALINK,
'public' => TRUE,
'publicly_queryable' => TRUE,
'query_var' => $l,
// Use a translated slug in pretty permalinks
'rewrite' => array (
'slug' => $l,
'with_front' => FALSE
),
'show_in_nav_menus' => TRUE,
'show_in_menu' => TRUE,
'show_in_admin_bar' => TRUE,
'show_ui' => TRUE,
/* 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author',
* 'excerpt', 'page-attributes', 'thumbnail' or 'custom-fields' */
'supports' => array(
'author',
'comments',
'editor',
'excerpt',
'revisions',
'thumbnail',
'title',
),
);
}
protected function tax_args( $taxonomy )
{
$u = ucfirst( $taxonomy );
$l = mb_strtolower( $taxonomy );
return array(
'hierarchical' => TRUE,
'public' => TRUE,
'query_var' => $taxonomy,
'rewrite' => TRUE,
'labels' => array(
'name' => $u . 's',
'singular_name' => $u,
'search_items' => "Search {$l}s",
'popular_items' => "Popular {$l}s",
'all_items' => "All {$l}s",
'parent_item' => "Parent {$l}",
'parent_item_colon' => "Parent {$l}:",
'edit_item' => "Edit $l",
'view_item' => "View $l",
'update_item' => "Update $l",
'add_new_item' => "Add new $l",
'new_item_name' => "New $l name",
'separate_items_with_commas' => "Separate {$l}s with commas",
'add_or_remove_items' => "Add or remove {$l}s",
'choose_from_most_used' => "Choose from the most used {$l}s",
),
'show_admin_column' => TRUE,
'show_in_nav_menus' => TRUE,
'show_tagcloud' => FALSE,
'show_ui' => TRUE,
'update_count_callback' => '',
);
}
}
@lkraav
Copy link

lkraav commented Mar 9, 2015

Why go against the grain here and lowercase "edit_item" etc? Core shows "Edit Post", not "Edit post".

@lkraav
Copy link

lkraav commented Apr 7, 2015

I'd recommend ucwords() instead of ucfirst(), to handle multi-word post types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment