BP_Signup::get( array $args = array() )
Fetch signups based on parameters.
Description
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. Default 'signup_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
(array)
- 'signups'
(array) Located signups. (IDs only iffields
is set toids
.) - 'total'
(int) Total number of signups matching params.
Source
File: bp-members/classes/class-bp-signup.php
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | 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 BuddyPress 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 BuddyPress 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
Version | Description |
---|---|
BuddyPress 2.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.