Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Last active October 2, 2017 08:23
Show Gist options
  • Save X-Raym/c4da3f94c910cbbb39cb to your computer and use it in GitHub Desktop.
Save X-Raym/c4da3f94c910cbbb39cb to your computer and use it in GitHub Desktop.
An add-on for Badgeos to display a pop-up when a user earn an achievement.
<?php
/* STEP 1 : DISPLAY A SIMPLE MODAL WINDOW JAVASCRIPT ALERT WHEN AN ACHIEVEMENT IS EARNED */
// Function for in wp_head : the javascript alert
function custom_badgeos_java_alert() {
$output='<script> alert("Bravo ! tu as gagné un badge !"); </script>';
echo $output;
}
// Function to be called when the user get an achievement
function custom_badgeos_award_popup_test ( $user_id, $achievement_id ) {
//VARIABLES (not useful at this time)
// Grab the current user ID
$user_id = wp_get_current_user()->ID;
// Grab the current post ID if no achievement_id was specified
if ( ! $achievement_id ) {
global $post;
$achievement_id = $post->ID;
}
// call the pop_up in wp_head
add_action('wp_head','custom_badgeos_java_alert');
}
// call master function
add_action( 'badgeos_award_achievement', 'custom_badgeos_award_popup_test', 10, 2);
?>
@jurijc
Copy link

jurijc commented Jan 21, 2015

hey! have You managed it working?

@X-Raym
Copy link
Author

X-Raym commented Jan 24, 2015

Nope ! I use the dedicated plugin :)

@jurijc
Copy link

jurijc commented Feb 7, 2015

sad it's sooo expansive for such esential functionality

@IvanciniGT
Copy link

Try to replace line 27 this way:
add_action('wp_footer','custom_badgeos_java_alert');
Hope this helps ;)

@X-Raym
Copy link
Author

X-Raym commented Nov 22, 2016

@IvanciniGT
This is nice to you :P
but this was a reallly raw test, the logic isn't even complete ^^
I don't plan to fix it as there is an official add-on now.

@baveersd
Copy link

baveersd commented Oct 2, 2017

Hi,

Does this work? Where would you input that script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment