Skip to:
Content

BuddyPress.org

Changeset 10834


Ignore:
Timestamp:
05/31/2016 06:58:43 AM (9 years ago)
Author:
r-a-y
Message:

Core: Introduce bp_core_extract_media_from_content().

This is a convenience function to access the BP_Media_Extractor class,
which was made available in BuddyPress 2.3.0.

See #6177.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r10825 r10834  
    16671667     */
    16681668    return apply_filters( 'bp_use_embed_in_private_messages', !defined( 'BP_EMBED_DISABLE_PRIVATE_MESSAGES' ) || !BP_EMBED_DISABLE_PRIVATE_MESSAGES );
     1669}
     1670
     1671/**
     1672 * Extracts media metadata from a given content.
     1673 *
     1674 * @since 2.6.0
     1675 *
     1676 * @param  string     $content The content to check.
     1677 * @param  string|int $type    The type to check. Can also use a bitmask. See the class constants in the
     1678 *                             BP_Media_Extractor class for more info.
     1679 * @return array|bool          If media exists, will return array of media metadata. Else, boolean false.
     1680 */
     1681function bp_core_extract_media_from_content( $content = '', $type = 'all' ) {
     1682    if ( is_string( $type ) ) {
     1683        $class = new ReflectionClass( 'BP_Media_Extractor' );
     1684        $bitmask = $class->getConstant( strtoupper( $type ) );
     1685    } else {
     1686        $bitmask = (int) $type;
     1687    }
     1688
     1689    // Type isn't valid, so bail.
     1690    if ( empty( $bitmask ) ) {
     1691        return false;
     1692    }
     1693
     1694    $x = new BP_Media_Extractor;
     1695    $media = $x->extract( $content, $bitmask );
     1696
     1697    unset( $media['has'] );
     1698    $retval = array_filter( $media );
     1699
     1700    return ! empty( $retval ) ? $retval : false;
    16691701}
    16701702
Note: See TracChangeset for help on using the changeset viewer.