ap_new_subscriber( integer|false $user_id = false, string $event = '', integer $ref_id )

Description #

Insert new subscriber.

Parameters #

  • $user_id
    integer | false (Optional) User ID. Default value: false
  • $event
    string (Optional) Event type. Default value: ''
  • $ref_id
    integer (Required) Reference identifier id.

Changelog #

VersionDescription
4.1.5Introduced.

Source #

File: includes/subscribers.php

function ap_new_subscriber( $user_id = false, $event = '', $ref_id = 0 ) {
	global $wpdb;

	if ( false === $user_id ) {
		$user_id = get_current_user_id();
	}

	$exists = ap_get_subscriber( $user_id, $event, $ref_id );

	if ( ! $exists ) {
		$insert = $wpdb->insert( // phpcs:ignore WordPress.DB
			$wpdb->ap_subscribers,
			array(
				'subs_user_id' => $user_id,
				'subs_event'   => sanitize_title( $event ),
				'subs_ref_id'  => $ref_id,
			),
			array( '%d', '%s', '%d' )
		);

		if ( false !== $insert ) {
			/**
			 * Hook triggered right after inserting a subscriber.
			 *
			 * @param integer $subs_id Subscription id.
			 * @param integer $user_id User id.
			 * @param string  $event   Event name.
			 * @param integer $ref_id  Reference id.
			 *
			 * @since 4.0.0
			 */
			do_action( 'ap_new_subscriber', $wpdb->insert_id, $user_id, $event, $ref_id );

			return $wpdb->insert_id;
		}
	}

	return false;
}

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