Skip to content

Commit e72fff9

Browse files
Code Modernization: Replace dirname( __FILE__ ) calls with __DIR__ magic constant.
This avoids the performance overhead of the function call every time `dirname( __FILE__ )` was used instead of `__DIR__`. This commit also includes: * Removing unnecessary parentheses from `include`/`require` statements. These are language constructs, not function calls. * Replacing `include` statements for several files with `require_once`, for consistency: * `wp-admin/admin-header.php` * `wp-admin/admin-footer.php` * `wp-includes/version.php` Props ayeshrajans, desrosj, valentinbora, jrf, joostdevalk, netweb. Fixes #48082. git-svn-id: https://develop.svn.wordpress.org/trunk@47198 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b02e49c commit e72fff9

File tree

304 files changed

+1072
-1067
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+1072
-1067
lines changed

src/_index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
define( 'WP_USE_THEMES', true );
1515

1616
/** Loads the WordPress Environment and Template */
17-
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
17+
require __DIR__ . '/wp-blog-header.php';

src/index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/** Define ABSPATH as this file's directory */
1010
if ( ! defined( 'ABSPATH' ) ) {
11-
define( 'ABSPATH', dirname( __FILE__ ) . '/' );
11+
define( 'ABSPATH', __DIR__ . '/' );
1212
}
1313

1414
if ( file_exists( ABSPATH . 'wp-includes/js/dist/edit-post.js' ) ) {
@@ -17,14 +17,14 @@
1717
}
1818

1919
define( 'WPINC', 'wp-includes' );
20-
require_once( ABSPATH . WPINC . '/load.php' );
20+
require_once ABSPATH . WPINC . '/load.php';
2121

2222
// Standardize $_SERVER variables across setups.
2323
wp_fix_server_vars();
2424

25-
require_once( ABSPATH . WPINC . '/functions.php' );
25+
require_once ABSPATH . WPINC . '/functions.php';
2626
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
27-
require_once( ABSPATH . WPINC . '/version.php' );
27+
require_once ABSPATH . WPINC . '/version.php';
2828

2929
wp_check_php_mysql_versions();
3030
wp_load_translations_early();

src/js/_enqueues/vendor/tinymce/wp-tinymce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
error_reporting( 0 );
1313

14-
$basepath = dirname( __FILE__ );
14+
$basepath = __DIR__;
1515

1616
function get_file( $path ) {
1717

src/wp-activate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
define( 'WP_INSTALLING', true );
1010

1111
/** Sets up the WordPress Environment. */
12-
require( dirname( __FILE__ ) . '/wp-load.php' );
12+
require __DIR__ . '/wp-load.php';
1313

14-
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
14+
require __DIR__ . '/wp-blog-header.php';
1515

1616
if ( ! is_multisite() ) {
1717
wp_redirect( wp_registration_url() );

src/wp-admin/_index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88

99
/** Load WordPress Bootstrap */
10-
require_once( dirname( __FILE__ ) . '/admin.php' );
10+
require_once __DIR__ . '/admin.php';
1111

1212
/** Load WordPress dashboard API */
13-
require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
13+
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
1414

1515
wp_dashboard_setup();
1616

@@ -108,7 +108,7 @@
108108
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
109109
);
110110

111-
include( ABSPATH . 'wp-admin/admin-header.php' );
111+
require_once ABSPATH . 'wp-admin/admin-header.php';
112112
?>
113113

114114
<div class="wrap">
@@ -153,4 +153,4 @@
153153
<?php
154154
wp_print_community_events_templates();
155155

156-
require( ABSPATH . 'wp-admin/admin-footer.php' );
156+
require_once ABSPATH . 'wp-admin/admin-footer.php';

src/wp-admin/about.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
*/
88

99
/** WordPress Administration Bootstrap */
10-
require_once( dirname( __FILE__ ) . '/admin.php' );
10+
require_once __DIR__ . '/admin.php';
1111

1212
/* translators: Page title of the About WordPress page in the admin. */
1313
$title = _x( 'About', 'page title' );
1414

1515
list( $display_version ) = explode( '-', get_bloginfo( 'version' ) );
1616

17-
include( ABSPATH . 'wp-admin/admin-header.php' );
17+
require_once ABSPATH . 'wp-admin/admin-header.php';
1818
?>
1919
<div class="wrap about__container">
2020

@@ -202,7 +202,7 @@
202202
</div>
203203
<?php
204204

205-
include( ABSPATH . 'wp-admin/admin-footer.php' );
205+
require_once ABSPATH . 'wp-admin/admin-footer.php';
206206

207207
// These are strings we may use to describe maintenance/security releases, where we aim for no new strings.
208208
return;

src/wp-admin/admin-ajax.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020

2121
/** Load WordPress Bootstrap */
22-
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
22+
require_once dirname( __DIR__ ) . '/wp-load.php';
2323

2424
/** Allow for cross-domain requests (from the front end). */
2525
send_origin_headers();
@@ -33,10 +33,10 @@
3333
}
3434

3535
/** Load WordPress Administration APIs */
36-
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
36+
require_once ABSPATH . 'wp-admin/includes/admin.php';
3737

3838
/** Load Ajax Handlers for WordPress Core */
39-
require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
39+
require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
4040

4141
send_nosniff_header();
4242
nocache_headers();

src/wp-admin/admin-functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
_deprecated_file( basename( __FILE__ ), '2.5.0', 'wp-admin/includes/admin.php' );
1313

1414
/** WordPress Administration API: Includes all Administration functions. */
15-
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
15+
require_once ABSPATH . 'wp-admin/includes/admin.php';

src/wp-admin/admin-header.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
1010
if ( ! defined( 'WP_ADMIN' ) ) {
11-
require_once( dirname( __FILE__ ) . '/admin.php' );
11+
require_once __DIR__ . '/admin.php';
1212
}
1313

1414
/**
@@ -233,7 +233,7 @@
233233
?>
234234

235235
<div id="wpwrap">
236-
<?php require( ABSPATH . 'wp-admin/menu-header.php' ); ?>
236+
<?php require ABSPATH . 'wp-admin/menu-header.php'; ?>
237237
<div id="wpcontent">
238238

239239
<?php
@@ -289,5 +289,5 @@
289289
do_action( 'all_admin_notices' );
290290

291291
if ( $parent_file == 'options-general.php' ) {
292-
require( ABSPATH . 'wp-admin/options-head.php' );
292+
require ABSPATH . 'wp-admin/options-head.php';
293293
}

src/wp-admin/admin-post.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
}
1515

1616
if ( defined( 'ABSPATH' ) ) {
17-
require_once( ABSPATH . 'wp-load.php' );
17+
require_once ABSPATH . 'wp-load.php';
1818
} else {
19-
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
19+
require_once dirname( __DIR__ ) . '/wp-load.php';
2020
}
2121

2222
/** Allow for cross-domain requests (from the front end). */
2323
send_origin_headers();
2424

25-
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
25+
require_once ABSPATH . 'wp-admin/includes/admin.php';
2626

2727
nocache_headers();
2828

0 commit comments

Comments
 (0)