| @@ -21,8 +21,63 @@ | ||
| 21 | 21 | */ |
| 22 | 22 | class AYG_Admin { |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | + * Insert missing plugin options. | |
| 26 | + * | |
| 27 | + * @since 1.6.4 | |
| 28 | + */ | |
| 29 | + public function insert_missing_options() { | |
| 30 | + if ( AYG_VERSION !== get_option( 'ayg_version' ) ) { | |
| 31 | + $defaults = ayg_get_default_settings(); | |
| 32 | + | |
| 33 | + // Insert the strings settings | |
| 34 | + if ( false == get_option( 'ayg_strings_settings' ) ) { | |
| 35 | + $gallery_settings = get_option( 'ayg_gallery_settings' ); | |
| 36 | + | |
| 37 | + $strings_settings = array( | |
| 38 | + 'more_button_label' => ! empty( $gallery_settings['more_button_label'] ) ? $gallery_settings['more_button_label'] : $defaults['ayg_strings_settings']['more_button_label'], | |
| 39 | + 'previous_button_label' => ! empty( $gallery_settings['previous_button_label'] ) ? $gallery_settings['previous_button_label'] : $defaults['ayg_strings_settings']['previous_button_label'], | |
| 40 | + 'next_button_label' => ! empty( $gallery_settings['next_button_label'] ) ? $gallery_settings['next_button_label'] : $defaults['ayg_strings_settings']['next_button_label'], | |
| 41 | + 'show_more_label' => $defaults['ayg_strings_settings']['show_more_label'], | |
| 42 | + 'show_less_label' => $defaults['ayg_strings_settings']['show_less_label'], | |
| 43 | + ); | |
| 44 | + | |
| 45 | + add_option( 'ayg_strings_settings', $strings_settings ); | |
| 46 | + } | |
| 47 | + | |
| 48 | + // Update the player settings | |
| 49 | + $player_settings = get_option( 'ayg_player_settings' ); | |
| 50 | + | |
| 51 | + if ( ! array_key_exists( 'player_type', $player_settings ) ) { | |
| 52 | + $player_settings['player_type'] = $defaults['ayg_player_settings']['player_type']; | |
| 53 | + $player_settings['player_color'] = $defaults['ayg_player_settings']['player_color']; | |
| 54 | + | |
| 55 | + update_option( 'ayg_player_settings', $player_settings ); | |
| 56 | + } | |
| 57 | + | |
| 58 | + // Insert the livestream settings | |
| 59 | + if ( false == get_option( 'ayg_livestream_settings' ) ) { | |
| 60 | + add_option( 'ayg_livestream_settings', $defaults['ayg_livestream_settings'] ); | |
| 61 | + } | |
| 62 | + | |
| 63 | + // Insert the privacy settings | |
| 64 | + if ( false == get_option( 'ayg_privacy_settings' ) ) { | |
| 65 | + add_option( 'ayg_privacy_settings', $defaults['ayg_privacy_settings'] ); | |
| 66 | + } | |
| 67 | + | |
| 68 | + // Create custom database tables | |
| 69 | + ayg_db_create_custom_tables(); | |
| 70 | + | |
| 71 | + // Delete the plugin cache | |
| 72 | + ayg_delete_cache(); | |
| 73 | + | |
| 74 | + // Update the plugin version | |
| 75 | + update_option( 'ayg_version', AYG_VERSION ); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 25 | 80 | * Enqueue styles for the admin area. |
| 26 | 81 | * |
| 27 | 82 | * @since 1.0.0 |
| 28 | 83 | */ |
| @@ -29,10 +84,18 @@ | ||
| 29 | 84 | public function enqueue_styles() { |
| 30 | 85 | wp_enqueue_style( 'wp-color-picker' ); |
| 31 | 86 | |
| 32 | 87 | wp_enqueue_style( |
| 88 | + AYG_SLUG . '-magnific-popup', | |
| 89 | + AYG_URL . 'vendor/magnific-popup/magnific-popup.css', | |
| 90 | + array(), | |
| 91 | + '1.2.0', | |
| 92 | + 'all' | |
| 93 | + ); | |
| 94 | + | |
| 95 | + wp_enqueue_style( | |
| 33 | 96 | AYG_SLUG . '-admin', |
| 34 | - AYG_URL . 'admin/assets/css/admin.css', | |
| 97 | + AYG_URL . 'admin/assets/css/admin.min.css', | |
| 35 | 98 | array(), |
| 36 | 99 | AYG_VERSION, |
| 37 | 100 | 'all' |
| 38 | 101 | ); |
| @@ -47,10 +110,18 @@ | ||
| 47 | 110 | wp_enqueue_media(); |
| 48 | 111 | wp_enqueue_script( 'wp-color-picker' ); |
| 49 | 112 | |
| 50 | 113 | wp_enqueue_script( |
| 114 | + AYG_SLUG . '-magnific-popup', | |
| 115 | + AYG_URL . 'vendor/magnific-popup/magnific-popup.min.js', | |
| 116 | + array( 'jquery' ), | |
| 117 | + '1.2.0', | |
| 118 | + array( 'strategy' => 'defer' ) | |
| 119 | + ); | |
| 120 | + | |
| 121 | + wp_enqueue_script( | |
| 51 | 122 | AYG_SLUG . '-admin', |
| 52 | - AYG_URL . 'admin/assets/js/admin.js', | |
| 123 | + AYG_URL . 'admin/assets/js/admin.min.js', | |
| 53 | 124 | array( 'jquery' ), |
| 54 | 125 | AYG_VERSION, |
| 55 | 126 | false |
| 56 | 127 | ); |
| @@ -58,13 +129,13 @@ | ||
| 58 | 129 | wp_localize_script( |
| 59 | 130 | AYG_SLUG . '-admin', |
| 60 | 131 | 'ayg_admin', |
| 61 | 132 | array( |
| 62 | - 'i18n' => array( | |
| 133 | + 'ajax_nonce' => wp_create_nonce( 'ayg_ajax_nonce' ), | |
| 134 | + 'i18n' => array( | |
| 63 | 135 | 'invalid_api_key' => __( 'Invalid API Key', 'automatic-youtube-gallery' ), |
| 64 | 136 | 'cleared' => __( 'Cleared', 'automatic-youtube-gallery' ) |
| 65 | - ), | |
| 66 | - 'ajax_nonce' => wp_create_nonce( 'ayg_admin_ajax_nonce' ) | |
| 137 | + ) | |
| 67 | 138 | ) |
| 68 | 139 | ); |
| 69 | 140 | } |
| 70 | 141 | |
| @@ -75,9 +146,14 @@ | ||
| 75 | 146 | * @param array $links An array of plugin action links. |
| 76 | 147 | * @return string $links Array of filtered plugin action links. |
| 77 | 148 | */ |
| 78 | 149 | public function plugin_action_links( $links ) { |
| 79 | - $dashboard_link = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=automatic-youtube-gallery' ), __( 'Build Gallery', 'automatic-youtube-gallery' ) ); | |
| 150 | + $dashboard_link = sprintf( | |
| 151 | + '<a href="%s">%s</a>', | |
| 152 | + admin_url( 'admin.php?page=automatic-youtube-gallery' ), | |
| 153 | + __( 'Build Gallery', 'automatic-youtube-gallery' ) | |
| 154 | + ); | |
| 155 | + | |
| 80 | 156 | array_unshift( $links, $dashboard_link ); |
| 81 | 157 | |
| 82 | 158 | return $links; |
| 83 | 159 | } |
| @@ -113,9 +189,9 @@ | ||
| 113 | 189 | * |
| 114 | 190 | * @since 1.3.0 |
| 115 | 191 | */ |
| 116 | 192 | public function display_dashboard_content() { |
| 117 | - $general_settings = get_option( 'ayg_general_settings', array() ); | |
| 193 | + $general_settings = get_option( 'ayg_general_settings' ); | |
| 118 | 194 | |
| 119 | 195 | $tabs = array( |
| 120 | 196 | 'dashboard' => __( 'Build Gallery', 'automatic-youtube-gallery' ) |
| 121 | 197 | ); |
| @@ -125,19 +201,45 @@ | ||
| 125 | 201 | require_once AYG_DIR . 'admin/templates/dashboard.php'; |
| 126 | 202 | } |
| 127 | 203 | |
| 128 | 204 | /** |
| 205 | + * Prints admin screen notices. | |
| 206 | + * | |
| 207 | + * @since 2.0.0 | |
| 208 | + */ | |
| 209 | + public function admin_notices() { | |
| 210 | + $general_settings = get_option( 'ayg_general_settings' ); | |
| 211 | + | |
| 212 | + if ( isset( $general_settings['development_mode'] ) && ! empty( $general_settings['development_mode'] ) ) { | |
| 213 | + ?> | |
| 214 | + <div class="notice notice-info"> | |
| 215 | + <p> | |
| 216 | + <?php | |
| 217 | + printf( | |
| 218 | + __( '<strong>Automatic YouTube Gallery:</strong> You have <a href="%s">development mode</a> enabled. We do not cache API results in this mode. While this is ok when you are testing the plugin, we strongly recommend disabling this option when your site goes live.', 'automatic-youtube-gallery' ), | |
| 219 | + esc_url( admin_url( 'admin.php?page=automatic-youtube-gallery-settings' ) ) | |
| 220 | + ); | |
| 221 | + ?> | |
| 222 | + </p> | |
| 223 | + </div> | |
| 224 | + <?php | |
| 225 | + } | |
| 226 | + } | |
| 227 | + | |
| 228 | + /** | |
| 129 | 229 | * Save API Key. |
| 130 | 230 | * |
| 131 | 231 | * @since 1.3.0 |
| 132 | 232 | */ |
| 133 | 233 | public function ajax_callback_save_api_key() { |
| 134 | - check_ajax_referer( 'ayg_admin_ajax_nonce', 'security' ); | |
| 234 | + check_ajax_referer( 'ayg_ajax_nonce', 'security' ); | |
| 135 | 235 | |
| 136 | - $general_settings = get_option( 'ayg_general_settings', array() ); | |
| 137 | - $general_settings['api_key'] = sanitize_text_field( $_POST['api_key'] ); | |
| 236 | + if ( current_user_can( 'manage_options' ) ) { | |
| 237 | + $general_settings = get_option( 'ayg_general_settings' ); | |
| 238 | + $general_settings['api_key'] = sanitize_text_field( $_POST['api_key'] ); | |
| 138 | 239 | |
| 139 | - update_option( 'ayg_general_settings', $general_settings ); | |
| 240 | + update_option( 'ayg_general_settings', $general_settings ); | |
| 241 | + } | |
| 140 | 242 | |
| 141 | 243 | wp_die(); |
| 142 | 244 | } |
| 143 | 245 | |