Skip to content

Fix inconsistent plugin path construction throughout codebase #1019

@coderabbitai

Description

@coderabbitai

Problem

There are inconsistencies in how plugin asset paths are constructed throughout the codebase, which can lead to broken asset loading when files are located in subdirectories.

Root Cause

The plugin defines EDAC_PLUGIN_URL constant correctly in the main plugin file:

define( 'EDAC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

However, several files use plugin_dir_url( __DIR__ ) instead of the EDAC_PLUGIN_URL constant. When __DIR__ is used in files located in subdirectories (like partials/), it points to the subdirectory rather than the plugin root, creating incorrect asset paths.

Affected Files

Files using incorrect plugin_dir_url( __DIR__ ):

  1. partials/welcome-page.php (line 40):

    <img src="<?php echo esc_url( plugin_dir_url( __DIR__ ) ); ?>assets/images/accessibility-checker-logo-transparent-bg.svg"
  2. partials/pro-callout.php:

    src="<?php echo esc_url( plugin_dir_url( __DIR__ ) ); ?>assets/images/edac-emblem.png"
  3. admin/class-enqueue-admin.php:

    'baseurl' => plugin_dir_url( __DIR__ ),

Files using different patterns:

  • Some files correctly use plugin_dir_url( EDAC_PLUGIN_FILE )
  • Some files correctly use EDAC_PLUGIN_URL constant
  • Some files use plugin_dir_url( __FILE__ ) in specific contexts

Solution

Standardize on using the EDAC_PLUGIN_URL constant for all plugin root asset references, as it's already properly defined and used in many places throughout the codebase.

Recommended changes:

  1. partials/welcome-page.php:

    <img src="<?php echo esc_url( EDAC_PLUGIN_URL ); ?>assets/images/accessibility-checker-logo-transparent-bg.svg"
  2. partials/pro-callout.php:

    src="<?php echo esc_url( EDAC_PLUGIN_URL ); ?>assets/images/edac-emblem.png"
  3. admin/class-enqueue-admin.php:

    'baseurl' => EDAC_PLUGIN_URL,

Background

This issue was identified during code review of PR #1018 where gemini-code-assist bot flagged the path construction problem.

References:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions