BP_Media_Extractor::extract( string|WP_Post $richtext, int $what_to_extract = self::ALL, array $extra_args = array() )
Extract media from text.
Description
Parameters
- $richtext
-
(Required) Content to parse.
- $what_to_extract
-
(Optional) Media type to extract (optional).
Default value: self::ALL
- $extra_args
-
(Optional) Bespoke data for a particular extractor (optional).
Default value: array()
Return
(array)
- 'has'
(array) Extracted media counts. { - 'audio'
(int) - 'embeds'
(int) - 'images'
(int) - 'links'
(int) - 'mentions'
(int) - 'shortcodes'
(int) - 'video'
(int)
(array) Extracted audio. { Array of extracted media.
(string) Media source. Either "html" or "shortcodes".
(string) Link to audio.
(array) Extracted oEmbeds. { Array of extracted media.
(string) oEmbed link.
(array) Extracted images. { Array of extracted media.
(int) Gallery ID. Optional, not always set.
(int) Width of image. If unknown, set to 0.
(string) Media source. Either "html" or "galleries".
(string) Link to image.
(int) Width of image. If unknown, set to 0.
(array) Extracted URLs. { Array of extracted media.
(string) Link.
(array) Extracted mentions. { Array of extracted media.
(string) @mention.
(string) User ID. Optional, only set if Activity component enabled.
(array) Extracted shortcodes. { Array of extracted media.
(array) Key/value pairs of the shortcodes attributes (if any).
(string) Text wrapped by the shortcode.
(string) Shortcode type.
(string) The entire shortcode.
(array) Extracted video. { Array of extracted media.
(string) Media source. Currently only "shortcodes".
(string) Link to audio.
Source
File: bp-core/classes/class-bp-media-extractor.php
public function extract( $richtext, $what_to_extract = self::ALL, $extra_args = array() ) { $media = array(); // Support passing a WordPress Post for the $richtext parameter. if ( is_a( $richtext, 'WP_Post' ) ) { $extra_args['post'] = $richtext; $richtext = $extra_args['post']->post_content; } $plaintext = $this->strip_markup( $richtext ); // Extract links. if ( self::LINKS & $what_to_extract ) { $media = array_merge_recursive( $media, $this->extract_links( $richtext, $plaintext, $extra_args ) ); } // Extract mentions. if ( self::MENTIONS & $what_to_extract ) { $media = array_merge_recursive( $media, $this->extract_mentions( $richtext, $plaintext, $extra_args ) ); } // Extract images. if ( self::IMAGES & $what_to_extract ) { $media = array_merge_recursive( $media, $this->extract_images( $richtext, $plaintext, $extra_args ) ); } // Extract shortcodes. if ( self::SHORTCODES & $what_to_extract ) { $media = array_merge_recursive( $media, $this->extract_shortcodes( $richtext, $plaintext, $extra_args ) ); } // Extract oEmbeds. if ( self::EMBEDS & $what_to_extract ) { $media = array_merge_recursive( $media, $this->extract_embeds( $richtext, $plaintext, $extra_args ) ); } // Extract audio. if ( self::AUDIO & $what_to_extract ) { $media = array_merge_recursive( $media, $this->extract_audio( $richtext, $plaintext, $extra_args ) ); } // Extract video. if ( self::VIDEOS & $what_to_extract ) { $media = array_merge_recursive( $media, $this->extract_video( $richtext, $plaintext, $extra_args ) ); } /** * Filters media extracted from text. * * @since BuddyPress 2.3.0 * * @param array $media Extracted media. See {@link BP_Media_Extractor::extract()} for format. * @param string $richtext Content to parse. * @param int $what_to_extract Media type to extract. * @param array $extra_args Bespoke data for a particular extractor. * @param string $plaintext Copy of $richtext without any markup. */ return apply_filters( 'bp_media_extractor_extract', $media, $richtext, $what_to_extract, $extra_args, $plaintext ); }
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.