1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Tabify_Edit_Screen_Settings_Base { |
4
|
|
|
private $type; |
5
|
|
|
private $sections; |
6
|
|
|
private $base_url; |
7
|
|
|
private $tabs; |
8
|
|
|
|
9
|
|
|
private $options; |
10
|
|
|
|
11
|
|
|
protected $items = array(); |
12
|
|
|
protected $defaults = array(); |
13
|
|
|
|
14
|
|
|
public function __construct( $type ) { |
15
|
|
|
$this->type = $type; |
16
|
|
|
$this->sections = $this->load_sections(); |
17
|
|
|
$this->base_url = remove_query_arg( array( 'type', 'section' ), $_SERVER["REQUEST_URI"] ); |
18
|
|
|
|
19
|
|
|
$this->tabs = new Tabify_Edit_Screen_Tabs( $this->sections, 'vertical', 'subtab' ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function load_sections() { |
23
|
|
|
return array(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function get_sections() { |
27
|
|
|
return $this->sections; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function get_sections_menu() { |
31
|
|
|
echo $this->tabs->get_tabs_with_container(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get all the metaboxes that should always be showed |
36
|
|
|
* |
37
|
|
|
* @return array All the metaboxes id's in an array |
38
|
|
|
* |
39
|
|
|
* @since 0.4.0 |
40
|
|
|
*/ |
41
|
|
|
public function get_default_items( $id ) { |
42
|
|
|
$defaults = apply_filters( 'tabify_default_metaboxes', $this->defaults, $id, $this->type ); |
43
|
|
|
$defaults = apply_filters( 'tabify_default_metaboxes_' . $this->type, $defaults, $id ); |
44
|
|
|
|
45
|
|
|
return $defaults; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Echo all the items |
50
|
|
|
* |
51
|
|
|
* @since 0.1.0 |
52
|
|
|
*/ |
53
|
|
|
public function get_sections_box() { |
54
|
|
|
$sections = $this->get_sections(); |
55
|
|
|
|
56
|
|
|
foreach ( $sections as $section => $label ) { |
57
|
|
|
$this->get_section_box( $section, $label ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
echo '<p class="submit">'; |
61
|
|
|
echo '<input type="submit" id="create_tab" name="create_tab" class="button button-secondary" value="' . __( 'Create a new tab', 'tabify-edit-screen' ) . '" />'; |
62
|
|
|
submit_button( '', 'primary', 'submit', false ); |
63
|
|
|
echo '</p>'; |
64
|
|
|
|
65
|
|
|
$this->print_backbone_template(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function get_section_box( $section, $label ) { |
|
|
|
|
69
|
|
|
$options = $this->get_options( $this->type ); |
70
|
|
|
$default_items = $this->get_default_items( $section ); |
71
|
|
|
|
72
|
|
|
if ( ! isset( $options[ $section ] ) ) { |
73
|
|
|
$options[ $section ] = array ( |
74
|
|
|
'tabs' => array( |
75
|
|
|
array( 'title' => __( 'Others', 'tabify-edit-screen' ), 'items' => array() ) |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ( $section == $this->tabs->get_current_tab() ) { |
81
|
|
|
echo '<div class="tabifybox tabifybox-' . $section . '">'; |
82
|
|
|
} |
83
|
|
|
else { |
84
|
|
|
echo '<div class="tabifybox tabifybox-hide tabifybox-' . $section . '" style="display: none;">'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$checked = ''; |
88
|
|
|
if ( isset( $options[ $section ]['show'] ) && $options[ $section ]['show'] == 1 ) { |
89
|
|
|
$checked = ' checked="checked"'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
echo '<div class="tabifybox-options">'; |
93
|
|
|
echo '<p id="show-type">'; |
94
|
|
|
_e( 'Show tabs in this post type:', 'tabify-edit-screen' ); |
95
|
|
|
echo ' <span class="switch">'; |
96
|
|
|
echo '<input type="checkbox" name="tabify[' . $this->type . '][' . $section . '][show]" value="1" class="switch-checkbox" id="switch-' . $this->type . '"' . $checked . '>'; |
97
|
|
|
echo '<label data-tg-off="' . __( 'Off', 'tabify-edit-screen' ) . '" data-tg-on="' . __( 'On', 'tabify-edit-screen' ) . '" for="switch-' . $this->type . '" class="switch-label"></label>'; |
98
|
|
|
echo '</span>'; |
99
|
|
|
echo '</p>'; |
100
|
|
|
|
101
|
|
|
do_action( 'tabify_settings', $this->type, $section, $options[ $section ] ); |
102
|
|
|
echo '</div>'; |
103
|
|
|
|
104
|
|
|
echo '<div class="tabify_control tabify_control_tabs">'; |
105
|
|
|
|
106
|
|
|
$tab_id = 0; |
107
|
|
|
$remove = false; |
108
|
|
|
|
109
|
|
|
if ( 1 < count( $options[ $section ]['tabs'] ) ) { |
110
|
|
|
$remove = true; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
foreach ( $options[ $section ]['tabs'] as $tab ) { |
114
|
|
|
$tab['id'] = $tab_id; |
115
|
|
|
|
116
|
|
|
if ( ! isset( $tab['permissions'] ) ) { |
117
|
|
|
$tab['permissions'] = array(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
if ( $tab['title'] == '' ) { |
121
|
|
|
$tab['title'] = __( 'Choose title', 'tabify-edit-screen' ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
echo '<div class="menu-item-handle tabify_tab">'; |
125
|
|
|
|
126
|
|
|
$this->get_section_tab_title( $section, $tab['title'], $tab, $remove ); |
127
|
|
|
$this->get_section_box_list( $section, $tab['items'], $tab_id, $default_items ); |
128
|
|
|
|
129
|
|
|
echo '</div>'; |
130
|
|
|
|
131
|
|
|
$tab_id++; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
echo '</div>'; |
136
|
|
|
|
137
|
|
|
echo '</div>'; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
private function get_section_tab_title( $section, $title, $tab, $remove ) { |
141
|
|
|
echo '<h2><span class="hide-if-no-js">' . $title . '</span><input type="text" name="tabify[' . $this->type . '][' . $section . '][tabs][' . $tab['id'] . '][title]" value="' . esc_html( $title ) . '" class="hide-if-js" /></h2>'; |
142
|
|
|
|
143
|
|
|
echo '<div class="tabify-title-box">'; |
144
|
|
|
do_action( 'tabify_settings_tab_title_box', $tab, $section, $this->type ); |
145
|
|
|
|
146
|
|
|
echo '<a href="#" class="tabify-remove-tab hide-if-no-js"'; |
147
|
|
|
if ( ! $remove ) { |
148
|
|
|
echo ' style="display: none;"'; |
149
|
|
|
} |
150
|
|
|
echo '>' . __( 'Remove', 'tabify-edit-screen' ) . '</a>'; |
151
|
|
|
echo '</div>'; |
152
|
|
|
|
153
|
|
|
echo '<div class="clear"></div>'; |
154
|
|
|
do_action( 'tabify_settings_tab_title_after', $tab, $section, $this->type ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
private function get_section_box_list( $section, $items, $tab_id, $default_items ) { |
158
|
|
|
$options = $this->get_options( $this->type ); |
159
|
|
|
|
160
|
|
|
echo '<ul>'; |
161
|
|
|
if ( isset( $items ) ) { |
162
|
|
|
foreach ( $items as $item_id ) { |
163
|
|
|
if ( empty( $item_id ) ) { |
164
|
|
|
continue; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$item_title = ''; |
168
|
|
|
if ( isset( $this->items[ $section ][ $item_id ] ) ) { |
169
|
|
|
$item_title = $this->items[ $section ][ $item_id ]; |
170
|
|
|
|
171
|
|
|
$item_title = apply_filters( 'tabify_items_title', $item_title, $item_id ); |
172
|
|
|
$item_title = apply_filters( 'tabify_items_title_' . $item_id , $item_title ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$this->list_show_items( $item_id, $item_title, $tab_id, $section, $default_items ); |
176
|
|
|
|
177
|
|
|
unset( $this->items[ $section ][ $item_id ] ); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
if ( count( $options[ $section ]['tabs'] ) == ( $tab_id + 1 ) ) { |
182
|
|
|
foreach ( $this->items[ $section ] as $item_id => $item_title ) { |
183
|
|
|
if ( empty( $item_id ) ) { |
184
|
|
|
continue; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
$item_title = apply_filters( 'tabify_items_title', $item_title, $item_id ); |
188
|
|
|
$item_title = apply_filters( 'tabify_items_title_' . $item_id , $item_title ); |
189
|
|
|
|
190
|
|
|
$this->list_show_items( $item_id, $item_title, $tab_id, $section, $default_items ); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
echo '</ul>'; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Show the items for the sortable list |
199
|
|
|
* |
200
|
|
|
* @since 0.4.0 |
201
|
|
|
*/ |
202
|
|
|
protected function list_show_items( $item_id, $item_title, $tab_id, $type, $default_items ) { |
203
|
|
|
$options = $this->get_options( $this->type ); |
204
|
|
|
|
205
|
|
|
// Most likely a meta box that doesn't exist anymore |
206
|
|
|
if ( empty( $item_title ) ) { |
207
|
|
|
return; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
$item_title = strip_tags( $item_title ); |
211
|
|
|
|
212
|
|
|
if ( in_array( $item_id, $default_items ) ) { |
213
|
|
|
echo '<li id="' . $type . '-' . $item_id . '" class="tabifybox-hide">'; |
214
|
|
|
} |
215
|
|
|
else { |
216
|
|
|
echo '<li id="' . $type . '-' . $item_id . '">'; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
echo '<div class="menu-item-bar"><div class="menu-item-handle">'; |
220
|
|
|
echo '<span class="item-title">' . $item_title . '</span>'; |
221
|
|
|
|
222
|
|
|
echo '<input type="hidden" name="tabify[' . $this->type . '][' . $type . '][tabs][' . $tab_id . '][items][]" value="' . $item_id . '" />'; |
223
|
|
|
|
224
|
|
|
echo '<span class="item-order hide-if-js">'; |
225
|
|
|
echo '<select name="tabify[' . $this->type . '][' . $type . '][tabs][' . $tab_id . '][items_tab][]">'; |
226
|
|
|
|
227
|
|
|
if ( isset( $options[ $type ] ) ) { |
228
|
|
|
$amount_tabs = count( $options[ $type ]['tabs'] ); |
229
|
|
|
|
230
|
|
|
for( $i = 0; $i < $amount_tabs; $i++ ) { |
231
|
|
|
if ( ! isset( $options[ $type ]['tabs'][ $i ] ) ) { |
232
|
|
|
continue; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
if ( $i == $tab_id ) { |
236
|
|
|
echo '<option value="' . $i . '" selected="selected">' . esc_html( $options[ $type ]['tabs'][ $i ]['title'] ) . '</option>'; |
237
|
|
|
} |
238
|
|
|
else { |
239
|
|
|
echo '<option value="' . $i . '">' . esc_html( $options[ $type ]['tabs'][ $i ]['title'] ) . '</option>'; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
echo '</select>'; |
245
|
|
|
echo '</span>'; |
246
|
|
|
echo '</div></div></li>'; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
private function print_backbone_template() { |
251
|
|
|
$tab = array( |
252
|
|
|
'id' => '{{ data.tab_id }}', |
253
|
|
|
'permissions' => array() |
254
|
|
|
); |
255
|
|
|
|
256
|
|
|
echo '<script type="text/template" id="tmpl-new-tab">'; |
257
|
|
|
echo '<div class="menu-item-handle tabify_tab">'; |
258
|
|
|
$this->get_section_tab_title( '{{ data.section }}', __( 'Choose title', 'tabify-edit-screen' ), $tab, true ); |
259
|
|
|
echo '<ul></ul>'; |
260
|
|
|
echo '</div>'; |
261
|
|
|
|
262
|
|
|
echo '</script>'; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
protected function get_options( $type = null ) { |
266
|
|
|
if ( ! $this->options ) { |
267
|
|
|
$this->options = get_option( 'tabify-edit-screen', array() ); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
if ( $type && isset( $this->options[ $type ] ) ) { |
271
|
|
|
return $this->options[ $type ]; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
return $this->options; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
} |
278
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.