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

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