PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.6.5
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.6.5
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
automatic-youtube-gallery / admin / settings.php

settings.php in Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels 2.6.5, at admin/settings.php

763 lines 29.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Settings.
5 *
6 * @link https://plugins360.com
7 * @since 1.0.0
8 *
9 * @package Automatic_YouTube_Gallery
10 */
11
12 // Exit if accessed directly
13 if ( ! defined( 'WPINC' ) ) {
14 die;
15 }
16
17 /**
18 * AYG_Admin_Settings class.
19 *
20 * @since 1.0.0
21 */
22 class AYG_Admin_Settings {
23
24 /**
25 * Settings tabs array.
26 *
27 * @since 1.0.0
28 * @access protected
29 * @var array
30 */
31 protected $tabs = array();
32
33 /**
34 * Settings sections array.
35 *
36 * @since 1.0.0
37 * @access protected
38 * @var array
39 */
40 protected $sections = array();
41
42 /**
43 * Settings fields array
44 *
45 * @since 1.0.0
46 * @access protected
47 * @var array
48 */
49 protected $fields = array();
50
51 /**
52 * Add "Settings" menu.
53 *
54 * @since 1.0.0
55 */
56 public function admin_menu() {
57 add_submenu_page(
58 'automatic-youtube-gallery',
59 __( 'Settings', 'automatic-youtube-gallery' ),
60 __( 'Settings', 'automatic-youtube-gallery' ),
61 'manage_options',
62 'automatic-youtube-gallery-settings',
63 array( $this, 'display_settings_form' )
64 );
65 }
66
67 /**
68 * Display settings form.
69 *
70 * @since 1.0.0
71 */
72 public function display_settings_form() {
73 require_once AYG_DIR . 'admin/templates/settings.php';
74 }
75
76 /**
77 * Initiate settings.
78 *
79 * @since 1.0.0
80 */
81 public function admin_init() {
82 $this->tabs = $this->get_tabs();
83 $this->sections = $this->get_sections();
84 $this->fields = $this->get_fields();
85
86 // Initialize settings
87 $this->initialize_settings();
88 }
89
90 /**
91 * Get settings tabs.
92 *
93 * @since 1.0.0
94 * @return array $tabs Setting tabs array.
95 */
96 public function get_tabs() {
97 $tabs = array(
98 'general' => __( 'General', 'automatic-youtube-gallery' ),
99 'gallery' => __( 'Gallery', 'automatic-youtube-gallery' ),
100 'player' => __( 'Player', 'automatic-youtube-gallery' ),
101 'livestream' => __( 'Livestream', 'automatic-youtube-gallery' ),
102 'privacy' => __( 'GDPR Compliance', 'automatic-youtube-gallery' )
103 );
104
105 return apply_filters( 'ayg_settings_tabs', $tabs );
106 }
107
108 /**
109 * Get settings sections.
110 *
111 * @since 1.0.0
112 * @return array $sections Setting sections array.
113 */
114 public function get_sections() {
115 $sections = array(
116 array(
117 'id' => 'ayg_general_settings',
118 'title' => __( 'General Settings', 'automatic-youtube-gallery' ),
119 'description' => '',
120 'tab' => 'general',
121 'page' => 'ayg_general_settings'
122 ),
123 array(
124 'id' => 'ayg_strings_settings',
125 'title' => __( 'Button & Link Labels', 'automatic-youtube-gallery' ),
126 'description' => '',
127 'tab' => 'general',
128 'page' => 'ayg_strings_settings'
129 ),
130 array(
131 'id' => 'ayg_gallery_settings',
132 'title' => __( 'Gallery Settings', 'automatic-youtube-gallery' ),
133 'description' => '',
134 'tab' => 'gallery',
135 'page' => 'ayg_gallery_settings'
136 ),
137 array(
138 'id' => 'ayg_player_settings',
139 'title' => __( 'Player Settings', 'automatic-youtube-gallery' ),
140 'description' => '',
141 'tab' => 'player',
142 'page' => 'ayg_player_settings'
143 ),
144 array(
145 'id' => 'ayg_livestream_settings',
146 'title' => __( 'Livestream Settings', 'automatic-youtube-gallery' ),
147 'description' => '',
148 'tab' => 'livestream',
149 'page' => 'ayg_livestream_settings'
150 ),
151 array(
152 'id' => 'ayg_privacy_settings',
153 'title' => __( 'GDPR Compliance', 'automatic-youtube-gallery' ),
154 'description' => __( 'These options will help with privacy restrictions such as GDPR and the EU Cookie Law.', 'automatic-youtube-gallery' ),
155 'tab' => 'privacy',
156 'page' => 'ayg_privacy_settings'
157 ),
158 );
159
160 return apply_filters( 'ayg_settings_sections', $sections );
161 }
162
163 /**
164 * Get settings fields.
165 *
166 * @since 1.0.0
167 * @return array $fields Setting fields array.
168 */
169 public function get_fields() {
170 // General Settings
171 $fields['ayg_general_settings'] = array(
172 array(
173 'name' => 'api_key',
174 'label' => __( 'Youtube API Key', 'automatic-youtube-gallery' ),
175 'description' => sprintf(
176 __( 'Follow <a href="%s" target="_blank" rel="noopener noreferrer">this guide</a> to get your own API key.', 'automatic-youtube-gallery' ),
177 'https://plugins360.com/automatic-youtube-gallery/how-to-get-youtube-api-key/'
178 ),
179 'type' => 'text',
180 'sanitize_callback' => 'sanitize_text_field'
181 ),
182 array(
183 'name' => 'lazyload',
184 'label' => __( 'Lazyload Images / Videos', 'automatic-youtube-gallery' ),
185 'description' => __( 'Enable this option to lazy load images and videos added by the plugin to enhance page load speed and performance. If you experience any issues with content display, try disabling this option.', 'automatic-youtube-gallery' ),
186 'type' => 'checkbox',
187 'sanitize_callback' => 'intval'
188 ),
189 array(
190 'name' => 'development_mode',
191 'label' => __( 'Development Mode', 'automatic-youtube-gallery' ),
192 'description' => __( 'Does not cache API results when checked. We strongly recommend disabling this option when your site is live.', 'automatic-youtube-gallery' ),
193 'type' => 'checkbox',
194 'sanitize_callback' => 'intval'
195 )
196 );
197
198 // Strings Settings
199 $fields['ayg_strings_settings'] = array(
200 array(
201 'name' => 'more_button_label',
202 'label' => __( 'More Button Label', 'automatic-youtube-gallery' ),
203 'description' => __( 'Text for the "Load More" button when pagination type is set to "More Button".', 'automatic-youtube-gallery' ),
204 'type' => 'text',
205 'sanitize_callback' => 'sanitize_text_field'
206 ),
207 array(
208 'name' => 'previous_button_label',
209 'label' => __( 'Previous Button Label', 'automatic-youtube-gallery' ),
210 'description' => __( 'Text for the "Previous" button when pagination type is set to "Pager".', 'automatic-youtube-gallery' ),
211 'type' => 'text',
212 'sanitize_callback' => 'sanitize_text_field'
213 ),
214 array(
215 'name' => 'next_button_label',
216 'label' => __( 'Next Button Label', 'automatic-youtube-gallery' ),
217 'description' => __( 'Text for the "Next" button when pagination type is set to "Pager".', 'automatic-youtube-gallery' ),
218 'type' => 'text',
219 'sanitize_callback' => 'sanitize_text_field'
220 ),
221 array(
222 'name' => 'show_more_label',
223 'label' => __( 'Show More Label', 'automatic-youtube-gallery' ),
224 'description' => __( 'Text for the "Show More" link that expands the video description below the player.', 'automatic-youtube-gallery' ),
225 'type' => 'text',
226 'sanitize_callback' => 'sanitize_text_field'
227 ),
228 array(
229 'name' => 'show_less_label',
230 'label' => __( 'Show Less Label', 'automatic-youtube-gallery' ),
231 'description' => __( 'Text for the "Show Less" link that collapses the video description below the player.', 'automatic-youtube-gallery' ),
232 'type' => 'text',
233 'sanitize_callback' => 'sanitize_text_field'
234 )
235 );
236
237 // Gallery Settings
238 $gallery_settings = ayg_get_gallery_settings_fields();
239
240 $gallery_settings[] = array(
241 'name' => 'scroll_top_offset',
242 'label' => __( 'Page Scroll Top Offset', 'automatic-youtube-gallery' ),
243 'description' => __( 'Set the top offset in pixels for scrolling to the video player after a thumbnail is clicked. Enter <code>-1</code> to disable automatic scrolling.', 'automatic-youtube-gallery' ),
244 'type' => 'text',
245 'sanitize_callback' => 'ayg_sanitize_int'
246 );
247
248 $fields['ayg_gallery_settings'] = $gallery_settings;
249
250 // Player Settings
251 $player_settings = array(
252 array(
253 'name' => 'player_type',
254 'label' => __( 'Player Type', 'automatic-youtube-gallery' ),
255 'description' => '',
256 'type' => 'radio',
257 'options' => array(
258 'youtube' => __( 'Native YouTube Embed', 'automatic-youtube-gallery' ),
259 'custom' => __( 'Custom Video Player', 'automatic-youtube-gallery' )
260 ),
261 'sanitize_callback' => 'sanitize_text_field'
262 ),
263 array(
264 'name' => 'player_color',
265 'label' => __( 'Player Color', 'automatic-youtube-gallery' ),
266 'description' => __( 'Set the theme color for your video player.', 'automatic-youtube-gallery' ),
267 'type' => 'color',
268 'sanitize_callback' => 'sanitize_text_field'
269 )
270 );
271
272 $player_settings = array_merge( $player_settings, ayg_get_player_settings_fields() );
273
274 $player_settings[] = array(
275 'name' => 'privacy_enhanced_mode',
276 'label' => __( 'Privacy Enhanced Mode', 'automatic-youtube-gallery' ),
277 'description' => __( "Prevent YouTube from leaving tracking cookies on your visitor's browsers unless they actually play the videos. Please uncheck this option if you see errors while testing your playlist embeds or watching your videos on mobile.", 'automatic-youtube-gallery' ),
278 'type' => 'checkbox',
279 'sanitize_callback' => 'intval'
280 );
281
282 $player_settings[] = array(
283 'name' => 'origin',
284 'label' => __( 'Extra Player Security', 'automatic-youtube-gallery' ),
285 'description' => __( 'Add site origin information with each embed code as an extra security measure. In YouTube\'s own words, checking this option "protects against malicious third-party JavaScript being injected into your page and hijacking control of your YouTube player."', 'automatic-youtube-gallery' ),
286 'type' => 'checkbox',
287 'sanitize_callback' => 'intval'
288 );
289
290 $fields['ayg_player_settings'] = $player_settings;
291
292 // Livestream Settings
293 $fields['ayg_livestream_settings'] = array(
294 array(
295 'name' => 'fallback_message',
296 'label' => __( 'Fallback Message', 'automatic-youtube-gallery' ),
297 'description' => __( 'Enter your Custom HTML message that should be displayed when there is no video streaming live.', 'automatic-youtube-gallery' ),
298 'type' => 'wysiwyg',
299 'sanitize_callback' => 'wp_kses_post'
300 )
301 );
302
303 // Privacy Settings
304 $fields['ayg_privacy_settings'] = array(
305 array(
306 'name' => 'cookie_consent',
307 'label' => __( 'Cookie Consent', 'automatic-youtube-gallery' ),
308 'description' => __( 'Ask for viewer consent to store YouTube cookies before showing videos.', 'automatic-youtube-gallery' ),
309 'type' => 'checkbox',
310 'sanitize_callback' => 'intval'
311 ),
312 array(
313 'name' => 'consent_message',
314 'label' => __( 'Consent Message', 'automatic-youtube-gallery' ),
315 'description' => '',
316 'type' => 'wysiwyg',
317 'sanitize_callback' => 'wp_kses_post'
318 ),
319 array(
320 'name' => 'button_label',
321 'label' => __( 'Button Label', 'automatic-youtube-gallery' ),
322 'description' => '',
323 'type' => 'text',
324 'sanitize_callback' => 'sanitize_text_field'
325 )
326 );
327
328 return apply_filters( 'ayg_settings_fields', $fields );
329 }
330
331 /**
332 * Initialize and registers the settings sections and fields to WordPress.
333 *
334 * @since 1.0.0
335 */
336 public function initialize_settings() {
337 // Register settings sections & fields
338 foreach ( $this->sections as $section ) {
339 $page_hook = isset( $section['page'] ) ? $section['page'] : $section['id'];
340
341 // Sections
342 if ( false == get_option( $section['id'] ) ) {
343 add_option( $section['id'] );
344 }
345
346 if ( isset( $section['description'] ) && ! empty( $section['description'] ) ) {
347 $callback = array( $this, 'settings_section_callback' );
348 } elseif ( isset( $section['callback'] ) ) {
349 $callback = $section['callback'];
350 } else {
351 $callback = null;
352 }
353
354 add_settings_section( $section['id'], $section['title'], $callback, $page_hook );
355
356 // Fields
357 $fields = $this->fields[ $section['id'] ];
358
359 foreach ( $fields as $option ) {
360 $name = $option['name'];
361 $type = isset( $option['type'] ) ? $option['type'] : 'text';
362 $label = isset( $option['label'] ) ? $option['label'] : '';
363 $callback = isset( $option['callback'] ) ? $option['callback'] : array( $this, 'callback_' . $type );
364 $args = array(
365 'id' => $name,
366 'class' => isset( $option['class'] ) ? $option['class'] : $name,
367 'label_for' => "{$section['id']}[{$name}]",
368 'description' => isset( $option['description'] ) ? $option['description'] : '',
369 'name' => $label,
370 'section' => $section['id'],
371 'size' => isset( $option['size'] ) ? $option['size'] : null,
372 'options' => isset( $option['options'] ) ? $option['options'] : '',
373 'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
374 'type' => $type,
375 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : '',
376 'min' => isset( $option['min'] ) ? $option['min'] : '',
377 'max' => isset( $option['max'] ) ? $option['max'] : '',
378 'step' => isset( $option['step'] ) ? $option['step'] : ''
379 );
380
381 add_settings_field( "{$section['id']}[{$name}]", $label, $callback, $page_hook, $section['id'], $args );
382 }
383
384 // Creates our settings in the options table
385 register_setting( $page_hook, $section['id'], array( $this, 'sanitize_options' ) );
386 }
387 }
388
389 /**
390 * Displays a section description.
391 *
392 * @since 1.0.0
393 * @param array $args Settings section args.
394 */
395 public function settings_section_callback( $args ) {
396 foreach ( $this->sections as $section ) {
397 if ( $section['id'] == $args['id'] ) {
398 printf( '<div class="inside">%s</div>', wp_kses_post( $section['description'] ) );
399 break;
400 }
401 }
402 }
403
404 /**
405 * Displays a text field for a settings field.
406 *
407 * @since 1.0.0
408 * @param array $args Settings field args.
409 */
410 public function callback_text( $args ) {
411 $value = esc_attr( $this->get_option( $args['id'], $args['section'], '' ) );
412 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
413 $type = isset( $args['type'] ) ? $args['type'] : 'text';
414 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
415
416 $html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );
417 $html .= $this->get_field_description( $args );
418
419 echo $html;
420 }
421
422 /**
423 * Displays a url field for a settings field.
424 *
425 * @since 1.0.0
426 * @param array $args Settings field args.
427 */
428 public function callback_url( $args ) {
429 $this->callback_text( $args );
430 }
431
432 /**
433 * Displays a number field for a settings field.
434 *
435 * @since 1.0.0
436 * @param array $args Settings field args.
437 */
438 public function callback_number( $args ) {
439 $value = esc_attr( $this->get_option( $args['id'], $args['section'], 0 ) );
440 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
441 $type = isset( $args['type'] ) ? $args['type'] : 'number';
442 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
443 $min = empty( $args['min'] ) ? '' : ' min="' . $args['min'] . '"';
444 $max = empty( $args['max'] ) ? '' : ' max="' . $args['max'] . '"';
445 $step = empty( $args['max'] ) ? '' : ' step="' . $args['step'] . '"';
446
447 $html = sprintf( '<input type="%1$s" class="%2$s-number" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );
448 $html .= $this->get_field_description( $args );
449
450 echo $html;
451 }
452
453 /**
454 * Displays a checkbox for a settings field.
455 *
456 * @since 1.0.0
457 * @param array $args Settings field args.
458 */
459 public function callback_checkbox( $args ) {
460 $value = esc_attr( $this->get_option( $args['id'], $args['section'], 0 ) );
461
462 $html = '<fieldset>';
463 $html .= sprintf( '<label for="%1$s[%2$s]">', $args['section'], $args['id'] );
464 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="0" />', $args['section'], $args['id'] );
465 $html .= sprintf( '<input type="checkbox" class="checkbox" id="%1$s[%2$s]" name="%1$s[%2$s]" value="1" %3$s />', $args['section'], $args['id'], checked( $value, 1, false ) );
466 $html .= sprintf( '%1$s</label>', $args['description'] );
467 $html .= '</fieldset>';
468
469 echo $html;
470 }
471
472 /**
473 * Displays a multicheckbox for a settings field.
474 *
475 * @since 1.0.0
476 * @param array $args Settings field args.
477 */
478 public function callback_multicheck( $args ) {
479 $value = $this->get_option( $args['id'], $args['section'], array() );
480
481 $html = '<fieldset>';
482 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="" />', $args['section'], $args['id'] );
483 foreach ( $args['options'] as $key => $label ) {
484 $checked = in_array( $key, $value ) ? 'checked="checked"' : '';
485 $html .= sprintf( '<label for="%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
486 $html .= sprintf( '<input type="checkbox" class="checkbox" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, $checked );
487 $html .= sprintf( '%1$s</label><br>', $label );
488 }
489 $html .= $this->get_field_description( $args );
490 $html .= '</fieldset>';
491
492 echo $html;
493 }
494
495 /**
496 * Displays a radio button for a settings field.
497 *
498 * @since 1.0.0
499 * @param array $args Settings field args.
500 */
501 public function callback_radio( $args ) {
502 $value = $this->get_option( $args['id'], $args['section'], '' );
503
504 $html = '<fieldset>';
505 foreach ( $args['options'] as $key => $label ) {
506 $html .= sprintf( '<label for="%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
507 $html .= sprintf( '<input type="radio" class="radio" id="%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $value, $key, false ) );
508 $html .= sprintf( '%1$s</label><br>', $label );
509 }
510 $html .= $this->get_field_description( $args );
511 $html .= '</fieldset>';
512
513 echo $html;
514 }
515
516 /**
517 * Displays a selectbox for a settings field.
518 *
519 * @since 1.0.0
520 * @param array $args Settings field args.
521 */
522 public function callback_select( $args ) {
523 $value = esc_attr( $this->get_option( $args['id'], $args['section'], '' ) );
524 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
525
526 $html = sprintf( '<select class="%1$s" name="%2$s[%3$s]" id="%2$s[%3$s]">', $size, $args['section'], $args['id'] );
527 foreach ( $args['options'] as $key => $label ) {
528 $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $value, $key, false ), $label );
529 }
530 $html .= sprintf( '</select>' );
531 $html .= $this->get_field_description( $args );
532
533 echo $html;
534 }
535
536 /**
537 * Displays a textarea for a settings field.
538 *
539 * @since 1.0.0
540 * @param array $args Settings field args.
541 */
542 public function callback_textarea( $args ) {
543 $value = esc_textarea( $this->get_option( $args['id'], $args['section'], '' ) );
544 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
545 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
546
547 $html = sprintf( '<textarea rows="5" cols="55" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );
548 $html .= $this->get_field_description( $args );
549
550 echo $html;
551 }
552
553 /**
554 * Displays the html for a settings field.
555 *
556 * @since 1.0.0
557 * @param array $args Settings field args.
558 */
559 public function callback_html( $args ) {
560 echo $this->get_field_description( $args );
561 }
562
563 /**
564 * Displays a rich text textarea for a settings field.
565 *
566 * @since 1.0.0
567 * @param array $args Settings field args.
568 */
569 public function callback_wysiwyg( $args ) {
570 $value = $this->get_option( $args['id'], $args['section'], '' );
571 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : '500px';
572
573 echo '<div style="max-width: ' . $size . ';">';
574 $editor_settings = array(
575 'teeny' => true,
576 'textarea_name' => $args['section'] . '[' . $args['id'] . ']',
577 'textarea_rows' => 10
578 );
579 if ( isset( $args['options'] ) && is_array( $args['options'] ) ) {
580 $editor_settings = array_merge( $editor_settings, $args['options'] );
581 }
582 wp_editor( $value, $args['section'] . '-' . $args['id'], $editor_settings );
583 echo '</div>';
584 echo $this->get_field_description( $args );
585 }
586
587 /**
588 * Displays a file upload field for a settings field.
589 *
590 * @since 1.0.0
591 * @param array $args Settings field args.
592 */
593 public function callback_file( $args ) {
594 $value = esc_attr( $this->get_option( $args['id'], $args['section'], '' ) );
595 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
596 $id = $args['section'] . '[' . $args['id'] . ']';
597 $label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : __( 'Choose File', 'automatic-youtube-gallery' );
598
599 $html = sprintf( '<input type="text" class="%1$s-text ayg-settings-url" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
600 $html .= '<input type="button" class="button ayg-settings-browse" value="' . $label . '" />';
601 $html .= $this->get_field_description( $args );
602
603 echo $html;
604 }
605
606 /**
607 * Displays a password field for a settings field.
608 *
609 * @since 1.0.0
610 * @param array $args Settings field args.
611 */
612 public function callback_password( $args ) {
613 $value = esc_attr( $this->get_option( $args['id'], $args['section'], '' ) );
614 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
615
616 $html = sprintf( '<input type="password" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
617 $html .= $this->get_field_description( $args );
618
619 echo $html;
620 }
621
622 /**
623 * Displays a color picker field for a settings field.
624 *
625 * @since 1.0.0
626 * @param array $args Settings field args.
627 */
628 public function callback_color( $args ) {
629 $value = esc_attr( $this->get_option( $args['id'], $args['section'], '#ffffff' ) );
630 $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
631
632 $html = sprintf( '<input type="text" class="%1$s-text ayg-color-picker" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s" data-default-color="%5$s" />', $size, $args['section'], $args['id'], $value, '#ffffff' );
633 $html .= $this->get_field_description( $args );
634
635 echo $html;
636 }
637
638 /**
639 * Displays a select box for creating the pages select box.
640 *
641 * @since 1.0.0
642 * @param array $args Settings field args.
643 */
644 public function callback_pages( $args ) {
645 $dropdown_args = array(
646 'show_option_none' => '-- ' . __( 'Select a page', 'automatic-youtube-gallery' ) . ' --',
647 'option_none_value' => -1,
648 'selected' => esc_attr($this->get_option($args['id'], $args['section'], -1 ) ),
649 'name' => $args['section'] . '[' . $args['id'] . ']',
650 'id' => $args['section'] . '[' . $args['id'] . ']',
651 'echo' => 0
652 );
653
654 $html = wp_dropdown_pages( $dropdown_args );
655 $html .= $this->get_field_description( $args );
656
657 echo $html;
658 }
659
660 /**
661 * Get field description for display.
662 *
663 * @since 1.0.0
664 * @param array $args Settings field args.
665 */
666 public function get_field_description( $args ) {
667 if ( ! empty( $args['description'] ) ) {
668 $description = sprintf( '<p class="description">%s</p>', $args['description'] );
669 } else {
670 $description = '';
671 }
672
673 return $description;
674 }
675
676 /**
677 * Sanitize callback for Settings API.
678 *
679 * @since 1.0.0
680 * @param array $options The unsanitized collection of options.
681 * @return The collection of sanitized values.
682 */
683 public function sanitize_options( $options ) {
684 if ( ! $options ) {
685 return $options;
686 }
687
688 foreach ( $options as $option_slug => $option_value ) {
689 $sanitize_callback = $this->get_sanitize_callback( $option_slug );
690
691 // If callback is set, call it
692 if ( $sanitize_callback ) {
693 $options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
694 continue;
695 }
696 }
697
698 return $options;
699 }
700
701 /**
702 * Get sanitization callback for given option slug.
703 *
704 * @since 1.0.0
705 * @param string $slug Option slug.
706 * @return mixed String or bool false.
707 */
708 public function get_sanitize_callback( $slug = '' ) {
709 if ( empty( $slug ) ) {
710 return false;
711 }
712
713 // Iterate over registered fields and see if we can find proper callback
714 foreach ( $this->fields as $section => $options ) {
715 foreach ( $options as $option ) {
716 if ( $option['name'] != $slug ) {
717 continue;
718 }
719
720 // Return the callback name
721 return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
722 }
723 }
724
725 return false;
726 }
727
728 /**
729 * Get the value of a settings field
730 *
731 * @since 1.0.0
732 * @param string $option Settings field name.
733 * @param string $section The section name this field belongs to
734 * @param string $default Default text if it's not found.
735 * @return string
736 */
737 public function get_option( $option, $section, $default = '' ) {
738 $options = get_option( $section );
739
740 if ( ! empty( $options[ $option ] ) ) {
741 return $options[ $option ];
742 }
743
744 return $default;
745 }
746
747 /**
748 * Dump our plugin transients.
749 *
750 * @since 1.3.0
751 */
752 public function ajax_callback_delete_cache() {
753 check_ajax_referer( 'ayg_ajax_nonce', 'security' );
754
755 if ( current_user_can( 'manage_options' ) ) {
756 ayg_delete_cache();
757 }
758
759 wp_die();
760 }
761
762 }
763