Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/generato.../schema
File: faq.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Generators\Schema;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Returns schema FAQ data.
[5] Fix | Delete
*/
[6] Fix | Delete
class FAQ extends Abstract_Schema_Piece {
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Determines whether or not a piece should be added to the graph.
[10] Fix | Delete
*
[11] Fix | Delete
* @return bool
[12] Fix | Delete
*/
[13] Fix | Delete
public function is_needed() {
[14] Fix | Delete
if ( empty( $this->context->blocks['yoast/faq-block'] ) ) {
[15] Fix | Delete
return false;
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
if ( ! \is_array( $this->context->schema_page_type ) ) {
[19] Fix | Delete
$this->context->schema_page_type = [ $this->context->schema_page_type ];
[20] Fix | Delete
}
[21] Fix | Delete
$this->context->schema_page_type[] = 'FAQPage';
[22] Fix | Delete
$this->context->main_entity_of_page = $this->generate_ids();
[23] Fix | Delete
[24] Fix | Delete
return true;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Generate the IDs so we can link to them in the main entity.
[29] Fix | Delete
*
[30] Fix | Delete
* @return array
[31] Fix | Delete
*/
[32] Fix | Delete
private function generate_ids() {
[33] Fix | Delete
$ids = [];
[34] Fix | Delete
foreach ( $this->context->blocks['yoast/faq-block'] as $block ) {
[35] Fix | Delete
foreach ( $block['attrs']['questions'] as $index => $question ) {
[36] Fix | Delete
if ( ! isset( $question['jsonAnswer'] ) || empty( $question['jsonAnswer'] ) ) {
[37] Fix | Delete
continue;
[38] Fix | Delete
}
[39] Fix | Delete
$ids[] = [ '@id' => $this->context->canonical . '#' . \esc_attr( $question['id'] ) ];
[40] Fix | Delete
}
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
return $ids;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Render a list of questions, referencing them by ID.
[48] Fix | Delete
*
[49] Fix | Delete
* @return array Our Schema graph.
[50] Fix | Delete
*/
[51] Fix | Delete
public function generate() {
[52] Fix | Delete
$graph = [];
[53] Fix | Delete
[54] Fix | Delete
$questions = [];
[55] Fix | Delete
foreach ( $this->context->blocks['yoast/faq-block'] as $index => $block ) {
[56] Fix | Delete
$questions = \array_merge( $questions, $block['attrs']['questions'] );
[57] Fix | Delete
}
[58] Fix | Delete
foreach ( $questions as $index => $question ) {
[59] Fix | Delete
if ( ! isset( $question['jsonAnswer'] ) || empty( $question['jsonAnswer'] ) ) {
[60] Fix | Delete
continue;
[61] Fix | Delete
}
[62] Fix | Delete
$graph[] = $this->generate_question_block( $question, ( $index + 1 ) );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
return $graph;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Generate a Question piece.
[70] Fix | Delete
*
[71] Fix | Delete
* @param array $question The question to generate schema for.
[72] Fix | Delete
* @param int $position The position of the question.
[73] Fix | Delete
*
[74] Fix | Delete
* @return array Schema.org Question piece.
[75] Fix | Delete
*/
[76] Fix | Delete
protected function generate_question_block( $question, $position ) {
[77] Fix | Delete
$url = $this->context->canonical . '#' . \esc_attr( $question['id'] );
[78] Fix | Delete
[79] Fix | Delete
$data = [
[80] Fix | Delete
'@type' => 'Question',
[81] Fix | Delete
'@id' => $url,
[82] Fix | Delete
'position' => $position,
[83] Fix | Delete
'url' => $url,
[84] Fix | Delete
'name' => $this->helpers->schema->html->smart_strip_tags( $question['jsonQuestion'] ),
[85] Fix | Delete
'answerCount' => 1,
[86] Fix | Delete
'acceptedAnswer' => $this->add_accepted_answer_property( $question ),
[87] Fix | Delete
];
[88] Fix | Delete
[89] Fix | Delete
$data = $this->helpers->schema->language->add_piece_language( $data );
[90] Fix | Delete
[91] Fix | Delete
return $data;
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Adds the Questions `acceptedAnswer` property.
[96] Fix | Delete
*
[97] Fix | Delete
* @param array $question The question to add the acceptedAnswer to.
[98] Fix | Delete
*
[99] Fix | Delete
* @return array Schema.org Question piece.
[100] Fix | Delete
*/
[101] Fix | Delete
protected function add_accepted_answer_property( $question ) {
[102] Fix | Delete
$data = [
[103] Fix | Delete
'@type' => 'Answer',
[104] Fix | Delete
'text' => $this->helpers->schema->html->sanitize( $question['jsonAnswer'] ),
[105] Fix | Delete
];
[106] Fix | Delete
[107] Fix | Delete
$data = $this->helpers->schema->language->add_piece_language( $data );
[108] Fix | Delete
[109] Fix | Delete
return $data;
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function