Noptin_Subscriber_Query::query()

Execute the query, with the current variables.


Source Source

File: includes/class-noptin-subscriber-query.php

	public function query() {
		global $wpdb;

		$qv =& $this->query_vars;

		/**
		 * Filters the subscribers query array before the query takes place.
		 *
		 * Return a non-null value to bypass the default Noptin subscriber queries.
		 * Filtering functions that require pagination information are encouraged to set
		 * the `total_subscribers` property of the Noptin_Subscriber_Query object, passed to the filter
		 * by reference. If Noptin_Subscriber_Query does not perform a database query, it will not
		 * have enough information to generate these values itself.
		 *
		 * @since 1.2.7
		 *
		 * @param array|null              $results Return an array of subscriber data to short-circuit the subscriber query
		 *                                or null to allow Noptin to run its normal queries.
		 * @param Noptin_Subscriber_Query $this The Noptin_Subscriber_Query instance (passed by reference).
		 */
		$this->results = apply_filters_ref_array( 'noptin_subscribers_pre_query', array( null, &$this ) );

		if ( null === $this->results ) {
			$this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";

			if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
				$this->results = $wpdb->get_results( $this->request );
			} else {
				$this->results = $wpdb->get_col( $this->request );
			}

			if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
				/**
				 * Filters SELECT FOUND_ROWS() query for the current Noptin_Subscriber_Query instance.
				 *
				 * @since 1.2.7
				 *
				 * @global wpdb $wpdb WordPress database abstraction object.
				 *
				 * @param string $sql         The SELECT FOUND_ROWS() query for the current Noptin_Subscriber_Query.
				 * @param Noptin_Subscriber_Query $this The current Noptin_Subscriber_Query instance.
				 */
				$found_subscribers_query = apply_filters( 'noptin_found_subscribers_query', 'SELECT FOUND_ROWS()', $this );

				$this->total_subscribers = (int) $wpdb->get_var( $found_subscribers_query );
			}
		}

		if ( ! $this->results ) {
			return;
		}

		if ( 'all_with_meta' === $qv['fields'] ) {

			$r = array();
			foreach ( $this->results as $subscriber_id ) {
				$r[ $subscriber_id ] = new Noptin_Subscriber( $subscriber_id );
			}

			$this->results = $r;
		} elseif ( 'all' == $qv['fields'] ) {
			foreach ( $this->results as $key => $subscriber ) {
				$this->results[ $key ] = new Noptin_Subscriber( $subscriber );
			}
		}
	}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.2.7Introduced.

Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation