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

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

109 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( 'WpssoJsonTypeProfilePage' ) ) {
14
15 class WpssoJsonTypeProfilePage {
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_profilepage' => 5,
33 ) );
34 }
35
36 /*
37 * See https://developers.google.cn/search/docs/appearance/structured-data/profile-page.
38 */
39 public function filter_json_data_https_schema_org_profilepage( $json_data, $mod, $mt_og, $page_type_id, $is_main ) {
40
41 if ( $this->p->debug->enabled ) {
42
43 $this->p->debug->mark();
44 }
45
46 /*
47 * Maybe add a "mentions" property with any post schema type.
48 */
49 $prop_type_ids = empty( $this->p->options[ 'schema_def_profile_page_mentions_prop' ] ) ? array() : array( 'mentions' => false );
50
51 WpssoSchema::add_posts_data( $json_data, $mod, $mt_og, $page_type_id, $is_main, $prop_type_ids );
52
53 /*
54 * Add the Schema Person as the 'mainEntity'.
55 */
56 $user_id = 'none';
57
58 if ( ! empty( $mod[ 'obj' ] ) ) { // Just in case.
59
60 $user_id = $mod[ 'obj' ]->get_options( $mod[ 'id' ], 'schema_profile_person_id', $filter_opts = true, $merge_defs = true );
61 }
62
63 if ( empty( $user_id ) || 'none' === $user_id ) {
64
65 if ( $mod[ 'is_home' ] ) { // Home page (static or blog archive).
66
67 $user_id = $this->p->options[ 'site_pub_person_id' ]; // 'none' by default.
68
69 } elseif ( $mod[ 'is_user' ] ) {
70
71 $user_id = $mod[ 'id' ]; // Could be false.
72
73 } else $user_id = 'none';
74
75 if ( empty( $user_id ) || 'none' === $user_id ) {
76
77 if ( $this->p->debug->enabled ) {
78
79 $this->p->debug->log( 'exiting early: user ID is empty or "none"' );
80 }
81
82 return $json_data;
83 }
84 }
85
86 /*
87 * $user_id can be 'none' or a number (including 0).
88 */
89 if ( $this->p->debug->enabled ) {
90
91 $this->p->debug->log( 'adding data for person id = ' . $user_id );
92 }
93
94 unset( $json_data[ 'mainEntityOfPage' ] );
95
96 $json_data[ 'mainEntity' ] = null;
97
98 if ( $this->p->debug->enabled ) {
99
100 $this->p->debug->log( 'merging json_data and json_ret arrays' );
101 }
102
103 WpssoSchemaSingle::add_person_data( $json_data[ 'mainEntity' ], $mod, $user_id, $list_el = false );
104
105 return $json_data;
106 }
107 }
108 }
109