WP_oEmbed_Controller::register_routes()

Register the oEmbed REST API route.


Source

File: wp-includes/class-wp-oembed-controller.php

	public function register_routes() {
		/**
		 * Filters the maxwidth oEmbed parameter.
		 *
		 * @since WP-4.4.0
		 *
		 * @param int $maxwidth Maximum allowed width. Default 600.
		 */
		$maxwidth = apply_filters( 'oembed_default_width', 600 );

		register_rest_route( 'oembed/1.0', '/embed', array(
			array(
				'methods'  => WP_REST_Server::READABLE,
				'callback' => array( $this, 'get_item' ),
				'args'     => array(
					'url'      => array(
						'required'          => true,
						'sanitize_callback' => 'esc_url_raw',
					),
					'format'   => array(
						'default'           => 'json',
						'sanitize_callback' => 'wp_oembed_ensure_format',
					),
					'maxwidth' => array(
						'default'           => $maxwidth,
						'sanitize_callback' => 'absint',
					),
				),
			),
		) );

		register_rest_route( 'oembed/1.0', '/proxy', array(
			array(
				'methods'  => WP_REST_Server::READABLE,
				'callback' => array( $this, 'get_proxy_item' ),
				'permission_callback' => array( $this, 'get_proxy_item_permissions_check' ),
				'args'     => array(
					'url'      => array(
						'description'       => __( 'The URL of the resource for which to fetch oEmbed data.' ),
						'type'              => 'string',
						'required'          => true,
						'sanitize_callback' => 'esc_url_raw',
					),
					'format'   => array(
						'description'       => __( 'The oEmbed format to use.' ),
						'type'              => 'string',
						'default'           => 'json',
						'enum'              => array(
							'json',
							'xml',
						),
					),
					'maxwidth' => array(
						'description'       => __( 'The maximum width of the embed frame in pixels.' ),
						'type'              => 'integer',
						'default'           => $maxwidth,
						'sanitize_callback' => 'absint',
					),
					'maxheight' => array(
						'description'       => __( 'The maximum height of the embed frame in pixels.' ),
						'type'              => 'integer',
						'sanitize_callback' => 'absint',
					),
					'discover' => array(
						'description'       => __( 'Whether to perform an oEmbed discovery request for non-whitelisted providers.' ),
						'type'              => 'boolean',
						'default'           => true,
					),
				),
			),
		) );
	}


Changelog

Changelog
Version Description
WP-4.4.0 Introduced.