Awarding Badges in Bulk
-
We’ve been tinkering with trying to grant admin-awarded badges in bulk through the WP Users screen
Started by repurposing a function for adding users to BuddyPress groups in bulk; that code can be found here.
Here is what we came up with:
function add_achievements_to_users() { if( isset( $_GET['action'] ) && isset( $_GET['achievement_id'] ) && isset( $_GET['users'] ) ) { $achievement_id = $_GET['achievement_id']; $users = $_GET['users']; foreach ( $users as $user_id ) { badgeos_award_achievement_to_user($achievement_id, $user_id); } } //form submission add_action( 'admin_footer', function() { ?> <script type="text/javascript" charset="utf-8"> jQuery("select[name='action']").append(jQuery('<option value="awardachievement">Award Achievement</option>')); jQuery("#doaction").click(function(e){ if(jQuery("select[name='action'] :selected").val()=="awardachievement") { e.preventDefault(); achievementid=prompt("Enter an Achievement ID","1"); jQuery(".wrap form").append('<input type="hidden" name="achievement_id" value="'+achievementid+'" />').submit(); } }); </script> <?php }); } add_action ( 'load-users.php', 'add_achievements_to_users' );
The problem is that the badge is awarded twice (we think, but aren’t sure because all our badges can only be earned once). However, 2 activity feed items are created.
Anyone have any thoughts on what’s going on?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Awarding Badges in Bulk’ is closed to new replies.