-
-
Save jonathanjanssens/7ca3196bd5ca1e943281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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