: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* * *************************************************************************
* ----------------------------------------------------------------------
* ----------------------------------------------------------------------
* ----------------------------------------------------------------------
* ************************************************************************* */
exit; // Exit if accessed directly
/************************************************************************** */
function themify_clear_menu_cache() {
$wpdb->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 );
if ( ! empty( $image_meta['sizes'] ) ) {
foreach ( $image_meta['sizes'] as $key => $value ) {
/* image size is smaller than what we need, skip */
if ( $width > $value['width'] || $height > $value['height'] ) {
$pixels = $value['width'] * $value['height'];
if ( $last_pixel_count === 0 || $pixels < $last_pixel_count ) {
$last_pixel_count = $pixels;
* 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 <img> tag and optional content prepended and/or appended
function themify_get_image($args):string {
'disable_responsive' => false,
'field_name' => 'post_image,image,wp_thumb,feature_image',
'fallback' => ''//when there is no image
foreach ($arr as $k => $v) {
} elseif ($v === 'false') {
* Post ID for single, query or archive views.
* Page ID is stored separately in $themify->page_id.
* URL of the image to use
$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] : '';
} 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
$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)) {
} 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);
// 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
foreach (explode(',', $args['field_name']) as $field) {
if ($img_url = get_post_meta($post_id, trim($field), true))
} 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);
foreach (explode(',', $args['field_name']) as $field) {
if ($img_url = get_post_meta($post_id, trim($field), true)) {
if ($height !== '' && 0 === ((int) $height )) {
/** 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']);
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'];
$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);
$start = strpos($content, '<' . $tag, 0);
$pos = substr($content, $start);
$end = strpos($pos, '>');
$temp = themify_prep_image(substr($pos, 0, $end + 1));
$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));
$img_url = esc_url($auto_image_url);
} elseif ($temp = themify_do_img($auto_image_url, $width, $height, (bool) $args['crop'])) {
unset($content, $upload_dir);
if (isset($temp['is_large']) && current_user_can('edit_post', $post_id)) {
$args['class'] .= ' tf_large_img';
if ($args['preload'] !== false || $args['prefetch'] !== false) {
Themify_Enqueue_Assets::addPreLoadMedia($img_url, $args['preload'] !== false ? 'preload' : 'prefetch');
themify_generateWebp($img_url);
$out = '<img src="' . $img_url . '"';
if ($width !== '' && $width !== 0) {
$out .= ' width="' . $width . '"';
if ($height !== '' && $height !== 0) {
$out .= ' height="' . $height . '"';
if ($attachment_id != 0) {
$args['class'] .= ' wp-post-image wp-image-' . $attachment_id; /* add attachment_id class to img tag */
if ($args['class'] !== '') {
$out .= ' class="' . trim($args['class']) . '"';
if ($args['style'] !== '') {
$out .= ' style="' . $args['style'] . '"';
if (!empty($args['alt'])) {
$out_alt = $attachment_id ? get_post_meta($attachment_id, '_wp_attachment_image_alt', true) : '';
$out_alt = !empty($args['title']) ? $args['title'] : '';
if (!$out_alt && $attachment_id) {
$p = get_post($attachment_id);
$out_alt = !empty($p) ? $p->post_title : '';
$out_alt = the_title_attribute('echo=0');
if($args['title'] !== false ){
if (!empty($args['title'])) {
} elseif ($attachment_id) {
$p = get_post($attachment_id);
// Add title attribute only if explicitly set in $args
$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) . '"';
$out .= ' alt="' . esc_attr($out_alt) . '"';
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 .= "<meta itemprop=\"width\" content=\"{$width}\"><meta itemprop=\"height\" content=\"{$height}\"><meta itemprop=\"url\" content=\"{$img_url}\">" . $out;
$out = $args['before'] . $out . $args['after'];
if (!function_exists('themify_edit_link')) {
function themify_edit_link(string $title = '') : bool {
$is = is_user_logged_in() && (!class_exists('Themify_Builder_Model',false) || !Themify_Builder::$frontedit_active === true) && !themify_is_rest();
$title = sprintf( __('Edit %s', 'themify'), '<span class="tf_hide">' . get_post_type_object( get_post_type() )->labels->singular_name . '</span>' );
edit_post_link($title, '<span class="edit-button tf_edit_post_' . get_the_ID() . '">', '</span>');
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.
function themify_image_url(bool $echo = false, string $size = 'full', $attachment_id = null):string {
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);
$url = apply_filters('themify_image_url', $url);
* Image Helper - Prep Image
function themify_prep_image(string $tag):array {
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']);
* Vimeo / Youtube Thumbnail grab
function themify_video_image(string $url):string {
$image_url = parse_url($url);
if ($image_url['host'] === 'www.youtube.com' || $image_url['host'] === 'youtube.com') {
parse_str($image_url['query'], $query);
if (!empty($query['v'])) {
$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'])) {
$path = explode('/', $image_url['path']);
$id = $path[(count($path) - 1)];
$content = Themify_Filesystem::get_contents('https://vimeo.com/api/v2/video/' . $id . '.php');
$hash = unserialize($content);
$return_url = $hash[0]["thumbnail_large"];
* Checks if a value referenced by $var exists in theme settings or post meta data.
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.
function themify_get(string $var, $default = null, bool $data_only = false) {
$data = themify_get_data();
if (isset($data[$var]) && $data[$var] !== '') {