На странице WordPress показаны шорткоды

Моя страница WordPress показывает короткие коды, такие как [vc_row] [vc_column] [vc_column_text]. Помогите мне определить первопричину.

Я перенес файлы sql wordpress с одного хоста на другой.

Вы проверили настройки плагина "Visual Composer"? Это теги, созданные этим плагином. Попробуйте закрыть их в обратном порядке, например [/ vc_column_text] [/ vc_column] [/ vc_row] в соответствующей позиции в содержимом.

zipkundan 18.12.2018 17:32

спасибо за комментарии. Я не видел плагин визуального композитора на панели управления после миграции сайта. Сайт разрабатывал какой-то разработчик. Можно ли сохранить шорткод, установив плагин визуального композитора и обратные закрывающие теги?

JAI 18.12.2018 18:07

Вам нужно будет добавить визуальный композитор, также известный как WP Bakery. это обычный визуальный конструктор страниц. альтернативой является использование чего-то вроде wordpress.org/plugins/wp-utility-script-runner для перебора всех сообщений и удаления всех шорткодов [vc ....] из содержимого сообщения.

mrben522 18.12.2018 20:10
Как убрать количество товаров в категории WooCommerce
Как убрать количество товаров в категории WooCommerce
По умолчанию WooCommerce показывает количество товаров рядом с категорией, как показано ниже.
0
3
2 974
1

Ответы 1

Вы можете изменить этот сценарий Утилита Script Runner, чтобы удалить короткие коды, которые больше не существуют, но находятся в содержимом вашей страницы. Обязательно сделайте это на постановке, прежде чем делать это вживую. высокая вероятность разрушения этого места. Этот сценарий просидел около года, и я, честно говоря, не могу вспомнить, работает ли что-то из этого, как ожидалось. много тестируйте на постановке, прежде чем запускать это на том, что вас действительно волнует.

<?php if (!defined('ABSPATH')) { die(); } 
/**
 * Utility Name: Remove and Flatten Shortcodes
 * Description: Strip Shortcodes from all posts, with several processing options
 * Supports: input
 * Version: 0.0.2
 **/

