WordPress.org

Forums

BadgeOS
[resolved] Action for Viewing a Post or Page? (4 posts)

  1. Christian Freeman (codelion)
    Member
    Posted 10 months ago #

    Hello,

    I just switched from WP-Achievements to BadgeOS recently and I noticed that BadgeOS doesn't have a trigger for when a user views a specific post or page, or even if they view any post or page. Both WP-Achievements and MyCRED have triggers for this, andI'm wondering why BadgeOS doesn't?

    I'm building an entire gaming system on my site and this basic wordpress function is VERY important to my setup. Do you know how this could be added to your system?

    https://wordpress.org/plugins/badgeos/

  2. Michael Beckwith
    Member
    Plugin Author

    Posted 10 months ago #

    hi takinglife2themax,

    I wasn't around for the original development of the plugin, so I can't say for certain why it was excluded as a default trigger.

    Getting it into the core plugin by default would take some development work and probably wouldn't be officially released until version 1.5, and I'm not sure at the moment when that is intended to be.

    Try this out, but note I haven't tested it myself. It's a shortcode that will have attributes of achievement ID and user ID. Achievement ID defaults to zero if none provided, and the current user ID if none provided. The only part you should need to provide is the achievement ID. Just place it in the post content of the post/page you want, provide the achievement ID you want to award for it, and it'll check to see if the user deserves it, awarding if they do, once they view the post in question.

    function tothemax_award_upon_viewing( $atts ) {
    
    	$atts = shortcode_atts( array(
    		'achievement_id' => 0,
    		'user' => get_current_user_id()
    	), $atts );
    
    	badgeos_maybe_award_achievement_to_user( $atts['achievement_id'], $atts['user'] );
    }
    add_shortcode( 'award_achievement_upon_viewing', 'tothemax_award_upon_viewing' );

    Let me know if this works out for you.

  3. Christian Freeman (codelion)
    Member
    Posted 9 months ago #

    Understood.

    I would like to contribute some code to extend the BOS trigger options, so once I fully understand how the pieces fit together, I'll let you know what I come up with.

    Thanks for the shortcode mod function. I set up a new admin-only awarded achievement and MyCRED gave the test user the points. But on the Achievements tab on the Buddypress profile, it doesn't show the achievement. But I did see that the user received the achievement in wp-admin for that user's profile.

    So it does work, but it doesn't show up on the Buddypress profile's achievements tab. Is this because I set it to Admin-awarded only? And if so, which setting would be best to use instead?

  4. Michael Beckwith
    Member
    Plugin Author

    Posted 9 months ago #

    If you go and edit the achievement type for this achievement, do you have it checked to "Profile Achievements: Display earned achievements of this type in the user profile "Achievements" section."

Reply

You must log in to post.

About this Plugin

  • BadgeOS
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic