PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.41
Post Grid Gutenberg Blocks – PostX v5.0.41
5.0.41 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 All 238 releases
← All changes | classes/Functions.php +2963 -370 2.1.15.0.41 View file →
@@ -1,415 +1,3008 @@
1 1 <?php
2 +/**
3 + * Common Functions.
4 + *
5 + * @package ULTP\Functions
6 + * @since v.1.0.0
7 + */
8 +
2 9 namespace ULTP;
3 10
4 -defined('ABSPATH') || exit;
11 +use ULTP\Includes\Durbin\Xpo;
5 12
6 -class Functions{
13 +defined( 'ABSPATH' ) || exit;
7 14
8 - public function __construct(){
9 - $GLOBALS['ultp_settings'] = get_option('ultp_options');
10 - }
15 +/**
16 + * Functions class.
17 + *
18 + * Provides utility functions for Ultimate Post plugin.
19 + *
20 + * @package ULTP\Functions
21 + * @since 4.0.0
22 + */
23 +class Functions {
11 24
12 - public function reusable_id($post_id){
13 - $reusable_id = array();
14 - if($post_id){
15 - $post = get_post($post_id);
16 - if (has_blocks($post->post_content)) {
17 - $blocks = parse_blocks($post->post_content);
18 - foreach ($blocks as $key => $value) {
19 - if(isset($value['attrs']['ref'])) {
20 - $reusable_id[] = $value['attrs']['ref'];
21 - }
22 - }
23 - }
24 - }
25 - return $reusable_id;
26 - }
27 -
28 - public function set_css_style($post_id){
29 - if( $post_id ){
30 - $upload_dir_url = wp_get_upload_dir();
25 + /**
26 + * Funtion
27 + *
28 + * @since v.3.2.4
29 + *
30 + * Instance of the class.
31 + *
32 + * @var Functions | null
33 + */
34 + private static $instance = null;
35 +
36 + /**
37 + * Setup class.
38 + *
39 + * @since v.1.0.0
40 + */
41 + public function __construct() {
42 + }
43 +
44 + /**
45 + * Gets the instance of \ULTP\Functions class
46 + *
47 + * @return Functions
48 + * @since v.3.2.4
49 + */
50 + public static function get_instance() {
51 + if ( ! isset( $GLOBALS['ultp_settings'] ) ) {
52 + $GLOBALS['ultp_settings'] = get_option( 'ultp_options' );
53 + }
54 +
55 + if ( is_null( self::$instance ) ) {
56 + self::$instance = new self();
57 + }
58 +
59 + return self::$instance;
60 + }
61 +
62 + /**
63 + * ID for the Builder Post or Normal Post
64 + *
65 + * @since v.2.3.1
66 + * @return NUMBER | is Builder or not
67 + */
68 + public function get_ID() {
69 + $id = $this->is_builder();
70 + return $id ? $id : ( function_exists( 'is_shop' ) ? ( is_shop() ? wc_get_page_id( 'shop' ) : get_the_ID() ) : get_the_ID() );
71 + }
72 +
73 + /**
74 + * Checking Statement of Dynamic Site Builder
75 + *
76 + * @since v.2.3.1
77 + * @return BOOLEAN | is Builder or not
78 + */
79 + public function is_archive_builder() {
80 + $id = get_the_ID();
81 + return get_post_type( $id ) == 'ultp_builder' ? get_post_meta( $id, '__ultp_builder_type', true ) : false;
82 + }
83 +
84 + /**
85 + * Set Link with the Parameters
86 + *
87 + * @since v.1.1.0
88 + * @param string $url .
89 + * @param string $tag .
90 + * @return STRING | URL with Arg
91 + */
92 + public function get_premium_link( $url = null, $tag = '' ) {
93 + return Xpo::generate_utm_link(
94 + array(
95 + 'url' => $url,
96 + 'utmKey' => $tag,
97 + )
98 + );
99 + }
100 +
101 +
102 + /**
103 + * Quick Query
104 + *
105 + * @since v.1.1.0
106 + * @param ARRAY $prams Quick query parameters.
107 + * @param ARRAY $args Query arguments to modify.
108 + * @return ARRAY
109 + */
110 + public function get_quick_query( $prams, $args ) {
111 + switch ( $prams['queryQuick'] ) {
112 + case 'related_posts':
113 + global $post;
114 + $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ); //phpcs:disable WordPress.Security.NonceVerification.Missing
115 + if ( $p_id ) {
116 + $args['post__not_in'] = array( $p_id );
117 + }
118 + break;
119 + case 'related_tag':
120 + global $post;
121 + $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
122 + if ( $p_id ) {
123 + $args['tax_query'] = array(
124 + array(
125 + 'taxonomy' => 'post_tag',
126 + 'terms' => $this->get_terms_id( $p_id, 'post_tag' ),
127 + 'field' => 'term_id',
128 + ),
129 + );
130 + $args['post__not_in'] = array( $p_id );
131 + }
132 + break;
133 + case 'related_category':
134 + global $post;
135 + $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
136 + if ( $p_id ) {
137 + $args['tax_query'] = array(
138 + array(
139 + 'taxonomy' => 'category',
140 + 'terms' => $this->get_terms_id( $p_id, 'category' ),
141 + 'field' => 'term_id',
142 + ),
143 + );
144 + $args['post__not_in'] = array( $p_id );
145 + }
146 + break;
147 + case 'related_cat_tag':
148 + global $post;
149 + $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
150 + if ( $p_id ) {
151 + $args['tax_query'] = array(
152 + array(
153 + 'taxonomy' => 'post_tag',
154 + 'terms' => $this->get_terms_id( $p_id, 'post_tag' ),
155 + 'field' => 'term_id',
156 + ),
157 + array(
158 + 'taxonomy' => 'category',
159 + 'terms' => $this->get_terms_id( $p_id, 'category' ),
160 + 'field' => 'term_id',
161 + ),
162 + );
163 + $args['post__not_in'] = array( $p_id );
164 + }
165 + break;
166 + case 'sticky_posts':
167 + $sticky = get_option( 'sticky_posts' );
168 + if ( is_array( $sticky ) ) {
169 + rsort( $sticky );
170 + // $sticky = array_slice($sticky, 0, $args['posts_per_page']);
171 + }
172 + $args['ignore_sticky_posts'] = 1;
173 + $args['post__in'] = $sticky;
174 + break;
175 + case 'latest_post_published':
176 + $args['orderby'] = 'date';
177 + $args['order'] = 'DESC';
178 + $args['ignore_sticky_posts'] = 1;
179 + break;
180 + case 'latest_post_modified':
181 + $args['orderby'] = 'modified';
182 + $args['order'] = 'DESC';
183 + $args['ignore_sticky_posts'] = 1;
184 + break;
185 + case 'oldest_post_published':
186 + $args['orderby'] = 'date';
187 + $args['order'] = 'ASC';
188 + break;
189 + case 'oldest_post_modified':
190 + $args['orderby'] = 'modified';
191 + $args['order'] = 'ASC';
192 + break;
193 + case 'alphabet_asc':
194 + $args['orderby'] = 'title';
195 + $args['order'] = 'ASC';
196 + break;
197 + case 'alphabet_desc':
198 + $args['orderby'] = 'title';
199 + $args['order'] = 'DESC';
200 + break;
201 + case 'random_post':
202 + $args['orderby'] = 'rand';
203 + $args['order'] = 'ASC';
204 + break;
205 + case 'random_post_7_days':
206 + $args['orderby'] = 'rand';
207 + $args['order'] = 'ASC';
208 + $args['date_query'] = array( array( 'after' => '1 week ago' ) );
209 + break;
210 + case 'random_post_30_days':
211 + $args['orderby'] = 'rand';
212 + $args['order'] = 'ASC';
213 + $args['date_query'] = array( array( 'after' => '1 month ago' ) );
214 + break;
215 + case 'most_comment':
216 + $args['orderby'] = 'comment_count';
217 + $args['order'] = 'DESC';
218 + break;
219 + case 'most_comment_1_day':
220 + $args['orderby'] = 'comment_count';
221 + $args['order'] = 'DESC';
222 + $args['date_query'] = array( array( 'after' => '1 day ago' ) );
223 + break;
224 + case 'most_comment_7_days':
225 + $args['orderby'] = 'comment_count';
226 + $args['order'] = 'DESC';
227 + $args['date_query'] = array( array( 'after' => '1 week ago' ) );
228 + break;
229 + case 'most_comment_30_days':
230 + $args['orderby'] = 'comment_count';
231 + $args['order'] = 'DESC';
232 + $args['date_query'] = array( array( 'after' => '1 month ago' ) );
233 + break;
234 + case 'popular_post_1_day_view':
235 + $args['meta_key'] = '__post_views_count';
236 + $args['orderby'] = 'meta_value_num';
237 + $args['order'] = 'DESC';
238 + $args['date_query'] = array( array( 'after' => '1 day ago' ) );
239 + break;
240 + case 'popular_post_7_days_view':
241 + $args['meta_key'] = '__post_views_count';
242 + $args['orderby'] = 'meta_value_num';
243 + $args['order'] = 'DESC';
244 + $args['date_query'] = array( array( 'after' => '1 week ago' ) );
245 + break;
246 + case 'popular_post_30_days_view':
247 + $args['meta_key'] = '__post_views_count';
248 + $args['orderby'] = 'meta_value_num';
249 + $args['order'] = 'DESC';
250 + $args['date_query'] = array( array( 'after' => '1 month ago' ) );
251 + break;
252 + case 'popular_post_all_times_view':
253 + $args['meta_key'] = '__post_views_count';
254 + $args['orderby'] = 'meta_value_num';
255 + $args['order'] = 'DESC';
256 + break;
257 + default:
258 + // code...
259 + break;
260 + }
261 + return $args;
262 + }
263 +
264 + /**
265 + * Get All Term IDs for a Post in a Taxonomy
266 + *
267 + * @since v.2.4.12
268 + * @param INT|STRING $id Post ID to get terms for.
269 + * @param STRING $type Taxonomy name (e.g. 'category', 'post_tag').
270 + * @return ARRAY
271 + */
272 + public function get_terms_id( $id, $type ) {
273 + $data = array();
274 + $arr = get_the_terms( $id, $type );
275 + if ( is_array( $arr ) ) {
276 + foreach ( $arr as $key => $val ) {
277 + $data[] = $val->term_id;
278 + }
279 + }
280 + return $data;
281 + }
282 +
283 + /**
284 + * Get all reusable block IDs referenced in a post's content
285 + *
286 + * @since v.1.1.0
287 + * @param INT|STRING $post_id .
288 + * @return ARRAY
289 + */
290 + public function get_reusable_ids( $post_id ) {
291 + $reusable_id = array();
292 + if ( $post_id ) {
293 + $post = get_post( $post_id );
294 + if ( isset( $post->post_content ) ) {
295 + if (
296 + has_blocks( $post->post_content ) &&
297 + strpos( $post->post_content, 'wp:block' ) &&
298 + strpos( $post->post_content, '"ref"' ) !== false
299 + ) {
300 + $blocks = parse_blocks( $post->post_content );
301 + foreach ( $blocks as $key => $value ) {
302 + if ( isset( $value['attrs']['ref'] ) ) {
303 + $reusable_id[] = $value['attrs']['ref'];
304 + }
305 + }
306 + }
307 + }
308 + }
309 + return $reusable_id;
310 + }
311 +
312 + /**
313 + * Safely reads file contents using WordPress Filesystem API
314 + *
315 + * @since v.4.1.8
316 + * @param STRING $path .
317 + * @return STRING|ARRAY.
318 + */
319 + public function get_path_file_contents( $path ) {
320 + global $wp_filesystem;
321 + if ( ! $wp_filesystem ) {
322 + require_once ABSPATH . 'wp-admin/includes/file.php';
323 + $init_fs = WP_Filesystem();
324 + if ( ! $init_fs ) {
325 + return '';
326 + }
327 + }
328 +
329 + if ( $wp_filesystem->exists( $path ) ) {
330 + return $wp_filesystem->get_contents( $path );
331 + } else {
332 + return '';
333 + }
334 + }
335 +
336 + /**
337 + * Builds and returns inline CSS for a post and its reusable blocks
338 + *
339 + * @since v.4.1.8
340 + * @param INT|STRING $post_id .
341 + * @param BOOLEAN $call_common .
342 + * @return STRING|ARRAY.
343 + */
344 + public function build_css_for_inline_print( $post_id, $call_common = true ) {
345 + if ( $post_id ) {
346 + $upload_dir_url = wp_get_upload_dir();
31 347 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
32 - $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
33 -
34 - $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
35 - if (is_ssl()) {
36 - $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
37 - }
38 -
39 - // Reusable CSS
40 - $reusable_id = ultimate_post()->reusable_id($post_id);
41 - foreach ( $reusable_id as $id ) {
42 - $reusable_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$id}.css";
43 - if (file_exists( $reusable_dir_path )) {
44 - $css_url = $css_dir_url . "ultimate-post/ultp-css-{$id}.css";
45 - wp_enqueue_style( "ultp-post-{$id}", $css_url, array(), ULTP_VER, 'all' );
46 - }else{
47 - $css = get_post_meta($id, '_ultp_css', true);
48 - if( $css ) {
49 - wp_enqueue_style("ultp-post-{$id}", $css, false, ULTP_VER);
50 - }
348 +
349 + $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
350 + if ( is_ssl() ) {
351 + $css_dir_url = str_replace( 'http://', 'https://', $css_dir_url );
352 + }
353 + $reusable_css = '';
354 + $reusable_id = $this->get_reusable_ids( $post_id );
355 + if ( ! empty( $reusable_id ) ) {
356 + foreach ( $reusable_id as $id ) {
357 + $reusable_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$id}.css";
358 + if ( file_exists( $reusable_dir_path ) ) {
359 + $reusable_css .= $this->get_path_file_contents( $reusable_dir_path );
360 + } else {
361 + $reusable_css .= get_post_meta( $reusable_id, '_ultp_css', true );
362 + }
51 363 }
52 - }
53 -
364 + }
365 +
366 + $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
367 + $css = '';
54 368 if ( file_exists( $css_dir_path ) ) {
55 - $css_url = $css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
56 - wp_enqueue_style( "ultp-post-{$post_id}", $css_url, array(), ULTP_VER, 'all' );
369 + $css = $this->get_path_file_contents( $css_dir_path );
57 370 } else {
58 - $css = get_post_meta($post_id, '_ultp_css', true);
59 - if( $css ) {
60 - wp_enqueue_style("ultp-post-{$post_id}", $css, false, ULTP_VER);
371 + $css = get_post_meta( $post_id, '_ultp_css', true );
372 + }
373 + if ( $reusable_css . $css ) {
374 + if ( $call_common ) {
375 + $this->register_scripts_common();
61 376 }
377 + return '<style id="ultp-post-' . $post_id . '" type="text/css">' . wp_strip_all_tags( $reusable_css . $css ) . '</style>';
62 378 }
63 379 }
64 - }
380 + return '';
381 + }
65 382
66 - public function get_setting($key = ''){
67 - $data = $GLOBALS['ultp_settings'];
68 - if ($key != '') {
69 - return isset($data[$key]) ? $data[$key] : '';
70 - } else {
71 - return $data;
72 - }
73 - }
74 383
75 - public function set_setting($key = '', $val = '') {
76 - if($key != ''){
77 - $data = $GLOBALS['ultp_settings'];
78 - $data[$key] = $val;
79 - update_option('ultp_options', $data);
80 - $GLOBALS['ultp_settings'] = $data;
81 - }
82 - }
384 + /**
385 + * Get Global Plugin Settings
386 + *
387 + * @since v.1.0.0
388 + * @param STRING $key of the Option .
389 + * @return ARRAY|STRING .
390 + */
391 + public function get_setting( $key = '' ) {
392 + $data = $GLOBALS['ultp_settings'];
393 + if ( $key != '' ) {
394 + return isset( $data[ $key ] ) ? $data[ $key ] : '';
395 + } else {
396 + return $data;
397 + }
398 + }
83 399
84 - public function get_image_html($url = '', $size = 'full', $class = '', $alt = ''){
85 - $alt = $alt ? ' alt="'.$alt.'" ' : '';
86 - if( function_exists('ultimate_post_pro') ){
87 - $addon_enable = ultimate_post()->get_setting();
88 - if(isset($addon_enable['addons_imageloading']) && $addon_enable['addons_imageloading'] == 'true'){
89 - $class = $class ? ' class="ultp-lazy '.$class.'" ' : ' class="ultp-lazy" ';
90 - return '<img loading="lazy" loading="lazy" '.$class.$alt.' '.ultimate_post_pro()->get_size($size).' src="'.ultimate_post_pro()->img_placeholder($size).'" data-src="'.$url.'"/>';
91 - }else{
92 - $class = $class ? ' class="'.$class.'" ' : '';
93 - return '<img loading="lazy" '.$class.$alt.' src="'.$url.'" />';
94 - }
95 - } else {
96 - $class = $class ? ' class="'.$class.'" ' : '';
97 - return '<img loading="lazy" '.$class.$alt.' src="'.$url.'" />';
98 - }
99 - }
100 400
101 - public function get_image($attach_id, $size = 'full', $class = '', $alt = ''){
102 - $alt = $alt ? ' alt="'.$alt.'" ' : '';
103 - if( function_exists('ultimate_post_pro') ){
104 - $addon_enable = ultimate_post()->get_setting();
105 - if(isset($addon_enable['addons_imageloading']) && $addon_enable['addons_imageloading'] == 'true'){
106 - $class = $class ? ' class="ultp-lazy '.$class.'" ' : ' class="ultp-lazy" ';
107 - return '<img loading="lazy" '.$class.$alt.' '.ultimate_post_pro()->get_size($size).' src="'.ultimate_post_pro()->img_placeholder($size).'" data-src="'.wp_get_attachment_image_url( $attach_id, $size ).'"/>';
108 - }else{
109 - $class = $class ? ' class="'.$class.'" ' : '';
110 - return '<img loading="lazy" '.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
111 - }
112 - } else {
113 - $class = $class ? ' class="'.$class.'" ' : '';
114 - return '<img loading="lazy" '.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
115 - }
116 - }
401 + /**
402 + * Set Option Settings
403 + *
404 + * @since v.1.0.0
405 + * @param STRING | $key of the Option (STRING) .
406 + * @param STRING | $val Value (STRING) .
407 + */
408 + public function set_setting( $key = '', $val = '' ) {
409 + if ( $key != '' ) {
410 + $data = $GLOBALS['ultp_settings'];
411 + $data[ $key ] = $val;
412 + update_option( 'ultp_options', $data );
413 + $GLOBALS['ultp_settings'] = $data;
414 + do_action( 'ultp_settings_updated', $key, $val );
415 + }
416 + }
117 417
118 - // Init data
119 - public function init_set_data(){
120 - $data = get_option( 'ultp_options', array() );
121 - $init_data = array(
122 - 'css_save_as' => 'wp_head',
123 - 'preloader_style' => 'style1',
124 - 'preloader_color' => '#1740f5',
125 - 'container_width' => '1140',
126 - 'editor_container' => 'full_width',
127 - 'hide_import_btn' => '',
128 - 'ultp_templates' => 'true',
129 - 'ultp_elementor' => 'true'
130 - );
131 - if (empty($data)) {
132 - update_option('ultp_options', $init_data);
133 - $GLOBALS['wopb_settings'] = $init_data;
134 - } else {
135 - foreach ($init_data as $key => $single) {
136 - if (!isset($data[$key])) {
137 - $data[$key] = $single;
138 - }
139 - }
140 - update_option('ultp_options', $data);
141 - $GLOBALS['wopb_settings'] = $data;
142 - }
143 - }
144 418
145 - // Excerpt
146 - public function excerpt( $post_id, $limit = 55 ) {
147 - return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
148 - }
419 + /**
420 + * Get Image HTML
421 + *
422 + * @since v.1.0.0
423 + * @param STRING | $url .
424 + * @param STRING | $size .
425 + * @param STRING | $class .
426 + * @param STRING | $alt .
427 + * @param STRING | $lazy .
428 + * @param ARRAY | $darkImg .
429 + * @param STRING | $srcset .
430 + * @return STRING
431 + */
432 + public function get_image_html( $url = '', $size = 'full', $class = '', $alt = '', $lazy = '', $darkImg = array(), $srcset = '' ) {
433 + $class = sanitize_html_class( $class );
434 + $alt = preg_replace( '/[^A-Za-z0-9_ -]/', '', $alt );
435 + $hasDarkImage = ( $darkImg['enable'] && $darkImg['url'] ) ? ' ultp-light-image-block ' : '';
436 + $alt = $alt ? ' alt="' . $alt . '" ' : '';
437 + $lazy_data = $lazy ? ' loading="lazy"' : '';
149 438
150 - // Query Builder
151 - public function get_query($attr) {
152 - $query_args = array(
153 - 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
154 - 'post_type' => isset($attr['queryType']) ? $attr['queryType'] : 'post',
155 - 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
156 - 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
157 - 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
158 - 'post_status' => 'publish'
159 - );
439 + $dlMode = isset( $_COOKIE['ultplocalDLMode'] ) ? $_COOKIE['ultplocalDLMode'] : ultimate_post()->get_dl_mode();
160 440
161 - if(isset($attr['queryOrderBy']) && isset($attr['metaKey'])){
162 - if($attr['queryOrderBy'] == 'meta_value_num') {
163 - $query_args['meta_key'] = $attr['metaKey'];
164 - }
165 - }
441 + $lightMode = $hasDarkImage ? ( $dlMode == 'ultplight' ? '' : 'inactive ' ) : '';
442 + $darkMode = $hasDarkImage ? ( $hasDarkImage && $dlMode == 'ultpdark' ? '' : ' inactive ' ) : '';
166 443
167 - if(isset($attr['queryInclude']) && $attr['queryInclude']){
168 - $query_args['post__in'] = explode(',', $attr['queryInclude']);
169 - $query_args['ignore_sticky_posts'] = 1;
170 - $query_args['orderby'] = 'post__in';
171 - }
444 + $image = '<img ' . $lazy_data . $srcset . ' class="' . $class . $hasDarkImage . $lightMode . '" ' . $alt . ' src="' . esc_url( $url ) . '" />';
445 + if ( $hasDarkImage ) {
446 + $image .= '<img ' . $lazy_data . $darkImg['srcset'] . ' class="' . $class . $darkMode . ' ultp-dark-image-block " ' . $alt . ' src="' . esc_url( $darkImg['url'] ) . '" />';
447 + }
448 + return $image;
449 + }
172 450
173 - if(isset($attr['queryExclude']) && $attr['queryExclude']){
174 - $query_args['post__not_in'] = explode(',', $attr['queryExclude']);
175 - }
176 451
177 - if(isset($attr['queryTax'])){
178 - if(isset($attr['queryCat'])){
179 - if($attr['queryTax'] == 'category' && !empty($attr['queryCat'])){
180 - $var = array('relation'=>'OR');
181 - foreach (json_decode($attr['queryCat']) as $val) {
182 - $var[] = array('taxonomy'=>'category', 'field' => 'slug', 'terms' => $val );
183 - }
184 - if(count($var) > 1){
185 - $query_args['tax_query'] = $var;
186 - }
187 - }
188 - }
189 - if(isset($attr['queryTag'])){
190 - if($attr['queryTax'] == 'post_tag' && !empty($attr['queryTag'])){
191 - $var = array('relation'=>'OR');
192 - foreach (json_decode($attr['queryTag']) as $val) {
193 - $var[] = array('taxonomy'=>'post_tag', 'field' => 'slug', 'terms' => $val );
194 - }
195 - $query_args['tax_query'] = $var;
196 - }
197 - }
198 - }
452 + /**
453 + * Get Image HTML
454 + *
455 + * @since v.1.0.0
456 + * @param STRING | $attach_id .
457 + * @param STRING | $size .
458 + * @param STRING | $class .
459 + * @param STRING | $alt .
460 + * @param STRING | $srcset .
461 + * @param STRING | $lazy .
462 + * @return STRING
463 + */
464 + public function get_image( $attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = '' ) {
465 + $img_alt = get_post_meta( $attach_id, '_wp_attachment_image_alt', true );
466 + $alt = $img_alt ? $img_alt : $alt;
467 + $alt = $alt ? ' alt="' . esc_html( $alt ) . '" ' : '';
468 + $class = $class ? ' class="' . $class . '" ' : '';
469 + $size = ( ultimate_post()->get_setting( 'disable_image_size' ) == 'yes' && strpos( $size, 'ultp_layout_' ) !== false ) ? 'full' : $size;
470 + $lazy_data = $lazy ? ' loading="lazy"' : '';
471 + $srcset_data = $srcset ? ' srcset="' . esc_attr( wp_get_attachment_image_srcset( $attach_id ) ) . '"' : '';
472 + return '<img ' . $srcset_data . $lazy_data . $class . $alt . ' src="' . wp_get_attachment_image_url( $attach_id, $size ) . '" />';
473 + }
199 474
200 - if(isset($attr['queryQuick'])){
201 - if($attr['queryQuick'] != ''){
202 - if(function_exists('ultimate_post_pro')){
203 - $query_args = ultimate_post_pro()->get_quick_query($attr, $query_args);
204 - }
205 - }
206 - }
207 475
208 - if(isset($attr['queryOffset']) && $attr['queryOffset'] ){
209 - if($query_args['paged'] > 1){
210 - $offset_post = wp_get_recent_posts($query_args, OBJECT);
211 - if( count($offset_post) > 0 ){
212 - $offset = array();
213 - for($x = count($offset_post); $x > count($offset_post) - $attr['queryOffset']; $x--){
214 - $offset[] = $offset_post[$x-1]->ID;
215 - }
216 - $query_args['post__not_in'] = $offset;
217 - }
218 - }else{
219 - $query_args['offset'] = isset($attr['queryOffset']) ? $attr['queryOffset'] : 0;
220 - }
221 - }
476 + /**
477 + * Get Excerpt Text
478 + *
479 + * @since v.1.0.0
480 + * @param STRING | $post_id .
481 + * @param NUMBER | $limit .
482 + * @return STRING
483 + */
484 + public function excerpt( $post_id, $limit = 55 ) {
485 + $content = preg_replace( '/(\[postx_template[\s\w="]*)]/m', '', get_the_excerpt( $post_id ) ); // Remove postx_template shortcode form Content
486 + return apply_filters( 'the_excerpt', wp_trim_words( $content, $limit ) );
487 + }
222 488
223 - $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
224 -
225 - return $query_args;
226 - }
489 + /**
490 + * Builder Attributes
491 + *
492 + * @since v.1.0.0
493 + * @param STRING | $type .
494 + * @return STRING
495 + */
496 + public function get_builder_attr( $type ) {
497 + $builder_data = '';
498 + if ( $type == 'archiveBuilder' || $type == 'archiveBuilderFilter' ) {
499 + if ( is_archive() ) {
500 + if ( is_date() ) {
501 + if ( is_year() ) {
502 + $builder_data = 'date###' . get_the_date( 'Y' );
503 + } elseif ( is_month() ) {
504 + $builder_data = 'date###' . get_the_date( 'Y-n' );
505 + } elseif ( is_day() ) {
506 + $builder_data = 'date###' . get_the_date( 'Y-n-j' );
507 + }
508 + } elseif ( is_author() ) {
509 + $builder_data = 'author###' . get_the_author_meta( 'ID' );
510 + } else {
511 + $obj = get_queried_object();
512 + if ( isset( $obj->taxonomy ) ) {
513 + $builder_data = 'taxonomy###' . $obj->taxonomy . '###' . $obj->slug;
514 + }
515 + }
516 + } elseif ( is_search() ) {
517 + $builder_data = 'search###' . get_search_query( true );
518 + }
519 + }
520 + if ( $type == 'archiveBuilderFilter' ) {
521 + return $builder_data ? $builder_data : '';
522 + }
523 + return $builder_data ? 'data-builder="' . $builder_data . '"' : '';
524 + }
227 525
228 526
229 - public function get_page_number($attr, $post_number) {
230 - if($post_number > 0){
231 - $post_per_page = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
232 - $pages = ceil($post_number/$post_per_page);
233 - return $pages ? $pages : 1;
234 - }else{
235 - return 1;
236 - }
237 - }
527 + /**
528 + * Determines if the builder is enabled based on the plugin settings.
529 + *
530 + * @param STRING $builder Optional. The builder name (currently unused).
531 + * @return BOOL True if the builder is enabled, false otherwise.
532 + */
533 + public function is_builder( $builder = '' ) {
534 + $id = '';
535 + if ( ultimate_post()->get_setting( 'ultp_builder' ) != 'false' ) {
536 + $page_id = ultimate_post()->builder_check_conditions( 'return_ib' );
537 + if ( $page_id ) {
538 + $id = $page_id;
539 + }
540 + }
541 + return $id;
542 + }
238 543
239 - public function get_image_size() {
240 - $sizes = get_intermediate_image_sizes();
241 - $filter = array('full' => 'Full');
242 - foreach ($sizes as $value) {
243 - $filter[$value] = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
244 - }
245 - return $filter;
246 - }
247 544
545 + /**
546 + * Get Post Number Depending On Device
547 + *
548 + * @since v.2.5.4
549 + * @param MIXED | $preDef .
550 + * @param MIXED | $prev .
551 + * @param MIXED | $current .
552 + * @return STRING
553 + */
554 + public function get_post_number( $preDef, $prev, $current ) {
248 555
249 - public function get_post_type() {
250 - $post_type = get_post_types( '', 'names' );
251 - return array_diff($post_type, array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block' ));
252 - }
556 + $current = is_object( $current ) ? json_decode( wp_json_encode( $current ), true ) : $current;
557 + if ( array(
558 + 'lg' => $preDef,
559 + 'sm' => $preDef,
560 + 'xs' => $preDef,
561 + ) == $current ) {
562 + if ( $preDef != $prev ) {
563 + return $prev;
564 + }
565 + }
253 566
567 + $lg = isset( $current['lg'] ) ? $current['lg'] : $prev;
568 + $sm = isset( $current['sm'] ) ? $current['sm'] : $lg;
569 + $xs = isset( $current['xs'] ) ? $current['xs'] : $lg;
570 + if ( $lg == $sm && $sm == $xs ) {
571 + return $lg;
572 + } else {
573 + global $ultpDevide;
574 + $currentDevice = ! empty( $ultpDevide ) ? $ultpDevide : $this->isDevice();
575 + if ( $currentDevice == 'mobile' ) {
576 + return $xs;
577 + } elseif ( $currentDevice == 'tablet' ) {
578 + return $sm;
579 + } else {
580 + return $lg;
581 + }
582 + }
583 + }
254 584
255 - // Pagination
256 - public function pagination($pages = '', $paginationNav, $range = 1) {
257 - $html = '';
258 - $showitems = 3;
259 - $paged = get_query_var('paged') ? get_query_var('paged') : 1;
260 - if($pages == '') {
261 - global $wp_query;
262 - $pages = $wp_query->max_num_pages;
263 - if(!$pages) {
264 - $pages = 1;
265 - }
266 - }
267 - $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
268 585
269 -
270 - if(1 != $pages) {
271 - $html .= '<ul class="ultp-pagination">';
272 - $display_none = 'style="display:none"';
273 - if($pages > 4) {
274 - $html .= '<li class="ultp-prev-page-numbers" '.($paged==1?$display_none:"").'><a href="'.get_pagenum_link($paged-1).'">'.ultimate_post()->svg_icon('leftAngle2').' '.($paginationNav == 'textArrow'?__("Previous", "ultimate-post"):"").'</a></li>';
275 - }
276 - if($pages > 4){
277 - $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
278 - }
279 - if($pages > 4){
280 - $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
281 - }
282 - foreach ($data as $i) {
283 - if($pages >= $i){
284 - $html .= ($paged == $i) ? '<li class="ultp-center-item pagination-active" data-current="'.$i.'"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>':'<li class="ultp-center-item" data-current="'.$i.'"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
285 - }
286 - }
287 - if($pages > 4){
288 - $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
289 - }
290 - if($pages > 4){
291 - $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
292 - }
293 - if ($paged != $pages) {
294 - $html .= '<li class="ultp-next-page-numbers"><a href="'.get_pagenum_link($paged + 1).'">'.($paginationNav == 'textArrow' ? __("Next", "ultimate-post") : "").ultimate_post()->svg_icon('rightAngle2').'</a></li>';
295 - }
296 - $html .= '</ul>';
297 - }
298 - return $html;
299 - }
586 + /**
587 + * Get Post Number Depending On Device
588 + *
589 + * @since v.2.5.4
590 + * @return STRING | Device Type
591 + */
592 + public function isDevice() {
593 + $useragent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_key( $_SERVER['HTTP_USER_AGENT'] ) : '';
594 + $device = 'desktop';
595 + if ( $useragent ) {
596 + if ( preg_match( '/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower( $useragent ) ) ) {
597 + $device = 'tablet';
598 + } elseif ( preg_match( '/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i', $useragent ) || preg_match( '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr( $useragent, 0, 4 ) ) ) {
599 + $device = 'mobile';
600 + }
601 + }
602 + global $ultpDevide;
603 + $ultpDevide = $device;
604 + return $device;
605 + }
300 606
301 - public function excerpt_word($charlength = 200) {
302 - $html = '';
303 - $charlength++;
304 - $excerpt = get_the_excerpt();
305 - if ( mb_strlen( $excerpt ) > $charlength ) {
306 - $subex = mb_substr( $excerpt, 0, $charlength - 5 );
307 - $exwords = explode( ' ', $subex );
308 - $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
309 - if ( $excut < 0 ) {
310 - $html = mb_substr( $subex, 0, $excut );
311 - } else {
312 - $html = $subex;
313 - }
314 - $html .= '...';
315 - } else {
316 - $html = $excerpt;
317 - }
318 - return $html;
319 - }
320 607
608 + /**
609 + * Get Raw Value from Objects
610 + *
611 + * @since v.2.5.3
612 + * @param ARRAY | $attr .
613 + * @return STRING | Device Type
614 + */
615 + public function get_value( $attr ) {
616 + $data = array();
617 + if ( is_array( $attr ) ) {
618 + foreach ( $attr as $val ) {
619 + $data[] = $val->value;
620 + }
621 + }
622 + return $data;
623 + }
321 624
322 - public function taxonomy( $prams = 'category' ) {
323 - $data = array();
324 - $terms = get_terms( $prams, array(
325 - 'hide_empty' => true,
326 - ));
327 - if( !empty($terms) ){
328 - foreach ($terms as $val) {
329 - $data[$val->slug] = $val->name;
330 - }
331 - }
332 - return $data;
333 - }
625 + /**
626 + * QueryArgs for Filter
627 + *
628 + * @since v.2.8.9
629 + * @param ARRAY | $attr .
630 + * @return ARRAY
631 + */
632 + public function getFilterQueryArgs( $attr ) {
633 + $tax_value = ( strlen( $attr['queryTaxValue'] ) > 2 ) ? $attr['queryTaxValue'] : array();
634 + $tax_value = is_array( $tax_value ) ? $tax_value : json_decode( $tax_value );
334 635
636 + $tax_value = ( isset( $tax_value[0] ) && is_object( $tax_value[0] ) ) ? $this->get_value( $tax_value ) : $tax_value;
335 637
336 - public function next_prev() {
337 - $html = '';
338 - $html .= '<ul>';
339 - $html .= '<li>';
340 - $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
341 - $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
342 - $html .= '</a>';
343 - $html .= '</li>';
344 - $html .= '<li>';
345 - $html .= '<a class="ultp-next-action">';
346 - $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
347 - $html .= '</a>';
348 - $html .= '</li>';
349 - $html .= '</ul>';
350 - return $html;
351 - }
638 + if ( is_array( $tax_value ) && count( $tax_value ) > 0 ) {
639 + $relation = isset( $attr['queryRelation'] ) ? $attr['queryRelation'] : 'OR';
352 640
353 - public function loading(){
354 - $html = '';
355 - $style = 'style1';
356 - $option_data = ultimate_post()->get_setting();
357 - if( isset($option_data['preloader_style']) ){
358 - $style = $option_data['preloader_style'];
359 - }
360 - if( $style == 'style2' ){
361 - $html .= '<div class="ultp-loading-spinner" style="width:100%;height:100%"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>';//ultp-block-items-wrap
362 - } else {
363 - $html .= '<div class="ultp-loading-blocks" style="width:100%;height:100%;"><div style="left: 0;top: 0;animation-delay:0s;"></div><div style="left: 21px;top: 0;animation-delay:0.125s;"></div><div style="left: 42px;top: 0;animation-delay:0.25s;"></div><div style="left: 0;top: 21px;animation-delay:0.875s;"></div><div style="left: 42px;top: 21px;animation-delay:0.375s;"></div><div style="left: 0;top: 42px;animation-delay:0.75s;"></div><div style="left: 42px;top: 42px;animation-delay:0.625s;"></div><div style="left: 21px;top: 42px;animation-delay:0.5s;"></div></div>';
364 - }
365 - return '<div class="ultp-loading">'.$html.'</div>';
366 - }
641 + // Adv Filter Query Relation Override
642 + if ( isset( $attr['advFilterEnable'] ) && $attr['advFilterEnable'] === true && isset( $attr['advRelation'] ) ) {
643 + $relation = 'AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'] ? $attr['advRelation'] : $relation;
644 + }
367 645
368 - public function filter($filterText = '', $filterType = '', $filterCat = '[]', $filterTag = '[]'){
369 - $html = '';
370 - $html .= '<ul class="ultp-flex-menu">';
371 - if ($filterType == 'category') {
372 - $cat = $this->taxonomy('category');
373 - if($filterText){
374 - $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
375 - }
376 - foreach (json_decode($filterCat) as $val) {
377 - $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
378 - }
379 - } else {
380 - $tag = $this->taxonomy('post_tag');
381 - if($filterText){
382 - $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
383 - }
384 - foreach (json_decode($filterTag) as $val) {
385 - $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($tag[$val]) ? $tag[$val] : $val).'</a></li>';
386 - }
387 - }
388 - $html .= '</ul>';
389 - return $html;
390 - }
646 + $var = array( 'relation' => $relation );
647 + foreach ( $tax_value as $val ) {
648 + $tax_name = $attr['queryTax'];
649 + // For Custom Terms
650 + if ( $attr['queryTax'] == 'multiTaxonomy' ) {
651 + $temp = explode( '###', $val );
652 + if ( isset( $temp[1] ) ) {
391 653
392 - public function svg_icon($icons = ''){
654 + if ( $temp[1] === '_all' ) {
655 + continue;
656 + }
393 657
394 - $icon_lists = array(
395 - 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
396 - 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
397 - 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
398 - 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
399 - 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
400 - 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
401 - 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
402 - 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
403 - 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
404 - 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
405 - 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
406 - 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
407 - 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
408 - 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
409 - );
410 - if($icons){
411 - return $icon_lists[ $icons ];
412 - }
413 - }
414 -
658 + $val = $temp[1];
659 + $tax_name = $temp[0];
660 + }
661 + }
662 + $var[] = array(
663 + 'taxonomy' => $tax_name,
664 + 'field' => 'slug',
665 + 'terms' => $val,
666 + );
667 + }
668 + }
669 + return isset( $var ) ? $var : array();
670 + }
671 +
672 + /**
673 + * Query Builder
674 + *
675 + * @since v.1.0.0
676 + * @param ARRAY | $attr .
677 + * @return ARRAY
678 + */
679 + public function get_query( $attr ) {
680 + $builder = isset( $attr['builder'] ) ? $attr['builder'] : '';
681 + $post_type = isset( $attr['queryType'] ) ? $attr['queryType'] : 'post';
682 + $get_post_type = isset( $attr['queryPostType'] ) ? $attr['queryPostType'] : '';
683 + if ( $post_type != 'archiveBuilder' && ! empty( $get_post_type ) && $post_type == 'customPostType' ) {
684 + $post_type = $get_post_type;
685 + }
686 +
687 + if ( $post_type == 'archiveBuilder' && ( $builder || $this->is_builder( $builder ) ) ) {
688 + $archive_query = array();
689 + if ( $builder ) {
690 + $str = explode( '###', $builder );
691 + if ( isset( $str[0] ) ) {
692 + if ( $str[0] == 'taxonomy' ) {
693 + if ( isset( $str[1] ) && isset( $str[2] ) ) {
694 + $archive_query['tax_query'] = array(
695 + array(
696 + 'taxonomy' => $str[1],
697 + 'field' => 'slug',
698 + 'terms' => $str[2],
699 + ),
700 + );
701 + }
702 + } elseif ( $str[0] == 'author' ) {
703 + if ( isset( $str[1] ) ) {
704 + $archive_query['author'] = $str[1];
705 + }
706 + } elseif ( $str[0] == 'search' ) {
707 + if ( isset( $str[1] ) ) {
708 + $archive_query['s'] = $str[1];
709 + }
710 + } elseif ( $str[0] == 'date' ) {
711 + if ( isset( $str[1] ) ) {
712 + $all_date = explode( '-', $str[1] );
713 + if ( ! empty( $all_date ) ) {
714 + $arg = array();
715 + if ( isset( $all_date[0] ) ) {
716 + $arg['year'] = $all_date[0];
717 + }
718 + if ( isset( $all_date[1] ) ) {
719 + $arg['month'] = $all_date[1];
720 + }
721 + if ( isset( $all_date[2] ) ) {
722 + $arg['day'] = $all_date[2];
723 + }
724 + $archive_query['date_query'][] = $arg;
725 + }
726 + }
727 + }
728 + }
729 + } else {
730 + global $wp_query;
731 + $archive_query = $wp_query->query_vars;
732 + }
733 + $archive_query['posts_per_page'] = isset( $attr['queryNumber'] ) ? $attr['queryNumber'] : 1;
734 + $archive_query['paged'] = isset( $attr['paged'] ) ? $attr['paged'] : 1;
735 +
736 + $archive_query['paged'] = ! wp_doing_ajax() && isset( $_GET[ $attr['blockId'] . '_page' ] ) && is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
737 + intval( $_GET[ $attr['blockId'] . '_page' ] ) :
738 + $archive_query['paged'];
739 +
740 + if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
741 + $offset = $this->get_offset( $attr['queryOffset'], $archive_query );
742 + $archive_query = array_merge( $archive_query, $offset );
743 + }
744 +
745 + // Include Remove from Version 2.5.4
746 + if ( isset( $attr['queryInclude'] ) && $attr['queryInclude'] ) {
747 + $_include = explode( ',', $attr['queryInclude'] );
748 + if ( is_array( $_include ) && count( $_include ) ) {
749 + $archive_query['post__in'] = isset( $archive_query['post__in'] ) ? array_merge( $archive_query['post__in'], $_include ) : $_include;
750 + $archive_query['ignore_sticky_posts'] = 1;
751 + $archive_query['orderby'] = 'post__in';
752 + }
753 + }
754 +
755 + if ( isset( $attr['queryExclude'] ) && $attr['queryExclude'] ) {
756 + $_exclude = ( substr( $attr['queryExclude'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryExclude'] ) ) : explode( ',', $attr['queryExclude'] );
757 + if ( is_array( $_exclude ) && count( $_exclude ) ) {
758 + $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $_exclude ) : $_exclude;
759 + }
760 + }
761 +
762 + if ( isset( $attr['querySticky'] ) && $attr['querySticky'] ) {
763 + if ( filter_var( $attr['querySticky'], FILTER_VALIDATE_BOOLEAN ) ) {
764 + $sticky = get_option( 'sticky_posts', array() );
765 + $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $sticky ) : $sticky;
766 + }
767 + }
768 + // ===============
769 + if ( isset( $attr['queryUnique'] ) && $attr['queryUnique'] ) {
770 + global $unique_ID;
771 + if ( isset( $unique_ID[ $attr['queryUnique'] ] ) ) {
772 + $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $unique_ID[ $attr['queryUnique'] ] ) : $unique_ID[ $attr['queryUnique'] ];
773 + }
774 + }
775 + // ===============
776 +
777 + $archive_query['post_status'] = 'publish';
778 + if ( is_user_logged_in() ) {
779 + if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) {
780 + $archive_query['post_status'] = array( 'publish', 'private' );
781 + }
782 + }
783 + // queryOrder
784 + if ( ! isset( $archive_query['orderby'] ) ) {
785 + $archive_query['orderby'] = isset( $attr['queryOrderBy'] ) ? $attr['queryOrderBy'] : 'date';
786 + }
787 + if ( ! isset( $archive_query['queryOrder'] ) ) {
788 + $archive_query['order'] = isset( $attr['queryOrder'] ) ? $attr['queryOrder'] : 'ASC';
789 + }
790 +
791 + // Quick Query Support for Builder
792 + if ( isset( $attr['queryQuick'] ) ) {
793 + if ( $attr['queryQuick'] != '' ) {
794 + $archive_query = ultimate_post()->get_quick_query( $attr, $archive_query );
795 + }
796 + }
797 +
798 + if ( ! isset( $attr['ajaxCall'] ) ) {
799 + if ( isset( $attr['filterShow'] ) && $attr['filterShow'] && $attr['filterShow'] != 'false' ) {
800 + if ( isset( $attr['filterType'] ) && isset( $attr['filterValue'] ) ) {
801 + $filterValue = strlen( $attr['filterValue'] ) > 2 ? $attr['filterValue'] : array();
802 + $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
803 + if ( count( $filterValue ) > 0 && $attr['filterType'] ) {
804 + $final = array( 'relation' => 'OR' );
805 + foreach ( $filterValue as $key => $val ) {
806 + $final[] = array(
807 + 'taxonomy' => $attr['filterType'],
808 + 'field' => 'slug',
809 + 'terms' => $val,
810 + );
811 + }
812 + $archive_query['tax_query'] = $final;
813 + }
814 + }
815 + }
816 + }
817 + // from v.3.0.7 - for search builder
818 + if ( is_search() ) {
819 + $archive_query['orderby'] = 'relevance';
820 + if ( isset( $_GET['ultp_exclude'] ) ) { // Added support for search block exclude
821 + $ultp_exclude = json_decode( stripslashes( $_GET['ultp_exclude'] ), true );
822 + if ( is_array( $ultp_exclude ) ) {
823 + $all_types = get_post_types( array( 'public' => true ), 'names' );
824 + $post_type = array_diff( $all_types, $ultp_exclude );
825 + $archive_query['post_type'] = $post_type;
826 + }
827 + }
828 + }
829 +
830 + return apply_filters( 'ultp_archive_query', $archive_query );
831 + }
832 +
833 + // When you use load more pagination block for a grid that did not have load more feature,
834 + // the incoming posts would not align properly with the blocks design and looked bad.
835 + // This fixes that.
836 + if (
837 + isset( $attr['paginationType'] ) &&
838 + isset( $attr['queryNumber2'] ) &&
839 + isset( $attr['notFirstLoad'] ) &&
840 + $attr['paginationType'] === 'loadMore' &&
841 + $attr['notFirstLoad']
842 + ) {
843 + $query_number = $attr['queryNumber2'];
844 + // $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
845 + } else {
846 + $query_number = isset( $attr['queryNumber'] ) ? $attr['queryNumber'] : 3;
847 + }
848 +
849 + $paged = isset( $attr['paged'] ) ? $attr['paged'] : 1;
850 + $paged = ! wp_doing_ajax() &&
851 + isset( $attr['blockId'] ) &&
852 + isset( $_GET[ $attr['blockId'] . '_page' ] ) &&
853 + is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
854 + intval( $_GET[ $attr['blockId'] . '_page' ] ) :
855 + $paged;
856 +
857 + $query_args = array(
858 + 'posts_per_page' => $query_number,
859 + 'post_type' => is_array( $post_type ) && ! empty( $post_type ) ? $post_type : ( 'archiveBuilder' == $post_type ? 'post' : ( is_string( $post_type ) ? is_array( json_decode( $post_type ) ) ? json_decode( $post_type ) : $post_type : $post_type ) ),
860 + 'orderby' => isset( $attr['queryOrderBy'] ) ? $attr['queryOrderBy'] : 'date',
861 + 'order' => isset( $attr['queryOrder'] ) ? $attr['queryOrder'] : 'desc',
862 + 'paged' => $paged,
863 + 'post_status' => 'publish',
864 + );
865 +
866 + // For Private Post 'private'.
867 + if ( is_user_logged_in() ) {
868 + if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) {
869 + $query_args['post_status'] = array( 'publish', 'private' );
870 + }
871 + }
872 +
873 + if ( $attr['queryType'] == 'posts' ) {
874 + if ( isset( $attr['queryPosts'] ) && $attr['queryPosts'] ) {
875 + unset( $query_args['post_type'] );
876 + $data = json_decode( isset( $attr['queryPosts'] ) ? $attr['queryPosts'] : '[]' );
877 + $final = $this->get_value( $data );
878 + if ( count( $final ) > 0 ) {
879 + $query_args['post__in'] = $final;
880 + // $query_args['posts_per_page'] = -1;
881 + }
882 + $query_args['ignore_sticky_posts'] = 1;
883 + return $query_args;
884 + }
885 + } elseif ( $attr['queryType'] == 'customPosts' ) {
886 + if ( isset( $attr['queryCustomPosts'] ) && $attr['queryCustomPosts'] ) {
887 + $query_args['post_type'] = $this->get_post_type();
888 + $data = json_decode( isset( $attr['queryCustomPosts'] ) ? $attr['queryCustomPosts'] : '[]' );
889 + $final = $this->get_value( $data );
890 + if ( count( $final ) > 0 ) {
891 + $query_args['post__in'] = $final;
892 + // $query_args['posts_per_page'] = -1;
893 + }
894 + $query_args['ignore_sticky_posts'] = 1;
895 + return $query_args;
896 + }
897 + }
898 +
899 + if ( isset( $attr['queryExcludeAuthor'] ) && $attr['queryExcludeAuthor'] ) {
900 + $data = json_decode( isset( $attr['queryExcludeAuthor'] ) ? $attr['queryExcludeAuthor'] : '[]' );
901 + $final = $this->get_value( $data );
902 + if ( count( $final ) > 0 ) {
903 + $query_args['author__not_in'] = $final;
904 + }
905 + }
906 +
907 + if ( isset( $attr['queryOrderBy'] ) && isset( $attr['metaKey'] ) ) {
908 + if ( $attr['queryOrderBy'] == 'meta_value_num' ) {
909 + $query_args['meta_key'] = $attr['metaKey'];
910 + }
911 + }
912 +
913 + // Include Remove from Version 2.5.4.
914 + if ( isset( $attr['queryInclude'] ) && $attr['queryInclude'] ) {
915 + $_include = explode( ',', $attr['queryInclude'] );
916 + if ( is_array( $_include ) && count( $_include ) ) {
917 + $query_args['post__in'] = isset( $query_args['post__in'] ) ? array_merge( $query_args['post__in'], $_include ) : $_include;
918 + $query_args['ignore_sticky_posts'] = 1;
919 + $query_args['orderby'] = 'post__in';
920 + }
921 + }
922 +
923 + if ( isset( $attr['queryTax'] ) ) {
924 + if ( isset( $attr['queryTaxValue'] ) ) {
925 + $var = $this->getFilterQueryArgs( $attr );
926 + if ( isset( $var ) && count( $var ) > 1 ) {
927 + $query_args['tax_query'] = $var;
928 + }
929 + }
930 + }
931 +
932 + if ( isset( $attr['queryExcludeTerm'] ) && $attr['queryExcludeTerm'] ) {
933 + $temp = json_decode( $attr['queryExcludeTerm'] );
934 + $_term = array();
935 + foreach ( $temp as $val ) {
936 + $temp = explode( '###', $val->value );
937 + if ( isset( $temp[1] ) ) {
938 + if ( is_array( $_term ) && array_key_exists( $temp[0], $_term ) ) {
939 + $_term[ $temp[0] ][] = $temp[1];
940 + } else {
941 + $_term[ $temp[0] ] = array( $temp[1] );
942 + }
943 + }
944 + }
945 + if ( count( $_term ) > 0 ) {
946 + $final = array( 'relation' => 'AND' );
947 + foreach ( $_term as $key => $val ) {
948 + $final[] = array(
949 + 'taxonomy' => $key,
950 + 'field' => 'slug',
951 + 'terms' => $val,
952 + 'operator' => 'NOT IN',
953 + );
954 + }
955 +
956 + if ( is_array( $query_args ) && array_key_exists( 'tax_query', $query_args ) ) {
957 + $query_args['tax_query'] = array(
958 + 'relation' => 'AND',
959 + $query_args['tax_query'],
960 + );
961 + $query_args['tax_query'][] = $final;
962 + } else {
963 + $query_args['tax_query'] = $final;
964 + }
965 + }
966 + }
967 +
968 + if ( isset( $attr['queryExclude'] ) && $attr['queryExclude'] ) {
969 + $_exclude = ( substr( $attr['queryExclude'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryExclude'] ) ) : explode( ',', $attr['queryExclude'] );
970 + if ( is_array( $_exclude ) && count( $_exclude ) ) {
971 + $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $_exclude ) : $_exclude;
972 + }
973 + }
974 +
975 + if ( isset( $attr['queryUnique'] ) && $attr['queryUnique'] ) {
976 + global $unique_ID;
977 + if ( isset( $unique_ID[ $attr['queryUnique'] ] ) ) {
978 + $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $unique_ID[ $attr['queryUnique'] ] ) : $unique_ID[ $attr['queryUnique'] ];
979 + }
980 + }
981 + // exclude current post from Post blocks // v.2.9.6.
982 + if ( is_single() && get_the_ID() ) {
983 + $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], array( get_the_ID() ) ) : array( get_the_ID() );
984 + }
985 +
986 + if ( isset( $attr['queryQuick'] ) ) {
987 + if ( $attr['queryQuick'] != '' && $post_type != 'archiveBuilder' ) {
988 + $query_args = ultimate_post()->get_quick_query( $attr, $query_args );
989 + }
990 + }
991 +
992 + if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
993 + $offset = $this->get_offset( $attr['queryOffset'], $query_args );
994 + $query_args = array_merge( $query_args, $offset );
995 + }
996 +
997 + if ( isset( $attr['queryAuthor'] ) && $attr['queryAuthor'] ) {
998 + $_include = ( substr( $attr['queryAuthor'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryAuthor'] ) ) : explode( ',', $attr['queryAuthor'] );
999 + if ( is_array( $_include ) && count( $_include ) ) {
1000 + $query_args['author__in'] = $_include;
1001 + }
1002 + }
1003 +
1004 + if ( isset( $attr['querySearch'] ) && $attr['querySearch'] ) {
1005 + $query_args['s'] = $attr['querySearch'];
1006 + }
1007 +
1008 + if ( isset( $attr['querySticky'] ) && $attr['querySticky'] ) {
1009 + if ( filter_var( $attr['querySticky'], FILTER_VALIDATE_BOOLEAN ) ) {
1010 + $sticky = get_option( 'sticky_posts', array() );
1011 + $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $sticky ) : $sticky;
1012 + }
1013 + }
1014 +
1015 + if ( ! isset( $attr['ajaxCall'] ) ) {
1016 + if ( isset( $attr['filterShow'] ) && $attr['filterShow'] && $attr['filterShow'] != 'false' ) {
1017 + if ( isset( $attr['checkFilter'] ) && isset( $attr['queryTax'] ) && isset( $attr['queryTaxValue'] ) ) {
1018 + $var = $this->getFilterQueryArgs( $attr );
1019 + if ( isset( $var ) && count( $var ) > 1 ) {
1020 + $query_args['tax_query'] = $var;
1021 + }
1022 + } elseif ( isset( $attr['filterType'] ) && isset( $attr['filterValue'] ) ) {
1023 + $filterValue = strlen( $attr['filterValue'] ) > 2 ? $attr['filterValue'] : array();
1024 + $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
1025 + if ( is_array( $filterValue ) && count( $filterValue ) > 0 && $attr['filterType'] ) {
1026 + $final = array( 'relation' => 'OR' );
1027 + foreach ( $filterValue as $key => $val ) {
1028 + $final[] = array(
1029 + 'taxonomy' => $attr['filterType'],
1030 + 'field' => 'slug',
1031 + 'terms' => $val,
1032 + // 'operator' => '=',
1033 + );
1034 + }
1035 + $query_args['tax_query'] = $final;
1036 + }
1037 + }
1038 + }
1039 + }
1040 +
1041 + // Advanced Filter Select Dropdown Default value.
1042 + // only on initial page load.
1043 + if (
1044 + ! wp_doing_ajax() &&
1045 + isset( $attr['advFilterEnable'] ) &&
1046 + $attr['advFilterEnable'] === true &&
1047 + isset( $attr['defQueryTax'] ) &&
1048 + count( $attr['defQueryTax'] ) > 0
1049 + ) {
1050 + $tax_query = array(
1051 + 'relation' =>
1052 + isset( $attr['advRelation'] ) &&
1053 + ( 'AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'] )
1054 + ? $attr['advRelation'] : 'AND',
1055 + );
1056 + $is_valid = false;
1057 +
1058 + foreach ( $attr['defQueryTax'] as $_ => $defQueryTaxValue ) {
1059 + $term = explode( '###', $defQueryTaxValue );
1060 +
1061 + // Validation
1062 + if (
1063 + ! in_array( $term[0], array( 'category', 'tags', 'author', 'custom_tax' ), true ) ||
1064 + '_all' === $term[1] ||
1065 + empty( $term[1] )
1066 + ) {
1067 + continue;
1068 + }
1069 +
1070 + if ( 'author' === $term[0] ) {
1071 +
1072 + if ( ! is_numeric( $term[1] ) ) {
1073 + continue;
1074 + }
1075 +
1076 + $query_args['author__in'] = $term[1];
1077 + } elseif ( 'custom_tax' === $term[0] && isset( $attr['queryType'] ) ) {
1078 + $post_type = sanitize_key( $attr['queryType'] );
1079 + $slug = sanitize_key( $term[1] );
1080 +
1081 + // These are not custom post type.
1082 + if ( in_array( $post_type, array( 'posts', 'customPosts' ), true ) ) {
1083 + continue;
1084 + }
1085 +
1086 + $taxonomy = $this->get_taxonomy_by_term_slug( $post_type, $slug );
1087 +
1088 + if ( ! empty( $taxonomy ) ) {
1089 + $q = array(
1090 + 'field' => 'slug',
1091 + 'taxonomy' => $taxonomy,
1092 + 'terms' => $slug,
1093 + );
1094 +
1095 + $tax_query[] = $q;
1096 + $is_valid = true;
1097 + }
1098 + } else {
1099 + if ( ! is_numeric( $term[1] ) ) {
1100 + continue;
1101 + }
1102 +
1103 + $q = array(
1104 + 'field' => 'term_id',
1105 + 'taxonomy' => 'tags' === $term[0] ? 'post_tag' : 'category',
1106 + 'terms' => $term[1],
1107 + );
1108 +
1109 + $tax_query[] = $q;
1110 + $is_valid = true;
1111 + }
1112 + }
1113 +
1114 + if ( $is_valid ) {
1115 + $query_args['tax_query'] = $tax_query;
1116 + }
1117 + }
1118 + // $query_args['test'] = is_array( $post_type ) && ! empty( $post_type ) ? $post_type : ( 'archiveBuilder' === $post_type ? 'post' : ( is_string( $post_type ) ? json_decode( $post_type ) : $post_type ) );
1119 + $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
1120 +
1121 + return apply_filters( 'ultp_frontend_query', $query_args );
1122 + }
1123 +
1124 + /**
1125 + * Get Page Offset
1126 + *
1127 + * @since v.1.0.0
1128 + * @param NUMBER | $queryOffset Offset .
1129 + * @param ARRAY | $query_args Query .
1130 + * @return ARRAY
1131 + */
1132 + function get_offset( $queryOffset, $query_args ) {
1133 + $query = array();
1134 + if ( $query_args['paged'] > 1 ) {
1135 + $offset_post = wp_get_recent_posts( $query_args, OBJECT );
1136 + if ( count( $offset_post ) > 0 ) {
1137 + $offset = array();
1138 + for ( $x = count( $offset_post ); $x > count( $offset_post ) - $queryOffset; $x-- ) {
1139 + $offset[] = $offset_post[ $x - 1 ]->ID;
1140 + }
1141 + $query['post__not_in'] = $offset;
1142 + }
1143 + } else {
1144 + $query['offset'] = isset( $queryOffset ) ? $queryOffset : 0;
1145 + }
1146 + return $query;
1147 + }
1148 +
1149 +
1150 + /**
1151 + * Get Page Number
1152 + *
1153 + * @since v.1.0.0
1154 + * @param array $attr Attribute of the Query.
1155 + * @param int $post_number Post Number.
1156 + * @return ARRAY
1157 + */
1158 + public function get_page_number( $attr, $post_number ) {
1159 + if ( $post_number > 0 ) {
1160 + if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
1161 + $post_number = $post_number - (int) $attr['queryOffset'];
1162 + }
1163 + $post_per_page = isset( $attr['queryNumber'] ) ? ( $attr['queryNumber'] ? $attr['queryNumber'] : 1 ) : 3;
1164 + $pages = ceil( $post_number / $post_per_page );
1165 + return $pages ? $pages : 1;
1166 + } else {
1167 + return 1;
1168 + }
1169 + }
1170 +
1171 +
1172 + /**
1173 + * Get Image Size
1174 + *
1175 + * @since v.1.0.0
1176 + * @return ARRAY
1177 + */
1178 + public function get_image_size() {
1179 + $sizes = get_intermediate_image_sizes();
1180 + $filter = array( 'full' => 'Full' );
1181 + foreach ( $sizes as $value ) {
1182 + $title = ucwords( str_replace( array( '_', '-', 'ultp' ), array( ' ', ' ', 'PostX' ), $value ) );
1183 + switch ( $value ) {
1184 + case 'thumbnail':
1185 + $title = $title . ' [150x150]';
1186 + break;
1187 + case 'medium':
1188 + $title = $title . ' [300x300]';
1189 + break;
1190 + case 'large':
1191 + $title = $title . ' [1024x1024]';
1192 + break;
1193 + case 'ultp_layout_landscape_large':
1194 + $title = $title . ' [1200x800]';
1195 + break;
1196 + case 'ultp_layout_landscape':
1197 + $title = $title . ' [870x570]';
1198 + break;
1199 + case 'ultp_layout_portrait':
1200 + $title = $title . ' [600x900]';
1201 + break;
1202 + case 'ultp_layout_square':
1203 + $title = $title . ' [600x600]';
1204 + break;
1205 + default:
1206 + break;
1207 + }
1208 + $filter[ $value ] = $title;
1209 + }
1210 + return $filter;
1211 + }
1212 +
1213 +
1214 + /**
1215 + * Get All PostType Registered
1216 + *
1217 + * @since v.1.0.0
1218 + * @return ARRAY
1219 + */
1220 + public function get_post_type() {
1221 + $filter = apply_filters( 'ultp_public_post_type', true );
1222 + $post_type = get_post_types( ( $filter ? array( 'public' => true ) : '' ), 'names' );
1223 + return array_diff( $post_type, array( 'attachment' ) );
1224 + }
1225 +
1226 + /**
1227 + * Get Pagination Url
1228 + *
1229 + * @since v.2.8.9
1230 + *
1231 + * @param NUMBER $pageNo The page number for pagination.
1232 + * @param STRING $baseUrl The base URL to append the pagination parameter to.
1233 + *
1234 + * @return STRING The generated pagination URL.
1235 + */
1236 + public function generatePaginationUrl( $pageNo, $baseUrl ) {
1237 + if ( $baseUrl ) {
1238 + $url = $baseUrl . ( $pageNo == 1 ? '' : 'page/' . $pageNo );
1239 + } else {
1240 + $url = get_pagenum_link( $pageNo );
1241 + }
1242 + return $url;
1243 + }
1244 + /**
1245 + * Get Pagination HTML
1246 + *
1247 + * @since v.1.0.0
1248 + * @param INT $pages Number of pages.
1249 + * @param STRING $paginationNav Pagination navigation type.
1250 + * @param STRING $paginationText Pagination text.
1251 + * @param BOOL $paginationAjax Whether to use AJAX pagination.
1252 + * @param STRING $baseUrl Base URL for pagination links.
1253 + * @param STRING $blockId Block ID for pagination.
1254 + * @return STRING
1255 + */
1256 + public function pagination( $pages = '', $paginationNav = '', $paginationText = '', $paginationAjax = true, $baseUrl = '', $blockId = '' ) {
1257 + $html = '';
1258 + $showitems = 3;
1259 + $paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
1260 + $paged = $paged ? $paged : 1;
1261 +
1262 + $paged = ! wp_doing_ajax() &&
1263 + isset( $_GET[ $blockId . '_page' ] ) &&
1264 + is_numeric( $_GET[ $blockId . '_page' ] ) ?
1265 + intval( $_GET[ $blockId . '_page' ] ) : $paged;
1266 +
1267 + if ( $pages == '' ) {
1268 + global $wp_query;
1269 + $pages = $wp_query->max_num_pages;
1270 + if ( ! $pages ) {
1271 + $pages = 1;
1272 + }
1273 + }
1274 +
1275 + $data = ( $paged >= 3 ? array( ( $paged - 1 ), $paged, $paged + 1 ) : array( 1, 2, 3 ) );
1276 +
1277 + $paginationText = explode( '|', $paginationText );
1278 +
1279 + $prev_text = isset( $paginationText[0] ) ? esc_html( $paginationText[0] ) : __( 'Previous', 'ultimate-post' );
1280 + $next_text = isset( $paginationText[1] ) ? esc_html( $paginationText[1] ) : __( 'Next', 'ultimate-post' );
1281 +
1282 + if ( 1 != $pages ) {
1283 + $html .= '<ul class="ultp-pagination">';
1284 + $display_none = 'style="display:none"';
1285 + if ( $paged > 1 || $paginationAjax && $pages > 1 ) {
1286 + $html .= '<li class="ultp-prev-page-numbers" ' . ( $paged == 1 ? $display_none : '' ) . '><a href="' . $this->generatePaginationUrl( $paged - 1, $baseUrl ) . '">' . ultimate_post()->get_svg_icon( 'leftAngle2' ) . ' ' . ( $paginationNav == 'textArrow' ? $prev_text : '' ) . '</a></li>';
1287 + }
1288 + if ( $pages > 3 ) {
1289 + $html .= '<li class="ultp-first-pages" ' . ( $paged < 2 ? $display_none : '' ) . ' data-current="1"><a href="' . $this->generatePaginationUrl( 1, $baseUrl ) . '">1</a></li>';
1290 + }
1291 + if ( $paged > 3 || $paginationAjax && $pages > 4 ) {
1292 + $html .= '<li class="ultp-first-dot"' . ( $paged == 1 ? $display_none : '' ) . '><a href="#">...</a></li>';
1293 + }
1294 + foreach ( $data as $i ) {
1295 + if ( $pages > 3 && $pages == $i ) {
1296 + continue;
1297 + }
1298 + if ( $pages >= $i ) {
1299 + $html .= ( $paged == $i ) ? '<li class="ultp-center-item pagination-active" data-current="' . $i . '"><a href="' . $this->generatePaginationUrl( $i, $baseUrl ) . '">' . $i . '</a></li>' : '<li class="ultp-center-item" data-current="' . $i . '" ' . ( ( $pages > 4 && $paged == 2 && $i == 1 && ! $paginationAjax ) ? $display_none : '' ) . '><a href="' . $this->generatePaginationUrl( $i, $baseUrl ) . '">' . $i . '</a></li>';
1300 + }
1301 + }
1302 + if ( $pages != ( $paged + 2 ) || $paginationAjax && $pages > 4 ) {
1303 + $html .= '<li class="ultp-last-dot" ' . ( $pages <= $paged + 1 ? $display_none : '' ) . '><a href="#">...</a></li>';
1304 + }
1305 + if ( $pages > 3 ) {
1306 + $html .= '<li class="ultp-last-pages' . ( $paged == $pages ? ' pagination-active' : '' ) . '" data-current="' . $pages . '"><a href="' . $this->generatePaginationUrl( $pages, $baseUrl ) . '">' . $pages . '</a></li>';
1307 + }
1308 + if ( $paged != $pages ) {
1309 + $html .= '<li class="ultp-next-page-numbers"><a href="' . $this->generatePaginationUrl( $paged + 1, $baseUrl ) . '">' . ( $paginationNav == 'textArrow' ? $next_text : '' ) . ultimate_post()->get_svg_icon( 'rightAngle2' ) . '</a></li>';
1310 + }
1311 + $html .= '</ul>';
1312 + }
1313 + return $html;
1314 + }
1315 +
1316 + /**
1317 + * Svg Icon Source
1318 + *
1319 + * @since v.1.0.0
1320 + * @param STRING $ultp_icons Name of the SVG icon file (without extension).
1321 + * @return STRING
1322 + */
1323 + public function get_svg_icon( $ultp_icons = '' ) {
1324 + $svg = '';
1325 + if ( $ultp_icons ) {
1326 + $icon = $this->svg_icon_compatibility( $ultp_icons );
1327 + $svg = $this->get_path_file_contents( ULTP_PATH . 'assets/img/iconpack/' . $icon . '.svg' );
1328 + }
1329 + return $svg;
1330 + }
1331 +
1332 + /**
1333 + * Get Taxonomy Lists
1334 + *
1335 + * @since v.1.0.0
1336 + * @param STRING|ARRAY $prams Taxonomy slug or arguments array.
1337 + * @return ARRAY
1338 + */
1339 + public function taxonomy( $prams = 'category' ) {
1340 + $data = array();
1341 +
1342 + $terms = get_terms(
1343 + is_string( $prams ) ? array(
1344 + 'taxonomy' => $prams,
1345 + 'hide_empty' => false,
1346 + ) : $prams
1347 + );
1348 + if ( ! is_wp_error( $terms ) ) {
1349 + foreach ( $terms as $val ) {
1350 + $data[ urldecode_deep( $val->slug ) ] = $val->name;
1351 + }
1352 + }
1353 + return $data;
1354 + }
1355 +
1356 +
1357 + /**
1358 + * Get Taxonomy Lists
1359 + *
1360 + * @since v.2.9.0
1361 + * @param STRING $tax_slug Taxonomy slug.
1362 + * @param INT $number Number of terms to retrieve.
1363 + * @return ARRAY
1364 + */
1365 + public function builder_preview( $tax_slug, $number ) {
1366 + $data = array();
1367 + $term_data = get_terms(
1368 + array(
1369 + 'taxonomy' => $tax_slug,
1370 + 'hide_empty' => true,
1371 + 'number' => $number,
1372 + 'parent' => 0,
1373 + )
1374 + );
1375 + if ( ! empty( $term_data ) ) {
1376 + foreach ( $term_data as $terms ) {
1377 + $data[] = $this->get_tax_data( $terms );
1378 + }
1379 + }
1380 + return $data;
1381 + }
1382 +
1383 + /**
1384 + * Get Taxonomy Data Lists
1385 + *
1386 + * @since v.1.0.0
1387 + * @param object $terms Taxonomy Object.
1388 + * @return ARRAY
1389 + */
1390 + public function get_tax_data( $terms ) {
1391 + $temp = array();
1392 + $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1393 + $image_src = array();
1394 + if ( $thumbnail_id ) {
1395 + $image_sizes = ultimate_post()->get_image_size();
1396 + foreach ( $image_sizes as $key => $value ) {
1397 + $img_src = wp_get_attachment_image_src( $thumbnail_id, $key, false );
1398 + if ( $img_src ) {
1399 + $image_src[ $key ] = $img_src[0];
1400 + }
1401 + }
1402 + }
1403 + $temp['url'] = get_term_link( $terms );
1404 + $temp['thumbnail_id'] = $thumbnail_id;
1405 + $temp['name'] = $terms->name;
1406 + $temp['desc'] = $terms->description;
1407 + $temp['count'] = $terms->count;
1408 + $temp['image'] = $image_src;
1409 + $color = get_term_meta( $terms->term_id, 'ultp_category_color', true );
1410 + $temp['color'] = $color ? $color : '#037fff';
1411 + return $temp;
1412 + }
1413 +
1414 + public function get_category_data( $catSlug, $number = 40, $type = '', $tax_slug = 'category', $archiveBuilder = '' ) {
1415 + $data = array();
1416 + if ( $type == 'child' ) {
1417 + if ( $archiveBuilder ) {
1418 + $data = $this->builder_preview( $tax_slug, $number );
1419 + } else {
1420 + if ( is_category() ) {
1421 + $catSlug = array( get_queried_object()->slug );
1422 + }
1423 + $image = '';
1424 + if ( ! empty( $catSlug ) ) {
1425 + foreach ( $catSlug as $cat ) {
1426 + $parent_term = get_term_by( 'slug', $cat, $tax_slug );
1427 + if ( ! empty( $parent_term ) ) {
1428 + $term_data = get_terms(
1429 + array(
1430 + 'taxonomy' => $tax_slug,
1431 + 'hide_empty' => true,
1432 + 'number' => $number,
1433 + 'parent' => $parent_term->term_id,
1434 + )
1435 + );
1436 + if ( ! empty( $term_data ) ) {
1437 + foreach ( $term_data as $terms ) {
1438 + $data[] = $this->get_tax_data( $terms );
1439 + }
1440 + }
1441 + }
1442 + }
1443 + }
1444 + }
1445 + } elseif ( $type == 'parent' ) {
1446 + $term_data = is_category() ? array( get_term( get_queried_object()->parent, 'category' ) ) : get_terms(
1447 + array(
1448 + 'taxonomy' => $tax_slug,
1449 + 'hide_empty' => true,
1450 + 'number' => $number,
1451 + 'parent' => 0,
1452 + )
1453 + );
1454 + if ( $archiveBuilder && ! empty( $term_data ) ) {
1455 + $term_data = array( $term_data[0] );
1456 + }
1457 + if ( ! empty( $term_data ) ) {
1458 + foreach ( $term_data as $terms ) {
1459 + if ( ! empty( $terms->term_id ) ) {
1460 + $data[] = $this->get_tax_data( $terms );
1461 + }
1462 + }
1463 + }
1464 + } elseif ( $type == 'custom' ) {
1465 + foreach ( $catSlug as $cat ) {
1466 + $terms = get_term_by( 'slug', $cat, $tax_slug );
1467 + if ( ! empty( $terms ) ) {
1468 + $data[] = $this->get_tax_data( $terms );
1469 + }
1470 + }
1471 + } elseif ( $type == 'immediate_child' ) {
1472 + if ( $archiveBuilder ) {
1473 + $data = $this->builder_preview( $tax_slug, $number );
1474 + } else {
1475 + $id_ = get_queried_object();
1476 + if ( isset( $id_->term_id ) ) {
1477 + $term_data = get_terms(
1478 + array(
1479 + 'taxonomy' => $tax_slug,
1480 + 'hide_empty' => true,
1481 + 'number' => 100,
1482 + 'parent' => $id_->term_id,
1483 + )
1484 + );
1485 + if ( ! empty( $term_data ) ) {
1486 + foreach ( $term_data as $terms ) {
1487 + $data[] = $this->get_tax_data( $terms );
1488 + }
1489 + }
1490 + }
1491 + }
1492 + } elseif ( $type == 'allchild' ) {
1493 + if ( $archiveBuilder ) {
1494 + $data = $this->builder_preview( $tax_slug, $number );
1495 + } else {
1496 + $id_ = get_queried_object();
1497 + if ( isset( $id_->term_taxonomy_id ) ) {
1498 + $termchildren = get_term_children( $id_->term_taxonomy_id, $tax_slug );
1499 + foreach ( $termchildren as $key => $value ) {
1500 + $terms = get_term_by( 'id', $value, $tax_slug );
1501 + $data[] = $this->get_tax_data( $terms );
1502 + }
1503 + }
1504 + }
1505 + } elseif ( $type == 'current_level' ) {
1506 + if ( $archiveBuilder ) {
1507 + $data = $this->builder_preview( $tax_slug, $number );
1508 + } else {
1509 + $id_ = get_queried_object();
1510 + if ( isset( $id_->parent ) ) {
1511 + $term_data = get_terms(
1512 + array(
1513 + 'taxonomy' => $tax_slug,
1514 + 'hide_empty' => true,
1515 + 'number' => $number,
1516 + 'parent' => $id_->parent,
1517 + )
1518 + );
1519 + if ( ! empty( $term_data ) ) {
1520 + foreach ( $term_data as $terms ) {
1521 + if ( $terms->term_id != $id_->term_id ) {
1522 + $data[] = $this->get_tax_data( $terms );
1523 + }
1524 + }
1525 + }
1526 + }
1527 + }
1528 + } else {
1529 + $term_data = get_terms(
1530 + array(
1531 + 'taxonomy' => $tax_slug,
1532 + 'hide_empty' => true,
1533 + 'number' => $number,
1534 + )
1535 + );
1536 + if ( ! empty( $term_data ) ) {
1537 + foreach ( $term_data as $terms ) {
1538 + $data[] = $this->get_tax_data( $terms );
1539 + }
1540 + }
1541 + }
1542 + return $data;
1543 + }
1544 +
1545 +
1546 + /**
1547 + * Get Next Previous HTML.
1548 + *
1549 + * @since v.1.0.0
1550 + * @return STRING
1551 + */
1552 + public function next_prev() {
1553 + $html = '';
1554 + $html .= '<ul>';
1555 + $html .= '<li>';
1556 + $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1557 + $html .= ultimate_post()->get_svg_icon( 'leftAngle2' ) . '<span class="screen-reader-text">' . esc_html__( 'Previous', 'ultimate-post' ) . '</span>';
1558 + $html .= '</a>';
1559 + $html .= '</li>';
1560 + $html .= '<li>';
1561 + $html .= '<a class="ultp-next-action">';
1562 + $html .= ultimate_post()->get_svg_icon( 'rightAngle2' ) . '<span class="screen-reader-text">' . esc_html__( 'Next', 'ultimate-post' ) . '</span>';
1563 + $html .= '</a>';
1564 + $html .= '</li>';
1565 + $html .= '</ul>';
1566 + return $html;
1567 + }
1568 +
1569 +
1570 + /**
1571 + * Get Loading HTML
1572 + *
1573 + * @since v.1.0.0
1574 + * @return STRING
1575 + */
1576 + public function postx_loading() {
1577 + $html = '';
1578 + $style = ultimate_post()->get_setting( 'preloader_style' );
1579 + if ( $style == 'style2' ) {
1580 + $html .= '<div class="ultp-loading-spinner" style="width:100%;height:100%"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>'; // ultp-block-items-wrap
1581 + } else {
1582 + $html .= '<div class="ultp-loading-blocks" style="width:100%;height:100%;"><div style="left: 0;top: 0;animation-delay:0s;"></div><div style="left: 21px;top: 0;animation-delay:0.125s;"></div><div style="left: 42px;top: 0;animation-delay:0.25s;"></div><div style="left: 0;top: 21px;animation-delay:0.875s;"></div><div style="left: 42px;top: 21px;animation-delay:0.375s;"></div><div style="left: 0;top: 42px;animation-delay:0.75s;"></div><div style="left: 42px;top: 42px;animation-delay:0.625s;"></div><div style="left: 21px;top: 42px;animation-delay:0.5s;"></div></div>';
1583 + }
1584 + return '<div class="ultp-loading">' . $html . '</div>';
1585 + }
1586 +
1587 +
1588 + /**
1589 + * Get Filter HTML
1590 + *
1591 + * @since v.1.0.0
1592 + * @param STRING $filterText Filter Text.
1593 + * @param STRING $filterType Filter Type.
1594 + * @param ARRAY|STRING $filterValue Filter Value.
1595 + * @param STRING $filterMobileText Filter Mobile Text.
1596 + * @param BOOL $filterMobile Enable Filter Mobile.
1597 + * @return STRING
1598 + */
1599 + public function filter_html( $filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true ) {
1600 + $html = '';
1601 + $html .= '<ul ' . ( $filterMobile ? 'class="ultp-flex-menu"' : '' ) . ' data-name="' . ( $filterMobileText ? $filterMobileText : '&nbsp;' ) . '">';
1602 + $cat = $this->taxonomy( $filterType );
1603 + if ( $filterText ) {
1604 + $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">' . $filterText . '</a></li>';
1605 + }
1606 + if ( $filterValue ) {
1607 + $filterValue = strlen( $filterValue ) > 2 ? $filterValue : array();
1608 + $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
1609 + if ( is_array( $filterValue ) && count( $filterValue ) ) {
1610 + foreach ( $filterValue as $val ) {
1611 + $val = isset( $val->value ) ? $val->value : $val;
1612 + $html .= '<li class="filter-item"><a data-taxonomy="' . $val . '" href="#">' . ( isset( $cat[ $val ] ) ? $cat[ $val ] : $val ) . '</a></li>';
1613 + }
1614 + }
1615 + }
1616 + $html .= '</ul>';
1617 + return $html;
1618 + }
1619 +
1620 +
1621 + /**
1622 + * Check License Status
1623 + *
1624 + * @since v.2.4.2
1625 + * @return BOOLEAN | Is pro license active or not
1626 + */
1627 + public function is_lc_active() {
1628 + return Xpo::is_lc_active();
1629 + }
1630 +
1631 +
1632 + /**
1633 + * Check if a pro feature is visible based on license expiration date.
1634 + *
1635 + * @since v.2.4.2
1636 + * @param STRING $date Date to compare with license expiration.
1637 + * @return BOOL True if the pro feature is visible, false otherwise.
1638 + */
1639 + public function is_pro_feature_visible( $date ) {
1640 + if ( function_exists( 'ultimate_post_pro' ) ) {
1641 + $license_data = get_option( 'edd_ultp_license_data' );
1642 + if ( isset( $license_data['expires'] ) ) {
1643 + $expires = $license_data['expires'];
1644 + if ( 'lifetime' === $expires ) {
1645 + return true;
1646 + }
1647 + return strtotime( $date ) < strtotime( $expires );
1648 + }
1649 + return true;
1650 + }
1651 + return false;
1652 + }
1653 +
1654 + /**
1655 + * Get SEO Meta
1656 + *
1657 + * @since v.2.4.3
1658 + * @param INT $post_id Post ID.
1659 + * @param INT $show_seo_meta Show SEO meta flag.
1660 + * @param INT $show_full_excerpt Show full excerpt flag.
1661 + * @param INT $excerpt_limit Excerpt word limit.
1662 + * @return STRING SEO Meta Description or Excerpt.
1663 + */
1664 + public function get_excerpt( $post_id = 0, $show_seo_meta = 0, $show_full_excerpt = 0, $excerpt_limit = 55 ) {
1665 + $html = '';
1666 + if ( $show_seo_meta ) {
1667 + $str = '';
1668 + if ( function_exists( 'ultimate_post_pro' ) ) {
1669 + if ( ultimate_post()->get_setting( 'ultp_yoast' ) == 'true' ) {
1670 + $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta( $post_id ) : '';
1671 + } elseif ( ultimate_post()->get_setting( 'ultp_rankmath' ) == 'true' ) {
1672 + $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta( $post_id ) : '';
1673 + } elseif ( ultimate_post()->get_setting( 'ultp_aioseo' ) == 'true' ) {
1674 + $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta( $post_id ) : '';
1675 + } elseif ( ultimate_post()->get_setting( 'ultp_seopress' ) == 'true' ) {
1676 + $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta( $post_id ) : '';
1677 + } elseif ( ultimate_post()->get_setting( 'ultp_squirrly' ) == 'true' ) {
1678 + $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta( $post_id ) : '';
1679 + }
1680 + }
1681 + $html = $str ? $str : ultimate_post()->excerpt( $post_id, $excerpt_limit );
1682 + } elseif ( $show_full_excerpt == 0 ) {
1683 + $html = ultimate_post()->excerpt( $post_id, $excerpt_limit );
1684 + } else {
1685 + $html = get_the_excerpt();
1686 + }
1687 + return $html;
1688 + }
1689 +
1690 + /**
1691 + * Get embedded video HTML.
1692 + *
1693 + * @since v.1.0.0
1694 + * @param STRING $url Video URL.
1695 + * @param BOOL $autoPlay Whether to autoplay the video.
1696 + * @param BOOL $loop Whether to loop the video.
1697 + * @param BOOL $mute Whether to mute the video.
1698 + * @param BOOL $playback Whether to show playback controls.
1699 + * @param STRING $preload Preload attribute value.
1700 + * @param ARRAY | string $poster Poster image for the video.
1701 + * @param BOOL $inline Whether to play inline.
1702 + * @param ARRAY | string $size Size for oEmbed.
1703 + * @return STRING | false Video embed HTML or false on failure.
1704 + */
1705 + public function get_embeded_video( $url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size, $location = '' ) {
1706 + $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = '';
1707 +
1708 + $video_type = '';
1709 + // Determine video type
1710 + $video_type = 'local';
1711 + if ( strpos( $url, 'youtube.com' ) !== false || strpos( $url, 'youtu.be' ) !== false ) {
1712 + $video_type = 'youtube';
1713 + } elseif ( strpos( $url, 'vimeo.com' ) !== false ) {
1714 + $video_type = 'vimeo';
1715 + }
1716 +
1717 + // Get poster URL
1718 + $poster_url = '';
1719 + if ( is_array( $poster ) && isset( $poster['url'] ) ) {
1720 + $poster_url = $poster['url'];
1721 + } elseif ( is_string( $poster ) ) {
1722 + $poster_url = $poster;
1723 + }
1724 +
1725 + // Prepare size attributes
1726 + $width = is_array( $size ) && isset( $size['width'] ) ? $size['width'] : 560;
1727 + $height = is_array( $size ) && isset( $size['height'] ) ? $size['height'] : 315;
1728 +
1729 + $video_id = '';
1730 +
1731 + if ( $url ) {
1732 + $regex = '/(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})/';
1733 + if ( preg_match( $regex, $url, $matches ) ) {
1734 + $video_id = $matches[1];
1735 + }
1736 + }
1737 +
1738 + // Create data attributes for lazy loading
1739 + $data_attrs = array(
1740 + 'data-video-url' => is_scalar( $url ) ? esc_attr( $url ) : '',
1741 + 'data-video-type' => is_scalar( $video_type ) ? esc_attr( $video_type ) : '',
1742 + 'data-autoplay' => ! empty( $autoPlay ) ? '1' : '0',
1743 + 'data-loop' => ! empty( $loop ) ? '1' : '0',
1744 + 'data-mute' => ! empty( $mute ) ? '1' : '0',
1745 + 'data-controls' => ! empty( $playback ) ? '1' : '0',
1746 + 'data-preload' => is_scalar( $preload ) ? esc_attr( $preload ) : '',
1747 + 'data-poster' => is_scalar( $poster_url ) ? esc_attr( $poster_url ) : '',
1748 + 'data-playsinline' => ! empty( $inline ) ? '1' : '0',
1749 + 'data-width' => is_scalar( $width ) ? esc_attr( $width ) : '',
1750 + 'data-height' => is_scalar( $height ) ? esc_attr( $height ) : '',
1751 + 'data-video-id' => is_scalar( $video_id ) ? esc_attr( $video_id ) : '',
1752 + );
1753 +
1754 + $data_string = implode(
1755 + ' ',
1756 + array_map(
1757 + function ( $key, $value ) {
1758 + return $key . '="' . $value . '"';
1759 + },
1760 + array_keys( $data_attrs ),
1761 + $data_attrs
1762 + )
1763 + );
1764 +
1765 + $html = '<div class="ultp-video-wrapper ultp-embaded-video"' . $data_string . '></div>';
1766 +
1767 + if ( $location == '' ) {
1768 + return $html;
1769 + }
1770 +
1771 + if ( $autoPlay ) {
1772 + $vidAutoPlay = 'autoplay';
1773 + }
1774 + if ( $poster ) {
1775 + $vidPoster = 'poster="' . $poster['url'] . '"';
1776 + }
1777 + if ( $loop ) {
1778 + $vidloop = 'loop';
1779 + }
1780 + if ( $mute ) {
1781 + $vidmute = 'muted';
1782 + }
1783 + if ( $playback ) {
1784 + $vidplayback = 'controls';
1785 + }
1786 + if ( $inline ) {
1787 + $vidInline = 'playsinline';
1788 + }
1789 + if ( ! empty( $url ) ) {
1790 + $embeded = wp_oembed_get( $url, $size );
1791 + if ( $embeded == false ) {
1792 + $format = '';
1793 + $url = strtolower( $url );
1794 + if ( strpos( $url, '.mp4' ) ) {
1795 + $format = 'mp4';
1796 + } elseif ( strpos( $url, '.ogg' ) ) {
1797 + $format = 'ogg';
1798 + } elseif ( strpos( $url, '.webm' ) ) {
1799 + $format = 'WebM';
1800 + }
1801 + $embeded = '<video
1802 + ' . $vidloop . '
1803 + ' . $vidmute . '
1804 + ' . $vidplayback . '
1805 + preload="' . $preload . '"
1806 + ' . $vidAutoPlay . '
1807 + ' . $vidPoster . '
1808 + ' . $vidInline . '
1809 + class="ultp-video-html"
1810 + ><source src="' . $url . '" type="video/' . $format . '">' . __( 'Your browser does not support the video tag.', 'ultimate-post' ) . '</video>';
1811 + return '<div class="ultp-video-wrapper">' . $embeded . '</div>';
1812 + }
1813 + return '<div class="ultp-video-wrapper ultp-embaded-video">' . $embeded . '</div>';
1814 + } else {
1815 + return false;
1816 + }
1817 + }
1818 +
1819 + /**
1820 + * Get Public taxonomy Lists
1821 + *
1822 + * @since v.2.7.0
1823 + * @return ARRAY | Taxonomy Lists as array
1824 + */
1825 + public function get_taxonomy_list() {
1826 + $taxonomy = get_taxonomies( array( 'public' => true ) );
1827 + return empty( $taxonomy ) ? array() : array_keys( $taxonomy );
1828 + }
1829 +
1830 + /**
1831 + * Content Print
1832 + *
1833 + * @since v.2.7.0
1834 + * @param int $post_id Post ID.
1835 + * @param string $builder_type Builder type.
1836 + * @return void | Content of the Post
1837 + */
1838 + public function get_post_content( $post_id, $builder_type = '' ) {
1839 + $content_post = get_post( $post_id );
1840 + $content = $content_post->post_content;
1841 + if ( $builder_type == 'divi' || $builder_type == 'elementor' ) {
1842 + $content = apply_filters( 'the_content', $content );
1843 + } else {
1844 + global $wp_embed;
1845 + $content = $wp_embed->autoembed( $content );
1846 + $content = do_blocks( $content );
1847 + $content = do_shortcode( $content );
1848 + }
1849 + $content = str_replace( ']]>', ']]&gt;', $content );
1850 + $content = preg_replace( '%<p>&nbsp;\s*</p>%', '', $content );
1851 + $content = preg_replace( '/^(?:<br\s*\/?>\s*)+/', '', $content );
1852 + echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1853 + }
1854 +
1855 + /**
1856 + * String Part finder inside array.
1857 + *
1858 + * @since v.2.7.0 updated 4.1.12
1859 + *
1860 + * @param STRING $part The part of the string to search for.
1861 + * @param ARRAY $data The array to search within.
1862 + * @param STRING $toR Return type: 'bool', 'value', or default (array).
1863 + * @return MIXED Returns true/false, value, or array depending on $toR.
1864 + * @since v.2.7.0 updated 4.1.12
1865 + */
1866 + public function in_array_part( $part, $data, $toR = '' ) {
1867 + $res = array();
1868 + foreach ( $data as $key => $val ) {
1869 + if ( strpos( $val, $part ) !== false ) {
1870 + if ( $toR == 'bool' ) {
1871 + return true;
1872 + } elseif ( $toR == 'value' ) {
1873 + return $val;
1874 + }
1875 + $res[ $key ] = $val;
1876 + }
1877 + }
1878 + if ( $toR == 'bool' ) {
1879 + return false;
1880 + } elseif ( $toR == 'value' ) {
1881 + return '';
1882 + }
1883 + return $res;
1884 + }
1885 +
1886 + /**
1887 + * Builder Conditions
1888 + *
1889 + * @since v.2.7.0 updated 4.1.12
1890 + * @param STRING $type Type of return value.
1891 + * @param MIXED $cus_condition Custom conditions array or value.
1892 + * @return MIXED ID or Path.
1893 + */
1894 + public function builder_check_conditions( $type = 'return', $cus_condition = '' ) {
1895 + $page_id = '';
1896 + $conditions = $cus_condition ? $cus_condition : get_option( 'ultp_builder_conditions', array() );
1897 +
1898 + if ( $type == 'header' || $type == 'footer' ) {
1899 + if ( ! empty( $conditions[ $type ] ) ) {
1900 + foreach ( $conditions[ $type ] as $key => $val ) {
1901 + if ( 'publish' == get_post_status( $key ) && ! empty( $val ) ) {
1902 + if ( in_array( 'include/' . $type . '/entire_site', $val ) ) {
1903 + $page_id = $key;
1904 + } elseif ( in_array( 'exclude/' . $type . '/entire_site', $val ) ) {
1905 + $page_id = '';
1906 + }
1907 +
1908 + $c_page = ( is_archive() || is_search() ) ? 'archive' : 'singular';
1909 + $hf_archive = $this->in_array_part( $type . '/' . $c_page, $val, '' );
1910 + if ( ! empty( $hf_archive ) ) {
1911 + foreach ( $hf_archive as $k => $v ) {
1912 + if ( strpos( $v, 'include/' . $type . '/' . $c_page ) !== false ) {
1913 + $temp = $this->builder_check_conditions( 'return_' . $type, array( $c_page => array( $key => array( str_replace( $type . '/', '', $v ) ) ) ) );
1914 + $page_id = $temp ? $temp : $page_id;
1915 + } elseif ( strpos( $v, 'exclude/' . $type . '/' . $c_page ) !== false ) {
1916 + $temp = $this->builder_check_conditions( 'return_' . $type, array( $c_page => array( $key => array( str_replace( 'exclude/' . $type, 'include', $v ) ) ) ) );
1917 + $page_id = $temp ? '' : $page_id;
1918 + }
1919 + }
1920 + }
1921 + }
1922 + }
1923 + }
1924 + } else {
1925 + // 404 page .
1926 + if ( ! empty( $conditions['404'] ) && is_404() ) {
1927 + foreach ( $conditions['404'] as $key => $val ) {
1928 + if ( 'publish' == get_post_status( $key ) ) {
1929 + $page_id = $key;
1930 + }
1931 + }
1932 + }
1933 + // Singular or Front Page .
1934 + elseif (
1935 + (
1936 + ! empty( $conditions['singular'] ) ||
1937 + ! empty( $conditions['front_page'] )
1938 + ) &&
1939 + (
1940 + is_singular() ||
1941 + is_front_page() ||
1942 + is_home()
1943 + )
1944 + ) {
1945 + $obj = get_queried_object();
1946 + $queried_is_obj = is_object( $obj );
1947 + // front page only .
1948 + if (
1949 + ( is_front_page() && is_home() ) ||
1950 + ( is_home() && ! $queried_is_obj ) ||
1951 + ( is_singular() && is_front_page() && $queried_is_obj )
1952 + ) {
1953 + $f_conditions = array();
1954 + if ( ! empty( $conditions['front_page'] ) ) {
1955 + $f_conditions = $conditions['front_page'];
1956 + } elseif ( ! empty( $conditions['singular'] ) ) {
1957 + $f_conditions = $conditions['singular'];
1958 + }
1959 + if ( ! empty( $f_conditions ) ) {
1960 + foreach ( $f_conditions as $key => $val ) {
1961 + if ( ( is_array( $val ) && in_array( 'include/singular/front_page', $val ) ) ||
1962 + ( is_array( $val ) && in_array( 'include/front_page', $val ) ) ||
1963 + 'include/front_page' == $val
1964 + ) {
1965 + if ( 'publish' == get_post_status( $key ) ) {
1966 + $page_id = $key;
1967 + }
1968 + }
1969 + // Default Front / Home page Header Footer Compatibility .
1970 + elseif ( is_array( $val ) && 'publish' == get_post_status( $key ) && ( $type == 'return_header' || $type == 'return_footer' ) ) {
1971 + $base_include = 'include/singular/' . $obj->post_type;
1972 + $base_exclude = 'exclude/singular/' . $obj->post_type;
1973 + $specific_include = $base_include . '/' . $obj->ID;
1974 + $specific_exclude = $base_exclude . '/' . $obj->ID;
1975 +
1976 + if ( in_array( $specific_include, $val ) ) {
1977 + $page_id = $key;
1978 + } elseif ( in_array( $specific_exclude, $val ) ) {
1979 + $page_id = '';
1980 + } elseif ( in_array( $base_include, $val ) ) {
1981 + $page_id = $key;
1982 + } elseif ( in_array( $base_exclude, $val ) ) {
1983 + $page_id = '';
1984 + }
1985 + }
1986 + }
1987 + }
1988 + }
1989 + // Singular page .
1990 + elseif ( ! empty( $conditions['singular'] ) ) {
1991 + foreach ( $conditions['singular'] as $key => $val ) {
1992 + if ( 'publish' == get_post_status( $key ) ) {
1993 + // All Post Type. -----Prority 1 .
1994 + if ( $queried_is_obj ) {
1995 + if ( in_array( 'include/singular/' . $obj->post_type, $val ) ) {
1996 + $page_id = $key;
1997 + } elseif ( in_array( 'exclude/singular/' . $obj->post_type, $val ) ) {
1998 + $page_id = '';
1999 + }
2000 + }
2001 +
2002 + $singular_in_tax = $this->in_array_part( '/singular/in_', $val, '' );
2003 + if ( ! empty( $singular_in_tax ) ) {
2004 + $tax_list = $this->get_taxonomy_list();
2005 + foreach ( $tax_list as $tax ) {
2006 + if ( in_array( 'include/singular/in_' . $tax . '_children', $singular_in_tax ) ) {
2007 + $page_id = $key;
2008 + } elseif ( in_array( 'exclude/singular/in_' . $tax . '_children', $singular_in_tax ) ) {
2009 + $page_id = '';
2010 + }
2011 +
2012 + if ( $queried_is_obj ) {
2013 + $singular_in_tax_children = $this->in_array_part( '/singular/in_' . $tax . '_children/', $singular_in_tax, '' );
2014 + foreach ( $singular_in_tax_children as $v ) {
2015 + $data = explode( '/', $v );
2016 + if ( isset( $data[3] ) && $data[3] ) {
2017 + $childs = get_term_children( $data[3], $tax );
2018 + if ( ! empty( $childs ) && has_term( $childs, $tax ) ) {
2019 + $page_id = $data[0] == 'exclude' ? '' : $key;
2020 + }
2021 + }
2022 + }
2023 + }
2024 +
2025 + if ( in_array( 'include/singular/in_' . $tax, $singular_in_tax ) ) {
2026 + if ( $tax == 'post_tag' && $queried_is_obj ) {
2027 + $cat = get_the_terms( $obj->ID, 'post_tag' );
2028 + if ( ! empty( $cat ) ) {
2029 + $page_id = $key;
2030 + }
2031 + } else {
2032 + $page_id = $key;
2033 + }
2034 + } elseif ( in_array( 'exclude/singular/in_' . $tax, $singular_in_tax ) ) {
2035 + $page_id = '';
2036 + }
2037 +
2038 + if ( $queried_is_obj ) {
2039 + $singular_in_tax_only = $this->in_array_part( '/singular/in_' . $tax . '/', $singular_in_tax, '' );
2040 + foreach ( $singular_in_tax_only as $v ) {
2041 + $data = explode( '/', $v );
2042 + if ( isset( $data[3] ) && $data[3] ) {
2043 + if ( is_object_in_term( $obj->ID, $tax, $data[3] ) ) {
2044 + $page_id = $data[0] == 'exclude' ? '' : $key;
2045 + }
2046 + }
2047 + }
2048 + }
2049 + }
2050 + }
2051 +
2052 + // Posts by author -----Prority 9 .
2053 + if ( in_array( 'include/singular/post_by_author', $val ) ) {
2054 + $page_id = $key;
2055 + } elseif ( in_array( 'exclude/singular/post_by_author', $val ) ) {
2056 + $page_id = '';
2057 + }
2058 + if ( $queried_is_obj ) {
2059 + if ( in_array( 'include/singular/post_by_author/' . $obj->post_author, $val ) ) {
2060 + $page_id = $key;
2061 + } elseif ( in_array( 'exclude/singular/post_by_author/' . $obj->post_author, $val ) ) {
2062 + $page_id = '';
2063 + }
2064 + // Post Type with specific id -----Prority 10 .
2065 + if ( in_array( 'include/singular/' . $obj->post_type . '/' . $obj->ID, $val ) ) {
2066 + $page_id = $key;
2067 + } elseif ( in_array( 'exclude/singular/' . $obj->post_type . '/' . $obj->ID, $val ) ) {
2068 + $page_id = '';
2069 + }
2070 + }
2071 + }
2072 + }
2073 + }
2074 + }
2075 +
2076 + // Archive and Search Page .
2077 + elseif ( ! empty( $conditions['archive'] ) ) {
2078 + // Search Page .
2079 + if ( is_search() ) {
2080 + foreach ( $conditions['archive'] as $key => $val ) {
2081 + if ( 'publish' == get_post_status( $key ) ) {
2082 + if ( in_array( 'include/archive/search', $val ) ) {
2083 + $page_id = $key;
2084 + } elseif ( in_array( 'exclude/archive/search', $val ) ) {
2085 + $page_id = '';
2086 + }
2087 + }
2088 + }
2089 + }
2090 + // Archive Page .
2091 + elseif ( is_archive() ) {
2092 + $is_cat = is_category();
2093 + $is_tag = is_tag();
2094 + $is_tax = is_tax();
2095 + $is_date = is_date();
2096 + $is_author = is_author();
2097 + $taxonomy = ( $is_cat || $is_tag || $is_tax ) ? get_queried_object() : (object) array();
2098 +
2099 + foreach ( $conditions['archive'] as $key => $val ) {
2100 + if ( 'publish' == get_post_status( $key ) ) {
2101 + // This section is for all archive page .
2102 + if ( in_array( 'include/archive', $val ) ) {
2103 + $page_id = $key;
2104 + } elseif ( in_array( 'exclude/archive', $val ) ) {
2105 + $page_id = '';
2106 + }
2107 + // For Category .
2108 + if ( $is_cat ) {
2109 + // all category .
2110 + if ( in_array( 'include/archive/category', $val ) ) {
2111 + $page_id = $key;
2112 + } elseif ( in_array( 'exclude/archive/category', $val ) ) {
2113 + $page_id = '';
2114 + }
2115 + // specific category .
2116 + if ( in_array( 'include/archive/category/' . $taxonomy->term_id, $val ) ) {
2117 + $page_id = $key;
2118 + } elseif ( in_array( 'exclude/archive/category/' . $taxonomy->term_id, $val ) ) {
2119 + $page_id = '';
2120 + }
2121 +
2122 + // any child of category .
2123 + if ( in_array( 'include/archive/any_child_of_category', $val ) ) {
2124 + $page_id = $key;
2125 + } elseif ( in_array( 'exclude/archive/any_child_of_category', $val ) ) {
2126 + $page_id = '';
2127 + }
2128 +
2129 + $any_child_of_cat = $this->in_array_part( 'archive/any_child_of_category/', $val, '' );
2130 + if ( ! empty( $any_child_of_cat ) ) {
2131 + foreach ( $any_child_of_cat as $v ) {
2132 + $data = explode( '/', $v );
2133 + if ( isset( $data[3] ) && $data[3] ) {
2134 + if ( term_is_ancestor_of( $data[3], $taxonomy->term_id, 'category' ) ) {
2135 + $page_id = $data[0] == 'exclude' ? '' : $key;
2136 + }
2137 + }
2138 + }
2139 + }
2140 +
2141 + // all child of category .
2142 + if ( in_array( 'include/archive/child_of_category', $val ) ) {
2143 + $page_id = $key;
2144 + } elseif ( in_array( 'exclude/archive/child_of_category', $val ) ) {
2145 + $page_id = '';
2146 + }
2147 + // specific child of category .
2148 + if ( in_array( 'include/archive/child_of_category/' . $taxonomy->parent, $val ) ) {
2149 + $page_id = $key;
2150 + } elseif ( in_array( 'exclude/archive/child_of_category/' . $taxonomy->parent, $val ) ) {
2151 + $page_id = '';
2152 + }
2153 + }
2154 + // For Tag .
2155 + elseif ( $is_tag ) {
2156 + if ( in_array( 'include/archive/post_tag', $val ) ) {
2157 + $page_id = $key;
2158 + } elseif ( in_array( 'exclude/archive/post_tag', $val ) ) {
2159 + $page_id = '';
2160 + }
2161 + if ( in_array( 'include/archive/post_tag/' . $taxonomy->term_id, $val ) ) {
2162 + $page_id = $key;
2163 + } elseif ( in_array( 'exclude/archive/post_tag/' . $taxonomy->term_id, $val ) ) {
2164 + $page_id = '';
2165 + }
2166 + }
2167 + // Other taxonomy .
2168 + elseif ( $is_tax ) {
2169 + if ( in_array( 'include/archive/' . $taxonomy->taxonomy, $val ) ) {
2170 + $page_id = $key;
2171 + } elseif ( in_array( 'exclude/archive/' . $taxonomy->taxonomy, $val ) ) {
2172 + $page_id = '';
2173 + }
2174 +
2175 + if ( in_array( 'include/archive/' . $taxonomy->taxonomy . '/' . $taxonomy->term_id, $val ) ) {
2176 + $page_id = $key;
2177 + } elseif ( in_array( 'exclude/archive/' . $taxonomy->taxonomy . '/' . $taxonomy->term_id, $val ) ) {
2178 + $page_id = '';
2179 + }
2180 +
2181 + if ( in_array( 'include/archive/any_child_of_' . $taxonomy->taxonomy, $val ) ) {
2182 + $page_id = $key;
2183 + } elseif ( in_array( 'exclude/archive/any_child_of_' . $taxonomy->taxonomy, $val ) ) {
2184 + $page_id = '';
2185 + }
2186 +
2187 + $any_child_of_tax = $this->in_array_part( 'archive/any_child_of_' . $taxonomy->taxonomy . '/', $val, '' );
2188 + if ( ! empty( $any_child_of_tax ) ) {
2189 + foreach ( $any_child_of_tax as $v ) {
2190 + $data = explode( '/', $v );
2191 + if ( isset( $data[3] ) && $data[3] ) {
2192 + if ( term_is_ancestor_of( $data[3], $taxonomy->term_id, $taxonomy->taxonomy ) ) {
2193 + $page_id = $data[0] == 'exclude' ? '' : $key;
2194 + }
2195 + }
2196 + }
2197 + }
2198 +
2199 + if ( in_array( 'include/archive/child_of_' . $taxonomy->taxonomy, $val ) ) {
2200 + $page_id = $key;
2201 + } elseif ( in_array( 'exclude/archive/child_of_' . $taxonomy->taxonomy, $val ) ) {
2202 + $page_id = '';
2203 + }
2204 +
2205 + if ( in_array( 'include/archive/child_of_' . $taxonomy->taxonomy . '/' . $taxonomy->parent, $val ) ) {
2206 + $page_id = $key;
2207 + } elseif ( in_array( 'exclude/archive/child_of_' . $taxonomy->taxonomy . '/' . $taxonomy->parent, $val ) ) {
2208 + $page_id = '';
2209 + }
2210 + }
2211 + // For Date.
2212 + elseif ( $is_date ) {
2213 + if ( in_array( 'include/archive/date', $val ) ) {
2214 + $page_id = $key;
2215 + } elseif ( in_array( 'exclude/archive/date', $val ) ) {
2216 + $page_id = '';
2217 + }
2218 + }
2219 + // For Author.
2220 + elseif ( $is_author ) {
2221 + if ( in_array( 'include/archive/author', $val ) ) {
2222 + $page_id = $key;
2223 + } elseif ( in_array( 'exclude/archive/author', $val ) ) {
2224 + $page_id = '';
2225 + }
2226 + $author_id = get_the_author_meta( 'ID' );
2227 + if ( in_array( 'include/archive/author/' . $author_id, $val ) ) {
2228 + $page_id = $key;
2229 + } elseif ( in_array( 'exclude/archive/author/' . $author_id, $val ) ) {
2230 + $page_id = '';
2231 + }
2232 + }
2233 + }
2234 + }
2235 + }
2236 + }
2237 + }
2238 + return $page_id;
2239 + }
2240 +
2241 + /**
2242 + * Get Date Default Format
2243 + *
2244 + * @since v.2.7.2
2245 + * @param STRING $format Format type.
2246 + * @return ARRAY | Default Data
2247 + */
2248 + public function get_format( $format ) {
2249 + if ( $format == 'default_date' ) {
2250 + return get_option( 'date_format' );
2251 + } elseif ( $format == 'default_date_time' ) {
2252 + return get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
2253 + } else {
2254 + return $format;
2255 + }
2256 + }
2257 +
2258 + /**
2259 + * Common Frontend and Backend CSS and JS Scripts
2260 + *
2261 + * @since v.1.0.0
2262 + */
2263 + public function register_scripts_common() {
2264 + if ( ! ( isset( $GLOBALS['wp_scripts'] ) && isset( $GLOBALS['wp_scripts']->registered ) && isset( $GLOBALS['wp_scripts']->registered['ultp-script'] ) ) ) {
2265 + wp_enqueue_style( 'ultp-style', ULTP_URL . 'assets/css/style.min.css', array(), ULTP_VER );
2266 + wp_enqueue_script( 'ultp-script', ULTP_URL . 'assets/js/ultp.min.js', array( 'jquery', 'wp-api-fetch' ), ULTP_VER, true );
2267 + wp_localize_script(
2268 + 'ultp-script',
2269 + 'ultp_data_frontend',
2270 + array(
2271 + 'url' => ULTP_URL,
2272 + 'active' => ultimate_post()->is_lc_active(),
2273 + 'ultpSavedDLMode' => ultimate_post()->get_dl_mode(),
2274 + 'ajax' => admin_url( 'admin-ajax.php' ),
2275 + 'security' => wp_create_nonce( 'ultp-nonce' ),
2276 + 'home_url' => home_url(),
2277 + 'dark_logo' => get_option( 'ultp_site_dark_logo', false ),
2278 + )
2279 + );
2280 + }
2281 + }
2282 +
2283 + /**
2284 + * Get Dark Light Mode
2285 + *
2286 + * @since 4.0.0
2287 + * @return STRING | Dark Light Mode .
2288 + */
2289 + public function get_dl_mode() {
2290 + $data = get_option( 'postx_global', array() );
2291 + $mode = 'ultplight';
2292 + if ( ! empty( $data ) ) {
2293 + $mode = isset( $data['enableDark'] ) && $data['enableDark'] ? 'ultpdark' : 'ultplight';
2294 + }
2295 + return $mode;
2296 + }
2297 +
2298 + /**
2299 + * Get Page Post Id ( Kadence element )
2300 + *
2301 + * @since v.2.8.9
2302 + * @param STRING|INT $blockId Block ID to search for.
2303 + * @return NULL
2304 + */
2305 + public function get_page_post_id( $blockId ) {
2306 + global $wpdb;
2307 + $post_meta = $wpdb->get_row( $wpdb->prepare( 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key=%s AND meta_value LIKE %s', '_ultp_css', '%.ultp-block-' . $blockId . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2308 + // For FSE theme
2309 + if ( ! $post_meta ) {
2310 + if ( wp_is_block_theme() ) {
2311 + $template = $wpdb->get_row( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_content LIKE %s', '%"blockId":"' . $blockId . '"%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2312 + if ( isset( $template->ID ) ) {
2313 + return $template->ID;
2314 + }
2315 + }
2316 + }
2317 + if ( $post_meta && isset( $post_meta->post_id ) ) {
2318 + return $post_meta->post_id;
2319 + }
2320 + return ultimate_post()->get_ID();
2321 + }
2322 +
2323 +
2324 + /**
2325 + * Get no Result found html
2326 + *
2327 + * @since v.2.9.0
2328 + * @param STRING $text No result found text.
2329 + * @return STRING | Taxonomy Lists as array
2330 + */
2331 + public function get_no_result_found_html( $text ) {
2332 + return $text ? '<div class="ultp-not-found-message" role="alert">' . wp_kses( $text, ultimate_post()->ultp_allowed_html_tags() ) . '</div>' : '';
2333 + }
2334 +
2335 + /**
2336 + * Get all Saved Templates Lists
2337 + *
2338 + * @since v.2.9.9
2339 + * @param STRING $post_type Post type to retrieve.
2340 + * @param STRING $empty Empty value for the select field.
2341 + * @return STRING | Taxonomy Lists as array
2342 + */
2343 + public function get_all_lists( $post_type = 'post', $empty = '' ) {
2344 + $args = array(
2345 + 'post_type' => $post_type,
2346 + 'post_status' => 'publish',
2347 + 'posts_per_page' => -1,
2348 + );
2349 + $loop = new \WP_Query( $args );
2350 + $data[ $empty ? $empty : '' ] = __( '- Select Template -', 'ultimate-post' );
2351 + if ( $loop->have_posts() ) {
2352 + foreach ( $loop->posts as $post ) {
2353 + $data[ $post->ID ] = $post->post_title;
2354 + }
2355 + }
2356 + wp_reset_postdata();
2357 + return $data;
2358 + }
2359 +
2360 + /**
2361 + * Get ID from the Youtube URL
2362 + *
2363 + * @since v.3.1.7
2364 + * @param STRING $url The Youtube URL .
2365 + * @return STRING | Taxonomy Lists as array
2366 + */
2367 + public function get_youtube_id( $url = '' ) {
2368 + if ( strpos( $url, 'youtu' ) !== false ) {
2369 + $reg = '/youtu(?:.*\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{11})/m';
2370 + preg_match( $reg, $url, $matches );
2371 + if ( isset( $matches[1] ) ) {
2372 + return $matches[1];
2373 + }
2374 + }
2375 + return false;
2376 + }
2377 +
2378 + /**
2379 + * Get Option Value bypassing cache
2380 + * Inspired By WordPress Core get_option
2381 + *
2382 + * @since v.3.1.6
2383 + * @param STRING $option Option Name.
2384 + * @param BOOLEAN $default_value option default value.
2385 + * @return mixed
2386 + */
2387 + public function get_option_without_cache( $option, $default_value = false ) {
2388 + global $wpdb;
2389 +
2390 + if ( is_scalar( $option ) ) {
2391 + $option = trim( $option );
2392 + }
2393 +
2394 + if ( empty( $option ) ) {
2395 + return false;
2396 + }
2397 +
2398 + $value = $default_value;
2399 +
2400 + $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2401 +
2402 + if ( is_object( $row ) ) {
2403 + $value = $row->option_value;
2404 + } else {
2405 + return apply_filters( "ultp_default_option_{$option}", $default_value, $option );
2406 + }
2407 +
2408 + return apply_filters( "ultp_option_{$option}", maybe_unserialize( $value ), $option );
2409 + }
2410 +
2411 + /**
2412 + * Get Transient Value bypassing cache
2413 + * Inspired By WordPress Core get_transient
2414 + *
2415 + * @since v.3.1.6
2416 + * @param STRING $transient Transient Name.
2417 + * @return MIXED
2418 + */
2419 + public function get_transient_without_cache( $transient ) {
2420 + $transient_option = '_transient_' . $transient;
2421 + $transient_timeout = '_transient_timeout_' . $transient;
2422 + $timeout = $this->get_option_without_cache( $transient_timeout );
2423 +
2424 + if ( false !== $timeout && $timeout < time() ) {
2425 + delete_option( $transient_option );
2426 + delete_option( $transient_timeout );
2427 + $value = false;
2428 + }
2429 +
2430 + if ( ! isset( $value ) ) {
2431 + $value = $this->get_option_without_cache( $transient_option );
2432 + }
2433 +
2434 + return apply_filters( "ultp_transient_{$transient}", $value, $transient );
2435 + }
2436 +
2437 + /**
2438 + * Set transient without adding to the cache
2439 + * Inspired By WordPress Core set_transient
2440 + *
2441 + * @since v.3.1.6
2442 + * @param STRING $transient Transient Name.
2443 + * @param MIXED $value Transient Value.
2444 + * @param INTEGER $expiration Time until expiration in seconds.
2445 + * @return BOOL
2446 + */
2447 + public function set_transient_without_cache( $transient, $value, $expiration = 0 ) {
2448 + $expiration = (int) $expiration;
2449 +
2450 + $transient_timeout = '_transient_timeout_' . $transient;
2451 + $transient_option = '_transient_' . $transient;
2452 +
2453 + $result = false;
2454 +
2455 + if ( false === $this->get_option_without_cache( $transient_option ) ) {
2456 + $autoload = 'yes';
2457 + if ( $expiration ) {
2458 + $autoload = 'no';
2459 + $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2460 + }
2461 + $result = $this->add_option_without_cache( $transient_option, $value, $autoload );
2462 + } else {
2463 + /*
2464 + * If expiration is requested, but the transient has no timeout option,
2465 + * delete, then re-create transient rather than update.
2466 + */
2467 + $update = true;
2468 +
2469 + if ( $expiration ) {
2470 + if ( false === $this->get_option_without_cache( $transient_timeout ) ) {
2471 + delete_option( $transient_option );
2472 + $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2473 + $result = $this->add_option_without_cache( $transient_option, $value, 'no' );
2474 + $update = false;
2475 + } else {
2476 + update_option( $transient_timeout, time() + $expiration );
2477 + }
2478 + }
2479 +
2480 + if ( $update ) {
2481 + $result = update_option( $transient_option, $value );
2482 + }
2483 + }
2484 +
2485 + return $result;
2486 + }
2487 +
2488 + /**
2489 + * Add option without adding to the cache
2490 + * Inspired By WordPress Core set_transient
2491 + *
2492 + * @since v.3.1.6
2493 + * @param STRING $option option name.
2494 + * @param STRING $value option value.
2495 + * @param STRING $autoload whether to load WordPress startup.
2496 + * @return BOOL
2497 + */
2498 + public function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
2499 + global $wpdb;
2500 +
2501 + if ( is_scalar( $option ) ) {
2502 + $option = trim( $option );
2503 + }
2504 +
2505 + if ( empty( $option ) ) {
2506 + return false;
2507 + }
2508 +
2509 + wp_protect_special_option( $option );
2510 +
2511 + if ( is_object( $value ) ) {
2512 + $value = clone $value;
2513 + }
2514 +
2515 + $value = sanitize_option( $option, $value );
2516 +
2517 + /*
2518 + * Make sure the option doesn't already exist.
2519 + */
2520 +
2521 + if ( apply_filters( "ultp_default_option_{$option}", false, $option, false ) !== $this->get_option_without_cache( $option ) ) {
2522 + return false;
2523 + }
2524 +
2525 + $serialized_value = maybe_serialize( $value );
2526 + $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
2527 +
2528 + $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2529 + if ( ! $result ) {
2530 + return false;
2531 + }
2532 +
2533 + return true;
2534 + }
2535 +
2536 + /**
2537 + * Permission_check_for_restapi
2538 + *
2539 + * @since v.3.2.4
2540 + * @param STRING/Bool $post_id .
2541 + * @param STRING $cap STRING .
2542 + * @return BOOL
2543 + */
2544 + public function permission_check_for_restapi( $post_id = false, $cap = '' ) {
2545 + $cap = $cap ? $cap : 'edit_others_posts';
2546 + $is_passed = false;
2547 + if ( $post_id ) {
2548 + $post_author = (int) get_post_field( 'post_author', $post_id );
2549 + $is_passed = (int) get_current_user_id() === $post_author;
2550 + }
2551 + return $is_passed || current_user_can( $cap );
2552 + }
2553 +
2554 + /**
2555 + * Sanitize params
2556 + *
2557 + * @param MIXED $params Parameters to sanitize.
2558 + * @return array|bool|mixed|string
2559 + * @since v.4.0.0
2560 + */
2561 + public function ultp_rest_sanitize_params( $params ) {
2562 + if ( is_array( $params ) ) {
2563 + return array_map( array( $this, 'ultp_rest_sanitize_params' ), $params );
2564 + } elseif ( is_bool( $params ) ) {
2565 + return rest_sanitize_boolean( $params );
2566 + } elseif ( is_object( $params ) ) {
2567 + return $params;
2568 + } else {
2569 + return sanitize_text_field( $params );
2570 + }
2571 + }
2572 +
2573 + /**
2574 + * Get Adv Filter Data Attributes
2575 + *
2576 + * @param ARRAY|NULL $attr .
2577 + * @param ARRAY|NULL $filter_attributes .
2578 + * @return string
2579 + * @since v.3.2.5
2580 + */
2581 + public function get_adv_data_attrs( $attr, $filter_attributes = null ) {
2582 + // Adv Filter Integration.
2583 + $adv_filter_dataset = array();
2584 +
2585 + if ( $filter_attributes ) {
2586 + $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars( $filter_attributes['queryTaxValue'] ) . '"';
2587 + $adv_filter_dataset[] = 'data-filter-type="' . htmlspecialchars( $filter_attributes['queryTax'] ) . '"';
2588 +
2589 + $is_adv = isset( $filter_attributes['isAdv'] ) ? $filter_attributes['isAdv'] : 0;
2590 + $adv_filter_dataset[] = 'data-filter-is-adv="' . $is_adv . '"';
2591 +
2592 + if ( $is_adv ) {
2593 + if ( isset( $filter_attributes['queryAuthor'] ) ) {
2594 + $adv_filter_dataset[] = "data-filter-author='" . $filter_attributes['queryAuthor'] . "'";
2595 + }
2596 +
2597 + if ( isset( $filter_attributes['queryOrder'] ) ) {
2598 + $adv_filter_dataset[] = "data-filter-order='" . $filter_attributes['queryOrder'] . "'";
2599 + }
2600 +
2601 + if ( isset( $filter_attributes['queryOrderBy'] ) ) {
2602 + $adv_filter_dataset[] = "data-filter-orderby='" . $filter_attributes['queryOrderBy'] . "'";
2603 + }
2604 +
2605 + if ( isset( $filter_attributes['search'] ) ) {
2606 + $adv_filter_dataset[] = 'data-filter-search="' . $filter_attributes['search'] . '"';
2607 + }
2608 +
2609 + if ( isset( $filter_attributes['queryQuick'] ) && $filter_attributes['queryQuick'] ) {
2610 + $adv_filter_dataset[] = 'data-filter-adv-sort="' . $filter_attributes['queryQuick'] . '"';
2611 + }
2612 + }
2613 + }
2614 +
2615 + if ( $attr && isset( $attr['advFilterEnable'] ) && $attr['advFilterEnable'] ) {
2616 + $adv_filter_dataset[] = 'data-filter-is-adv="1"';
2617 + $adv_filter_dataset[] = 'data-filter-type="multiTaxonomy"';
2618 +
2619 + $data_filter_value = isset( $attr['filterValue'] ) && $attr['filterValue'] ? $attr['filterValue'] : '[]';
2620 + $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars( $data_filter_value ) . '"';
2621 +
2622 + $data_author = isset( $attr['queryAuthor'] ) && $attr['queryAuthor'] ? $attr['queryAuthor'] : '[]';
2623 + $adv_filter_dataset[] = 'data-filter-author="' . $data_author . '"';
2624 +
2625 + $data_order = isset( $attr['queryOrder'] ) && $attr['queryOrder'] ? $attr['queryOrder'] : 'DESC';
2626 + $adv_filter_dataset[] = 'data-filter-order="' . $data_order . '"';
2627 +
2628 + $data_orderby = isset( $attr['queryOrderBy'] ) && $attr['queryOrderBy'] ? $attr['queryOrderBy'] : 'date';
2629 + $adv_filter_dataset[] = 'data-filter-orderby="' . $data_orderby . '"';
2630 +
2631 + $adv_filter_dataset[] = 'data-filter-search="' . ( isset( $attr['querySearch'] ) ? $attr['querySearch'] : '' ) . '"';
2632 +
2633 + $adv_filter_dataset[] = 'data-filter-adv-sort="' . ( isset( $attr['queryQuick'] ) ? $attr['queryQuick'] : '' ) . '"';
2634 + }
2635 +
2636 + $adv_filter_dataset = implode( ' ', $adv_filter_dataset );
2637 + return $adv_filter_dataset;
2638 + }
2639 +
2640 + /**
2641 + * Custom Text kses
2642 + *
2643 + * @since v.4.0.2
2644 + * @param MIXED $extras .
2645 + * @return ARRAY|BOOL|MIXED|STRING
2646 + */
2647 + public function ultp_allowed_html_tags( $extras = array() ) {
2648 + $allowed = array(
2649 + 'a' => array(
2650 + 'href' => true,
2651 + 'title' => true,
2652 + ),
2653 + 'abbr' => array(
2654 + 'title' => true,
2655 + ),
2656 + 'b' => array(),
2657 + 'br' => array(),
2658 + 'blockquote' => array(
2659 + 'cite' => true,
2660 + ),
2661 + 'em' => array(),
2662 + 'i' => array(),
2663 + 'q' => array(
2664 + 'cite' => true,
2665 + ),
2666 + 'strong' => array(
2667 + 'class' => true,
2668 + 'style' => true,
2669 + ),
2670 + 'mark' => array(
2671 + 'class' => true,
2672 + 'style' => true,
2673 + ),
2674 + );
2675 +
2676 + return array_merge( $allowed, $extras );
2677 + }
2678 +
2679 + /**
2680 + * Allowed Block Tags
2681 + *
2682 + * @since v.4.0.2
2683 + * @param STRING $search Optional. Tag name to check.
2684 + * @return ARRAY|BOOL Returns array of allowed tags or bool if $search is provided.
2685 + */
2686 + public function ultp_allowed_block_tags( $search = '' ) {
2687 + $array_lists = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'p', 'div', 'section', 'article' );
2688 + return $search ? in_array( $search, $array_lists ) : $array_lists;
2689 + }
2690 +
2691 + /**
2692 + * Formats datasets for html
2693 + *
2694 + * @since v.4.0.2
2695 + *
2696 + * @param ARRAY $datasets .
2697 + * @return STRING
2698 + */
2699 + public function get_formatted_datasets( &$datasets ) {
2700 + $res = '';
2701 + foreach ( $datasets as $key => $value ) {
2702 + $res .= ' data-' . $key . '="' . $value . '" ';
2703 + }
2704 + return $res;
2705 + }
2706 +
2707 + /**
2708 + * Sanitizes attributes after running necessary checks
2709 + *
2710 + * @since v.4.1.0
2711 + *
2712 + * @param ARRAY $attr The attributes array to sanitize.
2713 + * @param STRING $key The key to check in the attributes array.
2714 + * @param callable|null $sanitize_callback Callback function to sanitize the value.
2715 + * @param MIXED $def_value Default value to return if key is not set.
2716 + * @return MIXED Sanitized value or default value.
2717 + */
2718 + public function sanitize_attr( &$attr, $key, $sanitize_callback = null, $def_value = '' ) {
2719 + return isset( $attr[ $key ] ) && $attr[ $key ] ?
2720 + (
2721 + $sanitize_callback ?
2722 + $sanitize_callback( $attr[ $key ] ) :
2723 + $attr[ $key ]
2724 + )
2725 + : $def_value;
2726 + }
2727 +
2728 + /**
2729 + * Checks if dynamic content is active
2730 + *
2731 + * @since v.4.1.1
2732 + *
2733 + * @param ARRAY $attr The attributes to check for dynamic content.
2734 + * @return BOOLEAN
2735 + */
2736 + public function is_dc_active( &$attr ) {
2737 + if ( class_exists( '\ULTP\DCService' ) ) {
2738 + return \ULTP\DCService::is_dc_active( $attr );
2739 + }
2740 + return false;
2741 + }
2742 +
2743 +
2744 + /**
2745 + * Checks all the taxonomy of a post type for a given slug. Returns the taxonomy
2746 + * if it exists.
2747 + *
2748 + * @since v.4.1.16
2749 + *
2750 + * @param STRING $post_type The post type.
2751 + * @param STRING $slug The slug.
2752 + * @return STRING|NULL The taxonomy name or null if not found.
2753 + */
2754 + public function get_taxonomy_by_term_slug( $post_type, $slug ) {
2755 + $taxonomies = get_object_taxonomies( $post_type );
2756 + foreach ( $taxonomies as $taxonomy ) {
2757 + $res = get_term_by( 'slug', $slug, $taxonomy );
2758 +
2759 + if ( ! empty( $res ) ) {
2760 + return $taxonomy;
2761 + }
2762 + }
2763 +
2764 + return null;
2765 + }
2766 + /**
2767 + * Resolve Icon Alias
2768 + *
2769 + * @since v.4.0.0
2770 + * @param STRING $icon_name The icon name or alias to resolve.
2771 + * @return STRING|FALSE Returns the resolved icon name or false if no alias found.
2772 + */
2773 + public function svg_icon_compatibility( $icon_name = '' ) {
2774 + if ( empty( $icon_name ) ) {
2775 + return 'warning_triangle_solid';
2776 + }
2777 + // Get icon aliases mapping
2778 + $icon_aliases = array(
2779 + // Arrow aliases
2780 + 'angle_bottom_left_line' => 'arrow_down_bottom_left_solid',
2781 + 'angle_bottom_right_line' => 'arrow_down_bottom_right_solid',
2782 + 'angle_top_left_line' => 'arrow_up_top_left_solid',
2783 + 'angle_top_right_line' => 'arrow_up_top_right_solid',
2784 + 'rightFillAngle' => 'right_triangle_angle_play_arrow_forward_solid',
2785 + 'leftAngle2' => 'arrow_left_previous_backward_chevron_line',
2786 + 'rightAngle2' => 'arrow_right_next_forward_chevron_line',
2787 + 'collapse_bottom_line' => 'arrow_down_dropdown_maximize_chevron_line',
2788 + 'arrowUp2' => 'arrow_up_dropdown_minimize_chevron_line',
2789 + 'longArrowUp2' => 'long_arrow_up_top_increase_solid',
2790 +
2791 + // Circle arrow aliases
2792 + 'arrow_left_circle_line' => 'arrow_left_backward_circle_line',
2793 + 'arrow_bottom_circle_line' => 'arrow_down_bottom_downward_circle_line',
2794 + 'arrow_right_circle_line' => 'arrow_right_forward_circle_line',
2795 + 'arrow_top_circle_line' => 'arrow_up_top_upward_circle_line',
2796 +
2797 + // Close/Cross aliases
2798 + 'close_circle_line' => 'cross_close_x_minimize_circle_line',
2799 + 'close_line' => 'cross_x_close_minimize_line',
2800 +
2801 + // Direction aliases
2802 + 'arrow_down_line' => 'arrow_down_bottom_downward_line',
2803 + 'leftArrowLg' => 'arrow_left_backward_line',
2804 + 'rightArrowLg' => 'arrow_left_forward_line',
2805 + 'arrow_up_line' => 'long_arrow_up_top_increase_line',
2806 +
2807 + // Solid direction aliases
2808 + 'down_solid' => 'arrow_down_bottom_downward_circle_solid',
2809 + 'right_solid' => 'arrow_right_forward_circle_solid',
2810 + 'left_solid' => 'arrow_left_backward_circle_solid',
2811 + 'up_solid' => 'arrow_up_top_upward_circle_solid',
2812 +
2813 + // Move aliases
2814 + 'bottom_right_line' => 'arrow_move_up_right_line',
2815 + 'bottom_left_line' => 'arrow_move_up_left_line',
2816 + 'top_left_angle_line' => 'arrow_move_down_left_line',
2817 + 'top_right_line' => 'arrow_move_down_right_line',
2818 +
2819 + // Utility aliases
2820 + 'at_line' => 'at_a_mail_line',
2821 + 'refresh' => 'refresh_reset_cycle_loop_infinity_line',
2822 + 'cart_line' => 'shopping_cart_line',
2823 + 'cart_solid' => 'add_plus_shopping_cart_solid',
2824 + 'cog_line' => 'settings_tool_function_line',
2825 + 'cog_solid' => 'settings_tool_function_solid',
2826 + 'clock' => 'clock_reading_time_1_line',
2827 + 'book' => 'book_line',
2828 + 'download_line' => 'download_1_line',
2829 + 'download_solid' => 'download_1_solid',
2830 + 'downlod_bottom_solid' => 'download_1_solid',
2831 +
2832 + // Visibility aliases
2833 + 'eye' => 'view_count_show_visible_eye_open_2_line',
2834 + 'hidden_line' => 'hidden_hide_invisible_line',
2835 +
2836 + // Location aliases
2837 + 'home_line' => 'home_house_line',
2838 + 'home_solid' => 'home_house_solid',
2839 + 'location_line' => 'location_gps_map_line',
2840 + 'location_solid' => 'location_gps_map_solid',
2841 +
2842 + // Emotion aliases
2843 + 'love_line' => 'heart_love_wishlist_favourite_line',
2844 + 'love_solid' => 'heart_love_wishlist_favourite_solid',
2845 +
2846 + // Media aliases
2847 + 'play_line' => 'play_media_video_circle_line',
2848 + 'videoplay' => 'right_triangle_angle_play_arrow_forward_solid',
2849 + 'left_angle_solid' => 'left_triangle_angle_arrow_backward_solid',
2850 +
2851 + // Shape aliases
2852 + 'caretArrow' => 'caret_up_top_triangle_angle_arrow_upward_solid',
2853 + 'rectangle_solid' => 'square_rounded_solid',
2854 + 'triangle_solid' => 'triangle_shape_solid',
2855 +
2856 + // Status aliases
2857 + 'restriction_line' => 'restriction_no_stop_line',
2858 + 'right_circle_line' => 'correct_save_check_circle_line',
2859 + 'save_line' => 'correct_save_check_line',
2860 + 'search_line' => 'search_magnify_line',
2861 + 'search_solid' => 'search_magnify_solid',
2862 +
2863 + // Warning aliases
2864 + 'notice_circle_solid' => 'warning_circle_solid',
2865 + 'notice_solid' => 'warning_triangle_solid',
2866 + 'warning_circle_line' => 'warning_circle_line',
2867 + 'warning_triangle_line' => 'warning_triangle_line',
2868 +
2869 + // Category aliases
2870 + 'cat1' => 'category_file_documents_1_solid',
2871 + 'cat2' => 'category_book_line',
2872 + 'cat3' => 'category_file_documents_2_line',
2873 + 'cat4' => 'category_file_documents_3_line',
2874 + 'cat5' => 'category_file_documents_3_solid',
2875 + 'cat6' => 'category_file_documents_4_line',
2876 + 'cat7' => 'category_book_line',
2877 +
2878 + // Comment aliases
2879 + 'commentCount1' => 'messege_comment_1_line',
2880 + 'commentCount2' => 'messege_comment_3_solid',
2881 + 'commentCount3' => 'messege_comment_3_line',
2882 + 'commentCount4' => 'messege_comment_6_line',
2883 + 'commentCount5' => 'messege_comment_7_line',
2884 + 'commentCount6' => 'messege_comment_8_line',
2885 + 'comment' => 'messege_comment_4_line',
2886 +
2887 + // Date aliases
2888 + 'date1' => 'calendar_date_4_line',
2889 + 'date2' => 'calendar_date_1_solid',
2890 + 'date3' => 'calendar_date_2_line',
2891 + 'date4' => 'calendar_date_4_solid',
2892 + 'date5' => 'calendar_date_3_line',
2893 + 'calendar' => 'calendar_date_3_line',
2894 +
2895 + // Reading time aliases
2896 + 'readingTime1' => 'clock_reading_time_3_line',
2897 + 'readingTime2' => 'clock_reading_time_2_line',
2898 + 'readingTime3' => 'book_reading_time_line',
2899 + 'readingTime4' => 'clock_reading_time_1_line',
2900 + 'readingTime5' => 'hourglass_timer_time_line',
2901 +
2902 + // Tag aliases
2903 + 'tag1' => 'tag_bookmark_save_favourite_mark_discount_sale_line',
2904 + 'tag2' => 'price_tag_label_category_sale_discount_solid',
2905 + 'tag3' => 'price_tag_label_category_sale_discount_line',
2906 + 'tag4' => 'price_tag_offer_sale_coupon_solid',
2907 + 'tag5' => 'price_tag_label_category_sale_discount_line',
2908 + 'tag6' => 'growth_increase_up_solid',
2909 +
2910 + // View count aliases
2911 + 'viewCount1' => 'view_count_show_visible_eye_open_1_line',
2912 + 'viewCount2' => 'view_count_show_visible_eye_open_2_line',
2913 + 'viewCount3' => 'view_count_show_visible_eye_open_3_line',
2914 + 'viewCount4' => 'view_count_show_visible_eye_open_4_solid',
2915 + 'viewCount5' => 'view_count_show_visible_eye_open_5_solid',
2916 + 'viewCount6' => 'view_count_show_visible_eye_open_5_solid',
2917 +
2918 + // Author aliases
2919 + 'author1' => 'author_user_human_1_line',
2920 + 'author2' => 'author_user_human_4_line',
2921 + 'author3' => 'author_user_human_4_solid',
2922 + 'author4' => 'author_user_human_4_line',
2923 + 'author5' => 'author_user_human_3_solid',
2924 + 'author6' => 'author_user_human_6_line',
2925 + 'user' => 'author_user_human_3_line',
2926 +
2927 + // Device aliases
2928 + 'desktop' => 'desktop_monitor_computer_line',
2929 + 'laptop' => 'laptop_computer_line',
2930 + 'tablet' => 'tablet_ipad_pad_line',
2931 + 'mobile' => 'mobile_smartphone_phone_line',
2932 +
2933 + // Emoji aliases
2934 + 'angry_line' => 'angry_emoji_line',
2935 + 'angry_solid' => 'angry_emoji_solid',
2936 + 'confused_line' => 'confused_emoji_line',
2937 + 'confused_solid' => 'confused_emoji_solid',
2938 + 'happy_line' => 'happy_emoji_line',
2939 + 'happy_solid' => 'happy_emoji_solid',
2940 + 'smile_line' => 'smile_emoji_line',
2941 + 'smile_solid' => 'smile_emoji_solid',
2942 +
2943 + // Social aliases
2944 + 'share_line' => 'social_community_line',
2945 + 'share' => 'share_social_solid',
2946 + 'apple_solid' => 'apple_logo_icon_solid',
2947 + 'android_solid' => 'android_logo_icon_solid',
2948 + 'google_solid' => 'google_logo_icon_solid',
2949 + 'messenger' => 'messenger_logo_icon_solid',
2950 + 'microsoft_solid' => 'microsoft_logo_icon_solid',
2951 + 'mail' => 'mail_email_messege_solid',
2952 + 'facebook' => 'facebook_logo_icon_solid',
2953 + 'twitter' => 'twitter_x_logo_icon_line',
2954 + 'link' => 'link_chains_line',
2955 +
2956 + // Misc aliases
2957 + 'media_document' => 'media_document',
2958 + 'arrowDown2' => 'arrow_down_dropdown_maximize_chevron_line',
2959 + 'setting' => 'settings_tool_function_solid',
2960 + 'upload_solid' => 'upload_1_solid',
2961 +
2962 + // Empty aliases for missing icons (return empty string)
2963 + 'correct_solid' => 'correct_save_check_circle_line',
2964 + 'dot_solid' => 'dot_circle_solid',
2965 + 'right_circle_solid' => 'correct_save_check_circle_solid',
2966 + 'full_screen' => 'full_screen_corners_out_solid',
2967 + 'zoom_in' => 'zoom_in_magnifying_glass_plus_line',
2968 + 'zoom_out' => 'zoom_out_magnifying_glass_minus_line',
2969 + 'gallery_indicator' => 'gallery_indicator_image_solid',
2970 + 'ascending' => 'sort_ascending_order_solid',
2971 + 'descending' => 'sort_descending_order_line',
2972 + 'unlink' => 'unlink_link_break_line',
2973 + 'rocket' => 'rocket_fly_boost_launch_pro_line',
2974 + 'unlock' => 'unlocked_open_security_solid',
2975 + 'connect' => 'plugin_connect_socket_integration_solid',
2976 + 'leftAngle' => 'arrow_left_previous_backward_chevron_line',
2977 + 'rightAngle' => 'right_triangle_angle_play_arrow_forward_line',
2978 + 'plus2' => '',
2979 + 'hamicon_1' => 'left_align_1_line',
2980 + // extra in assets\img\iconpack folder
2981 + 'hamicon_2' => 'hemicon_2_line',
2982 + 'hamicon_3' => 'hemicon_3_line',
2983 + 'hamicon_4' => 'hamicon_5_line',
2984 + 'hamicon_5' => 'hamicon_4_sloid',
2985 + 'hamicon_6' => 'hamicon_6_line',
2986 + 'instagram_solid' => 'instagram_logo_icon_solid',
2987 + 'linkedin' => 'linkedin_logo_icon_solid',
2988 + 'pause_solid' => 'pause_solid',
2989 + 'pinterest' => 'pinterest_logo_icon_solid',
2990 + 'reddit' => 'reddit_logo_icon_solid',
2991 + 'skype' => 'skype_logo_icon_solid',
2992 + 'tiktok_lite_solid' => 'tiktok_logo_icon_line',
2993 + 'tiktok_solid' => 'tiktok_logo_icon_circle_solid',
2994 + 'whatsapp' => 'whatsapp_logo_icon_solid',
2995 + 'wordpress_lite_solid' => 'wordpress_logo_icon_solid',
2996 + 'wordpress_solid' => 'wordpress_logo_icon_2_solid',
2997 + 'wrong_solid' => 'cross_close_x_minimize_circle_solid',
2998 + 'youtube_solid' => 'youtube_logo_icon_solid',
2999 + 'five_star_line' => 'star_rating_line',
3000 + 'rightAngleBold' => 'arrow_right_next_forward_chevron_line',
3001 + 'leftAngleBold' => 'arrow_left_previous_backward_chevron_line',
3002 + 'plus' => 'plus',
3003 + 'reset_left_line' => 'refresh_reset_cycle_loop_infinity_line',
3004 + );
3005 + // Return resolved alias or false if not found
3006 + return isset( $icon_aliases[ $icon_name ] ) ? $icon_aliases[ $icon_name ] : $icon_name;
3007 + }
415 3008 }