This repository has been archived by the owner on Feb 7, 2021. It is now read-only.
/
archive-options.php
executable file
·348 lines (328 loc) · 13.7 KB
/
archive-options.php
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
/**
* Twenty'em WordPress Framework.
*
* WARNING: This file is part of Twenty'em WordPress Framework.
* DO NOT edit this file under any circumstances. Do all your modifications in the form of a child theme.
*
* @package WordPress
* @subpackage Twenty'em
* @author RogerTM
* @license license.txt
* @link https://themingisprose.com/twenty-em
* @since Twenty'em 1.0
*/
/**
* Twenty'em Archive theme options.
*/
/**
* Return an array of Archive Options for Twenty'em admin panel.
* This function manage what and how is displayed in our theme archive. Possibles options are:
* 0. Display the whole posts content (the-content).
* 1. Display the posts excerpt (the-excerpt), here we call t_em_excerpt_callback() function which
* display several sub-options.
*
* @return array
*
* @since Twenty'em 1.0
*/
function t_em_archive_options( $archive_options = '' ){
$archive_options = array(
/**
* Filter the callback function
*
* @param bool If false, the option will not be enable. Default true
* @since Twenty'em 1.0
*/
'the-content' => array(
'value' => 'the-content',
'label' => __( 'Display the content', 't_em' ),
'callback' => apply_filters( 't_em_admin_filter_archive_options_the_content', true ) ? __( '<p>The whole content of each post</p>', 't_em' ) : null,
),
'the-excerpt' => array(
'value' => 'the-excerpt',
'label' => __( 'Display the excerpt', 't_em' ),
'callback' => apply_filters( 't_em_admin_filter_archive_options_the_excerpt', true ) ? t_em_excerpt_callback() : null,
),
);
/**
* Filter the Archive Options
*
* @param array An array of new options in the Archive Options Set.
* Keyed by a string id. The ids point to arrays containing 'value', 'label', and 'callback' keys.
* @since Twenty'em 1.0
*/
return apply_filters( 't_em_admin_filter_archive_options', $archive_options );
}
/**
* Returns an array of our archive excerpt options.
*/
function t_em_excerpt_options( $excerpt_options = '' ){
$excerpt_options = array(
'thumbnail-left' => array(
'value' => 'thumbnail-left',
'label' => __( 'Thumbnail on left', 't_em' ),
'thumbnail' => T_EM_ENGINE_DIR_IMG_URL . '/template-thumbnail-left.png',
),
'thumbnail-right' => array(
'value' => 'thumbnail-right',
'label' => __( 'Thumbnail on right', 't_em' ),
'thumbnail' => T_EM_ENGINE_DIR_IMG_URL . '/template-thumbnail-right.png',
),
'thumbnail-center' => array(
'value' => 'thumbnail-center',
'label' => __( 'Thumbnail on center', 't_em' ),
'thumbnail' => T_EM_ENGINE_DIR_IMG_URL . '/template-thumbnail-center.png',
),
);
/**
* Filter the thumbnail options in Archive Options Set.
*
* @param array Array of new options.
* Keyed by a string id. The ids point to arrays containing 'value', 'label', and 'thumbnail' keys.
* @since Twenty'em 1.0
*/
return apply_filters( 't_em_admin_filter_excerpt_options', $excerpt_options );
}
/**
* Returns an array of our archive columns options.
*/
function t_em_archive_in_columns( $archive_in_columns = '' ){
$archive_in_columns = array(
'1' => array(
'value' => 1,
'label' => __( 'One column', 't_em' ),
),
'2' => array(
'value' => 2,
'label' => __( 'Two columns', 't_em' ),
),
'3' => array(
'value' => 3,
'label' => __( 'Three columns', 't_em' ),
),
);
/**
* Filter the Archive in Columns option in Archive Options Set
*
* @param array An array of new options
* Keyed by a string id. The ids point to arrays containing 'value' and 'label' keys.
* @since Twenty'em 1.0
*/
return apply_filters( 't_em_admin_filter_archive_in_columns', $archive_in_columns );
}
/**
* Render Width and Height text boxes for thumbnails in forms
*
* @param string $contex Require In which form ($contex) you want to use this function.
* Example: You have a new slider plugin, and you want set Width and Height for yours thumbnail in
* slideshow. So, you may call this function like this: $thumb = t_em_thumbnail_sizes( 'slideshow' );
* See t_em_excerpt_callback() in /engine/archive-options.php file
*
* @return array
*
* @since Twenty'em 1.0
*/
function t_em_thumbnail_sizes( $contex ){
$thumbnail_sizes = array(
'excerpt_thumbnail_width' => array(
'value' => '',
'name' => $contex . '_thumbnail_width',
'label' => __( 'Width', 't_em' ),
),
'excerpt_thumbnail_height' => array(
'value' => '',
'name' => $contex . '_thumbnail_height',
'label' => __( 'Height', 't_em' ),
),
);
return $thumbnail_sizes;
}
/**
* Extend setting for Archive Option in Twenty'em admin panel.
* Referenced via t_em_archive_options() in /engine/archive-options.php.
*
* @since Twenty'em 1.0
*/
function t_em_excerpt_callback(){
$extend_excerpt = '';
$extend_excerpt .= '<div class="sub-extend option-group">';
$extend_excerpt .= '<header>'. __( 'Excerpt Length', 't_em' ) .'</header>';
$extend_excerpt .= '<div class="layout text-option excerpt-length">';
$extend_excerpt .= '<label>';
$extend_excerpt .= '<p>'. sprintf( __( 'The amount of words displayed in the excerpt. If empty, the default value will be <code>%1$s</code> words.', 't_em' ), '55' ) .'</p>';
$extend_excerpt .= '<input type="number" name="t_em_theme_options[excerpt_length]" value="'. t_em( 'excerpt_length' ) .'" />';
$extend_excerpt .= '</label>';
$extend_excerpt .= '</div>';
$extend_excerpt .= '</div>';
$extend_excerpt .= '<div class="sub-extend option-group">';
$extend_excerpt .= '<header>'. __( 'Thumbnail Alignment', 't_em' ) .'</header>';
$extend_excerpt .= '<div class="image-radio-option-group">';
foreach ( t_em_excerpt_options() as $excerpt ) :
$active_option = ( t_em( 'excerpt_set' ) == $excerpt['value'] ) ? 'radio-image radio-image-active' : 'radio-image';
$extend_excerpt .= '<div class="layout theme-excerpt '. $active_option .'">';
$extend_excerpt .= '<label class="description">';
$extend_excerpt .= '<input class="input-image-radio-option" type="radio" name="t_em_theme_options[excerpt_set]" value="'.esc_attr( $excerpt['value'] ).'" '. checked( t_em( 'excerpt_set' ), $excerpt['value'], false ) .' />';
$extend_excerpt .= '<span><img src="'.esc_url( $excerpt['thumbnail'] ).'" width="200" /><p>'.$excerpt['label'].'</p></span>';
$extend_excerpt .= '</label>';
$extend_excerpt .= '</div>';
endforeach;
$extend_excerpt .= '</div>';
$extend_excerpt .= '</div>';
$extend_excerpt .= '<div class="sub-extend option-group">';
$thumb = t_em_thumbnail_sizes( 'excerpt' );
$extend_excerpt .= '<header>'. __( 'Thumbnail Dimensions', 't_em' ) .'</header>';
$extend_excerpt .= '<p>'. sprintf( __( 'Set thumbnail <strong>width</strong> and <strong>height</strong> in pixels. If empty, will be used the default thumbnail sizes (<code>%2$s</code> x <code>%3$s</code>) set at your <a href="%1$s" target="_blank">Media Settings</a> options.', 't_em' ),
admin_url( 'options-media.php' ),
get_option( 'thumbnail_size_w' ),
get_option( 'thumbnail_size_h' ) ) .'</p>';
foreach ( $thumb as $thumbnail ) :
$extend_excerpt .= '<div class="layout text-option thumbnail option-single">';
$extend_excerpt .= '<label><span>'. $thumbnail['label'] .'</span>';
$extend_excerpt .= '<input type="number" name="t_em_theme_options['.$thumbnail['name'].']" value="'.esc_attr( t_em ( $thumbnail['name'] ) ).'" /><span class="unit">px</span>';
$extend_excerpt .= '</label>';
$extend_excerpt .= '</div>';
endforeach;
$extend_excerpt .= '</div><!-- .sub-extend -->';
$extend_excerpt .= '<div class="sub-extend option-group">';
$extend_excerpt .= '<header>'. __( 'Thumbnail column width', 't_em' ) .'</header>';
$extend_excerpt .= '<p>'. __( 'Should be a number between <code>2</code> and <code>6</code>. Default to <code>3</code>.', 't_em' ) .'</p>';
$extend_excerpt .= '<input type="number" name="t_em_theme_options[excerpt_thumbnail_columns]" value="'. t_em( 'excerpt_thumbnail_columns' ) .'" min="2" max="6">';
$extend_excerpt .= '</div><!-- .sub-extend -->';
$extend_excerpt .= '<div class="sub-extend layout text-radio-option-group option-group">';
$extend_excerpt .= '<header>'. __( 'Columns', 't_em' ) .'</header>';
$extend_excerpt .= '<p>'. __( 'Break Loop in columns (It may affect the thumbnail size)', 't_em' ) .'</p>';
foreach ( t_em_archive_in_columns() as $columns ) :
$checked_option = checked( t_em( 'archive_in_columns' ), $columns['value'], false );
$extend_excerpt .= '<div class="layout text-radio-option-group archive-in-columns option-single">';
$extend_excerpt .= '<label class="description">';
$extend_excerpt .= '<input type="radio" name="t_em_theme_options[archive_in_columns]" value="'. esc_attr( $columns['value'] ) .'" '. $checked_option .'>';
$extend_excerpt .= '<span>'. $columns['label'] .'</span>';
$extend_excerpt .= '</label>';
$extend_excerpt .= '</div>';
endforeach;
$extend_excerpt .= '</div><!-- .sub-extend -->';
/**
* Filter the Archive Excerpt Option output
* @param string $extend_excerpt HTML output
*
* @since Twenty'em 1.2.2
*/
return apply_filters( 't_em_admin_filter_excerpt_output', $extend_excerpt );
}
/**
* Archive Pagination Options
*/
function t_em_archive_pagination_options( $archive_pagination = '' ){
$archive_pagination = array(
'prev-next' => array(
'value' => 'prev-next',
'label' => __( 'Display <code>Newer</code> and <code>Older</code> posts links', 't_em' ),
),
'pagination' => array(
'value' => 'pagination',
'label' => __( 'Display a paginated list of links <code>« Newer 1 … 3 4 5 6 7 … 9 Older »</code>', 't_em' ),
),
);
/**
* Filter the Pagination option in Archive Options Set
*
* @param array An array of new options
* Keyed by a string id. The ids point to arrays containing 'value' and 'label' keys.
* @since Twenty'em 1.0
*/
return apply_filters( 't_em_admin_filter_archive_pagination_options', $archive_pagination );
}
/**
* Extend setting for Archive Pagination Option in Twenty'em admin panel.
* Referenced via t_em_archive_options() in /engine/archive-options.php.
*
* @since Twenty'em 1.0
*/
function t_em_settings_archive_pagination(){
$extend_pagination = '';
$extend_pagination .= '<div class="sub-extend layout text-radio-option-group option-group">';
$extend_pagination .= '<header>'. __( 'Archive Pagination', 't_em' ) .'</header>';
foreach ( t_em_archive_pagination_options() as $pagination ) :
$checked_option = checked( t_em( 'archive_pagination_set' ), $pagination['value'], false );
$extend_pagination .= '<div class="layout text-radio-option-group archive-pagination option-single">';
$extend_pagination .= '<label class="description">';
$extend_pagination .= '<input type="radio" name="t_em_theme_options[archive_pagination_set]" value="'. esc_attr( $pagination['value'] ) .'" '. $checked_option .'>';
$extend_pagination .= '<span>'. $pagination['label'] .'</span>';
$extend_pagination .= '</label>';
$extend_pagination .= '</div>';
endforeach;
$extend_pagination .= '</div><!-- .sub-extend -->';
/**
* Filter the Archive Pagination Option output
* @param string $extend_pagination HTML output
*
* @since Twenty'em 1.2.2
*/
echo apply_filters( 't_em_admin_filter_archive_pagination_output', $extend_pagination );
}
add_action( 't_em_admin_action_archive_options_after', 't_em_settings_archive_pagination' );
/**
* Render the Archive setting field in admin panel.
* Referenced via t_em_register_setting_options_init(), add_settings_field() callback in
* /engine/theme-options.php.
*
* @since Twenty'em 1.0
*/
function t_em_settings_field_archive_set(){
// Check for a new default value if any option is set to false
$archive_value = array();
foreach ( t_em_archive_options() as $archive ) :
if ( $archive['callback'] ) :
array_push( $archive_value, $archive['value'] );
endif;
endforeach;
$default_checked = ( count( $archive_value ) > 0 && ! in_array( t_em( 'archive_set' ), $archive_value ) ) ? $archive_value[0] : null;
?>
<div id="archive-options" class="tabs">
<?php do_action( 't_em_admin_action_archive_options_before' ); ?>
<?php if ( count( $archive_value ) == 0 ) : ?>
<p class="alert alert-critical"><?php _e( '<strong>Oops!</strong> No options available for this setting...', 't_em' ); ?></p>
<?php else : ?>
<ul>
<?php
foreach ( t_em_archive_options() as $archive ) :
if ( $archive['callback'] ) :
$active_option = ( t_em( 'archive_set' ) == $archive['value'] ) ? 'ui-tabs-active' : '';
$checked = ( $default_checked == $archive['value'] )
? $checked = 'checked="checked"'
: checked( t_em( 'archive_set' ), $archive['value'], false );
?>
<li class="<?php echo $active_option ?>">
<a href="#<?php echo $archive['value'] ?>" class="tab-heading">
<input type="radio" class="head-radio-option" name="t_em_theme_options[archive_set]" value="<?php echo esc_attr( $archive['value'] ); ?>" <?php echo $checked; ?> />
<?php echo $archive['label']; ?>
</a>
</li>
<?php
endif;
endforeach;
?>
</ul>
<?php
/* If our 'callback' key brings something, then we display our callback function.
* Let's go for the_excerpt().
*/
foreach ( t_em_archive_options() as $sub_archive ) :
if ( $sub_archive['callback'] != '' ) :
$selected_option = ( t_em( 'archive_set' ) == $sub_archive['value'] ) ? 'selected-option' : '';
?>
<div id="<?php echo $sub_archive['value'] ?>" class="sub-layout archive-extend <?php echo $selected_option; ?>">
<?php do_action( "t_em_admin_action_archive_option_{$sub_archive['value']}_before" ); ?>
<?php echo $sub_archive['callback']; ?>
<?php do_action( "t_em_admin_action_archive_option_{$sub_archive['value']}_after" ); ?>
</div>
<?php
endif;
endforeach;
endif; ?>
<?php do_action( 't_em_admin_action_archive_options_after' ); ?>
</div><!-- #archive-options -->
<?php
}
?>