wp/wp-includes/class-wp-embed.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
--- a/wp/wp-includes/class-wp-embed.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/class-wp-embed.php	Fri Sep 05 18:40:08 2025 +0200
@@ -6,6 +6,7 @@
  * @subpackage Embed
  * @since 2.9.0
  */
+#[AllowDynamicProperties]
 class WP_Embed {
 	public $handlers = array();
 	public $post_ID;
@@ -211,8 +212,10 @@
 
 		$this->last_attr = $attr;
 
-		// KSES converts & into & and we need to undo this.
-		// See https://core.trac.wordpress.org/ticket/11311
+		/*
+		 * KSES converts & into & and we need to undo this.
+		 * See https://core.trac.wordpress.org/ticket/11311
+		 */
 		$url = str_replace( '&', '&', $url );
 
 		// Look for known internal handlers.
@@ -221,11 +224,11 @@
 			return $embed_handler_html;
 		}
 
-		$post_ID = ( ! empty( $post->ID ) ) ? $post->ID : null;
+		$post_id = ( ! empty( $post->ID ) ) ? $post->ID : null;
 
 		// Potentially set by WP_Embed::cache_oembed().
 		if ( ! empty( $this->post_ID ) ) {
-			$post_ID = $this->post_ID;
+			$post_id = $this->post_ID;
 		}
 
 		// Check for a cached result (stored as custom post or in the post meta).
@@ -241,18 +244,18 @@
 		 * @param int    $time    Time to live (in seconds).
 		 * @param string $url     The attempted embed URL.
 		 * @param array  $attr    An array of shortcode attributes.
-		 * @param int    $post_ID Post ID.
+		 * @param int    $post_id Post ID.
 		 */
-		$ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $post_ID );
+		$ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $post_id );
 
 		$cache      = '';
 		$cache_time = 0;
 
 		$cached_post_id = $this->find_oembed_post_id( $key_suffix );
 
-		if ( $post_ID ) {
-			$cache      = get_post_meta( $post_ID, $cachekey, true );
-			$cache_time = get_post_meta( $post_ID, $cachekey_time, true );
+		if ( $post_id ) {
+			$cache      = get_post_meta( $post_id, $cachekey, true );
+			$cache_time = get_post_meta( $post_id, $cachekey_time, true );
 
 			if ( ! $cache_time ) {
 				$cache_time = 0;
@@ -283,9 +286,9 @@
 				 * @param string|false $cache   The cached HTML result, stored in post meta.
 				 * @param string       $url     The attempted embed URL.
 				 * @param array        $attr    An array of shortcode attributes.
-				 * @param int          $post_ID Post ID.
+				 * @param int          $post_id Post ID.
 				 */
-				return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID );
+				return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_id );
 			}
 		}
 
@@ -304,12 +307,12 @@
 		// Use oEmbed to get the HTML.
 		$html = wp_oembed_get( $url, $attr );
 
-		if ( $post_ID ) {
+		if ( $post_id ) {
 			if ( $html ) {
-				update_post_meta( $post_ID, $cachekey, $html );
-				update_post_meta( $post_ID, $cachekey_time, time() );
+				update_post_meta( $post_id, $cachekey, $html );
+				update_post_meta( $post_id, $cachekey_time, time() );
 			} elseif ( ! $cache ) {
-				update_post_meta( $post_ID, $cachekey, '{{unknown}}' );
+				update_post_meta( $post_id, $cachekey, '{{unknown}}' );
 			}
 		} else {
 			$has_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' );
@@ -368,7 +371,7 @@
 		// If there was a result, return it.
 		if ( $html ) {
 			/** This filter is documented in wp-includes/class-wp-embed.php */
-			return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_ID );
+			return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_id );
 		}
 
 		// Still unknown.
@@ -378,17 +381,17 @@
 	/**
 	 * Deletes all oEmbed caches. Unused by core as of 4.0.0.
 	 *
-	 * @param int $post_ID Post ID to delete the caches for.
+	 * @param int $post_id Post ID to delete the caches for.
 	 */
-	public function delete_oembed_caches( $post_ID ) {
-		$post_metas = get_post_custom_keys( $post_ID );
+	public function delete_oembed_caches( $post_id ) {
+		$post_metas = get_post_custom_keys( $post_id );
 		if ( empty( $post_metas ) ) {
 			return;
 		}
 
 		foreach ( $post_metas as $post_meta_key ) {
-			if ( '_oembed_' === substr( $post_meta_key, 0, 8 ) ) {
-				delete_post_meta( $post_ID, $post_meta_key );
+			if ( str_starts_with( $post_meta_key, '_oembed_' ) ) {
+				delete_post_meta( $post_id, $post_meta_key );
 			}
 		}
 	}
@@ -396,10 +399,10 @@
 	/**
 	 * Triggers a caching of all oEmbed results.
 	 *
-	 * @param int $post_ID Post ID to do the caching for.
+	 * @param int $post_id Post ID to do the caching for.
 	 */
-	public function cache_oembed( $post_ID ) {
-		$post = get_post( $post_ID );
+	public function cache_oembed( $post_id ) {
+		$post = get_post( $post_id );
 
 		$post_types = get_post_types( array( 'show_ui' => true ) );