LLMS_Shortcodes::user_statistics( [array] $atts )

Output user statistics related to courses enrolled, completed, etc.


Description Description

..


Parameters Parameters

$atts

([array]) (Required) / array of user input attributes


Top ↑

Return Return

(string) / html content


Top ↑

Source Source

File: includes/shortcodes/class.llms.shortcodes.php

	public static function user_statistics( $atts ) {
		extract(shortcode_atts(array(
			'type' => 'course', // course, lesson, section
			'stat' => 'completed',// completed, enrolled
		),$atts));

		// setup the meta key to search on
		switch ( $stat ) {
			case 'completed':
				$key = '_is_complete';
				$val = false;
			break;

			case 'enrolled':
				$key = '_status';
				$val = 'Enrolled';
			break;
		}

		// get user id of logged in user
		$uid = wp_get_current_user()->ID;

		// init person class
		$person = new LLMS_Person();
		// get results
		$results = $person->get_user_postmetas_by_key( $uid,$key );

		if ( $results ) {
			// unset all items that are not courses
			foreach ( $results as $key => $obj ) {
				if ( get_post_type( $obj->post_id ) != $type ) {
					unset( $results[ $key ] );
				}
			}
		}

		// filter by value if set
		if ( is_array( $results ) && $val ) {
			foreach ( $results as $key => $obj ) {
				// remove from the results array if $val doesn't match
				if ( $obj->meta_value != $val ) {
					unset( $results[ $key ] );
				}
			}
		}

		$count = (is_array( $results )) ? count( $results ) : 0;

		if ( 1 == $count ) {
			return $count . ' ' . $type;
		}

		return $count . ' ' . $type . 's';

	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.