1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\Pollux\PostType; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\Pollux\Application; |
6
|
|
|
use GeminiLabs\Pollux\Facades\ArchiveMeta; |
7
|
|
|
use GeminiLabs\Pollux\Helper; |
8
|
|
|
use GeminiLabs\Pollux\Settings\Settings; |
9
|
|
|
|
10
|
|
|
class Archive extends Settings |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
CONST ID = 'archives'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
public function init() |
21
|
|
|
{ |
22
|
|
|
parent::init(); |
23
|
|
|
|
24
|
|
|
add_action( 'pollux/archives/saved', [$this, 'addCustomNoticeOnSave'] ); |
25
|
|
|
add_action( 'pollux/archives/editor', [$this, 'renderEditor'] ); |
26
|
|
|
add_filter( 'pollux/archives/metabox/submit', [$this, 'filterSubmitMetaBox'] ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return void |
31
|
|
|
* @action pollux/archives/saved |
32
|
|
|
*/ |
33
|
|
|
public function addCustomNoticeOnSave() |
34
|
|
|
{ |
35
|
|
|
add_settings_error( static::id(), 'updated', __( 'Archive Page saved.', 'pollux' ), 'updated' ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return void |
40
|
|
|
* @action admin_menu |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
public function addPage() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
// post => edit.php |
45
|
|
|
// page|cpt => edit.php?post_type=%s |
46
|
|
|
$this->hook = call_user_func_array( 'add_submenu_page', $this->filter( 'page', [ |
47
|
|
|
'edit.php', |
48
|
|
|
sprintf( __( '%s Archive', 'pollux' ), 'Post' ), |
49
|
|
|
__( 'Archive', 'pollux' ), |
50
|
|
|
'edit_theme_options', |
51
|
|
|
static::id(), |
52
|
|
|
[$this, 'renderPage'], |
53
|
|
|
])); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $instruction |
58
|
|
|
* @param string $fieldId |
59
|
|
|
* @param string $metaboxId |
60
|
|
|
* @return string |
61
|
|
|
* @action pollux/{static::ID}/instruction |
62
|
|
|
*/ |
63
|
|
|
public function filterInstruction( $instruction, $fieldId, $metaboxId ) |
64
|
|
|
{ |
65
|
|
|
return sprintf( "ArchiveMeta::get('%s', '%s');", $metaboxId, $fieldId ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
* @action pollux/{static::ID}/metabox/submit |
71
|
|
|
*/ |
72
|
|
|
public function filterSubmitMetaBox( array $args ) |
73
|
|
|
{ |
74
|
|
|
$args[1] = __( 'Save Archive', 'pollux' ); |
75
|
|
|
return $args; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return void |
80
|
|
|
* @action pollux/archives/editor |
81
|
|
|
*/ |
82
|
|
|
public function renderEditor( $content ) |
83
|
|
|
{ |
84
|
|
|
wp_editor( $content, 'content', [ |
85
|
|
|
'_content_editor_dfw' => true, |
86
|
|
|
'drag_drop_upload' => true, |
87
|
|
|
'tabfocus_elements' => 'content-html, publishing-action', |
88
|
|
|
'editor_height' => 300, |
89
|
|
|
'tinymce' => [ |
90
|
|
|
'resize' => false, |
91
|
|
|
'wp_autoresize_on' => true, |
92
|
|
|
'add_unload_trigger' => false, |
93
|
|
|
], |
94
|
|
|
]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return void |
99
|
|
|
* @callback add_menu_page |
100
|
|
|
*/ |
101
|
|
|
public function renderPage() |
102
|
|
|
{ |
103
|
|
|
$this->render( 'archive/index', [ |
104
|
|
|
'columns' => get_current_screen()->get_columns(), |
105
|
|
|
'content' => ArchiveMeta::get( 'content' ), |
106
|
|
|
'heading' => sprintf( __( '%s Archive', 'pollux' ), 'Post' ), |
107
|
|
|
'id' => static::id(), |
108
|
|
|
'title' => ArchiveMeta::get( 'title' ), |
109
|
|
|
]); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
protected function getDefaults() |
116
|
|
|
{ |
117
|
|
|
return []; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return string|array |
122
|
|
|
*/ |
123
|
|
|
protected function getValue( $key, $group ) |
124
|
|
|
{ |
125
|
|
|
return ArchiveMeta::get( $key, false ); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.