Restrict_Content_Tokens::rc_token( $value,  $pieces,  $recipe_id,  $trigger_data,  $user_id,  $replace_args = array() )


Parameters Parameters

$value

(Required)

$pieces

(Required)

$recipe_id

(Required)

$trigger_data

(Required)

$user_id

(Required)


Top ↑

Return Return

(string|null)


Source Source

File: src/integrations/restrict-content/tokens/restrict-content-tokens.php

	public function rc_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args = array() ) {

		if ( $pieces ) {
			if ( in_array( 'RCPURCHASESMEMBERSHIP', $pieces ) ) {
				if ( ! absint( $user_id ) ) {
					return $value;
				}

				if ( ! absint( $recipe_id ) ) {
					return $value;
				}


				$replace_pieces = $replace_args['pieces'];
				$trigger_log_id = $replace_args['trigger_log_id'];
				$run_number     = $replace_args['run_number'];
				$user_id        = $replace_args['user_id'];
				$trigger_id     = absint( $replace_pieces[0] );

				$membership_id = Automator()->get->get_trigger_log_meta(
					'RCMEMBERSHIPLEVEL_MEMBERSHIPID',
					$trigger_id,
					$trigger_log_id,
					$run_number,
					$user_id
				);

				if ( $membership_id ) {
					$membership = rcp_get_membership( $membership_id );

					if ( false !== $membership ) {
						switch ( $pieces[2] ) {
							case 'RCMEMBERSHIPLEVEL':
								return $membership->get_membership_level_name();
								break;
							case 'RCMEMBERSHIPLEVEL_INITIAL':
								return $membership->get_initial_amount();
								break;
							case 'RCMEMBERSHIPLEVEL_RECURRING':
								return $membership->get_recurring_amount();
								break;
						}
					}
				}
			}
		}

		return $value;
	}