Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Register Custom Reference
- * This will allow us to create a badge for Founders
- * @version 1.0
- */
- add_filter( 'mycred_all_references', 'mycred_pro_add_custom_ref' );
- function mycred_pro_add_custom_ref( $references ) {
- $references['founder'] = 'Founder';
- return $references;
- }
- /**
- * Assign Custom Badge
- * Intercepting the Assign Badge AJAX call, we check
- * if this is our custom badge, and if it is, assign it to
- * all subscribers.
- * @version 1.1
- */
- add_action( 'wp_ajax_mycred-assign-badge', 'mycred_pro_assign_custom_badge', 1 );
- function mycred_pro_assign_custom_badge() {
- check_ajax_referer( 'mycred-assign-badge', 'token' );
- $badge_id = absint( $_POST['badge_id'] );
- $requirements = mycred_get_badge_requirements( $badge_id );
- if ( ! empty( $requirements ) ) {
- $count = 0;
- foreach ( $requirements as $level => $needs ) {
- if ( isset( $needs['reference'] ) && $needs['reference'] == 'founder' ) {
- // Get all subscribers
- $users = get_users( array(
- 'role' => 'subscriber',
- 'fields' => array( 'ID' )
- ) );
- // If we have users loop through and award this badge to the users
- if ( ! empty( $users ) ) {
- foreach ( $users as $user ) {
- mycred_update_user_meta( $user->ID, 'mycred_badge' . $badge_id, '', 1 );
- $count ++;
- }
- }
- // No need to loop
- break;
- }
- }
- if ( $count > 0 )
- wp_send_json_success( sprintf( '%d Users earned the founder badge.', count( $count ) ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement