• Featured images assigned to one specific achievement type in BadgeOS are being replaced by a default Credly image (https://credlyapp.s3.amazonaws.com/badges/af2e834c1e23ab30f1d672579d61c25a_15.png) when users submit an auto-approved achievement.

    The multisite installation I am working on has featured images associated in WordPress for every achievement type. There are 5 types. The steps needed to acquire a larger achievement are the ones that are not getting the correct images.

    There is something really strange that happens. When the user submits the form, the submission is accepted and they receive a notice indicating it was submitted.

    There is one correct insertion and one incorrect insertion taking place as far as I can tell. The correct insertion shows up when a user goes to their BuddyPress profile and looks at their Achievements. The featured images show up next to each achievement in this section.

    The incorrect insertion (not showing featured image associated with the particular achievement type) is seen if viewing the user’s activity feed. For example:

    series of Quests -> Competency -> Series of Competencies -> Skill

    Only Quest achievement types are not getting the featured images assigned in the activity feed. They are correct in the Achievment section -> Quests on the BP profile.

    I am unable to figure out why the achievement_id is ending up empty and causing the default image to be inserted in the database. I traced the logic to the badgeos/achievement_functions.php file. There are two functions that have the URL to the credly default image:

    LINE 528 * Helper function to retrieve an achievement post thumbnail
     *
     * Falls back first to parent achievement type's thumbnail,
     * and finally to a default BadgeOS icon from Credly.
     *
     * @since  1.0.0
     * @param  integer $post_id    The achievement's post ID
     * @param  string  $image_size The name of a registered custom image size
     * @param  string  $class      A custom class to use for the image tag
     * @return string              Our formatted image tag
     */
    function badgeos_get_achievement_post_thumbnail( $post_id = 0, $image_size = 'badgeos-achievement', $class = 'badgeos-item-thumbnail' ) {
    
    	// Get our badge thumbnail
    	$image = get_the_post_thumbnail( $post_id, $image_size, array( 'class' => $class ) );
    
    	// If we don't have an image...
    	if ( ! $image ) {
    
    		// Grab our achievement type's post thumbnail
    		$achievement = get_page_by_path( get_post_type(), OBJECT, 'achievement-type' );
    		$image = is_object( $achievement ) ? get_the_post_thumbnail( $achievement->ID, $image_size, array( 'class' => $class ) ) : false;
    
    		// If we still have no image, use one from Credly
    		if ( ! $image ) {
    
    			// If we already have an array for image size
    			if ( is_array( $image_size ) ) {
    				// Write our sizes to an associative array
    				$image_sizes['width'] = $image_size[0];
    				$image_sizes['height'] = $image_size[1];
    
    			// Otherwise, attempt to grab the width/height from our specified image size
    			} else {
    				global $_wp_additional_image_sizes;
    				if ( isset( $_wp_additional_image_sizes[$image_size] ) )
    					$image_sizes = $_wp_additional_image_sizes[$image_size];
    			}
    
    			// If we can't get the defined width/height, set our own
    			if ( empty( $image_sizes ) ) {
    				$image_sizes = array(
    					'width'  => 100,
    					'height' => 100
    				);
    			}
    
    			// Available filter: 'badgeos_default_achievement_post_thumbnail'
    			$image = '<img src="' . apply_filters( 'badgeos_default_achievement_post_thumbnail', 'https://credlyapp.s3.amazonaws.com/badges/af2e834c1e23ab30f1d672579d61c25a_15.png' ) . '" width="' . $image_sizes['width'] . '" height="' . $image_sizes['height'] . '" class="' . $class .'">';
    
    		}
    	}
    
    	// Finally, return our image tag
    
    	return $image;
    }

    And…

    LINE 738 /**
     * Set default achievement image on achievement post save
     *
     * @since 1.2.0
     * @param integer $post_id The post ID of the post being saved
     * @return mixed    post ID if nothing to do, void otherwise.
     */
    function badgeos_achievement_set_default_thumbnail( $post_id ) {
    	global $pagenow;
    
    	// Bail early if:
    	// this IS NOT an achievement or achievement-type post
    	// OR this IS an autosave
    	// OR current user CAN NOT edit this post
    	// OR the post already has a thumbnail
    	// OR we've just loaded the new post page
    	if (
    		! (
    			badgeos_is_achievement( $post_id )
    			|| 'achievement-type' == get_post_type( $post_id )
    		)
    		|| ( defined('DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    		|| ! current_user_can( 'edit_post', $post_id )
    		|| has_post_thumbnail( $post_id )
    		|| 'post-new.php' == $pagenow
    	) {
    		//echo "postid = " . $post_id;
    		return $post_id;
    	}
    
    	$thumbnail_id = 0;
    
    	// Get the thumbnail of our parent achievement
    	if ( 'achievement-type' !== get_post_type( $post_id ) ) {
    		$achievement_type = get_page_by_path( get_post_type( $post_id ), OBJECT, 'achievement-type' );
    
    		if ( $achievement_type ) {
    			$thumbnail_id = get_post_thumbnail_id( $achievement_type->ID );
    			echo $thumbnail_id;
    		}
    	}
    
    	// If there is no thumbnail set, load in our default image
    	if ( empty( $thumbnail_id ) ) {
    
    		// Grab the default image
    		$file = apply_filters( 'badgeos_default_achievement_post_thumbnail', 'https://credlyapp.s3.amazonaws.com/badges/af2e834c1e23ab30f1d672579d61c25a_15.png' );
    
    		// Download file to temp location
    		$tmp = download_url( $file );
    
    		// Set variables for storage
    		// fix file filename for query strings
    		preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
    		$file_array['name'] = basename( $matches[0] );
    		$file_array['tmp_name'] = $tmp;
    
    		// If error storing temporarily, unlink
    		if ( is_wp_error( $tmp ) ) {
    			@unlink( $file_array['tmp_name'] );
    			$file_array['tmp_name'] = '';
    		}
    
    		// Upload the image
    		$thumbnail_id = media_handle_sideload( $file_array, $post_id );
    
    		// If upload errored, unlink the image file
    		if ( is_wp_error( $thumbnail_id ) ) {
    			@unlink( $file_array['tmp_name'] );
    
    		// Otherwise, if the achievement type truly doesn't have
    		// a thumbnail already, set this as its thumbnail, too.
    		// We do this so that WP won't upload a duplicate version
    		// of this image for every single achievement of this type.
    		} elseif (
    			badgeos_is_achievement( $post_id )
    			&& is_object( $achievement_type )
    			&& ! get_post_thumbnail_id( $achievement_type->ID )
    		) {
    			set_post_thumbnail( $achievement_type->ID, $thumbnail_id );
    		}
    	}
    
    	// Finally, if we have an image, set the thumbnail for our achievement
    	if ( $thumbnail_id && ! is_wp_error( $thumbnail_id ) )
    		set_post_thumbnail( $post_id, $thumbnail_id );
    
    }
    add_action( 'save_post', 'badgeos_achievement_set_default_thumbnail' );

    I would like to figure out why this one achievement type is not showing correct images.

    WordPress Multisite 4.2.2
    BadgeOS 1.4.4
    BadgeOS Community 1.2.0
    Buddypress 2.3.2.1

    https://www.ads-software.com/plugins/badgeos/

Viewing 15 replies - 1 through 15 (of 22 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    The only time that the default thumbs up graphic should be used for your achievements, is when you haven’t set an image yourself. However, we also have the “step” achievement type that is mostly behind the scenes, that does get it, as we don’t really have any UI to set the image for that part. Frequently, I’ve noticed, the actual set up achievement and the step associated with it are named the exact same. So, it’s possible you’re actually seeing the step instead of the custom achievement. The steps also don’t inherit.

    It’s possible that the steps are being added to the BuddyPress activity stream.

    Related, but perhaps unnoticed so far, I’m hoping to also have a fix in 1.4.5 that will prevent repeated uploading of said thumbs up graphic to the media library. Your library may have a numerous versions in there at the moment. I’d appreciate some beta testing if you’re willing as well.

    Thread Starter doedev

    (@doedev)

    Sure, I’m digging around behind the scenes anyway and would be happy to do some testing while I’m figuring this out. I’m looking into the naming of the various parts and will let you know if they are all the same. I wasn’t involved in the setup but that’s a good tip. Thanks and please let me know how I can help.

    Thread Starter doedev

    (@doedev)

    Each achievement type has a default achievement image in the right metabox assigned and those images are all different. In the backend of BadgeOS looking at user profile, the achievements with correct images can be seen. Steps with the default credly image show up in this backend profile area.

    On the public profile, what happens is that the lowest achievements, what we call Quests, end up with the default credly image in the Activity Feed. They do not appear to be the Steps since they are linked to the Quest, which is one of our achievement types with a custom image set.

    Any idea why this would be happening? Could the Steps and our achievement type, Quest, be getting mixed up somehow?

    An overview of our achievement type flow from bottom up:

    1 or more Quests earned results in 1 Competency earned
    1 or more Competencies earned results in 1 Skill earned

    Quests have incorrect, default credly images

    Competencies/Skills have correct images.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    See this thread for the BadgeOS 1.4.5 testing: https://www.ads-software.com/support/topic/badgeos-145-bugfix-release-testing?replies=1

    You’ll want to disable your 1.4.4 copy before activating, or else you’ll get fatal errors due to function name conflicts.

    Just checked the Community Add-on code and the function we use to insert activity items should be rejecting anything from the step post type. So I’m not sure what’s going on there, unless they aren’t steps like we first thought, or this is a different section of BuddyPress that we may have missed or was since added to BuddyPress itself.

    Thread Starter doedev

    (@doedev)

    I’m not sure if this points out anything to you but here is what is stored in the wp_bp_activity.content field and is what shows up on the activity feed incorrectly, but shows correctly in the profile/achievements/quests section correctly.

    <div class="badgeos-achievements-list-item user-has-earned"><div class="badgeos-item-image"><a href="https://<website-removed>/blog/quest/create-1-1-1/"><img src="https://credlyapp.s3.amazonaws.com/badges/af2e834c1e23ab30f1d672579d61c25a_15.png" width="100" height="100" class="badgeos-item-thumbnail"/></a></div><div class="badgeos-item-description">Explore the interrelationship between planning, establishing a specific schedule, and the successful development and delivery of an online course.
    </div></div>
    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hmm. Sadly not able to confirm one way or another what achievement type that is, with the information present.

    Thread Starter doedev

    (@doedev)

    Apologies for that. I pasted in the 3 columns I think will show the achievement types from our wp_posts table. After reading a bunch of forum topics slightly related, I’m wondering if our achievements are supposed to be named something else in post_type? They are all currently named achievement_type.

    Image

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    nope, those titles/types are as I would expect.

    Are you willing to let me into the website to see firsthand? It may be quicker than me scratching my head for next questions to ask.

    Thread Starter doedev

    (@doedev)

    I’m working on a localhost setup. I’ll ask our sysadmin if we can get you into the Live production site. It’s not quite the same setup as I have upgraded WordPress and plugins on the localhost. The live site is still WP 3.5. The data should still be the same?

    Silly question, how would I get access info to you if I can get approval?

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    data would be the same yes.

    If it’s approved to let me in and it’s as matching as possible to your localhost, then I’d provide my email to send a user registration to.

    Thread Starter doedev

    (@doedev)

    Thanks! We move really slow here in terms of servers/access so it might be a little while before I figure out what access options we have. Thanks for your patience.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Let me know when.

    Thread Starter doedev

    (@doedev)

    Hi Michael, I’m not sure I’m going to be able to get access anytime soon.

    I’m attempting to solve another related issue but cannot seem to narrow it down. I’m using xDebug and Netbeans to step through the code but it is still escaping me. The best I can do is show some of the values in time and see if you can point me in any direction that might help me pinpoint the issue.

    Issue: One achievement type is losing its custom thumbnail image (attachment) but other types do not.

    Overview: We are using bagdgeos with Skills that require multiple Compentencies that require multiple Quests.

    Hierarchy would be like this:

    Skill -> step ->>
    Competency1 -> step ->>
    Quest 1 -> step -> Quest2 -> step

    Competency2 -> step ->>
    Quest2.1 -> step -> Quest2.2 -> step

    Skills – attachment images images are correct in BP activity stream

    Competencies – attachment images are correct in BP activity stream

    Quests – default Credly image is used in BP activity stream

    I’m using Netbeans to set a breakpoint in the media.php/function wp_get_attachment_image to show what values are in the thumbnail attachment values. Somewhere right before the last database updates are made, the value of the image attachment is lost even though it was correctly retrieved/stored in a variable at the beginning of the form submission.

    Any ideas why the value would become empty for this one achievement type? The other two work fine although they are automatically triggered if all Quests have been approved.

    As I’m stepping through a Quest submission, I see the correct value early on:

    Correct Image Value – Correct thumbnail path stored in variable

    after continuing stepping through the form submission, the values get lost:

    Lost Value – Values seem to be lost

    Lost Value Before Credly Default Called – Right before Credly default assigned

    Credlydefault – Credly default assigned

    I’m at a loss as to why this particular achievement type loses the correct value during the submission processing. The database correctly stores everything but the image. The Badgeos “steps” are added for the achievements so the submitted achievements show up as earned.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Unrelated: kudos for xDebug + NetBeans. I’m a PHPStorm person myself, but anything is better than nothing and this type of debugging saves so much headache.

    Have you checked the achievement type for each time the badgeos_get_achievement_post_thumbnail() function has been called? I’m curious if that Quest is somehow a step and not the proper intended achievement type. Perhaps set a breakpoint inside of the function and refresh the page to see what’s coming in. Should be able to expand the $achievement spot in the variables panel to see all the properties on it.

    Thread Starter doedev

    (@doedev)

    Yeah, I looked into PHPStorm but had better luck getting netbeans installed. it’s working ok for now.

    So I sent another Quest through the submission form and think I found the $achievement array you were curious about.

    image: “” so it’s causing the function to look for achievement type’s post tb and when it fails to find that, it loads the default credly image.

    The achievement values when it enters the function for the Quest type, are:

    Image

    post_type = achievement-type << is that correct?

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘achievement_id empty on achievement submission form’ is closed to new replies.