Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PERFLAB_PLUGIN_DIR_PATH constant for plugin_dir_path() #429

Merged
merged 2 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

define( 'PERFLAB_VERSION', '1.2.0' );
define( 'PERFLAB_MAIN_FILE', __FILE__ );
define( 'PERFLAB_PLUGIN_DIR_PATH', plugin_dir_path( PERFLAB_MAIN_FILE ) );
define( 'PERFLAB_MODULES_SETTING', 'perflab_modules_settings' );
define( 'PERFLAB_MODULES_SCREEN', 'perflab-modules' );

Expand Down Expand Up @@ -50,7 +51,7 @@ function perflab_get_modules_setting_default() {

if ( null === $default_option ) {
// To set the default value for which modules are enabled, rely on this generated file.
$default_enabled_modules = require plugin_dir_path( __FILE__ ) . 'default-enabled-modules.php';
$default_enabled_modules = require PERFLAB_PLUGIN_DIR_PATH . 'default-enabled-modules.php';
$default_option = array_reduce(
$default_enabled_modules,
function( $module_settings, $module_dir ) {
Expand Down Expand Up @@ -152,7 +153,7 @@ function perflab_is_valid_module( $module ) {
}

// Do not load module if no longer exists.
$module_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php';
$module_file = PERFLAB_PLUGIN_DIR_PATH . 'modules/' . $module . '/load.php';
if ( ! file_exists( $module_file ) ) {
return false;
}
Expand Down Expand Up @@ -201,7 +202,7 @@ function perflab_render_generator() {
* @return bool Whether the module can be loaded or not.
*/
function perflab_can_load_module( $module ) {
$module_load_file = plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/can-load.php';
$module_load_file = PERFLAB_PLUGIN_DIR_PATH . 'modules/' . $module . '/can-load.php';

// If the `can-load.php` file does not exist, assume the module can be loaded.
if ( ! file_exists( $module_load_file ) ) {
Expand Down Expand Up @@ -231,16 +232,16 @@ function perflab_load_active_and_valid_modules() {

foreach ( $active_and_valid_modules as $module ) {

require_once plugin_dir_path( __FILE__ ) . 'modules/' . $module . '/load.php';
require_once PERFLAB_PLUGIN_DIR_PATH . 'modules/' . $module . '/load.php';
}
}

perflab_load_active_and_valid_modules();

// Only load admin integration when in admin.
if ( is_admin() ) {
require_once plugin_dir_path( __FILE__ ) . 'admin/load.php';
require_once PERFLAB_PLUGIN_DIR_PATH . 'admin/load.php';
}

// Polyfills.
require_once plugin_dir_path( __FILE__ ) . 'polyfills.php';
require_once PERFLAB_PLUGIN_DIR_PATH . 'polyfills.php';
6 changes: 3 additions & 3 deletions tests/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function test_perflab_sanitize_modules_setting() {
}

public function test_perflab_get_modules_setting_default() {
$default_enabled_modules = require plugin_dir_path( PERFLAB_MAIN_FILE ) . 'default-enabled-modules.php';
$default_enabled_modules = require PERFLAB_PLUGIN_DIR_PATH . 'default-enabled-modules.php';
$expected = array();
foreach ( $default_enabled_modules as $default_enabled_module ) {
$expected[ $default_enabled_module ] = array( 'enabled' => true );
Expand Down Expand Up @@ -123,7 +123,7 @@ function( $module_settings ) {
public function test_perflab_get_generator_content() {
// Assert that it returns the current version and active modules.
// For this test, set the active modules to all defaults but the last one.
$active_modules = require plugin_dir_path( PERFLAB_MAIN_FILE ) . 'default-enabled-modules.php';
$active_modules = require PERFLAB_PLUGIN_DIR_PATH . 'default-enabled-modules.php';
array_pop( $active_modules );
add_filter(
'perflab_active_modules',
Expand Down Expand Up @@ -185,7 +185,7 @@ public function data_perflab_can_load_module() {

private function get_expected_default_option() {
// This code is essentially copied over from the perflab_register_modules_setting() function.
$default_enabled_modules = require plugin_dir_path( PERFLAB_MAIN_FILE ) . 'default-enabled-modules.php';
$default_enabled_modules = require PERFLAB_PLUGIN_DIR_PATH . 'default-enabled-modules.php';
return array_reduce(
$default_enabled_modules,
function( $module_settings, $module_dir ) {
Expand Down