Skip to content

Instantly share code, notes, and snippets.

@technosailor
Created February 11, 2013 17:37
Show Gist options
  • Save technosailor/4756021 to your computer and use it in GitHub Desktop.
Save technosailor/4756021 to your computer and use it in GitHub Desktop.
CPT
<?php
class Example_Plugin_Class {
public function __construct()
{
$this->hooks();
}
protected function hooks()
{
add_action( 'init', array( $this, 'hooks' ) );
}
protected function cpt()
{
register_post_type( 'reviews', array(
'label' => 'Reviews',
'labels' => array(
'name' => 'Reviews',
'singular_name' => 'Review',
'add_new_item' => 'Add New Review',
'edit_item' => 'Edit Review',
'new_item' => 'New Review',
'view_item' => 'View Review',
'search_items' => 'Search Reviews',
),
'description' => 'User-generated reviews',
'public' => true,
'show_in_nav_menus' => false,
'show_in_menu' => true,
'show_in_admin_bar' => false,
'supports' => array(
'title',
'editor',
'author',
'excerpt',
'custom-fields',
'comments'
),
'menu_icon' => get_option('siteurl') . '/wp-content/plugins/example-plugin/images/reviews-icon.png',
)
);
}
}
new Example_Plugin_Class;
@brandondove
Copy link

Maybe it's just me, but this function seems like it's slated for disaster:

protected function hooks()
{
    add_action( 'init', array( $this, 'hooks' ) );
}

Should probably be this:

protected function hooks()
{
    add_action( 'init', array( $this, 'cpt' ) );
}

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