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

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