Skip to content

Commit

Permalink
Hooks: Standardize naming of dynamic hooks using values derived from …
Browse files Browse the repository at this point in the history
…superglobals to use interpolation vs concatenation.

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

Props ramiy.
Fixes #42698.

Built from https://develop.svn.wordpress.org/trunk@42349


git-svn-id: http://core.svn.wordpress.org/trunk@42178 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
DrewAPicture committed Dec 1, 2017
1 parent 2164413 commit 36b3f17
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
18 changes: 10 additions & 8 deletions wp-admin/admin-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,36 +146,38 @@

add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );

$action = ( isset( $_REQUEST['action'] ) ) ? $_REQUEST['action'] : '';

if ( is_user_logged_in() ) {
// If no action is registered, return a Bad Request response.
if ( ! has_action( 'wp_ajax_' . $_REQUEST['action'] ) ) {
if ( ! has_action( "wp_ajax_{$action}" ) ) {
wp_die( '0', 400 );
}

/**
* Fires authenticated Ajax actions for logged-in users.
*
* The dynamic portion of the hook name, `$_REQUEST['action']`,
* refers to the name of the Ajax action callback being fired.
* The dynamic portion of the hook name, `$action`, refers
* to the name of the Ajax action callback being fired.
*
* @since 2.1.0
*/
do_action( 'wp_ajax_' . $_REQUEST['action'] );
do_action( "wp_ajax_{$action}" );
} else {
// If no action is registered, return a Bad Request response.
if ( ! has_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] ) ) {
if ( ! has_action( "wp_ajax_nopriv_{$action}" ) ) {
wp_die( '0', 400 );
}

/**
* Fires non-authenticated Ajax actions for logged-out users.
*
* The dynamic portion of the hook name, `$_REQUEST['action']`,
* refers to the name of the Ajax action callback being fired.
* The dynamic portion of the hook name, `$action`, refers
* to the name of the Ajax action callback being fired.
*
* @since 2.8.0
*/
do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
do_action( "wp_ajax_nopriv_{$action}" );
}
// Default status
wp_die( '0' );
8 changes: 5 additions & 3 deletions wp-admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,15 @@
}

if ( ! empty( $_REQUEST['action'] ) ) {
$action = $_REQUEST['action'];

/**
* Fires when an 'action' request variable is sent.
*
* The dynamic portion of the hook name, `$_REQUEST['action']`,
* refers to the action derived from the `GET` or `POST` request.
* The dynamic portion of the hook name, `$action`, refers to
* the action derived from the `GET` or `POST` request.
*
* @since 2.6.0
*/
do_action( 'admin_action_' . $_REQUEST['action'] );
do_action( "admin_action_{$action}" );
}
10 changes: 6 additions & 4 deletions wp-admin/network/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
/** Load WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );

if ( empty( $_GET['action'] ) ) {
$action = ( isset( $_GET['action'] ) ) ? $_GET['action'] : '';

if ( empty( $action ) ) {
wp_redirect( network_admin_url() );
exit;
}
Expand All @@ -28,12 +30,12 @@
/**
* Fires the requested handler action.
*
* The dynamic portion of the hook name, `$_GET['action']`, refers to the name
* of the requested action.
* The dynamic portion of the hook name, `$action`, refers to the name
* of the requested action derived from the `GET` request.
*
* @since 3.1.0
*/
do_action( 'network_admin_edit_' . $_GET['action'] );
do_action( "network_admin_edit_{$action}" );

wp_redirect( network_admin_url() );
exit();
12 changes: 7 additions & 5 deletions wp-admin/network/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@

$msg = '';
if ( isset( $_GET['updated'] ) ) {
switch ( $_GET['updated'] ) {
$action = $_GET['updated'];

switch ( $action ) {
case 'all_notspam':
$msg = __( 'Sites removed from spam.' );
break;
Expand Down Expand Up @@ -314,16 +316,16 @@
break;
default:
/**
* Filters a specific, non-default site-updated message in the Network admin.
* Filters a specific, non-default, site-updated message in the Network admin.
*
* The dynamic portion of the hook name, `$_GET['updated']`, refers to the
* non-default site update action.
* The dynamic portion of the hook name, `$action`, refers to the non-default
* site update action.
*
* @since 3.1.0
*
* @param string $msg The update message. Default 'Settings saved'.
*/
$msg = apply_filters( 'network_sites_updated_message_' . $_GET['updated'], __( 'Settings saved.' ) );
$msg = apply_filters( "network_sites_updated_message_{$action}", __( 'Settings saved.' ) );
break;
}

Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-42348';
$wp_version = '5.0-alpha-42349';

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

0 comments on commit 36b3f17

Please sign in to comment.