Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/helpers
File: asset-helper.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Helpers;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* A helper object for author archives.
[5] Fix | Delete
*/
[6] Fix | Delete
class Asset_Helper {
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Recursively retrieves all dependency urls of a given handle.
[10] Fix | Delete
*
[11] Fix | Delete
* @param string $handle The handle.
[12] Fix | Delete
*
[13] Fix | Delete
* @return string[] All dependency urls of the given handle.
[14] Fix | Delete
*/
[15] Fix | Delete
public function get_dependency_urls_by_handle( $handle ) {
[16] Fix | Delete
$urls = [];
[17] Fix | Delete
[18] Fix | Delete
foreach ( $this->get_dependency_handles( $handle ) as $other_handle ) {
[19] Fix | Delete
$urls[ $other_handle ] = $this->get_asset_url( $other_handle );
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
return $urls;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Recursively retrieves all dependencies of a given handle.
[27] Fix | Delete
*
[28] Fix | Delete
* @param string $handle The handle.
[29] Fix | Delete
*
[30] Fix | Delete
* @return string[]|bool All dependencies of the given handle.
[31] Fix | Delete
*/
[32] Fix | Delete
public function get_dependency_handles( $handle ) {
[33] Fix | Delete
$scripts = \wp_scripts();
[34] Fix | Delete
[35] Fix | Delete
if ( ! isset( $scripts->registered[ $handle ] ) ) {
[36] Fix | Delete
return false;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$obj = $scripts->registered[ $handle ];
[40] Fix | Delete
$deps = $obj->deps;
[41] Fix | Delete
foreach ( $obj->deps as $other_handle ) {
[42] Fix | Delete
$nested_deps = $this->get_dependency_handles( $other_handle );
[43] Fix | Delete
if ( ! $nested_deps ) {
[44] Fix | Delete
continue;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
// Place nested dependencies before primary dependencies, they need to be loaded first.
[48] Fix | Delete
$deps = \array_merge( $nested_deps, $deps );
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
// Array unique keeps the first of each element so dependencies will be as early as they're required.
[52] Fix | Delete
return \array_values( \array_unique( $deps ) );
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Gets the URL of a given asset.
[57] Fix | Delete
*
[58] Fix | Delete
* This logic is copied from WP_Scripts::do_item as unfortunately that logic is not properly isolated.
[59] Fix | Delete
*
[60] Fix | Delete
* @param string $handle The handle of the asset.
[61] Fix | Delete
*
[62] Fix | Delete
* @return string|false The URL of the asset or false if the asset does not exist.
[63] Fix | Delete
*/
[64] Fix | Delete
public function get_asset_url( $handle ) {
[65] Fix | Delete
$scripts = \wp_scripts();
[66] Fix | Delete
[67] Fix | Delete
if ( ! isset( $scripts->registered[ $handle ] ) ) {
[68] Fix | Delete
return false;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
$obj = $scripts->registered[ $handle ];
[72] Fix | Delete
[73] Fix | Delete
if ( $obj->ver === null ) {
[74] Fix | Delete
$ver = '';
[75] Fix | Delete
}
[76] Fix | Delete
else {
[77] Fix | Delete
$ver = ( $obj->ver ) ? $obj->ver : $scripts->default_version;
[78] Fix | Delete
}
[79] Fix | Delete
if ( isset( $scripts->args[ $handle ] ) ) {
[80] Fix | Delete
$ver = ( $ver ) ? $ver . '&amp;' . $scripts->args[ $handle ] : $scripts->args[ $handle ];
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
$src = $obj->src;
[84] Fix | Delete
[85] Fix | Delete
if ( ! \preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && \strpos( $src, $scripts->content_url ) === 0 ) ) {
[86] Fix | Delete
$src = $scripts->base_url . $src;
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
if ( ! empty( $ver ) ) {
[90] Fix | Delete
$src = \add_query_arg( 'ver', $ver, $src );
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/** This filter is documented in wp-includes/class.wp-scripts.php */
[94] Fix | Delete
return \esc_url( \apply_filters( 'script_loader_src', $src, $handle ) );
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function