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

330 lines 14.8 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('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
68 // Backend and Frontend Load script
69 public function register_scripts_front_callback() {
70 if ('yes' == get_post_meta(get_the_ID(), '_ultp_active', true)) {
71 $this->register_scripts_common();
72 }
73 }
74
75 // Only Backend
76 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);
79 wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER);
80 if(is_rtl()){
81 wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER);
82 }
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
93 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
94 'url' => ULTP_URL,
95 'ajax' => admin_url('admin-ajax.php'),
96 'security' => wp_create_nonce('ultp-nonce'),
97 'hide_import_btn' => $import,
98 'upload' => wp_upload_dir()['basedir'] . '/ultp',
99 'license' => get_option('edd_ultp_license_key')
100 ));
101 }
102
103 // Fire When Plugin First Install
104 public function install_hook() {
105 if (!get_option('ultp_options')) {
106 ultimate_post()->init_set_data();
107 }
108 }
109
110 public function activation_redirect($plugin) {
111 if( $plugin == 'ultimate-post/ultimate-post.php' ) {
112 exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
113 }
114 }
115
116 // Require Blocks
117 public function blocks() {
118 require_once ULTP_PATH.'blocks/Post_List_1.php';
119 require_once ULTP_PATH.'blocks/Post_List_2.php';
120 require_once ULTP_PATH.'blocks/Post_List_3.php';
121 require_once ULTP_PATH.'blocks/Post_List_4.php';
122 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
123 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
124 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
125 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
126 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
127 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
128 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
129 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
130 require_once ULTP_PATH.'blocks/Heading.php';
131 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';
134 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
135 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
136 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
137 $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 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
140 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
141 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
142 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
143 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
144 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
145 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
146 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
147 $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();
150 }
151
152 // Require Categories
153 public function requires() {
154 require_once ULTP_PATH.'classes/Notice.php';
155 require_once ULTP_PATH.'classes/Styles.php';
156 require_once ULTP_PATH.'classes/Options.php';
157 require_once ULTP_PATH.'classes/REST_API.php';
158 require_once ULTP_PATH.'classes/Caches.php';
159 new \ULTP\Caches();
160 new \ULTP\Options();
161 new \ULTP\Styles();
162 new \ULTP\Notice();
163 }
164
165 // Block Categories
166 public function register_category_callback( $categories, $post ) {
167 return array_merge(
168 array(
169 array(
170 'slug' => 'ultimate-post',
171 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' )
172 )
173 ), $categories
174 );
175 }
176
177 // Post View Post Meta Set
178 public function popular_posts_tracker_callback($post_id) {
179 if (!is_single()){ return; }
180 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 );
184 }
185
186 // Set Image Size
187 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);
192 }
193
194 // Include Addons directory
195 public function include_addons() {
196 $addons_dir = array_filter(glob(ULTP_PATH.'addons/*'), 'is_dir');
197 if (count($addons_dir) > 0) {
198 foreach( $addons_dir as $key => $value ) {
199 $addon_dir_name = str_replace(dirname($value).'/', '', $value);
200 $file_name = ULTP_PATH . 'addons/'.$addon_dir_name.'/init.php';
201 if ( file_exists($file_name) ) {
202 include_once $file_name;
203 }
204 }
205 }
206 }
207
208
209 public function ultp_addon_callback() {
210 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
211 return ;
212 }
213 $addon_name = sanitize_text_field($_POST['addon']);
214 $addon_value = sanitize_text_field($_POST['value']);
215 if ($addon_name) {
216 $addon_data = ultimate_post()->get_setting();
217 $addon_data[$addon_name] = $addon_value;
218 $GLOBALS['wopb_settings'][$addon_name] = $addon_value;
219 update_option('ultp_options', $addon_data);
220 }
221 }
222
223 public function ultp_next_prev_callback() {
224 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
225 return ;
226 }
227
228 $paged = sanitize_text_field($_POST['paged']);
229 $blockId = sanitize_text_field($_POST['blockId']);
230 $postId = sanitize_text_field($_POST['postId']);
231 $blockRaw = sanitize_text_field($_POST['blockName']);
232 $blockName = str_replace('_','/', $blockRaw);
233
234 if( $paged && $blockId && $postId && $blockName ) {
235 $post = get_post($postId);
236 if (has_blocks($post->post_content)) {
237 $blocks = parse_blocks($post->post_content);
238 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
239 }
240 }
241 }
242
243 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
244 foreach ($blocks as $key => $value) {
245 if($blockName == $value['blockName']) {
246 if($value['attrs']['blockId'] == $blockId) {
247 $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 }
254 $value['attrs']['queryTax'] = $taxtype;
255 }
256 if(isset($value['attrs']['queryNumber'])){
257 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
258 }
259 $attr = array_merge($attr, $value['attrs']);
260 echo $this->all_blocks[$blockRaw]->content($attr, true);
261 die();
262 }
263 }
264 if(!empty($value['innerBlocks'])){
265 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
266 }
267 }
268 }
269
270
271 public function ultp_filter_callback() {
272 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
273 return ;
274 }
275
276 $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 ) {
284 $post = get_post($postId);
285 if (has_blocks($post->post_content)) {
286 $blocks = parse_blocks($post->post_content);
287 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
288 }
289 }
290 }
291
292 public function ultp_pagination_callback() {
293 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
294 return ;
295 }
296
297 $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) {
304 $post = get_post($postId);
305 if (has_blocks($post->post_content)) {
306 $blocks = parse_blocks($post->post_content);
307 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
308 }
309 }
310 }
311
312
313 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) {
314 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;
319 $attr = array_merge($attr, $value['attrs']);
320 echo $this->all_blocks[$blockRaw]->content($attr, true);
321 die();
322 }
323 }
324 if(!empty($value['innerBlocks'])){
325 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
326 }
327 }
328 }
329
330 }