| 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 class responsible for importing videos into the Gallery Builder galleries. |
| 85 |
*/ |
| 86 |
require_once AYG_DIR . 'includes/import.php'; |
| 87 |
|
| 88 |
/** |
| 89 |
* The classes responsible for defining all actions that occur in the admin area. |
| 90 |
*/ |
| 91 |
require_once AYG_DIR . 'admin/admin.php'; |
| 92 |
require_once AYG_DIR . 'admin/settings.php'; |
| 93 |
|
| 94 |
/** |
| 95 |
* The class responsible for defining all actions that occur in the public-facing |
| 96 |
* side of the site. |
| 97 |
*/ |
| 98 |
require_once AYG_DIR . 'public/public.php'; |
| 99 |
require_once AYG_DIR . 'public/cron.php'; |
| 100 |
|
| 101 |
/** |
| 102 |
* The class responsible for defining all actions that occur in the gutenberg block. |
| 103 |
*/ |
| 104 |
require_once AYG_DIR. 'block/block.php'; |
| 105 |
|
| 106 |
/** |
| 107 |
* The class responsible for defining all actions that occur in the widget. |
| 108 |
*/ |
| 109 |
require_once AYG_DIR . 'widget/widget.php'; |
| 110 |
|
| 111 |
/** |
| 112 |
* Create an instance of the loader. |
| 113 |
*/ |
| 114 |
$this->loader = new AYG_Loader(); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Define the locale for this plugin for internationalization. |
| 119 |
* |
| 120 |
* @since 1.0.0 |
| 121 |
* @access private |
| 122 |
*/ |
| 123 |
private function set_locale() { |
| 124 |
$i18n = new AYG_i18n(); |
| 125 |
$this->loader->add_action( 'plugins_loaded', $i18n, 'load_plugin_textdomain' ); |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Register all of the hooks related to the admin area functionality |
| 130 |
* of the plugin. |
| 131 |
* |
| 132 |
* @since 1.0.0 |
| 133 |
* @access private |
| 134 |
*/ |
| 135 |
private function define_admin_hooks() { |
| 136 |
// Hooks common to all admin pages |
| 137 |
$admin = new AYG_Admin(); |
| 138 |
|
| 139 |
$this->loader->add_action( 'admin_init', $admin, 'insert_missing_options', 1 ); |
| 140 |
$this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_styles' ); |
| 141 |
$this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_scripts' ); |
| 142 |
$this->loader->add_action( 'elementor/editor/after_enqueue_styles', $admin, 'enqueue_styles' ); |
| 143 |
$this->loader->add_action( 'elementor/editor/after_enqueue_scripts', $admin, 'enqueue_scripts' ); |
| 144 |
$this->loader->add_action( 'admin_menu', $admin, 'admin_menu' ); |
| 145 |
$this->loader->add_action( 'admin_notices', $admin, 'admin_notices' ); |
| 146 |
$this->loader->add_action( 'wp_ajax_ayg_save_api_key', $admin, 'ajax_callback_save_api_key' ); |
| 147 |
$this->loader->add_action( 'wp_ajax_ayg_save_gallery', $admin, 'ajax_callback_save_gallery' ); |
| 148 |
$this->loader->add_action( 'wp_ajax_ayg_import_gallery', $admin, 'ajax_callback_import_gallery' ); |
| 149 |
$this->loader->add_action( 'wp_ajax_ayg_delete_gallery', $admin, 'ajax_callback_delete_gallery' ); |
| 150 |
|
| 151 |
$this->loader->add_filter( 'plugin_action_links_' . AYG_FILE_NAME, $admin, 'plugin_action_links' ); |
| 152 |
|
| 153 |
// Hooks specific to the settings page |
| 154 |
$settings = new AYG_Admin_Settings(); |
| 155 |
|
| 156 |
$this->loader->add_action( 'admin_menu', $settings, 'admin_menu' ); |
| 157 |
$this->loader->add_action( 'admin_init', $settings, 'admin_init' ); |
| 158 |
$this->loader->add_action( 'wp_ajax_ayg_delete_cache', $settings, 'ajax_callback_delete_cache' ); |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Register all of the hooks related to the public-facing functionality |
| 163 |
* of the plugin. |
| 164 |
* |
| 165 |
* @since 1.0.0 |
| 166 |
* @access private |
| 167 |
*/ |
| 168 |
private function define_public_hooks() { |
| 169 |
// Hooks common to all public pages |
| 170 |
$public = new AYG_Public(); |
| 171 |
|
| 172 |
$this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_styles' ); |
| 173 |
$this->loader->add_action( 'wp_enqueue_scripts', $public, 'register_scripts' ); |
| 174 |
$this->loader->add_action( 'enqueue_block_assets', $public, 'enqueue_block_assets' ); |
| 175 |
$this->loader->add_action( 'elementor/editor/after_enqueue_scripts', $public, 'enqueue_editor_assets' ); |
| 176 |
$this->loader->add_action( 'elementor/preview/enqueue_scripts', $public, 'enqueue_editor_assets' ); |
| 177 |
$this->loader->add_action( 'wp_ajax_ayg_load_videos', $public, 'ajax_callback_load_videos' ); |
| 178 |
$this->loader->add_action( 'wp_ajax_nopriv_ayg_load_videos', $public, 'ajax_callback_load_videos' ); |
| 179 |
$this->loader->add_action( 'wp_ajax_ayg_set_cookie', $public, 'set_gdpr_cookie' ); |
| 180 |
$this->loader->add_action( 'wp_ajax_nopriv_ayg_set_cookie', $public, 'set_gdpr_cookie' ); |
| 181 |
|
| 182 |
$this->loader->add_filter( 'smush_skip_iframe_from_lazy_load', $public, 'smush', 999, 2 ); |
| 183 |
|
| 184 |
// Hooks specific to the cron jobs |
| 185 |
$cron = new AYG_Public_Cron(); |
| 186 |
|
| 187 |
$this->loader->add_action( 'wp', $cron, 'schedule_events' ); |
| 188 |
$this->loader->add_action( 'ayg_cron_schedule', $cron, 'cron_event' ); |
| 189 |
|
| 190 |
$this->loader->add_filter( 'cron_schedules', $cron, 'cron_schedules' ); |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Register all of the hooks related to the gutenberg block. |
| 195 |
* |
| 196 |
* @since 1.0.0 |
| 197 |
* @access private |
| 198 |
*/ |
| 199 |
private function define_block_hooks() { |
| 200 |
if ( is_admin() ) { |
| 201 |
global $pagenow; |
| 202 |
if ( 'widgets.php' === $pagenow ) return; |
| 203 |
} |
| 204 |
|
| 205 |
global $wp_version; |
| 206 |
|
| 207 |
$block = new AYG_Block(); |
| 208 |
|
| 209 |
$this->loader->add_action( 'init', $block, 'register_block_type' ); |
| 210 |
$this->loader->add_action( 'enqueue_block_editor_assets', $block, 'enqueue_block_editor_assets' ); |
| 211 |
|
| 212 |
if ( version_compare( $wp_version, '5.8', '>=' ) ) { |
| 213 |
$this->loader->add_filter( 'block_categories_all', $block, 'block_categories' ); |
| 214 |
} else { |
| 215 |
$this->loader->add_filter( 'block_categories', $block, 'block_categories' ); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
/** |
| 220 |
* Register all of the hooks related to the widget. |
| 221 |
* |
| 222 |
* @since 2.1.0 |
| 223 |
* @access private |
| 224 |
*/ |
| 225 |
private function define_widget_hooks() { |
| 226 |
$this->loader->add_action( 'widgets_init', $this, 'register_widget' ); |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Register the widget. |
| 231 |
* |
| 232 |
* @since 2.1.0 |
| 233 |
*/ |
| 234 |
public function register_widget() { |
| 235 |
register_widget( 'AYG_Widget' ); |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Run the loader to execute all of the hooks with WordPress. |
| 240 |
* |
| 241 |
* @since 1.0.0 |
| 242 |
*/ |
| 243 |
public function run() { |
| 244 |
$this->loader->run(); |
| 245 |
} |
| 246 |
|
| 247 |
} |