如何在WordPress中修复“警告:preg_match()[function.preg-match]:编译失败:在偏移量1处没有重复的内容”

时间:2019-05-23 12:19:18

标签: php wordpress woocommerce permalinks

当我在WordPress页面上安装WooCommerce时,我才有机会进行管理,每当我进入子页面时,我就开始出现这些错误:

  

警告:preg_match()[function.preg-match]:编译失败:在第222行的/var/www/watertours.dk/public_html/wp-includes/class-wp.php中的偏移量1上没有要重复的内容

     

警告:preg_match()[function.preg-match]:编译失败:在第223行的/var/www/watertours.dk/public_html/wp-includes/class-wp.php中,偏移1处没有重复的内容”

它甚至偶尔会出现在仪表板中。

我找到了已经尝试过几次的本指南:

  

第0步:如果可能,请备份您的WP安装文件夹。

     

步骤1:暂时停用所有插件(重要步骤)

     

步骤2:在WordPress管理控制台中,转到设置->永久链接

     

第3步:记住或记下自定义永久链接字段中的内容:http://awesomescreenshot.com/0534epzk0c 96

     

步骤4:临时启用(切换至)默认永久链接:http://awesomescreenshot.com/0f74epyi15 79单击“保存更改”按钮。

     

第5步:验证网站现在是否正常运行(不是所有功能,因为插件已被禁用,但preg_match错误应该消失了)

     

步骤6:切换回步骤3的自定义永久链接设置

     

第7步:启用所有插件

     

错误应该消失了。”

它会工作一会儿(两分钟左右),然后这两个错误再次弹出。

我正在考虑从头开始重新构建WordPress网站,因为无论如何它都是一团糟。但是,如果有人有解决方案,我将不胜感激。 :)

编辑:

     * Parse request to find correct WordPress query.
     *
     * Sets up the query variables based on the request. There are also many
     * filters and actions that can be used to further manipulate the result.
     *
     * @since 2.0.0
     *
     * @global WP_Rewrite $wp_rewrite
     *
     * @param array|string $extra_query_vars Set the extra query variables.
     */
    public function parse_request( $extra_query_vars = '' ) {
        global $wp_rewrite;

        /**
         * Filters whether to parse the request.
         *
         * @since 3.5.0
         *
         * @param bool         $bool             Whether or not to parse the request. Default true.
         * @param WP           $this             Current WordPress environment instance.
         * @param array|string $extra_query_vars Extra passed query variables.
         */
        if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) ) {
            return;
        }

        $this->query_vars     = array();
        $post_type_query_vars = array();

        if ( is_array( $extra_query_vars ) ) {
            $this->extra_query_vars = & $extra_query_vars;
        } elseif ( ! empty( $extra_query_vars ) ) {
            parse_str( $extra_query_vars, $this->extra_query_vars );
        }
        // Process PATH_INFO, REQUEST_URI, and 404 for permalinks.

        // Fetch the rewrite rules.
        $rewrite = $wp_rewrite->wp_rewrite_rules();

        if ( ! empty( $rewrite ) ) {
            // If we match a rewrite rule, this will be cleared.
            $error               = '404';
            $this->did_permalink = true;

            $pathinfo         = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';
            list( $pathinfo ) = explode( '?', $pathinfo );
            $pathinfo         = str_replace( '%', '%25', $pathinfo );

            list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] );
            $self            = $_SERVER['PHP_SELF'];
            $home_path       = trim( parse_url( home_url(), PHP_URL_PATH ), '/' );
            $home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) );

            // Trim path info from the end and the leading home path from the
            // front. For path info requests, this leaves us with the requesting
            // filename, if any. For 404 requests, this leaves us with the
            // requested permalink.
            $req_uri  = str_replace( $pathinfo, '', $req_uri );
            $req_uri  = trim( $req_uri, '/' );
            $req_uri  = preg_replace( $home_path_regex, '', $req_uri );
            $req_uri  = trim( $req_uri, '/' );
            $pathinfo = trim( $pathinfo, '/' );
            $pathinfo = preg_replace( $home_path_regex, '', $pathinfo );
            $pathinfo = trim( $pathinfo, '/' );
            $self     = trim( $self, '/' );
            $self     = preg_replace( $home_path_regex, '', $self );
            $self     = trim( $self, '/' );

            // The requested permalink is in $pathinfo for path info requests and
            //  $req_uri for other requests.
            if ( ! empty( $pathinfo ) && ! preg_match( '|^.*' . $wp_rewrite->index . '$|', $pathinfo ) ) {
                $requested_path = $pathinfo;
            } else {
                // If the request uri is the index, blank it out so that we don't try to match it against a rule.
                if ( $req_uri == $wp_rewrite->index ) {
                    $req_uri = '';
                }
                $requested_path = $req_uri;
            }
            $requested_file = $req_uri;

            $this->request = $requested_path;

            // Look for matches.
            $request_match = $requested_path;
            if ( empty( $request_match ) ) {
                // An empty request could only match against ^$ regex
                if ( isset( $rewrite['$'] ) ) {
                    $this->matched_rule = '$';
                    $query              = $rewrite['$'];
                    $matches            = array( '' );
                }
            } else {
                foreach ( (array) $rewrite as $match => $query ) {
                    // If the requested file is the anchor of the match, prepend it to the path info.
                    if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) {
                        $request_match = $requested_file . '/' . $requested_path;
                    }

                    if ( preg_match( "#^$match#", $request_match, $matches ) || // Line 222
                        preg_match( "#^$match#", urldecode( $request_match ), $matches ) ) { // Line 223

                        if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
                            // This is a verbose page match, let's check to be sure about it.
                            $page = get_page_by_path( $matches[ $varmatch[1] ] );
                            if ( ! $page ) {
                                continue;
                            }

                            $post_status_obj = get_post_status_object( $page->post_status );
                            if ( ! $post_status_obj->public && ! $post_status_obj->protected
                                && ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
                                continue;
                            }
                        }

                        // Got a match.
                        $this->matched_rule = $match;
                        break;
                    }
                }
            }

            if ( isset( $this->matched_rule ) ) {
                // Trim the query of everything up to the '?'.
                $query = preg_replace( '!^.+\?!', '', $query );

                // Substitute the substring matches into the query.
                $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) );

                $this->matched_query = $query;

                // Parse the query.
                parse_str( $query, $perma_query_vars );

                // If we're processing a 404 request, clear the error var since we found something.
                if ( '404' == $error ) {
                    unset( $error, $_GET['error'] );
                }
            }

            // If req_uri is empty or if it is a request for ourself, unset error.
            if ( empty( $requested_path ) || $requested_file == $self || strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) {
                unset( $error, $_GET['error'] );

                if ( isset( $perma_query_vars ) && strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) {
                    unset( $perma_query_vars );
                }

                $this->did_permalink = false;
            }
        }```

0 个答案:

没有答案