更改visual composer的原始html块中的URL

时间:2017-11-16 12:46:32

标签: wordpress migrate visual-composer

Visual Composer将原始HTML块保存为数据库中的base64编码(和url编码)字符串。我的网站需要从http到https,我需要更改这些原始HTML块中使用的资产URL以通过https提供。显然Wordpress搜索/替换工具在这里不起作用。

有人知道这方面的解决方案吗?

4 个答案:

答案 0 :(得分:2)

我也遇到了麻烦,为此我写了一些小脚本。
https://github.com/lSanik/WordPress-VisualComposer-RawHtml-Base64-Replace

# WordPress VisualComposer RawHtml Base64  data base mass Replacing

For developers only!

This is little script for mass changes in wordpress visual composer database. 
You can change all domains, html code, scripts and etc, data that in base64 coded.

MAKE BACK-UP database table WP_POSTS!

All what you need, its take this in function.php at your theme folder.
Change sample data to yours needs.
Run url - your_site.com/replace_composer_html_raw_base64

If success - all data will be changed and you are happy now ;)


<?php
function replace_composer_html_raw_base64(){

    if($_SERVER['REQUEST_URI'] == '/replace_composer_html_raw_base64'){
        global $wpdb;

        ini_set('error_reporting', E_ALL);
        ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);

        $response = $wpdb->get_results('SELECT ID,post_content FROM wp_posts WHERE post_type="page"',ARRAY_A);
        $count = count($response);
        $tag = 'vc_raw_js';//'vc_raw_js';//'vc_raw_html';//vc_raw_js
        $pattern = '\['.$tag.'].*?\]';

        foreach ($response as $post){

            $matches = '';
            preg_match_all('/' . $pattern . '/s', $post['post_content'], $matches);
            $content = replacedComposerHtmlRawString($matches[0],$tag);

            if(!$content && count($content)<1){
                continue;
            }

            foreach ($content as $key=>$item){
                $post['post_content'] = str_replace($item['original'],$item['modified'],$post['post_content']);
            }

            //$post['post_content'] = replacedComposerRawFromTo();

            $upd = array(// Update the post into the database
                'ID'           => $post['ID'],
                'post_content' => $post['post_content'],
            );
            wp_update_post( $upd );
        }

        die('If no errors, all successful! =)  ');
    }
}
// String with shortcode tag, and different tag send, like vc_raw_html,vc_raw_js, etc.
function replacedComposerHtmlRawString($strings,$tag){

    if(!is_array($strings)){
        return false;
    }

    $return=array();
    foreach ($strings as $key=>$string){
        $return[$key]['original']= $string;
        $string = str_replace('['.$tag.']','',$string);
        $string = str_replace('[/'.$tag.']','',$string);
        $string = base64_decode($string);
        $string = rawurldecode($string);//If something not working, try change this rawurlencode to urlencode, etc... dumped it =)

        //place to replace decoded string
        $string = replacedComposerRawFromTo($string);
        //end place..

        $string = rawurlencode($string);
        $string = base64_encode($string);
        $string = '['.$tag.']'.$string.'[/'.$tag.']';
        $return[$key]['modified'] = $string;
    }

    return $return;
}

function replacedComposerRawFromTo($string,$fromTo=false){
    //Changed from 'value' = > to 'value';
    $fromTo=array(
    //Sample data to change!
        'http'=>'https',
        'token123'=>'token321',
        '<script>Hello World</script>'=>'<script>HI WORLD</script>',

    );

    foreach ($fromTo as $from=>$to){
        $string = str_replace($from,$to,$string);
    }

    return $string;
}

add_action('init', 'replace_composer_html_raw_base64');

答案 1 :(得分:2)

这个WordPress插件可以达到目的: https://wordpress.org/plugins/better-search-replace/ 我尝试使用编码的字符串并成功。

从此: https%3A%2F%2Fevergreendent.com%2Fhu

为此:https%3A%2F%2Fevergreendent.hu

赞: http://prntscr.com/qxu65n

它取代了Visual Composer / WP Bakery页面构建器链接。

从此: https://evergreendent.com/hu

对此: https://evergreendent.hu

答案 2 :(得分:0)

将以下代码放在主题的functions.php

add_filter('the_content', 'chnage_http_to_https', 10);
function chnage_http_to_https($content){
    return str_replace('http://example.com','https://example.com', $content);
}

它会帮助你前端。 chnage exaple.com到您的网站名称

答案 3 :(得分:-1)

使用https://wordpress.org/plugins/velvet-blues-update-urls/并更新管理面板中的网址,这将更改网站中的所有网址,无论是内容链接还是网址链接。