| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The admin-specific functionality of the plugin. |
| 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 class. |
| 19 |
* |
| 20 |
* @since 1.0.0 |
| 21 |
*/ |
| 22 |
class AYG_Admin { |
| 23 |
|
| 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 gallery settings |
| 34 |
$gallery_settings = get_option( 'ayg_gallery_settings' ); |
| 35 |
|
| 36 |
if ( ! is_array( $gallery_settings ) || empty( $gallery_settings ) ) { |
| 37 |
$gallery_settings = $defaults['ayg_gallery_settings']; |
| 38 |
update_option( 'ayg_gallery_settings', $gallery_settings ); |
| 39 |
} |
| 40 |
|
| 41 |
// Insert the strings settings |
| 42 |
if ( false == get_option( 'ayg_strings_settings' ) ) { |
| 43 |
$strings_settings = array( |
| 44 |
'more_button_label' => ! empty( $gallery_settings['more_button_label'] ) ? $gallery_settings['more_button_label'] : $defaults['ayg_strings_settings']['more_button_label'], |
| 45 |
'previous_button_label' => ! empty( $gallery_settings['previous_button_label'] ) ? $gallery_settings['previous_button_label'] : $defaults['ayg_strings_settings']['previous_button_label'], |
| 46 |
'next_button_label' => ! empty( $gallery_settings['next_button_label'] ) ? $gallery_settings['next_button_label'] : $defaults['ayg_strings_settings']['next_button_label'], |
| 47 |
'show_more_label' => $defaults['ayg_strings_settings']['show_more_label'], |
| 48 |
'show_less_label' => $defaults['ayg_strings_settings']['show_less_label'], |
| 49 |
); |
| 50 |
|
| 51 |
add_option( 'ayg_strings_settings', $strings_settings ); |
| 52 |
} |
| 53 |
|
| 54 |
// Update the player settings |
| 55 |
$player_settings = get_option( 'ayg_player_settings' ); |
| 56 |
|
| 57 |
if ( ! is_array( $player_settings ) || empty( $player_settings ) ) { |
| 58 |
$player_settings = $defaults['ayg_player_settings']; |
| 59 |
update_option( 'ayg_player_settings', $player_settings ); |
| 60 |
} |
| 61 |
|
| 62 |
if ( ! array_key_exists( 'player_type', $player_settings ) ) { |
| 63 |
$player_settings['player_type'] = $defaults['ayg_player_settings']['player_type']; |
| 64 |
$player_settings['player_color'] = $defaults['ayg_player_settings']['player_color']; |
| 65 |
|
| 66 |
update_option( 'ayg_player_settings', $player_settings ); |
| 67 |
} |
| 68 |
|
| 69 |
// Insert the livestream settings |
| 70 |
if ( false == get_option( 'ayg_livestream_settings' ) ) { |
| 71 |
add_option( 'ayg_livestream_settings', $defaults['ayg_livestream_settings'] ); |
| 72 |
} |
| 73 |
|
| 74 |
// Insert the privacy settings |
| 75 |
if ( false == get_option( 'ayg_privacy_settings' ) ) { |
| 76 |
add_option( 'ayg_privacy_settings', $defaults['ayg_privacy_settings'] ); |
| 77 |
} |
| 78 |
|
| 79 |
// Create custom database tables |
| 80 |
ayg_db_create_custom_tables(); |
| 81 |
|
| 82 |
// Delete the plugin cache |
| 83 |
ayg_delete_cache(); |
| 84 |
|
| 85 |
// Update the plugin version |
| 86 |
update_option( 'ayg_version', AYG_VERSION ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Enqueue styles for the admin area. |
| 92 |
* |
| 93 |
* @since 1.0.0 |
| 94 |
*/ |
| 95 |
public function enqueue_styles() { |
| 96 |
wp_enqueue_style( 'wp-color-picker' ); |
| 97 |
|
| 98 |
wp_enqueue_style( |
| 99 |
AYG_SLUG . '-magnific-popup', |
| 100 |
AYG_URL . 'vendor/magnific-popup/magnific-popup.min.css', |
| 101 |
array(), |
| 102 |
'1.2.0', |
| 103 |
'all' |
| 104 |
); |
| 105 |
|
| 106 |
wp_enqueue_style( |
| 107 |
AYG_SLUG . '-admin', |
| 108 |
AYG_URL . 'admin/assets/css/admin.min.css', |
| 109 |
array(), |
| 110 |
AYG_VERSION, |
| 111 |
'all' |
| 112 |
); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Enqueue scripts for the admin area. |
| 117 |
* |
| 118 |
* @since 1.0.0 |
| 119 |
*/ |
| 120 |
public function enqueue_scripts() { |
| 121 |
wp_enqueue_media(); |
| 122 |
wp_enqueue_script( 'wp-color-picker' ); |
| 123 |
|
| 124 |
wp_enqueue_script( |
| 125 |
AYG_SLUG . '-magnific-popup', |
| 126 |
AYG_URL . 'vendor/magnific-popup/magnific-popup.min.js', |
| 127 |
array( 'jquery' ), |
| 128 |
'1.2.0', |
| 129 |
array( 'strategy' => 'defer' ) |
| 130 |
); |
| 131 |
|
| 132 |
wp_enqueue_script( |
| 133 |
AYG_SLUG . '-admin', |
| 134 |
AYG_URL . 'admin/assets/js/admin.min.js', |
| 135 |
array( 'jquery' ), |
| 136 |
AYG_VERSION, |
| 137 |
false |
| 138 |
); |
| 139 |
|
| 140 |
wp_localize_script( |
| 141 |
AYG_SLUG . '-admin', |
| 142 |
'ayg_admin', |
| 143 |
array( |
| 144 |
'ajax_nonce' => wp_create_nonce( 'ayg_ajax_nonce' ), |
| 145 |
'i18n' => array( |
| 146 |
'invalid_api_key' => __( 'Invalid API Key', 'automatic-youtube-gallery' ), |
| 147 |
'cleared' => __( 'Cleared', 'automatic-youtube-gallery' ) |
| 148 |
) |
| 149 |
) |
| 150 |
); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Add dashboard page link on the plugins menu. |
| 155 |
* |
| 156 |
* @since 1.0.0 |
| 157 |
* @param array $links An array of plugin action links. |
| 158 |
* @return string $links Array of filtered plugin action links. |
| 159 |
*/ |
| 160 |
public function plugin_action_links( $links ) { |
| 161 |
$dashboard_link = sprintf( |
| 162 |
'<a href="%s">%s</a>', |
| 163 |
admin_url( 'admin.php?page=automatic-youtube-gallery' ), |
| 164 |
__( 'Build Gallery', 'automatic-youtube-gallery' ) |
| 165 |
); |
| 166 |
|
| 167 |
array_unshift( $links, $dashboard_link ); |
| 168 |
|
| 169 |
return $links; |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* Add "Dashboard" menu. |
| 174 |
* |
| 175 |
* @since 1.3.0 |
| 176 |
*/ |
| 177 |
public function admin_menu() { |
| 178 |
add_menu_page( |
| 179 |
__( 'Automatic YouTube Gallery', 'automatic-youtube-gallery' ), |
| 180 |
__( 'YouTube Gallery', 'automatic-youtube-gallery' ), |
| 181 |
'manage_options', |
| 182 |
'automatic-youtube-gallery', |
| 183 |
array( $this, 'display_dashboard_content' ), |
| 184 |
'dashicons-video-alt3', |
| 185 |
10 |
| 186 |
); |
| 187 |
|
| 188 |
add_submenu_page( |
| 189 |
'automatic-youtube-gallery', |
| 190 |
__( 'Dashboard', 'automatic-youtube-gallery' ), |
| 191 |
__( 'Dashboard', 'automatic-youtube-gallery' ), |
| 192 |
'manage_options', |
| 193 |
'automatic-youtube-gallery', |
| 194 |
array( $this, 'display_dashboard_content' ) |
| 195 |
); |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Display dashboard content. |
| 200 |
* |
| 201 |
* @since 1.3.0 |
| 202 |
*/ |
| 203 |
public function display_dashboard_content() { |
| 204 |
$general_settings = ayg_get_option( 'ayg_general_settings' ); |
| 205 |
|
| 206 |
$tabs = array( |
| 207 |
'dashboard' => __( 'Build Gallery', 'automatic-youtube-gallery' ) |
| 208 |
); |
| 209 |
|
| 210 |
$active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'dashboard'; |
| 211 |
|
| 212 |
require_once AYG_DIR . 'admin/templates/dashboard.php'; |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* Prints admin screen notices. |
| 217 |
* |
| 218 |
* @since 2.0.0 |
| 219 |
*/ |
| 220 |
public function admin_notices() { |
| 221 |
$general_settings = ayg_get_option( 'ayg_general_settings' ); |
| 222 |
|
| 223 |
if ( isset( $general_settings['development_mode'] ) && ! empty( $general_settings['development_mode'] ) ) { |
| 224 |
?> |
| 225 |
<div class="notice notice-info"> |
| 226 |
<p> |
| 227 |
<?php |
| 228 |
printf( |
| 229 |
__( '<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' ), |
| 230 |
esc_url( admin_url( 'admin.php?page=automatic-youtube-gallery-settings' ) ) |
| 231 |
); |
| 232 |
?> |
| 233 |
</p> |
| 234 |
</div> |
| 235 |
<?php |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* Save API Key. |
| 241 |
* |
| 242 |
* @since 1.3.0 |
| 243 |
*/ |
| 244 |
public function ajax_callback_save_api_key() { |
| 245 |
check_ajax_referer( 'ayg_ajax_nonce', 'security' ); |
| 246 |
|
| 247 |
if ( current_user_can( 'manage_options' ) ) { |
| 248 |
$general_settings = ayg_get_option( 'ayg_general_settings' ); |
| 249 |
$general_settings['api_key'] = sanitize_text_field( $_POST['api_key'] ); |
| 250 |
|
| 251 |
update_option( 'ayg_general_settings', $general_settings ); |
| 252 |
} |
| 253 |
|
| 254 |
wp_die(); |
| 255 |
} |
| 256 |
|
| 257 |
} |
| 258 |
|