if (!class_exists('StripShortcodes')) {
    class StripShortcodes {
        var $wrappers = array(),
            $swaps = array();

        public static function Instance() {
            static $instance = null;
            if ($instance === null) {
                $instance = new self();
            }
            return $instance;
        }

        public function __construct() {
            add_filter('wp_util_script', array($this, 'strip_shortcodes_run'), 10, 3);
            add_filter('wp_util_input_html', array($this, 'strip_shortcodes_input_html'));
        }

        public function strip_shortcodes_input_html( $html ) {
            global $shortcode_tags;
            $post_types = get_post_types( array(
                'exclude_from_search' => false
            ), 'names' );
            $post_types = array_diff( $post_types, array( 'revision', 'attachment' ) );
            ?>
            <p>
                <strong>WARNING! DO NOT RUN THIS ON A LIVE SITE!</strong><br>
                This utility may cause data loss. Even restoring a backup may wipe out any changes since the last run of this utility.
            </p>
            <label>
                <input type = "checkbox" name = "restore" value = "restore"/>
                <span>Restore From Backup</span>
            </label>
            <label>
                <span>Post Types to Process</span>
                <select name = "post_types[]" multiple = "multiple">
                    <option value = "none" selected = "selected">none</option>
                    <option value = "any">all</option>
                    <?php
                    foreach( $post_types as $post_type ) {
                        echo '<option value = "' . esc_attr( $post_type ) . '">' . $post_type . '</option>';
                    }
                    ?>
                </select>
            </label>
            <hr/>
            <p>
                Select what you would like to do with each shortcode.
            </p>
            <?php
            if ( !empty( $shortcode_tags ) ) {
                foreach( $shortcode_tags as $tag => $callable ) {
                    ?>
                    <div class = "shortcode-options-wrapper">
                        <label>
                            <span>[<?php echo $tag; ?>]</span>
                            <select class = "shortcode-select" name = "shortcodes[<?php echo esc_attr( $tag ); ?>]"/>
                            <option value = "skip">Skip (do not process)</option>
                            <option value = "strip">Remove (deletes shortcode content)</option>
                            <option value = "unwrap">Unwrap Content</option>
                            <option value = "parse">Flatten (parses to HTML)</option>
                            <option value = "swap">Swap (Replace with another shortcode)</option>
                            </select>
                        </label>
                    </div>
                    <?php
                }
            }
            echo $this->build_form_script();
            return ob_get_clean();
        }

        private function build_form_script () {
            global $shortcode_tags;
            ob_start(); ?>
            <script type = "text/javascript">
                (jQuery)(function($) {
                    'use strict';

                    var unwrap = '<div class = "wrap-wrapper"><p>Wrapper for content (use "sprintf()" formatting, including the %s for the content)</p><label>Wrapper<input class = "shortcode-wrap"></label></div>';
                    var swap = '<div class = "swap-wrapper"><select class = "shortcode-swap"><?php foreach ($shortcode_tags as $tag => $callable) { echo '<option value = "' . $tag . '">' . esc_attr($tag) . '</option>'; }?></select></div>'
                    $(document).on('change', '.shortcode-select', function () {
                        var $this = $(this);
                        var name = $this.attr('name');
                        if ($this.val() == 'unwrap') {
                            $this.closest('.shortcode-options-wrapper').append(unwrap);
                            $this.closest('.shortcode-options-wrapper').find('.shortcode-wrap').attr('name', 'wrap_' + name);
                            $this.closest('.shortcode-options-wrapper').find('.swap-wrapper').remove();
                        }
                        else if ($this.val() == 'swap') {
                            $this.closest('.shortcode-options-wrapper').append(swap);
                            $this.closest('.shortcode-options-wrapper').find('.shortcode-swap').attr('name', 'swap_' + name);
                            $this.closest('.shortcode-options-wrapper').find('.wrap-wrapper').remove();
                        } else {
                            $this.closest('.shortcode-options-wrapper').find('.wrap-wrapper').remove();
                            $this.closest('.shortcode-options-wrapper').find('.swap-wrapper').remove();
                        }
                    })
                });
            </script>
            <?php return ob_get_clean();
        }

        public function strip_shortcodes_run( $legacy, $state, $atts ) {
            $batch = 10;
            $offset = 0;
            if ( !empty( $state['offset'] ) ) {
                $offset = $state['offset'];
            }
            $result = array(
                'state'   => 'error',
                'message' => 'an unknown error has occurred',
            );
            $post_types = 'none';
            if ( !empty( $atts['post_types'] ) && !in_array( 'none', $atts['post_types'] ) ) {
                $post_types = $atts['post_types'];
            }
            $shortcode_settings = array();
            if ( !empty( $atts['shortcodes'] ) ) {
                $shortcode_settings['core']    = $atts['shortcodes'];
                $shortcode_settings['wrap']    = $atts['wrap_shortcodes'];
                $shortcode_settings['swap']    = $atts['swap_shortcodes'];
            }

            $restore = true;
            if ( empty( $atts['restore'] ) ) {
                $this->replace_shortcode_functions( $shortcode_settings );
                $restore = false;
            }
            $query = new WP_Query( array(
                'posts_per_page' => $batch,
                'offset' => $offset,
                'post_type' => $post_types
            ) );
            if ( !$query->have_posts() ) {
                $result = array(
                    'state' => 'complete',
                    'message' => 'successfully processed all posts'
                );
            } else {
                $offset += $query->post_count;
                while( $query->have_posts() ) {
                    $query->the_post();
                    $post = get_post();
                    $backup = get_post_meta( $post->ID, 'flatten_shortcodes_backup', true );
                    if ( $restore ) {
                        if ( $backup ) {
                            $post->post_content = $backup;
                            wp_update_post( $post );
                            delete_post_meta( $post->ID, 'flatten_shortcodes_backup' );
                        }
                    } else {
                        if ( !$backup ) {
                            update_post_meta( $post->ID, 'flatten_shortcodes_backup', $post->post_content );
                        }
                        $post->post_content = do_shortcode( $post->post_content );
                        wp_update_post( $post );
                    }
                }
                $result = array(
                    'state' => array(
                        'offset' => $offset
                    ),
                    'message' => $offset . ' posts processed'
                );
            }

            return $result;
        }

        private function replace_shortcode_functions( $settings = array() ) {
            global $shortcode_tags;
            foreach( $shortcode_tags as $tag => $callable ) {
                $setting = 'skip';
                if ( !empty( $settings['core'][$tag] ) ) {
                    $setting = $settings['core'][$tag];
                }
                switch( $setting ) {
                    case 'strip' :
                        $shortcode_tags[$tag] = "__return_empty_string";
                        break;
                    case 'unwrap':
                        $shortcode_tags[$tag] = array($this, 'replace_shortcode_unwrap');
                        $this->wrappers[$tag] = $settings['wrap'][$tag];
                        break;
                    case 'parse' :
                        // nothing needed
                        break;
                    case 'swap' :
                        $shortcode_tags[$tag] = array($this, 'swap_shortcode');
                        $this->swaps[$tag] = $settings['swap'][$tag];
                        break;
                    case 'skip'  :
                    default      :
                        unset( $shortcode_tags[$tag] );
                }

            }
        }
        public function replace_shortcode_unwrap( $atts=array(), $content='', $tag ) {
            return sprintf($this->wrappers[$tag], $content);
        }
        public function swap_shortcode( $atts=array(), $content='', $tag ) {
            $attString = '';
            $newTag = $this->swaps[$tag];
            if (!empty($atts)) {
                foreach ($atts as $key => $att) {
                    $attString .= ' ' . $key . ' = "' . $att . '"';
                }
            }
            $output = '[' . $newTag . $attString . ']';
            if ($content) {
                $output .= $content . '[/' . $newTag . ']';
            }
            return $output;
        }
    }

    StripShortcodes::Instance();
}

Другие вопросы по теме