| @@ -5,13 +5,12 @@ | ||
| 5 | 5 | * |
| 6 | 6 | * A class definition that includes attributes and functions used across both the |
| 7 | 7 | * public-facing side of the site and the admin area. |
| 8 | 8 | * |
| 9 | - * @link https://plugins360.com | |
| 10 | - * @since 1.0.0 | |
| 9 | + * @link https://plugins360.com | |
| 10 | + * @since 1.0.0 | |
| 11 | 11 | * |
| 12 | - * @package Automatic_YouTube_Gallery | |
| 13 | - * @subpackage Automatic_YouTube_Gallery/includes | |
| 12 | + * @package Automatic_YouTube_Gallery | |
| 14 | 13 | */ |
| 15 | 14 | |
| 16 | 15 | // Exit if accessed directly |
| 17 | 16 | if ( ! defined( 'WPINC' ) ) { |
| @@ -40,15 +39,14 @@ | ||
| 40 | 39 | * |
| 41 | 40 | * @since 1.0.0 |
| 42 | 41 | */ |
| 43 | 42 | public function __construct() { |
| 44 | - | |
| 45 | 43 | $this->load_dependencies(); |
| 46 | 44 | $this->set_locale(); |
| 47 | 45 | $this->define_admin_hooks(); |
| 48 | 46 | $this->define_public_hooks(); |
| 49 | - $this->define_block_hooks(); | |
| 50 | - | |
| 47 | + $this->define_block_hooks(); | |
| 48 | + $this->define_widget_hooks(); | |
| 51 | 49 | } |
| 52 | 50 | |
| 53 | 51 | /** |
| 54 | 52 | * Load the required dependencies for this plugin. |
| @@ -59,9 +57,8 @@ | ||
| 59 | 57 | * @since 1.0.0 |
| 60 | 58 | * @access private |
| 61 | 59 | */ |
| 62 | 60 | private function load_dependencies() { |
| 63 | - | |
| 64 | 61 | /** |
| 65 | 62 | * The class responsible for orchestrating the actions and filters of the |
| 66 | 63 | * core plugin. |
| 67 | 64 | */ |
| @@ -85,12 +82,10 @@ | ||
| 85 | 82 | |
| 86 | 83 | /** |
| 87 | 84 | * The classes responsible for defining all actions that occur in the admin area. |
| 88 | 85 | */ |
| 89 | - require_once AYG_DIR . 'admin/admin.php'; | |
| 86 | + require_once AYG_DIR . 'admin/admin.php'; | |
| 90 | 87 | require_once AYG_DIR . 'admin/settings.php'; |
| 91 | - require_once AYG_DIR . 'admin/shortcode-builder.php'; | |
| 92 | - require_once AYG_DIR . 'admin/welcome.php'; | |
| 93 | 88 | |
| 94 | 89 | /** |
| 95 | 90 | * The class responsible for defining all actions that occur in the public-facing |
| 96 | 91 | * side of the site. |
| @@ -95,19 +90,24 @@ | ||
| 95 | 90 | * The class responsible for defining all actions that occur in the public-facing |
| 96 | 91 | * side of the site. |
| 97 | 92 | */ |
| 98 | 93 | require_once AYG_DIR . 'public/public.php'; |
| 94 | + require_once AYG_DIR . 'public/cron.php'; | |
| 99 | 95 | |
| 100 | 96 | /** |
| 101 | 97 | * The class responsible for defining all actions that occur in the gutenberg block. |
| 102 | 98 | */ |
| 103 | - require_once AYG_DIR. 'block/block.php'; | |
| 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'; | |
| 104 | 105 | |
| 105 | 106 | /** |
| 106 | 107 | * Create an instance of the loader. |
| 107 | 108 | */ |
| 108 | 109 | $this->loader = new AYG_Loader(); |
| 109 | - | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * Define the locale for this plugin for internationalization. |
| @@ -115,13 +115,10 @@ | ||
| 115 | 115 | * @since 1.0.0 |
| 116 | 116 | * @access private |
| 117 | 117 | */ |
| 118 | 118 | private function set_locale() { |
| 119 | - | |
| 120 | - $ayg_i18n = new AYG_i18n(); | |
| 121 | - | |
| 122 | - $this->loader->add_action( 'plugins_loaded', $ayg_i18n, 'load_plugin_textdomain' ); | |
| 123 | - | |
| 119 | + $i18n = new AYG_i18n(); | |
| 120 | + $this->loader->add_action( 'plugins_loaded', $i18n, 'load_plugin_textdomain' ); | |
| 124 | 121 | } |
| 125 | 122 | |
| 126 | 123 | /** |
| 127 | 124 | * Register all of the hooks related to the admin area functionality |
| @@ -130,38 +127,28 @@ | ||
| 130 | 127 | * @since 1.0.0 |
| 131 | 128 | * @access private |
| 132 | 129 | */ |
| 133 | 130 | private function define_admin_hooks() { |
| 134 | - | |
| 135 | 131 | // Hooks common to all admin pages |
| 136 | - $ayg_admin = new AYG_Admin(); | |
| 132 | + $admin = new AYG_Admin(); | |
| 137 | 133 | |
| 138 | - $this->loader->add_action( 'admin_enqueue_scripts', $ayg_admin, 'enqueue_styles' ); | |
| 139 | - $this->loader->add_action( 'admin_enqueue_scripts', $ayg_admin, 'enqueue_scripts' ); | |
| 140 | - $this->loader->add_action( 'admin_notices', $ayg_admin, 'admin_notice' ); | |
| 141 | - $this->loader->add_action( 'wp_ajax_ayg_dismiss_admin_notice', $ayg_admin, 'ajax_callback_dismiss_admin_notice' ); | |
| 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 | 142 | |
| 143 | - $this->loader->add_filter( 'plugin_action_links_' . AYG_FILE_NAME, $ayg_admin, 'plugin_action_links' ); | |
| 143 | + $this->loader->add_filter( 'plugin_action_links_' . AYG_FILE_NAME, $admin, 'plugin_action_links' ); | |
| 144 | 144 | |
| 145 | 145 | // Hooks specific to the settings page |
| 146 | - $ayg_admin_settings = new AYG_Admin_Settings(); | |
| 146 | + $settings = new AYG_Admin_Settings(); | |
| 147 | 147 | |
| 148 | - $this->loader->add_action( 'admin_menu', $ayg_admin_settings, 'add_settings_menu' ); | |
| 149 | - $this->loader->add_action( 'admin_init', $ayg_admin_settings, 'admin_init' ); | |
| 150 | - $this->loader->add_action( 'admin_init', $ayg_admin_settings, 'delete_cache' ); | |
| 151 | - $this->loader->add_action( 'admin_notices', $ayg_admin_settings, 'admin_notices' ); | |
| 152 | - | |
| 153 | - // Hooks specific to the shortcode builder | |
| 154 | - $ayg_admin_shortcode_builder = new AYG_Admin_Shortcode_Builder(); | |
| 155 | - | |
| 156 | - $this->loader->add_action( 'media_buttons', $ayg_admin_shortcode_builder, 'media_buttons', 11 ); | |
| 157 | - $this->loader->add_action( 'admin_footer', $ayg_admin_shortcode_builder, 'admin_footer' ); | |
| 158 | - | |
| 159 | - // Hooks specific to the welcome page | |
| 160 | - $ayg_admin_welcome = new AYG_Admin_Welcome(); | |
| 161 | - | |
| 162 | - $this->loader->add_action( 'admin_menu', $ayg_admin_welcome, 'add_welcome_page_menu' ); | |
| 163 | - | |
| 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' ); | |
| 164 | 151 | } |
| 165 | 152 | |
| 166 | 153 | /** |
| 167 | 154 | * Register all of the hooks related to the public-facing functionality |
| @@ -170,16 +157,30 @@ | ||
| 170 | 157 | * @since 1.0.0 |
| 171 | 158 | * @access private |
| 172 | 159 | */ |
| 173 | 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' ); | |
| 174 | 173 | |
| 175 | - $ayg_public = new AYG_Public(); | |
| 174 | + $this->loader->add_filter( 'smush_skip_iframe_from_lazy_load', $public, 'smush', 999, 2 ); | |
| 176 | 175 | |
| 177 | - $this->loader->add_action( 'wp_enqueue_scripts', $ayg_public, 'register_styles' ); | |
| 178 | - $this->loader->add_action( 'wp_enqueue_scripts', $ayg_public, 'register_scripts' ); | |
| 179 | - $this->loader->add_action( 'wp_ajax_ayg_load_more_videos', $ayg_public, 'ajax_callback_load_more_videos' ); | |
| 180 | - $this->loader->add_action( 'wp_ajax_nopriv_ayg_load_more_videos', $ayg_public, 'ajax_callback_load_more_videos' ); | |
| 176 | + // Hooks specific to the cron jobs | |
| 177 | + $cron = new AYG_Public_Cron(); | |
| 181 | 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' ); | |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | 185 | /** |
| 185 | 186 | * Register all of the hooks related to the gutenberg block. |
| @@ -187,20 +188,47 @@ | ||
| 187 | 188 | * @since 1.0.0 |
| 188 | 189 | * @access private |
| 189 | 190 | */ |
| 190 | 191 | private function define_block_hooks() { |
| 192 | + if ( is_admin() ) { | |
| 193 | + global $pagenow; | |
| 194 | + if ( 'widgets.php' === $pagenow ) return; | |
| 195 | + } | |
| 191 | 196 | |
| 192 | - $ayg_block = new AYG_Block(); | |
| 197 | + global $wp_version; | |
| 193 | 198 | |
| 194 | - $this->loader->add_action( 'init', $ayg_block, 'register_block_type' ); | |
| 195 | - $this->loader->add_action( 'enqueue_block_editor_assets', $ayg_block, 'enqueue_block_editor_assets' ); | |
| 196 | - $this->loader->add_action( 'enqueue_block_assets', $ayg_block, 'enqueue_block_assets' ); | |
| 199 | + $block = new AYG_Block(); | |
| 197 | 200 | |
| 198 | - $this->loader->add_filter( 'block_categories', $ayg_block, 'block_categories' ); | |
| 201 | + $this->loader->add_action( 'init', $block, 'register_block_type' ); | |
| 202 | + $this->loader->add_action( 'enqueue_block_editor_assets', $block, 'enqueue_block_editor_assets' ); | |
| 199 | 203 | |
| 200 | - } | |
| 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 | + } | |
| 201 | 220 | |
| 202 | 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 | + /** | |
| 203 | 231 | * Run the loader to execute all of the hooks with WordPress. |
| 204 | 232 | * |
| 205 | 233 | * @since 1.0.0 |
| 206 | 234 | */ |
| @@ -207,5 +235,5 @@ | ||
| 207 | 235 | public function run() { |
| 208 | 236 | $this->loader->run(); |
| 209 | 237 | } |
| 210 | 238 | |
| 211 | -} | |
| 239 | +} | |