1 | <?php |
||
10 | class Archive extends Settings |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | CONST ID = 'archives'; |
||
16 | |||
17 | public static $current; |
||
18 | |||
19 | public $hooks = []; |
||
20 | |||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | public function init() |
||
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | * @filter pollux/{static::ID}/before/instructions |
||
39 | */ |
||
40 | public function filterBeforeInstructions() |
||
41 | { |
||
42 | return sprintf( '<pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
||
43 | array_reduce( ['title', 'content', 'featured'], function( $instructions, $id ) { |
||
44 | return $instructions . $this->filterInstruction( null, ['slug' => $id], ['slug' => $this->getPostType()] ) . PHP_EOL; |
||
45 | }) |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $instruction |
||
51 | * @return string |
||
52 | * @action pollux/{static::ID}/instruction |
||
53 | */ |
||
54 | public function filterInstruction( $instruction, array $field, array $metabox ) |
||
55 | { |
||
56 | return sprintf( "ArchiveMeta::%s('%s');", $metabox['slug'], $field['slug'] ); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return array |
||
61 | * @action pollux/{static::ID}/metabox/submit |
||
62 | */ |
||
63 | public function filterSubmitMetaBox( array $args ) |
||
64 | { |
||
65 | $args[1] = __( 'Save Archive', 'pollux' ); |
||
66 | return $args; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @todo: Use gatekeeper to check capability, wp_die(-1) on fail; |
||
|
|||
71 | * @return string|null |
||
72 | * @action wp_ajax_pollux/archives/featured/html |
||
73 | */ |
||
74 | public function getFeaturedImageHtml() |
||
75 | { |
||
76 | check_ajax_referer( sprintf( '%s-options', static::id() )); |
||
77 | static::$current = filter_input( INPUT_POST, 'post_type' ); |
||
78 | ob_start(); |
||
79 | $this->renderFeaturedImageMetaBox( intval( filter_input( INPUT_POST, 'thumbnail_id' ))); |
||
80 | wp_send_json_success( ob_get_clean() ); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param string $key |
||
85 | * @param mixed $fallback |
||
86 | * @param string $group |
||
87 | * @return string|array |
||
88 | */ |
||
89 | public function getMetaValue( $key, $fallback = '', $group = '' ) |
||
90 | { |
||
91 | return ArchiveMeta::get( $key, $fallback, $group ); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return void |
||
96 | * @action current_screen |
||
97 | */ |
||
98 | public function register() |
||
99 | { |
||
100 | $screenId = ( new Helper )->getCurrentScreen()->id; |
||
101 | if( in_array( $screenId, $this->hooks )) { |
||
102 | $this->hook = $screenId; |
||
103 | } |
||
104 | parent::register(); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @return void |
||
109 | * @action pollux/archives/init |
||
110 | */ |
||
111 | public function registerFeaturedImageMetaBox() |
||
112 | { |
||
113 | if( !current_user_can( 'upload_files' ))return; |
||
114 | add_meta_box( 'postimagediv', __( 'Featured Image', 'pollux' ), [$this, 'renderFeaturedImageMetaBox'], null, 'side', 'low' ); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @return void |
||
119 | * @action admin_menu |
||
120 | */ |
||
121 | public function registerPage() |
||
122 | { |
||
123 | foreach( $this->getPostTypesWithArchive() as $type => $page ) { |
||
124 | $labels = get_post_type_labels( get_post_type_object( $type )); |
||
125 | $this->hooks[$type] = call_user_func_array( 'add_submenu_page', $this->filter( 'page', [ |
||
126 | $page, |
||
127 | sprintf( _x( '%s Archive', 'post archive', 'pollux' ), $labels->singular_name ), |
||
128 | sprintf( _x( '%s Archive', 'post archive', 'pollux' ), $labels->singular_name ), |
||
129 | 'edit_theme_options', |
||
130 | sprintf( '%s_archive', $type ), |
||
131 | [$this, 'renderPage'], |
||
132 | ])); |
||
133 | } |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @return void |
||
138 | * @action pollux/archives/editor |
||
139 | */ |
||
140 | public function renderEditor( $content, $type ) |
||
155 | |||
156 | /** |
||
157 | * @return void |
||
158 | * @callback add_meta_box |
||
159 | */ |
||
160 | public function renderFeaturedImageMetaBox( $imageId = null ) |
||
181 | |||
182 | /** |
||
183 | * @return void |
||
184 | * @callback add_submenu_page |
||
185 | */ |
||
186 | public function renderPage() |
||
200 | |||
201 | /** |
||
202 | * @return array |
||
203 | */ |
||
204 | protected function getDefaults() |
||
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | protected function getPostType() |
||
220 | |||
221 | /** |
||
222 | * @return array |
||
223 | */ |
||
224 | protected function getPostTypesWithArchive() |
||
231 | |||
232 | /** |
||
233 | * @return array |
||
234 | */ |
||
235 | protected function getSettings() |
||
239 | } |
||
240 |
This check looks
TODO
comments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.