: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( isset( $module['element_id'], $module['mod_settings'] ) && $module['element_id'] === $mod_id ) {
if(!empty($mod_setting)){
$paged=(int)$_POST['page'];
$paged=$paged<1?1:$paged;
if(themify_is_themify_theme() && is_file(THEME_DIR.'/theme-options.php')){
require_once( THEME_DIR.'/theme-options.php' );
if(isset($themify) && method_exists($themify,'template_redirect')){
$themify->template_redirect();
Themify_Builder_Component_Module::template($mod_setting, $builder_id);
add_action('wp_ajax_nopriv_themify_ajax_load_more','themify_ajax_load_more');
function themify_required_plugins_modal() {
check_ajax_referer( 'tf_nonce', 'nonce' );
if(!current_user_can('manage_options')){
wp_send_json_error(__( 'You are not allowed to import data.','themify' ));
$required_plugins = !empty($_POST['plugins'])?sanitize_text_field($_POST['plugins']):'';
$result=array('plugins'=>array());
if( ! empty( $required_plugins )) {
$required_plugins = explode( ',', $required_plugins );
$all_plugins = get_plugins();
$can_install=current_user_can( 'install_plugins' ) ;
$themify_updater = class_exists('Themify_Updater',false)?Themify_Updater::get_instance():null;
foreach($required_plugins as $plugin){
$plugin_info = themify_get_known_plugin_info($plugin);
if($plugin_info!==false){
if(isset($all_plugins[$plugin_info['path']])){
if(is_plugin_active( $plugin_info['path'] )){
$plugin_info['active']=1;
elseif(current_user_can( 'activate_plugin', $plugin )){
$valid= function_exists('validate_plugin_requirements')?validate_plugin_requirements($plugin_info['path']):true;
if(is_wp_error( $valid )){
$plugin_info['error']=$valid->get_error_message();
$plugin_info['active']=0;
$plugin_info['error']=__( 'You are not allowed to activate this plugin.','themify' );
elseif($can_install===true){
$plugin_info['install']=$themify_updater===null || $themify_updater->has_error() || !empty($plugin_info['wp_hosted']) || $themify_updater->has_access( $plugin )?1:'buy';
$plugin_info['error']= __( 'You are not allowed to install plugins on this site.' ,'themify' );
unset($plugin_info['desc'],$plugin_info['image'],$plugin_info['path'],$plugin_info['wp_hosted']);
$result['plugins'][$plugin]=$plugin_info;
$result['plugins'][$plugin]=array(
'error'=> __( 'Unknown plugin.','themify' ),
unset($required_plugins,$all_plugins,$can_install);
'head'=>__( 'This demo requires these plugins/addons:', 'themify' ),
'import_warning'=>__( 'Proceed import without the required addons/plugins might show incomplete/missing content.', 'themify' ),
'proceed_import'=> __( 'Proceed Import', 'themify' ),
'erase'=>__( 'Erase ALL previously imported demo content', 'themify' ),
'modify'=> __( 'Keep modified posts/pages', 'themify' ),
'builder_img'=>__('Import Builder layout images (will take longer)','themify'),
'install'=>__( 'Install', 'themify' ),
'activate'=>__( 'Activate', 'themify' ),
'buy'=>__( 'Buy', 'themify' ),
'note'=>__('WARNING: Importing the demo content will override your Themify settings, menu and widget settings. It will also add the content (posts, pages, featured images, widgets, menus, etc.) to your site as per our demo setup. It is recommend to do on a fresh/development site.','themify'),
'activate_done'=>__('%plugin% successfully activated','themify'),
'activate_fail'=>__('Failed to activate %plugin%: %error%','themify'),
'install_fail'=>__('Failed to install %plugin%: %error%','themify'),
'install_done'=>__('%plugin% successfully installed','themify'),
'install'=>__('Installing %plugin%','themify'),
'activate'=>__('Activating %plugin%','themify'),
$result['has_demo']=Themify_Import_Helper::has_demo_content();
wp_send_json_success($result);
* Install or Activate plugin for skin demo import and themify updater
function themify_activate_plugin() {
check_ajax_referer( 'tf_nonce', 'nonce' );
if(!empty($_POST['plugin']) && current_user_can( 'edit_theme_options' ) ){
$plugin=sanitize_key($_POST['plugin']);
$plugin_info = themify_get_known_plugin_info($plugin);
if($plugin_info!==false){
$allPlugins= get_plugins();
if(isset($allPlugins[$plugin_info['path']])){
if(!is_plugin_active( $plugin_info['path'] )){
if(current_user_can( 'activate_plugin', $plugin )){
$result =activate_plugin($plugin_info['path'],false,false);
if(is_wp_error($result)){
$err=$result->get_error_message();
$err=__( 'You are not allowed to activate this plugin.','themify' );
elseif(current_user_can( 'install_plugins' )){
$isFree=!empty($plugin_info['wp_hosted']);
if($plugin==='themify-updater'){
if(!empty( $_FILES['data'] ) && is_file($_FILES['data']['tmp_name'] )){
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$updgrader=new Plugin_Upgrader();
$result=$updgrader->install($_FILES['data']['tmp_name'],array('overwrite_package'=>true));
$result =activate_plugin($plugin_info['path'],false,false);
if(is_wp_error($result)){
$err=$result->get_error_message();
$err= is_wp_error($result)?$result->get_error_message():__('Themify Updater installation failed','themify');
$err=array('install_updater'=>1);
if(!class_exists('Themify_Updater',false)){
$updater=themify_get_known_plugin_info('themify-updater');
if(isset($allPlugins[$updater['path']]) && !is_plugin_active( $updater['path'] )){
$result =activate_plugin($updater['path'],false,false);
if(is_wp_error($result)){
$err=$result->get_error_message();
elseif(!class_exists('Themify_Updater',false) && function_exists('themify_updater_init')){//plugins_loaded event already fired
$themify_updater = class_exists('Themify_Updater',false)?Themify_Updater::get_instance():null;
if($themify_updater && method_exists($themify_updater, 'get_versions')){
$versions = $themify_updater->get_versions();
$isFree=!empty($versions)?$versions->has_attribute($plugin, 'wp_hosted'):false;
if($err==='' && $plugin!=='themify-updater'){
$_REQUEST['_ajax_nonce']=wp_create_nonce( 'updates' );
wp_ajax_install_plugin();
elseif(empty($themify_updater)){
$err=array('install_updater'=>1);
if($themify_updater->has_error()){
$err=array('check_license'=>1,'errorMessage'=>sprintf(__('A valid membership is required to install %s','themify'),$plugin_info['name']));
elseif(!$themify_updater->has_access( $plugin )){
$err=array('buy'=>1,'errorMessage'=>sprintf(__('Your membership/license does not include %s','themify'),$plugin_info['name']),'url'=>$plugin_info['page']);
$nonce=wp_create_nonce( 'install-plugin_'. str_replace('-plugin', '', $plugin) );
$installUrl= add_query_arg(array('action'=>'install-plugin','plugin'=>$plugin,'_wpnonce'=>$nonce),self_admin_url( 'update.php' ));
wp_send_json_success(array('install_plugin_url'=>$installUrl));
unset($themify_updater,$plugin_info);
$err=__( 'You are not allowed to install plugins on this site.','themify' );
$err=__('Unknown Plugin.','themify');
wp_send_json_error($err);
* Handle the display of the Themify News admin dashboard widget
* Hooked to wp_ajax_themify_news_widget
function themify_news_widget() {
wp_widget_rss_output( 'https://themify.me/blog/feed', array(
'title' => esc_html__( 'Themify News', 'themify' ),
$cache_key = 'themify_news_dashboard_widget';
Themify_Storage::set( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
* Handle the upload json file
function themify_upload_json(){
check_ajax_referer( 'tf_nonce', 'nonce' );
if (!empty($_POST['file'])) {
if (!current_user_can('upload_files')) {
$error = __('You aren`t allowed to upload file', 'themify');
if ( isset( $_POST['data'] ) ) {
$data = stripslashes_deep( $_POST['data'] );
elseif ( isset( $_FILES['data'] ) ) {
$data = file_get_contents( $_FILES['data']['tmp_name'] );
$slug = sanitize_file_name(pathinfo( $_POST['file'],PATHINFO_FILENAME));
$filename= $slug.'.json';
$sql= sprintf('post_name="%1$s" OR post_name="%1$s-1" OR post_name="%1$s-2" OR post_name="%1$s-3"',esc_sql($slug));
$query = $wpdb->get_row("SELECT ID FROM {$wpdb->prefix}posts WHERE ({$sql}) AND post_type='attachment' LIMIT 1" );
$attach_id=!empty($query) ? $query->ID : null;
$duplicate = get_attached_file($attach_id);
if(!$duplicate ||!is_file($duplicate) || sha1_file($duplicate)!==sha1($data)){
if($duplicate && !is_file($duplicate)){
wp_delete_attachment($attach_id);
$tmp = trailingslashit(sys_get_temp_dir()).$filename;
if(file_put_contents($tmp,$data)){
'size' => filesize($tmp),
$title=!empty($_POST['title'])?sanitize_textarea_field($_POST['title']):'';
$attach_id=media_handle_sideload( $file, 0,$title,array(
'post_mime_type'=>'application/json',
if(is_wp_error($attach_id)){
$error=$attach_id->get_error_message();
$error = __('Can`t write tmp file', 'themify');
wp_send_json_success(wp_get_attachment_url($attach_id));
$error = __('Upload data is corrupted', 'themify');
wp_send_json_error($error);
function themify_update_license() {
check_ajax_referer( 'tf_nonce', 'nonce' );
if(current_user_can( 'manage_options' )){
$themify_updater = Themify_Updater::get_instance();
$result = $themify_updater->menu_p(true);
$theme = is_child_theme() ? $theme->parent() : $theme;
$themify_updater->themify_reinstall_theme( $theme->stylesheet );
$result = array('html'=>ob_get_clean());
wp_send_json_success($result);
$msg = $result===false?__('Invalid license key. Please enter your Themify username and a valid license key.','themify'):
__('You need the latest Themify Updater plugin for this feature. Please update your Themify Updater plugin.','themify');
wp_send_json_error($msg);