public function find( $args, $assoc_args ) {
		if ( Utils\wp_version_compare( '4.9', '<' ) ) {
			WP_CLI::error( 'Requires WordPress 4.9 or greater.' );
		}

		/** @var \WP_Embed $wp_embed */
		global $wp_embed;

		$url      = $args[0];
		$width    = Utils\get_flag_value( $assoc_args, 'width' );
		$height   = Utils\get_flag_value( $assoc_args, 'height' );
		$discover = Utils\get_flag_value( $assoc_args, 'discover' );

		// The `$key_suffix` used for caching is part based on serializing the attributes array without normalizing it first so need to try to replicate that.
		$oembed_args = array();

		if ( null !== $width ) {
			$oembed_args['width'] = $width; // Keep as string as if from a shortcode attribute.
		}
		if ( null !== $height ) {
			$oembed_args['height'] = $height; // Keep as string as if from a shortcode attribute.
		}
		if ( null !== $discover ) {
			$discovers = array( ( $discover ) ? '1' : '0' );
		} else {
			$discovers = array( null, '1', '0' );
		}

		$attr = wp_parse_args( $oembed_args, wp_embed_defaults( $url ) );

		foreach ( $discovers as $discover ) {
			if ( null !== $discover ) {
				$attr['discover'] = $discover;
			}
			// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- needed to mimic WP Core behavior. See: \WP_Embed::shortcode.
			$key_suffix = md5( $url . serialize( $attr ) );

			$cached_post_id = $wp_embed->find_oembed_post_id( $key_suffix );

			if ( $cached_post_id ) {
				WP_CLI::line( $cached_post_id );

				return;
			}
		}

		WP_CLI::error( 'No cache post ID found!' );
	}
public function find( $args, $assoc_args ) {
		if ( Utils\wp_version_compare( '4.9', '<' ) ) {
			WP_CLI::error( 'Requires WordPress 4.9 or greater.' );
		}

		/** @var \WP_Embed $wp_embed */
		global $wp_embed;

		$url      = $args[0];
		$width    = Utils\get_flag_value( $assoc_args, 'width' );
		$height   = Utils\get_flag_value( $assoc_args, 'height' );
		$discover = Utils\get_flag_value( $assoc_args, 'discover' );

		// The `$key_suffix` used for caching is part based on serializing the attributes array without normalizing it first so need to try to replicate that.
		$oembed_args = array();

		if ( null !== $width ) {
			$oembed_args['width'] = $width; // Keep as string as if from a shortcode attribute.
		}
		if ( null !== $height ) {
			$oembed_args['height'] = $height; // Keep as string as if from a shortcode attribute.
		}
		if ( null !== $discover ) {
			$discovers = array( ( $discover ) ? '1' : '0' );
		} else {
			$discovers = array( null, '1', '0' );
		}

		$attr = wp_parse_args( $oembed_args, wp_embed_defaults( $url ) );

		foreach ( $discovers as $discover ) {
			if ( null !== $discover ) {
				$attr['discover'] = $discover;
			}
			// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- needed to mimic WP Core behavior. See: \WP_Embed::shortcode.
			$key_suffix = md5( $url . serialize( $attr ) );

			$cached_post_id = $wp_embed->find_oembed_post_id( $key_suffix );

			if ( $cached_post_id ) {
				WP_CLI::line( $cached_post_id );

				return;
			}
		}

		WP_CLI::error( 'No cache post ID found!' );
	}
public function find ( $ args , $ assoc_args ) { if ( Utils \ wp_version_compare ( '4.9' , '<' ) ) { WP_CLI :: error ( 'Requires WordPress 4.9 or greater.' ) ; } /** @var \WP_Embed $wp_embed */ global $ wp_embed ; $ url = $ args [ 0 ] ; $ width = Utils \ get_flag_value ( $ assoc_args , 'width' ) ; $ height = Utils \ get_flag_value ( $ assoc_args , 'height' ) ; $ discover = Utils \ get_flag_value ( $ assoc_args , 'discover' ) ; // The `$key_suffix` used for caching is part based on serializing the attributes array without normalizing it first so need to try to replicate that. $ oembed_args = array ( ) ; if ( null !== $ width ) { $ oembed_args [ 'width' ] = $ width ; // Keep as string as if from a shortcode attribute. } if ( null !== $ height ) { $ oembed_args [ 'height' ] = $ height ; // Keep as string as if from a shortcode attribute. } if ( null !== $ discover ) { $ discovers = array ( ( $ discover ) ? '1' : '0' ) ; } else { $ discovers = array ( null , '1' , '0' ) ; } $ attr = wp_parse_args ( $ oembed_args , wp_embed_defaults ( $ url ) ) ; foreach ( $ discovers as $ discover ) { if ( null !== $ discover ) { $ attr [ 'discover' ] = $ discover ; } // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- needed to mimic WP Core behavior. See: \WP_Embed::shortcode. $ key_suffix = md5 ( $ url . serialize ( $ attr ) ) ; $ cached_post_id = $ wp_embed -> find_oembed_post_id ( $ key_suffix ) ; if ( $ cached_post_id ) { WP_CLI :: line ( $ cached_post_id ) ; return ; } } WP_CLI :: error ( 'No cache post ID found!' ) ; }
Finds an oEmbed cache post ID for a given URL.

Starting with WordPress 4.9, embeds that aren't associated with a specific post will be cached in
a new oembed_cache post type. There can be more than one such entry for a url depending on attributes and context.

Not to be confused with oEmbed caches for a given post which are stored in the post's metadata.

## OPTIONS

<url>
: URL to retrieve oEmbed data for.

[--width=<width>]
: Width of the embed in pixels. Part of cache key so must match. Defaults to `content_width` if set else 500px, so is theme and context dependent.

[--height=<height>]
: Height of the embed in pixels. Part of cache key so must match. Defaults to 1.5 * default width (`content_width` or 500px), to a maximum of 1000px.

[--discover]
: Whether to search with the discover attribute set or not. Part of cache key so must match. If not given, will search with attribute: unset, '1', '0', returning first.

## EXAMPLES

# Find cache post ID for a given URL.
$ wp embed cache find https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500
123
Finds an oEmbed cache post ID for a given URL .