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

363 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 = ultimate_post()->get_setting('hide_import_btn');
119
120 $is_active = get_option('edd_ultp_license_status') == 'valid' ? true : ( get_transient( 'ulpt_theme_enable' ) == 'integration' ? true : false );
121
122 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
123 'url' => ULTP_URL,
124 'ajax' => admin_url('admin-ajax.php'),
125 'security' => wp_create_nonce('ultp-nonce'),
126 'hide_import_btn' => $import,
127 'upload' => wp_upload_dir()['basedir'] . '/ultp',
128 'premium_link' => ultimate_post()->get_premium_link(),
129 'license' => get_option('edd_ultp_license_key'),
130 'active' => $is_active,
131 ));
132 }
133
134 // Fire When Plugin First Install
135 public function install_hook() {
136 if (!get_option('ultp_options')) {
137 ultimate_post()->init_set_data();
138 }
139 }
140
141 public function activation_redirect($plugin) {
142 if( $plugin == 'ultimate-post/ultimate-post.php' ) {
143 exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
144 }
145 }
146
147 // Require Blocks
148 public function blocks() {
149 require_once ULTP_PATH.'blocks/Post_List_1.php';
150 require_once ULTP_PATH.'blocks/Post_List_2.php';
151 require_once ULTP_PATH.'blocks/Post_List_3.php';
152 require_once ULTP_PATH.'blocks/Post_List_4.php';
153 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
154 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
155 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
156 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
157 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
158 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
159 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
160 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
161 require_once ULTP_PATH.'blocks/Heading.php';
162 require_once ULTP_PATH.'blocks/Image.php';
163 require_once ULTP_PATH.'blocks/Post_Module_1.php';
164 require_once ULTP_PATH.'blocks/Post_Module_2.php';
165 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
166 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
167 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
168 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
169 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
170 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
171 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
172 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
173 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
174 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
175 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
176 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
177 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
178 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
179 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
180 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
181 }
182
183 // Require Categories
184 public function requires() {
185 require_once ULTP_PATH.'classes/Notice.php';
186 require_once ULTP_PATH.'classes/Styles.php';
187 require_once ULTP_PATH.'classes/Options.php';
188 require_once ULTP_PATH.'classes/REST_API.php';
189 require_once ULTP_PATH.'classes/Caches.php';
190 new \ULTP\Caches();
191 new \ULTP\Options();
192 new \ULTP\Styles();
193 new \ULTP\Notice();
194
195 require_once ULTP_PATH.'classes/Deactive.php';
196 new \ULTP\Deactive();
197 }
198
199 // Block Categories
200 public function register_category_callback( $categories, $post ) {
201 return array_merge(
202 array(
203 array(
204 'slug' => 'ultimate-post',
205 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' )
206 )
207 ), $categories
208 );
209 }
210
211 // Post View Post Meta Set
212 public function popular_posts_tracker_callback($post_id) {
213 if (!is_single()){ return; }
214 global $post;
215 if (empty($post_id)) { $post_id = $post->ID; }
216 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
217 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
218 }
219
220 // Set Image Size
221 public function add_image_size() {
222 $size_disable = ultimate_post()->get_setting('disable_image_size');
223 if ($size_disable != 'yes') {
224 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
225 add_image_size('ultp_layout_landscape', 870, 570, true);
226 add_image_size('ultp_layout_portrait', 600, 900, true);
227 add_image_size('ultp_layout_square', 600, 600, true);
228 }
229 }
230
231 // Include Addons directory
232 public function include_addons() {
233 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
234 if (count($addons_dir) > 0) {
235 foreach( $addons_dir as $key => $value ) {
236 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
237 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
238 if ( file_exists($file_name) ) {
239 include_once $file_name;
240 }
241 }
242 }
243 }
244
245
246 public function ultp_addon_callback() {
247 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
248 return ;
249 }
250 $addon_name = sanitize_text_field($_POST['addon']);
251 $addon_value = sanitize_text_field($_POST['value']);
252 if ($addon_name) {
253 $addon_data = ultimate_post()->get_setting();
254 $addon_data[$addon_name] = $addon_value;
255 $GLOBALS['wopb_settings'][$addon_name] = $addon_value;
256 update_option('ultp_options', $addon_data);
257 }
258 }
259
260 public function ultp_next_prev_callback() {
261 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
262 return ;
263 }
264
265 $paged = sanitize_text_field($_POST['paged']);
266 $blockId = sanitize_text_field($_POST['blockId']);
267 $postId = sanitize_text_field($_POST['postId']);
268 $blockRaw = sanitize_text_field($_POST['blockName']);
269 $blockName = str_replace('_','/', $blockRaw);
270
271 if( $paged && $blockId && $postId && $blockName ) {
272 $post = get_post($postId);
273 if (has_blocks($post->post_content)) {
274 $blocks = parse_blocks($post->post_content);
275 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
276 }
277 }
278 }
279
280 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
281 foreach ($blocks as $key => $value) {
282 if($blockName == $value['blockName']) {
283 if($value['attrs']['blockId'] == $blockId) {
284 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
285 if($taxonomy) {
286 $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
287 $value['attrs']['queryTax'] = $taxtype;
288 }
289 if(isset($value['attrs']['queryNumber'])){
290 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
291 }
292 $attr = array_merge($attr, $value['attrs']);
293 echo $this->all_blocks[$blockRaw]->content($attr, true);
294 die();
295 }
296 }
297 if(!empty($value['innerBlocks'])){
298 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
299 }
300 }
301 }
302
303
304 public function ultp_filter_callback() {
305 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
306 return ;
307 }
308
309 $taxtype = sanitize_text_field($_POST['taxtype']);
310 $blockId = sanitize_text_field($_POST['blockId']);
311 $postId = sanitize_text_field($_POST['postId']);
312 $taxonomy = sanitize_text_field($_POST['taxonomy']);
313 $blockRaw = sanitize_text_field($_POST['blockName']);
314 $blockName = str_replace('_','/', $blockRaw);
315
316 if( $taxtype ) {
317 $post = get_post($postId);
318 if (has_blocks($post->post_content)) {
319 $blocks = parse_blocks($post->post_content);
320 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
321 }
322 }
323 }
324
325 public function ultp_pagination_callback() {
326 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
327 return ;
328 }
329
330 $paged = sanitize_text_field($_POST['paged']);
331 $blockId = sanitize_text_field($_POST['blockId']);
332 $postId = sanitize_text_field($_POST['postId']);
333 $blockRaw = sanitize_text_field($_POST['blockName']);
334 $blockName = str_replace('_','/', $blockRaw);
335
336 if($paged) {
337 $post = get_post($postId);
338 if (has_blocks($post->post_content)) {
339 $blocks = parse_blocks($post->post_content);
340 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
341 }
342 }
343 }
344
345
346 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) {
347 foreach ($blocks as $key => $value) {
348 if($blockName == $value['blockName']) {
349 if($value['attrs']['blockId'] == $blockId) {
350 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
351 $attr['paged'] = $paged;
352 $attr = array_merge($attr, $value['attrs']);
353 echo $this->all_blocks[$blockRaw]->content($attr, true);
354 die();
355 }
356 }
357 if(!empty($value['innerBlocks'])){
358 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
359 }
360 }
361 }
362
363 }