BP_Media_Extractor::extract_video( string $richtext, string $plaintext, array $extra_args = array() )

Extract [video] shortcodes from text.


Description Description

See also See also


Top ↑

Parameters Parameters

$richtext

(Required) Content to parse.

$plaintext

(Required) Sanitized version of the content.

$extra_args

(Optional) Bespoke data for a particular extractor (optional).

Default value: array()


Top ↑

Return Return

(array)

  • 'has'
    (array) Extracted media counts. {
  • 'video'
    (int)
  • '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

    	protected function extract_video( $richtext, $plaintext, $extra_args = array() ) {
    		$data   = array( 'has' => array( 'videos' => 0 ), 'videos' => array() );
    		$videos = $this->extract_shortcodes( $richtext, $plaintext, $extra_args );
    
    		$video_types = wp_get_video_extensions();
    
    
    		// [video]
    		$videos = wp_list_filter( $videos['shortcodes'], array( 'type' => 'video' ) );
    		foreach ( $videos as $video ) {
    
    			// Media URL can appear as the first parameter inside the shortcode brackets.
    			if ( isset( $video['attributes']['src'] ) ) {
    				$src_param = 'src';
    			} elseif ( isset( $video['attributes'][0] ) ) {
    				$src_param = 0;
    			} else {
    				continue;
    			}
    
    			$path = untrailingslashit( parse_url( $video['attributes'][ $src_param ], PHP_URL_PATH ) );
    
    			foreach ( $video_types as $extension ) {
    				$extension = '.' . $extension;
    
    				// Check this URL's file extension matches that of an accepted video format (-5 for webm).
    				if ( ! $path || ( substr( $path, -4 ) !== $extension && substr( $path, -5 ) !== $extension ) ) {
    					continue;
    				}
    
    				$data['videos'][] = array(
    					'original' => $video['original'],  // Entire shortcode.
    					'source'   => 'shortcodes',
    					'url'      => esc_url_raw( $video['attributes'][ $src_param ] ),
    				);
    			}
    		}
    
    		$data['has']['videos'] = count( $data['videos'] );
    
    		/**
    		 * Filters videos extracted from text.
    		 *
    		 * @since 2.3.0
    		 *
    		 * @param array  $data       Extracted videos. See {@link BP_Media_Extractor::extract_videos()} 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_videos', $data, $richtext, $plaintext, $extra_args );
    	}
    

    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.