Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Main::get_filtered_items( array $assoc_args, string $filter_field = '' )

Retrieves an optionally filtered list of add-ons for use in the list command.


Parameters Parameters

$assoc_args

(array) (Required) Associative array of command options.

$filter_field

(string) (Optional) The optional name of the field to filter results by.

Default value: ''


Top ↑

Return Return

(array[]) Array of add-on items.


Top ↑

Source Source

File: libraries/lifterlms-cli/src/Commands/AddOn/Main.php

	private function get_filtered_items( $assoc_args, $filter_field = '' ) {

		$addons = llms_get_add_ons();

		$list = array_filter(
			$addons['items'],
			function( $item ) {
				return // Skip anything without a slug.
				! empty( $item['slug'] ) &&
				// Skip the LifterLMS core.
				'lifterlms' !== $item['slug'] &&
				// Skip third party add-ons.
				! in_array( 'third-party', array_keys( $item['categories'] ), true );
			}
		);

		// Format remaining items.
		$list = array_map( array( $this, 'format_item' ), $list );

		// Filter by field value.
		if ( $filter_field ) {
			$field_val = $assoc_args[ $filter_field ];
			$list      = array_filter(
				$list,
				function( $item ) use ( $filter_field, $field_val ) {
					return $item[ $filter_field ] === $field_val;
				}
			);
		}

		// Alpha sort the list by slug.
		usort(
			$list,
			function( $a, $b ) {
				return strcmp( $a['name'], $b['name'] );
			}
		);

		return $list;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
0.0.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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