Make WordPress Core

Changeset 55641


Ignore:
Timestamp:
04/09/2023 11:55:37 AM (19 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Replace include_once with require_once for required files.

Per 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.

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r55474 r55641  
    246246    check_ajax_referer( "image_editor-$post_id" );
    247247
    248     include_once ABSPATH . 'wp-admin/includes/image-edit.php';
     248    require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    249249
    250250    if ( ! stream_preview_image( $post_id ) ) {
     
    26502650
    26512651    check_ajax_referer( "image_editor-$attachment_id" );
    2652     include_once ABSPATH . 'wp-admin/includes/image-edit.php';
     2652    require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    26532653
    26542654    $msg = false;
     
    41584158
    41594159    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    4160     include_once ABSPATH . 'wp-admin/includes/theme.php';
     4160    require_once ABSPATH . 'wp-admin/includes/theme.php';
    41614161
    41624162    $api = themes_api(
     
    44034403    }
    44044404
    4405     include_once ABSPATH . 'wp-admin/includes/theme.php';
     4405    require_once ABSPATH . 'wp-admin/includes/theme.php';
    44064406
    44074407    $result = delete_theme( $stylesheet );
     
    44514451
    44524452    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    4453     include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     4453    require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
    44544454
    44554455    $api = plugins_api(
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r55556 r55641  
    3434
    3535        // Check if possible to use ftp functions.
    36         if ( ! include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) {
     36        if ( ! require_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) {
    3737            return;
    3838        }
  • trunk/src/wp-admin/includes/class-wp-plugin-install-list-table.php

    r54378 r55641  
    8989     */
    9090    public function prepare_items() {
    91         include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     91        require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
    9292
    9393        global $tabs, $tab, $paged, $type, $term;
  • trunk/src/wp-admin/includes/upgrade.php

    r55212 r55641  
    352352        } else {
    353353            if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
    354                 include_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
     354                require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
    355355            }
    356356
  • trunk/src/wp-admin/privacy-policy-guide.php

    r55263 r55641  
    1515
    1616if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
    17     include_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
     17    require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
    1818}
    1919
  • trunk/src/wp-admin/update.php

    r51475 r55641  
    108108        }
    109109
    110         include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api().
     110        require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // For plugins_api().
    111111
    112112        check_admin_referer( 'install-plugin_' . $plugin );
     
    259259        }
    260260
    261         include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // For themes_api().
     261        require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // For themes_api().
    262262
    263263        check_admin_referer( 'install-theme_' . $theme );
  • trunk/src/wp-includes/blocks.php

    r55547 r55641  
    319319    static $core_blocks_meta;
    320320    if ( ! $core_blocks_meta ) {
    321         $core_blocks_meta = include_once ABSPATH . WPINC . '/blocks/blocks-json.php';
     321        $core_blocks_meta = require_once ABSPATH . WPINC . '/blocks/blocks-json.php';
    322322    }
    323323
  • trunk/src/wp-includes/comment.php

    r55526 r55641  
    30523052 */
    30533053function pingback( $content, $post ) {
    3054     include_once ABSPATH . WPINC . '/class-IXR.php';
    3055     include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
     3054    require_once ABSPATH . WPINC . '/class-IXR.php';
     3055    require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    30563056
    30573057    // Original code by Mort (http://mort.mine.nu:8080).
     
    32193219 */
    32203220function weblog_ping( $server = '', $path = '' ) {
    3221     include_once ABSPATH . WPINC . '/class-IXR.php';
    3222     include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
     3221    require_once ABSPATH . WPINC . '/class-IXR.php';
     3222    require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    32233223
    32243224    // Using a timeout of 3 seconds should be enough to cover slow servers.
  • trunk/src/wp-includes/cron.php

    r55293 r55641  
    884884        flush();
    885885
    886         include_once ABSPATH . 'wp-cron.php';
     886        require_once ABSPATH . 'wp-cron.php';
    887887        return true;
    888888    }
  • trunk/src/wp-includes/functions.php

    r55598 r55641  
    883883
    884884    // @todo Tidy this code and make the debug code optional.
    885     include_once ABSPATH . WPINC . '/class-IXR.php';
     885    require_once ABSPATH . WPINC . '/class-IXR.php';
    886886
    887887    $post = get_post( $post );
  • trunk/src/wp-includes/update.php

    r54891 r55641  
    844844 */
    845845function wp_maybe_auto_update() {
    846     include_once ABSPATH . 'wp-admin/includes/admin.php';
     846    require_once ABSPATH . 'wp-admin/includes/admin.php';
    847847    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    848848
Note: See TracChangeset for help on using the changeset viewer.