PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / 22.7.0
WPSSO Core – Complete Schema Markup and Meta Tags v22.7.0
22.7.0 22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / lib / json / type / qapage.php

qapage.php in WPSSO Core – Complete Schema Markup and Meta Tags 22.7.0, at lib/json/type/qapage.php

119 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * License: GPLv3
4 * License URI: https://www.gnu.org/licenses/gpl.txt
5 * Copyright 2016-2026 Jean-Sebastien Morisset (https://wpsso.com/)
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9
10 die( 'These aren\'t the droids you\'re looking for.' );
11 }
12
13 if ( ! class_exists( 'WpssoJsonTypeQAPage' ) ) {
14
15 class WpssoJsonTypeQAPage {
16
17 private $p; // Wpsso class object.
18
19 /*
20 * Instantiated by Wpsso->init_json_filters().
21 */
22 public function __construct( &$plugin ) {
23
24 $this->p =& $plugin;
25
26 if ( $this->p->debug->enabled ) {
27
28 $this->p->debug->mark();
29 }
30
31 $this->p->util->add_plugin_filters( $this, array(
32 'json_data_https_schema_org_qapage' => 5,
33 ) );
34 }
35
36 public function filter_json_data_https_schema_org_qapage( $json_data, $mod, $mt_og, $page_type_id, $is_main ) {
37
38 if ( $this->p->debug->enabled ) {
39
40 $this->p->debug->mark();
41 }
42
43 unset( $json_data[ 'mainEntityOfPage' ] );
44
45 $json_ret = array();
46
47 $question = WpssoSchema::get_schema_type_context( 'https://schema.org/Question' );
48
49 /*
50 * $question and $json_data are passed by reference.
51 */
52 WpssoSchema::move_data_itemprop_from_assoc( $question, $json_data, array(
53 'url' => 'url',
54 'name' => 'name',
55 'description' => 'description',
56 'text' => 'text',
57 'inLanguage' => 'inLanguage',
58 'dateCreated' => 'dateCreated',
59 'datePublished' => 'datePublished',
60 'dateModified' => 'dateModified',
61 'author' => 'author',
62 ) );
63
64 /*
65 * The 'description' property describes the question.
66 *
67 * If the question has a group heading then this may be an appropriate place to call out what that heading is.
68 */
69 if ( ! empty( $mod[ 'obj' ] ) ) {
70
71 /*
72 * The CreativeWork 'text' property may be empty if 'schema_def_add_text_prop' is unchecked.
73 */
74 if ( empty( $question[ 'text' ] ) ) {
75
76 $question[ 'text' ] = $this->p->page->get_text( $mod, $md_key = 'schema_text', $max_len = 'schema_text' );
77 }
78
79 $question[ 'description' ] = $mod[ 'obj' ]->get_options( $mod[ 'id' ], 'schema_qa_desc' );
80
81 /*
82 * If we have an accepted answer, then add the 'description' group heading to the accepted answer.
83 */
84 if ( ! empty( $question[ 'acceptedAnswer' ] ) ) {
85
86 $question[ 'acceptedAnswer' ][ 'description' ] = $question[ 'description' ];
87 }
88
89 } else {
90
91 unset( $question[ 'description' ] );
92
93 unset( $question[ 'acceptedAnswer' ][ 'description' ] );
94 }
95
96 /*
97 * Calculate the number of accepted and suggested answers.
98 */
99 $answer_count = empty( $question[ 'acceptedAnswer' ] ) ? 0 : 1;
100
101 if ( isset( $question[ 'suggestedAnswer' ] ) ) {
102
103 $answer_count += SucomUtil::is_non_assoc( $question[ 'suggestedAnswer' ] ) ? count( $question[ 'suggestedAnswer' ] ) : 1;
104 }
105
106 $question[ 'answerCount' ] = $answer_count;
107
108 $json_ret[ 'mainEntity' ] = $question;
109
110 if ( $this->p->debug->enabled ) {
111
112 $this->p->debug->log( 'merging json_data and json_ret arrays' );
113 }
114
115 return WpssoSchema::return_data_from_filter( $json_data, $json_ret, $is_main );
116 }
117 }
118 }
119