Ошибка походу критическая

Ответов: 2

Warning: Undefined array key 0 in /var/www/u2720365/data/www/antiterror.press/wp-content/themes/journalx/vendor/wpshop/core/src/Template.php on line 251

Warning: Attempt to read property "cat_ID" on null in /var/www/u2720365/data/www/antiterror.press/wp-content/themes/journalx/vendor/wpshop/core/src/Template.php on line 251
Вот что пишет, кто может помочь?
Тема JournalX

Ответов: 25

Эта ошибка возникает, когда удалена стандартная категория Uncategorized. Тема при связывании записи к категории не проверяет, существует ли категория или нет. То есть, нужно добавить категорию по умолчанию, либо в код /core/src/Template.php добавить проверку на существование категории.

Нужно в этом файле .php найти секцию с Yoast, которая начинается со строки:

public function get_category( $args = array() ) {

И полностью заменить секцию Yoast на этот код:

public function get_category( $args = array() ) {
        $defaults = array(
            'post'      => '',
            'classes'   => '',
            'micro'     => true,
            'micro_out' => ' itemprop="articleSection"',
            'link'      => true,
        );
        $args = wp_parse_args($args, $defaults);

        if ( is_array( $args ) ) {
            $post = $args['post'];
        } else {
            $post = null;
        }

        if ( ! $post = get_post( $post ) ) {
            return false;
        }

        $category = get_the_category( $post->ID );

        // Fix: Check if category exists before accessing
        if ( empty( $category ) ) {
            return '';
        }

        $classes_out = '';
        if ( ! empty( $args['classes'] ) ) {
            $classes_out = ' class="' . $args['classes'] . '"';
        }

        $cat_id = $category[0]->cat_ID;

        // Fix: Validate Yoast primary term
        if ( class_exists( 'WPSEO_Primary_Term' ) ) {
            $primary_cat = new WPSEO_Primary_Term( 'category', $post->ID );
            $primary_cat_id = $primary_cat->get_primary_term();

            if ( $primary_cat_id ) {
                $term = get_term( $primary_cat_id );
                if ( ! is_wp_error( $term ) && $term ) {
                    $cat_id = $primary_cat_id;
                }
            }
        }

        if ( $args['micro'] ) {
            $micro_out = $args['micro_out'];
        } else {
            $micro_out = '';
        }

        if ( $args['link'] ) {
            $link = get_term_link( $cat_id );
            if ( is_wp_error( $link ) ) {
                $link = '#';
            }
            return '<a href="' . $link . '"' . $micro_out . $classes_out . '>' . get_cat_name( $cat_id ) . '</a>';
        } else {
            return '<span' . $micro_out . $classes_out . '>' . get_cat_name( $cat_id ) . '</span>';
        }
    }

Бэкап, конечно, лучше сделать))