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

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

151 lines 3.7 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( 'WpssoJsonTypeWebpage' ) ) {
14
15 class WpssoJsonTypeWebpage {
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_webpage' => 5,
33 ) );
34 }
35
36 public function filter_json_data_https_schema_org_webpage( $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 $filter_name = 'wpsso_json_prop_https_schema_org_breadcrumb';
46
47 if ( $this->p->debug->enabled ) {
48
49 $this->p->debug->log( 'applying filters "' . $filter_name . '"' );
50 }
51
52 $crumb_data = apply_filters( $filter_name, array(), $mod, $mt_og, $page_type_id, $is_main );
53
54 if ( ! empty( $crumb_data ) ) {
55
56 $json_ret[ 'breadcrumb' ] = $crumb_data;
57 }
58
59 if ( ! empty( $json_data[ 'image' ][ 0 ] ) ) {
60
61 if ( ! empty( $json_data[ 'image' ][ 0 ][ '@id' ] ) ) {
62
63 $json_ret[ 'primaryImageOfPage' ] = array( '@id' => $json_data[ 'image' ][ 0 ][ '@id' ] );
64
65 } else {
66
67 $json_ret[ 'primaryImageOfPage' ] = $json_data[ 'image' ][ 0 ];
68 }
69 }
70
71 $json_ret[ 'potentialAction' ][] = WpssoSchema::get_schema_type_context( 'https://schema.org/ReadAction', array(
72 'target' => $json_data[ 'url' ],
73 ) );
74
75 /*
76 * Since WPSSO Core v13.10.0.
77 *
78 * Add reviewed by organizations and persons.
79 *
80 * See https://schema.org/reviewedBy.
81 */
82 if ( is_object( $mod[ 'obj' ] ) && $mod[ 'id' ] ) { // Just in case.
83
84 $md_opts = $mod[ 'obj' ]->get_options( $mod[ 'id' ] );
85
86 foreach ( array(
87 'schema_webpage_reviewed_by_org_id' => 'reviewedBy',
88 'schema_webpage_reviewed_by_person_id' => 'reviewedBy',
89 ) as $opt_pre => $prop_name ) {
90
91 foreach ( SucomUtil::preg_grep_keys( '/^' . $opt_pre . '(_[0-9]+)?$/', $md_opts ) as $opt_key => $id ) {
92
93 if ( ! SucomUtil::is_valid_option_value( $id ) ) { // Not true, false, null, empty string, or 'none'.
94
95 continue;
96 }
97
98 switch ( $opt_pre ) {
99
100 case 'schema_webpage_reviewed_by_org_id':
101
102 WpssoSchemaSingle::add_organization_data( $json_ret[ $prop_name ], $mod, $id,
103 $org_logo_key = 'org_logo_url', $list_el = true );
104
105 break;
106
107 case 'schema_webpage_reviewed_by_person_id':
108
109 WpssoSchemaSingle::add_person_data( $json_ret[ $prop_name ], $mod, $id, $list_el = true );
110
111 break;
112 }
113 }
114 }
115 }
116
117 /*
118 * See https://schema.org/lastReviewed.
119 */
120 if ( is_object( $mod[ 'obj' ] ) && $mod[ 'id' ] ) { // Just in case.
121
122 if ( $date = WpssoSchema::get_opts_date_iso( $md_opts, 'schema_webpage_reviewed_last' ) ) {
123
124 $json_ret[ 'lastReviewed' ] = $date;
125 }
126 }
127
128 /*
129 * See https://schema.org/speakable.
130 */
131 if ( ! empty( $this->p->options[ 'plugin_speakable_css_csv' ] ) ) {
132
133 $speakable_css_sel = SucomUtil::explode_csv( $this->p->options[ 'plugin_speakable_css_csv' ] );
134
135 if ( ! empty( $speakable_css_sel ) ) {
136
137 $json_ret[ 'speakable' ] = WpssoSchema::get_schema_type_context( 'https://schema.org/SpeakableSpecification', array(
138 'cssSelector' => $speakable_css_sel ) );
139 }
140 }
141
142 if ( $this->p->debug->enabled ) {
143
144 $this->p->debug->log( 'merging json_data and json_ret arrays' );
145 }
146
147 return WpssoSchema::return_data_from_filter( $json_data, $json_ret, $is_main );
148 }
149 }
150 }
151