Mp_Tokens::mp_possible_tokens( array $tokens = array(), array $args = array() )


Parameters Parameters

$tokens

(array) (Optional)

Default value: array()

$args

(array) (Optional)

Default value: array()


Top ↑

Return Return

(array)


Source Source

File: src/integrations/memberpress/tokens/mp-tokens.php

	public function mp_possible_tokens( $tokens = array(), $args = array() ) {
		$form_id             = $args['value'];
		$trigger_integration = $args['integration'];
		$trigger_meta        = $args['meta'];
		$mepr_options        = MeprOptions::fetch();

		$fields = array();
		if ( $mepr_options->show_fname_lname ) {
			$fields[] = [
				'tokenId'         => 'first_name',
				'tokenName'       => 'First Name',
				'tokenType'       => 'text',
				'tokenIdentifier' => $trigger_meta,
			];
			$fields[] = [
				'tokenId'         => 'last_name',
				'tokenName'       => 'Last Name',
				'tokenType'       => 'text',
				'tokenIdentifier' => $trigger_meta,
			];
		}

		if ( $mepr_options->show_address_fields && ! empty( $mepr_options->address_fields ) ) {
			foreach ( $mepr_options->address_fields as $address_field ) {
				$fields[] = [
					'tokenId'         => $address_field->field_key,
					'tokenName'       => $address_field->field_name,
					'tokenType'       => $address_field->field_type,
					'tokenIdentifier' => $trigger_meta,
				];
			}
		}

		$custom_fields = $mepr_options->custom_fields;
		if ( ! empty( $custom_fields ) ) {
			foreach ( $custom_fields as $_field ) {
				$fields[] = [
					'tokenId'         => $_field->field_key,
					'tokenName'       => $_field->field_name,
					'tokenType'       => $_field->field_type,
					'tokenIdentifier' => $trigger_meta,
				];
			}
		}

		if ( ! empty( $fields ) ) {
			$tokens = array_merge( $tokens, $fields );
		}

		return $tokens;
	}