BP_Media_Extractor::extract( string|WP_Post $richtext, int $what_to_extract = self::ALL, array $extra_args = array() )

Extract media from text.


Description Description


Parameters 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()


Top ↑

Return Return

(array)

  • 'has'
    (array) Extracted media counts. {
  • 'audio'
    (int)
  • 'embeds'
    (int)
  • 'images'
    (int)
  • 'links'
    (int)
  • 'mentions'
    (int)
  • 'shortcodes'
    (int)
  • 'video'
    (int)
  • 'audio'
    (array) Extracted audio. { Array of extracted media.
  • 'source'
    (string) Media source. Either "html" or "shortcodes".
  • 'url'
    (string) Link to audio.
  • 'embeds'
    (array) Extracted oEmbeds. { Array of extracted media.
  • 'url'
    (string) oEmbed link.
  • 'images'
    (array) Extracted images. { Array of extracted media.
  • 'gallery_id'
    (int) Gallery ID. Optional, not always set.
  • 'height'
    (int) Width of image. If unknown, set to 0.
  • 'source'
    (string) Media source. Either "html" or "galleries".
  • 'url'
    (string) Link to image.
  • 'width'
    (int) Width of image. If unknown, set to 0.
  • 'links'
    (array) Extracted URLs. { Array of extracted media.
  • 'url'
    (string) Link.
  • 'mentions'
    (array) Extracted mentions. { Array of extracted media.
  • 'name'
    (string) @mention.
  • 'user_id'
    (string) User ID. Optional, only set if Activity component enabled.
  • 'shortcodes'
    (array) Extracted shortcodes. { Array of extracted media.
  • 'attributes'
    (array) Key/value pairs of the shortcodes attributes (if any).
  • 'content'
    (string) Text wrapped by the shortcode.
  • 'type'
    (string) Shortcode type.
  • 'original'
    (string) The entire shortcode.
  • 'videos'
    (array) Extracted video. { Array of extracted media.
  • 'source'
    (string) Media source. Currently only "shortcodes".
  • 'url'
    (string) Link to audio.

  • Top ↑

    Source 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 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 );
    	}
    

    Top ↑

    Changelog Changelog

    Changelog
    Version Description
    2.3.0 Introduced.

    Top ↑

    User Contributed Notes User Contributed Notes

    You must log in before being able to contribute a note or feedback.