| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters; |
| 4 |
|
| 5 |
use WP_User; |
| 6 |
use Yoast\WP\SEO\Presentations\Indexable_Presentation; |
| 7 |
|
| 8 |
/** |
| 9 |
* Presenter class for the meta author tag. |
| 10 |
*/ |
| 11 |
class Meta_Author_Presenter extends Abstract_Indexable_Tag_Presenter { |
| 12 |
|
| 13 |
/** |
| 14 |
* The tag key name. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $key = 'author'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Returns the author for a post in a meta author tag. |
| 22 |
* |
| 23 |
* @return string The meta author tag. |
| 24 |
*/ |
| 25 |
public function present() { |
| 26 |
$output = parent::present(); |
| 27 |
|
| 28 |
if ( ! empty( $output ) ) { |
| 29 |
return $output; |
| 30 |
} |
| 31 |
|
| 32 |
return ''; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Get the author's display name. |
| 37 |
* |
| 38 |
* @return string The author's display name. |
| 39 |
*/ |
| 40 |
public function get() { |
| 41 |
if ( $this->presentation->model->object_sub_type !== 'post' ) { |
| 42 |
return ''; |
| 43 |
} |
| 44 |
|
| 45 |
$user_data = \get_userdata( $this->presentation->context->post->post_author ); |
| 46 |
|
| 47 |
if ( ! $user_data instanceof WP_User ) { |
| 48 |
return ''; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Filter: 'wpseo_meta_author' - Allow developers to filter the article's author meta tag. |
| 53 |
* |
| 54 |
* @param string $author_name The article author's display name. Return empty to disable the tag. |
| 55 |
* @param Indexable_Presentation $presentation The presentation of an indexable. |
| 56 |
*/ |
| 57 |
return \trim( $this->helpers->schema->html->smart_strip_tags( \apply_filters( 'wpseo_meta_author', $user_data->display_name, $this->presentation ) ) ); |
| 58 |
} |
| 59 |
} |
| 60 |
|