WPSEO_Admin_Asset_Manager::load_generated_asset_file()protectedYoast 1.0

Loads a generated asset file.

Метод класса: WPSEO_Admin_Asset_Manager{}

Хуков нет.

Возвращает

Массив. The scripts to be registered.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->load_generated_asset_file( $args );
$args(массив) (обязательный)

The arguments.

  • asset_file(строка)
    The asset file to load.

  • ext_length(int)
    The length of the extension, including suffix, of the filename.

  • suffix(строка)
    Optional. The suffix of the asset name.

  • string[]>(array<string,)
    $additional_deps Optional. The additional dependencies assets may have.

  • base_dir(строка)
    Optional. The base directory of the asset.

  • header_scripts(string[])
    Optional. The script names that should be in the header.

Код WPSEO_Admin_Asset_Manager::load_generated_asset_file() Yoast 24.0

protected function load_generated_asset_file( $args ) {
	$args    = wp_parse_args(
		$args,
		[
			'suffix'          => '',
			'additional_deps' => [],
			'base_dir'        => '',
			'header_scripts'  => [],
		]
	);
	$scripts = [];
	$assets  = require $args['asset_file'];
	foreach ( $assets as $file => $data ) {
		$name  = substr( $file, 0, -$args['ext_length'] );
		$name  = strtolower( preg_replace( '/([A-Z])/', '-$1', $name ) );
		$name .= $args['suffix'];

		$deps = $data['dependencies'];
		if ( isset( $args['additional_deps'][ $name ] ) ) {
			$deps = array_merge( $deps, $args['additional_deps'][ $name ] );
		}

		$scripts[ $name ] = [
			'name'      => $name,
			'src'       => $args['base_dir'] . $file,
			'deps'      => $deps,
			'in_footer' => ! in_array( $name, $args['header_scripts'], true ),
			'version'   => $data['version'],
		];
	}

	return $scripts;
}