• Resolved hughie.molloy

    (@hughiemolloy)


    Trying to get property ‘display_name’ of non-object

    /wp-content/plugins/wordpress-seo/src/generators/schema/article.php:52

    When one calls wp_insert_post without a post_author set, the value of 0 is stored in the DB. get_userdata then returns false.

    The code should be like

    $data   = [
    	'@type'            => $this->context->schema_article_type,
    	'@id'              => $this->context->canonical . Schema_IDs::ARTICLE_HASH,
    	'isPartOf'         => [ '@id' => $this->context->main_schema_id ],
    	'headline'         => $this->helpers->schema->html->smart_strip_tags( $this->helpers->post->get_post_title_with_fallback( $this->context->id ) ),
    	'datePublished'    => $this->helpers->date->format( $this->context->post->post_date_gmt ),
    	'dateModified'     => $this->helpers->date->format( $this->context->post->post_modified_gmt ),
    	'mainEntityOfPage' => [ '@id' => $this->context->main_schema_id ],
    	'wordCount'        => $this->word_count( $this->context->post->post_content, $this->context->post->post_title ),
    ];
    
    $author = \get_userdata( $this->context->post->post_author );
    if ($author instanceof WP_User) {
        $data['author'] = [
            'name' => $this->helpers->schema->html->smart_strip_tags( $author->display_name ),
            '@id'  => $this->helpers->schema->id->get_user_schema_id( $this->context->post->post_author, $this->context ),
        ];
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Bug when no author’ is closed to new replies.