GravityView  2.10.1
The best, easiest way to display Gravity Forms entries on your website.
class-delete-entry-admin.php
Go to the documentation of this file.
1 <?php
2 /**
3  * GravityView Delete Entry - Admin logic
4  *
5  * @package GravityView
6  * @license GPL2+
7  * @author GravityView <[email protected]>
8  * @link http://gravityview.co
9  * @copyright Copyright 2014, Katz Web Services, Inc.
10  */
11 
12 if ( ! defined( 'WPINC' ) ) {
13  die;
14 }
15 
16 
18 
19  protected $loader;
20 
22  $this->loader = $loader;
23  }
24 
25  public function load() {
26 
27  if ( ! is_admin() ) {
28  return;
29  }
30 
31  // Add Delete Entry settings to View Settings Metabox.
32  add_action( 'gravityview/metaboxes/delete_entry', array( $this, 'view_settings_metabox' ) );
33 
34  // For the Delete Entry Link, you don't want visible to all users.
35  add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 );
36 
37  // Modify the field options based on the name of the field type
38  add_filter( 'gravityview_template_delete_link_options', array( $this, 'delete_link_field_options' ), 10, 5 );
39 
40  // Add Delete Entry settings to View Settings
41  add_action( 'gravityview/metaboxes/delete_entry', array( $this, 'view_settings_delete_entry_metabox' ), 7 );
42 
43  // Add Delete Link as a default field, outside those set in the Gravity Form form
44  add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 );
45  }
46 
47  /**
48  * Render Delete Entry View metabox settings
49  *
50  * @since 2.9.1
51  *
52  * @param $current_settings
53  *
54  * @return void
55  */
57 
59 
61  }
62 
63  /**
64  * Change wording for the Edit context to read Entry Creator
65  *
66  * @since 1.5.1
67  * @since 2.9.2 Moved here from GravityView_Delete_Entry
68  *
69  * @param array $visibility_caps Array of capabilities to display in field dropdown.
70  * @param string $field_type Type of field options to render (`field` or `widget`)
71  * @param string $template_id Table slug
72  * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
73  * @param string $context What context are we in? Example: `single` or `directory`
74  * @param string $input_type (textarea, list, select, etc.)
75  *
76  * @return array Array of field options with `label`, `value`, `type`, `default` keys
77  */
78  public function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) {
79 
80  $caps = $visibility_caps;
81 
82  // If we're configuring fields in the edit context, we want a limited selection
83  if ( $field_id === 'delete_link' ) {
84 
85  // Remove other built-in caps.
86  unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] );
87 
88  $caps['read'] = _x( 'Entry Creator', 'User capability', 'gravityview' );
89  }
90 
91  return $caps;
92  }
93 
94  /**
95  * Add "Delete Link Text" setting to the edit_link field settings
96  *
97  * @since 1.5.1
98  * @since 2.9.2 Moved here from GravityView_Delete_Entry
99  *
100  * @param array $field_options
101  * @param string $template_id
102  * @param string $field_id
103  * @param string $context
104  * @param string $input_type
105  *
106  * @return array $field_options, with "Delete Link Text" and "Allow the following users to delete the entry:" field options.
107  */
108  public function delete_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
109 
110  // Always a link, never a filter
111  unset( $field_options['show_as_link'], $field_options['search_filter'] );
112 
113  // Delete Entry link should only appear to visitors capable of editing entries
114  unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
115 
116  $add_option['delete_link'] = array(
117  'type' => 'text',
118  'label' => __( 'Delete Link Text', 'gravityview' ),
119  'desc' => null,
120  'value' => __( 'Delete Entry', 'gravityview' ),
121  'merge_tags' => true,
122  );
123 
124  $field_options['allow_edit_cap'] = array(
125  'type' => 'select',
126  'label' => __( 'Allow the following users to delete the entry:', 'gravityview' ),
127  'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
128  'tooltip' => 'allow_edit_cap',
129  'class' => 'widefat',
130  'value' => 'read', // Default: entry creator
131  'group' => 'visibility',
132  'priority' => 100,
133  );
134 
135  return array_merge( $add_option, $field_options );
136  }
137 
138 
139  /**
140  * Add Delete Entry Link to the Add Field dialog
141  *
142  * @since 1.5.1
143  * @since 2.9.2 Moved here from GravityView_Delete_Entry
144  *
145  * @param array $available_fields
146  *
147  * @return array
148  */
149  public function add_available_field( $available_fields = array() ) {
150 
151  $available_fields['delete_link'] = array(
152  'label_text' => __( 'Delete Entry', 'gravityview' ),
153  'field_id' => 'delete_link',
154  'label_type' => 'field',
155  'input_type' => 'delete_link',
156  'field_options' => null,
157  'icon' => 'dashicons-trash',
158  );
159 
160  return $available_fields;
161  }
162 
163  /**
164  * Render Delete Entry Permissions settings
165  *
166  * @since 2.9.2
167  *
168  * @param $current_settings
169  *
170  * @return void
171  */
173 
175 
176  }
177 
178  /**
179  * Add Edit Link as a default field, outside those set in the Gravity Form form
180  *
181  * @since 1.5.1
182  * @since 2.9.2 Moved here from GravityView_Delete_Entry
183  *
184  * @param array $entry_default_fields Existing fields
185  * @param string|array $form form_ID or form object
186  * @param string $zone Either 'single', 'directory', 'edit', 'header', 'footer'
187  *
188  * @return array
189  */
190  public function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
191 
192  if ( 'edit' !== $zone ) {
193  $entry_default_fields['delete_link'] = array(
194  'label' => __( 'Delete Entry', 'gravityview' ),
195  'type' => 'delete_link',
196  'desc' => __( 'A link to delete the entry. Respects the Delete Entry permissions.', 'gravityview' ),
197  'icon' => 'dashicons-trash',
198  );
199  }
200 
201  return $entry_default_fields;
202  }
203 }
view_settings_metabox( $current_settings)
Render Delete Entry View metabox settings.
load()
static render_setting_row( $key='', $current_settings=array(), $override_input=null, $name='template_settings[%s]', $id='gravityview_se_%s')
Output a table row for view settings.
add_available_field( $available_fields=array())
Add Delete Entry Link to the Add Field dialog.
if(gravityview() ->plugin->is_GF_25()) $form
add_default_field( $entry_default_fields, $form=array(), $zone='')
Add Edit Link as a default field, outside those set in the Gravity Form form.
$current_settings
view_settings_delete_entry_metabox( $current_settings)
Render Delete Entry Permissions settings.
$field_id
Definition: time.php:17
__construct(GravityView_Delete_Entry $loader)
delete_link_field_options( $field_options, $template_id, $field_id, $context, $input_type)
Add "Delete Link Text" setting to the edit_link field settings.
$loader
modify_visibility_caps( $visibility_caps=array(), $template_id='', $field_id='', $context='', $input_type='')
Change wording for the Edit context to read Entry Creator.
static get_cap_choices( $template_id='', $field_id='', $context='', $input_type='')
Get capabilities options for GravityView.