PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.4.6
Post Grid Gutenberg Blocks – PostX v2.4.6
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / Initialization.php

Initialization.php in Post Grid Gutenberg Blocks – PostX 2.4.6, at classes/Initialization.php

574 lines 20.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Initialization Action.
4 *
5 * @package ULTP\Notice
6 * @since v.1.1.0
7 */
8 namespace ULTP;
9
10 defined('ABSPATH') || exit;
11
12 /**
13 * Initialization class.
14 */
15 class ULTP_Initialization{
16
17 private $all_blocks;
18
19 /**
20 * Setup class.
21 *
22 * @since v.1.1.0
23 */
24 public function __construct(){
25 $this->compatibility_check();
26 $this->requires(); // Include Necessary Files
27 $this->blocks(); // Include Blocks
28 $this->include_addons(); // Include Addons
29
30 add_action('wp', array($this, 'popular_posts_tracker_callback'));
31 add_filter('block_categories', array($this, 'register_category_callback'), 10, 2); // Block Category Register
32 add_action('after_setup_theme', array($this, 'add_image_size'));
33
34 add_action('enqueue_block_editor_assets', array($this, 'register_scripts_back_callback')); // Only editor
35 add_action('admin_enqueue_scripts', array($this, 'register_scripts_option_panel_callback')); // Option Panel
36 add_action('wp_enqueue_scripts', array($this, 'register_scripts_front_callback')); // Both frontend
37 register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook'));
38 add_action( 'activated_plugin', array($this, 'activation_redirect'));
39
40 add_action('wp_ajax_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call
41 add_action('wp_ajax_nopriv_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call Logout User
42 add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call
43 add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User
44 add_action('wp_ajax_ultp_pagination', array($this, 'ultp_pagination_callback')); // Page Number AJAX Call
45 add_action('wp_ajax_nopriv_ultp_pagination',array($this, 'ultp_pagination_callback')); // Page Number AJAX Call Logout User
46 add_action('wp_ajax_ultp_addon', array($this, 'ultp_addon_callback')); // Next Previous AJAX Call
47
48 add_action('admin_init', array($this, 'check_theme_compatibility') );
49 add_action( 'after_switch_theme', array( $this, 'wpxpo_swithch_thememe' ) );
50 }
51
52
53 /**
54 * Theme Switch Callback
55 *
56 * @since v.1.1.0
57 * @return NULL
58 */
59 public function wpxpo_swithch_thememe () {
60 $this->check_theme_compatibility();
61 }
62
63
64 /**
65 * Theme Compatibility Action
66 *
67 * @since v.1.1.0
68 * @return NULL
69 */
70 public function check_theme_compatibility() {
71 $licence = apply_filters( 'ultp_theme_integration' , FALSE);
72 $theme = get_transient( 'ulpt_theme_enable' );
73
74 if( $licence ) {
75 if( $theme != 'integration' ) {
76 $themes = wp_get_theme();
77 $api_params = array(
78 'wpxpo_theme_action' => 'theme_license',
79 'slug' => $themes->get('TextDomain'),
80 'author' => $themes->get('Author'),
81 'item_id' => 181,
82 'url' => home_url()
83 );
84
85 $response = wp_remote_post( 'https://www.wpxpo.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
86
87 if ( !is_wp_error( $response ) || 200 === wp_remote_retrieve_response_code( $response ) ) {
88 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
89 if(isset($license_data->license)) {
90 if ( $license_data->license == 'valid' ) {
91 set_transient( 'ulpt_theme_enable', 'integration', 2592000 ); // 30 days time
92 }
93 }
94 }
95 }
96 } else {
97 if ( $theme == 'integration' ) {
98 delete_transient('ulpt_theme_enable');
99 }
100 }
101 }
102
103
104 /**
105 * Check Compatibility
106 *
107 * @since v.1.0.0
108 * @return NULL
109 */
110 public function compatibility_check(){
111 require_once ULTP_PATH.'classes/Compatibility.php';
112 new \ULTP\Compatibility();
113 }
114
115
116 /**
117 * Option Panel CSS and JS Scripts
118 *
119 * @since v.1.0.0
120 * @return NULL
121 */
122 public function register_scripts_option_panel_callback(){
123 wp_enqueue_style('wp-color-picker');
124 wp_enqueue_script('wp-color-picker');
125 wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true);
126 wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER);
127 wp_localize_script('ultp-option-script', 'ultp_option_panel', array(
128 'width' => ultimate_post()->get_setting('editor_container'),
129 'security' => wp_create_nonce('ultp-nonce'),
130 'ajax' => admin_url('admin-ajax.php')
131 ));
132 }
133
134
135 /**
136 * Common Frontend and Backend CSS and JS Scripts
137 *
138 * @since v.1.0.0
139 * @return NULL
140 */
141 public function register_scripts_common(){
142 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
143 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery'), ULTP_VER, true);
144 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
145 'url' => ULTP_URL,
146 'ajax' => admin_url('admin-ajax.php'),
147 'security' => wp_create_nonce('ultp-nonce')
148 ));
149
150 }
151
152
153 /**
154 * Only Frontend CSS and JS Scripts
155 *
156 * @since v.1.0.0
157 * @return NULL
158 */
159 public function register_scripts_front_callback() {
160 if ('yes' == get_post_meta(get_the_ID(), '_ultp_active', true)) {
161 $this->register_scripts_common();
162 } else {
163 if (ultimate_post()->is_builder()) {
164 $this->register_scripts_common();
165 }
166 }
167 }
168
169
170 /**
171 * Only Backend CSS and JS Scripts
172 *
173 * @since v.1.0.0
174 * @return NULL
175 */
176 public function register_scripts_back_callback() {
177 $this->register_scripts_common();
178 wp_enqueue_script('ultp-blocks-editor-script', ULTP_URL.'assets/js/editor.blocks.min.js', array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-editor' ), ULTP_VER, true);
179 wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER);
180 if(is_rtl()){
181 wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER);
182 }
183 $is_active = ultimate_post()->is_lc_active();
184 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
185 'url' => ULTP_URL,
186 'ajax' => admin_url('admin-ajax.php'),
187 'security' => wp_create_nonce('ultp-nonce'),
188 'hide_import_btn' => ultimate_post()->get_setting('hide_import_btn'),
189 'upload' => wp_upload_dir()['basedir'] . '/ultp',
190 'premium_link' => ultimate_post()->get_premium_link(),
191 'license' => $is_active ? get_option('edd_ultp_license_key') : '',
192 'active' => $is_active,
193 'archive' => $is_active ? ultimate_post()->is_archive_builder() : '',
194 'settings' => ultimate_post()->get_setting()
195 ));
196
197 wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
198 }
199
200
201 /**
202 * Fire When Plugin First Install
203 *
204 * @since v.1.0.0
205 * @return NULL
206 */
207 public function install_hook() {
208 if (!get_option('ultp_options')) {
209 ultimate_post()->init_set_data();
210 }
211 }
212
213
214 /**
215 * Redirect After Active Plugin
216 *
217 * @since v.1.0.0
218 * @param STRING | Plugin Path
219 * @return NULL
220 */
221 public function activation_redirect($plugin) {
222 if( $plugin == 'ultimate-post/ultimate-post.php' ) {
223 exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
224 }
225 }
226
227
228 /**
229 * Require Blocks
230 *
231 * @since v.1.0.0
232 * @return NULL
233 */
234 public function blocks() {
235 $setting = ultimate_post()->get_setting();
236 if (!isset($setting['post_list_1']) || $setting['post_list_1'] == 'yes') {
237 require_once ULTP_PATH.'blocks/Post_List_1.php';
238 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
239 }
240 if (!isset($setting['post_list_2']) || $setting['post_list_2'] == 'yes') {
241 require_once ULTP_PATH.'blocks/Post_List_2.php';
242 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
243 }
244 if (!isset($setting['post_list_3']) || $setting['post_list_3'] == 'yes') {
245 require_once ULTP_PATH.'blocks/Post_List_3.php';
246 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
247 }
248 if (!isset($setting['post_list_4']) || $setting['post_list_4'] == 'yes') {
249 require_once ULTP_PATH.'blocks/Post_List_4.php';
250 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
251 }
252 if (!isset($setting['post_grid_1']) || $setting['post_grid_1'] == 'yes') {
253 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
254 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
255 }
256 if (!isset($setting['post_grid_2']) || $setting['post_grid_2'] == 'yes') {
257 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
258 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
259 }
260 if (!isset($setting['post_grid_3']) || $setting['post_grid_3'] == 'yes') {
261 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
262 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
263 }
264 if (!isset($setting['post_grid_4']) || $setting['post_grid_4'] == 'yes') {
265 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
266 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
267 }
268 if (!isset($setting['post_grid_5']) || $setting['post_grid_5'] == 'yes') {
269 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
270 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
271 }
272 if (!isset($setting['post_grid_6']) || $setting['post_grid_6'] == 'yes') {
273 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
274 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
275 }
276 if (!isset($setting['post_grid_7']) || $setting['post_grid_7'] == 'yes') {
277 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
278 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
279 }
280 if (!isset($setting['post_slider_1']) || $setting['post_slider_1'] == 'yes') {
281 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
282 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
283 }
284 if (!isset($setting['post_module_1']) || $setting['post_module_1'] == 'yes') {
285 require_once ULTP_PATH.'blocks/Post_Module_1.php';
286 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
287 }
288 if (!isset($setting['post_module_2']) || $setting['post_module_2'] == 'yes') {
289 require_once ULTP_PATH.'blocks/Post_Module_2.php';
290 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
291 }
292 if (!isset($setting['heading']) || $setting['heading'] == 'yes') {
293 require_once ULTP_PATH.'blocks/Heading.php';
294 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
295 }
296 if (!isset($setting['image']) || $setting['image'] == 'yes') {
297 require_once ULTP_PATH.'blocks/Image.php';
298 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
299 }
300 if (!isset($setting['taxonomy']) || $setting['taxonomy'] == 'yes') {
301 require_once ULTP_PATH.'blocks/Taxonomy.php';
302 $this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy();
303 }
304
305 require_once ULTP_PATH.'blocks/Archive_Title.php';
306 $this->all_blocks['ultimate-post_archive-title'] = new \ULTP\blocks\Archive_Title();
307 }
308
309
310 /**
311 * Necessary Requires Class
312 *
313 * @since v.1.0.0
314 * @return NULL
315 */
316 public function requires() {
317 require_once ULTP_PATH.'classes/Notice.php';
318 require_once ULTP_PATH.'classes/Styles.php';
319 require_once ULTP_PATH.'classes/Options.php';
320 require_once ULTP_PATH.'classes/REST_API.php';
321 require_once ULTP_PATH.'classes/Caches.php';
322 new \ULTP\REST_API();
323 new \ULTP\Caches();
324 new \ULTP\Options();
325 new \ULTP\Styles();
326 new \ULTP\Notice();
327
328 require_once ULTP_PATH.'classes/Deactive.php';
329 new \ULTP\Deactive();
330 }
331
332
333 /**
334 * Block Categories Initialization
335 *
336 * @since v.1.0.0
337 * @param $categories(ARRAY) | $post (ARRAY)
338 * @return NULL
339 */
340 public function register_category_callback( $categories, $post ) {
341 return array_merge(
342 array(
343 array(
344 'slug' => 'ultimate-post',
345 'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' )
346 )
347 ), $categories
348 );
349 }
350
351
352 /**
353 * Post View Counter for Every Post
354 *
355 * @since v.1.0.0
356 * @param NUMBER | Post ID
357 * @return NULL
358 */
359 public function popular_posts_tracker_callback($post_id) {
360 if (!is_single()){ return; }
361 global $post;
362 $post_id = $post->ID;
363 if ($post_id) {
364 $has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? $_COOKIE['ultp_view_'.$post_id] : false;
365 if (!$has_cookie) {
366 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
367 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
368 setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
369 }
370 }
371 }
372
373
374 /**
375 * Set Image Size
376 *
377 * @since v.1.0.0
378 * @return NULL
379 */
380 public function add_image_size() {
381 $size_disable = ultimate_post()->get_setting('disable_image_size');
382 if ($size_disable != 'yes') {
383 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
384 add_image_size('ultp_layout_landscape', 870, 570, true);
385 add_image_size('ultp_layout_portrait', 600, 900, true);
386 add_image_size('ultp_layout_square', 600, 600, true);
387 }
388 }
389
390
391 /**
392 * Include Addons Directory
393 *
394 * @since v.1.0.0
395 * @return NULL
396 */
397 public function include_addons() {
398 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
399 if (count($addons_dir) > 0) {
400 foreach( $addons_dir as $key => $value ) {
401 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
402 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
403 if ( file_exists($file_name) ) {
404 include_once $file_name;
405 }
406 }
407 }
408 }
409
410
411 /**
412 * Addon Callback
413 *
414 * @since v.1.0.0
415 * @return STRING
416 */
417 public function ultp_addon_callback() {
418 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
419 return ;
420 }
421 $addon_name = sanitize_text_field($_POST['addon']);
422 $addon_value = sanitize_text_field($_POST['value']);
423 if ($addon_name) {
424 $addon_data = ultimate_post()->get_setting();
425 $addon_data[$addon_name] = $addon_value;
426 $GLOBALS['ultp_settings'][$addon_name] = $addon_value;
427 update_option('ultp_options', $addon_data);
428 }
429 }
430
431
432 /**
433 * Next Preview Callback of the Blocks
434 *
435 * @since v.1.0.0
436 * @return STRING
437 */
438 public function ultp_next_prev_callback() {
439 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
440 return ;
441 }
442
443 $paged = sanitize_text_field($_POST['paged']);
444 $blockId = sanitize_text_field($_POST['blockId']);
445 $postId = sanitize_text_field($_POST['postId']);
446 $blockRaw = sanitize_text_field($_POST['blockName']);
447 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
448
449 $blockName = str_replace('_','/', $blockRaw);
450
451 if( $paged && $blockId && $postId && $blockName ) {
452 $post = get_post($postId);
453 if (has_blocks($post->post_content)) {
454 $blocks = parse_blocks($post->post_content);
455 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder);
456 }
457 }
458 }
459
460
461 /**
462 * Filter Callback of the Blocks
463 *
464 * @since v.1.0.0
465 * @return STRING
466 */
467 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
468 foreach ($blocks as $key => $value) {
469 if($blockName == $value['blockName']) {
470 if($value['attrs']['blockId'] == $blockId) {
471 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
472 if($taxonomy) {
473 $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
474 $value['attrs']['queryTax'] = $taxtype;
475 }
476 if(isset($value['attrs']['queryNumber'])){
477 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
478 }
479 $attr = array_merge($attr, $value['attrs']);
480 echo $this->all_blocks[$blockRaw]->content($attr, true);
481 die();
482 }
483 }
484 if(!empty($value['innerBlocks'])){
485 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
486 }
487 }
488 }
489
490
491 /**
492 * Filter Callback of the Blocks
493 *
494 * @since v.1.0.0
495 * @return STRING
496 */
497 public function ultp_filter_callback() {
498 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
499 return ;
500 }
501
502 $taxtype = sanitize_text_field($_POST['taxtype']);
503 $blockId = sanitize_text_field($_POST['blockId']);
504 $postId = sanitize_text_field($_POST['postId']);
505 $taxonomy = sanitize_text_field($_POST['taxonomy']);
506 $blockRaw = sanitize_text_field($_POST['blockName']);
507 $blockName = str_replace('_','/', $blockRaw);
508
509 if( $taxtype ) {
510 $post = get_post($postId);
511 if (has_blocks($post->post_content)) {
512 $blocks = parse_blocks($post->post_content);
513 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
514 }
515 }
516 }
517
518
519 /**
520 * Pagination of the Blocks
521 *
522 * @since v.1.0.0
523 * @return STRING
524 */
525 public function ultp_pagination_callback() {
526 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
527 return ;
528 }
529
530 $paged = sanitize_text_field($_POST['paged']);
531 $blockId = sanitize_text_field($_POST['blockId']);
532 $postId = sanitize_text_field($_POST['postId']);
533 $blockRaw = sanitize_text_field($_POST['blockName']);
534 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
535
536 $blockName = str_replace('_','/', $blockRaw);
537
538 if($paged) {
539 $post = get_post($postId);
540 if (has_blocks($post->post_content)) {
541 $blocks = parse_blocks($post->post_content);
542 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder);
543 }
544 }
545 }
546
547
548 /**
549 * Blocks Content Start
550 *
551 * @since v.1.0.0
552 * @return STRING
553 */
554 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder) {
555 foreach ($blocks as $key => $value) {
556 if($blockName == $value['blockName']) {
557 if($value['attrs']['blockId'] == $blockId) {
558 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
559 $value['attrs']['paged'] = $paged;
560 if ($builder) {
561 $value['attrs']['builder'] = $builder;
562 }
563 $attr = array_merge($attr, $value['attrs']);
564 echo $this->all_blocks[$blockRaw]->content($attr, true);
565 die();
566 }
567 }
568 if(!empty($value['innerBlocks'])){
569 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder);
570 }
571 }
572 }
573
574 }