• 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 7 replies - 16 through 22 (of 22 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    We’re closer, but not quite there yet.

    I think this specific moment may be a case of fetching the image for the ‘achievement-type’ post type that BadgeOS registers to handle the custom achievements that users make. We’re wanting to see if there’s ever a moment where the achievement-type spot in that graphic is “quest” and it’s still returning an empty/default image, or if at that point, the achievement type spot says “step”

    Thread Starter doedev

    (@doedev)

    Michael,

    I’ve got PHPStorm up and running now and it’s a bit different then Netbeans.

    Is there a private forum/method to contact you? The organization I’m working for is a Credly Pro account and one of Credly’s more complicated projects. I would like to be able to give you more info that I do not want to make public. It might make troubleshooting a little easier.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    michael @ webdevstudios . com will reach my account I use for all BadgeOS related stuff.

    Thread Starter doedev

    (@doedev)

    I just noticed something else that might help pinpoint the issue. On auto-approved submission of an achievement type Quest, the correct image is loaded into $image variable in the badgeos_achivement_thumbnail function. Somewhere along the way, this value is replaced with the credly default image file location. When the page finishes loading, the correct image is showing on the page with the submission success message.

    So, high level view:

    Load page with submission form (correct image)
    Submit form – correct image file location loaded into $image var from db
    <processing….>
    Credly default image file location pulled from PHP coding b/c $image is empty

    DB processing finishes and page loads with success message (correct thumbnail image in page)

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Honestly not sure at the moment, though as you point out in the email, we’re kind of waiting on more information as well.

    Thread Starter doedev

    (@doedev)

    I’m upgrading our pro server next week so badgeos/buddypress/wordpress will be the latest versions on the server you have access to I believe. I would like to resolve this issue soon. I’ve tried to step through the code using PHPstorm but have not had luck finding the exact cause of the image switch.

    It only does it for one achievement type and does not look like it is being seen as a step. Any testing suggestions or ideas would be welcome.

    Thanks!

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    I have nothing new for it at the moment, but good to hear things will be updated and support people would be able to access more easily.

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