Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema.org JSON: Play #21

Open
Tracked by #19
carstingaxion opened this issue Mar 1, 2024 · 1 comment
Open
Tracked by #19

Schema.org JSON: Play #21

carstingaxion opened this issue Mar 1, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@carstingaxion
Copy link
Member

No description provided.

@carstingaxion
Copy link
Member Author

carstingaxion commented Mar 1, 2024

Idea

class Play extends Abstract_Schema_Piece {
  
    /**
     * A value object with context variables.
     *
     * @var WPSEO_Schema_Context
     */
    public $context;
  
    /**
     * Play constructor.
     *
     * @param WPSEO_Schema_Context $context Value object with context variables.
     */
    public function __construct( WPSEO_Schema_Context $context ) {
        $this->context = $context;
    }
  
    /**
     * Determines whether or not a piece should be added to the graph.
     *
     * @return bool Whether or not a piece should be added.
     */
    public function is_needed() {
        // Check if the current context requires a play schema
        return $this->context->indexable->object_type === 'play';
    }
  
    /**
     * Add Play piece of the graph.
     *
     * @return mixed
     */
    public function generate() {
        // Retrieve play data from context or other source
        $play_title = $this->context->post->post_title;
        $play_description = $this->context->post->post_content;
        $play_author = get_post_meta( $this->context->post->ID, 'play_author', true );
        $play_director = get_post_meta( $this->context->post->ID, 'play_director', true );
        $play_duration = get_post_meta( $this->context->post->ID, 'play_duration', true );
        $play_start_date = get_post_meta( $this->context->post->ID, 'play_start_date', true );
        $play_end_date = get_post_meta( $this->context->post->ID, 'play_end_date', true );
        $play_venue = get_post_meta( $this->context->post->ID, 'play_venue', true );
      
        // Construct play schema
        $play_schema = array(
            '@type' => 'Play',
            'name' => $play_title,
            'description' => $play_description,
            'author' => $play_author,
            'director' => $play_director,
            'duration' => $play_duration,
            'startDate' => $play_start_date,
            'endDate' => $play_end_date,
            'location' => array(
                '@type' => 'Place',
                'name' => $play_venue
            )
        );
      
        return $play_schema;
    }
}

@carstingaxion carstingaxion added the enhancement New feature or request label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant