WordPress.org

Make WordPress Core

Changeset 42349


Ignore:
Timestamp:
12/01/2017 11:35:31 AM (3 years ago)
Author:
DrewAPicture
Message:

Hooks: Standardize naming of dynamic hooks using values derived from superglobals to use interpolation vs concatenation.

This is a continuation of the work that happened in [38307] for #37748.

Props ramiy.
Fixes #42698.

Location:
trunk/src/wp-admin
Files:
4 edited

Legend:

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

    r42343 r42349  
    147147add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );
    148148
     149$action = ( isset( $_REQUEST['action'] ) ) ? $_REQUEST['action'] : '';
     150
    149151if ( is_user_logged_in() ) {
    150152    // If no action is registered, return a Bad Request response.
    151     if ( ! has_action( 'wp_ajax_' . $_REQUEST['action'] ) ) {
     153    if ( ! has_action( "wp_ajax_{$action}" ) ) {
    152154        wp_die( '0', 400 );
    153155    }
     
    156158     * Fires authenticated Ajax actions for logged-in users.
    157159     *
    158      * The dynamic portion of the hook name, `$_REQUEST['action']`,
    159      * refers to the name of the Ajax action callback being fired.
     160     * The dynamic portion of the hook name, `$action`, refers
     161     * to the name of the Ajax action callback being fired.
    160162     *
    161163     * @since 2.1.0
    162164     */
    163     do_action( 'wp_ajax_' . $_REQUEST['action'] );
     165    do_action( "wp_ajax_{$action}" );
    164166} else {
    165167    // If no action is registered, return a Bad Request response.
    166     if ( ! has_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] ) ) {
     168    if ( ! has_action( "wp_ajax_nopriv_{$action}" ) ) {
    167169        wp_die( '0', 400 );
    168170    }
     
    171173     * Fires non-authenticated Ajax actions for logged-out users.
    172174     *
    173      * The dynamic portion of the hook name, `$_REQUEST['action']`,
    174      * refers to the name of the Ajax action callback being fired.
     175     * The dynamic portion of the hook name, `$action`, refers
     176     * to the name of the Ajax action callback being fired.
    175177     *
    176178     * @since 2.8.0
    177179     */
    178     do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
     180    do_action( "wp_ajax_nopriv_{$action}" );
    179181}
    180182// Default status
  • trunk/src/wp-admin/admin.php

    r42343 r42349  
    373373
    374374if ( ! empty( $_REQUEST['action'] ) ) {
     375    $action = $_REQUEST['action'];
     376
    375377    /**
    376378     * Fires when an 'action' request variable is sent.
    377379     *
    378      * The dynamic portion of the hook name, `$_REQUEST['action']`,
    379      * refers to the action derived from the `GET` or `POST` request.
     380     * The dynamic portion of the hook name, `$action`, refers to
     381     * the action derived from the `GET` or `POST` request.
    380382     *
    381383     * @since 2.6.0
    382384     */
    383     do_action( 'admin_action_' . $_REQUEST['action'] );
    384 }
     385    do_action( "admin_action_{$action}" );
     386}
  • trunk/src/wp-admin/network/edit.php

    r38657 r42349  
    1111require_once( dirname( __FILE__ ) . '/admin.php' );
    1212
    13 if ( empty( $_GET['action'] ) ) {
     13$action = ( isset( $_GET['action'] ) ) ? $_GET['action'] : '';
     14
     15if ( empty( $action ) ) {
    1416    wp_redirect( network_admin_url() );
    1517    exit;
     
    2931 * Fires the requested handler action.
    3032 *
    31  * The dynamic portion of the hook name, `$_GET['action']`, refers to the name
    32  * of the requested action.
     33 * The dynamic portion of the hook name, `$action`, refers to the name
     34 * of the requested action derived from the `GET` request.
    3335 *
    3436 * @since 3.1.0
    3537 */
    36 do_action( 'network_admin_edit_' . $_GET['action'] );
     38do_action( "network_admin_edit_{$action}" );
    3739
    3840wp_redirect( network_admin_url() );
  • trunk/src/wp-admin/network/sites.php

    r42343 r42349  
    279279$msg = '';
    280280if ( isset( $_GET['updated'] ) ) {
    281     switch ( $_GET['updated'] ) {
     281    $action = $_GET['updated'];
     282
     283    switch ( $action ) {
    282284        case 'all_notspam':
    283285            $msg = __( 'Sites removed from spam.' );
     
    315317        default:
    316318            /**
    317              * Filters a specific, non-default site-updated message in the Network admin.
    318              *
    319              * The dynamic portion of the hook name, `$_GET['updated']`, refers to the
    320              * non-default site update action.
     319             * Filters a specific, non-default, site-updated message in the Network admin.
     320             *
     321             * The dynamic portion of the hook name, `$action`, refers to the non-default
     322             * site update action.
    321323             *
    322324             * @since 3.1.0
     
    324326             * @param string $msg The update message. Default 'Settings saved'.
    325327             */
    326             $msg = apply_filters( 'network_sites_updated_message_' . $_GET['updated'], __( 'Settings saved.' ) );
     328            $msg = apply_filters( "network_sites_updated_message_{$action}", __( 'Settings saved.' ) );
    327329            break;
    328330    }
Note: See TracChangeset for help on using the changeset viewer.