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

Extract <a href> tags from text.


Description Description


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. {
  • 'links'
    (int)
  • 'links'
    (array) Extracted URLs. { Array of extracted media.
  • 'url'
    (string) Link.

  • Top ↑

    Source Source

    File: bp-core/classes/class-bp-media-extractor.php

    	protected function extract_links( $richtext, $plaintext, $extra_args = array() ) {
    		$data = array( 'has' => array( 'links' => 0 ), 'links' => array() );
    
    		// Matches: href="text" and href='text'.
    		if ( stripos( $richtext, 'href=' ) !== false ) {
    			preg_match_all( '#href=(["\'])([^"\']+)\1#i', $richtext, $matches );
    
    			if ( ! empty( $matches[2] ) ) {
    				$matches[2] = array_unique( $matches[2] );
    
    				foreach ( $matches[2] as $link_src ) {
    					$link_src = esc_url_raw( $link_src );
    
    					if ( $link_src ) {
    						$data['links'][] = array( 'url' => $link_src );
    					}
    				}
    			}
    		}
    
    		$data['has']['links'] = count( $data['links'] );
    
    		/**
    		 * Filters links extracted from text.
    		 *
    		 * @since 2.3.0
    		 *
    		 * @param array  $data       Extracted links. See {@link BP_Media_Extractor::extract_links()} 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_links', $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.