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::loop( string[] $slugs, array $assoc_args, string $callback )

Reusable loop function for handling commands which accept one or more slugs as the commands first argument


Parameters Parameters

$slugs

(string[]) (Required) Array of add-on slugs, with or without the lifterlms- prefix.

$assoc_args

(array) (Required) Associative array of command options from the original command.

$callback

(string) (Required) Name of the method to use for handling a single add-on for the given command. The callback should accept three arguments: + @type string $slug Add-on slug for the current item. + @type LLMS_Add_On $addon Add-on object for the current item. + @type array $assoc_args Array of arguments from the initial command. The callback should return a truthy to signal success and a falsy to signal an error.


Top ↑

Return Return

(array) Associative arrays containing details on the errors and successes encountered during the loop.

  • 'errors'
    (int) Number of errors encountered in the loop.
  • 'successes'
    (int) Number of success encountered in the loop.


Top ↑

Source Source

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

	private function loop( $slugs, $assoc_args, $callback ) {

		$successes = 0;
		$errors    = 0;

		foreach ( $slugs as $slug ) {

			if ( empty( $slug ) ) {
				\WP_CLI::warning( 'Ignoring ambiguous empty slug value.' );
				continue;
			}

			$addon = $this->get_addon( $slug, true, 'warning' );
			if ( empty( $addon ) ) {
				$errors++;
				continue;
			}

			if ( ! $this->$callback( $slug, $addon, $assoc_args ) ) {
				$errors++;
				continue;
			}

			$successes++;

		}

		return compact( 'errors', 'successes' );

	}

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.