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

292 lines 13.4 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();
12 $this->blocks();
13
14 add_action('wp_head', array($this, 'popular_posts_tracker_callback'));
15 add_filter('block_categories', array($this, 'register_category_callback'), 10, 2); // Block Category Register
16 add_action('after_setup_theme', array($this, 'add_image_size'));
17
18 add_action('enqueue_block_editor_assets', array($this, 'register_scripts_back_callback')); // Only editor
19 add_action('admin_enqueue_scripts', array($this, 'register_scripts_option_panel_callback')); // Option Panel
20 add_action('wp_enqueue_scripts', array($this, 'register_scripts_front_callback')); // Both frontend
21
22 add_action('wp_ajax_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call
23 add_action('wp_ajax_nopriv_ultp_next_prev', array($this, 'ultp_next_prev_callback')); // Next Previous AJAX Call Logout User
24 add_action('wp_ajax_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call
25 add_action('wp_ajax_nopriv_ultp_filter', array($this, 'ultp_filter_callback')); // Next Previous AJAX Call Logout User
26 add_action('wp_ajax_ultp_pagination', array($this, 'ultp_pagination_callback')); // Page Number AJAX Call
27 add_action('wp_ajax_nopriv_ultp_pagination',array($this, 'ultp_pagination_callback')); // Page Number AJAX Call Logout User
28 register_activation_hook(ULTP_PATH.'ultimate-post.php', array($this, 'install_hook'));
29 add_action( 'activated_plugin', array($this, 'activation_redirect'));
30 add_action( 'upgrader_process_complete', array($this,'redirect_after_upgrade'), 10, 2 );
31 }
32
33 public function redirect_after_upgrade( $upgrader_object, $options ){
34 exit(wp_redirect(admin_url('admin.php?page=ultp-features')));
35 }
36
37 public function register_scripts_option_panel_callback(){
38 wp_enqueue_style('wp-color-picker');
39 wp_enqueue_script('wp-color-picker');
40 wp_enqueue_script('ultp-option-script', ULTP_URL.'assets/js/ultp-option.js', array('jquery'), ULTP_VER, true);
41 wp_enqueue_style('ultp-option-style', ULTP_URL.'assets/css/ultp-option.css', array(), ULTP_VER);
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()){
73 wp_enqueue_style('ultp-blocks-editor-rtl-css', ULTP_URL.'assets/css/rtl.css', array(), ULTP_VER);
74 }
75
76 $import = '';
77 $options = get_option('ultp_options');
78 if(!$options){
79 $options = ultimate_post()->init_set_data();
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 public function ultp_pagination_callback() {
111 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
112 return ;
113 }
114
115 $paged = sanitize_text_field($_POST['paged']);
116 $blockId = sanitize_text_field($_POST['blockId']);
117 $postId = sanitize_text_field($_POST['postId']);
118 $blockRaw = sanitize_text_field($_POST['blockName']);
119 $blockName = str_replace('_','/', $blockRaw);
120
121 if($paged) {
122 $post = get_post($postId);
123 if (has_blocks($post->post_content)) {
124 $blocks = parse_blocks($post->post_content);
125 $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
126 }
127 }
128 }
129
130 public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) {
131 foreach ($blocks as $key => $value) {
132 if($blockName == $value['blockName']) {
133 if($value['attrs']['blockId'] == $blockId) {
134 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
135 $attr['paged'] = $paged;
136 $attr = array_merge($attr, $value['attrs']);
137 echo $this->all_blocks[$blockRaw]->content($attr, true);
138 die();
139 }
140 }
141 if(!empty($value['innerBlocks'])){
142 $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
143 }
144 }
145 }
146
147
148 public function ultp_filter_callback() {
149 if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
150 return ;
151 }
152
153 $taxtype = sanitize_text_field($_POST['taxtype']);
154 $blockId = sanitize_text_field($_POST['blockId']);
155 $postId = sanitize_text_field($_POST['postId']);
156 $taxonomy = sanitize_text_field($_POST['taxonomy']);
157 $blockRaw = sanitize_text_field($_POST['blockName']);
158 $blockName = str_replace('_','/', $blockRaw);
159
160 if( $taxtype ) {
161 $post = get_post($postId);
162 if (has_blocks($post->post_content)) {
163 $blocks = parse_blocks($post->post_content);
164 $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
165 }
166 }
167 }
168
169 public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
170 foreach ($blocks as $key => $value) {
171 if($blockName == $value['blockName']) {
172 if($value['attrs']['blockId'] == $blockId) {
173 $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
174 if($taxonomy) {
175 if($taxtype == 'category'){
176 $value['attrs']['queryCat'] = json_encode(array($taxonomy));
177 }elseif($taxtype == 'post_tag'){
178 $value['attrs']['queryTag'] = json_encode(array($taxonomy));
179 }
180 $value['attrs']['queryTax'] = $taxtype;
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_List_4.php';
223 require_once ULTP_PATH.'blocks/Post_Slider_1.php';
224 require_once ULTP_PATH.'blocks/Post_Grid_1.php';
225 require_once ULTP_PATH.'blocks/Post_Grid_2.php';
226 require_once ULTP_PATH.'blocks/Post_Grid_3.php';
227 require_once ULTP_PATH.'blocks/Post_Grid_4.php';
228 require_once ULTP_PATH.'blocks/Post_Grid_5.php';
229 require_once ULTP_PATH.'blocks/Post_Grid_6.php';
230 require_once ULTP_PATH.'blocks/Post_Grid_7.php';
231 require_once ULTP_PATH.'blocks/Heading.php';
232 require_once ULTP_PATH.'blocks/Image.php';
233 require_once ULTP_PATH.'blocks/Post_Module_1.php';
234 require_once ULTP_PATH.'blocks/Post_Module_2.php';
235 $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
236 $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
237 $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
238 $this->all_blocks['ultimate-post_post-list-4'] = new \ULTP\blocks\Post_List_4();
239 $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
240 $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
241 $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
242 $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
243 $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
244 $this->all_blocks['ultimate-post_post-grid-5'] = new \ULTP\blocks\Post_Grid_5();
245 $this->all_blocks['ultimate-post_post-grid-6'] = new \ULTP\blocks\Post_Grid_6();
246 $this->all_blocks['ultimate-post_post-grid-7'] = new \ULTP\blocks\Post_Grid_7();
247 $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
248 $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
249 $this->all_blocks['ultimate-post_post-module-1'] = new \ULTP\blocks\Post_Module_1();
250 $this->all_blocks['ultimate-post_post-module-2'] = new \ULTP\blocks\Post_Module_2();
251 }
252
253 // Require Categories
254 public function requires() {
255 require_once ULTP_PATH.'classes/Notice.php';
256 require_once ULTP_PATH.'classes/Styles.php';
257 require_once ULTP_PATH.'classes/Options.php';
258 require_once ULTP_PATH.'classes/REST_API.php';
259 require_once ULTP_PATH.'classes/Caches.php';
260 new \ULTP\Caches();
261 new \ULTP\Options();
262 new \ULTP\Styles();
263 new \ULTP\Notice();
264 }
265
266 // Block Categories
267 public function register_category_callback( $categories, $post ) {
268 return array_merge(
269 array(
270 array(
271 'slug' => 'ultimate-post',
272 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' )
273 )
274 ), $categories
275 );
276 }
277
278 public function popular_posts_tracker_callback($post_id) {
279 if (!is_single()){ return; }
280 global $post;
281 if (empty($post_id)) { $post_id = $post->ID; }
282 $count = (int)get_post_meta( $post_id, '__post_views_count', true );
283 update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
284 }
285
286 public function add_image_size() {
287 add_image_size('ultp_layout_landscape_large', 1200, 800, true);
288 add_image_size('ultp_layout_landscape', 870, 570, true);
289 add_image_size('ultp_layout_portrait', 600, 900, true);
290 add_image_size('ultp_layout_square', 600, 600, true);
291 }
292 }