• LifterLMS
  • Knowledge Base
  • Academy
  • Blog
  • Podcast
  • Contributors
  • My Account

LifterLMS LifterLMS

  • Code Reference
  • REST API
  • LLMS-CLI
  • Changelog Subscribe

Code Reference

Skip to content
Filter by type:
Search
Browse: Home / Code Reference / Classes / LLMS_Query_User_Postmeta / LLMS_Query_User_Postmeta::parse_args()

LLMS_Query_User_Postmeta::parse_args()

Parses data passed to $statuses Convert strings to array and ensure resulting array contains only valid statuses If no valid statuses, returns to the default

Contents

  • Return
  • Source
  • Related
    • Uses
  • Changelog
  • User Contributed Notes

Return #Return

(void)


Top ↑

Source #Source

File: includes/class.llms.query.user.postmeta.php

		// Sanitize post & user ids.
		foreach ( array( 'post_id', 'user_id' ) as $key ) {

			$this->arguments[ $key ] = $this->sanitize_id_array( $this->arguments[ $key ] );

		}

		if ( $this->arguments['include_post_children'] ) {

			foreach ( $this->arguments['post_id'] as $id ) {

				if ( 'course' !== get_post_type( $id ) ) {
					continue;
				}

				$course                     = llms_get_post( $id );
				$this->arguments['post_id'] = array_merge(
					$this->arguments['post_id'],
					$this->sanitize_id_array( $course->get_sections( 'ids' ) ),
					$this->sanitize_id_array( $course->get_lessons( 'ids' ) ),
					$this->sanitize_id_array( $course->get_quizzes() )
				);

			}
		}

		if ( $this->arguments['types'] ) {

			$all_events = array(
				'completion'  => array(
					'key'   => '_is_complete',
					'value' => 'yes',
				),
				'status'      => array(
					'compare' => 'IS NOT NULL',
					'key'     => '_status',
				),
				'achievement' => array(
					'compare' => 'IS NOT NULL',
					'key'     => '_achievement_earned',
				),
				'certificate' => array(
					'compare' => 'IS NOT NULL',
					'key'     => '_certificate_earned',
				),
				'email'       => array(
					'compare' => 'IS NOT NULL',
					'key'     => '_email_sent',
				),
				'purchase'    => array(
					'compare' => 'LIKE',
					'key'     => '_enrollment_trigger',
					'value'   => 'order_%',
				),
				'favorites'   => array(
					'key'     => '_favorite',
					'compare' => 'IS NOT NULL',
				),
			);

			if ( is_string( $this->arguments['types'] ) && 'all' === $this->arguments['types'] ) {

				$this->arguments['query'] = array_values( $all_events );

			} else {

				$this->arguments['query'] = array();

				if ( ! is_array( $this->arguments['types'] ) ) {
					$this->arguments['types'] = array( $this->arguments['types'] );
				}

				foreach ( $this->arguments['types'] as $type ) {
					if ( ! isset( $all_events[ $type ] ) ) {
						continue;
					}
					$this->arguments['query'][] = $all_events[ $type ];
				}
			}
		}

		if ( $this->arguments['query'] ) {

			foreach ( $this->arguments['query'] as $i => &$query ) {

				// Ensure that each query has a compare operator.
				$query = wp_parse_args(
					$query,
					array(
						'compare' => '=',
						'key'     => '',
						'value'   => '',
					)
				);

				$operators = array( '=', '!=', 'LIKE', 'IN', 'NOT IN', 'IS NOT NULL' );
				if ( ! in_array( $query['compare'], $operators ) ) {
					unset( $this->arguments['query'][ $i ] );
				}
			}
		}

		if ( ! in_array( $this->arguments['query_compare'], array( 'AND', 'OR' ) ) ) {
			$this->arguments['query_compare'] = 'OR';

Expand full source code Collapse full source code View on GitHub


Top ↑

Related #Related

Uses #Uses

Uses
Uses Description
includes/llms.functions.core.php: llms_get_post()

Retrieve the LLMS Post Model for a give post by ID or WP_Post Object


Top ↑

Changelog #Changelog

Changelog
Version Description
3.15.0 Introduced.

Top ↑

User Contributed Notes #User Contributed Notes

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

© 2014 - 2025 LifterLMS · Privacy Policy · Terms and Conditions

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.