Automattic\WooCommerce\Blocks\Assets
Api::get_script_data()
Get src, version and dependencies given a script relative src.
Метод класса: Api{}
Хуков нет.
Возвращает
Массив
. src, version and dependencies of the script.
Использование
$Api = new Api(); $Api->get_script_data( $relative_src, $dependencies );
- $relative_src(строка) (обязательный)
- Relative src to the script.
- $dependencies(массив)
- An array of registered script handles this script depends on.
По умолчанию: empty array
Код Api::get_script_data() Api::get script data WC 9.2.3
public function get_script_data( $relative_src, $dependencies = [] ) { if ( ! $relative_src ) { return array( 'src' => '', 'version' => '1', 'dependencies' => $dependencies, ); } if ( is_null( $this->script_data ) ) { $this->script_data = $this->get_cached_script_data(); } if ( empty( $this->script_data[ $relative_src ] ) ) { $asset_path = $this->package->get_path( str_replace( '.js', '.asset.php', $relative_src ) ); // The following require is safe because we are checking if the file exists and it is not a user input. // nosemgrep audit.php.lang.security.file.inclusion-arg. $asset = file_exists( $asset_path ) ? require $asset_path : []; $this->script_data[ $relative_src ] = array( 'src' => $this->get_asset_url( $relative_src ), 'version' => ! empty( $asset['version'] ) ? $asset['version'] : $this->get_file_version( $relative_src ), 'dependencies' => ! empty( $asset['dependencies'] ) ? $asset['dependencies'] : [], ); } // Return asset details as well as the requested dependencies array. return [ 'src' => $this->script_data[ $relative_src ]['src'], 'version' => $this->script_data[ $relative_src ]['version'], 'dependencies' => array_merge( $this->script_data[ $relative_src ]['dependencies'], $dependencies ), ]; }