GravityView  1.19.4
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 Katz Web Services, Inc.
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_tooltips', array( $this, 'tooltips') );
42 
43  // custom fields' options for zone EDIT
44  add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 );
45  }
46 
47  /**
48  * Add Edit Link as a default field, outside those set in the Gravity Form form
49  * @param array $entry_default_fields Existing fields
50  * @param string|array $form form_ID or form object
51  * @param string $zone Either 'single', 'directory', 'header', 'footer'
52  */
53  function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
54 
55  if( $zone !== 'edit' ) {
56 
57  $entry_default_fields['edit_link'] = array(
58  'label' => __('Edit Entry', 'gravityview'),
59  'type' => 'edit_link',
60  'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'),
61  );
62 
63  }
64 
65  return $entry_default_fields;
66  }
67 
68  /**
69  * Change wording for the Edit context to read Entry Creator
70  *
71  * @param array $visibility_caps Array of capabilities to display in field dropdown.
72  * @param string $field_type Type of field options to render (`field` or `widget`)
73  * @param string $template_id Table slug
74  * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
75  * @param string $context What context are we in? Example: `single` or `directory`
76  * @param string $input_type (textarea, list, select, etc.)
77  * @return array Array of field options with `label`, `value`, `type`, `default` keys
78  */
79  function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) {
80 
81  $caps = $visibility_caps;
82 
83  // If we're configuring fields in the edit context, we want a limited selection
84  if( $context === 'edit' ) {
85 
86  // Remove other built-in caps.
87  unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] );
88 
89  $caps['read'] = _x('Entry Creator','User capability', 'gravityview');
90  }
91 
92  return $caps;
93  }
94 
95  /**
96  * Add "Edit Link Text" setting to the edit_link field settings
97  * @param [type] $field_options [description]
98  * @param [type] $template_id [description]
99  * @param [type] $field_id [description]
100  * @param [type] $context [description]
101  * @param [type] $input_type [description]
102  * @return [type] [description]
103  */
104  function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
105 
106  // Always a link, never a filter
107  unset( $field_options['show_as_link'], $field_options['search_filter'] );
108 
109  // Edit Entry link should only appear to visitors capable of editing entries
110  unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
111 
112  $add_option['edit_link'] = array(
113  'type' => 'text',
114  'label' => __( 'Edit Link Text', 'gravityview' ),
115  'desc' => NULL,
116  'value' => __('Edit Entry', 'gravityview'),
117  'merge_tags' => true,
118  );
119 
120  return array_merge( $add_option, $field_options );
121  }
122 
123  /**
124  * Add tooltips
125  * @param array $tooltips Existing tooltips
126  * @return array Modified tooltips
127  */
128  function tooltips( $tooltips ) {
129 
130  $return = $tooltips;
131 
132  $return['allow_edit_cap'] = array(
133  'title' => __('Limiting Edit Access', 'gravityview'),
134  'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'),
135  );
136 
137  return $return;
138  }
139 
140  /**
141  * Manipulate the fields' options for the EDIT ENTRY screen
142  * @param [type] $field_options [description]
143  * @param [type] $template_id [description]
144  * @param [type] $field_id [description]
145  * @param [type] $context [description]
146  * @param [type] $input_type [description]
147  * @return [type] [description]
148  */
149  function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
150 
151  // We only want to modify the settings for the edit context
152  if( 'edit' !== $context ) {
153 
154  /**
155  * @since 1.8.4
156  */
157  $field_options['new_window'] = array(
158  'type' => 'checkbox',
159  'label' => __( 'Open link in a new tab or window?', 'gravityview' ),
160  'value' => false,
161  );
162 
163  return $field_options;
164  }
165 
166  // Entry field is only for logged in users
167  unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
168 
169  $add_options = array(
170  'allow_edit_cap' => array(
171  'type' => 'select',
172  'label' => __( 'Make field editable to:', 'gravityview' ),
173  'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
174  'tooltip' => 'allow_edit_cap',
175  'class' => 'widefat',
176  'value' => 'read', // Default: entry creator
177  ),
178  );
179 
180  return array_merge( $field_options, $add_options );
181  }
182 
183 
184 } // end class
add_default_field($entry_default_fields, $form=array(), $zone= '')
Add Edit Link as a default field, outside those set in the Gravity Form form.
field_options($field_options, $template_id, $field_id, $context, $input_type)
Manipulate the fields&#39; options for the EDIT ENTRY screen.
tooltips($tooltips)
Add tooltips.
edit_link_field_options($field_options, $template_id, $field_id, $context, $input_type)
Add "Edit 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.
load()
$field_id
Definition: time.php:17
static get_cap_choices($template_id= '', $field_id= '', $context= '', $input_type= '')
Get capabilities options for GravityView.
__construct(GravityView_Edit_Entry $loader)