Make WordPress Core


Ignore:
Timestamp:
12/22/2022 11:06:10 AM (22 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/template.php.

While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit renames the $require_once parameter to $load_once in:

  • locate_template()
  • load_template()

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960], [54961], [54962], [54964], [54965], [54969], [54970], [54971], [54972], [54996], [55000], [55011].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/template.php

    r54747 r55013  
    691691 * @param string|array $template_names Template file(s) to search for, in order.
    692692 * @param bool         $load           If true the template file will be loaded if it is found.
    693  * @param bool         $require_once   Whether to require_once or require. Has no effect if `$load` is false.
     693 * @param bool         $load_once      Whether to require_once or require. Has no effect if `$load` is false.
    694694 *                                     Default true.
    695695 * @param array        $args           Optional. Additional arguments passed to the template.
     
    697697 * @return string The template filename if one is located.
    698698 */
    699 function locate_template( $template_names, $load = false, $require_once = true, $args = array() ) {
     699function locate_template( $template_names, $load = false, $load_once = true, $args = array() ) {
    700700    $located = '';
    701701    foreach ( (array) $template_names as $template_name ) {
     
    716716
    717717    if ( $load && '' !== $located ) {
    718         load_template( $located, $require_once, $args );
     718        load_template( $located, $load_once, $args );
    719719    }
    720720
     
    745745 *
    746746 * @param string $_template_file Path to template file.
    747  * @param bool   $require_once   Whether to require_once or require. Default true.
     747 * @param bool   $load_once      Whether to require_once or require. Default true.
    748748 * @param array  $args           Optional. Additional arguments passed to the template.
    749749 *                               Default empty array.
    750750 */
    751 function load_template( $_template_file, $require_once = true, $args = array() ) {
     751function load_template( $_template_file, $load_once = true, $args = array() ) {
    752752    global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
    753753
     
    775775     *
    776776     * @param string $_template_file The full path to the template file.
    777      * @param bool   $require_once   Whether to require_once or require.
     777     * @param bool   $load_once      Whether to require_once or require.
    778778     * @param array  $args           Additional arguments passed to the template.
    779779     */
    780     do_action( 'wp_before_load_template', $_template_file, $require_once, $args );
    781 
    782     if ( $require_once ) {
     780    do_action( 'wp_before_load_template', $_template_file, $load_once, $args );
     781
     782    if ( $load_once ) {
    783783        require_once $_template_file;
    784784    } else {
     
    792792     *
    793793     * @param string $_template_file The full path to the template file.
    794      * @param bool   $require_once   Whether to require_once or require.
     794     * @param bool   $load_once      Whether to require_once or require.
    795795     * @param array  $args           Additional arguments passed to the template.
    796796     */
    797     do_action( 'wp_after_load_template', $_template_file, $require_once, $args );
    798 }
     797    do_action( 'wp_after_load_template', $_template_file, $load_once, $args );
     798}
Note: See TracChangeset for help on using the changeset viewer.