| 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( 'WpssoJsonTypePerson' ) ) { |
| 14 |
|
| 15 |
class WpssoJsonTypePerson { |
| 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_person' => 5, |
| 33 |
) ); |
| 34 |
} |
| 35 |
|
| 36 |
public function filter_json_data_https_schema_org_person( $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 |
$user_id = 'none'; |
| 44 |
|
| 45 |
if ( ! empty( $mod[ 'obj' ] ) ) { // Just in case. |
| 46 |
|
| 47 |
$user_id = $mod[ 'obj' ]->get_options( $mod[ 'id' ], 'schema_person_id', $filter_opts = true, $merge_defs = true ); |
| 48 |
} |
| 49 |
|
| 50 |
if ( empty( $user_id ) || 'none' === $user_id ) { |
| 51 |
|
| 52 |
if ( $mod[ 'is_home' ] ) { // Home page (static or blog archive). |
| 53 |
|
| 54 |
$user_id = $this->p->options[ 'site_pub_person_id' ]; // 'none' by default. |
| 55 |
|
| 56 |
} elseif ( $mod[ 'is_user' ] ) { |
| 57 |
|
| 58 |
$user_id = $mod[ 'id' ]; // Could be false. |
| 59 |
|
| 60 |
} else $user_id = 'none'; |
| 61 |
|
| 62 |
if ( empty( $user_id ) || 'none' === $user_id ) { |
| 63 |
|
| 64 |
if ( $this->p->debug->enabled ) { |
| 65 |
|
| 66 |
$this->p->debug->log( 'exiting early: user ID is empty or "none"' ); |
| 67 |
} |
| 68 |
|
| 69 |
return $json_data; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/* |
| 74 |
* Possibly inherit the schema type. |
| 75 |
*/ |
| 76 |
if ( $this->p->debug->enabled ) { |
| 77 |
|
| 78 |
$this->p->debug->log( 'possibly inherit the schema type' ); |
| 79 |
|
| 80 |
$this->p->debug->log_arr( 'json_data', $json_data ); |
| 81 |
} |
| 82 |
|
| 83 |
$json_ret = WpssoSchema::get_data_context( $json_data ); // Returns array() if no schema type found. |
| 84 |
|
| 85 |
/* |
| 86 |
* $user_id can be 'none' or a number (including 0). |
| 87 |
*/ |
| 88 |
if ( $this->p->debug->enabled ) { |
| 89 |
|
| 90 |
$this->p->debug->log( 'adding data for person id = ' . $user_id ); |
| 91 |
} |
| 92 |
|
| 93 |
WpssoSchemaSingle::add_person_data( $json_ret, $mod, $user_id, $list_el = false ); |
| 94 |
|
| 95 |
/* |
| 96 |
* Override author's website url and use the og url instead. |
| 97 |
*/ |
| 98 |
if ( $mod[ 'is_home' ] ) { // Home page (static or blog archive). |
| 99 |
|
| 100 |
$json_ret[ 'url' ] = SucomUtilWP::get_home_url( $this->p->options, $mod ); |
| 101 |
} |
| 102 |
|
| 103 |
if ( $this->p->debug->enabled ) { |
| 104 |
|
| 105 |
$this->p->debug->log( 'merging json_data and json_ret arrays' ); |
| 106 |
} |
| 107 |
|
| 108 |
return WpssoSchema::return_data_from_filter( $json_data, $json_ret, $is_main ); |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|