Как исправить «Предупреждение: preg_match () [function.preg-match]: ошибка компиляции: нечего повторять со смещением 1» в WordPress - PullRequest
0 голосов
/ 23 мая 2019

Когда я установил WooCommerce на страницу WordPress, у меня появилась возможность управлять этим недавно, я начинал получать эти ошибки всякий раз, когда перехожу на подстраницу:

Предупреждение: preg_match () [function.preg-match]: ошибка компиляции: ничего не нужно? Повторить со смещением 1 в /var/www/watertours.dk/public_html/wp-includes/class-wp.php в строке 222

Предупреждение: preg_match () [function.preg-match]: ошибка компиляции: ничего не повторяется со смещением 1 в /var/www/watertours.dk/public_html/wp-includes/class-wp.php на строке 223 "

Он даже иногда появляется на приборной панели.

Я нашел это руководство, которое уже пробовал несколько раз:

шаг 0: если возможно, сделайте резервную копию вашей установочной папки WP.

шаг 1: временно отключить все плагины (важный шаг)

шаг 2: в панели администратора WordPress перейдите в «Настройки» -> «Постоянные ссылки»

шаг 3: запомните или запишите где-нибудь, что у вас есть в поле пользовательских постоянных ссылок: http://awesomescreenshot.com/0534epzk0c 96

шаг 4: временно включить (переключиться на) постоянную ссылку по умолчанию: http://awesomescreenshot.com/0f74epyi15 79 Нажмите кнопку Сохранить изменения.

шаг 5: убедитесь, что веб-сайт работает (не все, потому что плагины отключены, но ошибка preg_match должна исчезнуть)

шаг 6: вернитесь к настройке пользовательских постоянных ссылок, которую вы использовали на шаге 3

шаг 7: включить обратно все плагины

Ошибка должна исчезнуть. "

Это работает некоторое время (две минуты или около того), а затем эти две ошибки начинают появляться снова.

Я думаю о том, чтобы просто переделать сайт WordPress с нуля, так как в любом случае это довольно беспорядок. Но если у кого-то есть решение, я буду более чем благодарен. :)

EDIT:

     * 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;
            }
        }```
...