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

235 lines 6.3 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( 'admin_menu', $admin, 'admin_menu' );
138 $this->loader->add_action( 'admin_notices', $admin, 'admin_notices' );
139 $this->loader->add_action( 'wp_ajax_ayg_save_api_key', $admin, 'ajax_callback_save_api_key' );
140
141 $this->loader->add_filter( 'plugin_action_links_' . AYG_FILE_NAME, $admin, 'plugin_action_links' );
142
143 // Hooks specific to the settings page
144 $settings = new AYG_Admin_Settings();
145
146 $this->loader->add_action( 'admin_menu', $settings, 'admin_menu' );
147 $this->loader->add_action( 'admin_init', $settings, 'admin_init' );
148 $this->loader->add_action( 'wp_ajax_ayg_delete_cache', $settings, 'ajax_callback_delete_cache' );
149 }
150
151 /**
152 * Register all of the hooks related to the public-facing functionality
153 * of the plugin.
154 *
155 * @since 1.0.0
156 * @access private
157 */
158 private function define_public_hooks() {
159 // Hooks common to all public pages
160 $public = new AYG_Public();
161
162 $this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_styles' );
163 $this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_scripts' );
164 $this->loader->add_action( 'enqueue_block_editor_assets', $public, 'enqueue_block_editor_assets' );
165 $this->loader->add_action( 'wp_ajax_ayg_load_more_videos', $public, 'ajax_callback_load_more_videos' );
166 $this->loader->add_action( 'wp_ajax_nopriv_ayg_load_more_videos', $public, 'ajax_callback_load_more_videos' );
167 $this->loader->add_action( 'wp_ajax_ayg_set_cookie', $public, 'set_gdpr_cookie' );
168 $this->loader->add_action( 'wp_ajax_nopriv_ayg_set_cookie', $public, 'set_gdpr_cookie' );
169
170 $this->loader->add_filter( 'smush_skip_iframe_from_lazy_load', $public, 'smush', 999, 2 );
171
172 // Hooks specific to the cron jobs
173 $cron = new AYG_Public_Cron();
174
175 $this->loader->add_action( 'wp', $cron, 'schedule_events' );
176 $this->loader->add_action( 'ayg_schedule_weekly', $cron, 'cron_event' );
177
178 $this->loader->add_filter( 'cron_schedules', $cron, 'cron_schedules' );
179 }
180
181 /**
182 * Register all of the hooks related to the gutenberg block.
183 *
184 * @since 1.0.0
185 * @access private
186 */
187 private function define_block_hooks() {
188 if ( is_admin() ) {
189 global $pagenow;
190 if ( 'widgets.php' === $pagenow ) return;
191 }
192
193 global $wp_version;
194
195 $block = new AYG_Block();
196
197 $this->loader->add_action( 'init', $block, 'register_block_type' );
198 $this->loader->add_action( 'enqueue_block_editor_assets', $block, 'enqueue_block_editor_assets' );
199
200 if ( version_compare( $wp_version, '5.8', '>=' ) ) {
201 $this->loader->add_filter( 'block_categories_all', $block, 'block_categories' );
202 } else {
203 $this->loader->add_filter( 'block_categories', $block, 'block_categories' );
204 }
205 }
206
207 /**
208 * Register all of the hooks related to the widget.
209 *
210 * @since 2.1.0
211 * @access private
212 */
213 private function define_widget_hooks() {
214 $this->loader->add_action( 'widgets_init', $this, 'register_widget' );
215 }
216
217 /**
218 * Register the widget.
219 *
220 * @since 2.1.0
221 */
222 public function register_widget() {
223 register_widget( 'AYG_Widget' );
224 }
225
226 /**
227 * Run the loader to execute all of the hooks with WordPress.
228 *
229 * @since 1.0.0
230 */
231 public function run() {
232 $this->loader->run();
233 }
234
235 }