GravityView  2.10.1
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Private Member Functions
GravityView_Duplicate_Entry Class Reference

Public Member Functions

 __construct ()
 
 _filter_sortable_fields ( $fields)
 Prevent users from being able to sort by the Duplicate field. More...
 
 add_available_field ( $available_fields=array())
 Add Duplicate Entry Link to the Add Field dialog. More...
 
 add_default_field ( $entry_default_fields, $form=array(), $zone='')
 Add Edit Link as a default field, outside those set in the Gravity Form form. More...
 
 add_reserved_arg ( $args)
 Adds "duplicate" to the list of internal reserved query args. More...
 
 add_template_path ( $file_paths)
 Include this extension templates path. More...
 
 display_message ()
 
 duplicate_link_field_options ( $field_options, $template_id, $field_id, $context, $input_type)
 Add "Duplicate Link Text" setting to the edit_link field settings. More...
 
 make_duplicate_link_row ( $form_id, $field_id, $value, $entry, $query_string)
 Add a Duplicate link to the row of actions on the entry list in the backend. More...
 
 maybe_display_message ( $current_view_id=0)
 After processing duplicate entry, the user will be redirected to the referring View or embedded post/page. More...
 
 maybe_duplicate_list ( $form_id)
 Perhaps duplicate this entry if the action has been corrected. More...
 
 maybe_not_visible ( $visible, $field, $view)
 Hide the field or not. More...
 
 modify_visibility_caps ( $visibility_caps=array(), $template_id='', $field_id='', $context='', $input_type='')
 Change wording for the Edit context to read Entry Creator. More...
 
 process_duplicate ()
 Handle the duplication request, if $_GET['action'] is set to "duplicate". More...
 
 verify_nonce ()
 Is the current nonce valid for editing the entry? More...
 

Static Public Member Functions

static check_user_cap_duplicate_entry ( $entry, $field=array(), $view_id=0)
 checks if user has permissions to view the link or duplicate a specific entry More...
 
static get_confirm_dialog ()
 Get the onclick attribute for the confirm dialogs that warns users before they duplicate an entry. More...
 
static get_duplicate_link ( $entry, $view_id, $post_id=null)
 Generate a nonce link with the base URL of the current View embed. More...
 
static get_nonce_key ( $entry_id)
 Generate a consistent nonce key based on the Entry ID. More...
 
static getInstance ()
 Return the instantiated class object. More...
 

Data Fields

 $view_id
 

Static Public Attributes

static $file
 
static $instance
 

Private Member Functions

 add_hooks ()
 
 duplicate_entry ( $entry)
 Duplicate the entry. More...
 
 user_can_duplicate_entry ( $entry=array(), $view_id=null)
 Check if the user can edit the entry. More...
 

Detailed Description

Since
2.5

Definition at line 22 of file class-duplicate-entry.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Definition at line 36 of file class-duplicate-entry.php.

References add_hooks().

Member Function Documentation

◆ _filter_sortable_fields()

_filter_sortable_fields (   $fields)

Prevent users from being able to sort by the Duplicate field.

Since
2.8.3
Parameters
array$fieldsArray of field types not editable by users
Returns
array

Definition at line 156 of file class-duplicate-entry.php.

◆ add_available_field()

add_available_field (   $available_fields = array())

Add Duplicate Entry Link to the Add Field dialog.

Since
2.5
Parameters
array$available_fields
Returns
array Fields with duplicate_link added

Definition at line 259 of file class-duplicate-entry.php.

◆ add_default_field()

add_default_field (   $entry_default_fields,
  $form = array(),
  $zone = '' 
)

Add Edit Link as a default field, outside those set in the Gravity Form form.

Since
2.5
Parameters
array$entry_default_fieldsExisting fields
string | array$formform_ID or form object
string$zoneEither 'single', 'directory', 'edit', 'header', 'footer'
Returns
array $entry_default_fields, with duplicate_link added. Won't be added if in Edit Entry context.

Definition at line 236 of file class-duplicate-entry.php.

◆ add_hooks()

add_hooks ( )
private
Since
2.5

Definition at line 45 of file class-duplicate-entry.php.

Referenced by __construct().

◆ add_reserved_arg()

add_reserved_arg (   $args)

Adds "duplicate" to the list of internal reserved query args.

Since
2.10
Parameters
array$argsExisting reserved args
Returns
array

Definition at line 84 of file class-duplicate-entry.php.

References $args.

◆ add_template_path()

add_template_path (   $file_paths)

Include this extension templates path.

Since
2.5
Parameters
array$file_pathsList of template paths ordered
Returns
array File paths, with duplicate field path added at index 117

