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

367 lines 16.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP;
3
4 defined('ABSPATH') || exit;
5
6 class ULTP_Initialization{
7
8 private $all_blocks;
9
10 public function __construct(){
11 $this->compatibility_check();
12 $this->requires(); // Include Necessary Files
13 $this->blocks(); // Include Blocks
14 $this->include_addons(); // Include Addons
15
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
18 add_action('after_setup_theme', array($this, 'add_image_size'));
19
20 add_action('enqueue_block_editor_assets', array($this, 'register_scripts_back_callback')); // Only editor
21 add_action('admin_enqueue_scripts', array($this, 'register_scripts_option_panel_callback')); // Option Panel
22 add_action('wp_enqueue_scripts', array($this, 'register_scripts_front_callback')); // Both frontend
23 register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook'));
24 add_action( 'activated_plugin', array($this, 'activation_redirect'));
25
26 add_action('wp_ajax_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call
27 add_action('wp_ajax_nopriv_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call Logout User
28 add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call
29 add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User
30 add_action('wp_ajax_ultp_pagination', array($this, 'ultp_pagination_callback')); // Page Number AJAX Call
31 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
33
34 add_action('admin_init', array($this, 'check_theme_compatibility') );
35 add_action( 'after_switch_theme', array( $this, 'wpxpo_swithch_thememe' ) );
36 }
37
38 public function wpxpo_swithch_thememe () {
39 $this->check_theme_compatibility();
40 }
41
42 public function check_theme_compatibility() {
43 $licence = apply_filters( 'ultp_theme_integration' , FALSE);
44 $theme = get_transient( 'ulpt_theme_enable' );
45
46 if( $licence ) {
47 if( $theme != 'integration' ) {
48 $themes = wp_get_theme();
49 $api_params = array(
50 'wpxpo_theme_action' => 'theme_license',
51 'slug' => $themes->get('TextDomain'),
52 'author' => $themes->get('Author'),
53 'item_id' => 181,
54 'url' => home_url()
55 );
56
57 $response = wp_remote_post( 'https://www.wpxpo.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
58
59 if ( !is_wp_error( $response ) || 200 === wp_remote_retrieve_response_code( $response ) ) {
60 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
61 if(isset($license_data->license)) {
62 if ( $license_data->license == 'valid' ) {
63 set_transient( 'ulpt_theme_enable', 'integration', 2592000 ); // 30 days time
64 }
65 }
66 }
67 }
68 } else {
69 if ( $theme == 'integration' ) {
70 delete_transient('ulpt_theme_enable');
71 }
72 }
73 }
74
75 public function compatibility_check(){
76 require_once ULTP_PATH.'classes/Compatibility.php';
77 new \ULTP\Compatibility();
78 }
79
80 public function register_scripts_option_panel_callback(){
81 wp_enqueue_style('wp-color-picker');
82 wp_enqueue_script('wp-color-picker');
83 wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true);
84 wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER);
85 wp_localize_script('ultp-option-script', 'ultp_option_panel', array(
86 'width' => ultimate_post()->get_setting('editor_container'),
87 'security' => wp_create_nonce('ultp-nonce'),
88 'ajax' => admin_url('admin-ajax.php')
89 ));
90 }
91
92 public function register_scripts_common(){
93 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
94 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery'), ULTP_VER, true);
95 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
96 'url' => ULTP_URL,
97 'ajax' => admin_url('admin-ajax.php'),
98 'security' => wp_create_nonce('ultp-nonce')
99 ));
100 }
101
102 // Backend and Frontend Load script
103 public function register_scripts_front_callback() {
104 if ('yes' == get_post_meta(get_the_ID(), '_ultp_active', true)) {
105 $this->register_scripts_common();
106 }
107 }
108
109 // Only Backend
110 public function register_scripts_back_callback() {
111 $this->register_scripts_common();
112 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);
113 wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER);
114 if(is_rtl()){
115 wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER);
116 }
117
118 $import = '';
119 $options = ultimate_post()->get_setting();
120
121 if (isset($options['hide_import_btn'])) {
122 if ($options['hide_import_btn']=='yes') {
123 $import = 'yes';
124 }
125 }
126
127 $is_active = get_option('edd_ultp_license_status') == 'valid' ? true : ( get_transient( 'ulpt_theme_enable' ) == 'integration' ? true : false );
128
129 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
130 'url' => ULTP_URL,
131 'ajax' => admin_url('admin-ajax.php'),
132 'security' => wp_create_nonce('ultp-nonce'),
133 'hide_import_btn' => $import,
134 'upload' => wp_upload_dir()['basedir'] . '/ultp',
135 'premium_link' => ultimate_post()->get_premium_link(),
136 'license' => get_option('edd_ultp_license_key'),
137 'active' => $is_active,
138 ));
139 }
140
141 // Fire When Plugin First Install
142 public function install_hook() {
143 if (!get_option('ultp_options')) {
144 ultimate_post()->init_set_data();
145 }
146 }
147
148 public function activation_redirect($plugin) {
149 if( $plugin == 'ultimate-post/ultimate-post.php' ) {
150 exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
151 }
152 }
153
154 // Require Blocks
155 public function blocks() {
156 require_once ULTP_PATH.'blocks/Post_List_1.php';
157 require_once ULTP_PATH.'blocks/Post_List_2.php';
158 require_once ULTP_PATH.'blocks/Post_List_3.php';
159 require_once ULTP_PATH.'blocks/Post_List_4.php';
160 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
161 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
162 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
163 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
164 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
165 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
166 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
167 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
168 require_once ULTP_PATH.'blocks/Heading.php';
169 require_once ULTP_PATH.'blocks/Image.php';
170 require_once ULTP_PATH.'blocks/Post_Module_1.php';
171 require_once ULTP_PATH.'blocks/Post_Module_2.php';
172 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
173 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
174 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
175 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
176 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
177 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
178 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
179 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
180 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
181 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
182 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
183 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
184 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
185 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
186 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
187 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
188 }
189
190 // Require Categories
191 public function requires() {
192 require_once ULTP_PATH.'classes/Notice.php';
193 require_once ULTP_PATH.'classes/Styles.php';
194 require_once ULTP_PATH.'classes/Options.php';
195 require_once ULTP_PATH.'classes/REST_API.php';
196 require_once ULTP_PATH.'classes/Caches.php';
197 new \ULTP\Caches();
198 new \ULTP\Options();
199 new \ULTP\Styles();
200 new \ULTP\Notice();
201
202 require_once ULTP_PATH.'classes/Deactive.php';
203 new \ULTP\Deactive();
204 }
205
206 // Block Categories
207 public function register_category_callback( $categories, $post ) {
208 return array_merge(
209 array(
210 array(
211 'slug' => 'ultimate-post',
212 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' )
213 )
214 ), $categories
215 );
216 }
217
218 // Post View Post Meta Set
219 public function popular_posts_tracker_callback($post_id) {
220 if (!is_single()){ return; }
221 global $post;
222 if (empty($post_id)) { $post_id = $post->ID; }
223 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
224 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
225 }
226
227 // Set Image Size
228 public function add_image_size() {
229 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
230 add_image_size('ultp_layout_landscape', 870, 570, true);
231 add_image_size('ultp_layout_portrait', 600, 900, true);
232 add_image_size('ultp_layout_square', 600, 600, true);
233 }
234
235 // Include Addons directory
236 public function include_addons() {
237 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
238 if (count($addons_dir) > 0) {
239 foreach( $addons_dir as $key => $value ) {
240 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
241 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
242 if ( file_exists($file_name) ) {
243 include_once $file_name;
244 }
245 }
246 }
247 }
248
249
250 public function ultp_addon_callback() {
251 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
252 return ;
253 }
254 $addon_name = sanitize_text_field($_POST['addon']);
255 $addon_value = sanitize_text_field($_POST['value']);
256 if ($addon_name) {
257 $addon_data = ultimate_post()->get_setting();
258 $addon_data[$addon_name] = $addon_value;
259 $GLOBALS['wopb_settings'][$addon_name] = $addon_value;
260 update_option('ultp_options', $addon_data);
261 }
262 }
263
264 public function ultp_next_prev_callback() {
265 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
266 return ;
267 }
268
269 $paged = sanitize_text_field($_POST['paged']);
270 $blockId = sanitize_text_field($_POST['blockId']);
271 $postId = sanitize_text_field($_POST['postId']);
272 $blockRaw = sanitize_text_field($_POST['blockName']);
273 $blockName = str_replace('_','/', $blockRaw);
274
275 if( $paged && $blockId && $postId && $blockName ) {
276 $post = get_post($postId);
277 if (has_blocks($post->post_content)) {
278 $blocks = parse_blocks($post->post_content);
279 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
280 }
281 }
282 }
283
284 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
285 foreach ($blocks as $key => $value) {
286 if($blockName == $value['blockName']) {
287 if($value['attrs']['blockId'] == $blockId) {
288 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
289 if($taxonomy) {
290 $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
291 $value['attrs']['queryTax'] = $taxtype;
292 }
293 if(isset($value['attrs']['queryNumber'])){
294 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
295 }
296 $attr = array_merge($attr, $value['attrs']);
297 echo $this->all_blocks[$blockRaw]->content($attr, true);
298 die();
299 }
300 }
301 if(!empty($value['innerBlocks'])){
302 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
303 }
304 }
305 }
306
307
308 public function ultp_filter_callback() {
309 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
310 return ;
311 }
312
313 $taxtype = sanitize_text_field($_POST['taxtype']);
314 $blockId = sanitize_text_field($_POST['blockId']);
315 $postId = sanitize_text_field($_POST['postId']);
316 $taxonomy = sanitize_text_field($_POST['taxonomy']);
317 $blockRaw = sanitize_text_field($_POST['blockName']);
318 $blockName = str_replace('_','/', $blockRaw);
319
320 if( $taxtype ) {
321 $post = get_post($postId);
322 if (has_blocks($post->post_content)) {
323 $blocks = parse_blocks($post->post_content);
324 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
325 }
326 }
327 }
328
329 public function ultp_pagination_callback() {
330 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
331 return ;
332 }
333
334 $paged = sanitize_text_field($_POST['paged']);
335 $blockId = sanitize_text_field($_POST['blockId']);
336 $postId = sanitize_text_field($_POST['postId']);
337 $blockRaw = sanitize_text_field($_POST['blockName']);
338 $blockName = str_replace('_','/', $blockRaw);
339
340 if($paged) {
341 $post = get_post($postId);
342 if (has_blocks($post->post_content)) {
343 $blocks = parse_blocks($post->post_content);
344 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
345 }
346 }
347 }
348
349
350 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) {
351 foreach ($blocks as $key => $value) {
352 if($blockName == $value['blockName']) {
353 if($value['attrs']['blockId'] == $blockId) {
354 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
355 $attr['paged'] = $paged;
356 $attr = array_merge($attr, $value['attrs']);
357 echo $this->all_blocks[$blockRaw]->content($attr, true);
358 die();
359 }
360 }
361 if(!empty($value['innerBlocks'])){
362 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
363 }
364 }
365 }
366
367 }