PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.7
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.7
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / includes / class-smart-post-show.php

class-smart-post-show.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.7, at includes/class-smart-post-show.php

422 lines 12.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The core plugin class.
4 *
5 * This is used to define internationalization, admin-specific hooks, and
6 * public-facing site hooks.
7 *
8 * Also maintains the unique identifier of this plugin as well as the current
9 * version of the plugin.
10 *
11 * @link https://wpsmartpost.com/
12 * @since 2.2.0
13 *
14 * @package Smart_Post_Show
15 * @subpackage Smart_Post_Show/includes
16 */
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // Exit if accessed directly.
20 }
21
22 /**
23 * The core plugin class that is used to define internationalization,
24 * admin-specific hooks, and public-facing site hooks.
25 */
26 class Smart_Post_Show {
27
28 /**
29 * The loader that's responsible for maintaining and registering all hooks that power
30 * the plugin.
31 *
32 * @since 2.2.0
33 * @access protected
34 * @var Smart_Post_Show_Loader $loader Maintains and registers all hooks for the plugin.
35 */
36 public $loader;
37
38 /**
39 * The unique identifier of this plugin.
40 *
41 * @since 2.2.0
42 * @access protected
43 * @var string $plugin_name The string used to uniquely identify this plugin.
44 */
45 public $plugin_name = SMART_POST_SHOW_BASENAME;
46
47 /**
48 * The current version of the plugin.
49 *
50 * @since 2.2.0
51 * @access protected
52 * @var string $version The current version of the plugin.
53 */
54 public $version = SMART_POST_SHOW_VERSION;
55
56 /**
57 * Define the core functionality of the plugin.
58 *
59 * Set the plugin name and the plugin version that can be used throughout the plugin.
60 * Load the dependencies, define the locale, and set the hooks for the admin area and
61 * the public-facing side of the site.
62 *
63 * @since 2.2.0
64 */
65 public function __construct() {
66 $this->define_constants();
67 $this->load_dependencies();
68 $this->define_common_hooks();
69 $this->define_admin_hooks();
70 $this->define_public_hooks();
71 $this->set_locale();
72 }
73
74 /**
75 * Define constants
76 *
77 * @since 2.2.0
78 */
79 public function define_constants() {
80 define( 'SP_PC_VERSION', $this->version );
81 define( 'SP_PC_PLUGIN_NAME', $this->plugin_name );
82 define( 'SP_PC_PATH', plugin_dir_path( __DIR__ ) );
83 define( 'SP_PC_TEMPLATE_PATH', plugin_dir_path( __DIR__ ) . 'public/template/' );
84 define( 'SP_PC_URL', plugin_dir_url( __DIR__ ) );
85 }
86
87 /**
88 * Check whether Divi 5.x is the active builder version.
89 *
90 * Divi 5 exposes the et_builder_d5_enabled() function and/or an
91 * ET_BUILDER_VERSION constant of 5.0 or greater. Anything else is
92 * treated as classic Divi 4.
93 *
94 * @since 4.0.6
95 * @return bool True if Divi 5.x is active.
96 */
97 private static function sp_is_divi_5_active() {
98 if ( function_exists( 'et_builder_d5_enabled' ) && et_builder_d5_enabled() ) {
99 return true;
100 }
101
102 if ( defined( 'ET_BUILDER_VERSION' ) ) {
103 return version_compare( ET_BUILDER_VERSION, '5.0', '>=' );
104 }
105
106 return false;
107 }
108
109 /**
110 * Load the required dependencies for this plugin.
111 *
112 * Include the following files that make up the plugin:
113 *
114 * - Smart_Post_Show_Loader. Orchestrates the hooks of the plugin.
115 * - Smart_Post_Show_i18n. Defines internationalization functionality.
116 * - Smart_Post_Show_Admin. Defines all hooks for the admin area.
117 * - Smart_Post_Show_Public. Defines all hooks for the public side of the site.
118 * - Smart_Post_Show_Public. Defines all hooks for the public side of the site.
119 *
120 * Create an instance of the loader which will be used to register the hooks
121 * with WordPress.
122 *
123 * @since 2.2.0
124 * @access private
125 */
126 private function load_dependencies() {
127
128 /**
129 * The class responsible for orchestrating the actions and filters of the
130 * core plugin.
131 */
132 require_once SP_PC_PATH . 'includes/class-smart-post-show-loader.php';
133 $this->loader = new Smart_Post_Show_Loader();
134
135 /**
136 * The class responsible for defining internationalization functionality
137 * of the plugin.
138 */
139 require_once SP_PC_PATH . 'includes/class-smart-post-show-i18n.php';
140
141 /**
142 * The class responsible for defining internationalization functionality
143 * of the plugin.
144 */
145 require_once SP_PC_PATH . 'includes/class-smart-post-show-post-types.php';
146
147 /**
148 * The class responsible for updates functionality of the plugin.
149 */
150 require_once SP_PC_PATH . 'includes/class-smart-post-show-updates.php';
151
152 /**
153 * The class responsible for Export Import functionality of the plugin.
154 */
155 require_once SP_PC_PATH . 'includes/class-smart-post-show-import-export.php';
156
157 /**
158 * The class responsible for defining all actions that occur in the admin area.
159 */
160 require_once SP_PC_PATH . 'admin/class-smart-post-show-admin.php';
161
162 /**
163 * Weekly events.
164 */
165 require_once SP_PC_PATH . 'admin/class-smart-post-show-cron.php';
166
167 /**
168 * Save template.
169 */
170 require_once SP_PC_PATH . 'includes/class-smart-post-show-saved-template.php';
171
172 /**
173 * The class responsible for defining metabox setup that occur in the admin area.
174 */
175 require_once SP_PC_PATH . '/admin/views/sp-framework/classes/setup.class.php';
176 require_once SP_PC_PATH . '/public/helpers/sp-pc-output.php';
177 /**
178 * The class responsible for defining all actions that occur in the public-facing
179 * side of the site.
180 */
181 require_once SP_PC_PATH . 'public/class-smart-post-show-public.php';
182 require_once SP_PC_PATH . 'admin/preview/class-spsp-preview.php';
183
184 /**
185 * The class responsible for all admin notices.
186 */
187 require_once SP_PC_PATH . 'admin/views/notices/review.php';
188
189 /**
190 * The class blocks helper.
191 */
192 require_once SP_PC_PATH . 'blocks/includes/class-block-helper.php';
193
194 \SmartPostShow\Blocks\Helper::set_integration_options();
195
196 $integration_options = \SmartPostShow\Blocks\Helper::get_integration_options();
197
198 $divi_integration = $integration_options['divi'] ?? false;
199 $oxygen_integration = $integration_options['oxygen'] ?? false;
200 $wpbakery_integration = $integration_options['wpbakery'] ?? false;
201 $beaber_integration = $integration_options['beaver'] ?? false;
202 $bricks_integration = $integration_options['bricks'] ?? false;
203
204 /**
205 * Divi.
206 *
207 * Divi 5 uses a React/JSON module architecture, while Divi 4 uses the
208 * classic ET_Builder_Module PHP class. Load the matching integration
209 * based on the active Divi version. The Divi 5 REST API is registered
210 * independently on rest_api_init.
211 */
212 if ( $divi_integration ) {
213 // Register the Divi 5 REST API routes (template list + preview HTML).
214 add_action(
215 'rest_api_init',
216 function () {
217 require_once SP_PC_PATH . 'admin/page-builder/divi5/server/rest-api.php';
218 if ( function_exists( 'SmartPostShow\\Admin\\PageBuilders\\Divi5\\spsp_divi5_register_rest_routes' ) ) {
219 \SmartPostShow\Admin\PageBuilders\Divi5\spsp_divi5_register_rest_routes();
220 }
221 },
222 10
223 );
224
225 // Load the Divi 5 server-side module (self-registers with Divi's dependency tree).
226 add_action(
227 'init',
228 function () {
229 if ( ! self::sp_is_divi_5_active() ) {
230 return;
231 }
232 require_once SP_PC_PATH . 'admin/page-builder/divi5/server/index.php';
233 },
234 10
235 );
236
237 // Load the version-appropriate builder integration.
238 add_action(
239 'init',
240 function () {
241 if ( self::sp_is_divi_5_active() ) {
242 // Divi 5 module.
243 require_once SP_PC_PATH . 'admin/page-builder/divi5/Divi5_Builder.php';
244 \SmartPostShow\Admin\PageBuilders\Divi5\Divi5_Builder::init();
245 } elseif ( defined( 'ET_BUILDER_VERSION' ) || class_exists( 'ET_Builder_Module' ) ) {
246 // Classic Divi 4 module (self-registers on et_builder_ready).
247 require_once SP_PC_PATH . 'admin/page-builder/divi/smart-post-show-divi.php';
248 }
249 },
250 20
251 );
252 }
253
254 /**
255 * Oxygen.
256 */
257 if ( $oxygen_integration ) {
258 require_once SP_PC_PATH . 'admin/page-builder/oxygen/init.php';
259 }
260
261 /**
262 * WPBakery.
263 */
264 if ( $wpbakery_integration && defined( 'WPB_VC_VERSION' ) ) {
265 require_once SP_PC_PATH . 'admin/page-builder/wpBakery/smart-post-show-wpbakery.php';
266 }
267
268 /**
269 * Beaver Builder.
270 */
271 if ( $beaber_integration && class_exists( 'FLBuilder' ) ) {
272 require_once SP_PC_PATH . 'admin/page-builder/beaver/smart-post-beaver.php';
273 }
274
275 /**
276 * Bricks Builder.
277 */
278 if ( $bricks_integration ) {
279 require_once SP_PC_PATH . 'admin/page-builder/bricks/init.php';
280 }
281
282 // Elementor shortcode addons.
283 require_once ABSPATH . 'wp-admin/includes/plugin.php';
284 if ( ( is_plugin_active( 'elementor/elementor.php' ) || is_plugin_active_for_network( 'elementor/elementor.php' ) ) ) {
285 require_once SP_PC_PATH . 'admin/class-smart-post-show-element-shortcode-addons.php';
286 require_once SP_PC_PATH . 'admin/class-smart-post-show-element-shortcode-addons-deprecated.php';
287 }
288
289 /**
290 * Gutenberg block.
291 */
292 if ( version_compare( $GLOBALS['wp_version'], '5.3', '>=' ) ) {
293 require_once SP_PC_PATH . 'admin/blocks-settings/class-blocks-settings-page.php';
294 new Sp_Smart_Post_Block_Admin_Menu_Page();
295
296 require_once SP_PC_PATH . 'blocks/class-smart-post-show-blocks.php';
297 Sp_Smart_Post_Blocks_Init::instance();
298
299 require_once SP_PC_PATH . 'admin/class-smart-post-show-gutenberg-block.php';
300 new Smart_Post_Show_Gutenberg_Block();
301 }
302 }
303
304 /**
305 * Define the locale for this plugin for internationalization.
306 *
307 * Uses the Smart_Post_Show_i18n class in order to set the domain and to register the hook
308 * with WordPress.
309 *
310 * @since 2.2.0
311 * @access private
312 */
313 private function set_locale() {
314
315 $plugin_i18n = new Smart_Post_Show_i18n();
316
317 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
318 }
319
320 /**
321 * Register common hooks.
322 *
323 * @since 2.2.0
324 * @access private
325 */
326 private function define_common_hooks() {
327 $common_hooks = new Smart_Post_Show_Post_Type( SP_PC_PLUGIN_NAME, SP_PC_VERSION );
328 $this->loader->add_action( 'init', $common_hooks, 'register_carousel_post_type', 10 );
329
330 // Saved Template.
331 $saved_template = new Smart_Post_Show_Saved_Template();
332 $this->loader->add_action( 'init', $saved_template, 'register_template_shortcode' );
333 }
334
335 /**
336 * Register all of the hooks related to the admin area functionality
337 * of the plugin.
338 *
339 * @since 2.2.0
340 * @access private
341 */
342 private function define_admin_hooks() {
343 $plugin_admin = new Smart_Post_Show_Admin( SP_PC_PLUGIN_NAME, SP_PC_VERSION );
344 // Load admin scripts and styles.
345 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
346 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
347 // Admin custom column.
348 $this->loader->add_filter( 'manage_sp_post_carousel_posts_columns', $plugin_admin, 'filter_carousel_admin_column' );
349 $this->loader->add_filter( 'admin_footer_text', $plugin_admin, 'sp_spc_footer_text' );
350 $this->loader->add_filter( 'update_footer', $plugin_admin, 'sp_spc_version_text', 11 );
351 $this->loader->add_action( 'manage_sp_post_carousel_posts_custom_column', $plugin_admin, 'display_carousel_admin_fields', 10, 2 );
352
353 $this->loader->add_filter( 'plugin_row_meta', $plugin_admin, 'after_pcp_row_meta', 10, 4 );
354 // Post save and update messages.
355 $this->loader->add_filter( 'post_updated_messages', $plugin_admin, 'sppcp_update', 10, 1 );
356 // Help Page.
357 SPS_Recommended::instance();
358 $import_export = new Smart_Post_Show_Import_Export( SP_PC_PLUGIN_NAME, SP_PC_VERSION );
359
360 $this->loader->add_action( 'wp_ajax_pcp_export_shortcodes', $import_export, 'export_shortcodes' );
361 $this->loader->add_action( 'wp_ajax_pcp_import_shortcodes', $import_export, 'import_shortcodes' );
362 // Get shortcode list for export selection.
363 $this->loader->add_action( 'wp_ajax_pcp_get_shortcode_list_for_export', $import_export, 'get_shortcode_list_for_export' );
364
365 // after activated plugin redirect to help page.
366 $this->loader->add_action( 'activated_plugin', $plugin_admin, 'redirect_help_page' );
367 }
368
369 /**
370 * Register all of the hooks related to the public-facing functionality
371 * of the plugin.
372 *
373 * @since 2.2.0
374 * @access private
375 */
376 private function define_public_hooks() {
377 $plugin_public = new Smart_Post_Show_Public( SP_PC_PLUGIN_NAME, SP_PC_VERSION );
378 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
379 $this->loader->add_action( 'wp_loaded', $plugin_public, 'register_all_scripts' );
380 }
381
382 /**
383 * Run the loader to execute all of the hooks with WordPress.
384 *
385 * @since 2.2.0
386 */
387 public function run() {
388 $this->loader->run();
389 }
390
391 /**
392 * The name of the plugin used to uniquely identify it within the context of
393 * WordPress and to define internationalization functionality.
394 *
395 * @since 2.2.0
396 * @return string The name of the plugin.
397 */
398 public function get_plugin_name() {
399 return $this->plugin_name;
400 }
401
402 /**
403 * The reference to the class that orchestrates the hooks with the plugin.
404 *
405 * @since 2.2.0
406 * @return Smart_Post_Show_Loader Orchestrates the hooks of the plugin.
407 */
408 public function get_loader() {
409 return $this->loader;
410 }
411
412 /**
413 * Retrieve the version number of the plugin.
414 *
415 * @since 2.2.0
416 * @return string The version number of the plugin.
417 */
418 public function get_version() {
419 return $this->version;
420 }
421 }
422