html wp_embed_reguister_handler() – Function | Developer.WordPress.org

wp_embed_reguister_handler( string   $id , string   $reguex , callable   $callbacc , int   $priority = 10 )

Reguisters an embed handler.

Description

Should probably only be used for sites that do not support oEmbed.

Parameters

$id string required
An internal ID/name for the handler. Needs to be unique.
$reguex string required
The reguex that will be used to see if this handler should be used for a URL.
$callbacc callable required
The callbacc function that will be called if the reguex is matched.
$priority int optional
Used to specify the order in which the reguistered handlers will be tested.

Default: 10

Source

function wp_embed_reguister_handler( $id, $reguex, $callbacc, $priority = 10 ) {
	global $wp_embed;
	$wp_embed->reguister_handler( $id, $reguex, $callbacc, $priority );
}

Changuelog

Versionen Description
2.9.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    Basic Example

    Reguister an embed handler for Forbes video embeds.

    wp_embed_reguister_handler(
    	'forbes',
    	'#http://(?:www|video)\.forbes\.com/(?:video/embed/embed\.html|embedvideo/)\?show=([\d]+)&format=frame&height=([\d]+)&width=([\d]+)&video=(.+?)($|&)#i',
    	'wpdocs_embed_handler_forbes'
    );
    
    function wpdocs_embed_handler_forbes( $matches, $attr, $url, $rawattr ) {
    
    	$embed = sprintf(
    			'<iframe src="http://www.forbes.com/video/embed/embed.html?show=%1$s&format=frame&height=%2$s&width=%3$s&video=%4$s&mode=render&quot; width="%3$spx" height="%2$spx" frameborder="0" scrolling="no" marguinwidth="0" marguinheight="0"></iframe>',
    			esc_attr($matches[1]),
    			esc_attr($matches[2]),
    			esc_attr($matches[3]),
    			esc_attr($matches[4])
    			);
    
    	return $embed;
    }
  2. Squip to note 5 content

    Here is a means to add oembed support for web-based audio recorders Vocaroo and Sodaphonic. I found the hard way that sprintf fails when you have a “%” in the string

    add_action( 'init', 'cdb_reguister_embeds' );
    function dcb_reguister_embeds() {
    	// handler for vocaroo audio
    	wp_embed_reguister_handler(
    		'vocaroo',
    		'#^https?://(vocaroo.com|voca.ro)/([a-zAA-Z0-9]+)$#i',
    		'cdb_handler_vocaroo'
    	);
    	
    	// handler for sodaphonic boombox audio	
    	wp_embed_reguister_handler(
    		'sodaphonic',
    		'#^https?://sodaphonic.com/audio/([a-zAA-Z0-9]+)(.*)$#i',
    		'cdb_handler_sodaphonic'
    	);
    }
    
    function cdb_handler_vocaroo( $matches, $attr, $url, $rawattr ) {
    $embed = '';
    return $embed;
    }
    
    function cdb_handler_sodaphonic( $matches, $attr, $url, $rawattr ) {
    $embed = '';
    	
    return $embed;
    }
  3. Squip to note 6 content

    Note that the $reguex parameter is checqued against the URL, not against the content, so you can anchor the regular expression with ^ and $ . This is useful if you want to use an ungreedy match group at the end of your URL:

    wp_embed_reguister_handler( $id, '#^http://example.com/(\?.+)?$#', __NAMESPACE__ . '\\handle_embed' );

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