PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.4.10
Post Grid Gutenberg Blocks – PostX v2.4.10
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.10, at classes/Initialization.php

575 lines 21.0 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_all', 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 $isEnable = apply_filters('ultp_view_cookies', true);
364 if ($post_id && $isEnable) {
365 $has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? $_COOKIE['ultp_view_'.$post_id] : false;
366 if (!$has_cookie) {
367 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
368 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
369 setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
370 }
371 }
372 }
373
374
375 /**
376 * Set Image Size
377 *
378 * @since v.1.0.0
379 * @return NULL
380 */
381 public function add_image_size() {
382 $size_disable = ultimate_post()->get_setting('disable_image_size');
383 if ($size_disable != 'yes') {
384 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
385 add_image_size('ultp_layout_landscape', 870, 570, true);
386 add_image_size('ultp_layout_portrait', 600, 900, true);
387 add_image_size('ultp_layout_square', 600, 600, true);
388 }
389 }
390
391
392 /**
393 * Include Addons Directory
394 *
395 * @since v.1.0.0
396 * @return NULL
397 */
398 public function include_addons() {
399 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
400 if (count($addons_dir) > 0) {
401 foreach( $addons_dir as $key => $value ) {
402 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
403 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
404 if ( file_exists($file_name) ) {
405 include_once $file_name;
406 }
407 }
408 }
409 }
410
411
412 /**
413 * Addon Callback
414 *
415 * @since v.1.0.0
416 * @return STRING
417 */
418 public function ultp_addon_callback() {
419 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
420 return ;
421 }
422 $addon_name = sanitize_text_field($_POST['addon']);
423 $addon_value = sanitize_text_field($_POST['value']);
424 if ($addon_name && current_user_can('administrator')) {
425 $addon_data = ultimate_post()->get_setting();
426 $addon_data[$addon_name] = $addon_value;
427 $GLOBALS['ultp_settings'][$addon_name] = $addon_value;
428 update_option('ultp_options', $addon_data);
429 }
430 }
431
432
433 /**
434 * Next Preview Callback of the Blocks
435 *
436 * @since v.1.0.0
437 * @return STRING
438 */
439 public function ultp_next_prev_callback() {
440 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
441 return ;
442 }
443
444 $paged = sanitize_text_field($_POST['paged']);
445 $blockId = sanitize_text_field($_POST['blockId']);
446 $postId = sanitize_text_field($_POST['postId']);
447 $blockRaw = sanitize_text_field($_POST['blockName']);
448 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
449
450 $blockName = str_replace('_','/', $blockRaw);
451
452 if( $paged && $blockId && $postId && $blockName ) {
453 $post = get_post($postId);
454 if (has_blocks($post->post_content)) {
455 $blocks = parse_blocks($post->post_content);
456 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder);
457 }
458 }
459 }
460
461
462 /**
463 * Filter Callback of the Blocks
464 *
465 * @since v.1.0.0
466 * @return STRING
467 */
468 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
469 foreach ($blocks as $key => $value) {
470 if($blockName == $value['blockName']) {
471 if($value['attrs']['blockId'] == $blockId) {
472 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
473 if($taxonomy) {
474 $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
475 $value['attrs']['queryTax'] = $taxtype;
476 }
477 if(isset($value['attrs']['queryNumber'])){
478 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
479 }
480 $attr = array_merge($attr, $value['attrs']);
481 echo $this->all_blocks[$blockRaw]->content($attr, true);
482 die();
483 }
484 }
485 if(!empty($value['innerBlocks'])){
486 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
487 }
488 }
489 }
490
491
492 /**
493 * Filter Callback of the Blocks
494 *
495 * @since v.1.0.0
496 * @return STRING
497 */
498 public function ultp_filter_callback() {
499 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
500 return ;
501 }
502
503 $taxtype = sanitize_text_field($_POST['taxtype']);
504 $blockId = sanitize_text_field($_POST['blockId']);
505 $postId = sanitize_text_field($_POST['postId']);
506 $taxonomy = sanitize_text_field($_POST['taxonomy']);
507 $blockRaw = sanitize_text_field($_POST['blockName']);
508 $blockName = str_replace('_','/', $blockRaw);
509
510 if( $taxtype ) {
511 $post = get_post($postId);
512 if (has_blocks($post->post_content)) {
513 $blocks = parse_blocks($post->post_content);
514 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
515 }
516 }
517 }
518
519
520 /**
521 * Pagination of the Blocks
522 *
523 * @since v.1.0.0
524 * @return STRING
525 */
526 public function ultp_pagination_callback() {
527 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
528 return ;
529 }
530
531 $paged = sanitize_text_field($_POST['paged']);
532 $blockId = sanitize_text_field($_POST['blockId']);
533 $postId = sanitize_text_field($_POST['postId']);
534 $blockRaw = sanitize_text_field($_POST['blockName']);
535 $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
536
537 $blockName = str_replace('_','/', $blockRaw);
538
539 if($paged) {
540 $post = get_post($postId);
541 if (has_blocks($post->post_content)) {
542 $blocks = parse_blocks($post->post_content);
543 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder);
544 }
545 }
546 }
547
548
549 /**
550 * Blocks Content Start
551 *
552 * @since v.1.0.0
553 * @return STRING
554 */
555 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder) {
556 foreach ($blocks as $key => $value) {
557 if($blockName == $value['blockName']) {
558 if($value['attrs']['blockId'] == $blockId) {
559 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
560 $value['attrs']['paged'] = $paged;
561 if ($builder) {
562 $value['attrs']['builder'] = $builder;
563 }
564 $attr = array_merge($attr, $value['attrs']);
565 echo $this->all_blocks[$blockRaw]->content($attr, true);
566 die();
567 }
568 }
569 if(!empty($value['innerBlocks'])){
570 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder);
571 }
572 }
573 }
574
575 }