BBP_Admin::suggest_user()
Ajax action for facilitating the topic and reply author auto-suggest
Description Description
Source Source
File: includes/admin/classes/class-bbp-admin.php
public function suggest_user() {
// Bail early if no request
if ( empty( $_REQUEST['q'] ) ) {
wp_die( '0' );
}
// Bail if user cannot moderate - only moderators can change authorship
if ( ! current_user_can( 'moderate' ) ) {
wp_die( '0' );
}
// Check the ajax nonce
check_ajax_referer( 'bbp_suggest_user_nonce' );
// Try to get some users
$users_query = new WP_User_Query( array(
'search' => '*' . bbp_db()->esc_like( $_REQUEST['q'] ) . '*',
'fields' => array( 'ID', 'user_nicename' ),
'search_columns' => array( 'ID', 'user_nicename', 'user_email' ),
'orderby' => 'ID'
) );
// If we found some users, loop through and display them
if ( ! empty( $users_query->results ) ) {
foreach ( (array) $users_query->results as $user ) {
printf( esc_html__( '%s - %s', 'bbpress' ), bbp_get_user_id( $user->ID ), bbp_get_user_nicename( $user->ID, array( 'force' => $user->user_nicename ) ) . "\n" );
}
}
die();
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.4.0 | Introduced. |