learndash_get_activity_query_args

apply_filters( 'learndash_get_activity_query_args',  array $query_args )

Filters query arguments for getting user activity.


Description #


Parameters #

$query_args

(array) An array query arguments for getting user activity.


Source #

File: includes/ld-reports.php


Examples #

 <?php
/**
 * Example usage for learndash_get_activity_query_args filter.
 */
add_filter(
	'learndash_get_activity_query_args',
	function( $query_args = array() ) {

		$add_extra_post_ids = false;

		// Check if ProPanel Activity rows (widget) OR Activity Course export
		if ( ( ( isset( $_GET['action'] ) ) && ( $_GET['action'] == 'learndash_propanel_template' ) ) && ( ( isset( $_GET['template'] ) ) && ( $_GET['template'] == 'activity_rows' ) || ( $_GET['template'] == 'activity-courses' ) ) ) {
			$add_extra_post_ids = true;
		}

		// Check if LearnDash Course Report export
		if ( ( ( isset( $_POST['action'] ) ) && ( $_POST['action'] == 'learndash-data-reports' ) ) && ( ( isset( $_POST['data']['slug'] ) ) && ( $_POST['data']['slug'] == 'user-courses' ) ) ) {
			$add_extra_post_ids = true;
		}

		if ( $add_extra_post_ids === true ) {

			if ( ( isset( $query_args['user_ids'] ) ) && ( ! empty( $query_args['user_ids'] ) ) ) {
				if ( ! isset( $query_args['post_ids'] ) ) {
					$query_args['post_ids'] = array();
				}

				foreach ( $query_args['user_ids'] as $user_id ) {
					$user_course_progress = get_user_meta( $user_id, '_sfwd-course_progress', true );
					if ( ! empty( $user_course_progress ) ) {
						$query_args['post_ids'] = array_merge( $query_args['post_ids'], array_keys( $user_course_progress ) );
					}
				}
			}
		}

		// Always return $query_args
		return $query_args;
	}
);