PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
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 / helpers / twitter / image-helper.php

image-helper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.3, at src/helpers/twitter/image-helper.php

59 lines 1.2 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\Helpers\Twitter;
4
5 use Yoast\WP\SEO\Helpers\Image_Helper as Base_Image_Helper;
6
7 /**
8 * A helper object for Twitter images.
9 */
10 class Image_Helper {
11
12 /**
13 * The base image helper.
14 *
15 * @var Base_Image_Helper
16 */
17 private $image;
18
19 /**
20 * Image_Helper constructor.
21 *
22 * @codeCoverageIgnore
23 *
24 * @param Base_Image_Helper $image The image helper.
25 */
26 public function __construct( Base_Image_Helper $image ) {
27 $this->image = $image;
28 }
29
30 /**
31 * The image size to use for Twitter.
32 *
33 * @return string Image size string.
34 */
35 public function get_image_size() {
36 /**
37 * Filter: 'wpseo_twitter_image_size' - Allow changing the Twitter Card image size.
38 *
39 * @param string $featured_img Image size string.
40 */
41 return (string) \apply_filters( 'wpseo_twitter_image_size', 'full' );
42 }
43
44 /**
45 * Retrieves an image url by its id.
46 *
47 * @param int $image_id The image id.
48 *
49 * @return string The image url. Empty string if the attachment is not valid.
50 */
51 public function get_by_id( $image_id ) {
52 if ( ! $this->image->is_valid_attachment( $image_id ) ) {
53 return '';
54 }
55
56 return $this->image->get_attachment_image_source( $image_id, $this->get_image_size() );
57 }
58 }
59