| @@ -44,8 +44,9 @@ | ||
| 44 | 44 | $this->set_locale(); |
| 45 | 45 | $this->define_admin_hooks(); |
| 46 | 46 | $this->define_public_hooks(); |
| 47 | 47 | $this->define_block_hooks(); |
| 48 | + $this->define_widget_hooks(); | |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | /** |
| 51 | 52 | * Load the required dependencies for this plugin. |
| @@ -81,12 +82,10 @@ | ||
| 81 | 82 | |
| 82 | 83 | /** |
| 83 | 84 | * The classes responsible for defining all actions that occur in the admin area. |
| 84 | 85 | */ |
| 85 | - require_once AYG_DIR . 'admin/admin.php'; | |
| 86 | + require_once AYG_DIR . 'admin/admin.php'; | |
| 86 | 87 | require_once AYG_DIR . 'admin/settings.php'; |
| 87 | - require_once AYG_DIR . 'admin/shortcode-builder.php'; | |
| 88 | - require_once AYG_DIR . 'admin/welcome.php'; | |
| 89 | 88 | |
| 90 | 89 | /** |
| 91 | 90 | * The class responsible for defining all actions that occur in the public-facing |
| 92 | 91 | * side of the site. |
| @@ -91,13 +90,19 @@ | ||
| 91 | 90 | * The class responsible for defining all actions that occur in the public-facing |
| 92 | 91 | * side of the site. |
| 93 | 92 | */ |
| 94 | 93 | require_once AYG_DIR . 'public/public.php'; |
| 94 | + require_once AYG_DIR . 'public/cron.php'; | |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * The class responsible for defining all actions that occur in the gutenberg block. |
| 98 | 98 | */ |
| 99 | - 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'; | |
| 100 | 105 | |
| 101 | 106 | /** |
| 102 | 107 | * Create an instance of the loader. |
| 103 | 108 | */ |
| @@ -110,10 +115,10 @@ | ||
| 110 | 115 | * @since 1.0.0 |
| 111 | 116 | * @access private |
| 112 | 117 | */ |
| 113 | 118 | private function set_locale() { |
| 114 | - $ayg_i18n = new AYG_i18n(); | |
| 115 | - $this->loader->add_action( 'plugins_loaded', $ayg_i18n, 'load_plugin_textdomain' ); | |
| 119 | + $i18n = new AYG_i18n(); | |
| 120 | + $this->loader->add_action( 'plugins_loaded', $i18n, 'load_plugin_textdomain' ); | |
| 116 | 121 | } |
| 117 | 122 | |
| 118 | 123 | /** |
| 119 | 124 | * Register all of the hooks related to the admin area functionality |
| @@ -123,35 +128,27 @@ | ||
| 123 | 128 | * @access private |
| 124 | 129 | */ |
| 125 | 130 | private function define_admin_hooks() { |
| 126 | 131 | // Hooks common to all admin pages |
| 127 | - $ayg_admin = new AYG_Admin(); | |
| 132 | + $admin = new AYG_Admin(); | |
| 128 | 133 | |
| 129 | - $this->loader->add_action( 'admin_enqueue_scripts', $ayg_admin, 'enqueue_styles' ); | |
| 130 | - $this->loader->add_action( 'admin_enqueue_scripts', $ayg_admin, 'enqueue_scripts' ); | |
| 131 | - $this->loader->add_action( 'admin_notices', $ayg_admin, 'admin_notice' ); | |
| 132 | - $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' ); | |
| 133 | 142 | |
| 134 | - $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' ); | |
| 135 | 144 | |
| 136 | 145 | // Hooks specific to the settings page |
| 137 | - $ayg_admin_settings = new AYG_Admin_Settings(); | |
| 146 | + $settings = new AYG_Admin_Settings(); | |
| 138 | 147 | |
| 139 | - $this->loader->add_action( 'admin_menu', $ayg_admin_settings, 'add_settings_menu' ); | |
| 140 | - $this->loader->add_action( 'admin_init', $ayg_admin_settings, 'admin_init' ); | |
| 141 | - $this->loader->add_action( 'admin_init', $ayg_admin_settings, 'delete_cache' ); | |
| 142 | - $this->loader->add_action( 'admin_notices', $ayg_admin_settings, 'admin_notices' ); | |
| 143 | - | |
| 144 | - // Hooks specific to the shortcode builder | |
| 145 | - $ayg_admin_shortcode_builder = new AYG_Admin_Shortcode_Builder(); | |
| 146 | - | |
| 147 | - $this->loader->add_action( 'media_buttons', $ayg_admin_shortcode_builder, 'media_buttons', 11 ); | |
| 148 | - $this->loader->add_action( 'admin_footer', $ayg_admin_shortcode_builder, 'admin_footer' ); | |
| 149 | - | |
| 150 | - // Hooks specific to the welcome page | |
| 151 | - $ayg_admin_welcome = new AYG_Admin_Welcome(); | |
| 152 | - | |
| 153 | - $this->loader->add_action( 'admin_menu', $ayg_admin_welcome, 'add_welcome_page_menu' ); | |
| 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' ); | |
| 154 | 151 | } |
| 155 | 152 | |
| 156 | 153 | /** |
| 157 | 154 | * Register all of the hooks related to the public-facing functionality |
| @@ -160,14 +157,30 @@ | ||
| 160 | 157 | * @since 1.0.0 |
| 161 | 158 | * @access private |
| 162 | 159 | */ |
| 163 | 160 | private function define_public_hooks() { |
| 164 | - $ayg_public = new AYG_Public(); | |
| 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' ); | |
| 165 | 173 | |
| 166 | - $this->loader->add_action( 'wp_enqueue_scripts', $ayg_public, 'register_styles' ); | |
| 167 | - $this->loader->add_action( 'wp_enqueue_scripts', $ayg_public, 'register_scripts' ); | |
| 168 | - $this->loader->add_action( 'wp_ajax_ayg_load_more_videos', $ayg_public, 'ajax_callback_load_more_videos' ); | |
| 169 | - $this->loader->add_action( 'wp_ajax_nopriv_ayg_load_more_videos', $ayg_public, 'ajax_callback_load_more_videos' ); | |
| 174 | + $this->loader->add_filter( 'smush_skip_iframe_from_lazy_load', $public, 'smush', 999, 2 ); | |
| 175 | + | |
| 176 | + // Hooks specific to the cron jobs | |
| 177 | + $cron = new AYG_Public_Cron(); | |
| 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' ); | |
| 170 | 183 | } |
| 171 | 184 | |
| 172 | 185 | /** |
| 173 | 186 | * Register all of the hooks related to the gutenberg block. |
| @@ -175,18 +188,47 @@ | ||
| 175 | 188 | * @since 1.0.0 |
| 176 | 189 | * @access private |
| 177 | 190 | */ |
| 178 | 191 | private function define_block_hooks() { |
| 179 | - $ayg_block = new AYG_Block(); | |
| 192 | + if ( is_admin() ) { | |
| 193 | + global $pagenow; | |
| 194 | + if ( 'widgets.php' === $pagenow ) return; | |
| 195 | + } | |
| 180 | 196 | |
| 181 | - $this->loader->add_action( 'init', $ayg_block, 'register_block_type' ); | |
| 182 | - $this->loader->add_action( 'enqueue_block_editor_assets', $ayg_block, 'enqueue_block_editor_assets' ); | |
| 183 | - $this->loader->add_action( 'enqueue_block_assets', $ayg_block, 'enqueue_block_assets' ); | |
| 197 | + global $wp_version; | |
| 184 | 198 | |
| 185 | - $this->loader->add_filter( 'block_categories', $ayg_block, 'block_categories' ); | |
| 186 | - } | |
| 199 | + $block = new AYG_Block(); | |
| 187 | 200 | |
| 201 | + $this->loader->add_action( 'init', $block, 'register_block_type' ); | |
| 202 | + $this->loader->add_action( 'enqueue_block_editor_assets', $block, 'enqueue_block_editor_assets' ); | |
| 203 | + | |
| 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 | + | |
| 188 | 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 | + } | |
| 220 | + | |
| 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 | + /** | |
| 189 | 231 | * Run the loader to execute all of the hooks with WordPress. |
| 190 | 232 | * |
| 191 | 233 | * @since 1.0.0 |
| 192 | 234 | */ |
| @@ -193,5 +235,5 @@ | ||
| 193 | 235 | public function run() { |
| 194 | 236 | $this->loader->run(); |
| 195 | 237 | } |
| 196 | 238 | |
| 197 | -} | |
| 239 | +} | |