BP_Media_Extractor::extract_images_from_featured_images( string $richtext, string $plaintext, array $extra_args )
Extract the featured image from a Post.
Description
Parameters
- $richtext
-
(Required) Content to parse.
- $plaintext
-
(Required) Sanitized version of the content.
- $extra_args
-
(Required) Contains data that an implementation might need beyond the defaults.
Return
(array)
Source
File: bp-core/classes/class-bp-media-extractor.php
protected function extract_images_from_featured_images( $richtext, $plaintext, $extra_args ) {
$image = array();
$thumb = 0;
if ( isset( $extra_args['post'] ) ) {
$thumb = (int) get_post_thumbnail_id( $extra_args['post']->ID );
}
if ( $thumb ) {
// Validate the size of the images requested.
if ( isset( $extra_args['width'] ) ) {
if ( ! isset( $extra_args['height'] ) && ctype_digit( $extra_args['width'] ) ) {
// A width was specified but not a height, so calculate it assuming a 4:3 ratio.
$extra_args['height'] = round( ( $extra_args['width'] / 4 ) * 3 );
}
if ( ctype_digit( $extra_args['width'] ) ) {
$image_size = array( $extra_args['width'], $extra_args['height'] );
} else {
$image_size = $extra_args['width']; // E.g. "thumb", "medium".
}
} else {
$image_size = 'full';
}
$image = wp_get_attachment_image_src( $thumb, $image_size );
}
/**
* Filters featured images extracted from a WordPress Post.
*
* @since BuddyPress 2.3.0
*
* @param array $image Extracted images. See {@link BP_Media_Extractor_Post::extract_images()} for format.
* @param string $richtext Content to parse.
* @param string $plaintext Copy of $richtext without any markup.
* @param array $extra_args Bespoke data for a particular extractor.
*/
return apply_filters( 'bp_media_extractor_featured_images', $image, $richtext, $plaintext, $extra_args );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 2.3.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.