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

279 lines 12.5 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 private $api_endpoint = 'https://demo.wpxpo.com/wp-json/restapi/v2/';
10
11 public function __construct(){
12 $this->requires();
13 $this->blocks();
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
23 add_action('wp_ajax_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call
24 add_action('wp_ajax_nopriv_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call Logout User
25 add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call
26 add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User
27 add_action('wp_ajax_ultp_pagination', array($this, 'ultp_pagination_callback')); // Page Number AJAX Call
28 add_action('wp_ajax_nopriv_ultp_pagination',array($this, 'ultp_pagination_callback')); // Page Number AJAX Call Logout User
29
30 register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook'));
31
32 add_action( 'activated_plugin', array($this, 'activation_redirect'));
33 }
34
35 public function register_scripts_option_panel_callback(){
36 if( null !== ( $screen = get_current_screen() ) && 'toplevel_page_ultp-settings' !== $screen->id ) {
37 return;
38 }
39 wp_enqueue_style('wp-color-picker');
40 wp_enqueue_script('wp-color-picker');
41 wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true);
42 }
43
44 public function register_scripts_common(){
45 wp_enqueue_style('dashicons');
46 wp_enqueue_style('ultp-slick-style', ULTP_URL.'assets/css/slick.css', array(), ULTP_VER);
47 wp_enqueue_style('ultp-slick-theme-style', ULTP_URL.'assets/css/slick-theme.css', array(), ULTP_VER);
48 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/blocks.style.css', array(), ULTP_VER );
49 if(is_rtl()){ wp_enqueue_style('ultp-blocks-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); }
50 wp_enqueue_script('ultp-flexmenu-script', ULTP_URL.'assets/js/flexmenu.js', array('jquery'), ULTP_VER, true);
51 wp_enqueue_script('ultp-slick-script', ULTP_URL.'assets/js/slick.min.js', array('jquery'), ULTP_VER, true);
52 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.js', array('jquery','ultp-flexmenu-script'), ULTP_VER, true);
53 wp_localize_script('ultp-script', 'ultp_data', array(
54 'url' => ULTP_URL,
55 'ajax' => admin_url('admin-ajax.php'),
56 'security' => wp_create_nonce('ultp-nonce')
57 ));
58 }
59
60 // Backend and Frontend Load script
61 public function register_scripts_front_callback() {
62 if ('yes' == get_post_meta(get_the_ID(), '_ultp_active', true)) {
63 $this->register_scripts_common();
64 }
65 }
66
67 // Only Backend
68 public function register_scripts_back_callback() {
69 $this->register_scripts_common();
70 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);
71 wp_enqueue_style('ultp-blocks-editor-css', ULTP_URL.'assets/css/blocks.editor.css', array(), ULTP_VER);
72 if(is_rtl()){ wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER); }
73
74 $import = '';
75 $options = get_option('ultp_options');
76 if (isset($options['hide_import_btn'])) {
77 if ($options['hide_import_btn']=='yes') {
78 $import = 'yes';
79 }
80 }
81
82 wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
83 'url' => ULTP_URL,
84 'ajax' => admin_url('admin-ajax.php'),
85 'security' => wp_create_nonce('ultp-nonce'),
86 'hide_import_btn' => $import
87 ));
88 }
89
90 // Fire When Plugin First Install
91 public function install_hook() {
92 if (!get_option('ultp_options')) {
93 $option_data = array(
94 'css_save_as' => 'wp_head',
95 'preloader_style' => 'style1',
96 'preloader_color' => '#1740f5',
97 'container_width' => '1140',
98 'hide_import_btn' => ''
99 );
100 update_option('ultp_options', $option_data);
101 }
102
103 }
104
105 public function activation_redirect($plugin) {
106 if( $plugin == 'ultimate-post/ultimate-post.php' ) {
107 exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
108 }
109 }
110
111 public function ultp_pagination_callback() {
112 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
113 return ;
114 }
115
116 $paged = sanitize_text_field($_POST['paged']);
117 $blockId = sanitize_text_field($_POST['blockId']);
118 $postId = sanitize_text_field($_POST['postId']);
119 $blockRaw = sanitize_text_field($_POST['blockName']);
120 $blockName = str_replace('_','/', $blockRaw);
121
122 if($paged) {
123 $post = get_post($postId);
124 if (has_blocks($post->post_content)) {
125 $blocks = parse_blocks($post->post_content);
126 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
127 }
128 }
129 }
130
131 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) {
132 foreach ($blocks as $key => $value) {
133 if($blockName == $value['blockName']) {
134 if($value['attrs']['blockId'] == $blockId) {
135 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
136 $attr['paged'] = $paged;
137 $attr = array_merge($attr, $value['attrs']);
138 echo $this->all_blocks[$blockRaw]->content($attr, true);
139 die();
140 }
141 }
142 if(!empty($value['innerBlocks'])){
143 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
144 }
145 }
146 }
147
148
149 public function ultp_filter_callback() {
150 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
151 return ;
152 }
153
154 $taxtype = sanitize_text_field($_POST['taxtype']);
155 $blockId = sanitize_text_field($_POST['blockId']);
156 $postId = sanitize_text_field($_POST['postId']);
157 $taxonomy = sanitize_text_field($_POST['taxonomy']);
158 $blockRaw = sanitize_text_field($_POST['blockName']);
159 $blockName = str_replace('_','/', $blockRaw);
160
161 if( $taxtype ) {
162 $post = get_post($postId);
163 if (has_blocks($post->post_content)) {
164 $blocks = parse_blocks($post->post_content);
165 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
166 }
167 }
168 }
169
170 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
171 foreach ($blocks as $key => $value) {
172 if($blockName == $value['blockName']) {
173 if($value['attrs']['blockId'] == $blockId) {
174 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
175 $value['attrs']['queryTax'] = $taxtype == 'category' ? 'category' : 'tag';
176 if($taxtype == 'category' && $taxonomy) {
177 $value['attrs']['queryCat'] = json_encode(array($taxonomy));
178 }
179 if($taxtype == 'post_tag' && $taxonomy) {
180 $value['attrs']['queryTag'] = json_encode(array($taxonomy));
181 }
182 if(isset($value['attrs']['queryNumber'])){
183 $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
184 }
185 $attr = array_merge($attr, $value['attrs']);
186 echo $this->all_blocks[$blockRaw]->content($attr, true);
187 die();
188 }
189 }
190 if(!empty($value['innerBlocks'])){
191 $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
192 }
193 }
194 }
195
196
197 public function ultp_next_prev_callback() {
198 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
199 return ;
200 }
201
202 $paged = sanitize_text_field($_POST['paged']);
203 $blockId = sanitize_text_field($_POST['blockId']);
204 $postId = sanitize_text_field($_POST['postId']);
205 $blockRaw = sanitize_text_field($_POST['blockName']);
206 $blockName = str_replace('_','/', $blockRaw);
207
208 if( $paged && $blockId && $postId && $blockName ) {
209 $post = get_post($postId);
210 if (has_blocks($post->post_content)) {
211 $blocks = parse_blocks($post->post_content);
212 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
213 }
214 }
215 }
216
217 // Require Blocks
218 public function blocks() {
219 require_once ULTP_PATH.'blocks/Post_List_1.php';
220 require_once ULTP_PATH.'blocks/Post_List_2.php';
221 require_once ULTP_PATH.'blocks/Post_List_3.php';
222 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
223 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
224 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
225 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
226 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
227 require_once ULTP_PATH.'blocks/Heading.php';
228 require_once ULTP_PATH.'blocks/Image.php';
229 //require_once ULTP_PATH.'blocks/Taxonomy.php';
230 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
231 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
232 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
233 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
234 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
235 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
236 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
237 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
238 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
239 //$this->all_blocks['ultimate-post_taxonomy'] = new \ULTP\blocks\Taxonomy();
240 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
241 }
242
243 // Require Categories
244 public function requires() {
245 require_once ULTP_PATH.'classes/Styles.php';
246 require_once ULTP_PATH.'classes/Options.php';
247 require_once ULTP_PATH.'classes/REST_API.php';
248
249 new \ULTP\Options();
250 new \ULTP\Styles();
251 }
252
253 // Block Categories
254 public function register_category_callback( $categories, $post ) {
255 return array_merge(
256 array(
257 array(
258 'slug' => 'ultimate-post',
259 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' )
260 )
261 ), $categories
262 );
263 }
264
265 public function popular_posts_tracker_callback($post_id) {
266 if (!is_single()){ return; }
267 global $post;
268 if (empty($post_id)) { $post_id = $post->ID; }
269 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
270 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
271 }
272
273 public function add_image_size() {
274 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
275 add_image_size('ultp_layout_landscape', 870, 570, true);
276 add_image_size('ultp_layout_portrait', 600, 900, true);
277 add_image_size('ultp_layout_square', 600, 600, true);
278 }
279 }