Pmp_Tokens::pmp_token( $value,  $pieces,  $recipe_id,  $trigger_data,  $user_id,  $replace_args )


Parameters Parameters

$value

(Required)

$pieces

(Required)

$recipe_id

(Required)

$trigger_data

(Required)

$user_id

(Required)

$replace_args

(Required)


Top ↑

Return Return

(string|null)


Source Source

File: src/integrations/paid-memberships-pro/tokens/pmp-tokens.php

	public function pmp_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {

		if ( $pieces ) {
			if ( in_array( 'PMPMEMBERSHIP', $pieces ) ) {
				global $wpdb;
				$trigger_id     = $pieces[0];
				$field          = $pieces[2];
				$trigger_log_id = isset( $replace_args['trigger_log_id'] ) ? absint( $replace_args['trigger_log_id'] ) : 0;
				$qry            = "SELECT meta_value
									FROM {$wpdb->prefix}uap_trigger_log_meta
									WHERE meta_key = '$field'
									AND automator_trigger_log_id = $trigger_log_id
									AND automator_trigger_id = $trigger_id
									LIMIT 0,1";
				$entry          = $wpdb->get_var( $qry );
				$entry          = maybe_unserialize( $entry );
				if ( $entry ) {
					$level = pmpro_getLevel( $entry );
					if ( $level ) {
						if ( 'PMPMEMBERSHIP' === $field ) {
							$value = $level->name;
						} elseif ( 'PMPMEMBERSHIP_ID' === $field ) {
							$value = $entry;
						}
					}
				}
			}
		}

		return $value;
	}