| 1 |
<?php |
| 2 |
namespace Enteraddons\Classes; |
| 3 |
|
| 4 |
/** |
| 5 |
* Enteraddons Post Type Base class |
| 6 |
* |
| 7 |
* @package Enteraddons |
| 8 |
* @author ThemeLooks |
| 9 |
* @copyright 2022 ThemeLooks |
| 10 |
* @license GPL-2.0-or-later |
| 11 |
* |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
abstract class Post_Type_Base { |
| 16 |
|
| 17 |
abstract public function getPostTypeName(); |
| 18 |
|
| 19 |
public function getArgs() { |
| 20 |
return []; |
| 21 |
} |
| 22 |
|
| 23 |
public function getLabels() { |
| 24 |
return []; |
| 25 |
} |
| 26 |
public function addTaxonomy() { |
| 27 |
return []; |
| 28 |
} |
| 29 |
public function regPostType() { |
| 30 |
|
| 31 |
$labels = $this->getLabels(); |
| 32 |
|
| 33 |
$default = array( |
| 34 |
'labels' => $labels, |
| 35 |
'public' => true, |
| 36 |
'rewrite' => false, |
| 37 |
'show_ui' => true, |
| 38 |
'show_in_menu' => false, |
| 39 |
'show_in_nav_menus' => false, |
| 40 |
'exclude_from_search' => true, |
| 41 |
'capability_type' => 'post', |
| 42 |
'hierarchical' => false, |
| 43 |
'supports' => array( 'title', 'editor' ), |
| 44 |
); |
| 45 |
|
| 46 |
$args = wp_parse_args( $this->getArgs(), $default ); |
| 47 |
|
| 48 |
register_post_type( $this->getPostTypeName(), $args ); |
| 49 |
|
| 50 |
// Remove post type support |
| 51 |
if( !empty( $this->getremoveSupport() ) ) { |
| 52 |
foreach( $this->getremoveSupport() as $name ) { |
| 53 |
if( !empty( $name ) ) { |
| 54 |
$this->removePostTypeSupport($name); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
public function removePostTypeSupport( $name ) { |
| 62 |
remove_post_type_support( $this->getPostTypeName(), $name ); |
| 63 |
} |
| 64 |
|
| 65 |
public function registeTaxonomy() { |
| 66 |
|
| 67 |
if( $this->addTaxonomy() ) { |
| 68 |
foreach( $this->addTaxonomy() as $taxonomyinfo ) { |
| 69 |
if( !empty( $taxonomyinfo['taxonomy_name'] ) ) { |
| 70 |
register_taxonomy( $taxonomyinfo['taxonomy_name'], $this->getPostTypeName(), $taxonomyinfo['args'] ); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
function __construct() { |
| 77 |
$this->regPostType(); |
| 78 |
$this->registeTaxonomy(); |
| 79 |
} |
| 80 |
|
| 81 |
} |