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 / question.php

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

94 lines 2.6 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( 'WpssoJsonTypeQuestion' ) ) {
14
15 class WpssoJsonTypeQuestion {
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_question' => 5,
33 ) );
34 }
35
36 public function filter_json_data_https_schema_org_question( $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 $json_ret = array();
44
45 WpssoSchema::add_data_itemprop_from_assoc( $json_ret, $json_data, array(
46 'text' => 'name',
47 ) );
48
49 /*
50 * Answer:
51 *
52 * Schema Question is a sub-type of CreativeWork. We already have the question in 'name' (the post/page
53 * title), the answer excerpt in 'description', and the full answer text in 'text'. Create the answer
54 * first, before changing / removing some question properties.
55 */
56 $accepted_answer = WpssoSchema::get_schema_type_context( 'https://schema.org/Answer' );
57
58 WpssoSchema::add_data_itemprop_from_assoc( $accepted_answer, $json_data, array(
59 'url' => 'url',
60 'name' => 'description', // The Answer name is CreativeWork custom description or excerpt.
61 'text' => 'text', // May not exist if the 'schema_def_add_text_prop' option is disabled.
62 'inLanguage' => 'inLanguage',
63 ) );
64
65 unset( $json_data[ 'description' ] );
66
67 if ( empty( $accepted_answer[ 'text' ] ) ) { // May not exist if the 'schema_def_add_text_prop' option is disabled.
68
69 $accepted_answer[ 'text' ] = $this->p->page->get_text( $mod, $md_key = 'schema_text', $max_len = 'schema_text' );
70 }
71
72 WpssoSchema::add_data_itemprop_from_assoc( $accepted_answer, $json_ret, array(
73 'dateCreated' => 'dateCreated',
74 'datePublished' => 'datePublished',
75 'dateModified' => 'dateModified',
76 'author' => 'author',
77 ) );
78
79 $accepted_answer[ 'upvoteCount' ] = 0;
80
81 $json_ret[ 'acceptedAnswer' ] = $accepted_answer;
82
83 $json_ret[ 'answerCount' ] = 1;
84
85 if ( $this->p->debug->enabled ) {
86
87 $this->p->debug->log( 'merging json_data and json_ret arrays' );
88 }
89
90 return WpssoSchema::return_data_from_filter( $json_data, $json_ret, $is_main );
91 }
92 }
93 }
94