Skip to content

Commit

Permalink
Coding Standards: Replace include_once with require_once for requ…
Browse files Browse the repository at this point in the history
…ired files.

Per [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#writing-include-require-statements WordPress PHP coding standards], it is ''strongly recommended'' to use `require[_once]` for unconditional includes. When using `include[_once]`, PHP will throw a warning when the file is not found but will continue execution, which will almost certainly lead to other errors/warnings/notices being thrown if your application depends on the file loaded, potentially leading to security leaks. For that reason, `require[_once]` is generally the better choice as it will throw a `Fatal Error` if the file cannot be found.

Follow-up to [1674], [1812], [1964], [6779], [8540], [10521], [11005], [11911], [16065], [16149], [25421], [25466], [25823], [37714], [42981], [45448], [47198], [54276], [55633].

Props kausaralm, SergeyBiryukov.
See #57839.
Built from https://develop.svn.wordpress.org/trunk@55641


git-svn-id: http://core.svn.wordpress.org/trunk@55153 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
SergeyBiryukov committed Apr 9, 2023
1 parent 2193d75 commit 0008d8d
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function wp_ajax_imgedit_preview() {

check_ajax_referer( "image_editor-$post_id" );

include_once ABSPATH . 'wp-admin/includes/image-edit.php';
require_once ABSPATH . 'wp-admin/includes/image-edit.php';

if ( ! stream_preview_image( $post_id ) ) {
wp_die( -1 );
Expand Down Expand Up @@ -2649,7 +2649,7 @@ function wp_ajax_image_editor() {
}

check_ajax_referer( "image_editor-$attachment_id" );
include_once ABSPATH . 'wp-admin/includes/image-edit.php';
require_once ABSPATH . 'wp-admin/includes/image-edit.php';

$msg = false;

Expand Down Expand Up @@ -4157,7 +4157,7 @@ function wp_ajax_install_theme() {
}

require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/theme.php';
require_once ABSPATH . 'wp-admin/includes/theme.php';

$api = themes_api(
'theme_information',
Expand Down Expand Up @@ -4402,7 +4402,7 @@ function wp_ajax_delete_theme() {
wp_send_json_error( $status );
}

include_once ABSPATH . 'wp-admin/includes/theme.php';
require_once ABSPATH . 'wp-admin/includes/theme.php';

$result = delete_theme( $stylesheet );

Expand Down Expand Up @@ -4450,7 +4450,7 @@ function wp_ajax_install_plugin() {
}

require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';

$api = plugins_api(
'plugin_information',
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/includes/class-wp-filesystem-ftpsockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct( $opt = '' ) {
$this->errors = new WP_Error();

// Check if possible to use ftp functions.
if ( ! include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) {
if ( ! require_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion wp-admin/includes/class-wp-plugin-install-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function get_installed_plugin_slugs() {
* @global string $term
*/
public function prepare_items() {
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';

global $tabs, $tab, $paged, $type, $term;

Expand Down
2 changes: 1 addition & 1 deletion wp-admin/includes/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function wp_install_defaults( $user_id ) {
$privacy_policy_content = get_site_option( 'default_privacy_policy_content' );
} else {
if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
include_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
}

$privacy_policy_content = WP_Privacy_Policy_Content::get_default_content();
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/privacy-policy-guide.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
include_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
}

// Used in the HTML title tag.
Expand Down
4 changes: 2 additions & 2 deletions wp-admin/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
}

include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api().
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api().

check_admin_referer( 'install-plugin_' . $plugin );
$api = plugins_api(
Expand Down Expand Up @@ -258,7 +258,7 @@
wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
}

include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // For themes_api().
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // For themes_api().

check_admin_referer( 'install-theme_' . $theme );
$api = themes_api(
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
*/
static $core_blocks_meta;
if ( ! $core_blocks_meta ) {
$core_blocks_meta = include_once ABSPATH . WPINC . '/blocks/blocks-json.php';
$core_blocks_meta = require_once ABSPATH . WPINC . '/blocks/blocks-json.php';
}

$metadata_file = ( ! str_ends_with( $file_or_folder, 'block.json' ) ) ?
Expand Down
8 changes: 4 additions & 4 deletions wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3051,8 +3051,8 @@ function generic_ping( $post_id = 0 ) {
* @param int|WP_Post $post Post ID or object.
*/
function pingback( $content, $post ) {
include_once ABSPATH . WPINC . '/class-IXR.php';
include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
require_once ABSPATH . WPINC . '/class-IXR.php';
require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';

// Original code by Mort (http://mort.mine.nu:8080).
$post_links = array();
Expand Down Expand Up @@ -3218,8 +3218,8 @@ function trackback( $trackback_url, $title, $excerpt, $ID ) {
* @param string $path Path to send the ping.
*/
function weblog_ping( $server = '', $path = '' ) {
include_once ABSPATH . WPINC . '/class-IXR.php';
include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
require_once ABSPATH . WPINC . '/class-IXR.php';
require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';

// Using a timeout of 3 seconds should be enough to cover slow servers.
$client = new WP_HTTP_IXR_Client( $server, ( ( ! strlen( trim( $path ) ) || ( '/' === $path ) ) ? false : $path ) );
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ function spawn_cron( $gmt_time = 0 ) {
wp_ob_end_flush_all();
flush();

include_once ABSPATH . 'wp-cron.php';
require_once ABSPATH . 'wp-cron.php';
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ function do_enclose( $content, $post ) {
global $wpdb;

// @todo Tidy this code and make the debug code optional.
include_once ABSPATH . WPINC . '/class-IXR.php';
require_once ABSPATH . WPINC . '/class-IXR.php';

$post = get_post( $post );
if ( ! $post ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ function wp_update_themes( $extra_stats = array() ) {
* @since 3.7.0
*/
function wp_maybe_auto_update() {
include_once ABSPATH . 'wp-admin/includes/admin.php';
require_once ABSPATH . 'wp-admin/includes/admin.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

$upgrader = new WP_Automatic_Updater();
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-55637';
$wp_version = '6.3-alpha-55641';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 0008d8d

Please sign in to comment.