| @@ -21,8 +21,40 @@ | ||
| 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 livestream settings | |
| 34 | + if ( false == get_option( 'ayg_livestream_settings' ) ) { | |
| 35 | + add_option( 'ayg_livestream_settings', $defaults['ayg_livestream_settings'] ); | |
| 36 | + } | |
| 37 | + | |
| 38 | + // Insert the privacy settings | |
| 39 | + if ( false == get_option( 'ayg_privacy_settings' ) ) { | |
| 40 | + add_option( 'ayg_privacy_settings', $defaults['ayg_privacy_settings'] ); | |
| 41 | + } | |
| 42 | + | |
| 43 | + // Create a custom database table "{$wpdb->prefix}ayg_videos" | |
| 44 | + if ( version_compare( AYG_VERSION, '2.1.0', '<=' ) ) { | |
| 45 | + ayg_db_create_videos_table(); | |
| 46 | + } | |
| 47 | + | |
| 48 | + // Delete the plugin cache | |
| 49 | + ayg_delete_cache(); | |
| 50 | + | |
| 51 | + // Update the plugin version | |
| 52 | + update_option( 'ayg_version', AYG_VERSION ); | |
| 53 | + } | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 25 | 57 | * Enqueue styles for the admin area. |
| 26 | 58 | * |
| 27 | 59 | * @since 1.0.0 |
| 28 | 60 | */ |
| @@ -30,9 +62,9 @@ | ||
| 30 | 62 | wp_enqueue_style( 'wp-color-picker' ); |
| 31 | 63 | |
| 32 | 64 | wp_enqueue_style( |
| 33 | 65 | AYG_SLUG . '-admin', |
| 34 | - AYG_URL . 'admin/assets/css/admin.css', | |
| 66 | + AYG_URL . 'admin/assets/css/admin.min.css', | |
| 35 | 67 | array(), |
| 36 | 68 | AYG_VERSION, |
| 37 | 69 | 'all' |
| 38 | 70 | ); |
| @@ -48,9 +80,9 @@ | ||
| 48 | 80 | wp_enqueue_script( 'wp-color-picker' ); |
| 49 | 81 | |
| 50 | 82 | wp_enqueue_script( |
| 51 | 83 | AYG_SLUG . '-admin', |
| 52 | - AYG_URL . 'admin/assets/js/admin.js', | |
| 84 | + AYG_URL . 'admin/assets/js/admin.min.js', | |
| 53 | 85 | array( 'jquery' ), |
| 54 | 86 | AYG_VERSION, |
| 55 | 87 | false |
| 56 | 88 | ); |
| @@ -58,13 +90,13 @@ | ||
| 58 | 90 | wp_localize_script( |
| 59 | 91 | AYG_SLUG . '-admin', |
| 60 | 92 | 'ayg_admin', |
| 61 | 93 | array( |
| 62 | - 'i18n' => array( | |
| 94 | + 'ajax_nonce' => wp_create_nonce( 'ayg_ajax_nonce' ), | |
| 95 | + 'i18n' => array( | |
| 63 | 96 | 'invalid_api_key' => __( 'Invalid API Key', 'automatic-youtube-gallery' ), |
| 64 | 97 | 'cleared' => __( 'Cleared', 'automatic-youtube-gallery' ) |
| 65 | - ), | |
| 66 | - 'ajax_nonce' => wp_create_nonce( 'ayg_admin_ajax_nonce' ) | |
| 98 | + ) | |
| 67 | 99 | ) |
| 68 | 100 | ); |
| 69 | 101 | } |
| 70 | 102 | |
| @@ -75,9 +107,14 @@ | ||
| 75 | 107 | * @param array $links An array of plugin action links. |
| 76 | 108 | * @return string $links Array of filtered plugin action links. |
| 77 | 109 | */ |
| 78 | 110 | 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' ) ); | |
| 111 | + $dashboard_link = sprintf( | |
| 112 | + '<a href="%s">%s</a>', | |
| 113 | + admin_url( 'admin.php?page=automatic-youtube-gallery' ), | |
| 114 | + __( 'Build Gallery', 'automatic-youtube-gallery' ) | |
| 115 | + ); | |
| 116 | + | |
| 80 | 117 | array_unshift( $links, $dashboard_link ); |
| 81 | 118 | |
| 82 | 119 | return $links; |
| 83 | 120 | } |
| @@ -113,9 +150,9 @@ | ||
| 113 | 150 | * |
| 114 | 151 | * @since 1.3.0 |
| 115 | 152 | */ |
| 116 | 153 | public function display_dashboard_content() { |
| 117 | - $general_settings = get_option( 'ayg_general_settings', array() ); | |
| 154 | + $general_settings = get_option( 'ayg_general_settings' ); | |
| 118 | 155 | |
| 119 | 156 | $tabs = array( |
| 120 | 157 | 'dashboard' => __( 'Build Gallery', 'automatic-youtube-gallery' ) |
| 121 | 158 | ); |
| @@ -125,16 +162,40 @@ | ||
| 125 | 162 | require_once AYG_DIR . 'admin/templates/dashboard.php'; |
| 126 | 163 | } |
| 127 | 164 | |
| 128 | 165 | /** |
| 166 | + * Prints admin screen notices. | |
| 167 | + * | |
| 168 | + * @since 2.0.0 | |
| 169 | + */ | |
| 170 | + public function admin_notices() { | |
| 171 | + $general_settings = get_option( 'ayg_general_settings' ); | |
| 172 | + | |
| 173 | + if ( isset( $general_settings['development_mode'] ) && ! empty( $general_settings['development_mode'] ) ) { | |
| 174 | + ?> | |
| 175 | + <div class="notice notice-info"> | |
| 176 | + <p> | |
| 177 | + <?php | |
| 178 | + printf( | |
| 179 | + __( '<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' ), | |
| 180 | + esc_url( admin_url( 'admin.php?page=automatic-youtube-gallery-settings' ) ) | |
| 181 | + ); | |
| 182 | + ?> | |
| 183 | + </p> | |
| 184 | + </div> | |
| 185 | + <?php | |
| 186 | + } | |
| 187 | + } | |
| 188 | + | |
| 189 | + /** | |
| 129 | 190 | * Save API Key. |
| 130 | 191 | * |
| 131 | 192 | * @since 1.3.0 |
| 132 | 193 | */ |
| 133 | 194 | public function ajax_callback_save_api_key() { |
| 134 | - check_ajax_referer( 'ayg_admin_ajax_nonce', 'security' ); | |
| 195 | + check_ajax_referer( 'ayg_ajax_nonce', 'security' ); | |
| 135 | 196 | |
| 136 | - $general_settings = get_option( 'ayg_general_settings', array() ); | |
| 197 | + $general_settings = get_option( 'ayg_general_settings' ); | |
| 137 | 198 | $general_settings['api_key'] = sanitize_text_field( $_POST['api_key'] ); |
| 138 | 199 | |
| 139 | 200 | update_option( 'ayg_general_settings', $general_settings ); |
| 140 | 201 | |