PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.7.8
Post Grid Gutenberg Blocks – PostX v2.7.8
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 +527 -114 2.1.22.7.8 View file →
@@ -1,21 +1,35 @@
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
10 - public function __construct(){
19 + /**
20 + * Setup class.
21 + *
22 + * @since v.1.1.0
23 + */
24 + public function __construct() {
11 25 $this->compatibility_check();
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,99 +42,257 @@
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 + add_action('wp_ajax_ultp_share_count', array($this, 'ultp_shareCount_callback')); // share Count save
48 +
49 + add_action('admin_init', array($this, 'check_theme_compatibility'));
50 + add_action( 'after_switch_theme', array($this, 'wpxpo_swithch_thememe'));
51 +
52 + add_action( 'wp_ajax_plugin_settings', array( $this, 'save_plugin_settings_data' ) );
53 + add_action( 'in_plugin_update_message-'.ULTP_BASE, array( $this, 'in_plugin_settings_update_message' ) );
33 54 }
34 55
35 - public function compatibility_check(){
56 + /**
57 + * Theme Switch Callback
58 + *
59 + * @since v.1.1.0
60 + * @return NULL
61 + */
62 + public function wpxpo_swithch_thememe () {
63 + $this->check_theme_compatibility();
64 + }
65 +
66 +
67 + /**
68 + * Theme Compatibility Action
69 + *
70 + * @since v.1.1.0
71 + * @return NULL
72 + */
73 + public function check_theme_compatibility() {
74 + $licence = apply_filters( 'ultp_theme_integration' , FALSE);
75 + $theme = get_transient( 'ulpt_theme_enable' );
76 +
77 + if ($licence ) {
78 + if ($theme != 'integration' ) {
79 + $themes = wp_get_theme();
80 + $api_params = array(
81 + 'wpxpo_theme_action' => 'theme_license',
82 + 'slug' => $themes->get('TextDomain'),
83 + 'author' => $themes->get('Author'),
84 + 'item_id' => 181,
85 + 'url' => home_url()
86 + );
87 +
88 + $response = wp_remote_post( 'https://www.wpxpo.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
89 +
90 + if (!is_wp_error( $response ) || 200 === wp_remote_retrieve_response_code( $response ) ) {
91 + $license_data = json_decode( wp_remote_retrieve_body( $response ) );
92 + if (isset($license_data->license)) {
93 + if ($license_data->license == 'valid' ) {
94 + set_transient( 'ulpt_theme_enable', 'integration', 2592000 ); // 30 days time
95 + }
96 + }
97 + }
98 + }
99 + } else {
100 + if ($theme == 'integration' ) {
101 + delete_transient('ulpt_theme_enable');
102 + }
103 + }
104 + }
105 +
106 +
107 + /**
108 + * Check Compatibility
109 + *
110 + * @since v.1.0.0
111 + * @return NULL
112 + */
113 + public function compatibility_check() {
36 114 require_once ULTP_PATH.'classes/Compatibility.php';
37 115 new \ULTP\Compatibility();
38 116 }
39 117
40 - public function register_scripts_option_panel_callback(){
118 +
119 + /**
120 + * Option Panel CSS and JS Scripts
121 + *
122 + * @since v.1.0.0
123 + * @return NULL
124 + */
125 + public function register_scripts_option_panel_callback() {
126 + $is_active = ultimate_post()->is_lc_active();
127 + $license_key = $is_active ? get_option('edd_ultp_license_key') : '';
128 +
41 129 wp_enqueue_style('wp-color-picker');
42 130 wp_enqueue_script('wp-color-picker');
43 131 wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true);
44 132 wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER);
45 133 wp_localize_script('ultp-option-script', 'ultp_option_panel', array(
46 - 'width' => ultimate_post()->get_setting('editor_container'),
47 134 'security' => wp_create_nonce('ultp-nonce'),
48 - 'ajax' => admin_url('admin-ajax.php')
135 + 'ajax' => admin_url('admin-ajax.php'),
136 + 'license' => $license_key,
49 137 ));
138 +
139 + // Conditions
140 + $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
141 + if ($_page == 'ultp-settings' || get_post_type(get_the_ID()) == 'ultp_builder') {
142 + wp_enqueue_script('ultp-conditions-script', ULTP_URL.'addons/builder/assets/js/conditions.js', array('wp-api-fetch','wp-components','wp-i18n','wp-blocks'), ULTP_VER, true);
143 + wp_localize_script('ultp-conditions-script', 'ultp_condition', array(
144 + 'url' => ULTP_URL,
145 + 'active' => $is_active,
146 + 'premium_link' => ultimate_post()->get_premium_link(),
147 + 'license' => $license_key,
148 + 'builder_url' => admin_url('admin.php?page=ultp-settings#builder'),
149 + ));
150 + }
50 151 }
51 152
52 - 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_frontend', array(
62 - 'url' => ULTP_URL,
63 - 'ajax' => admin_url('admin-ajax.php'),
64 - 'security' => wp_create_nonce('ultp-nonce')
65 - ));
66 - }
67 153
68 - // Backend and Frontend Load script
154 + /**
155 + * Only Frontend CSS and JS Scripts
156 + *
157 + * @since v.1.0.0
158 + * @return NULL
159 + */
69 160 public function register_scripts_front_callback() {
70 - if ('yes' == get_post_meta(get_the_ID(), '_ultp_active', true)) {
71 - $this->register_scripts_common();
161 + $call_common = false;
162 + if (isset($_GET['preview_id']) && isset($_GET['preview_nonce'])) {
163 + $call_common = true;
164 + ultimate_post()->register_scripts_common();
165 + } else if ('yes' == get_post_meta(ultimate_post()->get_ID(), '_ultp_active', true)) {
166 + $call_common = true;
167 + ultimate_post()->register_scripts_common();
168 + } else if (ultimate_post()->is_builder()) {
169 + $call_common = true;
170 + ultimate_post()->register_scripts_common();
171 + } else if (apply_filters('postx_common_script', false)) {
172 + $call_common = true;
173 + ultimate_post()->register_scripts_common();
72 174 }
175 +
176 + // For WidgetWidget
177 + $has_block = false;
178 + $widget_blocks = array();
179 + global $wp_registered_sidebars, $sidebars_widgets;
180 + foreach ($wp_registered_sidebars as $key => $value) {
181 + if (is_active_sidebar($key)) {
182 + foreach ($sidebars_widgets[$key] as $val) {
183 + if (strpos($val, 'block-') !== false) {
184 + if (empty($widget_blocks)) {
185 + $widget_blocks = get_option( 'widget_block' );
186 + }
187 + foreach ( (array) $widget_blocks as $block ) {
188 + if (isset( $block['content'] ) && strpos($block['content'], 'wp:ultimate-post') !== false ) {
189 + $has_block = true;
190 + break;
191 + }
192 + }
193 + if ($has_block) {
194 + break;
195 + }
196 + }
197 + }
198 + }
199 + }
200 + if ($has_block) {
201 + if (!$call_common) {
202 + ultimate_post()->register_scripts_common();
203 + }
204 + $css = get_option('ultp-widget', true);
205 + if ($css) {
206 + wp_register_style('ultp-post-widget', false );
207 + wp_enqueue_style('ultp-post-widget' );
208 + wp_add_inline_style('ultp-post-widget', $css);
209 + }
210 + }
73 211 }
74 212
75 - // Only Backend
213 +
214 + /**
215 + * Only Backend CSS and JS Scripts
216 + *
217 + * @since v.1.0.0
218 + * @return NULL
219 + */
76 220 public function register_scripts_back_callback() {
77 - $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 + ultimate_post()->register_scripts_common();
222 + global $pagenow;
223 + $depends = 'wp-editor';
224 + if ($pagenow === 'widgets.php' ) {
225 + $depends = 'wp-edit-widgets';
226 + }
227 + wp_enqueue_script('ultp-blocks-editor-script', ULTP_URL.'assets/js/editor.blocks.js', array('wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', $depends ), ULTP_VER, true);
79 228 wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER);
80 - if(is_rtl()){
229 + if (is_rtl()) {
81 230 wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER);
82 231 }
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 -
232 + $is_active = ultimate_post()->is_lc_active();
93 233 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
94 234 'url' => ULTP_URL,
95 235 'ajax' => admin_url('admin-ajax.php'),
96 236 'security' => wp_create_nonce('ultp-nonce'),
97 - 'hide_import_btn' => $import,
237 + 'hide_import_btn' => ultimate_post()->get_setting('hide_import_btn'),
98 238 'upload' => wp_upload_dir()['basedir'] . '/ultp',
99 - 'license' => get_option('edd_ultp_license_key')
239 + 'premium_link' => ultimate_post()->get_premium_link(),
240 + 'license' => $is_active ? get_option('edd_ultp_license_key') : '',
241 + 'active' => $is_active,
242 + 'archive' => ultimate_post()->is_archive_builder(),
243 + 'settings' => ultimate_post()->get_setting(),
244 + 'post_type' => get_post_type(),
245 + 'date_format' => get_option('date_format'),
246 + 'time_format' => get_option('time_format')
100 247 ));
248 + wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
101 249 }
102 250
103 - // Fire When Plugin First Install
251 +
252 + /**
253 + * Fire When Plugin First Install
254 + *
255 + * @since v.1.0.0
256 + * @return NULL
257 + */
104 258 public function install_hook() {
105 259 if (!get_option('ultp_options')) {
106 260 ultimate_post()->init_set_data();
107 261 }
262 + if (!get_transient('wpxpo_installation_date')) {
263 + set_transient( 'wpxpo_installation_date', 'yes', 5 * DAY_IN_SECONDS ); // 5 Days Notice
264 + }
108 265 }
109 266
267 +
268 + /**
269 + * Redirect After Active Plugin
270 + *
271 + * @since v.1.0.0
272 + * @param STRING | Plugin Path
273 + * @return NULL
274 + */
110 275 public function activation_redirect($plugin) {
111 - if( $plugin == 'ultimate-post/ultimate-post.php' ) {
112 - exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
276 + if ($plugin == 'ultimate-post/ultimate-post.php' ) {
277 + exit(wp_redirect(admin_url('admin.php?page=ultp-settings#templatekit')));
113 278 }
114 279 }
115 280
116 - // Require Blocks
281 +
282 + /**
283 + * Require Blocks
284 + *
285 + * @since v.1.0.0
286 + * @return NULL
287 + */
117 288 public function blocks() {
289 + global $unique_ID;
290 + $setting = ultimate_post()->get_setting();
118 291 require_once ULTP_PATH.'blocks/Post_List_1.php';
119 292 require_once ULTP_PATH.'blocks/Post_List_2.php';
120 293 require_once ULTP_PATH.'blocks/Post_List_3.php';
121 294 require_once ULTP_PATH.'blocks/Post_List_4.php';
122 - require_once ULTP_PATH.'blocks/Post_Slider_1.php';
123 295 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
124 296 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
125 297 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
126 298 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
@@ -126,17 +298,20 @@
126 298 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
127 299 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
128 300 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
129 301 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
302 + require_once ULTP_PATH.'blocks/Post_Slider_1.php';
303 + require_once ULTP_PATH.'blocks/Post_Module_1.php';
304 + require_once ULTP_PATH.'blocks/Post_Module_2.php';
130 305 require_once ULTP_PATH.'blocks/Heading.php';
131 306 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';
307 + require_once ULTP_PATH.'blocks/Taxonomy.php';
308 + require_once ULTP_PATH.'blocks/News_Ticker.php';
309 +
134 310 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
135 311 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
136 312 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
137 313 $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 314 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
140 315 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
141 316 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
142 317 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
@@ -142,15 +317,68 @@
142 317 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
143 318 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
144 319 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
145 320 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
321 + $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
322 + $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
323 + $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
146 324 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
147 325 $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();
326 + $this->all_blocks['ultimate-post_ultp-taxonomy'] = new \ULTP\blocks\Taxonomy();
327 + $this->all_blocks['ultimate-post_news-ticker'] = new \ULTP\blocks\News_Ticker();
328 +
329 + if (ultimate_post()->get_setting('ultp_builder') == 'true') {
330 + require_once ULTP_PATH.'addons/builder/blocks/Archive_Title.php';
331 + require_once ULTP_PATH.'addons/builder/blocks/Post_Title.php';
332 + require_once ULTP_PATH.'addons/builder/blocks/Post_Content.php';
333 + require_once ULTP_PATH.'addons/builder/blocks/Post_Featured_Image.php';
334 + require_once ULTP_PATH.'addons/builder/blocks/Post_Breadcrumb.php';
335 + require_once ULTP_PATH.'addons/builder/blocks/Post_Tag.php';
336 + require_once ULTP_PATH.'addons/builder/blocks/Post_Category.php';
337 + require_once ULTP_PATH.'addons/builder/blocks/Next_Previous.php';
338 + require_once ULTP_PATH.'addons/builder/blocks/Post_Excerpt.php';
339 + // require_once ULTP_PATH.'addons/builder/blocks/Post_Video.php';
340 + require_once ULTP_PATH.'addons/builder/blocks/Author_Box.php';
341 + require_once ULTP_PATH.'addons/builder/blocks/Post_Comments.php';
342 + require_once ULTP_PATH.'addons/builder/blocks/Post_View_Count.php';
343 + require_once ULTP_PATH.'addons/builder/blocks/Post_Reading_Time.php';
344 + require_once ULTP_PATH.'addons/builder/blocks/Post_Comment_Count.php';
345 + require_once ULTP_PATH.'addons/builder/blocks/Post_Author_Meta.php';
346 + require_once ULTP_PATH.'addons/builder/blocks/Post_Date_Meta.php';
347 + // require_once ULTP_PATH.'addons/builder/blocks/Related_Posts.php';
348 + require_once ULTP_PATH.'addons/builder/blocks/Post_Social_Share.php';
349 + require_once ULTP_PATH.'addons/builder/blocks/Advance_Post_Meta.php';
350 +
351 + new \ULTP\blocks\Archive_Title();
352 + new \ULTP\blocks\Post_Title();
353 + new \ULTP\blocks\Post_Content();
354 + new \ULTP\blocks\Post_Featured_Image();
355 + new \ULTP\blocks\Post_Breadcrumb();
356 + new \ULTP\blocks\Post_Tag();
357 + new \ULTP\blocks\Post_Category();
358 + new \ULTP\blocks\Next_Previous();
359 + new \ULTP\blocks\Post_Excerpt();
360 + // new \ULTP\blocks\Post_Video();
361 + new \ULTP\blocks\Author_Box();
362 + new \ULTP\blocks\Post_Comments();
363 + new \ULTP\blocks\Post_View_Count();
364 + new \ULTP\blocks\Post_Reading_Time();
365 + new \ULTP\blocks\Post_Comment_Count();
366 + new \ULTP\blocks\Post_Author_Meta();
367 + new \ULTP\blocks\Post_Date_Meta();
368 + // new \ULTP\blocks\Related_Posts();
369 + new \ULTP\blocks\Post_Social_Share();
370 + new \ULTP\blocks\Advance_Post_Meta();
371 + }
150 372 }
151 373
152 - // Require Categories
374 +
375 + /**
376 + * Necessary Requires Class
377 + *
378 + * @since v.1.0.0
379 + * @return NULL
380 + */
153 381 public function requires() {
154 382 require_once ULTP_PATH.'classes/Notice.php';
155 383 require_once ULTP_PATH.'classes/Styles.php';
156 384 require_once ULTP_PATH.'classes/Options.php';
@@ -155,44 +383,89 @@
155 383 require_once ULTP_PATH.'classes/Styles.php';
156 384 require_once ULTP_PATH.'classes/Options.php';
157 385 require_once ULTP_PATH.'classes/REST_API.php';
158 386 require_once ULTP_PATH.'classes/Caches.php';
387 + new \ULTP\REST_API();
159 388 new \ULTP\Caches();
160 389 new \ULTP\Options();
161 390 new \ULTP\Styles();
162 391 new \ULTP\Notice();
392 +
393 + require_once ULTP_PATH.'classes/Deactive.php';
394 + new \ULTP\Deactive();
163 395 }
164 396
165 - // Block Categories
397 +
398 + /**
399 + * Block Categories Initialization
400 + *
401 + * @since v.1.0.0
402 + * @param $categories(ARRAY) | $post (ARRAY)
403 + * @return NULL
404 + */
166 405 public function register_category_callback( $categories, $post ) {
167 - return array_merge(
406 + $attr = array(
168 407 array(
169 - array(
170 - 'slug' => 'ultimate-post',
171 - 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' )
172 - )
173 - ), $categories
408 + 'slug' => 'ultimate-post',
409 + 'title' => __('PostX - Gutenberg Post Blocks', 'ultimate-post')
410 + ),
411 + array(
412 + 'slug' => 'postx-site-builder',
413 + 'title' => __('PostX Site Builder', 'ultimate-post')
414 + )
174 415 );
416 + return array_merge($attr, $categories);
175 417 }
176 418
177 - // Post View Post Meta Set
419 +
420 + /**
421 + * Post View Counter for Every Post
422 + *
423 + * @since v.1.0.0
424 + * @param NUMBER | Post ID
425 + * @return NULL
426 + */
178 427 public function popular_posts_tracker_callback($post_id) {
179 - if (!is_single()){ return; }
428 + if (!is_single()) { return; }
180 429 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 );
430 + $post_id = isset($post->ID) ? $post->ID : '';
431 + $isEnable = apply_filters('ultp_view_cookies', true);
432 + // add_filter( 'ultp_view_cookies', '__return_false' );
433 + $cookies_disable = ultimate_post()->get_setting('disable_view_cookies');
434 + if ($post_id && $isEnable && $cookies_disable != 'yes') {
435 + $has_cookie = isset( $_COOKIE['ultp_view_'.$post_id] ) ? $_COOKIE['ultp_view_'.$post_id] : false;
436 + if (!$has_cookie) {
437 + $count = (int)get_post_meta( $post_id, '__post_views_count', true );
438 + update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
439 + setcookie( 'ultp_view_'.$post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
440 + }
441 + }
184 442 }
185 443
186 - // Set Image Size
444 +
445 + /**
446 + * Set Image Size
447 + *
448 + * @since v.1.0.0
449 + * @return NULL
450 + */
187 451 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);
452 + $size_disable = ultimate_post()->get_setting('disable_image_size');
453 + if ($size_disable != 'yes') {
454 + add_image_size('ultp_layout_landscape_large', 1200, 800, true);
455 + add_image_size('ultp_layout_landscape', 870, 570, true);
456 + add_image_size('ultp_layout_portrait', 600, 900, true);
457 + add_image_size('ultp_layout_square', 600, 600, true);
458 + }
192 459 }
193 460
194 - // Include Addons directory
461 +
462 + /**
463 + * Include Addons Directory
464 + *
465 + * @since v.1.0.0
466 + * @return NULL
467 + */
195 468 public function include_addons() {
196 469 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
197 470 if (count($addons_dir) > 0) {
198 471 foreach( $addons_dir as $key => $value ) {
@@ -197,9 +470,9 @@
197 470 if (count($addons_dir) > 0) {
198 471 foreach( $addons_dir as $key => $value ) {
199 472 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
200 473 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
201 - if ( file_exists($file_name) ) {
474 + if (file_exists($file_name) ) {
202 475 include_once $file_name;
203 476 }
204 477 }
205 478 }
@@ -205,24 +478,37 @@
205 478 }
206 479 }
207 480
208 481
482 + /**
483 + * Addon Callback
484 + *
485 + * @since v.1.0.0
486 + * @return STRING
487 + */
209 488 public function ultp_addon_callback() {
210 - if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
489 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
211 490 return ;
212 491 }
213 492 $addon_name = sanitize_text_field($_POST['addon']);
214 493 $addon_value = sanitize_text_field($_POST['value']);
215 - if ($addon_name) {
494 + if ($addon_name && current_user_can('administrator')) {
216 495 $addon_data = ultimate_post()->get_setting();
217 496 $addon_data[$addon_name] = $addon_value;
218 - $GLOBALS['wopb_settings'][$addon_name] = $addon_value;
497 + $GLOBALS['ultp_settings'][$addon_name] = $addon_value;
219 498 update_option('ultp_options', $addon_data);
220 499 }
221 500 }
222 501
502 +
503 + /**
504 + * Next Preview Callback of the Blocks
505 + *
506 + * @since v.1.0.0
507 + * @return STRING
508 + */
223 509 public function ultp_next_prev_callback() {
224 - if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
510 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
225 511 return ;
226 512 }
227 513
228 514 $paged = sanitize_text_field($_POST['paged']);
@@ -228,41 +514,47 @@
228 514 $paged = sanitize_text_field($_POST['paged']);
229 515 $blockId = sanitize_text_field($_POST['blockId']);
230 516 $postId = sanitize_text_field($_POST['postId']);
231 517 $blockRaw = sanitize_text_field($_POST['blockName']);
518 + $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
519 +
232 520 $blockName = str_replace('_','/', $blockRaw);
233 521
234 - if( $paged && $blockId && $postId && $blockName ) {
522 + if ($paged && $blockId && $postId && $blockName ) {
235 523 $post = get_post($postId);
236 524 if (has_blocks($post->post_content)) {
237 525 $blocks = parse_blocks($post->post_content);
238 - $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
526 + $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
239 527 }
240 528 }
241 529 }
242 530
531 +
532 + /**
533 + * Filter Callback of the Blocks
534 + *
535 + * @since v.1.0.0
536 + * @return STRING
537 + */
243 538 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
244 539 foreach ($blocks as $key => $value) {
245 - if($blockName == $value['blockName']) {
246 - if($value['attrs']['blockId'] == $blockId) {
540 + if ($blockName == $value['blockName']) {
541 + if ($value['attrs']['blockId'] == $blockId) {
247 542 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
248 - 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 - }
543 + if ($taxonomy) {
544 + $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
254 545 $value['attrs']['queryTax'] = $taxtype;
546 + $value['attrs']['ajaxCall'] = true;
255 547 }
256 - if(isset($value['attrs']['queryNumber'])){
548 + if (isset($value['attrs']['queryNumber'])) {
257 549 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
258 550 }
259 551 $attr = array_merge($attr, $value['attrs']);
260 - echo $this->all_blocks[$blockRaw]->content($attr, true);
552 + echo $this->all_blocks[$blockRaw]->content($attr, true);
261 553 die();
262 554 }
263 555 }
264 - if(!empty($value['innerBlocks'])){
556 + if (!empty($value['innerBlocks'])) {
265 557 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
266 558 }
267 559 }
268 560 }
@@ -267,21 +559,26 @@
267 559 }
268 560 }
269 561
270 562
563 + /**
564 + * Filter Callback of the Blocks
565 + *
566 + * @since v.1.0.0
567 + * @return STRING
568 + */
271 569 public function ultp_filter_callback() {
272 - if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
570 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
273 571 return ;
274 572 }
275 573
276 574 $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 - if( $taxtype ) {
575 + if ($taxtype ) {
576 + $blockId = sanitize_text_field($_POST['blockId']);
577 + $postId = sanitize_text_field($_POST['postId']);
578 + $taxonomy = sanitize_text_field($_POST['taxonomy']);
579 + $blockRaw = sanitize_text_field($_POST['blockName']);
580 + $blockName = str_replace('_','/', $blockRaw);
284 581 $post = get_post($postId);
285 582 if (has_blocks($post->post_content)) {
286 583 $blocks = parse_blocks($post->post_content);
287 584 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
@@ -288,43 +585,159 @@
288 585 }
289 586 }
290 587 }
291 588
589 +
590 + /**
591 + * Pagination of the Blocks
592 + *
593 + * @since v.1.0.0
594 + * @return STRING
595 + */
292 596 public function ultp_pagination_callback() {
293 - if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
597 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local) {
294 598 return ;
295 599 }
296 600
297 601 $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 - if($paged) {
602 + if ($paged) {
603 + $blockId = sanitize_text_field($_POST['blockId']);
604 + $postId = sanitize_text_field($_POST['postId']);
605 + $blockRaw = sanitize_text_field($_POST['blockName']);
606 + $builder = isset($_POST['builder']) ? sanitize_text_field($_POST['builder']) : '';
607 + $blockName = str_replace('_','/', $blockRaw);
304 608 $post = get_post($postId);
305 609 if (has_blocks($post->post_content)) {
306 610 $blocks = parse_blocks($post->post_content);
307 - $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
611 + $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
308 612 }
309 613 }
310 614 }
311 615
616 + /**
617 + * share Count callback
618 + *
619 + * @since v.1.0.0
620 + * @return STRING
621 + */
622 + public function ultp_shareCount_callback() {
623 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
624 + return ;
625 + }
626 + $id = sanitize_text_field($_POST['postId']);
627 + $count = sanitize_text_field($_POST['shareCount']);
628 + $post_id = $id;
629 + $new_count = $count+1;
630 + update_post_meta($post_id, 'share_count', $new_count);
631 + }
312 632
313 - public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) {
633 + /**
634 + * Blocks Content Start
635 + *
636 + * @since v.1.0.0
637 + * @return STRING
638 + */
639 + public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName, $builder, $postId) {
314 640 foreach ($blocks as $key => $value) {
315 - if($blockName == $value['blockName']) {
316 - if($value['attrs']['blockId'] == $blockId) {
317 - $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
318 - $attr['paged'] = $paged;
641 + if ($blockName == $value['blockName']) {
642 + if ($value['attrs']['blockId'] == $blockId) {
643 + $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
644 + $value['attrs']['paged'] = $paged;
645 + if ($builder) {
646 + $value['attrs']['builder'] = $builder;
647 + }
648 + if ($postId) {
649 + $attr['current_post'] = $postId;
650 + }
319 651 $attr = array_merge($attr, $value['attrs']);
320 - echo $this->all_blocks[$blockRaw]->content($attr, true);
652 + echo $this->all_blocks[$blockRaw]->content($attr, true);
321 653 die();
322 654 }
323 655 }
324 - if(!empty($value['innerBlocks'])){
325 - $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
656 + if (!empty($value['innerBlocks'])) {
657 + $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName, $builder, $postId);
326 658 }
327 659 }
328 660 }
661 +
662 + /**
663 + * Save Settings of Option Panel
664 + *
665 + * @since v.2.6.0
666 + * @return NULL
667 + */
668 + public function save_plugin_settings_data() {
669 + if (!wp_verify_nonce(wp_unslash($_REQUEST['wpnonce']), 'ultp-nonce') && $local){
670 + return ;
671 + }
672 + $data = ultimate_post()->recursive_sanitize_text_field($_POST['data']);
673 + if (count($data) > 0) {
674 + foreach ($data as $key => $val) {
675 + ultimate_post()->set_setting($key, $val);
676 + }
677 + }
678 + wp_send_json_success(__('Settings Data Saved...', 'ultimate-post'));
679 + }
680 +
681 + /**
682 + * WordPress Plugin Notice
683 + *
684 + * @since v.2.6.4
685 + * @return NULL
686 + */
687 + public function in_plugin_settings_update_message() {
688 + $response = wp_remote_get(
689 + 'https://plugins.svn.wordpress.org/ultimate-post/trunk/readme.txt', array(
690 + 'method' => 'GET'
691 + ));
692 +
693 + if ( is_wp_error( $response ) || $response['response']['code'] != 200 ) {
694 + return;
695 + }
696 +
697 + $changelog_lines = preg_split("/(\r\n|\n|\r)/", $response['body']);
698 +
699 + $is_copy = false;
700 + $current_tag = '';
701 + $tag_text = 'Stable tag:';
702 + if (!empty($changelog_lines)) {
703 + echo '<div style="color:#cc0303;font-size:14px;font-weight:bold;">' . esc_html('PostX is ready for the next update. Here is the changelog:-') . '</div>';
704 + echo '<ul style="max-height:200px;overflow:scroll;display: grid;grid-template-columns: 1fr 1fr;grid-column-gap: 100px;">';
705 + $i = 0;
706 + foreach ($changelog_lines as $key => $line) {
707 + // Get Current Vesion
708 + if ($current_tag == '') {
709 + if (strpos($line, $tag_text) !== false) {
710 + $current_tag = trim(str_replace($tag_text, '', $line));
711 + }
712 + } else {
713 + if ($is_copy) {
714 + if (strpos($line, '= '.ULTP_VER) !== false) {
715 + break;
716 + }
717 + if (!empty($line)) {
718 + if (strpos($line, '= ') !== false) {
719 + if($i%2 == 1){
720 + echo '<li></li>';
721 + }
722 + }
723 + echo '<li>'.esc_html($line).'</li>';
724 + if (strpos($line, '= ') !== false) {
725 + echo '<li></li>';
726 + $i++;
727 + }
728 + }
729 + } else {
730 + if (strpos($line, '= '.$current_tag) !== false) { // Current Version
731 + $is_copy = true;
732 + echo '<li>'.esc_html($line).'</li><li></li>';
733 + }
734 + }
735 + }
736 + $i++;
737 + }
738 + echo '</ul>';
739 + }
740 + }
741 +
329 742
330 743 }