: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
defined('ABSPATH') || exit;
class Themify_Builder_Active{
public static function init():void{
private static function run():void{
if (Themify_Builder_Model::is_front_builder_activate()) {
// load module panel frontend
add_action('wp_footer', array(__CLASS__, 'load_javascript_template_front'), 1);
add_filter('show_admin_bar', '__return_false'); // Custom CSS
add_filter('themify_dev_mode', '__return_false');
$wp_actions['wp_enqueue_media'] = true;
themify_set_headers(array(
'X-FRAME-OPTIONS' => 'SAMEORIGIN',
'CONTENT-SECURITY-POLICY' => array(
'img-src' => "https://themify.org https://placehold.co 'unsafe-inline' blob:",
'default-src' => "https://placehold.co 'unsafe-inline' blob:"
$is_ajax=themify_is_ajax();
add_action('wp_ajax_tb_load_editor', array(__CLASS__, 'load_editor'), 10);
add_action('wp_ajax_tb_load_module_partial', array(__CLASS__, 'load_module_partial_ajaxify'), 10);
add_action('wp_ajax_tb_render_element', array(__CLASS__, 'render_element_ajaxify'), 10);
add_action('wp_ajax_tb_get_post_types', array(__CLASS__, 'get_ajax_post_types'), 10);
add_action('wp_ajax_tb_render_element_shortcode', array(__CLASS__, 'render_element_shortcode_ajaxify'), 10);
add_action('wp_ajax_tb_save_data', array(__CLASS__, 'save_data_builder'), 10);
add_action('wp_ajax_tb_save_css', array(__CLASS__, 'save_builder_css'), 10);
// AJAX Action Save Module Favorite Data
add_action('wp_ajax_tb_module_favorite', array(__CLASS__, 'save_module_favorite_data'));
//AJAX Action update ticks and TakeOver
add_action('wp_ajax_tb_update_tick', array(__CLASS__, 'update_tick'));
add_action('wp_ajax_tb_help', array(__CLASS__, 'help'));
add_action('wp_ajax_tb_get_ajax_builder_posts', array(__CLASS__, 'get_ajax_builder_posts'));
add_action('wp_ajax_tb_get_ajax_data', array(__CLASS__, 'get_ajax_data'));
add_action('wp_ajax_tb_validate_captcha', array(__CLASS__, 'ajax_validate_captcha'));
add_action('wp_ajax_tb_get_pages', array(__CLASS__, 'tb_get_pages'));
if ($is_admin === false || $is_ajax===true) {
add_action('admin_bar_menu', array(__CLASS__, 'builder_admin_bar_menu'), 100);
if ($is_admin === false) {
add_action('wp_footer', array(__CLASS__, 'async_footer'));
Themify_Builder_Import_Export::init();
// Library Module, Rows and Layout Parts
Themify_Builder_Library_Items::init();
// Themify Builder Revisions
Themify_Builder_Revisions::init();
// Fix security restrictions
add_filter('user_can_richedit', '__return_true');
* Load interface js and css
private static function load_frontend_interface():void {
// load only when builder is turn on
$editorUrl = THEMIFY_BUILDER_URI . '/css/editor/';
themify_enque_style('themify-builder-admin-ui', $editorUrl . 'themify-builder-admin-ui.css', array(), THEMIFY_VERSION, '', true);
$grids = array_diff(scandir(THEMIFY_DIR . '/css/grids/', SCANDIR_SORT_NONE), array('..', '.'));
Themify_Enqueue_Assets::loadGridCss(str_replace('.css', '', $g), true);
$editorUrl = THEMIFY_BUILDER_URI . '/js/editor/';
Themify_Icon_Font::enqueue();
themify_enque_script('themify-colorpicker', THEMIFY_METABOX_URI . 'js/themify.minicolors.js');
themify_enque_script('themify-combobox', $editorUrl . 'themify-combobox.min.js');
themify_enque_script('themify-builder-js', THEMIFY_BUILDER_URI . '/js/themify-builder-script.js');
themify_enque_script('tb_builder_js_style', THEMIFY_URI . '/js/generate-style.js');
themify_enque_script('themify-builder-app-js', $editorUrl . 'build/components.min.js', THEMIFY_VERSION, array('tb_builder_js_style'));
themify_enque_script('themify-builder-modules-js', $editorUrl . 'build/modules.min.js', THEMIFY_VERSION, array('themify-builder-app-js'));
themify_enque_script('themify-builder-front-ui-js', $editorUrl . 'frontend/themify-builder-visual.js', THEMIFY_VERSION, array('themify-builder-app-js'));
$builderData = self::get_active_builder_vars();
$builderData['upload_url'] = themify_upload_dir('baseurl');
$builderData['available_shortcodes'] = array_keys($shortcode_tags);
do_action('themify_builder_active_enqueue', 'visual');
wp_localize_script('themify-colorpicker', 'themifyCM', Themify_Metabox::themify_localize_cm_data());
wp_localize_script('themify-builder-app-js', 'themifyBuilder', $builderData);
private static function load_admin_interface():void {
$editorUrl = THEMIFY_BUILDER_URI . '/css/editor/';
themify_enque_style('tf_base', THEMIFY_URI . '/css/base.min.css', null, THEMIFY_VERSION, '', true);
themify_enque_style('themify-builder-loader', $editorUrl . 'themify-builder-loader.css', null, THEMIFY_VERSION, '', true);
themify_enque_style('themify-builder-style', THEMIFY_BUILDER_URI . '/css/themify-builder-style.css', null, THEMIFY_VERSION, '', true);
themify_enque_style('themify-builder-lightbox', $editorUrl . 'components/lightbox.css', null, THEMIFY_VERSION, '', true);
themify_enque_style('themify-builder-admin-ui', $editorUrl . 'themify-builder-admin-ui.css', null, THEMIFY_VERSION, '', true);
themify_enque_style('themify-backend-mode', $editorUrl . 'backend-mode.css', null, THEMIFY_VERSION, '', true);
themify_enque_style('themify-backend-ui', $editorUrl . 'backend/backend-ui.css', null, THEMIFY_VERSION, '', true);
$editorUrl = THEMIFY_BUILDER_URI . '/js/editor/';
Themify_Enqueue_Assets::loadMainScript();
themify_enque_script('themify-combobox', $editorUrl . 'themify-combobox.min.js');
themify_enque_script('tb_builder_js_style', THEMIFY_URI . '/js/generate-style.js');
themify_enque_script('themify-builder-app-js', $editorUrl . 'build/components.min.js', THEMIFY_VERSION, array('tb_builder_js_style'));
themify_enque_script('themify-builder-modules-js', $editorUrl . 'build/modules.min.js', THEMIFY_VERSION, array('themify-builder-app-js'));
themify_enque_script('themify-builder-backend-js', $editorUrl . 'backend/themify-builder-backend.js', THEMIFY_VERSION, array('themify-builder-app-js'));
themify_enque_script('themify-static-badge', THEMIFY_BUILDER_URI . '/js/editor/backend/themify-builder-static-badge.js', THEMIFY_VERSION, array('mce-view', 'themify-builder-backend-js'));
$builderData = self::get_active_builder_vars();
$builderData['post_ID'] = get_the_ID();
$builderData['is_gutenberg_editor'] = Themify_Builder_Model::is_gutenberg_editor();
do_action('themify_builder_active_enqueue', 'admin');
wp_localize_script('themify-builder-app-js', 'themifyBuilder', $builderData);
private static function get_active_builder_vars():array {
Themify_Builder_Component_Module::load_modules();
if(current_user_can('upload_files')){
$tmp_extensions = get_allowed_mime_types();
foreach($tmp_extensions as $ext=>$v){
if(strpos($ext,'|')!==false){
$allowed_extensions[$ex]=$v;
$allowed_extensions[$ext]=$v;
$extensions=wp_get_ext_types();
$_video= $extensions['video'];
$_audio=$extensions['audio'];
$_image= $extensions['image'];
$tmp_extensions=$extensions=null;
if ( isset($allowed_extensions[$v]) ) {
$mime=explode('/',$allowed_extensions[$v])[1];
if(!isset($video[$mime])){
if ( isset($allowed_extensions[$v]) ) {
$mime=explode('/',$allowed_extensions[$v])[1];
if(!isset($audio[$mime])){
if ( isset($allowed_extensions[$v]) ) {
$mime=explode('/',$allowed_extensions[$v])[1];
if(!isset($image[$mime])){
$allowed_extensions=$_video=$_audio=$_image=null;
$id = is_admin() ? get_the_ID() : Themify_Builder::$builder_active_id;
$i18n=include THEMIFY_BUILDER_INCLUDES_DIR . '/i18n.php';
$vars=apply_filters('themify_builder_active_vars',[
'builder_data' => ThemifyBuilder_Data_Manager::get_data($id),
'site_url' => get_site_url(),
'nonce' => wp_create_nonce('tf_nonce'),
'disableShortcuts' => themify_builder_get('setting-page_builder_disable_shortcuts', 'builder_disable_shortcuts'),
'widget_css' => array(home_url($wp_styles->registered['widgets']->src), home_url($wp_styles->registered['customize-widgets']->src)),
'modules' => Themify_Builder_Model::get_modules_localize_settings(),
'favorite' => Themify_Builder_Model::get_favorite_modules(),
'gutters' => Themify_Builder_Model::get_gutters(),
'layouts' => Themify_Builder_Model::get_layouts(),
'blocks' => 'https://themify.org/public-api/predesigned-rows/',
'custom_css' => get_post_meta($id, 'tbp_custom_css', true),
'post_title' => get_the_title($id),
'cf_api_url' => Themify_Custom_Fonts::$api_url,
'safe' => themify_get_web_safe_font_list(),
'google' => themify_get_google_web_fonts_list(),
'cf' => Themify_Custom_Fonts::get_list(),
'ticks' => Themify_Builder_Model::get_transient_time(),
'memory' => (int) (wp_convert_hr_to_bytes(WP_MEMORY_LIMIT) * MB_IN_BYTES),
'imgphp'=>Themify_Builder_Model::is_img_php_disabled(),
'admin_url'=>rtrim( get_admin_url(), '/' ),
'ext'=>['video'=>$video,'audio'=>$audio,'image'=>$image]
], is_admin() ? 'admin' : 'visual' );
unset($image,$video,$audio);
$jsonFiles=Themify_Builder_Component_Module::get_styles_json();
$vars['style_json']=$jsonFiles;
foreach($jsonFiles as $f){
Themify_Enqueue_Assets::addPreLoadMedia($f,'prefetch','json');
if(!current_user_can('upload_files')){
$vars['upload_disable']=1;
if(!function_exists('gzdecode')){
$vars['gzip_disabled']=1;
if(empty($vars['custom_css'])){
unset($vars['custom_css']);
if(empty($vars['imgphp'])){
if(empty($vars['favorite'])){
unset($vars['favorite']);
if(empty($vars['addons'])){
if(empty($vars['disableShortcuts'])){
unset($vars['disableShortcuts']);
if(empty($vars['style_json'])){
unset($vars['style_json']);
private static function includes():void {
include THEMIFY_BUILDER_CLASSES_DIR . '/class-themify-builder-revisions.php';
include THEMIFY_BUILDER_CLASSES_DIR . '/class-themify-builder-library-item.php';
include THEMIFY_BUILDER_CLASSES_DIR . '/class-builder-duplicate-page.php';
include THEMIFY_BUILDER_CLASSES_DIR . '/class-themify-builder-import-export.php';
* Loads JS templates for front-end editor.
public static function load_javascript_template_front():void {
add_filter( 'wp_inline_script_attributes', array(__CLASS__, 'exclude_cloudfare_js'), 11,1);
self::load_frontend_interface();
include THEMIFY_BUILDER_INCLUDES_DIR . '/tpl/tmpl-common.php';
include THEMIFY_BUILDER_INCLUDES_DIR . '/tpl/tmpl-front.php';
* Loads JS templates for WordPress admin dashboard editor.
public static function load_javascript_template_admin():void {
self::load_admin_interface();
self::print_static_content_badge_templates();
include THEMIFY_BUILDER_INCLUDES_DIR . '/tpl/tmpl-common.php';
include THEMIFY_BUILDER_INCLUDES_DIR . '/tpl/tmpl-admin.php';
public static function exclude_cloudfare_js(array $attr=array()):array {
if(isset($attr['id']) && ($attr['id']==='themify-builder-app-js-js-extra' || $attr['id']==='themify-colorpicker-js-extra' || $attr['id']==='tf-icon-picker-js-extra')){
$attr['data-cfasync']='false';
$attr['data-no-optimize']=$attr['data-noptimize']=1;
public static function load_editor() {
global $wp_scripts, $wp_styles, $concatenate_scripts, $wp_actions;
if (!defined('CONCATENATE_SCRIPTS')) {
define('CONCATENATE_SCRIPTS', false);
$concatenate_scripts = false;
/* ensure $wp_scripts and $wp_styles globals have been initialized */
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'shortcode' );
/* force a load uncompressed TinyMCE script, fix script issues on frontend editor */
$wp_scripts->remove('wp-tinymce');
wp_register_tinymce_scripts($wp_scripts, true); // true: $force_uncompressed
if (is_object($wp_styles)) {
$tmp_styles = clone $wp_styles;
$tmp_scripts = clone $wp_scripts;
foreach ($tmp_scripts->registered as $k => $v) {
$scripts_registered = $new;
if (isset($tmp_styles)) {
foreach ($tmp_styles->registered as $k => $v) {
$styles_registered = $new;
//don't allow loading wp_enqueue_media thirdy party plugins
$wp_actions['wp_enqueue_media'] = true;
//for thirdy party plugins, maybe they use wp_enqueue_scripts hook to add localize data in tinymce, the js files we don't need to check by wp standart they should use mce_external_plugins
do_action('wp_enqueue_scripts');
$data = !empty($wp_scripts->registered['editor']->extra['data']) ? $wp_scripts->registered['editor']->extra['data'] : null;
//restore original because we only need the js/css related with wp editor only,otherwise they will be loaded in wp_footer
if (isset($tmp_styles)) {
$tmp_styles->registered = $styles_registered;
$wp_styles = clone $tmp_styles;
$tmp_styles = $styles_registered = null;
$tmp_scripts->registered = $scripts_registered;
$wp_scripts = clone $tmp_scripts;
$tmp_scripts = $scripts_registered = null;
$wp_scripts->done[] = 'jquery';
$wp_scripts->done[] = 'jquery-core';
unset($wp_actions['wp_enqueue_media']);
echo '<div id="tb_tinymce_wrap">';
if (current_user_can('upload_files')) {
echo '<div style="display:none;">';
wp_editor(' ', 'tb_lb_hidden_editor');
if (!empty($wp_scripts->registered['editor']->deps)) {
$wp_scripts->registered['editor']->deps[] = 'wp-tinymce-root';
$wp_scripts->registered['editor']->deps = array('wp-tinymce-root');
//wp is returing is_admin() true on the ajax call,that is why we have to add these hooks manually
add_action('wp_print_footer_scripts', array('_WP_Editors', 'editor_js'), 50);
add_action('wp_print_footer_scripts', array('_WP_Editors', 'force_uncompressed_tinymce'), 1);
add_action('wp_print_footer_scripts', array('_WP_Editors', 'enqueue_scripts'), 1);
echo '<script>', $data, '</script>';
* Load module partial when update live content
public static function load_module_partial_ajaxify() {
check_ajax_referer('tf_nonce', 'nonce');
themify_disable_other_lazy();
Themify_Builder::$frontedit_active = true;
Themify_Builder::$builder_active_id = $_POST['bid'];
$new_modules = apply_filters('themify_builder_load_module_partial', array(
'mod_name' => $_POST['tb_module_slug'],
'mod_settings' => json_decode(stripslashes($_POST['tb_module_data']), true),
'element_id' => $_POST['element_id']
Themify_Builder_Component_Module::template($new_modules, Themify_Builder::$builder_active_id);
$css = Themify_Enqueue_Assets::get_css();
echo '<script type="text/template" id="tb_module_styles">', json_encode($css), '</script>';
public static function render_element_ajaxify() {
check_ajax_referer('tf_nonce', 'nonce');
themify_disable_other_lazy();
$batch = json_decode(stripslashes($_POST['batch']), true);
Themify_Builder::$frontedit_active = true;
$batch = apply_filters('themify_builder_load_module_partial', $batch);
Themify_Builder::$builder_active_id =$activeId= $_POST['bid'];
if (!empty($_POST['tmpGS'])) {
Themify_Global_Styles::$used_styles[$activeId] = Themify_Global_Styles::addGS($activeId, json_decode(stripslashes($_POST['tmpGS']), true));
$element_id = $b['element_id'];
if (isset($_POST['element_id'])) {
$element_id = $b['element_id'] = $_POST['element_id'];
$markup = Themify_Builder_Component_Module::template($b, $activeId, false);
$markup = Themify_Builder_Component_SubRow::template($b, $activeId, false);
$markup = Themify_Builder_Component_Column::template($b, $activeId, false);
$markup = Themify_Builder_Component_Row::template($b, $activeId, false);
$response[$element_id] = $markup;
if (!empty($b['attached_gs'])) {
$used_gs = array_merge($used_gs, $b['attached_gs']);
$used_gs = array_keys(array_flip($used_gs));
'exclude' => empty($_POST['loadedGS']) ? array() : $_POST['loadedGS'],
$used_gs = Themify_Global_Styles::get_global_styles($args);
$response['gs'] = $used_gs;
$css = Themify_Enqueue_Assets::get_css();
$response['tb_module_styles'] = $css;
//don't use wp_send_json it's very heavy,this array can be very large
header('Content-Type: application/json; charset=' . get_option('blog_charset'));
die(json_encode($response));
public static function render_element_shortcode_ajaxify() {
check_ajax_referer('tf_nonce', 'nonce');
$shortcodes = $styles = array();
$shortcode_data = json_decode(stripslashes_deep($_POST['shortcode_data']), true);
if (is_array($shortcode_data)) {
if(!empty($_POST['bid'])){
$p=get_post((int)$_POST['bid']);
'ignore_sticky_posts'=>true,
'post_status'=>$p->post_status,
'post_type'=>$p->post_type
if($p->post_type==='page'){
foreach ($shortcode_data as $shortcode) {
$shortcodes[] = array('key' => $shortcode, 'html' => Themify_Builder_Model::format_text($shortcode));