PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.2.0
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.2.0
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.2.0, at admin/admin.php

208 lines 4.9 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 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 ayg_delete_cache();
47 }
48
49 if ( version_compare( AYG_VERSION, '2.2.0', '<=' ) ) {
50 delete_option( 'ayg_gallery_page_ids' );
51 }
52
53 // Update the plugin version
54 update_option( 'ayg_version', AYG_VERSION );
55 }
56 }
57
58 /**
59 * Enqueue styles for the admin area.
60 *
61 * @since 1.0.0
62 */
63 public function enqueue_styles() {
64 wp_enqueue_style( 'wp-color-picker' );
65
66 wp_enqueue_style(
67 AYG_SLUG . '-admin',
68 AYG_URL . 'admin/assets/css/admin.css',
69 array(),
70 AYG_VERSION,
71 'all'
72 );
73 }
74
75 /**
76 * Enqueue scripts for the admin area.
77 *
78 * @since 1.0.0
79 */
80 public function enqueue_scripts() {
81 wp_enqueue_media();
82 wp_enqueue_script( 'wp-color-picker' );
83
84 wp_enqueue_script(
85 AYG_SLUG . '-admin',
86 AYG_URL . 'admin/assets/js/admin.js',
87 array( 'jquery' ),
88 AYG_VERSION,
89 false
90 );
91
92 wp_localize_script(
93 AYG_SLUG . '-admin',
94 'ayg_admin',
95 array(
96 'ajax_nonce' => wp_create_nonce( 'ayg_ajax_nonce' ),
97 'i18n' => array(
98 'invalid_api_key' => __( 'Invalid API Key', 'automatic-youtube-gallery' ),
99 'cleared' => __( 'Cleared', 'automatic-youtube-gallery' )
100 )
101 )
102 );
103 }
104
105 /**
106 * Add dashboard page link on the plugins menu.
107 *
108 * @since 1.0.0
109 * @param array $links An array of plugin action links.
110 * @return string $links Array of filtered plugin action links.
111 */
112 public function plugin_action_links( $links ) {
113 $dashboard_link = sprintf(
114 '<a href="%s">%s</a>',
115 admin_url( 'admin.php?page=automatic-youtube-gallery' ),
116 __( 'Build Gallery', 'automatic-youtube-gallery' )
117 );
118
119 array_unshift( $links, $dashboard_link );
120
121 return $links;
122 }
123
124 /**
125 * Add "Dashboard" menu.
126 *
127 * @since 1.3.0
128 */
129 public function admin_menu() {
130 add_menu_page(
131 __( 'Automatic YouTube Gallery', 'automatic-youtube-gallery' ),
132 __( 'YouTube Gallery', 'automatic-youtube-gallery' ),
133 'manage_options',
134 'automatic-youtube-gallery',
135 array( $this, 'display_dashboard_content' ),
136 'dashicons-video-alt3',
137 10
138 );
139
140 add_submenu_page(
141 'automatic-youtube-gallery',
142 __( 'Dashboard', 'automatic-youtube-gallery' ),
143 __( 'Dashboard', 'automatic-youtube-gallery' ),
144 'manage_options',
145 'automatic-youtube-gallery',
146 array( $this, 'display_dashboard_content' )
147 );
148 }
149
150 /**
151 * Display dashboard content.
152 *
153 * @since 1.3.0
154 */
155 public function display_dashboard_content() {
156 $general_settings = get_option( 'ayg_general_settings' );
157
158 $tabs = array(
159 'dashboard' => __( 'Build Gallery', 'automatic-youtube-gallery' )
160 );
161
162 $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'dashboard';
163
164 require_once AYG_DIR . 'admin/templates/dashboard.php';
165 }
166
167 /**
168 * Prints admin screen notices.
169 *
170 * @since 2.0.0
171 */
172 public function admin_notices() {
173 $general_settings = get_option( 'ayg_general_settings' );
174
175 if ( isset( $general_settings['development_mode'] ) && ! empty( $general_settings['development_mode'] ) ) {
176 ?>
177 <div class="notice notice-info">
178 <p>
179 <?php
180 printf(
181 __( '<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' ),
182 esc_url( admin_url( 'admin.php?page=automatic-youtube-gallery-settings' ) )
183 );
184 ?>
185 </p>
186 </div>
187 <?php
188 }
189 }
190
191 /**
192 * Save API Key.
193 *
194 * @since 1.3.0
195 */
196 public function ajax_callback_save_api_key() {
197 check_ajax_referer( 'ayg_ajax_nonce', 'security' );
198
199 $general_settings = get_option( 'ayg_general_settings' );
200 $general_settings['api_key'] = sanitize_text_field( $_POST['api_key'] );
201
202 update_option( 'ayg_general_settings', $general_settings );
203
204 wp_die();
205 }
206
207 }
208