1: <?php
2:
3: 4: 5: 6:
7: class Papi_Page_Type_Meta extends Papi_Core_Type {
8:
9: 10: 11: 12: 13:
14: public $_meta_method = 'page_type';
15:
16: 17: 18: 19: 20:
21: public $capabilities = [];
22:
23: 24: 25: 26: 27:
28: public $child_types = [];
29:
30: 31: 32: 33: 34:
35: public $description = '';
36:
37: 38: 39: 40: 41:
42: public $fill_labels = false;
43:
44: 45: 46: 47: 48:
49: public $labels = [];
50:
51: 52: 53: 54: 55:
56: public $name = '';
57:
58: 59: 60: 61: 62:
63: public $post_type = ['page'];
64:
65: 66: 67: 68: 69:
70: public $sort_order = null;
71:
72: 73: 74: 75: 76:
77: public $standard_type = false;
78:
79: 80: 81: 82: 83:
84: public $template = '';
85:
86: 87: 88: 89: 90:
91: public $thumbnail = '';
92:
93: 94: 95: 96: 97: 98: 99:
100: public function __construct( $file_path = '' ) {
101: parent::__construct( $file_path );
102: $this->setup_page_type();
103: $this->setup_post_types();
104: }
105:
106: 107: 108: 109: 110:
111: public function current_user_is_allowed() {
112: foreach ( $this->capabilities as $capability ) {
113: if ( ! current_user_can( $capability ) ) {
114: return false;
115: }
116: }
117:
118: return true;
119: }
120:
121: 122: 123: 124: 125:
126: public function get_child_types() {
127: $child_types = [];
128:
129: foreach ( papi_to_array( $this->child_types ) as $id ) {
130: $child_type = papi_get_page_type_by_id( $id );
131:
132: if ( papi_is_page_type( $child_type ) ) {
133: $child_types[] = $child_type;
134: }
135: }
136:
137: return $child_types;
138: }
139:
140: 141: 142: 143: 144: 145:
146: public function get_labels() {
147: if ( ! $this->fill_labels ) {
148: return $this->labels;
149: }
150:
151: return array_merge( $this->labels, [
152: 'add_new_item' => sprintf(
153: '%s %s',
154: __( 'Add New', 'papi' ),
155: $this->name
156: ),
157: 'edit_item' => sprintf(
158: '%s %s',
159: __( 'Edit', 'papi' ),
160: $this->name
161: ),
162: 'view_item' => sprintf(
163: '%s %s',
164: __( 'View', 'papi' ),
165: $this->name
166: )
167: ] );
168: }
169:
170: 171: 172: 173: 174:
175: public function get_thumbnail() {
176: if ( empty( $this->thumbnail ) ) {
177: return '';
178: }
179:
180: return $this->thumbnail;
181: }
182:
183: 184: 185: 186: 187:
188: public function has_name() {
189: return ! empty( $this->name );
190: }
191:
192: 193: 194: 195: 196: 197: 198:
199: public function has_post_type( $post_type ) {
200: return in_array( $post_type, $this->post_type );
201: }
202:
203: 204: 205:
206: private function setup_page_type() {
207: if ( is_null( $this->sort_order ) ) {
208: $this->sort_order = papi_filter_settings_sort_order();
209: }
210: }
211:
212: 213: 214:
215: private function setup_post_types() {
216: $this->post_type = papi_to_array( $this->post_type );
217:
218:
219:
220: if ( empty( $this->post_type ) ) {
221: $this->post_type = ['page'];
222: }
223: }
224: }
225: