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 / admin.php

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

247 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 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 /**
80 * Enqueue styles for the admin area.
81 *
82 * @since 1.0.0
83 */
84 public function enqueue_styles() {
85 wp_enqueue_style( 'wp-color-picker' );
86
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(
96 AYG_SLUG . '-admin',
97 AYG_URL . 'admin/assets/css/admin.min.css',
98 array(),
99 AYG_VERSION,
100 'all'
101 );
102 }
103
104 /**
105 * Enqueue scripts for the admin area.
106 *
107 * @since 1.0.0
108 */
109 public function enqueue_scripts() {
110 wp_enqueue_media();
111 wp_enqueue_script( 'wp-color-picker' );
112
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(
122 AYG_SLUG . '-admin',
123 AYG_URL . 'admin/assets/js/admin.min.js',
124 array( 'jquery' ),
125 AYG_VERSION,
126 false
127 );
128
129 wp_localize_script(
130 AYG_SLUG . '-admin',
131 'ayg_admin',
132 array(
133 'ajax_nonce' => wp_create_nonce( 'ayg_ajax_nonce' ),
134 'i18n' => array(
135 'invalid_api_key' => __( 'Invalid API Key', 'automatic-youtube-gallery' ),
136 'cleared' => __( 'Cleared', 'automatic-youtube-gallery' )
137 )
138 )
139 );
140 }
141
142 /**
143 * Add dashboard page link on the plugins menu.
144 *
145 * @since 1.0.0
146 * @param array $links An array of plugin action links.
147 * @return string $links Array of filtered plugin action links.
148 */
149 public function plugin_action_links( $links ) {
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
156 array_unshift( $links, $dashboard_link );
157
158 return $links;
159 }
160
161 /**
162 * Add "Dashboard" menu.
163 *
164 * @since 1.3.0
165 */
166 public function admin_menu() {
167 add_menu_page(
168 __( 'Automatic YouTube Gallery', 'automatic-youtube-gallery' ),
169 __( 'YouTube Gallery', 'automatic-youtube-gallery' ),
170 'manage_options',
171 'automatic-youtube-gallery',
172 array( $this, 'display_dashboard_content' ),
173 'dashicons-video-alt3',
174 10
175 );
176
177 add_submenu_page(
178 'automatic-youtube-gallery',
179 __( 'Dashboard', 'automatic-youtube-gallery' ),
180 __( 'Dashboard', 'automatic-youtube-gallery' ),
181 'manage_options',
182 'automatic-youtube-gallery',
183 array( $this, 'display_dashboard_content' )
184 );
185 }
186
187 /**
188 * Display dashboard content.
189 *
190 * @since 1.3.0
191 */
192 public function display_dashboard_content() {
193 $general_settings = get_option( 'ayg_general_settings' );
194
195 $tabs = array(
196 'dashboard' => __( 'Build Gallery', 'automatic-youtube-gallery' )
197 );
198
199 $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'dashboard';
200
201 require_once AYG_DIR . 'admin/templates/dashboard.php';
202 }
203
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 /**
229 * Save API Key.
230 *
231 * @since 1.3.0
232 */
233 public function ajax_callback_save_api_key() {
234 check_ajax_referer( 'ayg_ajax_nonce', 'security' );
235
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'] );
239
240 update_option( 'ayg_general_settings', $general_settings );
241 }
242
243 wp_die();
244 }
245
246 }
247