ActionScheduler_DBStore::get_group_idsprotectedWC 1.0

Get a group's ID based on its name/slug.

Method of the class: ActionScheduler_DBStore{}

No Hooks.

Returns

Array. The group IDs, if they exist or were successfully created. May be empty.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_group_ids( $slugs, $create_if_not_exists );
$slugs(string|array) (required)
The string name of a group, or names for several groups.
$create_if_not_exists(true|false)
Whether to create the group if it does not already exist. Default, true - create the group.
Default: true

ActionScheduler_DBStore::get_group_ids() code WC 9.9.5

protected function get_group_ids( $slugs, $create_if_not_exists = true ) {
	$slugs     = (array) $slugs;
	$group_ids = array();

	if ( empty( $slugs ) ) {
		return array();
	}

	/**
	 * Global.
	 *
	 * @var \wpdb $wpdb
	 */
	global $wpdb;

	foreach ( $slugs as $slug ) {
		$group_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT group_id FROM {$wpdb->actionscheduler_groups} WHERE slug=%s", $slug ) );

		if ( empty( $group_id ) && $create_if_not_exists ) {
			$group_id = $this->create_group( $slug );
		}

		if ( $group_id ) {
			$group_ids[] = $group_id;
		}
	}

	return $group_ids;
}