public
anonymous / b_affiliates_cpt.php
Created

CPT Registration, not working

  • Download Gist
b_affiliates_cpt.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
<?php
 
define('BAPT_CPT', 'b_affiliate');
define('BAPT_CTAX', 'b_aff_categories');
 
class B_Affiliate_Post_Type {
function initialize(){
add_action( 'init', array($this, '_init') );
}
 
function _init(){
if(is_admin()){
$this->_register_cpt();
$this->_register_taxonomy();
}
}
 
 
function _register_cpt(){
$labels = array(
'name' => _x( 'Affiliates', BAPT_CPT ),
'singular_name' => _x( 'Affiliate', BAPT_CPT ),
'add_new' => _x( 'Add New', BAPT_CPT ),
'add_new_item' => _x( 'Add New Affiliate', BAPT_CPT ),
'edit_item' => _x( 'Edit Affiliate', BAPT_CPT ),
'new_item' => _x( 'New Affiliate', BAPT_CPT ),
'view_item' => _x( 'View Affiliate', BAPT_CPT ),
'search_items' => _x( 'Search Affiliates', BAPT_CPT ),
'not_found' => _x( 'No affiliates found', BAPT_CPT ),
'not_found_in_trash' => _x( 'No affiliates found in Trash', BAPT_CPT ),
'parent_item_colon' => _x( 'Parent Affiliate:', BAPT_CPT ),
'menu_name' => _x( 'Affiliates', BAPT_CPT ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'Affiliate Custom Post Type',
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'taxonomies' => array( BAPT_CTAX ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'can_export' => true,
'rewrite' => array('slug' => 'listing', 'with_front' => false),
'capability_type' => 'post'
);
register_post_type( BAPT_CPT, $args );
}
function _register_taxonomy(){
$labels = array(
'name' => _x( 'Affiliate Categories', BAPT_CTAX ),
'singular_name' => _x( 'Affiliate Category', BAPT_CTAX ),
'search_items' => _x( 'Search Affiliate Categories', BAPT_CTAX ),
'popular_items' => _x( 'Popular Affiliate Categories', BAPT_CTAX ),
'all_items' => _x( 'All Affiliate Categories', BAPT_CTAX ),
'parent_item' => _x( 'Parent Affiliate Category', BAPT_CTAX ),
'parent_item_colon' => _x( 'Parent Affiliate Category:', BAPT_CTAX ),
'edit_item' => _x( 'Edit Affiliate Category', BAPT_CTAX ),
'update_item' => _x( 'Update Affiliate Category', BAPT_CTAX ),
'add_new_item' => _x( 'Add New Affiliate Category', BAPT_CTAX ),
'new_item_name' => _x( 'New Affiliate Category', BAPT_CTAX ),
'separate_items_with_commas' => _x( 'Separate affiliate categories with commas', BAPT_CTAX ),
'add_or_remove_items' => _x( 'Add or remove affiliate categories', BAPT_CTAX ),
'choose_from_most_used' => _x( 'Choose from the most used affiliate categories', BAPT_CTAX ),
'menu_name' => _x( 'Affiliate Categories', BAPT_CTAX ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array(
'slug' => 'listing-categories',
'with_front' => false,
'hierarchical' => true
),
'query_var' => true
);
register_taxonomy( BAPT_CTAX, array(BAPT_CPT), $args );
}
}
 
$bapt_plugin = new B_Affiliate_Post_Type();
$bapt_plugin->initialize();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.