mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
Introduce wp_validate_action( $action = '' ), a helper function that checks $_REQUEST for action and returns it, or empty string if not present. If $action is passed, it checks to make sure they match before returning it, or an empty string. Strings are always returned to avoid returning multiple types.
Implementing this removes 27 uses of direct superglobal access in the admin. For more reading: https://codeclimate.com/github/WordPress/WordPress/wp-admin/edit-comments.php See #33837. git-svn-id: https://develop.svn.wordpress.org/trunk@34059 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -4980,3 +4980,26 @@ function wp_post_preview_js() {
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve and, optionally, validate, an `action` query var
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $action Optional. Action to validate.
|
||||
* @return string Empty string if there is no action in the request or it doesn't
|
||||
* match the passed `$action`. Returns the [passed `$action` or
|
||||
* request action on succcess.
|
||||
*/
|
||||
function wp_validate_action( $action = '' ) {
|
||||
$r = $_REQUEST;
|
||||
if ( ! isset( $r['action'] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( ! empty( $action ) ) {
|
||||
return $action === $r['action'] ? $action : '';
|
||||
}
|
||||
|
||||
return $r['action'];
|
||||
}
|
||||
Reference in New Issue
Block a user