PluginProbe
Post Grid Gutenberg Blocks – PostX / 1.2.2
Post Grid Gutenberg Blocks – PostX v1.2.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
← All changes | classes/Initialization.php +238 -589 5.0.251.2.2 View file →
@@ -1,625 +1,274 @@
1 1 <?php
2 -
3 -/**
4 - * Initialization Action.
5 - *
6 - * @package ULTP\ULTP_Initialization
7 - * @since v.1.1.0
8 - */
9 -
10 2 namespace ULTP;
11 3
12 -defined( 'ABSPATH' ) || exit;
4 +defined('ABSPATH') || exit;
13 5
14 -use ULTP\Includes\Durbin\Xpo;
15 -use ULTP\Includes\Notice\Notice;
6 +class Initialization{
16 7
17 -/**
18 - * Initialization class.
19 - *
20 - * Handles plugin initialization for Ultimate Post.
21 - *
22 - * @package ULTP\Initialization
23 - * @since 4.0.0
24 - */
25 -class ULTP_Initialization {
8 + private $all_blocks;
9 + private $api_endpoint = 'https://demo.wpxpo.com/wp-json/restapi/v2/';
26 10
27 - /**
28 - * Setup class.
29 - *
30 - * @since 4.0.0
31 - * @return void No return value.
32 - */
33 - public function __construct() {
11 + public function __construct(){
12 + $this->requires();
13 + $this->blocks();
34 14
35 - $this->compatibility_check();
36 - $this->requires();
37 - $this->include_addons();
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'));
38 18
39 - add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ) ); // add body class in editor.
40 - add_filter( 'body_class', array( $this, 'add_body_class' ) ); // add body class in front end.
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
41 22
42 - add_action( 'wp', array( $this, 'popular_posts_tracker_callback' ) );
43 - add_action( 'after_setup_theme', array( $this, 'add_image_size' ) );
44 - add_filter( 'block_categories_all', array( $this, 'register_category_callback' ), 999999999, 2 ); // Block Category Register.
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'));
45 31
46 - add_filter( 'safe_style_css', array( $this, 'ultp_handle_safe_style_css' ) ); // support for css used in svg icon.
47 - add_filter( 'wp_kses_allowed_html', array( $this, 'ultp_handle_allowed_html' ), 99, 2 ); // support for svg icon used in list, row, icon block.
32 + add_action( 'activated_plugin', array($this, 'activation_redirect'));
33 + }
48 34
49 - add_action( 'enqueue_block_editor_assets', array( $this, 'register_block_scripts_editor_area' ) ); // Only editor.
50 - add_action( 'admin_enqueue_scripts', array( $this, 'register_option_panel_scripts_callback' ) ); // Option Panel.
51 - register_activation_hook( ULTP_PATH . 'ultimate-post.php', array( $this, 'plugin_activation_hook' ) );
52 - add_action( 'activated_plugin', array( $this, 'ultp_plugin_activation' ) ); // Plugin Activation Call.
53 - // new Notice();
54 - }
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 + }
55 43
56 - /**
57 - * Check plugin compatibility.
58 - *
59 - * @since v.1.0.0
60 - * @return void
61 - */
62 - public function compatibility_check() {
63 - require_once ULTP_PATH . 'classes/Compatibility.php';
64 - new \ULTP\Compatibility();
65 - }
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 + }
66 59
67 - /**
68 - * Load all required classes.
69 - *
70 - * @since v.1.0.0
71 - * @return void No return value.
72 - */
73 - public function requires() {
74 - require_once ULTP_PATH . 'classes/Styles.php';
75 - require_once ULTP_PATH . 'classes/Options.php';
76 - require_once ULTP_PATH . 'classes/REST_API.php';
77 - require_once ULTP_PATH . 'classes/Caches.php';
78 - require_once ULTP_PATH . 'classes/Importer.php';
79 - require_once ULTP_PATH . 'classes/Dashboard.php';
80 - require_once ULTP_PATH . 'classes/Blocks.php';
81 - new \ULTP\REST_API();
82 - new \ULTP\Options();
83 - new \ULTP\Caches();
84 - new \ULTP\Styles();
85 - new \ULTP\Importer();
86 - new \ULTP\Dashboard();
87 - new \ULTP\Blocks();
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 + }
88 66
89 - require_once ULTP_PATH . 'includes/durbin/class-durbin-client.php';
90 - require_once ULTP_PATH . 'includes/durbin/class-xpo.php';
91 - require_once ULTP_PATH . 'includes/deactive/class-deactive.php';
92 - require_once ULTP_PATH . 'includes/notice/class-notice.php';
93 - require_once ULTP_PATH . 'includes/durbin/class-our-plugins.php';
94 - require_once ULTP_PATH . 'includes/notice/class-wow-shipping-promotion.php';
95 - require_once ULTP_PATH . 'includes/notice/class-wow-revenue-promotion.php';
96 - require_once ULTP_PATH . 'includes/notice/class-wow-addons-promotion.php';
97 - new \ULTP\Includes\Deactive\Deactive();
98 - new \ULTP\Includes\notice\Notice();
99 - new \ULTP\Includes\notice\WowShippingPromotion();
100 - new \ULTP\Includes\notice\WowRevenuePromotion();
101 - new \ULTP\Includes\notice\WowAddonsPromotion();
102 - new \ULTP\Includes\Durbin\OurPlugins();
103 - }
104 -
105 - /**
106 - * Include all addons from the addons directory.
107 - *
108 - * @since v.1.0.0
109 - * @return void
110 - */
111 - public function include_addons() {
112 - $addons_dir = array_filter( glob( ULTP_PATH . 'addons/*' ), 'is_dir' );
113 - if ( count( $addons_dir ) > 0 ) {
114 - foreach ( $addons_dir as $key => $value ) {
115 - $addon_dir_name = str_replace( dirname( $value ) . '/', '', $value );
116 - $file_name = ULTP_PATH . 'addons/' . $addon_dir_name . '/init.php';
117 - if ( file_exists( $file_name ) ) {
118 - include_once $file_name;
119 - }
120 - }
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($option_data['css_save_as'])){
77 + $options = ultimate_post()->init_set_data();
121 78 }
122 - }
79 + if (isset($options['hide_import_btn'])) {
80 + if ($options['hide_import_btn']=='yes') {
81 + $import = 'yes';
82 + }
83 + }
123 84
85 + wp_localize_script('ultp-blocks-editor-script', 'ultp_data', array(
86 + 'url' => ULTP_URL,
87 + 'ajax' => admin_url('admin-ajax.php'),
88 + 'security' => wp_create_nonce('ultp-nonce'),
89 + 'hide_import_btn' => $import
90 + ));
91 + }
124 92
125 - /**
126 - * Add admin body class in editor.
127 - *
128 - * @since v.3.1.6
129 - * @param STRING $classes The existing admin body classes.
130 - * @return STRING Modified admin body classes.
131 - */
132 - public function add_admin_body_class( $classes ) {
133 - $classes .= ' postx-admin-page ';
134 - return $classes;
135 - }
93 + // Fire When Plugin First Install
94 + public function install_hook() {
95 + if (!get_option('ultp_options')) {
96 + ultimate_post()->init_set_data();
97 + }
98 + }
136 99
137 - /**
138 - * Add body class in front end.
139 - *
140 - * @since v.3.1.6
141 - * @param ARRAY $classes The existing body classes.
142 - * @return ARRAY Modified body classes.
143 - */
144 - public function add_body_class( $classes ) {
145 - $classes[] = 'postx-page';
146 - return $classes;
147 - }
100 + public function activation_redirect($plugin) {
101 + if( $plugin == 'ultimate-post/ultimate-post.php' ) {
102 + exit(wp_redirect(admin_url('admin.php?page=ultp-settings')));
103 + }
104 + }
148 105
149 - /**
150 - * Post view counter for every post.
151 - *
152 - * @since v.1.0.0
153 - * @param INT $post_id The post ID.
154 - * @return NULL No return value.
155 - */
156 - public function popular_posts_tracker_callback( $post_id ) {
157 - if ( ! is_single() ) {
158 - return;
159 - }
160 - global $post;
161 - $post_id = isset( $post->ID ) ? $post->ID : '';
162 - $isEnable = apply_filters( 'ultp_view_cookies', true );
163 - // add_filter( 'ultp_view_cookies', '__return_false' );
164 - $cookies_disable = ultimate_post()->get_setting( 'disable_view_cookies' );
165 - if ( $post_id && $isEnable && $cookies_disable != 'yes' ) {
166 - $has_cookie = isset( $_COOKIE[ 'ultp_view_' . $post_id ] ) ? sanitize_text_field( $_COOKIE[ 'ultp_view_' . $post_id ] ) : false;
167 - if ( ! $has_cookie ) {
168 - $count = (int) get_post_meta( $post_id, '__post_views_count', true );
169 - update_post_meta( $post_id, '__post_views_count', $count ? (int) $count + 1 : 1 );
170 - setcookie( 'ultp_view_' . $post_id, 1, time() + 86400, COOKIEPATH ); // 1 days cookies
171 - }
172 - }
173 - }
106 + public function ultp_pagination_callback() {
107 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local) {
108 + return ;
109 + }
174 110
175 - /**
176 - * Set image sizes for the plugin.
177 - *
178 - * @since v.1.0.0
179 - * @return void No return value.
180 - */
181 - public function add_image_size() {
182 - $size_disable = ultimate_post()->get_setting( 'disable_image_size' );
183 - if ( $size_disable != 'yes' ) {
184 - add_image_size( 'ultp_layout_landscape_large', 1200, 800, true );
185 - add_image_size( 'ultp_layout_landscape', 870, 570, true );
186 - add_image_size( 'ultp_layout_portrait', 600, 900, true );
187 - add_image_size( 'ultp_layout_square', 600, 600, true );
188 - }
189 - }
111 + $paged = sanitize_text_field($_POST['paged']);
112 + $blockId = sanitize_text_field($_POST['blockId']);
113 + $postId = sanitize_text_field($_POST['postId']);
114 + $blockRaw = sanitize_text_field($_POST['blockName']);
115 + $blockName = str_replace('_','/', $blockRaw);
190 116
191 - /**
192 - * Block categories initialization.
193 - *
194 - * @since v.1.0.0
195 - * @param ARRAY $categories The block categories.
196 - * @param ARRAY $post The post object.
197 - * @return ARRAY Modified block categories.
198 - */
199 - public function register_category_callback( $categories, $post ) {
200 - $attr = array(
201 - array(
202 - 'slug' => 'ultimate-post',
203 - 'title' => __( 'PostX - Gutenberg Post Blocks', 'ultimate-post' ),
204 - ),
205 - array(
206 - 'slug' => 'postx-site-builder',
207 - 'title' => __( 'PostX Site Builder', 'ultimate-post' ),
208 - ),
209 - );
210 - return array_merge( $attr, $categories );
211 - }
117 + if($paged) {
118 + $post = get_post($postId);
119 + if (has_blocks($post->post_content)) {
120 + $blocks = parse_blocks($post->post_content);
121 + $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
122 + }
123 + }
124 + }
212 125
213 - /**
214 - * Add support for CSS to use SVG.
215 - *
216 - * @since 4.0.0
217 - * @param ARRAY $styles The allowed CSS styles.
218 - * @return ARRAY Modified allowed CSS styles.
219 - */
220 - public function ultp_handle_safe_style_css( $styles ) {
221 - if ( ! is_multisite() && ! current_user_can( 'edit_posts' ) ) {
222 - return $styles;
223 - }
224 - return array_merge(
225 - $styles,
226 - array(
227 - 'opacity',
228 - // for SVG gradients.
229 - // 'stop-opacity',
230 - // 'stop-color',
231 - )
232 - );
233 - }
126 + public function block_return($blocks, $paged, $blockId, $blockRaw, $blockName) {
127 + foreach ($blocks as $key => $value) {
128 + if($blockName == $value['blockName']) {
129 + if($value['attrs']['blockId'] == $blockId) {
130 + $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
131 + $attr['paged'] = $paged;
132 + $attr = array_merge($attr, $value['attrs']);
133 + echo $this->all_blocks[$blockRaw]->content($attr, true);
134 + die();
135 + }
136 + }
137 + if(!empty($value['innerBlocks'])){
138 + $this->block_return($value['innerBlocks'], $paged, $blockId, $blockRaw, $blockName);
139 + }
140 + }
141 + }
234 142
235 - /**
236 - * Add support for HTML tags to use SVG.
237 - *
238 - * @since 4.0.0
239 - * @param ARRAY $tags The allowed HTML tags.
240 - * @param STRING $context The context for allowed HTML.
241 - * @return ARRAY Modified allowed HTML tags.
242 - */
243 - public function ultp_handle_allowed_html( $tags, $context ) {
244 - if ( 'post' !== $context && ! is_multisite() && ! current_user_can( 'edit_posts' ) ) {
245 - return $tags;
246 - }
247 - if ( ! isset( $tags['svg'] ) ) {
248 - $tags['svg'] = array_merge(
249 - array(
250 - 'xmlns' => true,
251 - // 'xmlns:xlink' => true,
252 - // 'xlink:href' => true,
253 - // 'xml:id' => true,
254 - // 'xlink:title' => true,
255 - // 'xml:space' => true,
256 - 'viewbox' => true,
257 - 'enable-background' => true,
258 - 'version' => true,
259 - 'preserveaspectratio' => true,
260 - 'fill' => true,
261 - )
262 - );
263 - }
264 - if ( ! isset( $tags['path'] ) || ! is_array( $tags['path'] ) ) {
265 - $tags['path'] = array();
266 - }
267 143
268 - $tags['path'] = array_merge(
269 - $tags['path'],
270 - array(
271 - 'd' => true,
272 - 'stroke' => true,
273 - 'stroke-miterlimit' => true,
274 - 'data-original' => true,
275 - 'class' => true,
276 - 'transform' => true,
277 - 'style' => true,
278 - 'opacity' => true,
279 - 'fill' => true,
280 - 'stroke-width' => true,
281 - 'stroke-linecap' => true,
282 - 'stroke-linejoin' => true,
283 - )
284 - );
144 + public function ultp_filter_callback() {
145 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
146 + return ;
147 + }
148 +
149 + $taxtype = sanitize_text_field($_POST['taxtype']);
150 + $blockId = sanitize_text_field($_POST['blockId']);
151 + $postId = sanitize_text_field($_POST['postId']);
152 + $taxonomy = sanitize_text_field($_POST['taxonomy']);
153 + $blockRaw = sanitize_text_field($_POST['blockName']);
154 + $blockName = str_replace('_','/', $blockRaw);
285 155
286 - if ( ! isset( $tags['g'] ) ) {
287 - $tags['g'] = array(
288 - 'transform' => true,
289 - 'clip-path' => true,
290 - );
291 - }
292 - if ( ! isset( $tags['clippath'] ) ) {
293 - $tags['clippath'] = array();
294 - }
295 - if ( ! isset( $tags['defs'] ) ) {
296 - $tags['defs'] = array();
297 - }
298 - if ( ! isset( $tags['rect'] ) ) {
299 - $tags['rect'] = array(
300 - 'rx' => true,
301 - 'height' => true,
302 - 'width' => true,
303 - 'transform' => true,
304 - 'x' => true,
305 - 'fill' => true,
306 - );
307 - }
308 - if ( ! isset( $tags['circle'] ) ) {
309 - $tags['circle'] = array(
310 - 'cx' => true,
311 - 'cy' => true,
312 - 'transform' => true,
313 - 'r' => true,
314 - );
315 - }
316 - if ( ! isset( $tags['polygon'] ) ) {
317 - $tags['polygon'] = array(
318 - 'points' => true,
319 - );
320 - }
321 - if ( ! isset( $tags['lineargradient'] ) ) {
322 - $tags['lineargradient'] = array(
323 - 'gradienttransform' => true,
324 - 'id' => true,
325 - );
326 - }
327 - if ( ! isset( $tags['stop'] ) ) {
328 - $tags['stop'] = array(
329 - 'offset' => true,
330 - 'stop-color' => true,
331 - 'style' => true,
332 - 'stop-opacity' => true,
333 - );
334 - }
335 - return $tags;
336 - }
156 + if( $taxtype ) {
157 + $post = get_post($postId);
158 + if (has_blocks($post->post_content)) {
159 + $blocks = parse_blocks($post->post_content);
160 + $this->filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
161 + }
162 + }
163 + }
337 164
338 - /**
339 - * Plugin activation callback.
340 - *
341 - * @since v.1.1.0
342 - * @param STRING $plugin The plugin file path.
343 - * @return NULL No return value.
344 - */
345 - public function ultp_plugin_activation( $plugin ) {
346 - if ( wp_doing_ajax() ) {
347 - return;
348 - }
349 - if ( $plugin == 'ultimate-post/ultimate-post.php' ) {
350 - if ( wp_doing_ajax() || is_network_admin() || isset( $_GET['activate-multi'] ) || isset( $_POST['action'] ) && 'activate-selected' == $_POST['action'] ) {
351 - return;
352 - }
353 - if ( ultimate_post()->get_setting( 'init_setup' ) != 'yes' ) {
354 - ultimate_post()->set_setting( 'init_setup', 'yes' );
355 - exit(wp_safe_redirect(admin_url('admin.php?page=ultp-setup-wizard'))); //phpcs:ignore
356 - } else {
357 - exit(wp_safe_redirect(admin_url('admin.php?page=ultp-settings#home'))); //phpcs:ignore
358 - }
359 - }
360 - }
165 + public function filter_block_return($blocks, $blockId, $blockRaw, $blockName, $taxtype, $taxonomy) {
166 + foreach ($blocks as $key => $value) {
167 + if($blockName == $value['blockName']) {
168 + if($value['attrs']['blockId'] == $blockId) {
169 + $attr = $this->all_blocks[$blockRaw]->get_attributes(true);
170 + $value['attrs']['queryTax'] = $taxtype == 'category' ? 'category' : 'tag';
171 + if($taxtype == 'category' && $taxonomy) {
172 + $value['attrs']['queryCat'] = json_encode(array($taxonomy));
173 + }
174 + if($taxtype == 'post_tag' && $taxonomy) {
175 + $value['attrs']['queryTag'] = json_encode(array($taxonomy));
176 + }
177 + if(isset($value['attrs']['queryNumber'])){
178 + $value['attrs']['queryNumber'] = $value['attrs']['queryNumber'];
179 + }
180 + $attr = array_merge($attr, $value['attrs']);
181 + echo $this->all_blocks[$blockRaw]->content($attr, true);
182 + die();
183 + }
184 + }
185 + if(!empty($value['innerBlocks'])){
186 + $this->filter_block_return($value['innerBlocks'], $blockId, $blockRaw, $blockName, $taxtype, $taxonomy);
187 + }
188 + }
189 + }
361 190
362 - /**
363 - * Enqueue option panel CSS and JS scripts.
364 - *
365 - * @since v.1.0.0
366 - * @return void No return value.
367 - */
368 - public function register_option_panel_scripts_callback() {
369 - $is_active = ultimate_post()->is_lc_active();
370 - $license_key = Xpo::get_lc_key();
371 - $_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; // @codingStandardsIgnoreLine
372 - $post_type = get_post_type();
373 - $is_woocommerce_active = class_exists( 'WooCommerce' ) ? true : false;
374 191
375 - wp_enqueue_style( 'wp-color-picker' );
376 - wp_enqueue_script( 'wp-color-picker' );
192 + public function ultp_next_prev_callback() {
193 + if (!wp_verify_nonce($_REQUEST['wpnonce'], 'ultp-nonce') && $local){
194 + return ;
195 + }
377 196
378 - wp_enqueue_script( 'ultp-option-script', ULTP_URL . 'assets/js/ultp-option.js', array( 'jquery' ), ULTP_VER, true );
379 - wp_enqueue_style( 'ultp-option-style', ULTP_URL . 'assets/css/ultp-option.css', array(), ULTP_VER );
380 - wp_localize_script(
381 - 'ultp-option-script',
382 - 'ultp_option_panel',
383 - array(
384 - 'url' => ULTP_URL,
385 - 'version' => ULTP_VER,
386 - 'active' => $is_active,
387 - 'security' => wp_create_nonce( 'ultp-nonce' ),
388 - 'ajax' => admin_url( 'admin-ajax.php' ),
389 - 'settings' => ultimate_post()->get_setting(),
390 - 'post_type' => $post_type,
391 - 'saved_template_url' => admin_url( 'admin.php?page=ultp-settings#saved-templates' ),
392 - 'woocommerce' => $is_woocommerce_active,
393 - )
394 - );
197 + $paged = sanitize_text_field($_POST['paged']);
198 + $blockId = sanitize_text_field($_POST['blockId']);
199 + $postId = sanitize_text_field($_POST['postId']);
200 + $blockRaw = sanitize_text_field($_POST['blockName']);
201 + $blockName = str_replace('_','/', $blockRaw);
395 202
396 - if ( $post_type == 'ultp_custom_font' ) {
397 - $font_settings = ultimate_post()->get_setting( 'ultp_custom_font' );
398 - if ( $font_settings == 'true' ) {
399 - wp_enqueue_media();
400 - }
401 - }
203 + if( $paged && $blockId && $postId && $blockName ) {
204 + $post = get_post($postId);
205 + if (has_blocks($post->post_content)) {
206 + $blocks = parse_blocks($post->post_content);
207 + $this->block_return($blocks, $paged, $blockId, $blockRaw, $blockName);
208 + }
209 + }
210 + }
402 211
403 - /* === Installation Wizard === */
404 - if ( $_page == 'ultp-setup-wizard' ) {
405 - wp_enqueue_script( 'ultp-initial-setup-script', ULTP_URL . 'assets/js/ultp_initial_setup_min.js', array( 'wp-i18n', 'wp-api-fetch', 'wp-api-request' ), ULTP_VER, true );
406 - wp_set_script_translations( 'ultp-initial-setup-script', 'ultimate-post', ULTP_PATH . 'languages/' );
407 - }
212 + // Require Blocks
213 + public function blocks() {
214 + require_once ULTP_PATH.'blocks/Post_List_1.php';
215 + require_once ULTP_PATH.'blocks/Post_List_2.php';
216 + require_once ULTP_PATH.'blocks/Post_List_3.php';
217 + require_once ULTP_PATH.'blocks/Post_Slider_1.php';
218 + require_once ULTP_PATH.'blocks/Post_Grid_1.php';
219 + require_once ULTP_PATH.'blocks/Post_Grid_2.php';
220 + require_once ULTP_PATH.'blocks/Post_Grid_3.php';
221 + require_once ULTP_PATH.'blocks/Post_Grid_4.php';
222 + require_once ULTP_PATH.'blocks/Heading.php';
223 + require_once ULTP_PATH.'blocks/Image.php';
224 + //require_once ULTP_PATH.'blocks/Taxonomy.php';
225 + $this->all_blocks['ultimate-post_post-list-1'] = new \ULTP\blocks\Post_List_1();
226 + $this->all_blocks['ultimate-post_post-list-2'] = new \ULTP\blocks\Post_List_2();
227 + $this->all_blocks['ultimate-post_post-list-3'] = new \ULTP\blocks\Post_List_3();
228 + $this->all_blocks['ultimate-post_post-slider-1'] = new \ULTP\blocks\Post_Slider_1();
229 + $this->all_blocks['ultimate-post_post-grid-1'] = new \ULTP\blocks\Post_Grid_1();
230 + $this->all_blocks['ultimate-post_post-grid-2'] = new \ULTP\blocks\Post_Grid_2();
231 + $this->all_blocks['ultimate-post_post-grid-3'] = new \ULTP\blocks\Post_Grid_3();
232 + $this->all_blocks['ultimate-post_post-grid-4'] = new \ULTP\blocks\Post_Grid_4();
233 + $this->all_blocks['ultimate-post_heading'] = new \ULTP\blocks\Heading();
234 + //$this->all_blocks['ultimate-post_taxonomy'] = new \ULTP\blocks\Taxonomy();
235 + $this->all_blocks['ultimate-post_image'] = new \ULTP\blocks\Image();
236 + }
408 237
409 - /* === Builder And Setting Pannel === */
410 - if ( get_post_type( get_the_ID() ) == 'ultp_builder' ) {
411 - wp_enqueue_script( 'ultp-conditions-script', ULTP_URL . 'addons/builder/assets/js/conditions.js', array( 'wp-i18n', 'wp-api-fetch', 'wp-components', 'wp-i18n', 'wp-blocks' ), ULTP_VER, true );
412 - wp_localize_script(
413 - 'ultp-conditions-script',
414 - 'ultp_condition',
415 - array(
416 - 'url' => ULTP_URL,
417 - 'active' => $is_active,
418 - 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
419 - )
420 - );
421 - wp_set_script_translations( 'ultp-conditions-script', 'ultimate-post', ULTP_PATH . 'languages/' );
422 - }
238 + // Require Categories
239 + public function requires() {
240 + require_once ULTP_PATH.'classes/Styles.php';
241 + require_once ULTP_PATH.'classes/Options.php';
242 + require_once ULTP_PATH.'classes/REST_API.php';
423 243
424 - /* === Dashboard === */
425 - if ( $_page == 'ultp-settings' ) {
426 - wp_enqueue_script( 'ultp-dashboard-script', ULTP_URL . 'assets/js/ultp_dashboard_min.js', array( 'wp-i18n', 'wp-api-fetch', 'wp-api-request', 'wp-components', 'wp-blocks' ), ULTP_VER, true );
427 - $user_info = get_userdata( get_current_user_id() );
428 - wp_localize_script(
429 - 'ultp-dashboard-script',
430 - 'ultp_dashboard_pannel',
431 - array_merge(
432 - array(
433 - 'ajax' => admin_url( 'admin-ajax.php' ),
434 - 'security' => wp_create_nonce( 'ultp-nonce' ),
435 - 'url' => ULTP_URL,
436 - 'active' => $is_active,
437 - 'license' => $license_key,
438 - 'settings' => ultimate_post()->get_setting(),
439 - 'addons_settings' => apply_filters( 'ultp_settings', array() ),
440 - 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
441 - 'version' => ULTP_VER,
442 - 'setup_wizard_link' => admin_url( 'admin.php?page=ultp-setup-wizard' ),
443 - 'is_free' => ! $is_active,
444 - 'user_email' => wp_get_current_user()->user_email,
445 - 'home_url' => home_url(),
446 - 'generalDiscount' => get_transient( 'ultp_generalDiscount' ),
447 - 'helloBar' => Notice::get_hellobar_config(),
448 - 'userInfo' => array(
449 - 'name' => $user_info->first_name ? $user_info->first_name . ( $user_info->last_name ? ' ' . $user_info->last_name : '' ) : $user_info->user_login,
450 - 'email' => $user_info->user_email,
451 - ),
452 - ),
453 - Xpo::get_wow_products_details()
454 - )
455 - );
456 - wp_set_script_translations( 'ultp-dashboard-script', 'ultimate-post', ULTP_PATH . 'languages/' );
457 - }
458 - }
244 + new \ULTP\Options();
245 + new \ULTP\Styles();
246 + }
459 247
460 - /**
461 - * Enqueue backend CSS and JS scripts for the block editor.
462 - *
463 - * @since v.1.0.0
464 - * @return void No return value.
465 - */
466 - public function register_block_scripts_editor_area() {
467 - ultimate_post()->register_scripts_common();
468 - global $pagenow;
469 - $depends = 'wp-editor';
470 - if ( $pagenow === 'widgets.php' ) {
471 - $depends = 'wp-edit-widgets';
472 - }
473 - wp_enqueue_script( 'ultp-blocks-editor-script', ULTP_URL . 'assets/js/editor.blocks.js', array( 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', $depends ), ULTP_VER, true );
474 - wp_enqueue_style( 'ultp-blocks-editor-css', ULTP_URL . 'assets/css/blocks.editor.css', array(), ULTP_VER );
475 - if ( is_rtl() ) {
476 - wp_enqueue_style( 'ultp-blocks-editor-rtl-css', ULTP_URL . 'assets/css/rtl.css', array(), ULTP_VER );
477 - }
478 - $is_active = ultimate_post()->is_lc_active();
479 - $post_type = get_post_type();
248 + // Block Categories
249 + public function register_category_callback( $categories, $post ) {
250 + return array_merge(
251 + array(
252 + array(
253 + 'slug' => 'ultimate-post',
254 + 'title' => __( 'Gutenberg Post Blocks', 'ultimate-post' )
255 + )
256 + ), $categories
257 + );
258 + }
480 259
481 - // Custom Font Support Added
482 - $font_settings = ultimate_post()->get_setting( 'ultp_custom_font' );
483 - $custom_fonts = array();
484 - if ( $font_settings == 'true' ) {
485 - $args = array(
486 - 'post_type' => 'ultp_custom_font',
487 - 'post_status' => 'publish',
488 - 'numberposts' => -1,
489 - 'order' => 'ASC',
490 - );
491 - $posts = get_posts( $args );
492 - if ( $posts ) {
493 - foreach ( $posts as $post ) {
494 - setup_postdata( $post );
495 - $font = get_post_meta( $post->ID, '__font_settings', true );
260 + public function popular_posts_tracker_callback($post_id) {
261 + if (!is_single()){ return; }
262 + global $post;
263 + if (empty($post_id)) { $post_id = $post->ID; }
264 + $count = (int)get_post_meta( $post_id, '__post_views_count', true );
265 + update_post_meta($post_id, '__post_views_count', $count ? (int)$count + 1 : 1 );
266 + }
496 267
497 - if ( $font ) {
498 - array_push(
499 - $custom_fonts,
500 - array(
501 - 'title' => $post->post_title,
502 - 'font' => $font,
503 - )
504 - );
505 - }
506 - }
507 - wp_reset_postdata();
508 - }
509 - }
510 -
511 - wp_localize_script(
512 - 'ultp-blocks-editor-script',
513 - 'ultp_data',
514 - array(
515 - 'url' => ULTP_URL,
516 - 'ajax' => admin_url( 'admin-ajax.php' ),
517 - 'security' => wp_create_nonce( 'ultp-nonce' ),
518 - 'hide_import_btn' => ultimate_post()->get_setting( 'hide_import_btn' ),
519 - 'premium_link' => Xpo::generate_utm_link(),
520 - 'license' => $is_active ? Xpo::get_lc_key() : '',
521 - 'active' => $is_active,
522 - 'archive' => ultimate_post()->is_archive_builder(),
523 - 'settings' => ultimate_post()->get_setting(),
524 - 'post_type' => $post_type == 'premade' ? 'ultp_builder' : $post_type, // premade used for ultp.wpxpo.com
525 - 'date_format' => get_option( 'date_format' ),
526 - 'time_format' => get_option( 'time_format' ),
527 - 'blog' => get_current_blog_id(),
528 - 'affiliate_id' => apply_filters( 'ultp_affiliate_id', false ),
529 - 'category_url' => admin_url( 'edit-tags.php?taxonomy=category' ),
530 - 'disable_image_size' => ultimate_post()->get_setting( 'disable_image_size' ),
531 - 'dark_logo' => get_option( 'ultp_site_dark_logo' ) ? get_option( 'ultp_site_dark_logo' ) : false,
532 - 'builder_url' => admin_url( 'admin.php?page=ultp-settings#builder' ),
533 - 'custom_fonts' => $custom_fonts,
534 - )
535 - );
536 - wp_set_script_translations( 'ultp-blocks-editor-script', 'ultimate-post', ULTP_PATH . 'languages/' );
537 - }
538 -
539 -
540 - /**
541 - * Fire when plugin is first installed.
542 - *
543 - * @since v.1.0.0
544 - * @return void No return value.
545 - */
546 - public function plugin_activation_hook() {
547 - $data = get_option( 'ultp_options', array() );
548 - $currentDate = new \DateTime();
549 - $currentDate->setTime( 0, 0, 0, 0 );
550 - $init_data = array(
551 - 'preloader_style' => 'style1',
552 - 'preloader_color' => '#037fff',
553 - 'container_width' => '1140',
554 - 'hide_import_btn' => '',
555 - 'disable_image_size' => '',
556 - 'disable_view_cookies' => '',
557 - 'disable_google_font' => '',
558 - 'ultp_templates' => 'true',
559 - 'ultp_elementor' => 'true',
560 - 'ultp_table_of_content' => 'true',
561 - 'ultp_builder' => 'true',
562 - 'ultp_dynamic_content' => 'true',
563 - 'ultp_custom_font' => 'true',
564 - 'ultp_chatgpt' => 'true',
565 - 'post_grid_1' => 'yes',
566 - 'post_grid_2' => 'yes',
567 - 'post_grid_3' => 'yes',
568 - 'post_grid_4' => 'yes',
569 - 'post_grid_5' => 'yes',
570 - 'post_grid_6' => 'yes',
571 - 'post_grid_7' => 'yes',
572 - 'post_list_1' => 'yes',
573 - 'post_list_2' => 'yes',
574 - 'post_list_3' => 'yes',
575 - 'post_list_4' => 'yes',
576 - 'post_module_1' => 'yes',
577 - 'post_module_2' => 'yes',
578 - 'post_slider_1' => 'yes',
579 - 'post_slider_2' => 'yes',
580 - 'heading' => 'yes',
581 - 'image' => 'yes',
582 - 'taxonomy' => 'yes',
583 - 'wrapper' => 'yes',
584 - 'news_ticker' => 'yes',
585 - 'accordion' => 'yes',
586 - 'star_rating' => 'yes',
587 - 'youtube_gallery' => 'yes',
588 - 'builder_advance_post_meta' => 'yes',
589 - 'builder_archive_title' => 'yes',
590 - 'builder_author_box' => 'yes',
591 - 'builder_post_next_previous' => 'yes',
592 - 'builder_post_author_meta' => 'yes',
593 - 'builder_post_breadcrumb' => 'yes',
594 - 'builder_post_category' => 'yes',
595 - 'builder_post_comment_count' => 'yes',
596 - 'builder_post_comments' => 'yes',
597 - 'builder_post_content' => 'yes',
598 - 'builder_post_date_meta' => 'yes',
599 - 'builder_post_excerpt' => 'yes',
600 - 'builder_post_featured_image' => 'yes',
601 - 'builder_post_reading_time' => 'yes',
602 - 'builder_post_social_share' => 'yes',
603 - 'builder_post_tag' => 'yes',
604 - 'builder_post_title' => 'yes',
605 - 'builder_post_view_count' => 'yes',
606 - 'save_version' => wp_rand( 1, 1000 ),
607 - 'activated_date' => $currentDate->getTimestamp(),
608 - );
609 - if ( empty( $data ) ) {
610 - update_option( 'ultp_options', $init_data );
611 - $GLOBALS['ultp_settings'] = $init_data;
612 - } else {
613 - foreach ( $init_data as $key => $single ) {
614 - if ( ! isset( $data[ $key ] ) ) {
615 - $data[ $key ] = $single;
616 - }
617 - }
618 - update_option( 'ultp_options', $data );
619 - $GLOBALS['ultp_settings'] = $data;
620 - }
621 - if ( ! get_transient( 'wpxpo_installation_date' ) ) {
622 - set_transient( 'wpxpo_installation_date', 'yes', 5 * DAY_IN_SECONDS ); // 5 Days Notice
623 - }
624 - }
625 -}
268 + public function add_image_size() {
269 + add_image_size('ultp_layout_landscape_large', 1200, 800, true);
270 + add_image_size('ultp_layout_landscape', 870, 570, true);
271 + add_image_size('ultp_layout_portrait', 600, 900, true);
272 + add_image_size('ultp_layout_square', 600, 600, true);
273 + }
274 +}