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 / includes / init.php

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

225 lines 6.0 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
95 /**
96 * The class responsible for defining all actions that occur in the gutenberg block.
97 */
98 require_once AYG_DIR. 'block/block.php';
99
100 /**
101 * The class responsible for defining all actions that occur in the widget.
102 */
103 require_once AYG_DIR . 'widget/widget.php';
104
105 /**
106 * Create an instance of the loader.
107 */
108 $this->loader = new AYG_Loader();
109 }
110
111 /**
112 * Define the locale for this plugin for internationalization.
113 *
114 * @since 1.0.0
115 * @access private
116 */
117 private function set_locale() {
118 $i18n = new AYG_i18n();
119 $this->loader->add_action( 'plugins_loaded', $i18n, 'load_plugin_textdomain' );
120 }
121
122 /**
123 * Register all of the hooks related to the admin area functionality
124 * of the plugin.
125 *
126 * @since 1.0.0
127 * @access private
128 */
129 private function define_admin_hooks() {
130 // Hooks common to all admin pages
131 $admin = new AYG_Admin();
132
133 $this->loader->add_action( 'admin_init', $admin, 'insert_missing_options', 1 );
134 $this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_styles' );
135 $this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_scripts' );
136 $this->loader->add_action( 'admin_menu', $admin, 'admin_menu' );
137 $this->loader->add_action( 'admin_notices', $admin, 'admin_notices' );
138 $this->loader->add_action( 'wp_ajax_ayg_save_api_key', $admin, 'ajax_callback_save_api_key' );
139
140 $this->loader->add_filter( 'plugin_action_links_' . AYG_FILE_NAME, $admin, 'plugin_action_links' );
141
142 // Hooks specific to the settings page
143 $settings = new AYG_Admin_Settings();
144
145 $this->loader->add_action( 'admin_menu', $settings, 'admin_menu' );
146 $this->loader->add_action( 'admin_init', $settings, 'admin_init' );
147 $this->loader->add_action( 'wp_ajax_ayg_delete_cache', $settings, 'ajax_callback_delete_cache' );
148 }
149
150 /**
151 * Register all of the hooks related to the public-facing functionality
152 * of the plugin.
153 *
154 * @since 1.0.0
155 * @access private
156 */
157 private function define_public_hooks() {
158 $public = new AYG_Public();
159
160 $this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_styles' );
161 $this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_scripts' );
162 $this->loader->add_action( 'enqueue_block_editor_assets', $public, 'enqueue_block_editor_assets' );
163 $this->loader->add_action( 'wp_ajax_ayg_load_more_videos', $public, 'ajax_callback_load_more_videos' );
164 $this->loader->add_action( 'wp_ajax_nopriv_ayg_load_more_videos', $public, 'ajax_callback_load_more_videos' );
165 $this->loader->add_action( 'wp_ajax_ayg_set_cookie', $public, 'set_gdpr_cookie' );
166 $this->loader->add_action( 'wp_ajax_nopriv_ayg_set_cookie', $public, 'set_gdpr_cookie' );
167
168 $this->loader->add_filter( 'smush_skip_iframe_from_lazy_load', $public, 'smush', 999, 2 );
169 }
170
171 /**
172 * Register all of the hooks related to the gutenberg block.
173 *
174 * @since 1.0.0
175 * @access private
176 */
177 private function define_block_hooks() {
178 if ( is_admin() ) {
179 global $pagenow;
180 if ( 'widgets.php' === $pagenow ) return;
181 }
182
183 global $wp_version;
184
185 $block = new AYG_Block();
186
187 $this->loader->add_action( 'init', $block, 'register_block_type' );
188 $this->loader->add_action( 'enqueue_block_editor_assets', $block, 'enqueue_block_editor_assets' );
189
190 if ( version_compare( $wp_version, '5.8', '>=' ) ) {
191 $this->loader->add_filter( 'block_categories_all', $block, 'block_categories' );
192 } else {
193 $this->loader->add_filter( 'block_categories', $block, 'block_categories' );
194 }
195 }
196
197 /**
198 * Register all of the hooks related to the widget.
199 *
200 * @since 2.1.0
201 * @access private
202 */
203 private function define_widget_hooks() {
204 $this->loader->add_action( 'widgets_init', $this, 'register_widget' );
205 }
206
207 /**
208 * Register the widget.
209 *
210 * @since 2.1.0
211 */
212 public function register_widget() {
213 register_widget( 'AYG_Widget' );
214 }
215
216 /**
217 * Run the loader to execute all of the hooks with WordPress.
218 *
219 * @since 1.0.0
220 */
221 public function run() {
222 $this->loader->run();
223 }
224
225 }