-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclass-base.php
More file actions
92 lines (76 loc) · 1.57 KB
/
class-base.php
File metadata and controls
92 lines (76 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Base class to register taxonomy.
*
* @package osi-features
*/
namespace Osi\Features\Inc\Taxonomies;
use Osi\Features\Inc\Traits\Singleton;
/**
* Class Base
*/
abstract class Base {
use Singleton;
/**
* Base constructor.
*/
protected function __construct() {
$this->setup_hooks();
}
/**
* To setup action/filter.
*
* @return void
*/
protected function setup_hooks() {
add_action( 'init', array( $this, 'register_taxonomy' ) );
}
/**
* Register taxonomy.
*
* @return void
*/
public function register_taxonomy() {
if ( empty( static::SLUG ) ) {
return;
}
$post_types = $this->get_post_types();
if ( empty( $post_types ) || ! is_array( $post_types ) ) {
return;
}
$args = $this->get_args();
$args = ( ! empty( $args ) && is_array( $args ) ) ? $args : array();
$labels = $this->get_labels();
$labels = ( ! empty( $labels ) && is_array( $labels ) ) ? $labels : array();
if ( ! empty( $labels ) && is_array( $labels ) ) {
$args['labels'] = $labels;
}
register_taxonomy( static::SLUG, $post_types, $args );
}
/**
* To get argument to register taxonomy.
*
* @return array
*/
public function get_args() {
return array(
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_rest' => true,
);
}
/**
* Labels for taxonomy.
*
* @return array
*/
abstract public function get_labels();
/**
* List of post types for taxonomy.
*
* @return array
*/
abstract public function get_post_types();
}