• Hi there,

    I modified a function to add a new shortcode parameter to show certificate images rather than titles.

    The new parameter is show-images and can be set to true or false and defaults to false.

    I also commented out a couple of seemingly useless lines for setting $quiz_title_fallback and $quiz_title variables which seems to be unused.

    I forget exactly how to post code on here but hopefully this works.

    The function starts at uncanny-learndash-toolkit/src/classes/show-certificates-shortcode.php line 77:

    
    	/**
    	 *
    	 *
    	 * @static
    	 *
    	 * @param $atts
    	 *
    	 * @return string
    	 */
    	public static function learndash_certificates( $atts ) {
    
    		if ( ! is_user_logged_in() ) {
    			return '';
    		}
    
    		if ( isset( $atts['class'] ) ) {
    			$class = $atts['class'];
    		} else {
    			$class = 'certificate-list-container';
    		}
    
    		if ( isset( $atts['title'] ) ) {
    			$title = $atts['title'];
    		} else {
    			$title = '';
    		}
    
    		if ( isset( $atts['no-cert-message'] ) ) {
    			$no_cert_message = $atts['no-cert-message'];
    		} else {
    			$no_cert_message = esc_html__( 'Complete courses to earn certificates', 'uncanny-learndash-toolkit' );
    		}
    
    		if ( isset( $atts['show-image'] ) ) {
    			$show_image = boolval($atts['show-image']);
    		} else {
    			$show_image = false;
    		}
    
    		$certificate_list = '';
    
    		/* GET Certificates For Courses*/
    		$args = array(
    			'post_type'      => 'sfwd-courses',
    			'posts_per_page' => - 1,
    			'post_status'    => 'publish',
    			'orderby'        => 'title',
    			'order'          => 'ASC',
    		);
    
    		$courses = get_posts( $args );
    
    		foreach ( $courses as $course ) {
    
    			$certificate_id     = learndash_get_setting( $course->ID, 'certificate' );
    			$certificate_object = get_post( $certificate_id );
    
    			if ( ! empty( $certificate_object ) ) {
    			    if($show_image) {
    				    $certificate_img = get_the_post_thumbnail($certificate_id, array(175, 175));
    				    $certificate_link  = learndash_get_course_certificate_link( $course->ID );
    
    				    if ( $certificate_link && '' !== $certificate_link ) {
    					    $certificate_list .= '<a target="_blank" href="' . $certificate_link . '">' . $certificate_img . '</a>';
    				    }
    			    } else {
                        $certificate_title = $certificate_object->post_title;
                        $certificate_link  = learndash_get_course_certificate_link( $course->ID );
    
                        if ( $certificate_link && '' !== $certificate_link ) {
                            $certificate_list .= '<a target="_blank" href="' . $certificate_link . '">' . $certificate_title . '</a><br>';
                        }
    			    }
    			}
    
    		}
    
    		/* GET Certificates for Quizzes*/
    		$quiz_attempts = self::quiz_attempts();
    
    		if ( ! empty( $quiz_attempts ) ) {
    
    			$quiz_attempts = array_reverse( $quiz_attempts );
    
    			foreach ( $quiz_attempts as $k => $quiz_attempt ) {
    
    				if ( isset( $quiz_attempt['certificate'] ) ) {
    					$certificateLink     = $quiz_attempt['certificate']['certificateLink'];
    					//$quiz_title_fallback = ( isset( $quiz_attempt['quiz_title'] ) ) ? $quiz_attempt['quiz_title'] : '';
    					//$quiz_title          = ! empty( $quiz_attempt['post']->post_title ) ? $quiz_attempt['post']->post_title : $quiz_title_fallback;
    
    					if ( ! empty( $certificateLink ) ) {
    
    						$meta               = get_post_meta( $quiz_attempt['post']->ID, '_sfwd-quiz', true );
    						$certificate_id     = $meta['sfwd-quiz_certificate'];
    						$certificate_object = get_post( $certificate_id );
    
    						if($show_image) {
    							$certificate_img = get_the_post_thumbnail($certificate_id, array(175, 175));
    
    							$certificate_list .= '<a target="_blank" href="' . esc_url( $certificateLink ) . '">' . $certificate_img . '</a>';
    						} else {
    							$certificate_title = $certificate_object->post_title;
    
    							$certificate_list .= '<a target="_blank" href="' . esc_url( $certificateLink ) . '">' . $certificate_title . '</a><br>';
    						}
    
    					}
    				}
    			}
    		}
    
    		$certificate_list = apply_filters( 'certificate_list_shortcode', $certificate_list );
    
    		if ( '' === $certificate_list ) {
    			$certificate_list = $no_cert_message;
    		}
    
    		ob_start();
    		?>
            <div class="<?php echo esc_attr( $class ); ?>">
                <div class="cert-list-title"><?php echo $title; ?></div>
                <div class="certificate-list"><?php echo $certificate_list; ?></div>
            </div>
    
    		<?php
    
    		$shortcode_html = ob_get_clean();
    
    		return $shortcode_html;
    
    	}
    
    
    • This topic was modified 6 years, 1 month ago by ryvix.
Viewing 1 replies (of 1 total)
  • Plugin Author Uncanny Owl

    (@uncannyowl)

    Thanks for letting us know about this! We’ll add it to our backlog and may incorporate it into a future release.

Viewing 1 replies (of 1 total)
  • The topic ‘How to display certificate images with the uo_learndash_certificates shortcode’ is closed to new replies.