Definition at line 174 of file class-duplicate-entry.php.

◆ check_user_cap_duplicate_entry()

static check_user_cap_duplicate_entry (   $entry,
  $field = array(),
  $view_id = 0 
)
static

checks if user has permissions to view the link or duplicate a specific entry

Since
2.5
Parameters
array$entryGravity Forms entry array
array$fieldField settings (optional)
int$view_idPass a View ID to check caps against. If not set, check against current View
Returns
bool

Definition at line 658 of file class-duplicate-entry.php.

References $entry, $field, gravityview(), and GVCommon\has_cap().

◆ display_message()

display_message ( )
Runs Filter:
gravityview/duplicate-entry/message Modify the Duplicate Entry messages. Allows HTML; will not be further sanitized.
Since
2.5
Parameters
string$messageMessage to be displayed, sanitized using esc_attr()
string$statusMessage status (error or success)
string$message_from_urlThe original error message, if any, without the "There was an error duplicating the entry:" prefix

Definition at line 760 of file class-duplicate-entry.php.

References $class, and Utils\_GET().

Referenced by maybe_display_message().

◆ duplicate_entry()

duplicate_entry (   $entry)
private

Duplicate the entry.

Done after all the checks in self::process_duplicate.

Since
2.5
Parameters
array$entryThe entry to be duplicated
Returns
WP_Error|boolean
Runs Filter:
gravityview/entry/duplicate/details Modify the new entry details before it's created.
Since
2.5
Parameters
[in,out]array$rowThe entry details
array$entryThe original entry
Runs Filter:
gravityview/entry/duplicate/meta Modify the new entry meta details.
Parameters
[in,out]array$save_this_metaThe duplicate meta. Use/add meta_key, meta_value, item_index.
array$rowThe duplicated entry
array$entryThe original entry
Runs Actions:
gravityview/duplicate-entry/duplicated Triggered when an entry is duplicated
Since
2.5
Parameters
array$duplicated_entryThe duplicated entry
array$entryThe original entry

Definition at line 456 of file class-duplicate-entry.php.

References $entry, GV\$form, Utils\_SERVER(), GV\get(), and gravityview().

Referenced by maybe_duplicate_list(), and process_duplicate().

◆ duplicate_link_field_options()

duplicate_link_field_options (   $field_options,
  $template_id,
  $field_id,
  $context,
  $input_type 
)

Add "Duplicate Link Text" setting to the edit_link field settings.

Since
2.5
Parameters
array$field_options[description]
[type]$template_id [description]
[type]$field_id [description]
[type]$context [description]
[type]$input_type [description]
Returns
array [description]

Definition at line 196 of file class-duplicate-entry.php.

References $field_id, and GravityView_Render_Settings\get_cap_choices().

◆ get_confirm_dialog()

static get_confirm_dialog ( )
static

Get the onclick attribute for the confirm dialogs that warns users before they duplicate an entry.

Since
2.5
Returns
string HTML onclick attribute
Runs Filter:
gravityview/duplicate-entry/confirm-text Modify the Duplicate Entry Javascript confirmation text (will be sanitized when output)
Parameters
string$confirmDefault: "Are you sure you want to duplicate this entry?". If empty, disable confirmation dialog.

Definition at line 592 of file class-duplicate-entry.php.

◆ get_duplicate_link()

static get_duplicate_link (   $entry,
  $view_id,
  $post_id = null 
)
static

Generate a nonce link with the base URL of the current View embed.

We don't want to link to the single entry, because when duplicated, there would be nothing to return to.

Since
2.5
Parameters
array$entryGravity Forms entry array
int$view_idThe View id. Not optional since 2.0
int$post_idID of the current post/page being embedded on, if any
Returns
string|null If directory link is valid, the URL to process the duplicate request. Otherwise, NULL.

Definition at line 329 of file class-duplicate-entry.php.

References $entry, GravityView_API\directory_link(), and gravityview().

◆ get_nonce_key()

static get_nonce_key (   $entry_id)
static

Generate a consistent nonce key based on the Entry ID.

Since
2.5
Parameters
int$entry_idEntry ID
Returns
string Key used to validate request

Definition at line 311 of file class-duplicate-entry.php.

◆ getInstance()

static getInstance ( )
static

Return the instantiated class object.

Since
2.5
Returns
GravityView_Duplicate_Entry

Definition at line 97 of file class-duplicate-entry.php.

Referenced by maybe_duplicate_list().

◆ make_duplicate_link_row()

make_duplicate_link_row (   $form_id,
  $field_id,
  $value,
  $entry,
  $query_string 
)

Add a Duplicate link to the row of actions on the entry list in the backend.

