data = $data; $this->block = $block; $this->context = $context; $this->position = 0; } /** * Find an image based on its URL and generate a Schema object for it. * * @return array The Schema with Questions added. */ public function generate() { foreach ( $this->block['attrs']['questions'] as $question ) { if ( ! isset( $question['jsonAnswer'] ) || empty( $question['jsonAnswer'] ) ) { continue; } $this->data[] = $this->generate_question_block( $question ); } return $this->data; } /** * Generate a Question piece. * * @param array $question The question to generate schema for. * * @return array Schema.org Question piece. */ protected function generate_question_block( $question ) { $url = $this->context->canonical . '#' . esc_attr( $question['id'] ); return [ '@type' => 'Question', '@id' => $url, 'position' => $this->position ++, 'url' => $url, 'name' => wp_strip_all_tags( $question['jsonQuestion'] ), 'answerCount' => 1, 'acceptedAnswer' => [ '@type' => 'Answer', 'text' => strip_tags( $question['jsonAnswer'], '