: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/***************************************************************************
* ----------------------------------------------------------------------
* ----------------------------------------------------------------------
* ----------------------------------------------------------------------
***************************************************************************/
defined( 'ABSPATH' ) || exit;
$themify_ajax_actions = array(
'required_plugins_modal',
foreach($themify_ajax_actions as $action){
add_action('wp_ajax_themify_' . $action, 'themify_' . $action);
//Show 404 page in autocomplete
function themify_get_404_pages(){
if ( ! empty( $_POST['term'] ) && current_user_can( 'manage_options' ) ) {
'sort_column' => 'post_title',
's'=> sanitize_text_field($_POST['term']),
'ignore_sticky_posts'=>true,
'update_post_term_cache'=>false,
'update_post_meta_cache'=>false,
'post_status' => 'publish',
add_filter( 'posts_search', 'themify_posts_where', 10, 2 );
$terms = new WP_Query($args);
if($terms->have_posts()){
while ($terms->have_posts()){
$items[] = array('value'=> get_the_ID(),'label'=> get_the_title());
echo wp_json_encode($items);
//Search only by post title
function themify_posts_where($search,$wp_query ){
if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
$q = $wp_query->query_vars;
$n = ! empty( $q['exact'] ) ? '' : '%';
$search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $wpdb->esc_like( implode(' ',$q['search_terms']) ) . $n );
if ( ! is_user_logged_in() )
$search[] = "$wpdb->posts.post_password = ''";
$search = ' AND ' . implode( ' AND ', $search );
* Handles theme settings import via file
function themify_import_settings() {
if ( ! current_user_can( 'manage_options' ) ) {
check_ajax_referer( 'themify_import_settings' );
if ( ! empty( $_POST['data'] ) ) {
$data = stripslashes( $_POST['data'] );
$data = is_serialized( $data ) ? unserialize( $data, [ 'allowed_classes' => false ] ) : json_decode( $data, true );
if ( ! empty( $data ) ) {
themify_set_data( $data );
* AJAX - Plupload execution routines
function themify_plupload() {
if( ! current_user_can( 'upload_files' ) ) {
$imgid = $_POST['imgid'];
check_ajax_referer( $imgid . 'themify-plupload' );
/** Decide whether to send this image to Media. @var String */
$add_to_media_library = isset( $_POST['tomedia'] ) ? $_POST['tomedia'] : false;
/** If post ID is set, uploaded image will be attached to it. @var String */
$postid = isset( $_POST['topost'] )? $_POST['topost'] : '';
/** Handle file upload storing file|url|type. @var Array */
$file = wp_handle_upload($_FILES[$imgid . 'async-upload'], array('test_form' => true, 'action' => 'themify_plupload'));
// if $file returns error, return it and exit the function
if ( isset( $file['error'] ) && ! empty( $file['error'] ) ) {
wp_send_json_error( $file['error'] );
'image' => [ 'jpg', 'jpeg', 'gif', 'png', 'ico', 'svg' ],
'audio' => [ 'mp3', 'm4a', 'ogg', 'wav', 'wma' ],
'video' => [ 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv' ],
'font' => [ 'woff', 'woff2', 'ttf', 'otf', 'svg', 'eot' ]
// let's see if it's a valid file type
$extension = pathinfo( $file['file'], PATHINFO_EXTENSION );
if ( ! in_array( $extension, $allowed_extensions[ $type ], true ) ) {
Themify_Filesystem::delete( $file['file'], 'f' );
wp_send_json_error( __( 'Invalid file type.', 'themify' ) );
if( 'tomedia' === $add_to_media_library ){
// Insert into Media Library
// Set up options array to add this file as an attachment
'post_mime_type' => sanitize_mime_type($file['type']),
'post_title' => str_replace('-', ' ', sanitize_file_name(pathinfo($file['file'], PATHINFO_FILENAME))),
'post_status' => 'inherit'
$attach_id = wp_insert_attachment( $attachment, $file['file'], $postid );
$attach_id = wp_insert_attachment( $attachment, $file['file'] );
$file['id'] = $attach_id;
// Common attachment procedures
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $file['file'] );
wp_update_attachment_metadata($attach_id, $attach_data);
$full = wp_get_attachment_image_src( $attach_id, 'full' );
update_post_meta($postid, $_POST['fields'], $full[0]);
update_post_meta($postid, '_'.$_POST['fields'] . '_attach_id', $attach_id);
/* Return URL for the image field in meta box */
if ( $type === 'image' ) {
$thumb = wp_get_attachment_image_src( $attach_id, 'thumbnail' );
$file['thumb'] = $thumb[0];
$file['type'] = $extension;
wp_send_json_success( $file );
* AJAX - Save user settings
check_ajax_referer( 'tf_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
$previous_data = themify_get_data();
$temp = themify_normalize_save_data( $_POST['data'] );
unset($temp['tmp_cache_network'],$temp['tmp_cache_concte_network'],$temp['tmp_regenerate_all_css']);
themify_set_data( $temp );
_e('Your settings were saved', 'themify');
Themify_Enqueue_Assets::$mobileMenuActive !== intval( $temp['setting-mobile_menu_trigger_point'] )
|| ( isset( $previous_data['skin'] ) && $previous_data['skin'] !== $temp['skin'])
|| ( isset( $previous_data['setting-header_design'] ) && $previous_data['setting-header_design'] !== $temp['setting-header_design'])
|| ( isset( $previous_data['setting-exclude_menu_navigation'] ) && $previous_data['setting-exclude_menu_navigation'] !== $temp['setting-exclude_menu_navigation'])
Themify_Enqueue_Assets::clearConcateCss();
/* clear webP image cache when changing image quality */
if ( (empty( $previous_data['setting-gf'] ) && !empty($temp['setting-gf'])) || (!empty( $previous_data['setting-gf'] ) && empty($temp['setting-gf']))) {
Themify_Storage::deleteByPrefix('tf_fg_css_');
/* clear google fonts cache*/
if ( class_exists( 'Themify_Builder_Stylesheet',false ) ) {
$breakpoints=themify_get_breakpoints('all',true);
foreach ( $breakpoints as $bp=>$v ) {
if ( isset( $previous_data["setting-customizer_responsive_design_{$bp}"] ) && $previous_data["setting-customizer_responsive_design_{$bp}"] !== $temp["setting-customizer_responsive_design_{$bp}"] ) {
Themify_Builder_Stylesheet::regenerate_css_files();
if(themify_get_server()==='nginx'){
if(empty($temp['setting-webp'])){
Themify_Enqueue_Assets::removeWebp();
$isDev=!empty($temp['setting-dev-mode']);
$gzip=$isDev?true:empty($temp['setting-cache_gzip']);
$browser=$isDev?true:empty($temp['setting-cache_browser']);
Themify_Enqueue_Assets::rewrite_htaccess($gzip,empty($temp['setting-webp']),$browser);
if(empty($temp['setting-dev-mode'])){
TFCache::create_config($temp);
TFCache::disable_cache();
TFCache::clear_3rd_plugins_cache();
do_action( 'themify_settings_save' );
function themify_normalize_save_data($data){
$data = explode('&', $data);
$temp[$v[0]] = urldecode( str_replace('+',' ',preg_replace_callback('/%([0-9a-f]{2})/i', 'themify_save_replace_cb', urlencode($v[1]))) );
/* cleanup Hook Content data, remove empty hooks */
if ( ! empty( $temp['setting-hooks_field_ids'] ) ) {
$ids = json_decode( $temp['setting-hooks_field_ids'] );
foreach ( $ids as $id ) {
if ( empty( $temp["setting-hooks-{$id}-code"] ) ) {
unset( $temp["setting-hooks-{$id}-code"], $temp["setting-hooks-{$id}-location"], $temp["setting-hooks-{$id}-r"], $temp["setting-hooks-{$id}-visibility"] );
$temp['setting-hooks_field_ids'] = json_encode( $new_ids );
* Replace callback for preg_replace_callback used in themify_save().
* @param array $matches 0 complete match 1 first match enclosed in (...)
* @return string One character specified by ascii.
function themify_save_replace_cb( $matches ) {
return chr( hexdec( $matches[1] ) );
function themify_reset_settings(){
check_ajax_referer( 'tf_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
$temp_data = themify_normalize_save_data($_POST['data']);
foreach($temp_data as $key => $val){
// Don't reset if it's not a setting or the # of social links or a social link or the Hook Contents
if(strpos($key, 'setting') === false || strpos($key, 'hooks') || strpos($key, 'link_field_ids') || strpos($key, 'themify-link') || strpos($key, 'custom_css')){
$temp['setting-script_minification'] = 'disable';
print_r(themify_set_data($temp));
function themify_add_link_field(){
check_ajax_referer( 'tf_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
if( isset($_POST['fid']) ) {
$type = isset( $_POST['type'] )? $_POST['type'] : 'image-icon';
echo themify_add_link_template( 'themify-link-'.$hash, array(), true, $type);
* Set image from wp library
function themify_media_lib_browse() {
if ( ! wp_verify_nonce( $_POST['media_lib_nonce'], 'media_lib_nonce' ) ) die(-1);
if ( ! current_user_can( 'upload_files' ) ) {
$postid = $_POST['post_id'];
$attach_id = $_POST['attach_id'];
$full = wp_get_attachment_image_src( $attach_id, 'full' );
if( $_POST['featured'] ){
//Set the featured image for the post
set_post_thumbnail($postid, $attach_id);
update_post_meta($postid, $_POST['field_name'], $full[0]);
update_post_meta($postid, '_'.$_POST['field_name'] . '_attach_id', $attach_id);
$thumb = wp_get_attachment_image_src( $attach_id, 'thumbnail' );
//Return URL for the image field in meta box
$file['thumb'] = $thumb[0];
function themify_clear_all_webp(){
check_ajax_referer('tf_nonce', 'nonce');
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_success(Themify_Enqueue_Assets::removeWebp());
function themify_clear_all_concate(){
check_ajax_referer('tf_nonce', 'nonce');
if ( ! current_user_can( 'manage_options' ) ) {
if(!empty($_POST['all'])){
$data = themify_normalize_save_data($_POST['data']);
if(!empty($data['tmp_cache_concte_network'])){
Themify_Enqueue_Assets::clearConcateCss($type);
function themify_clear_all_menu(){
check_ajax_referer('tf_nonce', 'nonce');
if ( ! current_user_can( 'manage_options' ) ) {
TFCache::clear_3rd_plugins_cache();
themify_clear_menu_cache();
function themify_clear_all_html(){
check_ajax_referer('tf_nonce', 'nonce');
if ( ! current_user_can( 'manage_options' ) ) {
$data = themify_normalize_save_data($_POST['data']);
if(!empty($data['tmp_cache_network'])){
TFCache::remove_cache($type);
function themify_clear_gfonts(){
check_ajax_referer('tf_nonce', 'nonce');
if ( ! current_user_can( 'manage_options' ) ) {
Themify_Storage::deleteByPrefix('tf_fg_css_');
add_action('wp_ajax_nopriv_themify_search_autocomplete','themify_search_autocomplete');
function themify_search_autocomplete(){
$s = sanitize_text_field($_POST['s']);
global $query,$found_types;
if(!empty($_POST['post_type'])){
$post_types = array(sanitize_text_field($_POST['post_type']));
if(true===themify_is_woocommerce_active() && 'product' === themify_get( 'setting-search_post_type','all',true )){
$post_types = array('product');
$post_types = Themify_Builder_Model::get_post_types();
unset($post_types['attachment']);
$post_types=array_keys($post_types);
'post_type'=>$post_types,
'post_status'=>'publish',
$query_args = apply_filters('themify_search_args',$query_args);
$query = new WP_Query( $query_args );
while ( $query->have_posts() ){
$post_type = get_post_type();
if (($key = array_search($post_type, $query_args['post_type'])) !== false) {
unset($query_args['post_type'][$key]);
$found_types[]=$post_type;
if(empty($query_args['post_type'])){
include( THEMIFY_DIR.'/includes/search-box-result.php' );
/*Load More Ajax - Used for module ajax load more*/
if(!function_exists('themify_ajax_load_more')){
function themify_ajax_load_more(){
if(!empty($_POST['module']) && !empty($_POST['id'])){
$builder_id=(int)($_POST['id']);
$mod_id=str_replace('tb_','',$_POST['module']);
$data = Themify_Builder::get_builder_modules_list( (int)$_POST['id'] );
if ( ! empty( $data ) ) {
foreach ( $data as $module ) {