Wpwh_Tokens::wpwh_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/wp-webhooks/tokens/wpwh-tokens.php

	function wpwh_possible_tokens( $tokens = array(), $args = array() ) {
		if ( 'WPWHTRIGGER' === $args['meta'] ) {
			$trigger_meta = $args['meta'];
			$triggers     = WPWHPRO()->webhook->get_triggers();

			if ( ! empty( $triggers ) ) {
				$returns_code = array();
				if ( ! empty( $args['value'] ) ) {
					switch ( $args['value'] ) {
						case 'create_user':
						case 'login_user':
						case 'update_user':
							$possible_tokens = [
								'ID',
								'user_login',
								'user_pass',
								'user_nicename',
								'user_email',
								'user_url',
								'user_registered',
								'user_activation_key',
								'user_status',
								'display_name',
							];
							foreach ( $possible_tokens as $_token ) {
								$fields[] = [
									'tokenId'         => 'data|' . $_token,
									'tokenName'       => $_token,
									'tokenType'       => 'text',
									'tokenIdentifier' => $trigger_meta,
								];
							}
							$tokens = array_merge( $tokens, $fields );
							break;
						case 'deleted_user':
							$possible_tokens = [
								'user_id',
								'reassign',
							];
							foreach ( $possible_tokens as $_token ) {
								$fields[] = [
									'tokenId'         => $_token,
									'tokenName'       => $_token,
									'tokenType'       => 'text',
									'tokenIdentifier' => $trigger_meta,
								];
							}
							$tokens = array_merge( $tokens, $fields );
							break;
						case 'post_create':
						case 'post_update':
						case 'post_delete':
						case 'post_trash':
							$possible_tokens = [
								'ID',
								'post_author',
								'post_date',
								'post_date_gmt',
								'post_content',
								'post_title',
								'post_excerpt',
								'post_status',
								'comment_status',
								'ping_status',
								'post_password',
								'post_name',
								'to_ping',
								'pinged',
								'post_modified',
								'post_modified_gmt',
								'post_content_filtered',
								'post_parent',
								'guid',
								'menu_order',
								'post_type',
								'post_mime_type',
								'comment_count',
								'filter',
							];
							foreach ( $possible_tokens as $_token ) {
								$fields[] = [
									'tokenId'         => 'post|' . $_token,
									'tokenName'       => $_token,
									'tokenType'       => 'text',
									'tokenIdentifier' => $trigger_meta,
								];
							}
							$tokens = array_merge( $tokens, $fields );
							break;
					}
				}
			}
		}

		return $tokens;
	}