ActionScheduler_wpPostStore::find_actions_by_claim_id()publicWC 1.0

Find actions by claim ID.

Method of the class: ActionScheduler_wpPostStore{}

No Hooks.

Return

Array.

Usage

$ActionScheduler_wpPostStore = new ActionScheduler_wpPostStore();
$ActionScheduler_wpPostStore->find_actions_by_claim_id( $claim_id );
$claim_id(string) (required)
Claim ID.

ActionScheduler_wpPostStore::find_actions_by_claim_id() code WC 9.3.3

public function find_actions_by_claim_id( $claim_id ) {
	/**
	 * Global wpdb object.
	 *
	 * @var wpdb $wpdb
	 */
	global $wpdb;

	$action_ids  = array();
	$before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object();
	$cut_off     = $before_date->format( 'Y-m-d H:i:s' );

	// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
	$results = $wpdb->get_results(
		$wpdb->prepare(
			"SELECT ID, post_date_gmt FROM {$wpdb->posts} WHERE post_type = %s AND post_password = %s",
			array(
				self::POST_TYPE,
				$claim_id,
			)
		)
	);

	// Verify that the scheduled date for each action is within the expected bounds (in some unusual
	// cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify).
	foreach ( $results as $claimed_action ) {
		if ( $claimed_action->post_date_gmt <= $cut_off ) {
			$action_ids[] = absint( $claimed_action->ID );
		}
	}

	return $action_ids;
}