PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.7.1
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.7.1
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 / includes / init.php

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

239 lines 6.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 file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link https://plugins360.com
10 * @since 1.0.0
11 *
12 * @package Automatic_YouTube_Gallery
13 */
14
15 // Exit if accessed directly
16 if ( ! defined( 'WPINC' ) ) {
17 die;
18 }
19
20 /**
21 * AYG_Init - The main plugin class.
22 *
23 * @since 1.0.0
24 */
25 class AYG_Init {
26
27 /**
28 * The loader that's responsible for maintaining and registering all hooks that power
29 * the plugin.
30 *
31 * @since 1.0.0
32 * @access protected
33 * @var AYG_Loader $loader Maintains and registers all hooks for the plugin.
34 */
35 protected $loader;
36
37 /**
38 * Get things started.
39 *
40 * @since 1.0.0
41 */
42 public function __construct() {
43 $this->load_dependencies();
44 $this->set_locale();
45 $this->define_admin_hooks();
46 $this->define_public_hooks();
47 $this->define_block_hooks();
48 $this->define_widget_hooks();
49 }
50
51 /**
52 * Load the required dependencies for this plugin.
53 *
54 * Create an instance of the loader which will be used to register the hooks
55 * with WordPress.
56 *
57 * @since 1.0.0
58 * @access private
59 */
60 private function load_dependencies() {
61 /**
62 * The class responsible for orchestrating the actions and filters of the
63 * core plugin.
64 */
65 require_once AYG_DIR . 'includes/loader.php';
66
67 /**
68 * The class responsible for defining internationalization functionality
69 * of the plugin.
70 */
71 require_once AYG_DIR . 'includes/i18n.php';
72
73 /**
74 * A wrapper class for the Youtube Data API v3.
75 */
76 require_once AYG_DIR . 'includes/youtube-api.php';
77
78 /**
79 * The file that holds the general helper functions.
80 */
81 require_once AYG_DIR . 'includes/functions.php';
82
83 /**
84 * The classes responsible for defining all actions that occur in the admin area.
85 */
86 require_once AYG_DIR . 'admin/admin.php';
87 require_once AYG_DIR . 'admin/settings.php';
88
89 /**
90 * The class responsible for defining all actions that occur in the public-facing
91 * side of the site.
92 */
93 require_once AYG_DIR . 'public/public.php';
94 require_once AYG_DIR . 'public/cron.php';
95
96 /**
97 * The class responsible for defining all actions that occur in the gutenberg block.
98 */
99 require_once AYG_DIR. 'block/block.php';
100
101 /**
102 * The class responsible for defining all actions that occur in the widget.
103 */
104 require_once AYG_DIR . 'widget/widget.php';
105
106 /**
107 * Create an instance of the loader.
108 */
109 $this->loader = new AYG_Loader();
110 }
111
112 /**
113 * Define the locale for this plugin for internationalization.
114 *
115 * @since 1.0.0
116 * @access private
117 */
118 private function set_locale() {
119 $i18n = new AYG_i18n();
120 $this->loader->add_action( 'plugins_loaded', $i18n, 'load_plugin_textdomain' );
121 }
122
123 /**
124 * Register all of the hooks related to the admin area functionality
125 * of the plugin.
126 *
127 * @since 1.0.0
128 * @access private
129 */
130 private function define_admin_hooks() {
131 // Hooks common to all admin pages
132 $admin = new AYG_Admin();
133
134 $this->loader->add_action( 'admin_init', $admin, 'insert_missing_options', 1 );
135 $this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_styles' );
136 $this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_scripts' );
137 $this->loader->add_action( 'elementor/editor/after_enqueue_styles', $admin, 'enqueue_styles' );
138 $this->loader->add_action( 'elementor/editor/after_enqueue_scripts', $admin, 'enqueue_scripts' );
139 $this->loader->add_action( 'admin_menu', $admin, 'admin_menu' );
140 $this->loader->add_action( 'admin_notices', $admin, 'admin_notices' );
141 $this->loader->add_action( 'wp_ajax_ayg_save_api_key', $admin, 'ajax_callback_save_api_key' );
142
143 $this->loader->add_filter( 'plugin_action_links_' . AYG_FILE_NAME, $admin, 'plugin_action_links' );
144
145 // Hooks specific to the settings page
146 $settings = new AYG_Admin_Settings();
147
148 $this->loader->add_action( 'admin_menu', $settings, 'admin_menu' );
149 $this->loader->add_action( 'admin_init', $settings, 'admin_init' );
150 $this->loader->add_action( 'wp_ajax_ayg_delete_cache', $settings, 'ajax_callback_delete_cache' );
151 }
152
153 /**
154 * Register all of the hooks related to the public-facing functionality
155 * of the plugin.
156 *
157 * @since 1.0.0
158 * @access private
159 */
160 private function define_public_hooks() {
161 // Hooks common to all public pages
162 $public = new AYG_Public();
163
164 $this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_styles' );
165 $this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_scripts' );
166 $this->loader->add_action( 'enqueue_block_editor_assets', $public, 'enqueue_block_editor_assets' );
167 $this->loader->add_action( 'elementor/editor/after_enqueue_scripts', $public, 'enqueue_block_editor_assets' );
168 $this->loader->add_action( 'elementor/preview/enqueue_scripts', $public, 'enqueue_block_editor_assets' );
169 $this->loader->add_action( 'wp_ajax_ayg_load_videos', $public, 'ajax_callback_load_videos' );
170 $this->loader->add_action( 'wp_ajax_nopriv_ayg_load_videos', $public, 'ajax_callback_load_videos' );
171 $this->loader->add_action( 'wp_ajax_ayg_set_cookie', $public, 'set_gdpr_cookie' );
172 $this->loader->add_action( 'wp_ajax_nopriv_ayg_set_cookie', $public, 'set_gdpr_cookie' );
173
174 $this->loader->add_filter( 'smush_skip_iframe_from_lazy_load', $public, 'smush', 999, 2 );
175
176 // Hooks specific to the cron jobs
177 $cron = new AYG_Public_Cron();
178
179 $this->loader->add_action( 'wp', $cron, 'schedule_events' );
180 $this->loader->add_action( 'ayg_schedule_weekly', $cron, 'cron_event' );
181
182 $this->loader->add_filter( 'cron_schedules', $cron, 'cron_schedules' );
183 }
184
185 /**
186 * Register all of the hooks related to the gutenberg block.
187 *
188 * @since 1.0.0
189 * @access private
190 */
191 private function define_block_hooks() {
192 if ( is_admin() ) {
193 global $pagenow;
194 if ( 'widgets.php' === $pagenow ) return;
195 }
196
197 global $wp_version;
198
199 $block = new AYG_Block();
200
201 $this->loader->add_action( 'init', $block, 'register_block_type' );
202 $this->loader->add_action( 'enqueue_block_editor_assets', $block, 'enqueue_block_editor_assets' );
203
204 if ( version_compare( $wp_version, '5.8', '>=' ) ) {
205 $this->loader->add_filter( 'block_categories_all', $block, 'block_categories' );
206 } else {
207 $this->loader->add_filter( 'block_categories', $block, 'block_categories' );
208 }
209 }
210
211 /**
212 * Register all of the hooks related to the widget.
213 *
214 * @since 2.1.0
215 * @access private
216 */
217 private function define_widget_hooks() {
218 $this->loader->add_action( 'widgets_init', $this, 'register_widget' );
219 }
220
221 /**
222 * Register the widget.
223 *
224 * @since 2.1.0
225 */
226 public function register_widget() {
227 register_widget( 'AYG_Widget' );
228 }
229
230 /**
231 * Run the loader to execute all of the hooks with WordPress.
232 *
233 * @since 1.0.0
234 */
235 public function run() {
236 $this->loader->run();
237 }
238
239 }