WP_Embed::register_handler() WordPress Method

The WP_Embed::register_handler() method allows you to register a newembed handler. Embed handlers are responsible for turning URLs into embed code. For example, the YouTube embed handler turns a YouTube URL into embed code that will display a YouTube video. This method accepts two parameters: $id (string) (required) The ID of the embed handler. Must be unique. $handler (callable) (required) The callback function that will generate the embed code for the URL. Here is an example of how to use this method to register a new embed handler: WP_Embed::register_handler( 'my_embed_handler', 'my_embed_handler_callback' ); my_embed_handler_callback() is the callback function that will generate the embed code. This method returns true if the embed handler is registered successfully, or false if there is an error.

WP_Embed::register_handler( string $id, string $regex, callable $callback, int $priority = 10 ) #

Registers an embed handler.


Description

Do not use this function directly, use wp_embed_register_handler() instead.

This function should probably also only be used for sites that do not support oEmbed.


Top ↑

Parameters

$id

(string)(Required)An internal ID/name for the handler. Needs to be unique.

$regex

(string)(Required)The regex that will be used to see if this handler should be used for a URL.

$callback

(callable)(Required)The callback function that will be called if the regex is matched.

$priority

(int)(Optional) Used to specify the order in which the registered handlers will be tested. Lower numbers correspond with earlier testing, and handlers with the same priority are tested in the order in which they were added to the action.

Default value: 10


Top ↑

Source

File: wp-includes/class-wp-embed.php

	public function register_handler( $id, $regex, $callback, $priority = 10 ) {
		$this->handlers[ $priority ][ $id ] = array(
			'regex'    => $regex,
			'callback' => $callback,
		);
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.