Since
2.5.1
Parameters
int$form_idThe form ID.
int$field_idThe field ID.
string$valueThe value.
array$entryThe entry.
string$query_stringThe query.
Returns
void
Runs Filter:
gravityview/duplicate/backend/enable Disables the duplicate link on the backend.
Parameters
[in,out]boolean$enableTrue by default. Enabled.
int$form_idThe form ID.

Definition at line 807 of file class-duplicate-entry.php.

References $form_id.

◆ maybe_display_message()

maybe_display_message (   $current_view_id = 0)

After processing duplicate entry, the user will be redirected to the referring View or embedded post/page.

Display a message on redirection.

If success, there will be status URL parameters status=>success If an error, there will be status and message URL parameters status=>error&message=example

Since
2.5
Parameters
int$current_view_idThe ID of the View being rendered
Returns
void

Definition at line 747 of file class-duplicate-entry.php.

References display_message().

◆ maybe_duplicate_list()

maybe_duplicate_list (   $form_id)

Perhaps duplicate this entry if the action has been corrected.

Since
2.5.1
Parameters
int$form_idThe form ID.
Returns
void

Definition at line 835 of file class-duplicate-entry.php.

References $entry, duplicate_entry(), getInstance(), gravityview(), GVCommon\has_cap(), and GravityView_Logging\is_logging_active().

◆ maybe_not_visible()

maybe_not_visible (   $visible,
  $field,
  $view 
)

Hide the field or not.

For non-logged in users. For users that have no duplicate rights on any of the current entries.

Parameters
bool$visibleVisible or not.
\GV\Field$fieldThe field.
\GV\View$viewThe View context.
Returns
bool

Definition at line 118 of file class-duplicate-entry.php.

References $entry, $field, and GV\get().

◆ modify_visibility_caps()

modify_visibility_caps (   $visibility_caps = array(),
  $template_id = '',
  $field_id = '',
  $context = '',
  $input_type = '' 
)

Change wording for the Edit context to read Entry Creator.

Since
2.5
Parameters
array$visibility_capsArray of capabilities to display in field dropdown.
string$field_typeType of field options to render (field or widget)
string$template_idTable slug
float | string$field_idGF Field ID - Example: 3, 5.2, entry_link, created_by
string$contextWhat context are we in? Example: single or directory
string$input_type(textarea, list, select, etc.)
Returns
array Array of field options with label, value, type, default keys

Definition at line 286 of file class-duplicate-entry.php.

References $field_id.

◆ process_duplicate()

process_duplicate ( )

Handle the duplication request, if $_GET['action'] is set to "duplicate".

  1. Check referrer validity
  2. Make sure there's an entry with the slug of $_GET['entry_id']
  3. If so, attempt to duplicate the entry. If not, set the error status
  4. Remove action=duplicate from the URL
  5. Redirect to the page using wp_safe_redirect()
Since
2.5

wp_safe_redirect()

Returns
void|string $url URL during tests instead of redirect.

Definition at line 363 of file class-duplicate-entry.php.

References $entry, $entry_slug, duplicate_entry(), gravityview(), gravityview_get_entry(), and user_can_duplicate_entry().

◆ user_can_duplicate_entry()

user_can_duplicate_entry (   $entry = array(),
  $view_id = null 
)
private

Check if the user can edit the entry.

  • Is the nonce valid?
  • Does the user have the right caps for the entry
  • Is the entry in the trash?
Since
2.5
Parameters
array$entryGravity Forms entry array
int$view_idID of the View being rendered
Returns
boolean|WP_Error True: can edit form. WP_Error: nope.

Definition at line 624 of file class-duplicate-entry.php.

References gravityview().

Referenced by process_duplicate().

◆ verify_nonce()

verify_nonce ( )

Is the current nonce valid for editing the entry?

Since
2.5
Returns
boolean
Runs Filter:
gravityview/duplicate-entry/verify_nonce Override Duplicate Entry nonce validation. Return true to declare nonce valid.
Since
2.5
See also
wp_verify_nonce()
Parameters
int | boolean$validFalse if invalid; 1 or 2 when nonce was generated
string$nonce_keyName of nonce action used in wp_verify_nonce. $_GET['duplicate'] holds the nonce value itself. Default: duplicate_{entry_id}

Definition at line 562 of file class-duplicate-entry.php.

Field Documentation

◆ $file

$file
static

Definition at line 27 of file class-duplicate-entry.php.

◆ $instance

$instance
static

Definition at line 32 of file class-duplicate-entry.php.

◆ $view_id

$view_id

Definition at line 34 of file class-duplicate-entry.php.


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