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