achievement_id empty on achievement submission form
-
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
- The topic ‘achievement_id empty on achievement submission form’ is closed to new replies.