| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Generators\Schema\Third_Party; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Generators\Schema\Author; |
| 6 |
|
| 7 |
/** |
| 8 |
* Returns schema Author data for the CoAuthor Plus assigned user on a post. |
| 9 |
*/ |
| 10 |
class CoAuthor extends Author { |
| 11 |
|
| 12 |
/** |
| 13 |
* The user ID of the author we're generating data for. |
| 14 |
* |
| 15 |
* @var int $user_id |
| 16 |
*/ |
| 17 |
private $user_id; |
| 18 |
|
| 19 |
/** |
| 20 |
* Determine whether we should return Person schema. |
| 21 |
* |
| 22 |
* @return bool |
| 23 |
*/ |
| 24 |
public function is_needed() { |
| 25 |
return true; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Returns Person Schema data. |
| 30 |
* |
| 31 |
* @return bool|array Person data on success, false on failure. |
| 32 |
*/ |
| 33 |
public function generate() { |
| 34 |
$user_id = $this->determine_user_id(); |
| 35 |
if ( ! $user_id ) { |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
$data = $this->build_person_data( $user_id, true ); |
| 40 |
|
| 41 |
$data['@type'] = 'Person'; |
| 42 |
unset( $data['logo'] ); |
| 43 |
|
| 44 |
// If this is a post and the author archives are enabled, set the author archive url as the author url. |
| 45 |
if ( $this->helpers->options->get( 'disable-author' ) !== true ) { |
| 46 |
$data['url'] = $this->helpers->user->get_the_author_posts_url( $user_id ); |
| 47 |
} |
| 48 |
|
| 49 |
return $data; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Generate the Person data given a user ID. |
| 54 |
* |
| 55 |
* @param int $user_id User ID. |
| 56 |
* |
| 57 |
* @return array|bool |
| 58 |
*/ |
| 59 |
public function generate_from_user_id( $user_id ) { |
| 60 |
$this->user_id = $user_id; |
| 61 |
|
| 62 |
return $this->generate(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Determines a User ID for the Person data. |
| 67 |
* |
| 68 |
* @return bool|int User ID or false upon return. |
| 69 |
*/ |
| 70 |
protected function determine_user_id() { |
| 71 |
return $this->user_id; |
| 72 |
} |
| 73 |
} |
| 74 |
|