| @@ -48,21 +48,20 @@ | ||
| 48 | 48 | */ |
| 49 | 49 | protected $fields = array(); |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | - * Add a settings menu for the plugin. | |
| 52 | + * Add "Settings" menu. | |
| 53 | 53 | * |
| 54 | 54 | * @since 1.0.0 |
| 55 | 55 | */ |
| 56 | - public function add_settings_menu() { | |
| 57 | - add_menu_page( | |
| 58 | - __( 'Automatic YouTube Gallery', 'automatic-youtube-gallery' ), | |
| 59 | - __( 'YouTube Gallery', 'automatic-youtube-gallery' ), | |
| 60 | - 'manage_options', | |
| 61 | - 'automatic-youtube-gallery', | |
| 62 | - array( $this, 'display_settings_form' ), | |
| 63 | - 'dashicons-video-alt3', | |
| 64 | - 10 | |
| 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' ) | |
| 65 | 64 | ); |
| 66 | 65 | } |
| 67 | 66 | |
| 68 | 67 | /** |
| @@ -72,10 +71,11 @@ | ||
| 72 | 71 | */ |
| 73 | 72 | public function display_settings_form() { |
| 74 | 73 | $gallery_settings = get_option( 'ayg_gallery_settings' ); |
| 75 | 74 | |
| 76 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; | |
| 77 | - $active_theme = $gallery_settings['theme']; | |
| 75 | + $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; | |
| 76 | + $active_theme = $gallery_settings['theme']; | |
| 77 | + $pagination_type = $gallery_settings['pagination_type']; | |
| 78 | 78 | |
| 79 | 79 | require_once AYG_DIR . 'admin/templates/settings.php'; |
| 80 | 80 | } |
| 81 | 81 | |
| @@ -100,11 +100,13 @@ | ||
| 100 | 100 | * @return array $tabs Setting tabs array. |
| 101 | 101 | */ |
| 102 | 102 | public function get_tabs() { |
| 103 | 103 | $tabs = array( |
| 104 | - 'general' => __( 'General', 'automatic-youtube-gallery' ), | |
| 105 | - 'gallery' => __( 'Gallery', 'automatic-youtube-gallery' ), | |
| 106 | - 'player' => __( 'Player', 'automatic-youtube-gallery' ) | |
| 104 | + 'general' => __( 'General', 'automatic-youtube-gallery' ), | |
| 105 | + 'gallery' => __( 'Gallery', 'automatic-youtube-gallery' ), | |
| 106 | + 'player' => __( 'Player', 'automatic-youtube-gallery' ), | |
| 107 | + 'livestream' => __( 'Livestream', 'automatic-youtube-gallery' ), | |
| 108 | + 'privacy' => __( 'GDPR Compliance', 'automatic-youtube-gallery' ) | |
| 107 | 109 | ); |
| 108 | 110 | |
| 109 | 111 | return apply_filters( 'ayg_settings_tabs', $tabs ); |
| 110 | 112 | } |
| @@ -117,22 +119,37 @@ | ||
| 117 | 119 | */ |
| 118 | 120 | public function get_sections() { |
| 119 | 121 | $sections = array( |
| 120 | 122 | array( |
| 121 | - 'id' => 'ayg_general_settings', | |
| 122 | - 'title' => __( 'General Settings', 'automatic-youtube-gallery' ), | |
| 123 | - 'tab' => 'general' | |
| 123 | + 'id' => 'ayg_general_settings', | |
| 124 | + 'title' => __( 'General Settings', 'automatic-youtube-gallery' ), | |
| 125 | + 'description' => '', | |
| 126 | + 'tab' => 'general' | |
| 124 | 127 | ), |
| 125 | 128 | array( |
| 126 | - 'id' => 'ayg_gallery_settings', | |
| 127 | - 'title' => __( 'Gallery Settings', 'automatic-youtube-gallery' ), | |
| 128 | - 'tab' => 'gallery' | |
| 129 | + 'id' => 'ayg_gallery_settings', | |
| 130 | + 'title' => __( 'Gallery Settings', 'automatic-youtube-gallery' ), | |
| 131 | + 'description' => '', | |
| 132 | + 'tab' => 'gallery' | |
| 129 | 133 | ), |
| 130 | 134 | array( |
| 131 | - 'id' => 'ayg_player_settings', | |
| 132 | - 'title' => __( 'Player Settings', 'automatic-youtube-gallery' ), | |
| 133 | - 'tab' => 'player' | |
| 134 | - ) | |
| 135 | + 'id' => 'ayg_player_settings', | |
| 136 | + 'title' => __( 'Player Settings', 'automatic-youtube-gallery' ), | |
| 137 | + 'description' => '', | |
| 138 | + 'tab' => 'player' | |
| 139 | + ), | |
| 140 | + array( | |
| 141 | + 'id' => 'ayg_livestream_settings', | |
| 142 | + 'title' => __( 'Livestream Settings', 'automatic-youtube-gallery' ), | |
| 143 | + 'description' => '', | |
| 144 | + 'tab' => 'livestream' | |
| 145 | + ), | |
| 146 | + array( | |
| 147 | + 'id' => 'ayg_privacy_settings', | |
| 148 | + 'title' => __( 'GDPR Compliance', 'automatic-youtube-gallery' ), | |
| 149 | + 'description' => __( 'These options will help with privacy restrictions such as GDPR and the EU Cookie Law.', 'automatic-youtube-gallery' ), | |
| 150 | + 'tab' => 'privacy' | |
| 151 | + ), | |
| 135 | 152 | ); |
| 136 | 153 | |
| 137 | 154 | return apply_filters( 'ayg_settings_sections', $sections ); |
| 138 | 155 | } |
| @@ -154,12 +171,51 @@ | ||
| 154 | 171 | 'https://plugins360.com/automatic-youtube-gallery/how-to-get-youtube-api-key/' |
| 155 | 172 | ), |
| 156 | 173 | 'type' => 'text', |
| 157 | 174 | 'sanitize_callback' => 'sanitize_text_field' |
| 175 | + ), | |
| 176 | + array( | |
| 177 | + 'name' => 'development_mode', | |
| 178 | + 'label' => __( 'Development Mode', 'automatic-youtube-gallery' ), | |
| 179 | + 'description' => __( 'Does not cache API results when checked. We strongly recommend disabling this option when your site is live.', 'automatic-youtube-gallery' ), | |
| 180 | + 'type' => 'checkbox', | |
| 181 | + 'sanitize_callback' => 'intval' | |
| 182 | + ), | |
| 183 | + ), | |
| 184 | + 'ayg_gallery_settings' => ayg_get_gallery_settings_fields(), | |
| 185 | + 'ayg_player_settings' => ayg_get_player_settings_fields(), | |
| 186 | + 'ayg_livestream_settings' => array( | |
| 187 | + array( | |
| 188 | + 'name' => 'fallback_message', | |
| 189 | + 'label' => __( 'Fallback Message', 'automatic-youtube-gallery' ), | |
| 190 | + 'description' => __( 'Enter your Custom HTML message that should be displayed when there is no video streaming live.', 'automatic-youtube-gallery' ), | |
| 191 | + 'type' => 'wysiwyg', | |
| 192 | + 'sanitize_callback' => 'wp_kses_post' | |
| 158 | 193 | ) |
| 159 | 194 | ), |
| 160 | - 'ayg_gallery_settings' => ayg_get_gallery_settings_fields(), | |
| 161 | - 'ayg_player_settings' => ayg_get_player_settings_fields() | |
| 195 | + 'ayg_privacy_settings' => array( | |
| 196 | + array( | |
| 197 | + 'name' => 'cookie_consent', | |
| 198 | + 'label' => __( 'Cookie Consent', 'automatic-youtube-gallery' ), | |
| 199 | + 'description' => __( 'Ask for viewer consent to store YouTube cookies before showing videos.', 'automatic-youtube-gallery' ), | |
| 200 | + 'type' => 'checkbox', | |
| 201 | + 'sanitize_callback' => 'intval' | |
| 202 | + ), | |
| 203 | + array( | |
| 204 | + 'name' => 'consent_message', | |
| 205 | + 'label' => __( 'Consent Message', 'automatic-youtube-gallery' ), | |
| 206 | + 'description' => '', | |
| 207 | + 'type' => 'wysiwyg', | |
| 208 | + 'sanitize_callback' => 'wp_kses_post' | |
| 209 | + ), | |
| 210 | + array( | |
| 211 | + 'name' => 'button_label', | |
| 212 | + 'label' => __( 'Button Label', 'automatic-youtube-gallery' ), | |
| 213 | + 'description' => '', | |
| 214 | + 'type' => 'text', | |
| 215 | + 'sanitize_callback' => 'sanitize_text_field' | |
| 216 | + ) | |
| 217 | + ) | |
| 162 | 218 | ); |
| 163 | 219 | |
| 164 | 220 | return apply_filters( 'ayg_settings_fields', $fields ); |
| 165 | 221 | } |
| @@ -231,9 +287,9 @@ | ||
| 231 | 287 | */ |
| 232 | 288 | public function settings_section_callback( $args ) { |
| 233 | 289 | foreach ( $this->sections as $section ) { |
| 234 | 290 | if ( $section['id'] == $args['id'] ) { |
| 235 | - printf( '<div class="inside">%s</div>', sanitize_text_field( $section['description'] ) ); | |
| 291 | + printf( '<div class="inside">%s</div>', wp_kses_post( $section['description'] ) ); | |
| 236 | 292 | break; |
| 237 | 293 | } |
| 238 | 294 | } |
| 239 | 295 | } |
| @@ -559,45 +615,11 @@ | ||
| 559 | 615 | } |
| 560 | 616 | } |
| 561 | 617 | |
| 562 | 618 | return false; |
| 563 | - } | |
| 619 | + } | |
| 564 | 620 | |
| 565 | 621 | /** |
| 566 | - * Dump our plugin transients. | |
| 567 | - * | |
| 568 | - * @since 1.0.0 | |
| 569 | - */ | |
| 570 | - public function delete_cache() { | |
| 571 | - // If delete cache button clicked | |
| 572 | - if ( isset( $_POST[ 'ayg_delete_cache' ] ) ) { | |
| 573 | - | |
| 574 | - // Run a quick security check | |
| 575 | - if ( ! check_admin_referer( 'ayg_delete_cache_nonce', 'ayg_delete_cache_nonce' ) ) { | |
| 576 | - return; | |
| 577 | - } | |
| 578 | - | |
| 579 | - // Get the current list of transients | |
| 580 | - $transient_keys = get_option( 'ayg_transient_keys', array() ); | |
| 581 | - | |
| 582 | - // For each key, delete that transient | |
| 583 | - foreach ( $transient_keys as $key ) { | |
| 584 | - delete_transient( $key ); | |
| 585 | - } | |
| 586 | - | |
| 587 | - // Reset our DB value | |
| 588 | - update_option( 'ayg_transient_keys', array() ); | |
| 589 | - | |
| 590 | - // Redirect | |
| 591 | - $base_url = admin_url( 'admin.php?page=automatic-youtube-gallery' ); | |
| 592 | - $redirect = add_query_arg( 'cache_deleted', 1, $base_url ); | |
| 593 | - | |
| 594 | - wp_redirect( $redirect ); | |
| 595 | - exit(); | |
| 596 | - } | |
| 597 | - } | |
| 598 | - | |
| 599 | - /** | |
| 600 | 622 | * Get the value of a settings field |
| 601 | 623 | * |
| 602 | 624 | * @since 1.0.0 |
| 603 | 625 | * @param string $option Settings field name. |
| @@ -613,17 +635,21 @@ | ||
| 613 | 635 | } |
| 614 | 636 | |
| 615 | 637 | return $default; |
| 616 | 638 | } |
| 617 | - | |
| 639 | + | |
| 618 | 640 | /** |
| 619 | - * Display Admin Notices. | |
| 641 | + * Dump our plugin transients. | |
| 620 | 642 | * |
| 621 | - * @since 1.0.0 | |
| 643 | + * @since 1.3.0 | |
| 622 | 644 | */ |
| 623 | - public function admin_notices() { | |
| 624 | - if ( isset( $_GET['cache_deleted'] ) ) { | |
| 625 | - printf( '<div class="notice notice-success"><p>%s</p></div>', __( 'Cache Deleted.', 'automatic-youtube-gallery' ) ); | |
| 626 | - } | |
| 627 | - } | |
| 645 | + public function ajax_callback_delete_cache() { | |
| 646 | + check_ajax_referer( 'ayg_ajax_nonce', 'security' ); | |
| 647 | + | |
| 648 | + if ( current_user_can( 'manage_options' ) ) { | |
| 649 | + ayg_delete_cache(); | |
| 650 | + } | |
| 651 | + | |
| 652 | + wp_die(); | |
| 653 | + } | |
| 628 | 654 | |
| 629 | 655 | } |