WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта с помощью браузерных PUSH уведомлений
функция не описана

ActionScheduler_DBStore::get_query_actions_sql() protected WC 1.0

Returns the SQL statement to query (or count) actions.

{} Это метод класса: ActionScheduler_DBStore{}

Хуков нет.

Возвращает

Строку. SQL statement already properly escaped.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_query_actions_sql( $query, $select_or_count );
$query(массив) (обязательный)
Filtering options.
$select_or_count(строка)
Whether the SQL should select and return the IDs or just the row count.

Код ActionScheduler_DBStore::get_query_actions_sql() WC 5.3.0

<?php
protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) {

	if ( ! in_array( $select_or_count, array( 'select', 'count' ) ) ) {
		throw new InvalidArgumentException( __( 'Invalid value for select or count parameter. Cannot query actions.', 'woocommerce' ) );
	}

	$query = wp_parse_args( $query, [
		'hook'             => '',
		'args'             => null,
		'date'             => null,
		'date_compare'     => '<=',
		'modified'         => null,
		'modified_compare' => '<=',
		'group'            => '',
		'status'           => '',
		'claimed'          => null,
		'per_page'         => 5,
		'offset'           => 0,
		'orderby'          => 'date',
		'order'            => 'ASC',
	] );

	/** @var \wpdb $wpdb */
	global $wpdb;
	$sql  = ( 'count' === $select_or_count ) ? 'SELECT count(a.action_id)' : 'SELECT a.action_id';
	$sql .= " FROM {$wpdb->actionscheduler_actions} a";
	$sql_params = [];

	if ( ! empty( $query[ 'group' ] ) || 'group' === $query[ 'orderby' ] ) {
		$sql .= " LEFT JOIN {$wpdb->actionscheduler_groups} g ON g.group_id=a.group_id";
	}

	$sql .= " WHERE 1=1";

	if ( ! empty( $query[ 'group' ] ) ) {
		$sql          .= " AND g.slug=%s";
		$sql_params[] = $query[ 'group' ];
	}

	if ( $query[ 'hook' ] ) {
		$sql          .= " AND a.hook=%s";
		$sql_params[] = $query[ 'hook' ];
	}
	if ( ! is_null( $query[ 'args' ] ) ) {
		$sql          .= " AND a.args=%s";
		$sql_params[] = $this->get_args_for_query( $query[ 'args' ] );
	}

	if ( $query[ 'status' ] ) {
		$sql          .= " AND a.status=%s";
		$sql_params[] = $query[ 'status' ];
	}

	if ( $query[ 'date' ] instanceof \DateTime ) {
		$date = clone $query[ 'date' ];
		$date->setTimezone( new \DateTimeZone( 'UTC' ) );
		$date_string  = $date->format( 'Y-m-d H:i:s' );
		$comparator   = $this->validate_sql_comparator( $query[ 'date_compare' ] );
		$sql          .= " AND a.scheduled_date_gmt $comparator %s";
		$sql_params[] = $date_string;
	}

	if ( $query[ 'modified' ] instanceof \DateTime ) {
		$modified = clone $query[ 'modified' ];
		$modified->setTimezone( new \DateTimeZone( 'UTC' ) );
		$date_string  = $modified->format( 'Y-m-d H:i:s' );
		$comparator   = $this->validate_sql_comparator( $query[ 'modified_compare' ] );
		$sql          .= " AND a.last_attempt_gmt $comparator %s";
		$sql_params[] = $date_string;
	}

	if ( $query[ 'claimed' ] === true ) {
		$sql .= " AND a.claim_id != 0";
	} elseif ( $query[ 'claimed' ] === false ) {
		$sql .= " AND a.claim_id = 0";
	} elseif ( ! is_null( $query[ 'claimed' ] ) ) {
		$sql          .= " AND a.claim_id = %d";
		$sql_params[] = $query[ 'claimed' ];
	}

	if ( ! empty( $query['search'] ) ) {
		$sql .= " AND (a.hook LIKE %s OR (a.extended_args IS NULL AND a.args LIKE %s) OR a.extended_args LIKE %s";
		for( $i = 0; $i < 3; $i++ ) {
			$sql_params[] = sprintf( '%%%s%%', $query['search'] );
		}

		$search_claim_id = (int) $query['search'];
		if ( $search_claim_id ) {
			$sql .= ' OR a.claim_id = %d';
			$sql_params[] = $search_claim_id;
		}

		$sql .= ')';
	}

	if ( 'select' === $select_or_count ) {
		switch ( $query['orderby'] ) {
			case 'hook':
				$orderby = 'a.hook';
				break;
			case 'group':
				$orderby = 'g.slug';
				break;
			case 'modified':
				$orderby = 'a.last_attempt_gmt';
				break;
			case 'date':
			default:
				$orderby = 'a.scheduled_date_gmt';
				break;
		}
		if ( strtoupper( $query[ 'order' ] ) == 'ASC' ) {
			$order = 'ASC';
		} else {
			$order = 'DESC';
		}
		$sql .= " ORDER BY $orderby $order";
		if ( $query[ 'per_page' ] > 0 ) {
			$sql          .= " LIMIT %d, %d";
			$sql_params[] = $query[ 'offset' ];
			$sql_params[] = $query[ 'per_page' ];
		}
	}

	if ( ! empty( $sql_params ) ) {
		$sql = $wpdb->prepare( $sql, $sql_params );
	}

	return $sql;
}