Skip to content

Commit

Permalink
Merge pull request #1761 from SohamPatel46/update/enqueue-scripts-to-…
Browse files Browse the repository at this point in the history
…use-plugins-url

Enqueued scripts should use plugins_url() instead of plugin_dir_url()
  • Loading branch information
mukeshpanchal27 authored Dec 20, 2024
2 parents d0299a3 + eba1933 commit ebec285
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugins/embed-optimizer/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function embed_optimizer_filter_extension_module_urls( $extension_module_urls ):
if ( ! is_array( $extension_module_urls ) ) {
$extension_module_urls = array();
}
$extension_module_urls[] = add_query_arg( 'ver', EMBED_OPTIMIZER_VERSION, plugin_dir_url( __FILE__ ) . embed_optimizer_get_asset_path( 'detect.js' ) );
$extension_module_urls[] = plugins_url( add_query_arg( 'ver', EMBED_OPTIMIZER_VERSION, embed_optimizer_get_asset_path( 'detect.js' ) ), __FILE__ );
return $extension_module_urls;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/image-prioritizer/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function image_prioritizer_filter_extension_module_urls( $extension_module_urls
if ( ! is_array( $extension_module_urls ) ) {
$extension_module_urls = array();
}
$extension_module_urls[] = add_query_arg( 'ver', IMAGE_PRIORITIZER_VERSION, plugin_dir_url( __FILE__ ) . image_prioritizer_get_asset_path( 'detect.js' ) );
$extension_module_urls[] = plugins_url( add_query_arg( 'ver', IMAGE_PRIORITIZER_VERSION, image_prioritizer_get_asset_path( 'detect.js' ) ), __FILE__ );
return $extension_module_urls;
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/optimization-detective/detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function od_get_cache_purge_post_id(): ?int {
*/
function od_get_detection_script( string $slug, OD_URL_Metric_Group_Collection $group_collection ): string {
$web_vitals_lib_data = require __DIR__ . '/build/web-vitals.asset.php';
$web_vitals_lib_src = add_query_arg( 'ver', $web_vitals_lib_data['version'], plugin_dir_url( __FILE__ ) . 'build/web-vitals.js' );
$web_vitals_lib_src = plugins_url( add_query_arg( 'ver', $web_vitals_lib_data['version'], 'build/web-vitals.js' ), __FILE__ );

/**
* Filters the list of extension script module URLs to import when performing detection.
Expand Down Expand Up @@ -118,7 +118,7 @@ static function ( OD_URL_Metric_Group $group ): array {
return wp_get_inline_script_tag(
sprintf(
'import detect from %s; detect( %s );',
wp_json_encode( add_query_arg( 'ver', OPTIMIZATION_DETECTIVE_VERSION, plugin_dir_url( __FILE__ ) . od_get_asset_path( 'detect.js' ) ) ),
wp_json_encode( plugins_url( add_query_arg( 'ver', OPTIMIZATION_DETECTIVE_VERSION, od_get_asset_path( 'detect.js' ) ), __FILE__ ) ),
wp_json_encode( $detect_args )
),
array( 'type' => 'module' )
Expand Down
2 changes: 1 addition & 1 deletion plugins/optimization-detective/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ For example:
add_filter(
'od_extension_module_urls',
static function ( array $extension_module_urls ): array {
$extension_module_urls[] = add_query_arg( 'ver', '1.0', plugin_dir_url( __FILE__ ) . 'detect.js' );
$extension_module_urls[] = plugins_url( add_query_arg( 'ver', '1.0', 'detect.js' ), __FILE__ );
return $extension_module_urls;
}
);
Expand Down
2 changes: 1 addition & 1 deletion plugins/performance-lab/includes/admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function perflab_enqueue_features_page_scripts(): void {
// Enqueue plugin activate AJAX script and localize script data.
wp_enqueue_script(
'perflab-plugin-activate-ajax',
plugin_dir_url( PERFLAB_MAIN_FILE ) . perflab_get_asset_path( 'includes/admin/plugin-activate-ajax.js' ),
plugins_url( perflab_get_asset_path( 'includes/admin/plugin-activate-ajax.js' ), PERFLAB_MAIN_FILE ),
array( 'wp-i18n', 'wp-a11y', 'wp-api-fetch' ),
PERFLAB_VERSION,
true
Expand Down
2 changes: 1 addition & 1 deletion plugins/web-worker-offloading/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function plwwo_get_configuration(): array {
$config = array(
// The source code in the build directory is compiled from <https://github.com/BuilderIO/partytown/tree/main/src/lib>.
// See webpack config in the WordPress/performance repo: <https://github.com/WordPress/performance/blob/282a068f3eb2575d37aeb9034e894e7140fcddca/webpack.config.js#L84-L130>.
'lib' => wp_parse_url( plugin_dir_url( __FILE__ ), PHP_URL_PATH ) . 'build/',
'lib' => wp_parse_url( plugins_url( 'build/', __FILE__ ), PHP_URL_PATH ),
);

if ( WP_DEBUG && SCRIPT_DEBUG ) {
Expand Down

0 comments on commit ebec285

Please sign in to comment.