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

320 lines 14.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 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
35 public function compatibility_check(){
36 require_once ULTP_PATH.'classes/Compatibility.php';
37 new \ULTP\Compatibility();
38 }
39
40 public function register_scripts_option_panel_callback(){
41 wp_enqueue_style('wp-color-picker');
42 wp_enqueue_script('wp-color-picker');
43 wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true);
44 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_panel', array(
46 'width' => ultimate_post()->get_setting('editor_container'),
47 'security' => wp_create_nonce('ultp-nonce'),
48 'ajax' => admin_url('admin-ajax.php')
49 ));
50 }
51
52 public function register_scripts_common(){
53 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
54 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery'), ULTP_VER, true);
55 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
56 'url' => ULTP_URL,
57 'ajax' => admin_url('admin-ajax.php'),
58 'security' => wp_create_nonce('ultp-nonce')
59 ));
60 }
61
62 // Backend and Frontend Load script
63 public function register_scripts_front_callback() {
64 if ('yes' == get_post_meta(get_the_ID(), '_ultp_active', true)) {
65 $this->register_scripts_common();
66 }
67 }
68
69 // Only Backend
70 public function register_scripts_back_callback() {
71 $this->register_scripts_common();
72 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);
73 wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER);
74 if(is_rtl()){
75 wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER);
76 }
77
78 $import = '';
79 $options = ultimate_post()->get_setting();
80
81 if (isset($options['hide_import_btn'])) {
82 if ($options['hide_import_btn']=='yes') {
83 $import = 'yes';
84 }
85 }
86
87 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
88 'url' => ULTP_URL,
89 'ajax' => admin_url('admin-ajax.php'),
90 'security' => wp_create_nonce('ultp-nonce'),
91 'hide_import_btn' => $import,
92 'upload' => wp_upload_dir()['basedir'] . '/ultp',
93 'license' => get_option('edd_ultp_license_key')
94 ));
95 }
96
97 // Fire When Plugin First Install
98 public function install_hook() {
99 if (!get_option('ultp_options')) {
100 ultimate_post()->init_set_data();
101 }
102 }
103
104 public function activation_redirect($plugin) {
105 if( $plugin == 'ultimate-post/ultimate-post.php' ) {
106 exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
107 }
108 }
109
110 // Require Blocks
111 public function blocks() {
112 require_once ULTP_PATH.'blocks/Post_List_1.php';
113 require_once ULTP_PATH.'blocks/Post_List_2.php';
114 require_once ULTP_PATH.'blocks/Post_List_3.php';
115 require_once ULTP_PATH.'blocks/Post_List_4.php';
116 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
117 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
118 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
119 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
120 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
121 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
122 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
123 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
124 require_once ULTP_PATH.'blocks/Heading.php';
125 require_once ULTP_PATH.'blocks/Image.php';
126 require_once ULTP_PATH.'blocks/Post_Module_1.php';
127 require_once ULTP_PATH.'blocks/Post_Module_2.php';
128 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
129 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
130 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
131 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
132 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
133 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
134 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
135 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
136 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
137 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
138 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
139 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
140 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
141 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
142 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
143 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
144 }
145
146 // Require Categories
147 public function requires() {
148 require_once ULTP_PATH.'classes/Notice.php';
149 require_once ULTP_PATH.'classes/Styles.php';
150 require_once ULTP_PATH.'classes/Options.php';
151 require_once ULTP_PATH.'classes/REST_API.php';
152 require_once ULTP_PATH.'classes/Caches.php';
153 new \ULTP\Caches();
154 new \ULTP\Options();
155 new \ULTP\Styles();
156 new \ULTP\Notice();
157 }
158
159 // Block Categories
160 public function register_category_callback( $categories, $post ) {
161 return array_merge(
162 array(
163 array(
164 'slug' => 'ultimate-post',
165 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' )
166 )
167 ), $categories
168 );
169 }
170
171 // Post View Post Meta Set
172 public function popular_posts_tracker_callback($post_id) {
173 if (!is_single()){ return; }
174 global $post;
175 if (empty($post_id)) { $post_id = $post->ID; }
176 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
177 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
178 }
179
180 // Set Image Size
181 public function add_image_size() {
182 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
183 add_image_size('ultp_layout_landscape', 870, 570, true);
184 add_image_size('ultp_layout_portrait', 600, 900, true);
185 add_image_size('ultp_layout_square', 600, 600, true);
186 }
187
188 // Include Addons directory
189 public function include_addons() {
190 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
191 if (count($addons_dir) > 0) {
192 foreach( $addons_dir as $key => $value ) {
193 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
194 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
195 if ( file_exists($file_name) ) {
196 include_once $file_name;
197 }
198 }
199 }
200 }
201
202
203 public function ultp_addon_callback() {
204 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
205 return ;
206 }
207 $addon_name = sanitize_text_field($_POST['addon']);
208 $addon_value = sanitize_text_field($_POST['value']);
209 if ($addon_name) {
210 $addon_data = ultimate_post()->get_setting();
211 $addon_data[$addon_name] = $addon_value;
212 $GLOBALS['wopb_settings'][$addon_name] = $addon_value;
213 update_option('ultp_options', $addon_data);
214 }
215 }
216
217 public function ultp_next_prev_callback() {
218 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
219 return ;
220 }
221
222 $paged = sanitize_text_field($_POST['paged']);
223 $blockId = sanitize_text_field($_POST['blockId']);
224 $postId = sanitize_text_field($_POST['postId']);
225 $blockRaw = sanitize_text_field($_POST['blockName']);
226 $blockName = str_replace('_','/', $blockRaw);
227
228 if( $paged && $blockId && $postId && $blockName ) {
229 $post = get_post($postId);
230 if (has_blocks($post->post_content)) {
231 $blocks = parse_blocks($post->post_content);
232 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
233 }
234 }
235 }
236
237 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
238 foreach ($blocks as $key => $value) {
239 if($blockName == $value['blockName']) {
240 if($value['attrs']['blockId'] == $blockId) {
241 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
242 if($taxonomy) {
243 $value['attrs']['queryTaxValue'] = json_encode(array($taxonomy));
244 $value['attrs']['queryTax'] = $taxtype;
245 }
246 if(isset($value['attrs']['queryNumber'])){
247 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
248 }
249 $attr = array_merge($attr, $value['attrs']);
250 echo $this->all_blocks[$blockRaw]->content($attr, true);
251 die();
252 }
253 }
254 if(!empty($value['innerBlocks'])){
255 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
256 }
257 }
258 }
259
260
261 public function ultp_filter_callback() {
262 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
263 return ;
264 }
265
266 $taxtype = sanitize_text_field($_POST['taxtype']);
267 $blockId = sanitize_text_field($_POST['blockId']);
268 $postId = sanitize_text_field($_POST['postId']);
269 $taxonomy = sanitize_text_field($_POST['taxonomy']);
270 $blockRaw = sanitize_text_field($_POST['blockName']);
271 $blockName = str_replace('_','/', $blockRaw);
272
273 if( $taxtype ) {
274 $post = get_post($postId);
275 if (has_blocks($post->post_content)) {
276 $blocks = parse_blocks($post->post_content);
277 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
278 }
279 }
280 }
281
282 public function ultp_pagination_callback() {
283 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
284 return ;
285 }
286
287 $paged = sanitize_text_field($_POST['paged']);
288 $blockId = sanitize_text_field($_POST['blockId']);
289 $postId = sanitize_text_field($_POST['postId']);
290 $blockRaw = sanitize_text_field($_POST['blockName']);
291 $blockName = str_replace('_','/', $blockRaw);
292
293 if($paged) {
294 $post = get_post($postId);
295 if (has_blocks($post->post_content)) {
296 $blocks = parse_blocks($post->post_content);
297 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
298 }
299 }
300 }
301
302
303 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) {
304 foreach ($blocks as $key => $value) {
305 if($blockName == $value['blockName']) {
306 if($value['attrs']['blockId'] == $blockId) {
307 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
308 $attr['paged'] = $paged;
309 $attr = array_merge($attr, $value['attrs']);
310 echo $this->all_blocks[$blockRaw]->content($attr, true);
311 die();
312 }
313 }
314 if(!empty($value['innerBlocks'])){
315 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
316 }
317 }
318 }
319
320 }