: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$htaccess_file = self::getHtaccessFile();
if (is_file($htaccess_file) && Themify_Filesystem::is_writable($htaccess_file)) {
if (themify_get_server() === 'iis') {//for iis we need to add webp mimeType
$iis_config = get_home_path() . 'web.config';
if (is_file($iis_config) && Themify_Filesystem::is_writable($iis_config)) {
$rules = trim(Themify_Filesystem::get_contents($iis_config));
if (!empty($rules) && strpos($rules, 'mimeType="image/webp"') === false) {
$replace = '<!--BEGIN_WEBP_OUTPUT_BY_THEMIFY-->
<mimeMap fileExtension=".webp" mimeType="image/webp"/>
<!--END_WEBP_OUTPUT_BY_THEMIFY-->';
if (preg_match_all('#\<staticContent\>#', $rules) > 0) {
$rules = preg_replace('#\<staticContent\>#', '<staticContent>' . $replace, $rules, 1);
$rules = preg_replace('#\<rewrite\>#', '<staticContent>' . $replace . '</staticContent><rewrite>', $rules, 1);
Themify_Filesystem::put_contents($iis_config, trim($rules));
$rules = trim(Themify_Filesystem::get_contents($htaccess_file));
$startOutputTag = '#BEGIN_GZIP_OUTPUT_BY_THEMIFY';
$endOutputTag = '#END_GZIP_OUTPUT_BY_THEMIFY';
$startGzipTag = '#BEGIN_GZIP_COMPRESSION_BY_THEMIFY';
$endGzipTag = '#END_GZIP_COMPRESSION_BY_THEMIFY';
$startWebTag = '#BEGIN_WEBP_OUTPUT_BY_THEMIFY';
$endWebTag = '#END_WEBP_OUTPUT_BY_THEMIFY';
if (strpos($rules, $startWebTag) === false) {
$rules = self::get_webp_support() . $rules;
} elseif (strpos($rules, $startWebTag) !== false) {
$startsAt = strpos($rules, $startWebTag);
$endsAt = strpos($rules, $endWebTag, $startsAt);
$textToDelete = substr($rules, $startsAt, ($endsAt + strlen($endWebTag)) - $startsAt);
$rules = str_replace($textToDelete, '', $rules);
if (strpos($rules, $startOutputTag) === false) {
$rules = self::get_gzip_htaccess() . $rules;
elseif (strpos($rules, $startOutputTag) !== false) {
$startsAt = strpos($rules, $startOutputTag);
$endsAt = strpos($rules, $endOutputTag, $startsAt);
$textToDelete = substr($rules, $startsAt, ($endsAt + strlen($endOutputTag)) - $startsAt);
$rules = str_replace($textToDelete, '', $rules);
if (strpos($rules, 'mod_deflate.c') === false && strpos($rules, 'mod_gzip.c') === false) {
$rules .= self::get_mod_rewrite();
elseif (strpos($rules, $startGzipTag) !== false) {
$startsAt = strpos($rules, $startGzipTag);
$endsAt = strpos($rules, $endGzipTag, $startsAt);
$textToDelete = substr($rules, $startsAt, ($endsAt + strlen($endGzipTag)) - $startsAt);
$rules = str_replace($textToDelete, '', $rules);
if ($hasChange === true) {
return Themify_Filesystem::put_contents($htaccess_file, trim($rules));
public static function getHtaccessFile():string{
$f=get_home_path() . '.htaccess';
$f=ABSPATH . '.htaccess';
public static function addCssToFile(string $handle, string $src,?string $ver = THEMIFY_VERSION, $position = false):bool {
if (self::$concateFile === null) {
if (!isset(self::$css[$handle])) {
if ($position === false) {
self::$css[$handle] = array('s' => $src, 'v' => $ver);
} elseif (isset(self::$css[$position])) {
$keys = array_keys(self::$css);
$index = array_search($position, $keys) + 1;
self::$css = array_slice(self::$css, 0, $index) + array($handle => array('s' => $src, 'v' => $ver)) + array_slice(self::$css, $index);
public static function addPreLoadJs(string $src,string $ver = THEMIFY_VERSION, string $importance = 'low'):array {
return self::addPreLoadMedia($src, 'preload', 'script', $ver, null, $importance);
public static function addPrefetchJs(string $src, string $ver = THEMIFY_VERSION, string $importance = 'low'):array {
return self::addPreLoadMedia($src, 'prefetch', 'script', $ver, null, $importance);
public static function addPreLoadCss(string $src, string $ver = THEMIFY_VERSION, $m = 'all', string $importance = ''):array {
return self::addPreLoadMedia($src, 'preload', 'style', $ver, $m, $importance);
public static function addPrefetchCss(string $src,string $ver = THEMIFY_VERSION, $m = 'all', string $importance = ''):array {
return self::addPreLoadMedia($src, 'prefetch', 'style', $ver, $m, $importance);
public static function addPreLoadMedia(string $src, string $rel = 'preload', string $type = 'image', $ver = '', $m = 'all', string $importance = ''):array {
if(!isset(self::$done[$src]) && ($rel!=='prefetch' || !isset(self::$preLoadMedia[$src]))){
self::$preLoadMedia[$src] = array('t' => $type, 'r' => $rel);
if ($type !== 'image' && $type !== 'font') {
self::$preLoadMedia[$src]['m'] = $m;
self::$preLoadMedia[$src]['v'] = $ver;
elseif($type==='image' && $ver!=='' && $ver!==null && $m!=='' && $m!==null && $m!=='all'){//ver is srcset, m sizes for image
self::$preLoadMedia[$src]['srcset'] = $ver;
self::$preLoadMedia[$src]['sizes'] = $m;
if ($importance !== '') {
self::$preLoadMedia[$src]['i'] = $importance;
return array('s'=>$src,'v'=>isset(self::$preLoadMedia[$src]['v'])?self::$preLoadMedia[$src]['v']:null);
public static function add_js($handle, $src, $deps, $ver, $in_footer = true) {
wp_enqueue_script($handle, $src, $deps, $ver, $in_footer);
public static function getKnownJs():array {
$isDefered=themify_check('setting-jquery', true)?true:(themify_check('setting-optimize-wc', true)?false:!themify_check('setting-defer-wc', true));
if ($isDefered===true && themify_is_woocommerce_active()) {
$arr = array('flexslider', 'wc-single-product', 'woocommerce', 'zoom', 'js-cookie', 'jquery-blockui', 'jquery-cookie', 'jquery-payment', 'prettyPhoto', 'prettyPhoto-init', 'select2', 'selectWoo', 'wc-address-i18n', 'wc-add-payment-method', 'wc-cart', 'wc-cart-fragments', 'wc-checkout', 'wc-country-select', 'wc-credit-card-form', 'wc-add-to-cart', 'wc-add-to-cart-variation', 'wc-geolocation', 'wc-lost-password', 'wc-password-strength-meter', 'photoswipe', 'photoswipe-ui-default', 'wc-add-to-cart-composite');
//Authorize.Net Gateway for WooCommerce
if (function_exists('wc_authorize_net_cim')) {
$arr[] = 'wc-authorize-net-cim';
$arr[] = 'wc-authorize-net-apple-pay';
$arr[] = 'wc-authorize-net-my-payment-methods';
$arr[] = 'sv-wc-payment-gateway-payment-form-v5_8_1';
$arr[] = 'sv-wc-payment-gateway-my-payment-methods-v5_8_1';
$arr[] = 'sv-wc-jilt-prompt-customers';
$arr[] = 'sv-wc-apple-pay-v5_8_1';
if (defined('WOOCOMMERCE_GATEWAY_EWAY_VERSION')) {//plugin eWAY WooCommerce gateway
$arr[] = 'eway-credit-card-form';
if (defined('WPCF7_PLUGIN')) {
$arr[] = 'contact-form-7';
if (defined('SBI_PLUGIN_DIR')) {//plugin instagram feed
$arr[] = 'sb_instagram_scripts';
if (defined('LP_PLUGIN_FILE')) {//plugin learnpress
$arr[] = 'lp-plugins-all';
$arr[] = 'learn-press-enroll';
$arr[] = 'become-a-teacher';
public static function removeWebp($dir = null) {
$dir = themify_upload_dir('basedir');
if (!Themify_Filesystem::is_dir($dir) || !Themify_Filesystem::is_readable($dir)) {
return array('error' => sprintf(__('The directory %s doesn`t exist or not readable', 'themify'), $dir));
$arr = array('.png', '.jpg', '.jpeg','.gif');
$files = scandir($dir,SCANDIR_SORT_NONE);
foreach ($files as $value) {
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (!Themify_Filesystem::is_dir($path)) {
if (pathinfo($path, PATHINFO_EXTENSION) === 'webp') {
if (Themify_Filesystem::is_file(str_replace('.webp', $v, $path))) {
Themify_Filesystem::delete($path,'f');
} elseif ($value !== '.' && $value !== '..') {
* Load assets required by Themify framework
public static function loadMainScript() {
//Enqueue main js that will load others needed js
global $wp_scripts, $wp_version;
if (!isset($wp_scripts->registered['themify-main-script']) && empty($_GET['legacy-widget-preview'])) { /* disable in Block widget preview */
wp_enqueue_script('themify-main-script', THEMIFY_URI . '/js/main.js', array('jquery'), THEMIFY_VERSION, true);
'breakpoints' => themify_get_breakpoints(),
'ajax_url' => admin_url('admin-ajax.php'),
'map_key' => wp_strip_all_tags( themify_builder_get('setting-google_map_key', 'builder_settings_google_map_key') ?: '' ),
'bing_map_key' =>wp_strip_all_tags( themify_builder_get('setting-bing_map_key', 'builder_settings_bing_map_key') ?: '' ),
'plugin_url'=>rtrim(plugins_url(),'/'),
'content_url'=>content_url(),
'includes_url' => trailingslashit( includes_url() )
if (!themify_is_lazyloading()) {
if (self::$themeVersion !== null) {
$themeSrc = THEME_URI . '/js/themify-script.js';
$args['theme_v'] = self::$themeVersion;
self::addPrefetchJs($themeSrc, self::$themeVersion);
$args['emailSub']=__('Check this out!', 'themify');
$args['nop']=__('Check this out!', 'themify');
$args['lightbox']=themify_lightbox_vars_init();
if (is_user_logged_in()) {
$args['pg_opt_updt'] = __('Update', 'themify');
if (current_user_can('edit_posts')) {
$args['lgi'] = __('Your uploaded image is too large (%w x %hpx). Please resize it below 1600px and re-upload it.', 'themify');
$post_type = get_post_type_object(get_post_type());
$t = $post_type ? $post_type->labels->singular_name : __('Page', 'themify');
$args['pg_opt_t'] = sprintf('%s %s', $t, __('Options', 'themify'));
if (!empty($wp_scripts->registered['wp-embed'])) {
$wp_scripts->done[] = 'wp-embed';
if (self::$themeVersion !== null) {
global $wp_styles, $wp_filter;
if (isset($wp_filter['wp_head'], $wp_filter['wp_head']->callbacks[7], $wp_filter['wp_head']->callbacks[7]['print_emoji_detection_script'])) {
add_filter('wp_resource_hints', array(__CLASS__, 'remove_emoji_prefetch'), 100, 2);
if (themify_check('setting-emoji', true)) {
$src = apply_filters('script_loader_src', includes_url('js/wp-emoji-release.min.js'), 'concatemoji');
print_emoji_detection_script();
self::$localiztion['wp_emoji'] = trim(str_replace(array('<script type="text/javascript">', '<script>', '</script>'), array('', ''), ob_get_clean()));
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_filter('embed_head', 'print_emoji_detection_script');
self::$localiztion['menu_point'] = self::$mobileMenuActive;
if (is_singular() && comments_open() && get_option('thread_comments') == 1) {
self::$localiztion['commentUrl'] = home_url($wp_scripts->registered['comment-reply']->src);
$wp_scripts->done[] = 'comment-reply';
$wp_scripts->done[] = 'wp-playlist';
if (apply_filters('wp_video_shortcode_library', 'mediaelement') === 'tf_lazy') {
if (!empty($wp_scripts->registered['mediaelement-core'])) {
$wp_scripts->done[] = 'mediaelement-core';
$wp_scripts->done[] = 'mediaelement-migrate';
$wp_scripts->done[] = 'wp-mediaelement';
if (!empty($wp_styles->registered['wp-mediaelement'])) {
$wp_styles->done[] = 'wp-mediaelement';
$wp_styles->done[] = 'mediaelement';
self::$localiztion += $args;
if (!self::$localiztion['bing_map_key']) {
unset(self::$localiztion['bing_map_key']);
if (!self::$localiztion['map_key']) {
unset(self::$localiztion['map_key']);
public static function remove_emoji_prefetch(array $urls, string $relation_type):array {
if ($relation_type === 'dns-prefetch') {
remove_filter('wp_resource_hints', array(__CLASS__, 'remove_emoji_prefetch'), 100);
foreach ($urls as $k => $v) {
if (strpos('core/emoji/', $v) !== false) {
public static function addLocalization($key, $val, $type = false, $object_val = true) {
if (self::$localiztion !== null) {
if (!isset(self::$localiztion[$key])) {
self::$localiztion[$key] = $val;
self::$localiztion[$key] = array();
self::$localiztion[$key][] = $val;
self::$localiztion[$key][$val] = $object_val;
self::$localiztion[$key] = $val;
} elseif ($type === 'arr') {
self::$localiztion[$key][] = $val;
self::$localiztion[$key][$val] = $object_val;
public static function getLocalization():array {
return self::$localiztion;
public static function loadGalleryCss() {
self::add_css('tf_wp_gallery', self::THEMIFY_CSS_MODULES_URI . 'gallery.min.css', null, THEMIFY_VERSION);
public static function preFetchMasonry() {
self::addPrefetchJs(THEMIFY_URI . '/js/modules/isotop.js');
public static function loadFluidMasonryCss($in_footer = false) {
if (!isset(self::$css['tf_fluid_masonry'])) {
self::add_css('tf_fluid_masonry', self::THEMIFY_CSS_MODULES_URI . 'fluid-masonry.css', null, THEMIFY_VERSION, null, $in_footer);
self::addLocalization('done', 'tf_fluid_masonry', true);
public static function loadAutoTilesCss() {
self::loadGridCss('auto_tiles');
public static function loadinfiniteCss() {
if (!isset(self::$css['tf_infinite'])) {
self::add_css('tf_infinite', self::THEMIFY_CSS_MODULES_URI . 'infinite.css', null, THEMIFY_VERSION, null, true);
self::addLocalization('done', 'tf_infinite', true);
public static function loadThemeStyleModule(string $file, $media = '',bool $in_footer = false) {
self::add_css('tf_theme_' . str_replace('/', '_', $file), self::$THEME_CSS_MODULES_URI . $file . '.css', null, self::$themeVersion, $media, $in_footer);
public static function loadThemeWCStyleModule(string $file, $media = '',bool $in_footer = false) {
self::add_css('tf_theme_wc_' . str_replace('/', '_', $file), self::$THEME_WC_CSS_MODULES_URI . $file . '.css', null, self::$themeVersion, $media, $in_footer);
public static function loadGridCss(string $grid, bool $in_footer = false) {
if (!isset(self::$css['tf_grid_' . $grid]) && in_array($grid, array('list-post', 'grid2-thumb', 'grid2', 'grid3', 'grid4', 'grid5', 'grid6', 'list-large-image', 'list-thumb-image', 'auto_tiles'), true)) {
if ($grid === 'auto_tiles') {
self::addPrefetchJs(THEMIFY_URI . '/js/modules/auto-tiles.js');
self::add_css('tf_grid_' . $grid, THEMIFY_URI . '/css/grids/' . $grid . '.css', null, THEMIFY_VERSION, null, $in_footer);
if (isset(self::$theme_css_support[$grid]) && self::$THEME_CSS_MODULES_DIR !== null) {
self::add_css('tf_grid_theme_' . $grid, self::$THEME_CSS_MODULES_URI . 'grids/' . $grid . '.css', null, self::$themeVersion, null, $in_footer);
self::addLocalization('done', 'tf_grid_theme_' . $grid, true);
self::addLocalization('done', 'tf_grid_' . $grid, true);
public static function loadGoogleFonts() {
if (!defined('THEMIFY_GOOGLE_FONTS') || THEMIFY_GOOGLE_FONTS == true) {
$fonts = apply_filters('themify_google_fonts', self::$googleFonts);
foreach ($fonts as $font) {
if (!empty($font) && preg_match('/^\w/', $font)) {
/* fix the delimiter with multiple weight variants, it should use `,` and not `:`
reset the delimiter between font name and first variant */
$font = preg_replace('/,/', ':', str_replace(':', ',', $font), 1);
$key = explode(':', $font)[0];
if (!isset($res[$key])) {
if (strpos($font, ',') !== false || strpos($font, ':') !== false) {
$font = str_replace(array($key . ':', $key), array('', ''), explode(',', $font));
/* when loading either italic or non-italic variant, make sure other variant is loaded too */
$res[$key][] = strpos( $f, 'i' ) !== false ? (int) $f : $f . 'i';
foreach ($res as $k => $v) {
$fonts[] = $k . ':' . implode(',', array_keys( array_flip($v)));
$fonts = implode('%7C', $fonts);
$path = '://fonts.googleapis.com/css?family=' . $fonts . '&display=swap';
$_key=Themify_Storage::getHash($fonts);
$css =Themify_Storage::get($_key,'tf_fg_css_');
$resp = wp_remote_get('https' . $path, array(
'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
$css = wp_remote_retrieve_body($resp);
/* validate response's content type */
$content_type = wp_remote_retrieve_header( $resp, 'content-type' );
if ( is_wp_error( $css ) || strpos( $content_type, 'text/css' ) === false ) {
if ($css && strpos($css,'fonts.gstatic')!==false) {
$donwload=themify_builder_check('setting-gf','setting-gf');
$split=explode('@font-face',$css);
require_once ABSPATH . 'wp-admin/includes/image.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/media.php';
add_filter('wp_handle_sideload_overrides',array(__CLASS__,'sideload_overrides_google_fonts'),9999,1);
if($v!=='' && $v[0]==='{'){
$v=explode(';', str_replace(array('{','}'),'',$v));
$props=explode(':',str_replace('https:','',$styles));
if(isset($props[0],$props[1])){
$value=explode(' ',$value)[0];
$value=trim(str_replace(array('url',')','('),'',trim($value)));
elseif($prop==='unicode-range'){
$value=str_replace(' ', '', $value);
elseif(isset($props[0])){
$arr['subset']=trim($props[0]);