You appear to be a bot. Output may be restricted
Description
Returns the SQL statement to query (or count) actions.
Usage
$string = ActionScheduler_wpPostStore::get_query_actions_sql( $query, $select_or_count );
Parameters
- $query
- ( array ) required – Filtering options
- $select_or_count
- ( string ) optional default: select – Whether the SQL should select and return the IDs or just the row count
Returns
string SQL statement. The returned SQL is already properly escaped.
Source
File name: woocommerce/packages/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php
Lines:
1 to 100 of 129
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 schedule. Cannot save action.', 'woocommerce' ) ); } $query = wp_parse_args( $query, array( 'hook' => '', 'args' => NULL, 'date' => NULL, 'date_compare' => '<=', 'modified' => NULL, 'modified_compare' => '<=', 'group' => '', 'status' => '', 'claimed' => NULL, 'per_page' => 5, 'offset' => 0, 'orderby' => 'date', 'order' => 'ASC', 'search' => '', ) ); /** @var wpdb $wpdb */ global $wpdb; $sql = ( 'count' === $select_or_count ) ? 'SELECT count(p.ID)' : 'SELECT p.ID '; $sql .= "FROM {$wpdb->posts} p"; $sql_params = array(); if ( empty( $query['group'] ) && 'group' === $query['orderby'] ) { $sql .= " LEFT JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID"; $sql .= " LEFT JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id"; $sql .= " LEFT JOIN {$wpdb->terms} t ON tt.term_id=t.term_id"; } elseif ( ! empty( $query['group'] ) ) { $sql .= " INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID"; $sql .= " INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id"; $sql .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id"; $sql .= " AND t.slug=%s"; $sql_params[] = $query['group']; } $sql .= " WHERE post_type=%s"; $sql_params[] = self::POST_TYPE; if ( $query['hook'] ) { $sql .= " AND p.post_title=%s"; $sql_params[] = $query['hook']; } if ( !is_null($query['args']) ) { $sql .= " AND p.post_content=%s"; $sql_params[] = json_encode($query['args']); } if ( ! empty( $query['status'] ) ) { $sql .= " AND p.post_status=%s"; $sql_params[] = $this->get_post_status_by_action_status( $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 p.post_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 p.post_modified_gmt $comparator %s"; $sql_params[] = $date_string; } if ( $query['claimed'] === TRUE ) { $sql .= " AND p.post_password != ''"; } elseif ( $query['claimed'] === FALSE ) { $sql .= " AND p.post_password = ''"; } elseif ( !is_null($query['claimed']) ) { $sql .= " AND p.post_password = %s"; $sql_params[] = $query['claimed']; } if ( ! empty( $query['search'] ) ) { $sql .= " AND (p.post_title LIKE %s OR p.post_content LIKE %s OR p.post_password LIKE %s)"; for( $i = 0; $i < 3; $i++ ) { $sql_params[] = sprintf( '%%%s%%', $query['search'] ); } } if ( 'select' === $select_or_count ) { switch ( $query['orderby'] ) { case 'hook': $orderby = 'p.post_title'; break; case 'group': $orderby = 't.name'; break; case 'status': $orderby = 'p.post_status';