BP_Signup::get( array $args = array() )
Fetch signups based on parameters.
Description Description
Parameters Parameters
- $args
-
(Optional) The argument to retrieve desired signups.
- 'offset'
(int) Offset amount. Default 0. - 'number'
(int) How many to fetch. Default 1. - 'usersearch'
(bool|string) Whether or not to search for a username. Default false. - 'orderby'
(string) Order By parameter. Possible values aresignup_id,login,email,registered,activated. Defaultsignup_id. - 'order'
(string) Order direction. Default 'DESC'. - 'include'
(bool) Whether or not to include more specific query params. - 'activation_key'
(string) Activation key to search for. - 'user_login'
(string) Specific user login to return. - 'fields'
(string) Which fields to return. Specify 'ids' to fetch a list of signups IDs. Default: 'all' (return BP_Signup objects).
Default value: array()
- 'offset'
Return Return
(array)
- 'signups'
(array) Located signups. (IDs only iffieldsis set toids.) - 'total'
(int) Total number of signups matching params.
Source Source
File: bp-members/classes/class-bp-signup.php
public static function get( $args = array() ) {
global $wpdb;
$r = bp_parse_args( $args,
array(
'offset' => 0,
'number' => 1,
'usersearch' => false,
'orderby' => 'signup_id',
'order' => 'DESC',
'include' => false,
'activation_key' => '',
'user_login' => '',
'fields' => 'all',
),
'bp_core_signups_get_args'
);
// @todo whitelist sanitization
if ( $r['orderby'] !== 'signup_id' ) {
$r['orderby'] = 'user_' . $r['orderby'];
}
$r['orderby'] = sanitize_title( $r['orderby'] );
$sql = array();
$signups_table = buddypress()->members->table_name_signups;
$sql['select'] = "SELECT * FROM {$signups_table}";
$sql['where'] = array();
$sql['where'][] = "active = 0";
if ( empty( $r['include'] ) ) {
// Search terms.
if ( ! empty( $r['usersearch'] ) ) {
$search_terms_like = '%' . bp_esc_like( $r['usersearch'] ) . '%';
$sql['where'][] = $wpdb->prepare( "( user_login LIKE %s OR user_email LIKE %s OR meta LIKE %s )", $search_terms_like, $search_terms_like, $search_terms_like );
}
// Activation key.
if ( ! empty( $r['activation_key'] ) ) {
$sql['where'][] = $wpdb->prepare( "activation_key = %s", $r['activation_key'] );
}
// User login.
if ( ! empty( $r['user_login'] ) ) {
$sql['where'][] = $wpdb->prepare( "user_login = %s", $r['user_login'] );
}
$sql['orderby'] = "ORDER BY {$r['orderby']}";
$sql['order'] = bp_esc_sql_order( $r['order'] );
$sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", $r['offset'], $r['number'] );
} else {
$in = implode( ',', wp_parse_id_list( $r['include'] ) );
$sql['in'] = "AND signup_id IN ({$in})";
}
// Implode WHERE clauses.
$sql['where'] = 'WHERE ' . implode( ' AND ', $sql['where'] );
/**
* Filters the Signups paged query.
*
* @since 2.0.0
*
* @param string $value SQL statement.
* @param array $sql Array of SQL statement parts.
* @param array $args Array of original arguments for get() method.
* @param array $r Array of parsed arguments for get() method.
*/
$paged_signups = $wpdb->get_results( apply_filters( 'bp_members_signups_paged_query', join( ' ', $sql ), $sql, $args, $r ) );
if ( empty( $paged_signups ) ) {
return array( 'signups' => false, 'total' => false );
}
// We only want the IDs.
if ( 'ids' === $r['fields'] ) {
$paged_signups = wp_list_pluck( $paged_signups, 'signup_id' );
} else {
// Used to calculate a diff between now & last
// time an activation link has been resent.
$now = current_time( 'timestamp', true );
foreach ( (array) $paged_signups as $key => $signup ) {
$signup->id = intval( $signup->signup_id );
$signup->meta = ! empty( $signup->meta ) ? maybe_unserialize( $signup->meta ) : false;
$signup->user_name = '';
if ( ! empty( $signup->meta['field_1'] ) ) {
$signup->user_name = wp_unslash( $signup->meta['field_1'] );
}
// Sent date defaults to date of registration.
if ( ! empty( $signup->meta['sent_date'] ) ) {
$signup->date_sent = $signup->meta['sent_date'];
} else {
$signup->date_sent = $signup->registered;
}
$sent_at = mysql2date('U', $signup->date_sent );
$diff = $now - $sent_at;
/**
* Add a boolean in case the last time an activation link
* has been sent happened less than a day ago.
*/
if ( $diff < 1 * DAY_IN_SECONDS ) {
$signup->recently_sent = true;
}
if ( ! empty( $signup->meta['count_sent'] ) ) {
$signup->count_sent = absint( $signup->meta['count_sent'] );
} else {
$signup->count_sent = 1;
}
$paged_signups[ $key ] = $signup;
}
}
unset( $sql['limit'] );
$sql['select'] = preg_replace( "/SELECT.*?FROM/", "SELECT COUNT(*) FROM", $sql['select'] );
/**
* Filters the Signups count query.
*
* @since 2.0.0
*
* @param string $value SQL statement.
* @param array $sql Array of SQL statement parts.
* @param array $args Array of original arguments for get() method.
* @param array $r Array of parsed arguments for get() method.
*/
$total_signups = $wpdb->get_var( apply_filters( 'bp_members_signups_count_query', join( ' ', $sql ), $sql, $args, $r ) );
return array( 'signups' => $paged_signups, 'total' => $total_signups );
}
Changelog Changelog
| Version | Description |
|---|---|
| 6.0.0 | Added a list of allowed orderby parameters. |
| 2.0.0 | Introduced. |