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

197 lines 5.1 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 }
49
50 /**
51 * Load the required dependencies for this plugin.
52 *
53 * Create an instance of the loader which will be used to register the hooks
54 * with WordPress.
55 *
56 * @since 1.0.0
57 * @access private
58 */
59 private function load_dependencies() {
60 /**
61 * The class responsible for orchestrating the actions and filters of the
62 * core plugin.
63 */
64 require_once AYG_DIR . 'includes/loader.php';
65
66 /**
67 * The class responsible for defining internationalization functionality
68 * of the plugin.
69 */
70 require_once AYG_DIR . 'includes/i18n.php';
71
72 /**
73 * A wrapper class for the Youtube Data API v3.
74 */
75 require_once AYG_DIR . 'includes/youtube-api.php';
76
77 /**
78 * The file that holds the general helper functions.
79 */
80 require_once AYG_DIR . 'includes/functions.php';
81
82 /**
83 * The classes responsible for defining all actions that occur in the admin area.
84 */
85 require_once AYG_DIR . 'admin/admin.php';
86 require_once AYG_DIR . 'admin/settings.php';
87
88 /**
89 * The class responsible for defining all actions that occur in the public-facing
90 * side of the site.
91 */
92 require_once AYG_DIR . 'public/public.php';
93
94 /**
95 * The class responsible for defining all actions that occur in the gutenberg block.
96 */
97 require_once AYG_DIR. 'block/block.php';
98
99 /**
100 * Create an instance of the loader.
101 */
102 $this->loader = new AYG_Loader();
103 }
104
105 /**
106 * Define the locale for this plugin for internationalization.
107 *
108 * @since 1.0.0
109 * @access private
110 */
111 private function set_locale() {
112 $i18n = new AYG_i18n();
113 $this->loader->add_action( 'plugins_loaded', $i18n, 'load_plugin_textdomain' );
114 }
115
116 /**
117 * Register all of the hooks related to the admin area functionality
118 * of the plugin.
119 *
120 * @since 1.0.0
121 * @access private
122 */
123 private function define_admin_hooks() {
124 // Hooks common to all admin pages
125 $admin = new AYG_Admin();
126
127 $this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_styles' );
128 $this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_scripts' );
129 $this->loader->add_action( 'admin_menu', $admin, 'admin_menu' );
130 $this->loader->add_action( 'wp_ajax_ayg_save_api_key', $admin, 'ajax_callback_save_api_key' );
131
132 $this->loader->add_filter( 'plugin_action_links_' . AYG_FILE_NAME, $admin, 'plugin_action_links' );
133
134 // Hooks specific to the settings page
135 $settings = new AYG_Admin_Settings();
136
137 $this->loader->add_action( 'admin_menu', $settings, 'admin_menu' );
138 $this->loader->add_action( 'admin_init', $settings, 'admin_init' );
139 $this->loader->add_action( 'wp_ajax_ayg_delete_cache', $settings, 'ajax_callback_delete_cache' );
140 }
141
142 /**
143 * Register all of the hooks related to the public-facing functionality
144 * of the plugin.
145 *
146 * @since 1.0.0
147 * @access private
148 */
149 private function define_public_hooks() {
150 $public = new AYG_Public();
151
152 $this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_styles' );
153 $this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_scripts' );
154 $this->loader->add_action( 'enqueue_block_editor_assets', $public, 'enqueue_block_editor_assets' );
155 $this->loader->add_action( 'wp_ajax_ayg_load_more_videos', $public, 'ajax_callback_load_more_videos' );
156 $this->loader->add_action( 'wp_ajax_nopriv_ayg_load_more_videos', $public, 'ajax_callback_load_more_videos' );
157
158 $this->loader->add_filter( 'smush_skip_iframe_from_lazy_load', $public, 'smush', 999, 2 );
159 }
160
161 /**
162 * Register all of the hooks related to the gutenberg block.
163 *
164 * @since 1.0.0
165 * @access private
166 */
167 private function define_block_hooks() {
168 if ( is_admin() ) {
169 global $pagenow;
170 if ( 'widgets.php' === $pagenow ) return;
171 }
172
173 global $wp_version;
174
175 $block = new AYG_Block();
176
177 $this->loader->add_action( 'init', $block, 'register_block_type' );
178 $this->loader->add_action( 'enqueue_block_editor_assets', $block, 'enqueue_block_editor_assets' );
179
180 if ( version_compare( $wp_version, '5.8', '>=' ) ) {
181 $this->loader->add_filter( 'block_categories_all', $block, 'block_categories' );
182 } else {
183 $this->loader->add_filter( 'block_categories', $block, 'block_categories' );
184 }
185 }
186
187 /**
188 * Run the loader to execute all of the hooks with WordPress.
189 *
190 * @since 1.0.0
191 */
192 public function run() {
193 $this->loader->run();
194 }
195
196 }
197