query("DELETE FROM $wpdb->options WHERE `option_name` LIKE ('_transient_tf_menu_%')"); return Themify_Storage::deleteByPrefix('tf_menu_'); } /** * Image Helper - Echoes themify_get_image * @param string $args Format string. */ function themify_image($args) {//deprecated use themify_get_image echo themify_get_image($args); } function themify_find_nearest_image_size(?int $attachment_id,int $width,int $height ) : string { $image_meta = wp_get_attachment_metadata( $attachment_id ); $size = ''; if ( ! empty( $image_meta['sizes'] ) ) { $last_pixel_count = 0; foreach ( $image_meta['sizes'] as $key => $value ) { /* image size is smaller than what we need, skip */ if ( $width > $value['width'] || $height > $value['height'] ) { continue; } /* find smallest size */ $pixels = $value['width'] * $value['height']; if ( $last_pixel_count === 0 || $pixels < $last_pixel_count ) { $last_pixel_count = $pixels; $size = $key; } } } return $size; } /** * Returns the post image, either from Themify Custom Panel fields or from WordPress Featured Image. * @param string|array $args Format string. * @return string String with tag and optional content prepended and/or appended */ function themify_get_image($args):string { global $themify; /** * List of parameters * @var array */ $defaults = array( 'src' => '', 'class' => '', 'style' => '', 'preload' => false, 'prefetch' => false, 'lazy_load' => true, 'is_slider' => false, 'disable_responsive' => false, 'w' => '', // width 'h' => '', // height 'before' => '', 'after' => '', 'alt' => '', 'title' => '', 'crop' => true, 'field_name' => 'post_image,image,wp_thumb,feature_image', 'urlonly' => false, 'image_size' => '', 'image_meta' => false, 'f_image' => false, 'attr' => array(), 'fallback' => ''//when there is no image ); if (is_string($args)) { $arr = array(); parse_str($args, $arr); $args = array(); foreach ($arr as $k => $v) { if ($v === 'true') { $args[$k] = true; } elseif ($v === 'false') { $args[$k] = false; } else { $args[$k] = $v; } } } $args+=$defaults; unset($defaults); /** * Post ID for single, query or archive views. * Page ID is stored separately in $themify->page_id. * @var string */ $post_id = get_the_ID(); /** * URL of the image to use * @var string */ $img_url = ''; /** * Image width * @var string */ $width = $args['w']; if ($width !== '') { $width = (int) $width; } /** * Image height * @var string */ $height = $args['h']; if ($height !== '') { $height = (int) $height; } $attachment_id = 0; $is_disabled = themify_is_image_script_disabled(); if (is_numeric($args['src'])) { $attachment_id = $args['src']; $img = wp_get_attachment_image_src($attachment_id, 'large'); $args['src'] = !empty($img[0]) ? $img[0] : ''; unset($img); } elseif ($args['fallback'] !== '' && empty($args['src']) && !has_post_thumbnail()) { $args['src'] = $args['fallback']; } if ($is_disabled === true) { // Use WP standard image sizes if (!empty($args['image_size'])) { // If image_size parameter is set $feature_size = $args['image_size']; } elseif (!empty($themify->image_size)) { // or if Themify::image_size is set $feature_size = $themify->image_size; } elseif (empty($themify->is_shortcode) && in_the_loop()) { // Main query area if (is_single()) { $feature_size = get_post_meta($post_id, 'feature_size', true); if (empty($feature_size) || 'blank' === $feature_size) { $feature_size = themify_get('setting-image_post_single_feature_size', null, true); } } elseif (!empty($themify->page_id) && !empty($themify->query_post_type) && themify_is_query_page()) { $feature_size = get_post_meta($themify->page_id, $themify->query_post_type . 'feature_size_page', true); if (empty($feature_size)) { $feature_size = null; } } elseif (is_archive() || is_tax() || is_search() || is_home()) { $feature_size = themify_get('setting-image_post_feature_size', null, true); } } if (!empty($args['src'])) { $attachment_id = themify_get_attachment_id_from_url($args['src']); } if (!isset($feature_size) || 'blank' === $feature_size) { $feature_size = $attachment_id && ! empty( $width ) && ! empty( $height ) ? themify_find_nearest_image_size( $attachment_id, $width, $height ) : ''; if ( $feature_size === '' ) { $feature_size = apply_filters('themify_global_feature_size', themify_get('setting-global_feature_size', 'large', true)); } } if (!empty($attachment_id)) { $tmp = wp_get_attachment_image_src($attachment_id, $feature_size); if (!empty($tmp)) { $img_url = $tmp[0]; } unset($tmp); } if ($img_url === '') { // Set URL to use for final output. $img_url = empty($args['src']) ? themify_image_url(false, $feature_size) : $args['src']; $img_url = trim($img_url); // Fix for showing feature_image when Themify Image Script is disabled if ('' === $img_url) { foreach (explode(',', $args['field_name']) as $field) { if ($img_url = get_post_meta($post_id, trim($field), true)) break; } } } } else { // Use Image Script if (empty($args['src'])) { if (has_post_thumbnail()) { $img_url = $width !== '' && $height !== '' ? ((int) get_post_thumbnail_id()) : get_the_post_thumbnail_url(); /* Image script works with thumbnail IDs as well as URLs, use ID which is faster */ } elseif ('attachment' === get_post_type()) { $img_url = wp_get_attachment_url($post_id); } else { foreach (explode(',', $args['field_name']) as $field) { if ($img_url = get_post_meta($post_id, trim($field), true)) { break; } } } } else { $img_url = $args['src']; } if ($height !== '' && 0 === ((int) $height )) { $height = 0; $args['crop'] = false; } /** filter $img_url before it goes off to themify_do_img for processing * */ $img_url = apply_filters('themify_get_image_before_do_img', $img_url, $width, $height, $args); // Set URL to use for final output. $temp = themify_do_img((empty($attachment_id) ? $img_url : $attachment_id), $width, $height, (bool) $args['crop']); $img_url = $temp['url']; if ($temp['width'] !== '' && $temp['height'] !== '') { $width = (int) $temp['width']; $height = (int) $temp['height']; } // Get title/alt text by attachment id if it was returned. if (!$attachment_id && isset($temp['attachment_id'])) { $attachment_id = $temp['attachment_id']; } } if ($attachment_id) { $attachment_id = themify_maybe_translate_object_id($attachment_id); } // No image was defined, parse content to find the first image. if (empty($img_url) && ($args['f_image'] || themify_check('setting-auto_featured_image', true) )) { $content = get_the_content(); $upload_dir = themify_upload_dir('baseurl'); foreach ( [ 'img', 'iframe' ] as $tag) { $count = substr_count($content, '<' . $tag); if ($count >= 1) { $start = strpos($content, '<' . $tag, 0); $pos = substr($content, $start); $end = strpos($pos, '>'); $temp = themify_prep_image(substr($pos, 0, $end + 1)); $src = $temp['src']; $parse = parse_url($src); if (!empty($parse['query'])) { $src = str_replace('?' . $parse['query'], '', $src); } $auto_image_url = isset($temp['src']) ? $temp['src'] : ''; if (isset($temp['class'])) { $args['class'] .= ' ' . $temp['class']; } $args['alt'] = $temp['alt']; if ($is_disabled === true) { $img_url = themify_image_url(false, $feature_size, themify_get_attachment_id_from_url($auto_image_url, $upload_dir)); if (empty($img_url)) { $img_url = esc_url($auto_image_url); } } elseif ($temp = themify_do_img($auto_image_url, $width, $height, (bool) $args['crop'])) { $img_url = $temp['url']; } break; } } unset($content, $upload_dir); } if (!empty($img_url)) { if (isset($temp['is_large']) && current_user_can('edit_post', $post_id)) { $args['class'] .= ' tf_large_img'; } else { if ($args['preload'] !== false || $args['prefetch'] !== false) { Themify_Enqueue_Assets::addPreLoadMedia($img_url, $args['preload'] !== false ? 'preload' : 'prefetch'); } themify_generateWebp($img_url); } unset($temp); if ($args['urlonly']) { $out = $img_url; } else { // Build final image $out = 'post_title : ''; $p = null; } if (!$out_alt) { $out_alt = the_title_attribute('echo=0'); } $title = $out_alt; } } if($args['title'] !== false ){ if ($title === '') { if (!empty($args['title'])) { $title = $args['title']; } elseif ($attachment_id) { $p = get_post($attachment_id); if (!empty($p)) { $title = $p->post_title; } $p = null; } } // Add title attribute only if explicitly set in $args if (!empty($title)) { $out .= ' title="' . esc_attr($title) . '"'; } } if ($args['lazy_load'] === false || $args['lazy_load'] === 'eager') { $out .= ' data-tf-not-load="1"'; if ($args['lazy_load'] === 'eager') { $out .= ' loading="eager" decoding="auto"'; } } if (!empty($args['attr'])) { foreach ($args['attr'] as $k => $v) { $out .= ' ' . $k . '="' . esc_attr($v) . '"'; } } if (!empty($out_alt)) { $out .= ' alt="' . esc_attr($out_alt) . '"'; } $out .= '>'; if ($attachment_id && $args['disable_responsive'] === false) { $out = function_exists('wp_filter_content_tags') ? wp_img_tag_add_srcset_and_sizes_attr($out, null, $attachment_id) // WP 5.5 : wp_make_content_images_responsive($out); } if (($args['is_slider'] === true || $themify->post_layout === 'slider') && $args['lazy_load'] === true) { $out = themify_make_lazy($out, false); } if ($args['image_meta'] == true) { $out .= "" . $out; } $out = $args['before'] . $out . $args['after']; } } else { $out = ''; } return $out; } if (!function_exists('themify_edit_link')) { function themify_edit_link(string $title = '') : bool { static $is = null; if ($is === null) { $is = is_user_logged_in() && (!class_exists('Themify_Builder_Model',false) || !Themify_Builder::$frontedit_active === true) && !themify_is_rest(); } if ($is === true) { if ($title === '') { $title = sprintf( __('Edit %s', 'themify'), '' . get_post_type_object( get_post_type() )->labels->singular_name . '' ); } edit_post_link($title, '', ''); } return $is; } } if (!function_exists('themify_image_url')) { /** * Returns the featured image url * @param bool $echo Specify to echo or return the url * @param string $size The image size to return * @param null|int $attachment_id ID of image to load. * @return void|string */ function themify_image_url(bool $echo = false, string $size = 'full', $attachment_id = null):string { $url = ''; if (has_post_thumbnail()) { $image = wp_get_attachment_image_src(get_post_thumbnail_id(), $size); $url = $image === false ? '' : $image[0]; } elseif ($attachment_id !== null) { $image = wp_get_attachment_image_src($attachment_id, $size); if ($image) { $url = $image[0]; } } $url = apply_filters('themify_image_url', $url); if ($echo) { echo esc_url($url); return ''; } return $url; } } /** * Image Helper - Prep Image * @param $tag * @return array */ function themify_prep_image(string $tag):array { $image = []; preg_match_all( '/(alt|title|src|class)=(("|\')[^("|\')]*("|\'))/i', $tag, $image_reg ); foreach ( $image_reg[1] as $index => $attribute ) { $image[ $attribute ] = substr( $image_reg[2][ $index ], 1, -1 ); } $image += [ 'src' => '', 'alt' => '', 'title' => '' ]; if (strpos($image['src'], 'youtube.com') !== false || strpos($image['src'], 'vimeo.com') !== false) { $image['src'] = themify_video_image($image['src']); } $image['src'] = preg_replace('/(-\d+x\d+)(?=\.\w{3,4})/', '', $image['src']); return $image; } /** * Vimeo / Youtube Thumbnail grab * * @param $url * * @return string */ function themify_video_image(string $url):string { $image_url = parse_url($url); $return_url = ''; if ($image_url['host'] === 'www.youtube.com' || $image_url['host'] === 'youtube.com') { parse_str($image_url['query'], $query); if (!empty($query['v'])) { $id = $query['v']; } else { $path = explode('/', $image_url['path']); $id = $path[count($path) - 1]; } $return_url = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg'; } elseif ($image_url['host'] === 'www.vimeo.com' || $image_url['host'] === 'vimeo.com' || $image_url['host'] === 'player.vimeo.com') { parse_str($image_url['query'], $query); if (!empty($query['clip_id'])) { $id = $query['clip_id']; } else { $path = explode('/', $image_url['path']); $id = $path[(count($path) - 1)]; } $content = Themify_Filesystem::get_contents('https://vimeo.com/api/v2/video/' . $id . '.php'); if (!empty($content)) { $hash = themify_maybe_unserialize( $content ); if ( ! is_array( $hash ) ) { $hash = array(); } if (!empty($hash[0])) { $return_url = $hash[0]["thumbnail_large"]; } } } return $return_url; } /** * Checks if a value referenced by $var exists in theme settings or post meta data. * @param $var * @return bool */ function themify_check(string $var, bool $data_only = false):bool { $val = themify_get($var, null, $data_only); return $val !== null && $val !== '' && $val !== 'off'; } /** * Returns a value referenced by $var checking in theme settings or post meta data. * @param $var * @return mixed */ function themify_get(string $var, $default = null, bool $data_only = false) { $data = themify_get_data(); if (isset($data[$var]) && $data[$var] !== '') { return $data[$var]; } elseif ($data_only !== true) { global $post; if (themify_is_shop() && !in_the_loop()) { $id = themify_shop_pageId(); } elseif (is_object($post)) { $id = $post->ID; } else { $id = false; } $val = ( $id !== false && $id !== 0 ) ? get_post_meta($id, $var, true) : ''; if ($val !== '') { return $val; } } return $default; } /** * Returns a value referenced by $meta,$var checking in theme settings or post meta data. * @param $meta - post meta * @param $var - theme settings * @param $default * @return mixed */ function themify_get_both(string $meta, string $var, $default = null) { $val = themify_get($meta); if ($val === null || $val === 'default') { $val = themify_get($var, $default, true); } return $val; } /** * Get a color value, uses themify_get and sanitizes the value * * @return string */ function themify_get_color_both(string $meta, string $var, $default = null) { $val = themify_get_color($meta); if ($val === null || $val === 'default') { $val = themify_get_color($var, $default, true); } return $val; } /** * Returns a value referenced by $meta,$var checking in theme settings or post meta data. * @param $meta - post meta * @param $var - theme settings * @return mixed */ function themify_check_both(string $meta, string $var):bool { $val = themify_get($meta, null); if ($val === null || $val === 'default') { $val = themify_get($var, null, true); } return $val !== null && $val !== '' && $val !== 'off'; } function themify_shop_pageId() { static $id = null; if ($id === null) { if (themify_is_woocommerce_active() && function_exists( 'wc_get_page_id' ) ) { $id = wc_get_page_id('shop'); if ($id <= 0) {//wc bug, page id isn't from wc settings,the default should be page with slug 'shop' $page = get_page_by_path('shop'); $id = !empty($page) ? (int) $page->ID : false; } } else { $id = false; } } return $id; } /** * Get a color value, uses themify_get and sanitizes the value * * @return string */ function themify_get_color(string $var, $default = null, bool $data_only = false) { $value = themify_get($var, $default, $data_only); if ( $value === null || false === $value || '' === $value ) { return $value; } $value = trim( (string) $value ); if ( '' === $value ) { return $value; } if ( 0 === stripos( $value, 'var(' ) ) { return $value; } if ( 0 === strpos( $value, '--' ) ) { return 'var(' . $value . ')'; } return themify_sanitize_hex_color( $value ); } /** * Sanitize a string to ensure it's valid hex color code * * @since 3.1.2 */ function themify_sanitize_hex_color($value) { if ($value===null || false === $value) { return $value; } $value = ltrim($value, '#'); /* match 3 to 6 hex digits */ if (preg_match('|^([A-Fa-f0-9]{3}){1,2}$|', $value)) { $value = '#' . $value; } return $value; } if (!function_exists('themify_get_image_sizes_list')) { /** * Return list of image sizes with labels for translation. * @param bool $nested * @return mixed|void * @since 1.6.8 */ function themify_get_image_sizes_list(bool $nested = true) { $size_names = apply_filters('image_size_names_choose', array( 'thumbnail' => __('Thumbnail', 'themify'), 'medium' => __('Medium', 'themify'), 'large' => __('Large', 'themify'), 'full' => __('Original Image', 'themify') ) ); $out = array( array('value' => 'blank', 'name' => ''), ); foreach ($size_names as $size => $label) { $out[] = array('value' => $size, 'name' => $label); } return apply_filters('themify_get_image_sizes_list', $nested ? $out : $size_names, $nested); } } /** * Check if the site is using an HTTPS scheme and returns the proper url * @param String $url requested url * @return String * @since 1.1.5 */ function themify_https_esc(string $url = ''):string { if (is_ssl()) { $url = str_replace('http:', 'https:', $url); } return $url; } /** * Returns an array with the post types managed by Themify, * where the Themify Custom Panel is initialized. * Filterable using themify_post_types * @param Array $types additional post types * @return Array * @since 1.1.5 */ function themify_post_types(array $types = array()):array { $defaults = array_merge(array('post', 'page'), apply_filters('themify_specific_post_types', array('menu', 'slider', 'highlight', 'portfolio', 'testimonial', 'section')), $types); if (themify_is_themify_theme() && themify_is_woocommerce_active() && is_file(THEME_DIR . '/admin/post-type-product.php')) { $defaults[] = 'product'; } return array_keys(array_flip(apply_filters('themify_post_types', $defaults))); } if (!function_exists('themify_options_module')) { /** * Returns list of '; } } else { foreach ($options as $option) { $option = esc_attr($option); $selected = $sel === $option ? ' selected="selected"' : ''; $output .= ''; } } return $output; } } if (!function_exists('themify_lightbox_vars_init')) { /** * Post Gallery lightbox/fullscreen and single lightbox definition * @return array Lightbox/Fullscreen galleries initialization parameters */ function themify_lightbox_vars_init():array { $gallery_lightbox = themify_get('setting-gallery_lightbox', 'lightbox', true); // Lightbox default settings $overlay_args = array(); if (themify_check('setting-lightbox_content_images', true)) { $overlay_args['contentImagesAreas'] = '.post, .type-page, .type-highlight, .type-slider'; } if (themify_check('setting-lightbox_disable_share', true)) { $overlay_args['disable_sharing'] = true; } if ($gallery_lightbox === 'none') { $overlay_args['gallerySelector'] = ''; } $overlay_args = apply_filters('themify_gallery_plugins_args', $overlay_args); // sanitize contentImagesAreas, ensure it's a valid CSS selector if (isset($overlay_args['contentImagesAreas'])) { $overlay_args['contentImagesAreas'] = trim($overlay_args['contentImagesAreas'], ','); } $overlay_args['i18n'] = array( 'tCounter' => __('%curr% of %total%', 'themify'), ); return $overlay_args; } } if (!function_exists('themify_get_shortcode_template')) { /** * Returns markup * @param $posts * @param string $slug * @param string $name * @return mixed|void */ function themify_get_shortcode_template($posts, string $slug = 'includes/loop', string $name = 'index', array $args = array()):string { global $post, $themify; Themify_Enqueue_Assets::loadGridCss($themify->post_layout); if (is_object($post)){ $saved_post = clone $post; } if(property_exists($themify, 'is_shortcode')){ $isShortcode = $themify->is_shortcode === true; $themify->is_shortcode = true; } // Add flag that template loop is in builder loop if (class_exists('\Themify_Builder',false)) { $isLoop = Themify_Builder::$is_loop; Themify_Builder::$is_loop = true; } // get_template_part, defined in wp-includes/general-template.php $templates = array(); if ('' !== $name) { $templates[] = "{$slug}-{$name}.php"; } $templates[] = "{$slug}.php"; $template_file = apply_filters('themify_get_shortcode_template_file', locate_template($templates, false, false), $slug, $name); $isSlider = $themify->post_layout === 'slider' || (isset($args['isSlider']) && $args['isSlider'] === true); ob_start(); if (!empty($template_file)) { $before = isset($args['before_post']) ? $args['before_post'] : ''; $after = isset($args['after_post']) ? $args['after_post'] : ''; foreach ($posts as $p) { $post=$p; setup_postdata($post); if ($isSlider === true) { echo '
'; } echo $before; include $template_file; echo $after; if ($isSlider === true) { echo '
'; } } $posts = null; } if (isset($saved_post)) { $post = $saved_post; setup_postdata($saved_post); unset($saved_post); } // Add flag that template loop is in builder loop if (isset($isLoop)) { Themify_Builder::$is_loop = $isLoop; } if(isset($isShortcode)){ $themify->is_shortcode = $isShortcode; } $res=ob_get_clean(); return $res?$res:''; } } if (!function_exists('themify_resolve_gallery_shortcode_string')) { /** * Expand wrapper shortcodes (e.g. ACF) that return a literal [gallery ids="..."] string. * Stops before WordPress would render [gallery] to HTML. * * @param string|null $shortcode Raw field value from Builder (may be [acf_...] or [gallery ...]). * @return string String containing [gallery ... ids=...] when resolvable, otherwise original/expanded text. */ function themify_resolve_gallery_shortcode_string(?string $shortcode): string { if ($shortcode === null || $shortcode === '') { return ''; } $shortcode = trim($shortcode); if (strpos($shortcode, '[') === false) { return $shortcode; } // Already a gallery shortcode with ids — do not run do_shortcode() or core will output HTML. if (preg_match('/\[gallery\s+[^\]]*ids\s*=/i', $shortcode)) { return $shortcode; } $prev = ''; for ($i = 0; $i < 8; ++$i) { if ($shortcode === $prev) { break; } $prev = $shortcode; $next = do_shortcode($shortcode); if ($next === $shortcode) { break; } $shortcode = $next; if (preg_match('/\[gallery\s+[^\]]*ids\s*=/i', $shortcode)) { break; } } return $shortcode; } } if (!function_exists('themify_get_gallery_shortcode')) { /** * Get images from gallery shortcode * @return object */ function themify_get_gallery_shortcode(?string $shortcode):array { if ($shortcode) { $shortcode = themify_resolve_gallery_shortcode_string($shortcode); preg_match('/\[gallery.*ids.*?=.(.*).\]/si', $shortcode, $ids); if (isset($ids[1])) { $ids = trim($ids[1], '\\'); $ids = trim($ids, '"'); $image_ids = explode(',', $ids); // Check if post has more than one image in gallery return get_posts(array( 'post__in' => $image_ids, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1, 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'orderby' => themify_get_gallery_shortcode_params($shortcode, 'orderby', 'post__in'), 'order' => themify_get_gallery_shortcode_params($shortcode, 'order', 'ASC') )); } } return array(); } } if (!function_exists('themify_get_gallery_shortcode_params')) { /** * Get gallery shortcode options * @param $shortcode * @param $param */ function themify_get_gallery_shortcode_params(string $shortcode, string $param = 'link', $default = '') { $shortcode = themify_resolve_gallery_shortcode_string($shortcode); $pattern = '/\[gallery .*?(?=' . $param . ')' . $param . '=.([^\']+)./si'; preg_match($pattern, $shortcode, $out); $out = isset($out[1]) ? explode('"', $out[1]) : array(''); return $out[0] !== '' ? $out[0] : $default; } } function themify_get_additional_image_sizes(string $size = 'all', $default = false) { $allSizes = wp_get_additional_image_sizes(); if ($size === 'all') { return $allSizes; } return isset($allSizes[$size]) ? $allSizes[$size] : $default; } if (!function_exists('themify_get_all_terms_ids')) { /** * Returns all IDs from the given taxonomy * @param string $tax Taxonomy to retrieve terms from. * @return array $term_ids Array of all taxonomy terms * @since 1.5.6 */ function themify_get_all_terms_ids(string $tax = 'category') { if (!$term_ids = wp_cache_get('all_' . $tax . '_ids', $tax)) { $term_ids = get_terms(array('taxonomy' => $tax, 'fields' => 'ids', 'get' => 'all')); wp_cache_add('all_' . $tax . '_ids', $term_ids, $tax); } return $term_ids; } } if (!function_exists('themify_is_touch')) { /** * According to what $check parameter specifies to check, returns true if it's a phone, tablet, or both. * @param string $check * @return mixed * @since 1.6.8 */ function themify_is_touch($check = 'all') { static $arr = array(); if (!isset($arr[$check])) { if (!class_exists('Themify_Mobile_Detect',false)) { require_once 'class-themify-mobile-detect.php'; } $detect = new Themify_Mobile_Detect(); $is_tablet = isset($arr['tablet']) ? $arr['tablet'] : $detect->isTablet(); $is_mobile = isset($arr['phone']) ? $arr['phone'] : (wp_is_mobile() || $detect->isMobile()); $arr = array( 'phone' => $is_mobile && !$is_tablet, 'tablet' => $is_tablet, 'all' => $is_mobile ); $detect = null; } return $arr[$check]; } } /** * Checks that status of the image script. * @return bool * @since 1.7.4 */ function themify_is_image_script_disabled():bool { static $is = null; if ($is === null) { $is = wp_image_editor_supports() ? themify_check('setting-img_settings_use', true) : false; } return $is; } if (!function_exists('themify_get_available_menus')) { /** * Returns available navigation menus. * * @since 1.9.5 * * @return array */ function themify_get_available_menus():array { $out = array(array('name' => '', 'value' => '', 'selected' => true)); $menus = get_terms(array( 'taxonomy' => 'nav_menu', 'hide_empty' => false, )); if (!empty($menus) && !is_wp_error($menus)) { foreach ($menus as $menu) { $out[] = array('name' => $menu->name, 'value' => $menu->slug); } } return apply_filters('themify_get_available_menus', $out); } } /** * Returns true if the active theme is using Themify framework * * @since 2.2.5 * @return bool */ function themify_is_themify_theme():bool { static $is = null; if ($is === null) { $is = is_file(trailingslashit(get_template_directory()) . 'themify/themify-utils.php'); } return $is; } if (!function_exists('themify_is_woocommerce_active')) { /** * Checks if Woocommerce plugin is active and returns the proper value * @return bool * @since 1.4.6 */ function themify_is_woocommerce_active():bool { static $is = null; if ($is === null) { $plugin = 'woocommerce/woocommerce.php'; include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); return is_plugin_active($plugin) // validate if $plugin actually exists, the plugin might be active however not installed. && is_file(trailingslashit(WP_PLUGIN_DIR) . $plugin); } return $is; } } /** * Calls is_shop() in a safe manner * * @note: this function should not be called before template_redirect. * * @since 2.9.0 */ function themify_is_shop($pageId = false):bool { static $is = null; if ($is === null) { $is = themify_is_woocommerce_active(); if ($is === true) { $is = is_post_type_archive('product') || ($pageId > 0 && $pageId === themify_shop_pageId()); //don't use shop function will give error if ($is === false) { $shop_url = themify_get_shop_permalink(); //wc bug, page id isn't set from wc settings,the default should be page with slug 'shop' if ($shop_url !== '') { $current_url = 'http'; if (is_ssl()) { $current_url .= 's'; } $current_url .= '://'; if (isset($_SERVER['HTTP_HOST'])) { $current_url .= $_SERVER['HTTP_HOST']; } else { $host = parse_url(home_url(), PHP_URL_HOST); if ($host !== false) { $current_url .= $host; } unset($host); } $current_url .= strtok($_SERVER['REQUEST_URI'], '?'); $is = $current_url === $shop_url; } else { $is = false; } } } } return $is; } /** * Modified version of wp_parse_args which adds filters to modify the args * * @return array * @since 2.7.7 */ function themify_parse_args($args, $defaults = '', $filter_key = '') { // Setup a temporary array from $args if (is_object($args)) { $r = get_object_vars($args); } elseif (is_array($args)) { $r = & $args; } else { wp_parse_str($args, $r); } // Passively filter the args before the parse if (!empty($filter_key)) { $r = apply_filters('themify_before_' . $filter_key . '_parse_args', $r); } // Parse if (is_array($defaults)) { $r = array_merge($defaults, $r); } // Aggressively filter the args after the parse if (!empty($filter_key)) { $r = apply_filters('themify_after_' . $filter_key . '_parse_args', $r); } // Return the parsed results return $r; } /** * Display the Builder's backend editor in Themify Custom Panel * * @return null * @since 2.8.8 */ function themify_meta_field_page_builder() { do_action('themify_builder_metabox'); } /** * Get an array of key => value pairs and outputs them as HTML attributes * * @since 2.9.1 * @return string */ function themify_get_element_attributes(array $props):string { $out = ''; foreach ($props as $k => $v) { $out .= ' ' . $k . '="' . esc_attr($v) . '"'; } return $out; } /** * Get breakpoints settings * if it's framework return customizer breakpoints,else if it's builder plugin builder breakpoints * @since 3.0.0 * @return mixed array/int */ function themify_get_breakpoints(string $select = 'all', bool $max_min = false) { static $res = array(); if (($select === 'all' && empty($res)) || (empty($res[$select]))) { $breakpoints = array( 'tablet_landscape' => array(769, 1280), 'tablet' => array(681, 768), 'mobile' => 680 ); if ($max_min === true) { return $breakpoints; } foreach ($breakpoints as $bp => $value) { $v = themify_builder_get('setting-customizer_responsive_design_' . $bp, 'builder_responsive_design_' . $bp); if ('' != $v) { if (is_array($value)) { $res[$bp] = array(); $res[$bp][0] = $value[0]; $res[$bp][1] = (int) $v; } else { $res[$bp] = (int) $v; } } else { $res[$bp] = $value; } } $res['tablet'][0] = $res['mobile'] + 1; $res['tablet_landscape'][0] = $res['tablet'][1] + 1; } return 'all' === $select ? $res : $res[$select]; } /** * Unserialize data if it is serialized * * If PHP supports it disables unserializing PHP objects in order to prevent object injection. * * @param string $original Maybe unserialized original, if is needed. * @return mixed Unserialized data can be any type. */ function themify_maybe_unserialize(string $original) { if (is_serialized($original)) { // don't attempt to unserialize data that wasn't serialized going in return @unserialize($original, array('allowed_classes' => false)); } return $original; } /** * Display the post video * Must be used inside the loop * * @since 2.7.3 */ function themify_post_video(string $url = '', bool $echo = true) { $video_file = $url ? $url : themify_get('video_url'); $output = ''; if (!empty($video_file)) { if ('mp4' !== pathinfo($video_file, PATHINFO_EXTENSION)) { global $wp_embed; $output = $wp_embed->run_shortcode('[embed]' . $video_file . '[/embed]'); } else { $output = '
'; $output .= do_shortcode('[video src="' . $video_file . '"]'); $output .= '
'; } } if ($echo === true) { echo $output; } else { return $output; } } function themify_get_embed(string $url, array $args):string { $reg = '#(vimeo\.com|youtu(be\.com|\.be|be))\/(shorts\/|video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(\&\S+)?\/?([A-Za-z0-9._%-]*)(\&\S+)?#i'; preg_match($reg, $url, $m); if (!empty($m) && isset($m[1], $m[4])) { $type = ($m[1] === 'youtube.com' || strpos($m[1], 'youtu') !== false) ? 'youtube' : ($m[1] === 'vimeo.com' || strpos($m[1], 'vimeo') ? 'vimeo' : false); if ($type !== false) { $id = $m[4]; $query_args = array(); if ($type !== 'youtube' && isset($m[6])) {//h query argument should be first in vimeo $query_args['h'] = $m[6]; } $query_args += array( 'pip' => 1, 'playsinline' => 1 ); $params = parse_url($url); if (!empty($params['query'])) { parse_str($params['query'], $output); unset($output['v']); $query_args += $output; unset($output); } if ($type === 'youtube') { $allow = 'accelerometer;encrypted-media;gyroscope;picture-in-picture;fullscreen'; $src = 'https://www.youtube'; if (!empty($args['privacy'])) { $src .= '-nocookie'; } $src .= '.com/embed/' . $id; if (!empty($args['start']) ) { $query_args['start'] = (float) $args['start']; } elseif (!empty($params['fragment'])) { $query_args['start'] = (float) $params['fragment']; if(empty($query_args['start'])){ unset($query_args['start']); } } if (!empty($args['end'])) { $query_args['end'] = (float) $args['end']; } } else { $allow = 'fullscreen'; $src = 'https://player.vimeo.com/video/' . $id; if (!empty($args['start'])) { $src .= '#t=' . $args['start']; } elseif (!empty($params['fragment'])) { $src .= '#' . $params['fragment']; } if (!empty($args['privacy'])) { $query_args['dnt'] = 1; } $query_args['byline'] =$query_args['title'] = $query_args['portrait'] = 0; } unset( $params, $query_args['modestbranding'], $query_args['controls'], $query_args['loop'], $query_args['mute'], $query_args['muted'] ); if (!empty($args['hide_controls'])) { $query_args['controls'] = 0; } if (!empty($args['loop'])) { $query_args['loop'] = 1; if (!isset($query_args['playlist'])) { $query_args['playlist'] = $id; } } if (!empty($args['autoplay']) || !empty($query_args['autoplay'])) { $allow .= ';autoplay'; $query_args['autoplay'] = 1; } if (!empty($args['muted'])) { if ($type === 'youtube') { $query_args['mute'] = 1; } else { $query_args['muted'] = 1; } } $lazy = !empty($args['disable_lazy']) ? ' data-no-script' : ''; $src .= '?' . http_build_query($query_args); $class=isset($args['class'])?$args['class']:'tf_abs tf_w tf_h'; return ''; } } return ''; } function themify_enque_style(string $handle,string $src = '',?array $deps = array(),?string $ver = THEMIFY_VERSION,?string $media = 'all', bool $in_footer = false) { Themify_Enqueue_Assets::add_css($handle, $src, $deps, $ver, $media, $in_footer); } function themify_enque_script(string $handle, string $src = '', string $ver = THEMIFY_VERSION,?array $deps = array(), bool $in_footer = true) { Themify_Enqueue_Assets::add_js($handle, $src, $deps, $ver, $in_footer); } if (!function_exists('themify_get_query_categories')) { function themify_get_query_categories():array { global $themify; $taxes = $themify->query_category == '0' ? themify_get_all_terms_ids($themify->query_taxonomy) : explode(',', str_replace(' ', '', $themify->query_category)); if (empty($taxes) || is_wp_error($taxes)) { $taxes= array(); } return $taxes; } } /** * Returns the URL to the WooCommerce Shop page * * @return string * @since 4.5.7 */ function themify_get_shop_permalink():string { static $link = null; if ($link === null) { $id = themify_shop_pageId(); $link = !empty($id) ? get_permalink($id) : ''; } return $link; } function themify_is_login_page():bool { static $is = null; if ($is === null) { global $pagenow; $is = !empty($pagenow) && in_array($pagenow, array('wp-login.php', 'wp-register.php'), true); } return $is; } function themify_is_ajax():bool { static $is = null; if ($is === null) { $is = defined('DOING_AJAX') || (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); } return $is; } function themify_is_rest():bool { static $is = null; if ($is === null) { $is = (defined('REST_REQUEST') && REST_REQUEST) || strpos($_SERVER['REQUEST_URI'], '/wp-json/') !== false; } return $is; } function themify_is_lazyloading():bool { static $is = null; if ($is === null) { $is = !themify_builder_check('setting-disable-lazy', 'performance-disable-lazy', true); if ($is === true) { global $wp_customize; $is = !is_admin() && themify_is_ajax() === false && !isset($_GET['tf-scroll']) && !isset($_GET['post_in_lightbox']) && themify_is_prefetch_request() === false && (!class_exists('Themify_Builder',false) || !Themify_Builder_Model::is_front_builder_activate()) && !( $wp_customize instanceof WP_Customize_Manager && $wp_customize->is_preview()); if ($is === true) { $is = apply_filters('tf_lazy_enable', true); } } else { add_filter('wp_lazy_loading_enabled', '__return_false', 100); } } return $is; } function themify_make_lazy(?string $html, bool $load = true):?string {//@todo move to class if (isset($html) && (strpos($html, ' src=') !== false || strpos($html, ' '', 'iframe' => '.*?<\/iframe>', 'audio' => '.*?<\/audio>', 'video' => '.*?<\/video>' ); $hasLazy = themify_is_lazyloading(); if($hasLazy===false){ unset($tags['img'],$tags['iframe']); } foreach ($tags as $k => $v) { if (strpos($html, '<' . $k) === false) { unset($tags[$k]); } } if (empty($tags)) { return $html; } if (isset($tags['img']) || isset($tags['iframe'])) {//skip noscript img/iframe preg_match_all('/