Actually a pretty simple thing to accomplish, that I had a code snippet save for from a previous request for this.
function romanguro_earn_achievement_for_page_view_shortcode( $atts = array() ) {
$atts = shortcode_atts( array(
'achievement_id' => 0,
'user_id' => get_current_user_id()
), $atts );
badgeos_maybe_award_achievement_to_user( $atts['achievement_id'], $atts['user_id'] );
}
add_shortcode( 'romanguro_earn_achievement_for_page_view', 'romanguro_earn_achievement_for_page_view_shortcode' );
This will prevent the user from earning it multiple times, and to use it, simply place this in your page editor where you want to award it:
[romanguro_earn_achievement_for_page_view achievement_id="#"]
Replace the # with the actual ID of the achievement you want to award for it. Feel free to change the shortcode keyword or function names as necessary for your install. This would be something you put in a quick custom plugin or if anything your site’s functions.php file.
Thanks a lot:)
It works!
How can I put this shortcode into ‘Add BungeOS Shortcode’ menu button?
Since I had the code handy from what I copied it all from, I just turned it into its own quick plugin for you, and altered descriptions, textdomains, function names for you http://cl.ly/000h3b0M180s
Should match up to the previous snippets I provided, and add it to the popup as well.
That’s cool 🙂
Thanks:)))
but I think it’s should be in the next version of plugin, for sure.
What code would I use to award a badge? It is a survey completed outside of word press, so I thought I’d go with admin award? But I cannot figure out how to award the badge when they have completed the survey.
I would use either of these:
badgeos_award_achievement_to_user( $args[ 'achievement_id' ], $args[ 'user_id' ] );
badgeos_maybe_award_achievement_to_user( $args[ 'achievement_id' ], $args[ 'user_id' ] );
However you’re going to need both parameters, the ID of the achievement to award, and the user ID. I can’t say how you’re going to get those values, because I am not familiar with your setup.