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:
Scott Taylor
2015-09-11 21:07:45 +00:00
parent 9805723e3d
commit 33953cb392
12 changed files with 44 additions and 16 deletions
+23
View File
@@ -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'];
}