Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../src/generato.../schema
File: person.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Generators\Schema;
[2] Fix | Delete
[3] Fix | Delete
use WP_User;
[4] Fix | Delete
use Yoast\WP\SEO\Config\Schema_IDs;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Returns schema Person data.
[8] Fix | Delete
*/
[9] Fix | Delete
class Person extends Abstract_Schema_Piece {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Array of the social profiles we display for a Person.
[13] Fix | Delete
*
[14] Fix | Delete
* @var string[]
[15] Fix | Delete
*/
[16] Fix | Delete
private $social_profiles = [
[17] Fix | Delete
'facebook',
[18] Fix | Delete
'instagram',
[19] Fix | Delete
'linkedin',
[20] Fix | Delete
'pinterest',
[21] Fix | Delete
'twitter',
[22] Fix | Delete
'myspace',
[23] Fix | Delete
'youtube',
[24] Fix | Delete
'soundcloud',
[25] Fix | Delete
'tumblr',
[26] Fix | Delete
'wikipedia',
[27] Fix | Delete
];
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* The Schema type we use for this class.
[31] Fix | Delete
*
[32] Fix | Delete
* @var string[]
[33] Fix | Delete
*/
[34] Fix | Delete
protected $type = [ 'Person', 'Organization' ];
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Determine whether we should return Person schema.
[38] Fix | Delete
*
[39] Fix | Delete
* @return bool
[40] Fix | Delete
*/
[41] Fix | Delete
public function is_needed() {
[42] Fix | Delete
// Using an author piece instead.
[43] Fix | Delete
if ( $this->site_represents_current_author() ) {
[44] Fix | Delete
return false;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
return $this->context->site_represents === 'person';
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Returns Person Schema data.
[52] Fix | Delete
*
[53] Fix | Delete
* @return bool|array<string|string[]> Person data on success, false on failure.
[54] Fix | Delete
*/
[55] Fix | Delete
public function generate() {
[56] Fix | Delete
$user_id = $this->determine_user_id();
[57] Fix | Delete
if ( ! $user_id ) {
[58] Fix | Delete
return false;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
return $this->build_person_data( $user_id );
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Determines a User ID for the Person data.
[66] Fix | Delete
*
[67] Fix | Delete
* @return bool|int User ID or false upon return.
[68] Fix | Delete
*/
[69] Fix | Delete
protected function determine_user_id() {
[70] Fix | Delete
/**
[71] Fix | Delete
* Filter: 'wpseo_schema_person_user_id' - Allows filtering of user ID used for person output.
[72] Fix | Delete
*
[73] Fix | Delete
* @param int|bool $user_id The user ID currently determined.
[74] Fix | Delete
*/
[75] Fix | Delete
$user_id = \apply_filters( 'wpseo_schema_person_user_id', $this->context->site_user_id );
[76] Fix | Delete
[77] Fix | Delete
// It should to be an integer higher than 0.
[78] Fix | Delete
if ( \is_int( $user_id ) && $user_id > 0 ) {
[79] Fix | Delete
return $user_id;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
return false;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Retrieve a list of social profile URLs for Person.
[87] Fix | Delete
*
[88] Fix | Delete
* @param string[] $same_as_urls Array of SameAs URLs.
[89] Fix | Delete
* @param int $user_id User ID.
[90] Fix | Delete
*
[91] Fix | Delete
* @return string[] A list of SameAs URLs.
[92] Fix | Delete
*/
[93] Fix | Delete
protected function get_social_profiles( $same_as_urls, $user_id ) {
[94] Fix | Delete
/**
[95] Fix | Delete
* Filter: 'wpseo_schema_person_social_profiles' - Allows filtering of social profiles per user.
[96] Fix | Delete
*
[97] Fix | Delete
* @param string[] $social_profiles The array of social profiles to retrieve. Each should be a user meta field
[98] Fix | Delete
* key. As they are retrieved using the WordPress function `get_the_author_meta`.
[99] Fix | Delete
* @param int $user_id The current user we're grabbing social profiles for.
[100] Fix | Delete
*/
[101] Fix | Delete
$social_profiles = \apply_filters( 'wpseo_schema_person_social_profiles', $this->social_profiles, $user_id );
[102] Fix | Delete
[103] Fix | Delete
// We can only handle an array.
[104] Fix | Delete
if ( ! \is_array( $social_profiles ) ) {
[105] Fix | Delete
return $same_as_urls;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
foreach ( $social_profiles as $profile ) {
[109] Fix | Delete
// Skip non-string values.
[110] Fix | Delete
if ( ! \is_string( $profile ) ) {
[111] Fix | Delete
continue;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$social_url = $this->url_social_site( $profile, $user_id );
[115] Fix | Delete
if ( $social_url ) {
[116] Fix | Delete
$same_as_urls[] = $social_url;
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
return $same_as_urls;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Builds our array of Schema Person data for a given user ID.
[125] Fix | Delete
*
[126] Fix | Delete
* @param int $user_id The user ID to use.
[127] Fix | Delete
* @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
[128] Fix | Delete
*
[129] Fix | Delete
* @return array<string|string[]> An array of Schema Person data.
[130] Fix | Delete
*/
[131] Fix | Delete
protected function build_person_data( $user_id, $add_hash = false ) {
[132] Fix | Delete
$user_data = \get_userdata( $user_id );
[133] Fix | Delete
$data = [
[134] Fix | Delete
'@type' => $this->type,
[135] Fix | Delete
'@id' => $this->helpers->schema->id->get_user_schema_id( $user_id, $this->context ),
[136] Fix | Delete
];
[137] Fix | Delete
[138] Fix | Delete
// Safety check for the `get_userdata` WP function, which could return false.
[139] Fix | Delete
if ( $user_data === false ) {
[140] Fix | Delete
return $data;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
$data['name'] = $this->helpers->schema->html->smart_strip_tags( $user_data->display_name );
[144] Fix | Delete
$data = $this->add_image( $data, $user_data, $add_hash );
[145] Fix | Delete
[146] Fix | Delete
if ( ! empty( $user_data->description ) ) {
[147] Fix | Delete
$data['description'] = $this->helpers->schema->html->smart_strip_tags( $user_data->description );
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
if ( \is_array( $this->context->schema_page_type ) && \in_array( 'ProfilePage', $this->context->schema_page_type, true ) ) {
[151] Fix | Delete
$data['mainEntityOfPage'] = [
[152] Fix | Delete
'@id' => $this->context->main_schema_id,
[153] Fix | Delete
];
[154] Fix | Delete
}
[155] Fix | Delete
$data = $this->add_same_as_urls( $data, $user_data, $user_id );
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Filter: 'wpseo_schema_person_data' - Allows filtering of schema data per user.
[159] Fix | Delete
*
[160] Fix | Delete
* @param array $data The schema data we have for this person.
[161] Fix | Delete
* @param int $user_id The current user we're collecting schema data for.
[162] Fix | Delete
*/
[163] Fix | Delete
$data = \apply_filters( 'wpseo_schema_person_data', $data, $user_id );
[164] Fix | Delete
[165] Fix | Delete
return $data;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Returns an ImageObject for the persons avatar.
[170] Fix | Delete
*
[171] Fix | Delete
* @param array<string|string[]> $data The Person schema.
[172] Fix | Delete
* @param WP_User $user_data User data.
[173] Fix | Delete
* @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
[174] Fix | Delete
*
[175] Fix | Delete
* @return array<string|string[]> The Person schema.
[176] Fix | Delete
*/
[177] Fix | Delete
protected function add_image( $data, $user_data, $add_hash = false ) {
[178] Fix | Delete
$schema_id = $this->context->site_url . Schema_IDs::PERSON_LOGO_HASH;
[179] Fix | Delete
[180] Fix | Delete
$data = $this->set_image_from_options( $data, $schema_id, $add_hash, $user_data );
[181] Fix | Delete
if ( ! isset( $data['image'] ) ) {
[182] Fix | Delete
$data = $this->set_image_from_avatar( $data, $user_data, $schema_id, $add_hash );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
if ( \is_array( $this->type ) && \in_array( 'Organization', $this->type, true ) ) {
[186] Fix | Delete
$data_logo = ( $data['image']['@id'] ?? $schema_id );
[187] Fix | Delete
$data['logo'] = [ '@id' => $data_logo ];
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
return $data;
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
/**
[194] Fix | Delete
* Generate the person image from our settings.
[195] Fix | Delete
*
[196] Fix | Delete
* @param array<string|string[]> $data The Person schema.
[197] Fix | Delete
* @param string $schema_id The string used in the `@id` for the schema.
[198] Fix | Delete
* @param bool $add_hash Whether or not the person's image url hash should be added to the image id.
[199] Fix | Delete
* @param WP_User $user_data User data.
[200] Fix | Delete
*
[201] Fix | Delete
* @return array<string|string[]> The Person schema.
[202] Fix | Delete
*/
[203] Fix | Delete
protected function set_image_from_options( $data, $schema_id, $add_hash = false, $user_data = null ) {
[204] Fix | Delete
if ( $this->context->site_represents !== 'person' ) {
[205] Fix | Delete
return $data;
[206] Fix | Delete
}
[207] Fix | Delete
if ( \is_array( $this->context->person_logo_meta ) ) {
[208] Fix | Delete
$data['image'] = $this->helpers->schema->image->generate_from_attachment_meta( $schema_id, $this->context->person_logo_meta, $data['name'], $add_hash );
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
return $data;
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Generate the person logo from gravatar.
[216] Fix | Delete
*
[217] Fix | Delete
* @param array<string|string[]> $data The Person schema.
[218] Fix | Delete
* @param WP_User $user_data User data.
[219] Fix | Delete
* @param string $schema_id The string used in the `@id` for the schema.
[220] Fix | Delete
* @param bool $add_hash Wether or not the person's image url hash should be added to the image id.
[221] Fix | Delete
*
[222] Fix | Delete
* @return array<string|string[]> The Person schema.
[223] Fix | Delete
*/
[224] Fix | Delete
protected function set_image_from_avatar( $data, $user_data, $schema_id, $add_hash = false ) {
[225] Fix | Delete
// If we don't have an image in our settings, fall back to an avatar, if we're allowed to.
[226] Fix | Delete
$show_avatars = \get_option( 'show_avatars' );
[227] Fix | Delete
if ( ! $show_avatars ) {
[228] Fix | Delete
return $data;
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
$url = \get_avatar_url( $user_data->user_email );
[232] Fix | Delete
if ( empty( $url ) ) {
[233] Fix | Delete
return $data;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
$data['image'] = $this->helpers->schema->image->simple_image_object( $schema_id, $url, $user_data->display_name, $add_hash );
[237] Fix | Delete
[238] Fix | Delete
return $data;
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
/**
[242] Fix | Delete
* Returns an author's social site URL.
[243] Fix | Delete
*
[244] Fix | Delete
* @param string $social_site The social site to retrieve the URL for.
[245] Fix | Delete
* @param int|false $user_id The user ID to use function outside of the loop.
[246] Fix | Delete
*
[247] Fix | Delete
* @return string
[248] Fix | Delete
*/
[249] Fix | Delete
protected function url_social_site( $social_site, $user_id = false ) {
[250] Fix | Delete
$url = \get_the_author_meta( $social_site, $user_id );
[251] Fix | Delete
[252] Fix | Delete
if ( ! empty( $url ) && $social_site === 'twitter' ) {
[253] Fix | Delete
$url = 'https://x.com/' . $url;
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
return $url;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
/**
[260] Fix | Delete
* Checks the site is represented by the same person as this indexable.
[261] Fix | Delete
*
[262] Fix | Delete
* @param WP_User $user_data User data.
[263] Fix | Delete
*
[264] Fix | Delete
* @return bool True when the site is represented by the same person as this indexable.
[265] Fix | Delete
*/
[266] Fix | Delete
protected function site_represents_current_author( $user_data = null ) {
[267] Fix | Delete
// Can only be the case when the site represents a user.
[268] Fix | Delete
if ( $this->context->site_represents !== 'person' ) {
[269] Fix | Delete
return false;
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
// Article post from the same user as the site represents.
[273] Fix | Delete
if (
[274] Fix | Delete
$this->context->indexable->object_type === 'post'
[275] Fix | Delete
&& $this->helpers->schema->article->is_author_supported( $this->context->indexable->object_sub_type )
[276] Fix | Delete
&& $this->context->schema_article_type !== 'None'
[277] Fix | Delete
) {
[278] Fix | Delete
$user_id = ( ( ! \is_null( $user_data ) ) && ( isset( $user_data->ID ) ) ) ? $user_data->ID : $this->context->indexable->author_id;
[279] Fix | Delete
[280] Fix | Delete
return $this->context->site_user_id === $user_id;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
// Author archive from the same user as the site represents.
[284] Fix | Delete
return $this->context->indexable->object_type === 'user' && $this->context->site_user_id === $this->context->indexable->object_id;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Builds our SameAs array.
[289] Fix | Delete
*
[290] Fix | Delete
* @param array<string|string[]> $data The Person schema data.
[291] Fix | Delete
* @param WP_User $user_data The user data object.
[292] Fix | Delete
* @param int $user_id The user ID to use.
[293] Fix | Delete
*
[294] Fix | Delete
* @return array<string|string[]> The Person schema data.
[295] Fix | Delete
*/
[296] Fix | Delete
protected function add_same_as_urls( $data, $user_data, $user_id ) {
[297] Fix | Delete
$same_as_urls = [];
[298] Fix | Delete
[299] Fix | Delete
// Add the "Website" field from WordPress' contact info.
[300] Fix | Delete
if ( ! empty( $user_data->user_url ) ) {
[301] Fix | Delete
$same_as_urls[] = $user_data->user_url;
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
// Add the social profiles.
[305] Fix | Delete
$same_as_urls = $this->get_social_profiles( $same_as_urls, $user_id );
[306] Fix | Delete
[307] Fix | Delete
if ( ! empty( $same_as_urls ) ) {
[308] Fix | Delete
$same_as_urls = \array_values( \array_unique( $same_as_urls ) );
[309] Fix | Delete
$data['sameAs'] = $same_as_urls;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
return $data;
[313] Fix | Delete
}
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function