GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-edit-entry-admin.php
Go to the documentation of this file.
1 <?php
2 /**
3  * GravityView Edit 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  function load() {
26 
27  if( !is_admin() ) {
28  return;
29  }
30 
31  // Add Edit Link as a default field, outside those set in the Gravity Form form
32  add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 );
33 
34  // For the Edit 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_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 );
39 
40  // add tooltips
41  add_filter( 'gravityview/metaboxes/tooltips', array( $this, 'tooltips') );
42 
43  // custom fields' options for zone EDIT
44  add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 6 );
45 
46  // Add Edit Entry settings to View Settings
47  add_action( 'gravityview/metaboxes/edit_entry', array( $this, 'view_settings_metabox' ) );
48  }
49 
50  /**
51  * Render Edit Entry View metabox settings
52  *
53  * @since 2.9
54  *
55  * @param $current_settings
56  *
57  * @return void
58  */
60 
62 
64 
66 
68 
70 
72 
74  }
75 
76  /**
77  * Add Edit Link as a default field, outside those set in the Gravity Form form
78  * @param array $entry_default_fields Existing fields
79  * @param string|array $form form_ID or form object
80  * @param string $zone Either 'single', 'directory', 'header', 'footer'
81  */
82  function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
83 
84  if( $zone !== 'edit' ) {
85 
86  $entry_default_fields['edit_link'] = array(
87  'label' => __('Link to Edit Entry', 'gk-gravityview'),
88  'type' => 'edit_link',
89  'desc' => __('A link to edit the entry. Visible based on View settings.', 'gk-gravityview'),
90  'icon' => 'dashicons-welcome-write-blog',
91  );
92 
93  }
94 
95  return $entry_default_fields;
96  }
97 
98  /**
99  * Change wording for the Edit context to read Entry Creator
100  *
101  * @param array $visibility_caps Array of capabilities to display in field dropdown.
102  * @param string $field_type Type of field options to render (`field` or `widget`)
103  * @param string $template_id Table slug
104  * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
105  * @param string $context What context are we in? Example: `single` or `directory`
106  * @param string $input_type (textarea, list, select, etc.)
107  * @return array Array of field options with `label`, `value`, `type`, `default` keys
108  */
109  function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) {
110 
111  $caps = $visibility_caps;
112 
113  // If we're configuring fields in the edit context, we want a limited selection
114  if( $context === 'edit' ) {
115 
116  // Remove other built-in caps.
117  unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] );
118 
119  $caps['read'] = _x('Entry Creator','User capability', 'gk-gravityview');
120  }
121 
122  return $caps;
123  }
124 
125  /**
126  * Add "Edit Link Text" setting to the edit_link field settings
127  *
128  * @param array $field_options
129  * @param string $template_id
130  * @param string $field_id
131  * @param string $context
132  * @param string $input_type
133  *
134  * @return array $field_options, with "Edit Link Text" field option
135  */
136  function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
137 
138  // Always a link, never a filter
139  unset( $field_options['show_as_link'], $field_options['search_filter'] );
140 
141  // Edit Entry link should only appear to visitors capable of editing entries
142  unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
143 
144  $add_option['edit_link'] = array(
145  'type' => 'text',
146  'label' => __( 'Edit Link Text', 'gk-gravityview' ),
147  'desc' => NULL,
148  'value' => __('Edit Entry', 'gk-gravityview'),
149  'merge_tags' => true,
150  );
151 
152  $add_option['new_window'] = array(
153  'type' => 'checkbox',
154  'label' => __( 'Open link in a new tab or window?', 'gk-gravityview' ),
155  'value' => false,
156  'group' => 'display',
157  'priority' => 1300,
158  );
159 
160  return array_merge( $add_option, $field_options );
161  }
162 
163  /**
164  * Add tooltips
165  * @param array $tooltips Existing tooltips
166  * @return array Modified tooltips
167  */
168  function tooltips( $tooltips ) {
169 
170  $return = $tooltips;
171 
172  $return['allow_edit_cap'] = array(
173  'title' => __('Limiting Edit Access', 'gk-gravityview'),
174  'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gk-gravityview'),
175  );
176 
177  return $return;
178  }
179 
180  /**
181  * Add "Edit Link Text" setting to the edit_link field settings
182  *
183  * @param array $field_options
184  * @param string $template_id
185  * @param string $field_id
186  * @param string $context
187  * @param string $input_type
188  * @param int $form_id
189  *
190  * @return array $field_options, with added field options
191  */
192  public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) {
193 
194  // We only want to modify the settings for the edit context
195  if( 'edit' !== $context ) {
196  return $field_options;
197  }
198 
199  // Entry field is only for logged in users
200  unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
201 
202  $add_options = array(
203  'allow_edit_cap' => array(
204  'type' => 'select',
205  'label' => __( 'Make field editable to:', 'gk-gravityview' ),
206  'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
207  'tooltip' => 'allow_edit_cap',
208  'class' => 'widefat',
209  'value' => 'read', // Default: entry creator
210  'group' => 'visibility',
211  ),
212  );
213 
214  return array_merge( $field_options, $add_options );
215  }
216 
217 
218 } // end class
edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type)
Add "Edit Link Text" setting to the edit_link field settings.
tooltips( $tooltips)
Add tooltips.
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.
field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
Add "Edit Link Text" setting to the edit_link field settings.
$loader
if(gravityview() ->plugin->is_GF_25()) $form
$current_settings
load()
view_settings_metabox( $current_settings)
Render Edit Entry View metabox settings.
if(empty( $created_by)) $form_id
static get_cap_choices( $template_id='', $field_id='', $context='', $input_type='')
Get capabilities options for GravityView.
modify_visibility_caps( $visibility_caps=array(), $template_id='', $field_id='', $context='', $input_type='')
Change wording for the Edit context to read Entry Creator.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
Definition: time.php:22
add_default_field( $entry_default_fields, $form=array(), $zone='')
Add Edit Link as a default field, outside those set in the Gravity Form form.
__construct(GravityView_Edit_Entry $loader)