On this page
wp_ajax_save_wporg_username()
Ajax handler for saving the user’s WordPress.org username.
Source
File: wp-admin/includes/ajax-actions.php. View all references
function wp_ajax_save_wporg_username() {
if ( ! current_user_can( 'install_themes' ) && ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error();
}
check_ajax_referer( 'save_wporg_username_' . get_current_user_id() );
$username = isset( $_REQUEST['username'] ) ? wp_unslash( $_REQUEST['username'] ) : false;
if ( ! $username ) {
wp_send_json_error();
}
wp_send_json_success( update_user_meta( get_current_user_id(), 'wporg_favorites', $username ) );
}
Related
Uses
| Uses | Description |
|---|---|
| update_user_meta() wp-includes/user.php | Updates user meta field based on user ID. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| wp_unslash() wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. |
| check_ajax_referer() wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. |
| wp_send_json_error() wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating failure. |
| wp_send_json_success() wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating success. |
| get_current_user_id() wp-includes/user.php | Gets the current user’s ID. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_ajax_save_wporg_username