GravityView  2.17
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 Delete Entry Settings Metabox.
32  add_action( 'gravityview/metaboxes/delete_entry', array( $this, 'view_settings_metabox' ) );
33 
34  // Add Delete Entry settings to Edit Entry Settings Metabox.
35  add_action( 'gravityview/metaboxes/edit_entry', array( $this, 'view_settings_edit_entry_metabox' ), 20 );
36 
37  // For the Delete Entry Link, you don't want visible to all users.
38  add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 );
39 
40  // Modify the field options based on the name of the field type
41  add_filter( 'gravityview_template_delete_link_options', array( $this, 'delete_link_field_options' ), 10, 5 );
42 
43  // Add Delete Entry settings to View Settings
44  add_action( 'gravityview/metaboxes/delete_entry', array( $this, 'view_settings_delete_entry_metabox' ), 7 );
45 
46  // Add Delete Link as a default field, outside those set in the Gravity Form form
47  add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 );
48  }
49 
50  /**
51  * Render Delete Entry View metabox settings
52  *
53  * @since 2.9.1
54  *
55  * @param $current_settings
56  *
57  * @return void
58  */
60 
62 
64 
65  }
66 
67  /**
68  * Renders settings relating to Delete Entry that should appear in the Edit Entry metabox
69  *
70  * @since 2.11
71  *
72  * @param $current_settings
73  */
76  }
77 
78  /**
79  * Change wording for the Edit context to read Entry Creator
80  *
81  * @since 1.5.1
82  * @since 2.9.2 Moved here from GravityView_Delete_Entry
83  *
84  * @param array $visibility_caps Array of capabilities to display in field dropdown.
85  * @param string $field_type Type of field options to render (`field` or `widget`)
86  * @param string $template_id Table slug
87  * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
88  * @param string $context What context are we in? Example: `single` or `directory`
89  * @param string $input_type (textarea, list, select, etc.)
90  *
91  * @return array Array of field options with `label`, `value`, `type`, `default` keys
92  */
93  public function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) {
94 
95  $caps = $visibility_caps;
96 
97  // If we're configuring fields in the edit context, we want a limited selection
98  if ( $field_id === 'delete_link' ) {
99 
100  // Remove other built-in caps.
101  unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] );
102 
103  $caps['read'] = _x( 'Entry Creator', 'User capability', 'gk-gravityview' );
104  }
105 
106  return $caps;
107  }
108 
109  /**
110  * Add "Delete Link Text" setting to the edit_link field settings
111  *
112  * @since 1.5.1
113  * @since 2.9.2 Moved here from GravityView_Delete_Entry
114  *
115  * @param array $field_options
116  * @param string $template_id
117  * @param string $field_id
118  * @param string $context
119  * @param string $input_type
120  *
121  * @return array $field_options, with "Delete Link Text" and "Allow the following users to delete the entry:" field options.
122  */
123  public function delete_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
124 
125  // Always a link, never a filter
126  unset( $field_options['show_as_link'], $field_options['search_filter'] );
127 
128  // Delete Entry link should only appear to visitors capable of editing entries
129  unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
130 
131  $add_option['delete_link'] = array(
132  'type' => 'text',
133  'label' => __( 'Delete Link Text', 'gk-gravityview' ),
134  'desc' => null,
135  'value' => __( 'Delete Entry', 'gk-gravityview' ),
136  'merge_tags' => true,
137  );
138 
139  $field_options['allow_edit_cap'] = array(
140  'type' => 'select',
141  'label' => __( 'Allow the following users to delete the entry:', 'gk-gravityview' ),
142  'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
143  'tooltip' => 'allow_edit_cap',
144  'class' => 'widefat',
145  'value' => 'read', // Default: entry creator
146  'group' => 'visibility',
147  'priority' => 100,
148  );
149 
150  return array_merge( $add_option, $field_options );
151  }
152 
153 
154  /**
155  * Add Delete Entry Link to the Add Field dialog
156  *
157  * @since 1.5.1
158  * @since 2.9.2 Moved here from GravityView_Delete_Entry
159  *
160  * @param array $available_fields
161  *
162  * @return array
163  */
164  public function add_available_field( $available_fields = array() ) {
165 
166  $available_fields['delete_link'] = array(
167  'label_text' => __( 'Delete Entry', 'gk-gravityview' ),
168  'field_id' => 'delete_link',
169  'label_type' => 'field',
170  'input_type' => 'delete_link',
171  'field_options' => null,
172  'icon' => 'dashicons-trash',
173  );
174 
175  return $available_fields;
176  }
177 
178  /**
179  * Render Delete Entry Permissions settings
180  *
181  * @since 2.9.2
182  *
183  * @param $current_settings
184  *
185  * @return void
186  */
188 
190 
191  }
192 
193  /**
194  * Add Edit Link as a default field, outside those set in the Gravity Form form
195  *
196  * @since 1.5.1
197  * @since 2.9.2 Moved here from GravityView_Delete_Entry
198  *
199  * @param array $entry_default_fields Existing fields
200  * @param string|array $form form_ID or form object
201  * @param string $zone Either 'single', 'directory', 'edit', 'header', 'footer'
202  *
203  * @return array
204  */
205  public function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
206 
207  if ( 'edit' !== $zone ) {
208  $entry_default_fields['delete_link'] = array(
209  'label' => __( 'Delete Entry', 'gk-gravityview' ),
210  'type' => 'delete_link',
211  'desc' => __( 'A link to delete the entry. Respects the Delete Entry permissions.', 'gk-gravityview' ),
212  'icon' => 'dashicons-trash',
213  );
214  }
215 
216  return $entry_default_fields;
217  }
218 }
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.
__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.
view_settings_edit_entry_metabox( $current_settings)
Renders settings relating to Delete Entry that should appear in the Edit Entry metabox.
static get_cap_choices( $template_id='', $field_id='', $context='', $input_type='')
Get capabilities options for GravityView.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
Definition: time.php:22