ap_get_subscribers( array $where = array(), null $event = null, null $ref_id = null )

Description #

Get subscribers. Total subscribers count will be returned if no argument is passed.

Parameters #

  • $where
    array (Optional) Where clauses.
    • 'subs_event'
      (string) Event type.
    • 'subs_ref_id'
      (integer) Reference id.
    • 'subs_user_id'
      (integer) User id.
    Default value: array()
  • $event
    null (Optional) Deprecated. Default value: null
  • $ref_id
    null (Optional) Deprecated. Default value: null

Changelog #

VersionDescription
4.1.5Introduced.

Source #

File: includes/subscribers.php

function ap_get_subscribers( $where = array(), $event = null, $ref_id = null ) {
	if ( null !== $event || null !== $ref_id ) {
		_deprecated_argument( __FUNCTION__, '4.1.5', esc_attr__( 'All 2 arguments $event and $ref_id are deprecated.', 'anspress-question-answer' ) );
	}

	global $wpdb;

	$where = wp_parse_args(
		$where,
		array(
			'subs_event'   => '',
			'subs_ref_id'  => '',
			'subs_user_id' => '',
		)
	);

	$where = wp_array_slice_assoc( $where, array( 'subs_event', 'subs_ref_id', 'subs_user_id' ) );

	// Return if where clauses are empty.
	if ( empty( $where ) ) {
		return;
	}

	$query = '';

	if ( isset( $where['subs_ref_id'] ) && $where['subs_ref_id'] > 0 ) {
		$query .= $wpdb->prepare( ' AND s.subs_ref_id = %d', $where['subs_ref_id'] );
	}

	if ( ! empty( $where['subs_event'] ) ) {
		$query .= $wpdb->prepare( ' AND s.subs_event = %s', $where['subs_event'] );
	}

	if ( ! empty( $where['subs_user_id'] ) ) {
		$query .= $wpdb->prepare( ' AND s.subs_user_id = %s', $where['subs_user_id'] );
	}

	$results = $wpdb->get_results( "SELECT * FROM {$wpdb->ap_subscribers} s LEFT JOIN {$wpdb->users} u ON u.ID = s.subs_user_id WHERE 1=1 {$query}" ); // phpcs:ignore WordPress.DB

	return $results;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment