bp_core_extract_media_from_content

Extracts media metadata from a given content.

Description

(array|bool) bp_core_extract_media_from_content( (string) $content = '', (string) $type = 'all' ); 

Returns (array|bool)

If media exists, will return array of media metadata. Else, boolean false.

Parameters (2)

0. $content — Optional. (string) => ''
The content to check.
1. $type — Optional. (string) => 'all'
The type to check. Can also use a bitmask. See the class constants in the BP_Media_Extractor class for more info.

Usage

  1. if ( !function_exists( 'bp_core_extract_media_from_content' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // The content to check. 
  5. $content = ''; 
  6.  
  7. // The type to check. Can also use a bitmask. See the class constants in the 
  8. // BP_Media_Extractor class for more info. 
  9. $type = 'all'; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bp_core_extract_media_from_content($content, $type); 
  13.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-functions.php  
  1. function bp_core_extract_media_from_content( $content = '', $type = 'all' ) { 
  2. if ( is_string( $type ) ) { 
  3. $class = new ReflectionClass( 'BP_Media_Extractor' ); 
  4. $bitmask = $class->getConstant( strtoupper( $type ) ); 
  5. } else { 
  6. $bitmask = (int) $type; 
  7.  
  8. // Type isn't valid, so bail. 
  9. if ( empty( $bitmask ) ) { 
  10. return false; 
  11.  
  12. $x = new BP_Media_Extractor; 
  13. $media = $x->extract( $content, $bitmask ); 
  14.  
  15. unset( $media['has'] ); 
  16. $retval = array_filter( $media ); 
  17.  
  18. return ! empty( $retval ) ? $retval : false;