PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.9
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / presenters / twitter / site-presenter.php

site-presenter.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.9, at src/presenters/twitter/site-presenter.php

61 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Presenters\Twitter;
4
5 use Yoast\WP\SEO\Presentations\Indexable_Presentation;
6 use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
7
8 /**
9 * Presenter class for the Twitter site tag.
10 */
11 class Site_Presenter extends Abstract_Indexable_Tag_Presenter {
12
13 /**
14 * The tag key name.
15 *
16 * @var string
17 */
18 protected $key = 'twitter:site';
19
20 /**
21 * Run the Twitter site through the `wpseo_twitter_site` filter.
22 *
23 * @return string The filtered Twitter site.
24 */
25 public function get() {
26 /**
27 * Filter: 'wpseo_twitter_site' - Allow changing the Twitter site account as output in the Twitter card by Yoast SEO.
28 *
29 * @api string $twitter_site Twitter site account string.
30 *
31 * @param Indexable_Presentation $presentation The presentation of an indexable.
32 */
33 $twitter_site = \apply_filters( 'wpseo_twitter_site', $this->presentation->twitter_site, $this->presentation );
34 $twitter_site = $this->get_twitter_id( $twitter_site );
35
36 if ( ! \is_string( $twitter_site ) || $twitter_site === '' ) {
37 return '';
38 }
39
40 return '@' . $twitter_site;
41 }
42
43 /**
44 * Checks if the given id is actually an id or a url and if url, distills the id from it.
45 *
46 * Solves issues with filters returning urls and theme's/other plugins also adding a user meta
47 * twitter field which expects url rather than an id (which is what we expect).
48 *
49 * @param string $id Twitter ID or url.
50 *
51 * @return string|bool Twitter ID or false if it failed to get a valid Twitter ID.
52 */
53 private function get_twitter_id( $id ) {
54 if ( \preg_match( '`([A-Za-z0-9_]{1,25})$`', $id, $match ) ) {
55 return $match[1];
56 }
57
58 return false;
59 }
60 }
61