Skip to content

Most constants for paths like are set incorrectly #282

@slaFFik

Description

@slaFFik

Hello there,

I just noticed in vendor/szepeviktor/phpstan-wordpress/bootstrap.php that the constants that describe the paths are incorrect set in this stubs library.

define('WP_PLUGIN_DIR', './');
define('WPMU_PLUGIN_DIR', './');
define('WP_LANG_DIR', './');
define('WP_CONTENT_DIR', './');

ABSPATH is set correctly with a trailing slash.

WP_PLUGIN_DIR and WPMU_PLUGIN_DIR and WP_LANG_DIR are set in WP itself without a trailing slash in wp-includes/default-constants.php:

if ( ! defined( 'WP_CONTENT_DIR' ) ) {
	define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // No trailing slash, full paths only - WP_CONTENT_URL is defined further down.
}

/**
 * Allows for the plugins directory to be moved from the default location.
 *
 * @since 2.6.0
 */
if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
	define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // Full path, no trailing slash.
}

/**
 * Allows for the mu-plugins directory to be moved from the default location.
 *
 * @since 2.8.0
 */
if ( ! defined( 'WPMU_PLUGIN_DIR' ) ) {
	define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); // Full path, no trailing slash.
}

define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );

This results in incorrect reporting in PhpStorm when PHPStan is configured:

Image

IMO, in bootstrap.php the paths should be modified:

define('WP_CONTENT_DIR', './wp-content');
define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
define('WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins');
define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions