PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 15.1.2
Jetpack – WP Security, Backup, Speed, & Growth v15.1.2
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / class.jetpack-post-images.php
jetpack Last commit date
3rd-party 11 months ago _inc 1 day ago css 1 year ago extensions 10 months ago images 1 year ago jetpack_vendor 1 day ago json-endpoints 10 months ago modules 10 months ago sal 10 months ago src 1 year ago vendor 10 months ago views 11 months ago CHANGELOG.md 10 months ago LICENSE.txt 5 years ago SECURITY.md 2 years ago class-jetpack-connection-status.php 2 years ago class-jetpack-gallery-settings.php 1 year ago class-jetpack-newsletter-dashboard-widget.php 1 year ago class-jetpack-pre-connection-jitms.php 2 years ago class-jetpack-stats-dashboard-widget.php 1 year ago class-jetpack-xmlrpc-methods.php 1 year ago class.frame-nonce-preview.php 1 year ago class.jetpack-admin.php 11 months ago class.jetpack-autoupdate.php 1 year ago class.jetpack-cli.php 11 months ago class.jetpack-client-server.php 2 years ago class.jetpack-gutenberg.php 11 months ago class.jetpack-heartbeat.php 2 years ago class.jetpack-modules-list-table.php 1 year ago class.jetpack-network-sites-list-table.php 1 year ago class.jetpack-network.php 1 year ago class.jetpack-plan.php 3 years ago class.jetpack-post-images.php 1 year ago class.jetpack-twitter-cards.php 1 year ago class.jetpack-user-agent.php 2 years ago class.jetpack.php 11 months ago class.json-api-endpoints.php 11 months ago class.json-api.php 11 months ago class.photon.php 3 years ago composer.json 10 months ago enhanced-open-graph.php 1 year ago functions.compat.php 1 year ago functions.cookies.php 2 years ago functions.global.php 1 year ago functions.is-mobile.php 2 years ago functions.opengraph.php 1 year ago functions.photon.php 2 years ago jetpack.php 1 day ago json-api-config.php 3 years ago json-endpoints.php 2 years ago load-jetpack.php 1 year ago locales.php 1 year ago readme.txt 1 day ago unauth-file-upload.php 1 year ago uninstall.php 1 year ago wpml-config.xml 4 years ago
class.jetpack-post-images.php
1168 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Useful for finding an image to display alongside/in representation of a specific post.
4 *
5 * @package automattic/jetpack
6 */
7
8 use Automattic\Block_Scanner;
9 use Automattic\Jetpack\Image_CDN\Image_CDN_Core;
10
11 /**
12 * Useful for finding an image to display alongside/in representation of a specific post.
13 *
14 * Includes a few different methods, all of which return a similar-format array containing
15 * details of any images found. Everything can (should) be called statically, it's just a
16 * function-bucket. You can also call Jetpack_PostImages::get_image() to cycle through all of the methods until
17 * one of them finds something useful.
18 *
19 * This file is included verbatim in Jetpack
20 */
21 class Jetpack_PostImages {
22 /**
23 * If a slideshow is embedded within a post, then parse out the images involved and return them
24 *
25 * @param int $post_id Post ID.
26 * @param int $width Image width.
27 * @param int $height Image height.
28 * @return array Images.
29 */
30 public static function from_slideshow( $post_id, $width = 200, $height = 200 ) {
31 $images = array();
32
33 $post = get_post( $post_id );
34
35 if ( ! $post ) {
36 return $images;
37 }
38
39 if ( ! empty( $post->post_password ) ) {
40 return $images;
41 }
42
43 if ( false === has_shortcode( $post->post_content, 'slideshow' ) ) {
44 return $images; // no slideshow - bail.
45 }
46
47 $permalink = get_permalink( $post->ID );
48
49 // Mechanic: Somebody set us up the bomb.
50 $old_post = $GLOBALS['post'] ?? null;
51 $GLOBALS['post'] = $post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
52 $old_shortcodes = $GLOBALS['shortcode_tags'];
53 $GLOBALS['shortcode_tags'] = array( 'slideshow' => $old_shortcodes['slideshow'] ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
54
55 // Find all the slideshows.
56 preg_match_all( '/' . get_shortcode_regex() . '/sx', $post->post_content, $slideshow_matches, PREG_SET_ORDER );
57
58 ob_start(); // The slideshow shortcode handler calls wp_print_scripts and wp_print_styles... not too happy about that.
59
60 foreach ( $slideshow_matches as $slideshow_match ) {
61 $slideshow = do_shortcode_tag( $slideshow_match );
62 $pos = stripos( $slideshow, 'jetpack-slideshow' );
63 if ( false === $pos ) { // must be something wrong - or we changed the output format in which case none of the following will work.
64 continue;
65 }
66 $start = strpos( $slideshow, '[', $pos );
67 $end = strpos( $slideshow, ']', $start );
68 $post_images = json_decode( wp_specialchars_decode( str_replace( "'", '"', substr( $slideshow, $start, $end - $start + 1 ) ), ENT_QUOTES ) ); // parse via JSON
69 // If the JSON didn't decode don't try and act on it.
70 if ( is_array( $post_images ) ) {
71 foreach ( $post_images as $post_image ) {
72 $post_image_id = absint( $post_image->id );
73 if ( ! $post_image_id ) {
74 continue;
75 }
76
77 $meta = wp_get_attachment_metadata( $post_image_id );
78
79 // Must be larger than 200x200 (or user-specified).
80 if ( ! isset( $meta['width'] ) || $meta['width'] < $width ) {
81 continue;
82 }
83 if ( ! isset( $meta['height'] ) || $meta['height'] < $height ) {
84 continue;
85 }
86
87 $url = wp_get_attachment_url( $post_image_id );
88
89 $images[] = array(
90 'type' => 'image',
91 'from' => 'slideshow',
92 'src' => $url,
93 'src_width' => $meta['width'],
94 'src_height' => $meta['height'],
95 'href' => $permalink,
96 );
97 }
98 }
99 }
100 ob_end_clean();
101
102 // Operator: Main screen turn on.
103 $GLOBALS['shortcode_tags'] = $old_shortcodes; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
104 $GLOBALS['post'] = $old_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
105
106 return $images;
107 }
108
109 /**
110 * Filtering out images with broken URL from galleries.
111 *
112 * @param array $galleries Galleries.
113 * @return array $filtered_galleries
114 */
115 public static function filter_gallery_urls( $galleries ) {
116 $filtered_galleries = array();
117 foreach ( $galleries as $this_gallery ) {
118 if ( ! isset( $this_gallery['src'] ) ) {
119 continue;
120 }
121 $ids = isset( $this_gallery['ids'] ) ? explode( ',', $this_gallery['ids'] ) : array();
122 // Make sure 'src' array isn't associative and has no holes.
123 $this_gallery['src'] = array_values( $this_gallery['src'] );
124 foreach ( $this_gallery['src'] as $idx => $src_url ) {
125 if ( filter_var( $src_url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED ) === false ) {
126 unset( $this_gallery['src'][ $idx ] );
127 unset( $ids[ $idx ] );
128 }
129 }
130 if ( isset( $this_gallery['ids'] ) ) {
131 $this_gallery['ids'] = implode( ',', $ids );
132 }
133 // Remove any holes we introduced.
134 $this_gallery['src'] = array_values( $this_gallery['src'] );
135 $filtered_galleries[] = $this_gallery;
136 }
137
138 return $filtered_galleries;
139 }
140
141 /**
142 * If a gallery is detected, then get all the images from it.
143 *
144 * @param int $post_id Post ID.
145 * @param int $width Minimum image width to consider.
146 * @param int $height Minimum image height to consider.
147 * @return array Images.
148 */
149 public static function from_gallery( $post_id, $width = 200, $height = 200 ) {
150 $images = array();
151
152 $post = get_post( $post_id );
153
154 if ( ! $post ) {
155 return $images;
156 }
157
158 if ( ! empty( $post->post_password ) ) {
159 return $images;
160 }
161 add_filter( 'get_post_galleries', array( __CLASS__, 'filter_gallery_urls' ), 999999 );
162
163 $permalink = get_permalink( $post->ID );
164
165 /**
166 * Juggle global post object because the gallery shortcode uses the
167 * global object.
168 *
169 * See core ticket:
170 * https://core.trac.wordpress.org/ticket/39304
171 */
172 // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
173 if ( isset( $GLOBALS['post'] ) ) {
174 $juggle_post = $GLOBALS['post'];
175 $GLOBALS['post'] = $post;
176 $galleries = get_post_galleries( $post->ID, false );
177 $GLOBALS['post'] = $juggle_post;
178 } else {
179 $GLOBALS['post'] = $post;
180 $galleries = get_post_galleries( $post->ID, false );
181 unset( $GLOBALS['post'] );
182 }
183 // phpcs:enable WordPress.WP.GlobalVariablesOverride.Prohibited
184
185 foreach ( $galleries as $gallery ) {
186 if ( ! empty( $gallery['ids'] ) ) {
187 $image_ids = explode( ',', $gallery['ids'] );
188 $image_size = isset( $gallery['size'] ) ? $gallery['size'] : 'thumbnail';
189 foreach ( $image_ids as $image_id ) {
190 $image = wp_get_attachment_image_src( $image_id, $image_size );
191 $meta = wp_get_attachment_metadata( $image_id );
192
193 if ( isset( $gallery['type'] ) && 'slideshow' === $gallery['type'] ) {
194 // Must be larger than 200x200 (or user-specified).
195 if ( ! isset( $meta['width'] ) || $meta['width'] < $width ) {
196 continue;
197 }
198 if ( ! isset( $meta['height'] ) || $meta['height'] < $height ) {
199 continue;
200 }
201 }
202
203 if ( ! empty( $image[0] ) ) {
204 list( $raw_src ) = explode( '?', $image[0] ); // pull off any Query string (?w=250).
205 $raw_src = wp_specialchars_decode( $raw_src ); // rawify it.
206 $raw_src = esc_url_raw( $raw_src ); // clean it.
207 $images[] = array(
208 'type' => 'image',
209 'from' => 'gallery',
210 'src' => $raw_src,
211 'src_width' => $meta['width'] ?? 0,
212 'src_height' => $meta['height'] ?? 0,
213 'href' => $permalink,
214 'alt_text' => self::get_alt_text( $image_id ),
215 );
216 }
217 }
218 } elseif ( ! empty( $gallery['src'] ) ) {
219 foreach ( $gallery['src'] as $src ) {
220 list( $raw_src ) = explode( '?', $src ); // pull off any Query string (?w=250).
221 $raw_src = wp_specialchars_decode( $raw_src ); // rawify it.
222 $raw_src = esc_url_raw( $raw_src ); // clean it.
223 $images[] = array(
224 'type' => 'image',
225 'from' => 'gallery',
226 'src' => $raw_src,
227 'href' => $permalink,
228 );
229 }
230 }
231 }
232
233 return $images;
234 }
235
236 /**
237 * Get attachment images for a specified post and return them. Also make sure
238 * their dimensions are at or above a required minimum.
239 *
240 * @param int $post_id The post ID to check.
241 * @param int $width Image width.
242 * @param int $height Image height.
243 * @return array Containing details of the image, or empty array if none.
244 */
245 public static function from_attachment( $post_id, $width = 200, $height = 200 ) {
246 $images = array();
247
248 $post = get_post( $post_id );
249
250 if ( ! empty( $post->post_password ) ) {
251 return $images;
252 }
253
254 $post_images = get_posts(
255 array(
256 'post_parent' => $post_id, // Must be children of post.
257 'numberposts' => 5, // No more than 5.
258 'post_type' => 'attachment', // Must be attachments.
259 'post_mime_type' => 'image', // Must be images.
260 'suppress_filters' => false,
261 )
262 );
263
264 if ( ! $post_images ) {
265 return $images;
266 }
267
268 $permalink = get_permalink( $post_id );
269
270 foreach ( $post_images as $post_image ) {
271 $current_image = self::get_attachment_data( $post_image->ID, $permalink, $width, $height );
272 if ( false !== $current_image ) {
273 $images[] = $current_image;
274 }
275 }
276
277 /*
278 * We only want to pass back attached images that were actually inserted.
279 * We can load up all the images found in the HTML source and then
280 * compare URLs to see if an image is attached AND inserted.
281 */
282 $html_images = self::from_html( $post_id );
283 $inserted_images = array();
284
285 foreach ( $html_images as $html_image ) {
286 $src = wp_parse_url( $html_image['src'] );
287 if ( ! $src || empty( $src['path'] ) ) {
288 continue;
289 }
290
291 // strip off any query strings from src.
292 if ( ! empty( $src['scheme'] ) && ! empty( $src['host'] ) ) {
293 $inserted_images[] = $src['scheme'] . '://' . $src['host'] . $src['path'];
294 } elseif ( ! empty( $src['host'] ) ) {
295 $inserted_images[] = set_url_scheme( 'http://' . $src['host'] . $src['path'] );
296 } else {
297 $inserted_images[] = site_url( '/' ) . $src['path'];
298 }
299 }
300 foreach ( $images as $i => $image ) {
301 if ( ! in_array( $image['src'], $inserted_images, true ) ) {
302 unset( $images[ $i ] );
303 }
304 }
305
306 return $images;
307 }
308
309 /**
310 * Check if a Featured Image is set for this post, and return it in a similar
311 * format to the other images?_from_*() methods.
312 *
313 * @param int $post_id The post ID to check.
314 * @param int $width Image width.
315 * @param int $height Image height.
316 * @return array containing details of the Featured Image, or empty array if none.
317 */
318 public static function from_thumbnail( $post_id, $width = 200, $height = 200 ) {
319 $images = array();
320
321 $post = get_post( $post_id );
322
323 if ( ! empty( $post->post_password ) ) {
324 return $images;
325 }
326
327 if ( 'attachment' === get_post_type( $post ) && wp_attachment_is_image( $post ) ) {
328 $thumb = $post_id;
329 } else {
330 $thumb = get_post_thumbnail_id( $post );
331 }
332
333 if ( $thumb ) {
334 $meta = wp_get_attachment_metadata( $thumb );
335 // Must be larger than requested minimums.
336 if ( ! isset( $meta['width'] ) || $meta['width'] < $width ) {
337 return $images;
338 }
339 if ( ! isset( $meta['height'] ) || $meta['height'] < $height ) {
340 return $images;
341 }
342 $max_dimension = self::get_max_thumbnail_dimension();
343 $too_big = ( ( ! empty( $meta['width'] ) && $meta['width'] > $max_dimension ) || ( ! empty( $meta['height'] ) && $meta['height'] > $max_dimension ) );
344
345 if (
346 $too_big &&
347 (
348 ( method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'photon' ) ) ||
349 ( defined( 'IS_WPCOM' ) && IS_WPCOM )
350 )
351 ) {
352 $size = self::determine_thumbnail_size_for_photon( $meta['width'], $meta['height'] );
353 $photon_args = array(
354 'fit' => $size['width'] . ',' . $size['height'],
355 );
356 $img_src = array( Image_CDN_Core::cdn_url( wp_get_attachment_url( $thumb ), $photon_args ), $size['width'], $size['height'], true ); // Match the signature of wp_get_attachment_image_src
357 } else {
358 $img_src = wp_get_attachment_image_src( $thumb, 'full' );
359 }
360 if ( ! is_array( $img_src ) ) {
361 // If wp_get_attachment_image_src returns false but we know that there should be an image that could be used.
362 // we try a bit harder and user the data that we have.
363 $thumb_post_data = get_post( $thumb );
364 $img_src = array( $thumb_post_data->guid ?? null, $meta['width'], $meta['height'] );
365 }
366
367 // Let's try to use the postmeta if we can, since it seems to be
368 // more reliable
369 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
370 $featured_image = get_post_meta( $post->ID, '_jetpack_featured_image' );
371 if ( $featured_image ) {
372 $url = $featured_image[0];
373 } else {
374 $url = $img_src[0];
375 }
376 } else {
377 $url = $img_src[0];
378 }
379 $images = array(
380 array( // Other methods below all return an array of arrays.
381 'type' => 'image',
382 'from' => 'thumbnail',
383 'src' => $url,
384 'src_width' => $img_src[1],
385 'src_height' => $img_src[2],
386 'href' => get_permalink( $thumb ),
387 'alt_text' => self::get_alt_text( $thumb ),
388 ),
389 );
390
391 }
392
393 if ( empty( $images ) && ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
394 $meta_thumbnail = get_post_meta( $post_id, '_jetpack_post_thumbnail', true );
395 if ( ! empty( $meta_thumbnail ) ) {
396 if ( ! isset( $meta_thumbnail['width'] ) || $meta_thumbnail['width'] < $width ) {
397 return $images;
398 }
399
400 if ( ! isset( $meta_thumbnail['height'] ) || $meta_thumbnail['height'] < $height ) {
401 return $images;
402 }
403
404 $images = array(
405 array( // Other methods below all return an array of arrays.
406 'type' => 'image',
407 'from' => 'thumbnail',
408 'src' => $meta_thumbnail['URL'],
409 'src_width' => $meta_thumbnail['width'],
410 'src_height' => $meta_thumbnail['height'],
411 'href' => $meta_thumbnail['URL'],
412 'alt_text' => self::get_alt_text( $thumb ),
413 ),
414 );
415 }
416 }
417
418 return $images;
419 }
420
421 /**
422 * Get images from Gutenberg Image blocks.
423 *
424 * @since 6.9.0
425 * @since 14.8 Updated to use Block_Delimiter for improved performance.
426 * @since 14.9 Updated to use Block_Scanner for improved performance.
427 *
428 * @param mixed $html_or_id The HTML string to parse for images, or a post id.
429 * @param int $width Minimum Image width.
430 * @param int $height Minimum Image height.
431 */
432 public static function from_blocks( $html_or_id, $width = 200, $height = 200 ) {
433 $images = array();
434
435 $html_info = self::get_post_html( $html_or_id );
436
437 if ( empty( $html_info['html'] ) ) {
438 return $images;
439 }
440
441 $scanner = Block_Scanner::create( $html_info['html'] );
442 if ( ! $scanner ) {
443 return $images;
444 }
445
446 /*
447 * Use Block_Scanner to parse our post content HTML,
448 * and find all the block delimiters for supported blocks,
449 * whether they're parent or nested blocks.
450 */
451 $supported_blocks = array(
452 'core/image',
453 'core/media-text',
454 'core/gallery',
455 'jetpack/tiled-gallery',
456 'jetpack/slideshow',
457 'jetpack/story',
458 );
459
460 while ( $scanner->next_delimiter() ) {
461 $type = $scanner->get_delimiter_type();
462 // Only process opening delimiters for supported block types.
463 if ( Block_Scanner::OPENER !== $type ) {
464 continue;
465 }
466
467 $block_type = $scanner->get_block_type();
468 $is_supported_block = in_array( $block_type, $supported_blocks, true );
469 if ( ! $is_supported_block ) {
470 continue;
471 }
472
473 $attributes = $scanner->allocate_and_return_parsed_attributes() ?? array();
474 $block_images = self::get_images_from_block_attributes( $block_type, $attributes, $html_info, $width, $height );
475
476 if ( ! empty( $block_images ) ) {
477 $images = array_merge( $images, $block_images );
478 }
479 }
480
481 /**
482 * Returning a filtered array because get_attachment_data returns false
483 * for unsuccessful attempts.
484 */
485 return array_filter( $images );
486 }
487
488 /**
489 * Extract images from block attributes based on block type.
490 *
491 * @since 14.8
492 *
493 * @param string $block_type Block type name.
494 * @param array $attributes Block attributes.
495 * @param array $html_info Info about the post where the block is found.
496 * @param int $width Desired image width.
497 * @param int $height Desired image height.
498 *
499 * @return array Array of images found.
500 */
501 private static function get_images_from_block_attributes( $block_type, $attributes, $html_info, $width, $height ) {
502 $images = array();
503
504 switch ( $block_type ) {
505 case 'core/image':
506 case 'core/media-text':
507 $id_key = 'core/image' === $block_type ? 'id' : 'mediaId';
508 if ( ! empty( $attributes[ $id_key ] ) ) {
509 $image = self::get_attachment_data( $attributes[ $id_key ], $html_info['post_url'], $width, $height );
510 if ( false !== $image ) {
511 $images[] = $image;
512 }
513 }
514 break;
515
516 case 'core/gallery':
517 case 'jetpack/tiled-gallery':
518 case 'jetpack/slideshow':
519 if ( ! empty( $attributes['ids'] ) && is_array( $attributes['ids'] ) ) {
520 foreach ( $attributes['ids'] as $img_id ) {
521 $image = self::get_attachment_data( $img_id, $html_info['post_url'], $width, $height );
522 if ( false !== $image ) {
523 $images[] = $image;
524 }
525 }
526 }
527 break;
528
529 case 'jetpack/story':
530 if ( ! empty( $attributes['mediaFiles'] ) && is_array( $attributes['mediaFiles'] ) ) {
531 foreach ( $attributes['mediaFiles'] as $media_file ) {
532 if ( ! empty( $media_file['id'] ) ) {
533 $image = self::get_attachment_data( $media_file['id'], $html_info['post_url'], $width, $height );
534 if ( false !== $image ) {
535 $images[] = $image;
536 }
537 }
538 }
539 }
540 break;
541 }
542
543 return $images;
544 }
545
546 /**
547 * Very raw -- just parse the HTML and pull out any/all img tags and return their src
548 *
549 * @param mixed $html_or_id The HTML string to parse for images, or a post id.
550 * @param int $width Minimum Image width.
551 * @param int $height Minimum Image height.
552 *
553 * @uses DOMDocument
554 *
555 * @return array containing images
556 */
557 public static function from_html( $html_or_id, $width = 200, $height = 200 ) {
558 $images = array();
559
560 $html_info = self::get_post_html( $html_or_id );
561
562 if ( empty( $html_info['html'] ) ) {
563 return $images;
564 }
565
566 // Do not go any further if DOMDocument is disabled on the server.
567 if ( ! class_exists( 'DOMDocument' ) ) {
568 return $images;
569 }
570
571 // Let's grab all image tags from the HTML.
572 $dom_doc = new DOMDocument();
573
574 // DOMDocument defaults to ISO-8859 because we're loading only the post content, without head tag.
575 // Fix: Enforce encoding with meta tag.
576 $charset = get_option( 'blog_charset' );
577 if ( empty( $charset ) || ! preg_match( '/^[a-zA-Z0-9_-]+$/', $charset ) ) {
578 $charset = 'UTF-8';
579 }
580 $html_prefix = sprintf( '<meta http-equiv="Content-Type" content="text/html; charset=%s">', esc_attr( $charset ) );
581
582 // The @ is not enough to suppress errors when dealing with libxml,
583 // we have to tell it directly how we want to handle errors.
584 libxml_use_internal_errors( true );
585 @$dom_doc->loadHTML( $html_prefix . $html_info['html'] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
586 libxml_use_internal_errors( false );
587
588 $image_tags = $dom_doc->getElementsByTagName( 'img' );
589
590 // For each image Tag, make sure it can be added to the $images array, and add it.
591 foreach ( $image_tags as $image_tag ) {
592 $img_src = $image_tag->getAttribute( 'src' );
593
594 if ( empty( $img_src ) ) {
595 continue;
596 }
597
598 // Do not grab smiley images that were automatically created by WP when entering text smilies.
599 if ( stripos( $img_src, '/smilies/' ) ) {
600 continue;
601 }
602
603 // Do not grab Gravatar images.
604 if ( stripos( $img_src, 'gravatar.com' ) ) {
605 continue;
606 }
607
608 // First try to get the width and height from the img attributes, but if they are not set, check to see if they are specified in the url. WordPress automatically names files like foo-1024x768.jpg during the upload process
609 $width = (int) $image_tag->getAttribute( 'width' );
610 $height = (int) $image_tag->getAttribute( 'height' );
611 if ( 0 === $width && 0 === $height ) {
612 preg_match( '/-([0-9]{1,5})x([0-9]{1,5})\.(?:jpg|jpeg|png|gif|webp)$/i', $img_src, $matches );
613 if ( ! empty( $matches[1] ) ) {
614 $width = (int) $matches[1];
615 }
616 if ( ! empty( $matches[2] ) ) {
617 $height = (int) $matches[2];
618 }
619 }
620 // If width and height are still 0, try to get the id of the image from the class, e.g. wp-image-1234
621 if ( 0 === $width && 0 === $height ) {
622
623 preg_match( '/wp-image-([0-9]+)/', $image_tag->getAttribute( 'class' ), $matches );
624 if ( ! empty( $matches[1] ) ) {
625 $attachment_id = $matches[1];
626 $meta = wp_get_attachment_metadata( $attachment_id );
627 $height = $meta['height'] ?? 0;
628 $width = $meta['width'] ?? 0;
629 }
630 }
631
632 $meta = array(
633 'width' => $width,
634 'height' => $height,
635 'alt_text' => $image_tag->getAttribute( 'alt' ),
636 );
637
638 /**
639 * Filters the switch to ignore minimum image size requirements. Can be used
640 * to add custom logic to image dimensions, like only enforcing one of the dimensions,
641 * or disabling it entirely.
642 *
643 * @since 6.4.0
644 *
645 * @param bool $ignore Should the image dimensions be ignored?
646 * @param array $meta Array containing image dimensions parsed from the markup.
647 */
648 $ignore_dimensions = apply_filters( 'jetpack_postimages_ignore_minimum_dimensions', false, $meta );
649
650 // Must be larger than 200x200 (or user-specified).
651 if (
652 ! $ignore_dimensions
653 && (
654 empty( $meta['width'] )
655 || empty( $meta['height'] )
656 || $meta['width'] < $width
657 || $meta['height'] < $height
658 )
659 ) {
660 continue;
661 }
662
663 $image = array(
664 'type' => 'image',
665 'from' => 'html',
666 'src' => $img_src,
667 'src_width' => $meta['width'],
668 'src_height' => $meta['height'],
669 'href' => $html_info['post_url'],
670 );
671 if ( ! empty( $meta['alt_text'] ) ) {
672 $image['alt_text'] = $meta['alt_text'];
673 }
674 $images[] = $image;
675 }
676 return $images;
677 }
678
679 /**
680 * Data from blavatar.
681 *
682 * @param int $post_id The post ID to check.
683 * @param int $size Size.
684 * @return array containing details of the image, or empty array if none.
685 */
686 public static function from_blavatar( $post_id, $size = 96 ) {
687
688 $permalink = get_permalink( $post_id );
689
690 if ( function_exists( 'blavatar_domain' ) && function_exists( 'blavatar_exists' ) && function_exists( 'blavatar_url' ) ) {
691 $domain = blavatar_domain( $permalink );
692
693 if ( ! blavatar_exists( $domain ) ) {
694 return array();
695 }
696
697 $url = blavatar_url( $domain, 'img', $size );
698 } else {
699 $url = get_site_icon_url( $size );
700 if ( ! $url ) {
701 return array();
702 }
703 }
704
705 return array(
706 array(
707 'type' => 'image',
708 'from' => 'blavatar',
709 'src' => $url,
710 'src_width' => $size,
711 'src_height' => $size,
712 'href' => $permalink,
713 'alt_text' => '',
714 ),
715 );
716 }
717
718 /**
719 * Gets a post image from the author avatar.
720 *
721 * @param int $post_id The post ID to check.
722 * @param int $size The size of the avatar to get.
723 * @param string $default The default image to use.
724 * @return array containing details of the image, or empty array if none.
725 */
726 public static function from_gravatar( $post_id, $size = 96, $default = false ) {
727 $post = get_post( $post_id );
728 $permalink = get_permalink( $post_id );
729
730 if ( ! $post instanceof WP_Post ) {
731 return array();
732 }
733
734 if ( function_exists( 'wpcom_get_avatar_url' ) ) {
735 $url = wpcom_get_avatar_url( $post->post_author, $size, $default, true );
736 if ( $url && is_array( $url ) ) {
737 $url = $url[0];
738 }
739 } else {
740 $url = get_avatar_url(
741 $post->post_author,
742 array(
743 'size' => $size,
744 'default' => $default,
745 )
746 );
747 }
748
749 return array(
750 array(
751 'type' => 'image',
752 'from' => 'gravatar',
753 'src' => $url,
754 'src_width' => $size,
755 'src_height' => $size,
756 'href' => $permalink,
757 'alt_text' => '',
758 ),
759 );
760 }
761
762 /**
763 * Run through the different methods that we have available to try to find a single good
764 * display image for this post.
765 *
766 * @param int $post_id Post ID.
767 * @param array $args Other arguments (currently width and height required for images where possible to determine).
768 * @return array|null containing details of the best image to be used, or null if no image is found.
769 */
770 public static function get_image( $post_id, $args = array() ) {
771 $image = null;
772
773 /**
774 * Fires before we find a single good image for a specific post.
775 *
776 * @since 2.2.0
777 *
778 * @param int $post_id Post ID.
779 */
780 do_action( 'jetpack_postimages_pre_get_image', $post_id );
781 $media = self::get_images( $post_id, $args );
782
783 if ( is_array( $media ) ) {
784 foreach ( $media as $item ) {
785 if ( 'image' === $item['type'] ) {
786 $image = $item;
787 break;
788 }
789 }
790 }
791
792 /**
793 * Fires after we find a single good image for a specific post.
794 *
795 * @since 2.2.0
796 *
797 * @param int $post_id Post ID.
798 */
799 do_action( 'jetpack_postimages_post_get_image', $post_id );
800
801 return $image;
802 }
803
804 /**
805 * Get an array containing a collection of possible images for this post, stopping once we hit a method
806 * that returns something useful.
807 *
808 * @param int $post_id Post ID.
809 * @param array $args Optional args, see defaults list for details.
810 * @return array containing images that would be good for representing this post
811 */
812 public static function get_images( $post_id, $args = array() ) {
813 // Figure out which image to attach to this post.
814 $media = array();
815
816 /**
817 * Filters the array of images that would be good for a specific post.
818 * This filter is applied before options ($args) filter the original array.
819 *
820 * @since 2.0.0
821 *
822 * @param array $media Array of images that would be good for a specific post.
823 * @param int $post_id Post ID.
824 * @param array $args Array of options to get images.
825 */
826 $media = apply_filters( 'jetpack_images_pre_get_images', $media, $post_id, $args );
827 if ( $media ) {
828 return $media;
829 }
830
831 $defaults = array(
832 'width' => 200, // Required minimum width (if possible to determine).
833 'height' => 200, // Required minimum height (if possible to determine).
834
835 'fallback_to_avatars' => false, // Optionally include Blavatar and Gravatar (in that order) in the image stack.
836 'avatar_size' => 96, // Used for both Grav and Blav.
837 'gravatar_default' => false, // Default image to use if we end up with no Gravatar.
838
839 'from_thumbnail' => true, // Use these flags to specify which methods to use to find an image.
840 'from_slideshow' => true,
841 'from_gallery' => true,
842 'from_attachment' => true,
843 'from_blocks' => true,
844 'from_html' => true,
845
846 'html_content' => '', // HTML string to pass to from_html().
847 );
848 $args = wp_parse_args( $args, $defaults );
849
850 $media = array();
851 if ( $args['from_thumbnail'] ) {
852 $media = self::from_thumbnail( $post_id, $args['width'], $args['height'] );
853 }
854 if ( ! $media && $args['from_slideshow'] ) {
855 $media = self::from_slideshow( $post_id, $args['width'], $args['height'] );
856 }
857 if ( ! $media && $args['from_gallery'] ) {
858 $media = self::from_gallery( $post_id );
859 }
860 if ( ! $media && $args['from_attachment'] ) {
861 $media = self::from_attachment( $post_id, $args['width'], $args['height'] );
862 }
863 if ( ! $media && $args['from_blocks'] ) {
864 if ( empty( $args['html_content'] ) ) {
865 $media = self::from_blocks( $post_id, $args['width'], $args['height'] ); // Use the post_id, which will load the content.
866 } else {
867 $media = self::from_blocks( $args['html_content'], $args['width'], $args['height'] ); // If html_content is provided, use that.
868 }
869 }
870 if ( ! $media && $args['from_html'] ) {
871 if ( empty( $args['html_content'] ) ) {
872 $media = self::from_html( $post_id, $args['width'], $args['height'] ); // Use the post_id, which will load the content.
873 } else {
874 $media = self::from_html( $args['html_content'], $args['width'], $args['height'] ); // If html_content is provided, use that.
875 }
876 }
877
878 if ( ! $media && $args['fallback_to_avatars'] ) {
879 $media = self::from_blavatar( $post_id, $args['avatar_size'] );
880 if ( ! $media ) {
881 $media = self::from_gravatar( $post_id, $args['avatar_size'], $args['gravatar_default'] );
882 }
883 }
884
885 /**
886 * Filters the array of images that would be good for a specific post.
887 * This filter is applied after options ($args) filter the original array.
888 *
889 * @since 2.0.0
890 *
891 * @param array $media Array of images that would be good for a specific post.
892 * @param int $post_id Post ID.
893 * @param array $args Array of options to get images.
894 */
895 return apply_filters( 'jetpack_images_get_images', $media, $post_id, $args );
896 }
897
898 /**
899 * Takes an image and base pixel dimensions and returns a srcset for the
900 * resized and cropped images, based on a fixed set of multipliers.
901 *
902 * @param array $image Array containing details of the image.
903 * @param int $base_width Base image width (i.e., the width at 1x).
904 * @param int $base_height Base image height (i.e., the height at 1x).
905 * @param bool $use_widths Whether to generate the srcset with widths instead of multipliers.
906 * @return string The srcset for the image.
907 */
908 public static function generate_cropped_srcset( $image, $base_width, $base_height, $use_widths = false ) {
909 $srcset = '';
910
911 if ( ! is_array( $image ) || empty( $image['src'] ) || empty( $image['src_width'] ) ) {
912 return $srcset;
913 }
914
915 $multipliers = array( 1, 1.5, 2, 3, 4 );
916 $srcset_values = array();
917 foreach ( $multipliers as $multiplier ) {
918 $srcset_width = (int) ( $base_width * $multiplier );
919 $srcset_height = (int) ( $base_height * $multiplier );
920 if ( $srcset_width < 1 || $srcset_width > $image['src_width'] ) {
921 break;
922 }
923
924 $srcset_url = self::fit_image_url(
925 $image['src'],
926 $srcset_width,
927 $srcset_height
928 );
929
930 if ( $use_widths ) {
931 $srcset_values[] = "{$srcset_url} {$srcset_width}w";
932 } else {
933 $srcset_values[] = "{$srcset_url} {$multiplier}x";
934 }
935 }
936
937 if ( count( $srcset_values ) > 1 ) {
938 $srcset = implode( ', ', $srcset_values );
939 }
940
941 return $srcset;
942 }
943
944 /**
945 * Takes an image URL and pixel dimensions then returns a URL for the
946 * resized and cropped image.
947 *
948 * @param string $src Image URL.
949 * @param int $width Image width.
950 * @param int $height Image height.
951 * @return string Transformed image URL
952 */
953 public static function fit_image_url( $src, $width, $height ) {
954 $width = (int) $width;
955 $height = (int) $height;
956
957 if ( $width < 1 || $height < 1 ) {
958 return $src;
959 }
960
961 // See if we should bypass WordPress.com SaaS resizing.
962 if ( has_filter( 'jetpack_images_fit_image_url_override' ) ) {
963 /**
964 * Filters the image URL used after dimensions are set by Photon.
965 *
966 * @since 3.3.0
967 *
968 * @param string $src Image URL.
969 * @param int $width Image width.
970 * @param int $width Image height.
971 */
972 return apply_filters( 'jetpack_images_fit_image_url_override', $src, $width, $height );
973 }
974
975 // If WPCOM hosted image use native transformations.
976 $img_host = wp_parse_url( $src, PHP_URL_HOST );
977 if ( $img_host && str_ends_with( $img_host, '.files.wordpress.com' ) ) {
978 return add_query_arg(
979 array(
980 'w' => $width,
981 'h' => $height,
982 'crop' => 1,
983 ),
984 set_url_scheme( $src )
985 );
986 }
987
988 // Use image cdn magic.
989 if ( class_exists( Image_CDN_Core::class ) && method_exists( Image_CDN_Core::class, 'cdn_url' ) ) {
990 return Image_CDN_Core::cdn_url( $src, array( 'resize' => "$width,$height" ) );
991 }
992
993 // Arg... no way to resize image using WordPress.com infrastructure!
994 return $src;
995 }
996
997 /**
998 * Get HTML from given post content.
999 *
1000 * @since 6.9.0
1001 *
1002 * @param mixed $html_or_id The HTML string to parse for images, or a post id.
1003 *
1004 * @return array $html_info {
1005 * @type string $html Post content.
1006 * @type string $post_url Post URL.
1007 * }
1008 */
1009 public static function get_post_html( $html_or_id ) {
1010 if ( is_numeric( $html_or_id ) ) {
1011 $post = get_post( $html_or_id );
1012
1013 if ( empty( $post ) || ! empty( $post->post_password ) ) {
1014 return '';
1015 }
1016
1017 $html_info = array(
1018 'html' => $post->post_content, // DO NOT apply the_content filters here, it will cause loops.
1019 'post_url' => get_permalink( $post->ID ),
1020 );
1021 } else {
1022 $html_info = array(
1023 'html' => $html_or_id,
1024 'post_url' => '',
1025 );
1026 }
1027 return $html_info;
1028 }
1029
1030 /**
1031 * Get info about a WordPress attachment.
1032 *
1033 * @since 6.9.0
1034 *
1035 * @param int $attachment_id Attachment ID.
1036 * @param string $post_url URL of the post, if we have one.
1037 * @param int $width Minimum Image width.
1038 * @param int $height Minimum Image height.
1039 * @return array|bool Image data or false if unavailable.
1040 */
1041 public static function get_attachment_data( $attachment_id, $post_url, $width, $height ) {
1042 if ( empty( $attachment_id ) ) {
1043 return false;
1044 }
1045
1046 $meta = wp_get_attachment_metadata( $attachment_id );
1047
1048 if ( empty( $meta ) ) {
1049 return false;
1050 }
1051
1052 if ( ! empty( $meta['videopress'] ) ) {
1053 // Use poster image for VideoPress videos.
1054 $url = $meta['videopress']['poster'];
1055 $meta_width = $meta['videopress']['width'];
1056 $meta_height = $meta['videopress']['height'];
1057 } elseif ( ! empty( $meta['thumb'] ) ) {
1058 // On WordPress.com, VideoPress videos have a 'thumb' property with the
1059 // poster image filename instead.
1060 $media_url = wp_get_attachment_url( $attachment_id );
1061 $url = str_replace( wp_basename( $media_url ), $meta['thumb'], $media_url );
1062 $meta_width = $meta['width'];
1063 $meta_height = $meta['height'];
1064 } elseif ( wp_attachment_is( 'video', $attachment_id ) ) {
1065 // We don't have thumbnail images for non-VideoPress videos - skip them.
1066 return false;
1067 } else {
1068 if ( ! isset( $meta['width'] ) || ! isset( $meta['height'] ) ) {
1069 return false;
1070 }
1071 $url = wp_get_attachment_url( $attachment_id );
1072 $meta_width = $meta['width'];
1073 $meta_height = $meta['height'];
1074 }
1075
1076 if ( $meta_width < $width || $meta_height < $height ) {
1077 return false;
1078 }
1079
1080 return array(
1081 'type' => 'image',
1082 'from' => 'attachment',
1083 'src' => $url,
1084 'src_width' => $meta_width,
1085 'src_height' => $meta_height,
1086 'href' => $post_url,
1087 'alt_text' => self::get_alt_text( $attachment_id ),
1088 );
1089 }
1090
1091 /**
1092 * Get the alt text for an image or other media from the Media Library.
1093 *
1094 * @since 7.1
1095 *
1096 * @param int $attachment_id The Post ID of the media.
1097 * @return string The alt text value or an empty string.
1098 */
1099 public static function get_alt_text( $attachment_id ) {
1100 return (string) get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
1101 }
1102
1103 /**
1104 * Determine the size to use with Photon for a thumbnail image.
1105 * Images larger than the maximum thumbnail dimension in either dimension are resized to maintain aspect ratio.
1106 *
1107 * @since 14.6
1108 * @see https://github.com/Automattic/jetpack/issues/40349
1109 *
1110 * @param int $width Original image width.
1111 * @param int $height Original image height.
1112 * @return array Array containing the width and height to use with Photon (null means auto).
1113 */
1114 public static function determine_thumbnail_size_for_photon( $width, $height ) {
1115 $max_dimension = self::get_max_thumbnail_dimension();
1116
1117 // If neither dimension exceeds max size, return original dimensions.
1118 if ( $width <= $max_dimension && $height <= $max_dimension ) {
1119 return array(
1120 'width' => $width,
1121 'height' => $height,
1122 );
1123 }
1124
1125 if ( $width >= $height ) {
1126 // For landscape or square images.
1127 $dims = image_resize_dimensions( $width, $height, $max_dimension, 0 ); // Height will be calculated automatically.
1128 } else {
1129 // For portrait images.
1130 $dims = image_resize_dimensions( $width, $height, 0, $max_dimension ); // Width will be calculated automatically.
1131 }
1132
1133 // $dims can be false if the image is virtually the same size as the max dimension, e.g. wp_fuzzy_number_match.
1134 if ( $dims && isset( $dims[4] ) && isset( $dims[5] ) ) {
1135 return array(
1136 'width' => $dims[4],
1137 'height' => $dims[5],
1138 );
1139 }
1140
1141 return array(
1142 'width' => $width,
1143 'height' => $height,
1144 );
1145 }
1146
1147 /**
1148 * Function to provide the maximum dimension for a thumbnail image.
1149 * Filterable via the `jetpack_post_images_max_dimension` filter.
1150 *
1151 * @since 14.6
1152 * @see https://github.com/Automattic/jetpack/issues/40349
1153 *
1154 * @return int The maximum dimension for a thumbnail image.
1155 */
1156 public static function get_max_thumbnail_dimension() {
1157 /**
1158 * Filter the maximum dimension allowed for a thumbnail image.
1159 * The default value is 1200 pixels.
1160 *
1161 * @since 14.6
1162 *
1163 * @param int $max_dimension Maximum dimension in pixels.
1164 */
1165 return (int) apply_filters( 'jetpack_post_images_max_thumbnail_dimension', 1200 );
1166 }
1167 }
1168