| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Frontend\Schema |
| 6 |
*/ |
| 7 |
|
| 8 |
use Yoast\WP\SEO\Config\Schema_IDs; |
| 9 |
use Yoast\WP\SEO\Generators\Schema\Person; |
| 10 |
|
| 11 |
/** |
| 12 |
* Returns schema Person data. |
| 13 |
* |
| 14 |
* @since 10.2 |
| 15 |
* @deprecated 14.0 |
| 16 |
*/ |
| 17 |
class WPSEO_Schema_Person extends WPSEO_Deprecated_Graph_Piece { |
| 18 |
|
| 19 |
/** |
| 20 |
* The hash used for images. |
| 21 |
* |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
protected $image_hash = Schema_IDs::PERSON_LOGO_HASH; |
| 25 |
|
| 26 |
/** |
| 27 |
* Array of the social profiles we display for a Person. |
| 28 |
* |
| 29 |
* @var string[] |
| 30 |
*/ |
| 31 |
private $social_profiles = [ |
| 32 |
'facebook', |
| 33 |
'instagram', |
| 34 |
'linkedin', |
| 35 |
'pinterest', |
| 36 |
'twitter', |
| 37 |
'myspace', |
| 38 |
'youtube', |
| 39 |
'soundcloud', |
| 40 |
'tumblr', |
| 41 |
'wikipedia', |
| 42 |
]; |
| 43 |
|
| 44 |
/** |
| 45 |
* WPSEO_Schema_Person constructor. |
| 46 |
* |
| 47 |
* @deprecated 14.0 |
| 48 |
* @codeCoverageIgnore |
| 49 |
* |
| 50 |
* @param null $context The context. No longer used but present for BC. |
| 51 |
*/ |
| 52 |
public function __construct( $context = null ) { |
| 53 |
parent::__construct( Person::class ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Determines a User ID for the Person data. |
| 58 |
* |
| 59 |
* @deprecated 14.0 |
| 60 |
* @codeCoverageIgnore |
| 61 |
* |
| 62 |
* @return bool|int User ID or false upon return. |
| 63 |
*/ |
| 64 |
protected function determine_user_id() { |
| 65 |
_deprecated_function( __METHOD__, 'WPSEO 14.0', 'Yoast\WP\SEO\Generators\Schema\Person::determine_user_id' ); |
| 66 |
|
| 67 |
return $this->stable->determine_user_id(); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Retrieve a list of social profile URLs for Person. |
| 72 |
* |
| 73 |
* @deprecated 14.0 |
| 74 |
* @codeCoverageIgnore |
| 75 |
* |
| 76 |
* @param int $user_id User ID. |
| 77 |
* |
| 78 |
* @return string[] A list of social profiles. |
| 79 |
*/ |
| 80 |
protected function get_social_profiles( $user_id ) { |
| 81 |
_deprecated_function( __METHOD__, 'WPSEO 14.0', 'Yoast\WP\SEO\Generators\Schema\Person::get_social_profiles' ); |
| 82 |
|
| 83 |
/** |
| 84 |
* Filter: 'wpseo_schema_person_social_profiles' - Allows filtering of social profiles per user. |
| 85 |
* |
| 86 |
* @param int $user_id The current user we're grabbing social profiles for. |
| 87 |
* |
| 88 |
* @api string[] $social_profiles The array of social profiles to retrieve. Each should be a user meta field |
| 89 |
* key. As they are retrieved using the WordPress function `get_the_author_meta`. |
| 90 |
*/ |
| 91 |
$social_profiles = apply_filters( 'wpseo_schema_person_social_profiles', $this->social_profiles, $user_id ); |
| 92 |
$output = []; |
| 93 |
|
| 94 |
// We can only handle an array. |
| 95 |
if ( ! is_array( $social_profiles ) ) { |
| 96 |
return $output; |
| 97 |
} |
| 98 |
|
| 99 |
foreach ( $social_profiles as $profile ) { |
| 100 |
// Skip non-string values. |
| 101 |
if ( ! is_string( $profile ) ) { |
| 102 |
continue; |
| 103 |
} |
| 104 |
|
| 105 |
$social_url = $this->url_social_site( $profile, $user_id ); |
| 106 |
if ( $social_url ) { |
| 107 |
$output[] = $social_url; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
return $output; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Builds our array of Schema Person data for a given user ID. |
| 116 |
* |
| 117 |
* @deprecated 14.0 |
| 118 |
* @codeCoverageIgnore |
| 119 |
* |
| 120 |
* @param int $user_id The user ID to use. |
| 121 |
* |
| 122 |
* @return array An array of Schema Person data. |
| 123 |
*/ |
| 124 |
protected function build_person_data( $user_id ) { |
| 125 |
_deprecated_function( __METHOD__, 'WPSEO 14.0', 'Yoast\WP\SEO\Generators\Schema\Person::build_person_data' ); |
| 126 |
|
| 127 |
return $this->stable->build_person_data( $user_id ); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Returns an ImageObject for the persons avatar. |
| 132 |
* |
| 133 |
* @deprecated 14.0 |
| 134 |
* @codeCoverageIgnore |
| 135 |
* |
| 136 |
* @param array $data The Person schema. |
| 137 |
* @param WP_User $user_data User data. |
| 138 |
* |
| 139 |
* @return array The Person schema. |
| 140 |
*/ |
| 141 |
protected function add_image( $data, $user_data ) { |
| 142 |
_deprecated_function( __METHOD__, 'WPSEO 14.0', 'Yoast\WP\SEO\Generators\Schema\Person::add_image' ); |
| 143 |
|
| 144 |
return $this->stable->add_image( $data, $user_data ); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Returns an author's social site URL. |
| 149 |
* |
| 150 |
* @deprecated 14.0 |
| 151 |
* @codeCoverageIgnore |
| 152 |
* |
| 153 |
* @param string $social_site The social site to retrieve the URL for. |
| 154 |
* @param mixed $user_id The user ID to use function outside of the loop. |
| 155 |
* |
| 156 |
* @return string |
| 157 |
*/ |
| 158 |
protected function url_social_site( $social_site, $user_id = false ) { |
| 159 |
_deprecated_function( __METHOD__, 'WPSEO 14.0', 'Yoast\WP\SEO\Generators\Schema\Person::url_social_site' ); |
| 160 |
|
| 161 |
$url = get_the_author_meta( $social_site, $user_id ); |
| 162 |
|
| 163 |
if ( ! empty( $url ) && $social_site === 'twitter' ) { |
| 164 |
$url = 'https://twitter.com/' . $url; |
| 165 |
} |
| 166 |
|
| 167 |
return $url; |
| 168 |
} |
| 169 |
} |
| 170 |
|