Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeluno/a2b95a1d20566d92d729 to your computer and use it in GitHub Desktop.
Save michaeluno/a2b95a1d20566d92d729 to your computer and use it in GitHub Desktop.
Demonstrates how to create a custom post type and a custom taxonomy which belongs to it with Admin Page Framework. This is a sample plugin introduced in the tutorial Create a Custom Post Type and Custom Taxonomy (http://en.michaeluno.jp/admin-page-framework/tutorials-v3/12-create-a-custom-post-type-and-custom-taxonomy/).
<?php
/**
* Plugin Name: Admin Page Framework Tutorial 12 - Create a Custom Post Type and Custom Taxonomy
* Plugin URI: http://en.michaeluno.jp/admin-page-framework
* Description: Creates a custom post type and a custom taxonomy that belongs to it.
* Author: Michael Uno
* Author URI: http://michaeluno.jp
* Version: 1.0.1
* Requirements: PHP 5.2.4 or above, WordPress 3.4 or above. Admin Page Framework 3.0.6 or above
*/
// Include the library file. Set your file path here.
include( dirname( dirname( __FILE__ ) ) . '/library/apf/admin-page-framework.php' );
class APF_Tutorial_ExamplePostType extends AdminPageFramework_PostType {
/**
* Automatically called with the 'wp_loaded' hook.
*/
public function setUp() {
$this->setArguments(
array( // argument - for the array structure, refer to http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
'labels' => array(
'name' => 'Tutorial Example',
'add_new_item' => __( 'Example Post', 'admin-page-framework-tutorial' ),
'plugin_action_link' => __( 'Tutorial Example Custom Post Type', 'admin-page-framework-tutorial' ), // (framework specific key). [3.0.6+]
),
'supports' => array( 'title', 'editor' ), // e.g. array( 'title', 'editor', 'comments', 'thumbnail', 'excerpt' ),
'public' => true,
'menu_icon' => version_compare( $GLOBALS['wp_version'], '3.8', '>=' )
? 'dashicons-wordpress'
: plugins_url( 'asset/image/wp-logo_16x16.png', APFDEMO_FILE ),
// (framework specific key) this sets the screen icon for the post type for WordPress v3.7.1 or below.
'screen_icon' => dirname( APFDEMO_FILE ) . '/asset/image/wp-logo_32x32.png', // a file path can be passed instead of a url, plugins_url( 'asset/image/wp-logo_32x32.png', APFDEMO_FILE )
)
);
$this->addTaxonomy(
'apf_tutorial_example_taxonomy', // taxonomy slug
array( // argument - for the argument array keys, refer to : http://codex.wordpress.org/Function_Reference/register_taxonomy#Arguments
'labels' => array(
'name' => __( 'Tutorial Taxonomy', 'admin-page-framework-tutorial' ),
'add_new_item' => __( 'Add New Taxonomy', 'admin-page-framework-tutorial' ),
'new_item_name' => __( 'New Taxonomy', 'admin-page-framework-tutorial' )
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_table_filter' => true, // framework specific key
'show_in_sidebar_menus' => true, // framework specific key
)
);
}
}
new APF_Tutorial_ExamplePostType( 'my_apf_post_type' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment