GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Data Fields | Protected Member Functions | Private Member Functions
GravityView_Entry_Approval_Merge_Tags Class Reference

If this file is called directly, abort. More...

Public Member Functions

 __construct ()
 Initialization. More...
 
 _filter_gform_custom_merge_tags ( $custom_merge_tags=array(), $form_id=0, $fields=array(), $element_id='')
 Adds custom merge tags to merge tag options. More...
 
 _filter_gform_form_settings_fields ( $fields=array(), $form=array())
 Filters existing GF Form Settings Fields. More...
 
 _filter_gform_replace_merge_tags ( $text, $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
 Matches the merge tag in replacement text for the field. More...
 
 maybe_show_approval_notice ()
 Checks page load for approval link result then maybe show notice. More...
 
 maybe_update_approved ()
 Checks page load for approval link token then maybe process it. More...
 

Data Fields

const DEFAULT_EXPIRATION_UNIT = 'hours'
 Default value for the expiration_unit modifier. More...
 
const DEFAULT_EXPIRATION_VALUE = 24
 Default value for the expiration modifier. More...
 
const FORM_SETTINGS_KEY = 'gravityview_entry_moderation'
 
const NOTICE_URL_ARG = 'gv_approval_link_result'
 
const TOKEN_URL_ARG = 'gv_token'
 The name of the query arg used to pass token information to the approval URL. More...
 

Protected Member Functions

 decode_token ( $token=false)
 Decodes received token to its original form. More...
 
 get_approval_status ( $action=false)
 Returns an approval status based on the provided action. More...
 
 get_link_url ( $token=false, $expiration_seconds=DAY_IN_SECONDS, $privacy='private')
 Generates an approval link URL. More...
 
 get_token ( $action=false, $expiration_timestamp=0, $privacy='private', $entry=array())
 Generates a JWT token based on the merge tag parameters. More...
 
 is_request_valid ( $token)
 Verifies the token. More...
 
 is_token_valid (array $token)
 Validates an approval token. More...
 
 replace_merge_tag ( $matches=array(), $text='', $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
 Replaces merge tags. More...
 
 update_approved ( $entry_id, $approval_status, $form_id, $scopes, $return_url)
 Updates the entry approval status and redirects to $return_url. More...
 

Private Member Functions

 add_hooks ()
 Adds actions and filters related to entry approval links. More...
 

Detailed Description

If this file is called directly, abort.

Handles approval links

Since
2.17

Definition at line 23 of file class-gravityview-entry-approval-merge-tags.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Initialization.

Definition at line 48 of file class-gravityview-entry-approval-merge-tags.php.

References add_hooks().

Member Function Documentation

◆ _filter_gform_custom_merge_tags()

_filter_gform_custom_merge_tags (   $custom_merge_tags = array(),
  $form_id = 0,
  $fields = array(),
  $element_id = '' 
)

Adds custom merge tags to merge tag options.

Since
2.17
Parameters
array$custom_merge_tags
int$form_idGF Form ID
GF_Field[]$fields Array of fields in the form
string$element_idThe ID of the input that Merge Tags are being used on
Returns
array Modified merge tags

Definition at line 123 of file class-gravityview-entry-approval-merge-tags.php.

◆ _filter_gform_form_settings_fields()

_filter_gform_form_settings_fields (   $fields = array(),
  $form = array() 
)

Filters existing GF Form Settings Fields.

Since
2.17
Parameters
array$fieldsArray of sections and settings fields
array$formGF Form
Returns
array Modified array of sections and settings fields

Definition at line 76 of file class-gravityview-entry-approval-merge-tags.php.

References gravityview().

◆ _filter_gform_replace_merge_tags()

_filter_gform_replace_merge_tags (   $text,
  $form = array(),
  $entry = array(),
  $url_encode = false,
  $esc_html = false 
)

Matches the merge tag in replacement text for the field.

Since
2.17
See also
replace_merge_tag Override replace_merge_tag() to handle any matches
Parameters
string$textText to replace
array$formGravity Forms form array
array$entryEntry array
bool$url_encodeWhether to URL-encode output
Returns
string Original text if {_custom_merge_tag} isn't found. Otherwise, replaced text.

Definition at line 157 of file class-gravityview-entry-approval-merge-tags.php.

References $entry, GV\$form, gravityview(), and replace_merge_tag().

◆ add_hooks()

add_hooks ( )
private

Adds actions and filters related to entry approval links.

Returns
void

Definition at line 57 of file class-gravityview-entry-approval-merge-tags.php.

Referenced by __construct().

◆ decode_token()

decode_token (   $token = false)
protected

Decodes received token to its original form.

Since
2.17
Parameters
string | bool$token
Returns
array|WP_Error Original scopes or WP Error object
Parameters
string$body_64$parts[0]
string$sig$parts[1]

Definition at line 560 of file class-gravityview-entry-approval-merge-tags.php.

Referenced by maybe_update_approved().

◆ get_approval_status()

get_approval_status (   $action = false)
protected

Returns an approval status based on the provided action.

Since
2.17
Parameters
string | bool$action
Returns
int Value of respective approval status

Definition at line 310 of file class-gravityview-entry-approval-merge-tags.php.

References GravityView_Entry_Approval_Status\get_key(), and GravityView_Entry_Approval_Status\get_values().

Referenced by get_token().

◆ get_link_url()

get_link_url (   $token = false,
  $expiration_seconds = DAY_IN_SECONDS,
  $privacy = 'private' 
)
protected

Generates an approval link URL.

Since
2.17
Parameters
string | bool$token
string$privacyApproval link privacy. Accepted values are 'private' or 'public'.
Returns
string Approval link URL

Definition at line 332 of file class-gravityview-entry-approval-merge-tags.php.

References $base_url.

Referenced by replace_merge_tag().

◆ get_token()

get_token (   $action = false,
  $expiration_timestamp = 0,
  $privacy = 'private',
  $entry = array() 
)
protected

Generates a JWT token based on the merge tag parameters.

See also
https://jwt.io
Since
2.17
Parameters
string | bool$actionAction to be taken by the merge tag.
int$expiration_timestampTimestamp when the token expires.
string$privacyApproval link privacy. Accepted values are 'private' or 'public'.
array$entryEntry array.
Returns
string Encrypted token.

Definition at line 253 of file class-gravityview-entry-approval-merge-tags.php.

References $entry, and get_approval_status().

Referenced by replace_merge_tag().

◆ is_request_valid()

is_request_valid (   $token)
protected

Verifies the token.

Since
2.17
Parameters
array$token
Returns
bool|WP_Error

Definition at line 464 of file class-gravityview-entry-approval-merge-tags.php.

References gravityview().

Referenced by maybe_update_approved().

◆ is_token_valid()

is_token_valid ( array  $token)
protected

Validates an approval token.

Since
2.17
Parameters
array$token
Returns
true|WP_Error Token is valid or there was an error.

Definition at line 613 of file class-gravityview-entry-approval-merge-tags.php.

Referenced by maybe_update_approved().

◆ maybe_show_approval_notice()

maybe_show_approval_notice ( )

Checks page load for approval link result then maybe show notice.

Since
2.17

Expects a $_GET request with the following $_GET keys and values:

Returns
void array $_GET { string $gv_approval_link_result Approval link result }

Definition at line 510 of file class-gravityview-entry-approval-merge-tags.php.

References Utils\_GET(), GVCommon\generate_notice(), and GravityView_Entry_Approval_Status\get_label().

◆ maybe_update_approved()

maybe_update_approved ( )

Checks page load for approval link token then maybe process it.

Since
2.17

Expects a $_GET request with the following $_GET keys and values:

Returns
void array $_GET { string $gv_token Approval link token string $nonce (optional) Nonce hash to be validated. Only available if $expiration_seconds is smaller than DAY_IN_SECONDS. }

Definition at line 367 of file class-gravityview-entry-approval-merge-tags.php.

References $entry, $form_id, Utils\_GET(), decode_token(), gravityview(), GVCommon\has_cap(), is_request_valid(), is_token_valid(), GravityView_Entry_Approval_Status\is_valid(), and update_approved().

◆ replace_merge_tag()

replace_merge_tag (   $matches = array(),
  $text = '',
  $form = array(),
  $entry = array(),
  $url_encode = false,
  $esc_html = false 
)
protected

Replaces merge tags.

Since
2.17
Parameters
array$matchesArray of Merge Tag matches found in text by preg_match_all
string$textText to replace
array | bool$formGravity Forms form array. When called inside {
See also
GFCommon::replace_variables()} (now deprecated), false
Parameters
array | bool$entryEntry array. When called inside {
See also
GFCommon::replace_variables()} (now deprecated), false
Parameters
bool$url_encodeWhether to URL-encode output
bool$esc_htmlWhether to apply esc_html() to output
Returns
mixed

Definition at line 188 of file class-gravityview-entry-approval-merge-tags.php.

References $entry, GV\$form, $link, GravityView_Entry_Approval_Status\get_action(), get_link_url(), and get_token().

Referenced by _filter_gform_replace_merge_tags().

◆ update_approved()

update_approved (   $entry_id,
  $approval_status,
  $form_id,
  $scopes,
  $return_url 
)
protected

Updates the entry approval status and redirects to $return_url.

Parameters
int$entry_idEntry ID.
int$approval_statusApproval status.
int$form_idForm ID.
array$scopesToken scopes to be passed to the return URL and used in {
See also
maybe_show_approval_notice()}.
Parameters
string$return_urlUrl to redirect to once moderation happens.
Returns
void

Definition at line 654 of file class-gravityview-entry-approval-merge-tags.php.

References $form_id, and GravityView_Entry_Approval\update_approved().

Referenced by maybe_update_approved().

Field Documentation

◆ DEFAULT_EXPIRATION_UNIT

const DEFAULT_EXPIRATION_UNIT = 'hours'

Default value for the expiration_unit modifier.

Definition at line 39 of file class-gravityview-entry-approval-merge-tags.php.

◆ DEFAULT_EXPIRATION_VALUE

const DEFAULT_EXPIRATION_VALUE = 24

Default value for the expiration modifier.

Definition at line 34 of file class-gravityview-entry-approval-merge-tags.php.

◆ FORM_SETTINGS_KEY

const FORM_SETTINGS_KEY = 'gravityview_entry_moderation'

◆ NOTICE_URL_ARG

const NOTICE_URL_ARG = 'gv_approval_link_result'

◆ TOKEN_URL_ARG

const TOKEN_URL_ARG = 'gv_token'

The name of the query arg used to pass token information to the approval URL.

Example: ?gv_token=eyJpYXQiOjE2NzM0ODgw[...]

Definition at line 29 of file class-gravityview-entry-approval-merge-tags.php.


The documentation for this class was generated from the following file: