php 更新后字符类中的Wordpress无效范围

ycggw6v2  于 2022-12-02  发布在  PHP
关注(0)|答案(2)|浏览(134)

我有一个关于Visual Compser后端不显示任何元素的问题,它只显示经典模式编辑器中的代码。
See Screenshot
警告:preg_match_all():编译失败:第162行上字符类中偏移量11处的范围无效,该字符类位于/home/customer/www/*****.com/public_html/wp-content/plugins/js_composer/include/autoload/hook-vc-grid.php中
"这是第162行"
preg_match_all( "/$pattern/", $post->post_content, $found ); // fetch only needed shortcodes

```public function gridSavePostSettingsId( array $settings, $post_id, $post ) {
    $pattern = $this->getShortcodeRegexForId();
    preg_match_all( "/$pattern/", $post->post_content, $found ); // fetch only needed shortcodes
    $settings['vc_grid_id'] = array();
    if ( is_array( $found ) && ! empty( $found[0] ) ) {
        $to_save = array();
        if ( isset( $found[1] ) && is_array( $found[1] ) ) {
            foreach ( $found[1] as $key => $parse_able ) {
                if ( empty( $parse_able ) || '[' !== $parse_able ) {
                    $id_pattern = '/' . $this->grid_id_unique_name . '\:([\w-_]+)/';
                    $id_value = $found[4][ $key ];

                    preg_match( $id_pattern, $id_value, $id_matches );

                    if ( ! empty( $id_matches ) ) {
                        $id_to_save = $id_matches[1];

                        // why we need to check if shortcode is parse able?
                        // 1: if it is escaped it must not be displayed (parsed)
                        // 2: so if 1 is true it must not be saved in database meta
                        $shortcode_tag = $found[2][ $key ];
                        $shortcode_atts_string = $found[3][ $key ];
                        /** @var $atts array */
                        $atts = shortcode_parse_atts( $shortcode_atts_string );
                        $content = $found[6][ $key ];
                        $data = array(
                            'tag' => $shortcode_tag,
                            'atts' => $atts,
                            'content' => $content,
                        );

                        $to_save[ $id_to_save ] = $data;
                    }
                }
            }
        }
        if ( ! empty( $to_save ) ) {
            $settings['vc_grid_id'] = array( 'shortcodes' => $to_save );
        }
    }

    return $settings;
}```

我试过禁用所有插件并回滚wordpress版本,但还是一样。这个问题是不是和上面的警告有关?我对编码知之甚少。请给我指出正确的方向。
谢谢你,谢谢你

wfveoks0

wfveoks01#

完全相同的问题后端模式没有显示任何元素和/hook-vc-grid. php在第162行的错误.“[\w-_]是错误的,它必须是[\w-]“这只有助于消 debugging 误,但不是解决不显示元素。
编辑:php7.1工作。它解决了元素的事情也。谢谢大家

pcrecxhr

pcrecxhr2#

所有连字符'-'(不作为范围字符使用)应该转义'-'从PHP 7.3这样它将不再被视为范围字符。因此下面的WordPress函数需要这样改变,使这个表达式再次工作:

private function getShortcodeRegexForId() {
    return '\\['           // Opening bracket
        . '(\\[?)'         // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
        . '([\\w\-_]+)'    // 2: Shortcode name
        . '(?![\\w\-])'    // Not followed by word character or hyphen

相关问题