PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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 28.5, at src/presenters/twitter/site-presenter.php

60 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 * @param string $twitter_site Twitter site account string.
30 * @param Indexable_Presentation $presentation The presentation of an indexable.
31 */
32 $twitter_site = \apply_filters( 'wpseo_twitter_site', $this->presentation->twitter_site, $this->presentation );
33 $twitter_site = $this->get_twitter_id( $twitter_site );
34
35 if ( ! \is_string( $twitter_site ) || $twitter_site === '' ) {
36 return '';
37 }
38
39 return '@' . $twitter_site;
40 }
41
42 /**
43 * Checks if the given id is actually an id or a url and if url, distills the id from it.
44 *
45 * Solves issues with filters returning urls and theme's/other plugins also adding a user meta
46 * twitter field which expects url rather than an id (which is what we expect).
47 *
48 * @param string $id Twitter ID or url.
49 *
50 * @return string|bool Twitter ID or false if it failed to get a valid Twitter ID.
51 */
52 private function get_twitter_id( $id ) {
53 if ( \preg_match( '`([A-Za-z0-9_]{1,25})$`', $id, $match ) ) {
54 return $match[1];
55 }
56
57 return false;
58 }
59 }
60