PluginProbe
Cooked – Recipe Management / 1.9.5
Cooked – Recipe Management v1.9.5
1.16.1 1.16.0 1.15.0 trunk 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.12.0 1.13.0 1.14.0 1.7.10 1.7.11 1.7.12 1.7.13 1.7.15.1 1.7.15.3 1.7.15.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 All 37 releases
cooked / includes / class.cooked-settings.php

class.cooked-settings.php in Cooked – Recipe Management 1.9.5, at includes/class.cooked-settings.php

676 lines 33.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Register Settings
4 *
5 * @package Cooked
6 * @subpackage Settings
7 * @since 1.0.0
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * Cooked_Settings Class
15 *
16 * This class handles the settings creation and contains functions for retreiving those settings.
17 *
18 * @since 1.0.0
19 */
20 class Cooked_Settings {
21
22 public function __construct() {
23 add_filter( 'admin_init', [&$this, 'init'] );
24 add_filter( 'init', [&$this, 'init'] );
25 add_action( 'save_post', [&$this, 'browse_page_saved'], 10, 1 );
26 add_action( 'admin_notices', [&$this, 'cooked_settings_saved_admin_notice'] );
27 }
28
29 public function browse_page_saved( $post_id ) {
30 // Just a revision, don't do anything
31 if ( wp_is_post_revision( $post_id ) ) return;
32
33 $_cooked_settings = Cooked_Settings::get();
34 if ( isset($_cooked_settings['browse_page']) && $_cooked_settings['browse_page'] == $post_id ) {
35 flush_rewrite_rules(false);
36 }
37 }
38
39 public static function init() {
40 global $_cooked_settings, $list_id_counter;
41
42 $list_id_counter = 0;
43 $_cooked_settings = Cooked_Settings::get();
44 register_setting( 'cooked_settings_group', 'cooked_settings' );
45 register_setting( 'cooked_settings_group', 'cooked_settings_saved' );
46 }
47
48 function cooked_settings_saved_admin_notice() {
49 if (isset($_GET['settings-updated']) && $_GET['settings-updated'] && isset($_GET['page']) && $_GET['page'] === 'cooked_settings') {
50 add_settings_error(
51 'cooked_settings_group',
52 'cooked_settings_updated',
53 __( 'Cooked settings has been updated!', 'cooked' ),
54 'updated'
55 );
56 }
57 }
58
59 public static function reset() {
60 global $_cooked_settings;
61 $_cooked_settings = Cooked_Settings::get();
62 }
63
64 public static function get() {
65 $update_settings = false;
66 $_cooked_settings = get_option( 'cooked_settings' );
67 $cooked_settings_saved = get_option( 'cooked_settings_saved', false );
68 $_cooked_settings_version = get_option( 'cooked_settings_version', '1.0.0' );
69
70 $version_compare = version_compare( $_cooked_settings_version, COOKED_VERSION );
71
72 // Get defaults for fields that are not set yet.
73 $cooked_tabs_fields = self::tabs_fields();
74 if ( isset($cooked_tabs_fields) && !empty($cooked_tabs_fields) ) {
75 foreach ( $cooked_tabs_fields as $tab ) {
76 if ( isset($tab['fields']) && !empty($tab['fields']) ) {
77 foreach ( $tab['fields'] as $name => $field ) {
78 if ( $field['type'] == 'nonce' || $field['type'] == 'misc_button' ) continue;
79
80 if ( !$cooked_settings_saved || ( $cooked_settings_saved && $version_compare < 0 ) ) {
81 if ( $field['type'] == 'checkboxes' ) {
82 $_cooked_settings[$name] = isset($_cooked_settings[$name]) ? $_cooked_settings[$name] : ( isset( $field['default'] ) ? $field['default'] : [] );
83 } else {
84 $_cooked_settings[$name] = isset($_cooked_settings[$name]) ? $_cooked_settings[$name] : ( isset( $field['default'] ) ? $field['default'] : false );
85 }
86
87 // Update the settings only if the version has changed.
88 $update_settings = true;
89 }
90 }
91 }
92 }
93 }
94
95 if ( $update_settings ) {
96 update_option( 'cooked_settings', $_cooked_settings );
97
98 if ( self::needs_rewrite_flush( $_cooked_settings_version ) ) {
99 flush_rewrite_rules();
100 }
101 }
102
103 if ( $version_compare < 0 ) {
104 update_option( 'cooked_settings_version', COOKED_VERSION );
105 }
106
107 return apply_filters( 'cooked_get_settings', $_cooked_settings );
108 }
109
110 private static function needs_rewrite_flush( $old_version ) {
111 // List versions that require a rewrite flush
112 $versions_requiring_flush = [
113 '1.9.0', // New rewrite rules for Browse page introduced.
114 '1.9.1', // Hotfix for the permalink structure.
115 '1.9.2', // Hotfix for the permalink structure.
116 '1.9.4', // Hotfix for the permalink structure.
117 '1.9.5', // Hotfix for the permalink structure (sort & search).
118 ];
119
120 // If old version is newer than our latest flush requirement, no flush needed
121 if (version_compare($old_version, end($versions_requiring_flush), '>=')) {
122 return false;
123 }
124
125 // Find the next version that requires a flush after the old version
126 foreach ($versions_requiring_flush as $version) {
127 if (version_compare($old_version, $version, '<') &&
128 version_compare(COOKED_VERSION, $version, '>=')) {
129 return true;
130 }
131 }
132
133 return false;
134 }
135
136 public static function tabs_fields() {
137 $pages_array = self::pages_array( __('Choose a page...','cooked'), __('No pages','cooked') );
138 $categories_array = self::terms_array( 'cp_recipe_category', __('No default','cooked'), __('No categories','cooked') );
139 $recipes_per_page_array = self::per_page_array();
140
141 // Dynamically load roles.
142 $role_options = [];
143 if (is_user_logged_in()) {
144 global $wp_roles;
145 $roles = $wp_roles->roles;
146
147 if (!empty($roles)) {
148 foreach ( $roles as $role => $data ) {
149 $role_options[$role] = [
150 'label' => $data['name']
151 ];
152 }
153 }
154 }
155
156 return apply_filters('cooked_settings_tabs_fields', [
157 'recipe_settings' => [
158 'name' => __('General', 'cooked'),
159 'icon' => 'gear',
160 'fields' => [
161 'browse_page' => [
162 'title' => __('Browse/Search Recipes Page', 'cooked'),
163 /* translators: a description on how to add the [cooked-browse] shortcode to a page */
164 'desc' => sprintf(__('Create a page with the %s shortcode on it, then choose it from this dropdown.', 'cooked'), '<code>[cooked-browse]</code>'),
165 'type' => 'select',
166 'default' => 0,
167 'options' => $pages_array
168 ],
169 'recipes_per_page' => [
170 'title' => __('Recipes Per Page', 'cooked'),
171 /* translators: a description on how to choose the default number of recipes per page. */
172 'desc' => sprintf(__('Choose the default (set via the %s panel) or choose a different number here.', 'cooked'), '<a href="' . trailingslashit(get_admin_url()) . 'options-reading.php">' . __('Settings > Reading', 'cooked') . '</a>'),
173 'type' => 'select',
174 'default' => 9,
175 'options' => $recipes_per_page_array
176 ],
177 'recipe_taxonomies' => [
178 'title' => __('Recipe Taxonomies', 'cooked'),
179 'desc' => __('Choose which taxonomies you want to enable for your recipes.', 'cooked'),
180 'type' => 'checkboxes',
181 'default' => ['cp_recipe_category'],
182 'options' => apply_filters(
183 'cooked_taxonomy_options',
184 [
185 'cp_recipe_category' => __('Categories', 'cooked')
186 ]
187 )
188 ],
189 'recipe_info_display_options' => [
190 'title' => __('Global Recipe Toggles', 'cooked'),
191 'desc' => __('You can quickly hide or show different recipe elements (site-wide) with these checkboxes.', 'cooked'),
192 'type' => 'checkboxes',
193 'default' => apply_filters('cooked_recipe_info_display_options_defaults', ['author', 'taxonomies', 'difficulty_level', 'excerpt', 'timing_prep', 'timing_cook', 'timing_total', 'servings']),
194 'options' => apply_filters(
195 'cooked_recipe_info_display_options',
196 [
197 'author' => __('Author', 'cooked'),
198 'taxonomies' => __('Category', 'cooked'),
199 'difficulty_level' => __('Difficulty Level', 'cooked'),
200 'excerpt' => __('Excerpt', 'cooked'),
201 'notes' => __('Notes', 'cooked'),
202 'timing_prep' => __('Prep Time', 'cooked'),
203 'timing_cook' => __('Cook Time', 'cooked'),
204 'timing_total' => __('Total Time', 'cooked'),
205 'servings' => __('Servings', 'cooked')
206 ]
207 )
208 ],
209 'carb_format' => [
210 'title' => __('Carbs Format', 'cooked'),
211 'desc' => __('You can display carbs as "Total" or "Net".', 'cooked'),
212 'type' => 'select',
213 'default' => 'total',
214 'options' => apply_filters(
215 'cooked_settings_carb_formats',
216 [
217 'total' => __('Total Carbs', 'cooked'),
218 'net' => __('Net Carbs', 'cooked')
219 ]
220 )
221 ],
222 'author_name_format' => [
223 'title' => __('Author Name Format', 'cooked'),
224 'desc' => __('You can show the full author\'s name or just a part of it.', 'cooked'),
225 'type' => 'select',
226 'default' => 'full',
227 'options' => apply_filters(
228 'cooked_settings_author_formats',
229 [
230 'full' => __('Full name', 'cooked'),
231 'first_last_initial' => __('Full first name w/last name initial', 'cooked'),
232 'first_initial_last' => __('First name initial w/full last name', 'cooked'),
233 'first_only' => __('First name only', 'cooked')
234 ]
235 )
236 ],
237 'disable_author_links' => [
238 'title' => __('Author Links', 'cooked'),
239 'desc' => __('If you do not want the author names to link to the author recipe listings, you can disable them here.', 'cooked'),
240 'type' => 'checkboxes',
241 'color' => 'red',
242 'default' => [],
243 'options' => apply_filters(
244 'cooked_author_link_options',
245 [
246 'disabled' => __('Disable Author Links', 'cooked'),
247 ]
248 )
249 ],
250 'browse_default_cp_recipe_category' => [
251 'title' => __('Default Category', 'cooked'),
252 /* translators: a description on how to set the default recipe category for the [cooked-browse] shortcode. */
253 'desc' => sprintf(__('Optionally set the default recipe category for your %s shortcode display.', 'cooked'), '[cooked-browse]'),
254 'type' => 'select',
255 'default' => 0,
256 'options' => $categories_array
257 ],
258 'browse_default_sort' => [
259 'title' => __('Default Sort Order', 'cooked'),
260 /* translators: a description on how to set the default sort order for the [cooked-browse] shortcode. */
261 'desc' => sprintf(__('Set the default sort order for your %s shortcode display.', 'cooked'), '[cooked-browse]'),
262 'type' => 'select',
263 'default' => 'date_desc',
264 'options' => apply_filters(
265 'cooked_settings_sort_options',
266 [
267 'date_desc' => __('Newest First', 'cooked'),
268 'date_asc' => __('Oldest First', 'cooked'),
269 'title_asc' => __('Alphabetical', 'cooked'),
270 'title_desc' => __('Alphabetical (reversed)', 'cooked'),
271 ]
272 )
273 ],
274 'recipe_wp_editor_roles' => [
275 'title' => __('WP Editor Roles', 'cooked'),
276 'desc' => __('Choose which user roles can use the WP Editor for the Excerpt, Directions & Notes fields.', 'cooked'),
277 'type' => 'checkboxes',
278 'default' => apply_filters('cooked_add_recipe_wp_editor_roles_defaults', ['administrator', 'editor', 'cooked_recipe_editor']),
279 'options' => $role_options
280 ],
281 'advanced' => [
282 'title' => __('Advanced Settings', 'cooked'),
283 'desc' => '',
284 'type' => 'checkboxes',
285 'color' => 'red',
286 'class' => 'cooked-danger',
287 'default' => [],
288 'options' => apply_filters(
289 'cooked_advanced_options',
290 [
291 /* translators: an option to only show recipes with the [cooked-recipe] shortcode. */
292 'disable_public_recipes' => '<strong>' . __('Disable Public Recipes', 'cooked') . '</strong> &mdash; ' . sprintf(__('Only show recipes using the %s shortcode.', 'cooked'), '<code>[cooked-recipe]</code>'),
293 /* translators: an option to disable "meta" tags. */
294 'disable_meta_tags' => '<strong>' . sprintf(__('Disable %s Tags', 'cooked'), 'Cooked <code>&lt;meta&gt;</code>') . '</strong> &mdash; ' . __('Prevents duplicates when tags already exist.', 'cooked'),
295 'disable_servings_switcher' => '<strong>' . __('Disable "Servings Switcher"', 'cooked') . '</strong> &mdash; ' . __('Removes the servings dropdown on recipes.', 'cooked'),
296 'disable_schema_output' => '<strong>' . __('Disable Recipe Schema Output', 'cooked') . '</strong> &mdash; ' . __('You should only do this if you\'re using something else to output schema information.', 'cooked'),
297 'disable_cp_recipe_archive' => '<strong>' . __('Disable Recipe Archive Page', 'cooked') . '</strong> &mdash; ' . __('Prevents the recipe archive from being displayed.', 'cooked')
298 ]
299 )
300 ],
301 ]
302 ],
303 'design' => [
304 'name' => __('Design', 'cooked'),
305 'icon' => 'pencil',
306 'fields' => [
307 'dark_mode' => [
308 'title' => __('Dark Mode', 'cooked'),
309 'desc' => __('If your site has a dark background, you should enable "Dark Mode" so that Cooked can match this style.', 'cooked'),
310 'type' => 'checkboxes',
311 'default' => [],
312 'options' => apply_filters(
313 'cooked_dark_mode_options',
314 [
315 'enabled' => __('Enable "Dark Mode"', 'cooked'),
316 ]
317 )
318 ],
319 'hide_author_avatars' => [
320 'title' => __('Author Images', 'cooked'),
321 'desc' => __('If you do not want to display the author images (avatars), you can disable them here.', 'cooked'),
322 'type' => 'checkboxes',
323 'color' => 'red',
324 'default' => [],
325 'options' => apply_filters(
326 'cooked_author_image_options',
327 [
328 'hidden' => __('Hide Author Images', 'cooked'),
329 ]
330 )
331 ],
332 'main_color' => [
333 'title' => __('Main Color', 'cooked'),
334 'desc' => __('Used on buttons, cooking timer, etc.', 'cooked'),
335 'type' => 'color_field',
336 'default' => '#16a780',
337 'options' => '#16a780'
338 ],
339 'main_color_hover' => [
340 'title' => __('Main Color (on hover)', 'cooked'),
341 'desc' => __('Used when hovering over buttons.', 'cooked'),
342 'type' => 'color_field',
343 'default' => '#1b9371',
344 'options' => '#1b9371'
345 ],
346 'responsive_breakpoint_1' => [
347 'title' => __('First Responsive Breakpoint', 'cooked'),
348 'desc' => __('Set the first responsive breakpoint. Best for large tablets.', 'cooked'),
349 'type' => 'number_field',
350 'default' => '1000',
351 'options' => ''
352 ],
353 'responsive_breakpoint_2' => [
354 'title' => __('Second Responsive Breakpoint', 'cooked'),
355 'desc' => __('Set the second responsive breakpoint. Best for small tablets.', 'cooked'),
356 'type' => 'number_field',
357 'default' => '750',
358 'options' => ''
359 ],
360 'responsive_breakpoint_3' => [
361 'title' => __('Third Responsive Breakpoint', 'cooked'),
362 'desc' => __('Set the third responsive breakpoint. Best for phones and other small devices.', 'cooked'),
363 'type' => 'number_field',
364 'default' => '520',
365 'options' => ''
366 ]
367 ]
368 ],
369 'permalinks' => [
370 'name' => __('Permalinks', 'cooked'),
371 'icon' => 'link-lt',
372 'fields' => [
373 'recipe_permalink' => [
374 'title' => __('Recipe Permalink', 'cooked'),
375 'desc' => '',
376 'type' => 'permalink_field',
377 'options' => __('recipe-name', 'cooked'),
378 'default' => 'recipes'
379 ],
380 'recipe_author_permalink' => [
381 'title' => __('Recipe Author Permalink', 'cooked'),
382 'desc' => '',
383 'type' => 'permalink_field',
384 'options' => __('author-name', 'cooked'),
385 'default' => 'recipe-author'
386 ],
387 'recipe_category_permalink' => [
388 'title' => __('Recipe Category Permalink', 'cooked'),
389 'desc' => '',
390 'type' => 'permalink_field',
391 'options' => __('recipe-category-name', 'cooked'),
392 'default' => 'recipe-category'
393 ]
394 ]
395 ]
396 ], $pages_array, $categories_array);
397 }
398
399 public static function per_page_array() {
400 $counter = 0;
401 /* translators: posts_per_page default */
402 $per_page_array[] = sprintf( __('WordPress Default %s','cooked'), '(' . get_option( 'posts_per_page' ) . ')' );
403 do {
404 $counter++;
405 $per_page_array[$counter] = $counter;
406 } while ( $counter < 50 );
407 $per_page_array['-1'] = __('Show All (no pagination)','cooked');
408
409 return apply_filters( 'cooked_per_page_options', $per_page_array );
410 }
411
412 public static function pages_array( $choose_text, $none_text = false ) {
413 $page_array = [];
414 $pages = get_posts([
415 'post_type' => 'page',
416 'posts_per_page' => -1]
417 );
418
419 if( !empty($pages) ) {
420 $page_array[0] = $choose_text;
421 foreach ($pages as $_page) {
422 $page_array[$_page->ID] = $_page->post_title . ' (ID:' . $_page->ID . ')';
423 }
424 } elseif ( $none_text ) {
425 $page_array[0] = $none_text;
426 }
427
428 return apply_filters( 'cooked_settings_pages_array', $page_array );
429 }
430
431 public static function terms_array( $term, $choose_text, $none_text = false, $hide_empty = false, $parents_only = false, $child_of = false ) {
432 $terms_array = [];
433
434 $args = [
435 'taxonomy' => $term,
436 'hide_empty' => $hide_empty
437 ];
438
439 if ( $parents_only ) {
440 $args['parent'] = '0';
441 } elseif ( $child_of ) {
442 $_term = is_numeric($child_of) ? $child_of : get_term_by( 'slug', $child_of, $term );
443 $term_id = is_object( $_term ) ? $_term->term_id : $_term;
444 $args['parent'] = $term_id;
445 }
446
447 $terms = get_terms( $args );
448
449 if ( !empty($terms) ) {
450 if ($choose_text) {
451 $terms_array[0] = $choose_text;
452 }
453
454 foreach ($terms as $_term) {
455 if ( !is_array($_term) ) {
456 $terms_array[$_term->term_id] = $_term->name;
457 }
458 }
459 } elseif ( $none_text ) {
460 $terms_array[0] = $none_text;
461 }
462
463 return apply_filters( 'cooked_settings_' . $term . '_array', $terms_array );
464 }
465
466 public static function field_radio( $field_name, $options ) {
467 global $_cooked_settings, $conditions;
468
469 $counter = 1;
470
471 echo '<p class="cooked-padded">';
472 foreach ( $options as $value => $name) {
473 $is_disabled = '';
474 $conditional_value = '';
475 $conditional_requirement = '';
476
477 if ( is_array($name) ):
478 if ( isset($name['read_only']) && $name['read_only'] ):
479 $is_disabled = ' disabled';
480 endif;
481
482 if ( isset($name['conditional_value']) && $name['conditional_value'] ):
483 $conditional_value = ' v-model="' . esc_attr($name['conditional_value']) . '"';
484 if ( !in_array( $name['conditional_value'], $conditions ) ):
485 $conditions[$value] = esc_attr($name['conditional_requirement']);
486 endif;
487 endif;
488
489 if ( isset($name['conditional_requirement']) && $name['conditional_requirement'] ):
490 if ( is_array($name['conditional_requirement']) ):
491 $conditional_requirement = ' v-show="' . implode( ' && ', $name['conditional_requirement'] ) . '"';
492 else:
493 $conditional_requirement = ' v-show="' . esc_attr($name['conditional_requirement']) . '"';
494 endif;
495 endif;
496
497 $name = $name['label'];
498 endif;
499
500 $combined_extras = $is_disabled . $conditional_value;
501
502 if ( $conditional_requirement ): echo '<transition name="fade"><span class="conditional-requirement"' . esc_attr( $conditional_requirement ) . '>'; endif;
503 echo '<input' . $combined_extras . ' type="radio" id="radio-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '" name="cooked_settings[' . esc_attr( $field_name ) . ']" value="' . esc_attr( $value ) . '"' . ( isset( $_cooked_settings[$field_name] ) && $_cooked_settings[$field_name] == $value || isset( $_cooked_settings[$field_name][0] ) && $_cooked_settings[$field_name][0] == $value ? ' checked' : '' ) . '/>';
504 echo '&nbsp;<label for="radio-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '">' . wp_kses_post( $name ) . '</label>';
505 echo '<br>';
506 if ( $conditional_requirement ): echo '</span></transition>'; endif;
507
508 $counter++;
509 }
510 echo '</p>';
511 }
512
513 public static function field_select( $field_name, $options, $color = false, $field = []) {
514 global $_cooked_settings;
515
516 $is_disabled = '';
517
518 if ( isset($field['read_only']) && $field['read_only'] ) {
519 $is_disabled = ' disabled';
520 }
521
522 echo '<p>';
523 echo '<select' . $is_disabled . ' name="cooked_settings[' . esc_attr( $field_name ) . ']">';
524 foreach ( $options as $value => $name) {
525 echo '<option value="' . esc_attr( $value ) . '"' . ( isset( $_cooked_settings[$field_name] ) && $_cooked_settings[$field_name] == $value ? ' selected' : '' ) . '>' . esc_attr( $name ) . '</option>';
526 }
527 echo '</select>';
528 echo '</p>';
529 }
530
531 public static function field_nonce( $field_name, $options ) {
532 wp_nonce_field( $field_name, $field_name );
533 }
534
535 // Kept here for backwards compatibility only. Removed used in Cooked Pro 1.0.1
536 public static function field_misc_button( $field_name, $title ) {
537 echo '<p>';
538 echo '<input type="submit" class="button-secondary" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $title ) . '">';
539 echo '</p>';
540 }
541 // END
542
543 public static function field_migrate_button( $field_name, $title ) {
544 $old_recipes = get_transient('cooked_classic_recipes');
545
546 if ($old_recipes != 'complete') {
547 $total = count($old_recipes);
548
549 if ($total > 0) {
550 echo '<p>';
551 echo '<input id="cooked-migration-button" type="button" class="button-secondary" name="begin_cooked_migration" value="' . __( 'Begin Migration', 'cooked' ) . '">';
552 echo '</p>';
553 echo '<p>';
554 echo '<span id="cooked-migration-progress" class="cooked-progress"><span class="cooked-progress-bar"></span></span><span id="cooked-migration-progress-text" class="cooked-progress-text">0 / ' . esc_html( $total ) . '</span>';
555 echo '</p>';
556 echo '<p id="cooked-migration-completed"><strong>Migration Complete!</strong> You can now <a href="' . esc_url( add_query_arg(['page' => 'cooked_settings'], admin_url( 'admin.php' ) ) ) . '">' . __( 'reload', 'cooked' ) . '</a> the settings screen.</p>';
557 }
558 }
559 }
560
561 public static function field_text($field_name, $placeholder) {
562 global $_cooked_settings;
563
564 echo '<p>';
565 echo '<input id="cooked_field--' . esc_attr( $field_name ) . '" type="text"' . ( $placeholder ? ' placeholder="' . esc_attr( $placeholder ) . '"' : '' ) . ' name="cooked_settings[' . esc_attr( $field_name ) . ']" value="' . ( isset( $_cooked_settings[$field_name] ) && $_cooked_settings[$field_name] ? esc_attr( $_cooked_settings[$field_name] ) : '' ) . '">';
566 echo '</p>';
567 }
568
569 public static function field_password($field_name, $placeholder) {
570 global $_cooked_settings;
571
572 echo '<p>';
573 echo '<input type="password"' . ( $placeholder ? ' placeholder="' . esc_attr( $placeholder ) . '"' : '' ) . ' name="cooked_settings[' . esc_attr( $field_name ) . ']" value="' . ( isset( $_cooked_settings[$field_name] ) && $_cooked_settings[$field_name] ? esc_attr( $_cooked_settings[$field_name] ) : '' ) . '">';
574 echo '</p>';
575 }
576
577 public static function field_html($field_name, $html) {
578 echo wp_kses_post($html);
579 }
580
581 public static function field_permalink_field($field_name, $end_of_url) {
582 global $_cooked_settings;
583
584 $home_url = get_home_url();
585
586 if (substr($home_url, -1) !== '/') {
587 $home_url .= '/';
588 }
589
590 echo '<p class="cooked-permalink-field-wrapper">';
591 echo '<span>' . $home_url . '</span><input type="text" class="cooked-permalink-field" name="cooked_settings[' . esc_attr( $field_name ) . ']" value="' . ( isset( $_cooked_settings[$field_name] ) && $_cooked_settings[$field_name] ? esc_attr( $_cooked_settings[$field_name] ) : '' ) . '"><span>/' . esc_html( $end_of_url ) . '/</span>';
592 echo '</p>';
593 }
594
595 public static function field_number_field( $field_name, $options ) {
596 global $_cooked_settings;
597
598 echo '<p>';
599 echo '<input type="number" step="any" name="cooked_settings[' . esc_attr( $field_name ) . ']" value="' . ( isset( $_cooked_settings[$field_name] ) && $_cooked_settings[$field_name] ? esc_attr( $_cooked_settings[$field_name] ) : '' ) . '">';
600 echo '</p>';
601 }
602
603 public static function field_color_field( $field_name, $default ) {
604 global $_cooked_settings;
605
606 echo '<p>';
607 echo '<input class="cooked-color-field" type="text"' . ( $default ? ' data-default-color="' . esc_attr( $default ) . '"' : '' ) . ' name="cooked_settings[' . esc_attr( $field_name ) . ']" value="' . ( isset( $_cooked_settings[$field_name] ) && $_cooked_settings[$field_name] ? esc_attr( $_cooked_settings[$field_name] ) : '' ) . '">';
608 echo '</p>';
609 }
610
611 public static function field_checkboxes( $field_name, $options, $color = false, $field = [] ) {
612 global $_cooked_settings, $conditions;
613
614 echo '<p class="cooked-padded">';
615 foreach ( $options as $value => $name) {
616 $is_disabled = '';
617 $conditional_value = '';
618 $conditional_requirement = '';
619
620 if ( is_array($name) ):
621 if ( isset($name['read_only']) && $name['read_only'] ):
622 $is_disabled = ' disabled';
623 endif;
624
625 if ( isset($name['conditional_value']) && $name['conditional_value'] ):
626 $conditional_value = ' v-model="' . esc_attr($name['conditional_value']) . '"';
627 if ( !in_array( $name['conditional_value'], $conditions ) ):
628 $conditions[$field_name][$name['conditional_value']] = $value;
629 endif;
630 endif;
631
632 if ( isset($name['conditional_requirement']) && $name['conditional_requirement'] ):
633 if ( is_array($name['conditional_requirement']) ):
634 $conditional_requirement = ' v-show="' . implode( ' && ', $name['conditional_requirement'] ) . '"';
635 else:
636 $conditional_requirement = ' v-show="' . esc_attr($name['conditional_requirement']) . '"';
637 endif;
638 endif;
639
640 $name = $name['label'];
641 endif;
642
643 $combined_extras = $is_disabled . $conditional_value;
644
645 if ( $conditional_requirement ):
646 echo '<transition name="fade"><span class="conditional-requirement"' . esc_attr( $conditional_requirement ) . '>';
647 endif;
648
649 if ( $is_disabled ):
650 echo '<input type="hidden" name="cooked_settings[' . esc_attr( $field_name ) . '][]" value="' . esc_attr( $value ) . '">';
651 echo '<input' . $combined_extras . ' class="cooked-switch' . ( $color ? '-' . esc_attr( $color ) : '' ) . '" type="checkbox" id="checkbox-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '"' . (
652 (isset( $_cooked_settings[$field_name] ) && !empty($_cooked_settings[$field_name]) && in_array( $value, $_cooked_settings[$field_name] )) ||
653 $is_disabled ||
654 (empty($_cooked_settings[$field_name]) && isset($field['default']) && in_array($value, (array)$field['default']))
655 ? ' checked' : '' ) . '/>';
656 else:
657 echo '<input' . $combined_extras . ' class="cooked-switch' . ( $color ? '-' . esc_attr( $color ) : '' ) . '" type="checkbox" id="checkbox-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '" name="cooked_settings[' . esc_attr( $field_name ) . '][]" value="' . esc_attr( $value ) . '"' . (
658 (isset( $_cooked_settings[$field_name] ) && !empty($_cooked_settings[$field_name]) && is_array( $_cooked_settings[$field_name] ) && in_array( $value, $_cooked_settings[$field_name] )) ||
659 $is_disabled ||
660 (empty($_cooked_settings[$field_name]) && isset($field['default']) && in_array($value, (array)$field['default']))
661 ? ' checked' : '' ) . '/>';
662 endif;
663
664 echo '&nbsp;<label for="checkbox-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '">' . wp_kses_post( $name ) . '</label>';
665 echo '<br>';
666
667 if ( $conditional_requirement ):
668 echo '</span></transition>';
669 endif;
670
671 }
672 echo '</p>';
673 }
674
675 }
676