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

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