WordPress.org

Ready to get started?Download WordPress

Forums

Achievements for WordPress
[resolved] [closed] Is there any badges system (24 posts)

  1. sdglhm
    Member
    Posted 1 year ago #

    Is there any badges system for this plugin. I've searched for it. But lost hopes. If there any, Please help me (BTW I love your plugin paul)

    http://wordpress.org/extend/plugins/achievements/

  2. Paul Gibbs
    BuddyPress Lead Developer
    Plugin Author

    Posted 1 year ago #

    There's a feature built-in that I call badges, but I don't know what you mean specifically by badges :) Let me know what you were thinking of!

  3. icepin
    Member
    Posted 1 year ago #

    I think he meant to append some kind of badges to user's profile (next to send private message or add friend, or in that area), which I am also looking for this :)

  4. sdglhm
    Member
    Posted 1 year ago #

    Yes, @icepin is correct. I mean that kind of badge system. If you got time @djpaul Please, We need that function. Thanks for your replies.

  5. Paul Gibbs
    BuddyPress Lead Developer
    Plugin Author

    Posted 1 year ago #

    Displaying badges in/around user comments, profile areas, and other similar places is on my to-do list. But some time away.

  6. mikebronner
    Member
    Posted 1 year ago #

    Do you guys think this should be the last achievement awarded to that user, or an achievement that can be assigned as their "badge", say with a checkmark on the user profile admin page?

    I'm thinking of doing something similar, but wanted to see what your thoughts were. In my case we will have achievements of type "rank", and we want to specify for each user what their rank is and display it on their profile.

  7. pmcvicker
    Member
    Posted 1 year ago #

    I think if we have some sort of achievement taxonomy in place, you'd want to show the last achievement earned within a chosen taxonomy. Could be levels, ranks, titles, etc.

    Without a taxonomy, I think the last badge earned is a good default.

  8. mikebronner
    Member
    Posted 1 year ago #

    I'll see what I can put together. Just as a disclaimer: all my work-arounds and how-tos are not officially endorsed by Paul, and may in fact lead to unintended consequences. On the plus side, Paul is kind enough to consider integration of those features that make sense to the goals of A4WP, so you might see them make it into the plugin over time.

    That being said: take a look at my How-To on implementing Achievement Categories: http://wordpress.org/support/topic/how-to-achievement-categories?replies=6. This should allow you to create the taxonomies you need. Be sure to read to the end to get all the updates in -- if Paul decides this isn't in-line with his current goals, I will eventually put this together as a plugin.

    Hopefully I can come up with a way to get badges to work with and without the categories functionality. I'll post back here when I get something. :) Fair warning: Paul did mention that he has something in mind, but it might be a ways off. Paul's solution will likely supersede mine once it is published.

  9. pmcvicker
    Member
    Posted 1 year ago #

    Thanks for the disclaimer Mike, and for your contributions.

    I'm working up a beta for my project to test internally in May/June, so even rough/buggy code is helpful to give my testers an idea of what kind of functionality might be possible, even if it gets reworked by you/Paul later.

  10. Paul Gibbs
    BuddyPress Lead Developer
    Plugin Author

    Posted 1 year ago #

    A4WP is such an awesome short name :)

  11. mikebronner
    Member
    Posted 1 year ago #

    Making some progress ... able to select and store badge. Next step is to retrieve selected badge and display it in comments. Code is still too rough to post, should have something tomorrow though.

    PS: Thanks, Paul! Glad you like it ... assumed it was already in use so didn't think anything of it. :) hehe

  12. sdglhm
    Member
    Posted 1 year ago #

    Cool. We all are waiting. Thanks for your replies

  13. mikebronner
    Member
    Posted 1 year ago #

    Quick status update before I call it a night:
    Completed Functionality so far:
    - can specify badge manually.
    - display badge next to page/post/comment author

    To Do:
    - select most recent achievement as badge from a specified category
    - In the absence of categories, select most recent overall achievement as badge
    - Show badge in profile

    I should definitely be able to get this done by tomorrow evening.

  14. icepin
    Member
    Posted 1 year ago #

    "[...]an achievement that can be assigned as their "badge", say with a checkmark on the user profile admin page"
    "In my case we will have achievements of type "rank", and we want to specify for each user what their rank is and display it on their profile."

    @mikebronner that, is exactly what I'm looking for. You are a hero! :)

  15. mikebronner
    Member
    Posted 1 year ago #

    OK, I'm almost there. The only thing not working is getting the latest achievement from a badge-enabled category (any help on how to construct a WP_QUERY to filter on custom taxonomy custom fields is appreciated!).

    Step 1: if you have used my achievements category "hack", be sure to remove the dpa_achievements_add_profile_fields_with_categories() from your functions.php file in your child-theme first.

    Step 2: add the following code to your functions.php:

    /* Group Achievements by Category in User Profile and Select Badge ************/
    	function dpa_achievements_add_profile_fields_with_categories($user)
    	{
    //		if (!is_super_admin()) {return;}
    		$uses_categories = function_exists(register_achievements_custom_taxonomy);
    ?>
    		<h3><?php _e( 'Achievements Settings', 'dpa' ); ?>test</h3>
    		<table class="form-table">
    			<tr>
    				<th><label for="dpa_achievements"><?php _ex( 'Total Points', "User’s total points from unlocked Achievements", 'dpa' ); ?></label></th>
    				<td><?php
    		if (is_super_admin())
    		{
    			?><input type="number" name="dpa_achievements" id="dpa_achievements" value="<?php
    		}
    		echo esc_attr( (int)dpa_get_user_points( $user->ID ) );
    		if (is_super_admin())
    		{
    			?>" class="regular-text" /><?php
    		}
    ?>
    				</td>
    			</tr>
    <?php
    		if ( dpa_has_achievements( array( 'ach_populate_progress' => $user->ID, 'ach_progress_status' => dpa_get_unlocked_status_id(), 'posts_per_page' => -1, "orderby"=>"konb_term_relationships.term_taxonomy_id",) ) )
    		{
    ?>
    			<tr>
    				<th scope="row"><?php _e( 'Unlocked Achievements', 'dpa' ); ?></th>
    				<td>
    					<span class="description"><?php
    			if (is_super_admin())
    			{
    				_e('Award achievements through checking the appropriate checkboxes.', 'dpa') . " ";
    			}
    			_e('Use the radio button to choose your badge.', 'dpa'); ?></span>
    					<fieldset>
    						<legend class="screen-reader-text"><?php _e( 'Assign or remove achievements from this user', 'dpa' ); ?></legend>
    <?php
    			$previous_achievment_category = "";
    			while ( dpa_achievements() )
    			{
    				dpa_the_achievement();
    				if ($uses_categories)
    				{
    					$current_category = "";
    					$categories = get_the_terms($post_id, 'dpa_achievement_category');
    					foreach($categories as $category)
    					{
    						if (strlen($current_category) > 0)
    						{
    							$current_category .= ", ";
    						}
    						$current_category .= $category->name;
    					}
    
    					if ($current_category != $previous_achievment_category)
    					{
    						if ($previous_achievment_category != "")
    						{
    ?>
    						<br />
    <?php
    						}
    						$previous_achievment_category = $current_category;
    ?>
    
    						<strong><?php echo $current_category; ?>:</strong><br />
    <?php
    					}
    				}
    				if (dpa_is_achievement_unlocked() || is_super_admin())
    				{
    					if (!is_super_admin())
    					{
    ?>
    						<label>
    <?php
    					}
    ?>
    						<input type="radio" name="dpa_user_achievement_badge" id="dpa_achievement_badge_<?php echo dpa_get_the_achievement_ID(); ?>" value="<?php echo esc_attr( dpa_get_the_achievement_ID() ); ?>" <?php disabled( !dpa_is_achievement_unlocked(), true ); ?> <?php checked((int)get_user_option( '_dpa_user_achievement_badge', $user->ID ), (int)dpa_get_the_achievement_ID()); ?> title="<?php _ex( 'Set Profile Badge', "Select unlocked achievement as profile badge.", 'dpa' ); ?>" />
    <?php
    					if (is_super_admin())
    					{
    ?>
    						<label>
    							<input type="checkbox" name="dpa_user_achievements[]" value="<?php echo esc_attr( dpa_get_the_achievement_ID() ); ?>" <?php checked( dpa_is_achievement_unlocked(), true ); ?> onchange="document.getElementById('dpa_achievement_badge_<?php echo dpa_get_the_achievement_ID(); ?>').disabled = !this.checked; if (document.getElementById('dpa_achievement_badge_<?php echo dpa_get_the_achievement_ID(); ?>').disabled) {document.getElementById('dpa_achievement_badge_<?php echo dpa_get_the_achievement_ID(); ?>').checked = false;}">
    <?php
    					}
    ?>
    							<?php dpa_achievement_title(); ?>
    						</label>
    						<br />
    <?php
    				}
    			}
    ?>
    
    					</fieldset>
    				</td>
    			</tr>
    <?php
    		}
    ?>
    		</table>
    <?php
    		remove_action('edit_user_profile', array(achievements()->admin, 'add_profile_fields'));
    		remove_action('show_user_profile', array(achievements()->admin, 'add_profile_fields'));
    	}
    	add_action('edit_user_profile', 'dpa_achievements_add_profile_fields_with_categories', 9);
    	add_action('show_user_profile', 'dpa_achievements_add_profile_fields_with_categories', 9);
    
    /* Save Achievement Badge on User Profile Admin *******************************/
    	function dpa_achievement_badge_save($user_id)
    	{
    		$saved = false;
    		if ( empty( $user_id ) && is_user_logged_in() )
    		{
    			$user_id = get_current_user_id();
    		}
    		if ( empty( $user_id ) ) {return false;}
    		if ( current_user_can( 'edit_user', $user_id ) )
    		{
    			// As Achievements can run independently (as well as sitewide) on a multisite, decide where to store the user option
    			$store_global = is_multisite() && dpa_is_running_networkwide();
    			$new_value = apply_filters( 'dpa_update_user_points', $_POST['dpa_user_achievement_badge'], $user_id );
    			update_user_option( $user_id, '_dpa_user_achievement_badge', $new_value, $store_global );
    			$saved = true;
    		}
    
    		return true;
    	}
    	add_action( 'personal_options_update', 'dpa_achievement_badge_save' );
    	add_action( 'edit_user_profile_update', 'dpa_achievement_badge_save' );
    
    /* Show Achievement Badge on Comments *****************************************/
    	function dpa_achievement_comment_with_badge($comment, $args, $depth)
    	{
    		$GLOBALS['comment'] = $comment;
    		extract($args, EXTR_SKIP);
    		if ( 'div' == $args['style'] )
    		{
    			$tag = 'div';
    			$add_below = 'comment';
    		}
    		else
    		{
    			$tag = 'li';
    			$add_below = 'div-comment';
    		}
    ?>
    		<<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
    <?php
    		if ( 'div' != $args['style'] )
    		{
    ?>
    	<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
    <?php
    		}
    ?>
    		<div class="comment-author vcard">
    			<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
    			<?php echo get_the_post_thumbnail( get_user_option('_dpa_user_achievement_badge', get_comment(get_comment_ID())->user_id), array(39, 39)); ?>
    			<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
    		</div>
    <?php
    		if ($comment->comment_approved == '0')
    		{
    ?>
    		<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
    		<br />
    <?php
    		}
    ?>
    		<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
    			<?php printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','' ); ?>
    		</div>
    			<?php comment_text(); ?>
    		<div class="reply">
    			<?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
    		</div>
    <?php
    		if ( 'div' != $args['style'] )
    		{
    ?>
    	</div>
    <?php
    		}
    	}
    
    /* Configure Achievement Categories to Support Badges *************************/
    	function dpa_achievement_category_with_badge_add()
    	{
    ?>
    	<div class="form-field">
    		<label for="term_meta[dpa_achievement_category_for_badge]"><?php _e('Badge-Enabled?', 'dpa'); ?></label>
    		<input type="checkbox" name="term_meta[dpa_achievement_category_for_badge]" id="term_meta[dpa_achievement_category_for_badge]" value="1" />
    		<p class="description"><?php _e('Should this category be used to determine user badges? If the user has no badge selected, the most current achievement from badge-enabled categories will be used.', 'dpa'); ?></p>
    	</div>
    <?php
    	}
    	add_action('dpa_achievement_category_add_form_fields', 'dpa_achievement_category_with_badge_add', 10, 2);
    
    	function dpa_achievement_category_with_badge_edit($term)
    	{
    		$t_id = $term->term_id;
    		$term_meta = get_option( "taxonomy_$t_id" );
    ?>
    	<tr>
    		<th scope="row" valign="top"><label for="term_meta[dpa_achievement_category_for_badge]"><?php _e('Badge-Enabled?', 'dpa'); ?></label></th>
    		<td>
    			<input type="checkbox" name="term_meta[dpa_achievement_category_for_badge]" id="term_meta[dpa_achievement_category_for_badge]" value="1" <?php checked($term_meta['dpa_achievement_category_for_badge'], 1); ?> />
    			<p class="description"><?php _e('Should this category be used to determine user badges? If the user has no badge selected, the most current achievement from badge-enabled categories will be used.', 'dpa'); ?></p>
    		</td>
    	</tr>
    <?php
    	}
    	add_action('dpa_achievement_category_edit_form_fields', 'dpa_achievement_category_with_badge_edit', 10, 2);
    
    	function dpa_achievement_category_save_meta($term_id)
    	{
    		if ( isset( $_POST['term_meta'] ) )
    		{
    			$t_id = $term_id;
    			$term_meta = get_option( "taxonomy_$t_id" );
    			$cat_keys = array_keys( $_POST['term_meta'] );
    			foreach ( $cat_keys as $key )
    			{
    				if ( isset ( $_POST['term_meta'][$key] ) )
    				{
    					$term_meta[$key] = $_POST['term_meta'][$key];
    				}
    			}
    			update_option( "taxonomy_$t_id", $term_meta );
    		}
    	}
    	add_action('edited_dpa_achievement_category', 'dpa_achievement_category_save_meta', 10, 2);
    	add_action('create_dpa_achievement_category', 'dpa_achievement_category_save_meta', 10, 2);
    
    /* Get Achievement Thumbnail **************************************************/
    /**
     * Output the featured image of the achievement
     *
     * @param int $achievement_id Optional. Achievement ID
     * @see dpa_get_achievement_title()
     * @since Achievements 3.2.2
     * @author Mike Bronner <mike.bronner@gmail.com>
     */
    function dpa_achievement_image( $achievement_id = 0, $size = 'thumbnail' )
    {
    	echo dpa_get_achievement_image( $achievement_id, $size );
    }
    
    /**
     * Output the featured image of the achievement
     *
     * @param int $achievement_id Optional. Achievement ID
     * @since Achievements 3.2.2
     * @author Mike Bronner <mike.bronner@gmail.com>
     */
    function dpa_get_achievement_image($achievement_id = 0, $size = 'thumbnail')
    {
    	$achievement_id = dpa_get_achievement_ID($achievement_id);
    	$image          = get_the_post_thumbnail($achievement_id, $size, array("title"=>dpa_get_achievement_title($achievement_id)));
    
    	return apply_filters('dpa_get_achievement_image', $image, $achievement_id);
    }
    
    /* Get Achievement Badge **************************************************/
    /**
     * Output the chosen achievement badge for the user
     *
     * @param int $achievement_user_id Required. User ID of the user to fetch the badge for.
     * @param string $size Optional.
     * @see dpa_get_achievement_badge()
     * @since Achievements 3.2.2
     * @author Mike Bronner <mike.bronner@gmail.com>
     */
    function dpa_achievement_badge( $achievement_user_id, $size = 'thumbnail' )
    {
    	echo dpa_get_achievement_badge( $achievement_user_id, $size );
    }
    
    /**
     * Output the chosen achievement badge for the user
     *
     * @param int $achievement_user_id Required. User ID of the user to fetch the badge for.
     * @param string $size Optional.
     * @since Achievements 3.2.2
     * @author Mike Bronner <mike.bronner@gmail.com>
     */
    function dpa_get_achievement_badge($achievement_user_id, $size = 'thumbnail')
    {
    	$achievement_id = get_user_option( '_dpa_user_achievement_badge', $achievement_user_id);
    /* Need to figure out how to query custom taxonomy fields from WP_Query, and help is appreciated, this will then retireve the latest achievement from badge-enabled categories
    	if (!$achievement_id)
    	{
    		$latest_achievement = dpa_get_progress(array("author"=>$achievement_user_id, "status"=>"dpa_unlocked", "meta_key"=>"dpa_achievement_category_for_badge", "meta_compare"=>"=", "meta_value"=>"1", "orderby"=>"post_date, ID", "order"=>"DESC"));
    		$achievement_id = $latest_achievement[0]->post_parent;
    	}
    */
    	if (!$achievement_id)
    	{
    		$latest_achievement = dpa_get_progress(array("author"=>$achievement_user_id, "status"=>"dpa_unlocked", "orderby"=>"post_date, ID", "order"=>"DESC"));
    		$achievement_id = $latest_achievement[0]->post_parent;
    	}
    	$image = get_the_post_thumbnail($achievement_id, $size, array("title"=>dpa_get_achievement_title($achievement_id)));
    
    	return apply_filters('dpa_get_achievement_badge', $image, $achievement_id);
    }

    Step 3: Customize dpa_achievement_comment_with_badge() to format your comments as needed.

    Step 4: If you don't have comments.php in your child-theme, go ahead and copy it there from your current theme.

    Step 5: Edit comments.php in your child-theme by replacing the existing wp_list_comments() with the following:
    <?php wp_list_comments( array( 'callback' => 'dpa_achievement_comment_with_badge', 'style' => 'ol' ) ); ?>

    Conclusion: This code should add the following:

    • Badge Selectors on User Profile admin page for both SuperAdmin and User.
    • Designate achievement categories (if you have them implemented) to be badge-enabled. Do this by modifying existing categories, or making the selection for new categories. The selection will save, but I still need to work on the selection process.
    • Display the most recent achievement as the badge if there is no badge selected for the user.
    • Display badge next to user's avatar in comments and author info.
    • Added function dpa_get_achievement_badge($user_id, $size) and dpa_achievement_badge($user_id, $size) to allow you to insert the badge whereever you like in your theme.

    Please let me know if you're having trouble with this -- I know it's a lot of code. Also, I'd be interested in seeing your results, post your links here! :)

    Happy coding!
    ~Mike

  16. Paul Gibbs
    BuddyPress Lead Developer
    Plugin Author

    Posted 1 year ago #

  17. mikebronner
    Member
    Posted 1 year ago #

    Will do :) Thanks for the link, I'll look into that.

  18. mikebronner
    Member
    Posted 1 year ago #

    Example 1: Badge on bbPress profile page underneath the avatar image: http://konb.info/forums/users/brent-owen/
    This is implemented by adding the following code to the template file in the child-theme:

    <div id="dpa_achievement_badge">
    			<?php dpa_achievement_badge(bbp_get_user_id( null, true, false ), "small"); ?>
    		</div>

    Example 2: Badge on profile information in comment and author info:
    http://konb.info/richard-garriott-interview-lord-blackthorn/

    Future Features: tighter integration with Achievement-supported plugins, like bbPress, BuddyPress, etc.

  19. mikebronner
    Member
    Posted 1 year ago #

    @Paul: I was reading up on taxonomy queries all day yesterday, but haven't been able to get this to work.

    I added a custom field dpa_achievement_category_for_badge to the custom taxonomy which stores if the acheivement category is to be used for badges or not.
    This value is saved in [wp_prefix]_options table as the following example:

    option_id: 1545
    option_name: taxonomy_87
    option_value: a:1:{s:34:"dpa_achievement_category_for_badge";s:1:"1";}
    autoload: yes

    The taxonomy_87 refers to the achievement category term_taxonomy_id, and the option_value holds all the information. Any suggestions on where to go from here? I haven't found any examples of queries that actually fetch and filter based on custom taxonomy custom fields -- or at least I haven't been able to get any of them to work.

    The following results in a completely incorrect query that seems to not even consider the taxonomy:
    var_dump(new WP_Query(array(array("taxonomy"=>"dpa_achievement_category", "field"=>"dpa_achievement_category_for_badge", "terms"=>"1"))));

  20. Tomas Dostal
    Member
    Posted 1 year ago #

    [Moderated] check-out [link to non-WP commercial product removed] It is a global service for badges and achievements. There is already a shortcut plugin for this service and full-integration plugin coming up soon.

  21. mikebronner
    Member
    Posted 1 year ago #

    Tomas, was looking at Badge Fever, and even there to implement it in wordpress you need to do custom coding in your theme, or at the very least install another plugin.

    Obviously you know what Achievements for WordPress is, and as a plugin it will evolve and get more features. I don't think it's quite right to troll here for users in this support forum as a developer on Badge Fever. This is a support forum, and we're all trying to help each other out here. There are those that like Achievements for WordPress just fine and just want to tweak it here and there.

  22. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    @Tomas - per forum policy, please do not use these forums to promote outside plugins or services.

  23. Paul Gibbs
    BuddyPress Lead Developer
    Plugin Author

    Posted 1 year ago #

    Tomas,
    I think advertising your service/plugin on a competitor's *support* thread is cheeky, at best.

    ---

    Everyone: start new topics for follow-up please. This was a support request/question which has been resolved.

    @WPyogi Thanks for jumping in so promptly! :)

  24. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    No problem and since this is resolved - it's now closed.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags