PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.4.0
Post Grid Gutenberg Blocks – PostX v2.4.0
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.0, at classes/Initialization.php

537 lines 18.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_head', 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
184 $import = ultimate_post()->get_setting('hide_import_btn');
185
186 $is_active = get_option('edd_ultp_license_status') == 'valid' ? true : ( get_transient( 'ulpt_theme_enable' ) == 'integration' ? true : false );
187
188 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
189 'url' => ULTP_URL,
190 'ajax' => admin_url('admin-ajax.php'),
191 'security' => wp_create_nonce('ultp-nonce'),
192 'hide_import_btn' => $import,
193 'upload' => wp_upload_dir()['basedir'] . '/ultp',
194 'premium_link' => ultimate_post()->get_premium_link(),
195 'license' => get_option('edd_ultp_license_key'),
196 'active' => $is_active,
197 'archive' => ultimate_post()->is_archive_builder()
198 ));
199
200 wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
201 }
202
203
204 /**
205 * Fire When Plugin First Install
206 *
207 * @since v.1.0.0
208 * @return NULL
209 */
210 public function install_hook() {
211 if (!get_option('ultp_options')) {
212 ultimate_post()->init_set_data();
213 }
214 }
215
216
217 /**
218 * Redirect After Active Plugin
219 *
220 * @since v.1.0.0
221 * @param STRING | Plugin Path
222 * @return NULL
223 */
224 public function activation_redirect($plugin) {
225 if( $plugin == 'ultimate-post/ultimate-post.php' ) {
226 exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
227 }
228 }
229
230
231 /**
232 * Require Blocks
233 *
234 * @since v.1.0.0
235 * @return NULL
236 */
237 public function blocks() {
238 require_once ULTP_PATH.'blocks/Post_List_1.php';
239 require_once ULTP_PATH.'blocks/Post_List_2.php';
240 require_once ULTP_PATH.'blocks/Post_List_3.php';
241 require_once ULTP_PATH.'blocks/Post_List_4.php';
242 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
243 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
244 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
245 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
246 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
247 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
248 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
249 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
250 require_once ULTP_PATH.'blocks/Heading.php';
251 require_once ULTP_PATH.'blocks/Image.php';
252 require_once ULTP_PATH.'blocks/Post_Module_1.php';
253 require_once ULTP_PATH.'blocks/Post_Module_2.php';
254 require_once ULTP_PATH.'blocks/Taxonomy.php';
255
256 require_once ULTP_PATH.'blocks/Archive_Title.php';
257
258 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
259 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
260 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
261 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
262 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
263 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
264 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
265 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
266 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
267 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
268 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
269 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
270 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
271 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
272 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
273 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
274 $this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy();
275 $this->all_blocks['ultimate-post_archive-title'] = new \ULTP\blocks\Archive_Title();
276 }
277
278
279 /**
280 * Necessary Requires Class
281 *
282 * @since v.1.0.0
283 * @return NULL
284 */
285 public function requires() {
286 require_once ULTP_PATH.'classes/Notice.php';
287 require_once ULTP_PATH.'classes/Styles.php';
288 require_once ULTP_PATH.'classes/Options.php';
289 require_once ULTP_PATH.'classes/REST_API.php';
290 require_once ULTP_PATH.'classes/Caches.php';
291 new \ULTP\REST_API();
292 new \ULTP\Caches();
293 new \ULTP\Options();
294 new \ULTP\Styles();
295 new \ULTP\Notice();
296
297 require_once ULTP_PATH.'classes/Deactive.php';
298 new \ULTP\Deactive();
299 }
300
301
302 /**
303 * Block Categories Initialization
304 *
305 * @since v.1.0.0
306 * @param $categories(ARRAY) | $post (ARRAY)
307 * @return NULL
308 */
309 public function register_category_callback( $categories, $post ) {
310 return array_merge(
311 array(
312 array(
313 'slug' => 'ultimate-post',
314 'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' )
315 )
316 ), $categories
317 );
318 }
319
320
321 /**
322 * Post View Counter for Every Post
323 *
324 * @since v.1.0.0
325 * @param NUMBER | Post ID
326 * @return NULL
327 */
328 public function popular_posts_tracker_callback($post_id) {
329 if (!is_single()){ return; }
330 global $post;
331 if (empty($post_id)) { $post_id = $post->ID; }
332 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
333 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
334 }
335
336
337 /**
338 * Set Image Size
339 *
340 * @since v.1.0.0
341 * @return NULL
342 */
343 public function add_image_size() {
344 $size_disable = ultimate_post()->get_setting('disable_image_size');
345 if ($size_disable != 'yes') {
346 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
347 add_image_size('ultp_layout_landscape', 870, 570, true);
348 add_image_size('ultp_layout_portrait', 600, 900, true);
349 add_image_size('ultp_layout_square', 600, 600, true);
350 }
351 }
352
353
354 /**
355 * Include Addons Directory
356 *
357 * @since v.1.0.0
358 * @return NULL
359 */
360 public function include_addons() {
361 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
362 if (count($addons_dir) > 0) {
363 foreach( $addons_dir as $key => $value ) {
364 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
365 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
366 if ( file_exists($file_name) ) {
367 include_once $file_name;
368 }
369 }
370 }
371 }
372
373
374 /**
375 * Addon Callback
376 *
377 * @since v.1.0.0
378 * @return STRING
379 */
380 public function ultp_addon_callback() {
381 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
382 return ;
383 }
384 $addon_name = sanitize_text_field($_POST['addon']);
385 $addon_value = sanitize_text_field($_POST['value']);
386 if ($addon_name) {
387 $addon_data = ultimate_post()->get_setting();
388 $addon_data[$addon_name] = $addon_value;
389 $GLOBALS['ultp_settings'][$addon_name] = $addon_value;
390 update_option('ultp_options', $addon_data);
391 }
392 }
393
394
395 /**
396 * Next Preview Callback of the Blocks
397 *
398 * @since v.1.0.0
399 * @return STRING
400 */
401 public function ultp_next_prev_callback() {
402 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
403 return ;
404 }
405
406 $paged = sanitize_text_field($_POST['paged']);
407 $blockId = sanitize_text_field($_POST['blockId']);
408 $postId = sanitize_text_field($_POST['postId']);
409 $blockRaw = sanitize_text_field($_POST['blockName']);
410 $builder = sanitize_text_field($_POST['builder']);
411
412 $blockName = str_replace('_','/', $blockRaw);
413
414 if( $paged && $blockId && $postId && $blockName ) {
415 $post = get_post($postId);
416 if (has_blocks($post->post_content)) {
417 $blocks = parse_blocks($post->post_content);
418 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder);
419 }
420 }
421 }
422
423
424 /**
425 * Filter Callback of the Blocks
426 *
427 * @since v.1.0.0
428 * @return STRING
429 */
430 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
431 foreach ($blocks as $key => $value) {
432 if($blockName == $value['blockName']) {
433 if($value['attrs']['blockId'] == $blockId) {
434 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
435 if($taxonomy) {
436 $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
437 $value['attrs']['queryTax'] = $taxtype;
438 }
439 if(isset($value['attrs']['queryNumber'])){
440 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
441 }
442 $attr = array_merge($attr, $value['attrs']);
443 echo $this->all_blocks[$blockRaw]->content($attr, true);
444 die();
445 }
446 }
447 if(!empty($value['innerBlocks'])){
448 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
449 }
450 }
451 }
452
453
454 /**
455 * Filter Callback of the Blocks
456 *
457 * @since v.1.0.0
458 * @return STRING
459 */
460 public function ultp_filter_callback() {
461 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
462 return ;
463 }
464
465 $taxtype = sanitize_text_field($_POST['taxtype']);
466 $blockId = sanitize_text_field($_POST['blockId']);
467 $postId = sanitize_text_field($_POST['postId']);
468 $taxonomy = sanitize_text_field($_POST['taxonomy']);
469 $blockRaw = sanitize_text_field($_POST['blockName']);
470 $blockName = str_replace('_','/', $blockRaw);
471
472 if( $taxtype ) {
473 $post = get_post($postId);
474 if (has_blocks($post->post_content)) {
475 $blocks = parse_blocks($post->post_content);
476 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
477 }
478 }
479 }
480
481
482 /**
483 * Pagination of the Blocks
484 *
485 * @since v.1.0.0
486 * @return STRING
487 */
488 public function ultp_pagination_callback() {
489 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
490 return ;
491 }
492
493 $paged = sanitize_text_field($_POST['paged']);
494 $blockId = sanitize_text_field($_POST['blockId']);
495 $postId = sanitize_text_field($_POST['postId']);
496 $blockRaw = sanitize_text_field($_POST['blockName']);
497 $builder = sanitize_text_field($_POST['builder']);
498
499 $blockName = str_replace('_','/', $blockRaw);
500
501 if($paged) {
502 $post = get_post($postId);
503 if (has_blocks($post->post_content)) {
504 $blocks = parse_blocks($post->post_content);
505 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder);
506 }
507 }
508 }
509
510
511 /**
512 * Blocks Content Start
513 *
514 * @since v.1.0.0
515 * @return STRING
516 */
517 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder) {
518 foreach ($blocks as $key => $value) {
519 if($blockName == $value['blockName']) {
520 if($value['attrs']['blockId'] == $blockId) {
521 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
522 $value['attrs']['paged'] = $paged;
523 if ($builder) {
524 $value['attrs']['builder'] = $builder;
525 }
526 $attr = array_merge($attr, $value['attrs']);
527 echo $this->all_blocks[$blockRaw]->content($attr, true);
528 die();
529 }
530 }
531 if(!empty($value['innerBlocks'])){
532 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
533 }
534 }
535 }
536
537 }