Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.