wp/wp-includes/class-wp-dependencies.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   488 
   488 
   489 		$this->groups[ $handle ] = $group;
   489 		$this->groups[ $handle ] = $group;
   490 
   490 
   491 		return true;
   491 		return true;
   492 	}
   492 	}
       
   493 
       
   494 	/**
       
   495 	 * Get etag header for cache validation.
       
   496 	 *
       
   497 	 * @since 6.7.0
       
   498 	 *
       
   499 	 * @global string $wp_version The WordPress version string.
       
   500 	 *
       
   501 	 * @param string[] $load Array of script or style handles to load.
       
   502 	 * @return string Etag header.
       
   503 	 */
       
   504 	public function get_etag( $load ) {
       
   505 		/*
       
   506 		 * Note: wp_get_wp_version() is not used here, as this file can be included
       
   507 		 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
       
   508 		 * wp-includes/functions.php is not loaded.
       
   509 		 */
       
   510 		global $wp_version;
       
   511 
       
   512 		$etag = "WP:{$wp_version};";
       
   513 
       
   514 		foreach ( $load as $handle ) {
       
   515 			if ( ! array_key_exists( $handle, $this->registered ) ) {
       
   516 				continue;
       
   517 			}
       
   518 
       
   519 			$ver   = $this->registered[ $handle ]->ver ?? $wp_version;
       
   520 			$etag .= "{$handle}:{$ver};";
       
   521 		}
       
   522 
       
   523 		/*
       
   524 		 * This is not intended to be cryptographically secure, just a fast way to get
       
   525 		 * a fixed length string based on the script versions. As this file does not
       
   526 		 * load the full WordPress environment, it is not possible to use the salted
       
   527 		 * wp_hash() function.
       
   528 		 */
       
   529 		return 'W/"' . md5( $etag ) . '"';
       
   530 	}
   493 }
   531 }