Skip to content

Instantly share code, notes, and snippets.

@jonathanjanssens
Created March 13, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanjanssens/7ca3196bd5ca1e943281 to your computer and use it in GitHub Desktop.
Save jonathanjanssens/7ca3196bd5ca1e943281 to your computer and use it in GitHub Desktop.
<?php
class BasePostType {
protected $defaultArgs = array(
'public' => true,
'supports' => array(
'title', 'editor', 'thumbnail'
),
'has_archive' => true
);
function __construct()
{
global $wpdb;
$this->wpdb = $wpdb;
$defaultArgs = array_filter($this->defaultArgs);
$this->parsedArgs = wp_parse_args( $this->args, $defaultArgs );
add_action( 'init', array( $this, 'register' ) );
}
function register()
{
register_post_type( $this->name, $this->parsedArgs );
}
}
<?php
class ExamplePostType extends BasePostType
{
protected $name = 'example';
protected $args = array(
'label' => 'Example',
'rewrite' => array( 'slug' => 'example' ),
'supports' => array( 'title', 'thumbnail' ),
'menu_icon' => 'dashicons-images-alt',
'taxonomies' => array('category'),
);
public function __construct()
{
parent::__construct();
}
}
$example = new Example();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment