|
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
|
|
|
|
|
17
|
|
|
class GravityView_Edit_Entry_Admin { |
|
18
|
|
|
|
|
19
|
|
|
protected $loader; |
|
20
|
|
|
|
|
21
|
|
|
function __construct( GravityView_Edit_Entry $loader ) { |
|
|
|
|
|
|
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
|
|
|
*/ |
|
59
|
|
|
public function view_settings_metabox( $current_settings ) { |
|
60
|
|
|
|
|
61
|
|
|
GravityView_Render_Settings::render_setting_row( 'edit_locking', $current_settings ); |
|
62
|
|
|
|
|
63
|
|
|
GravityView_Render_Settings::render_setting_row( 'user_edit', $current_settings ); |
|
64
|
|
|
|
|
65
|
|
|
GravityView_Render_Settings::render_setting_row( 'unapprove_edit', $current_settings ); |
|
66
|
|
|
|
|
67
|
|
|
GravityView_Render_Settings::render_setting_row( 'edit_redirect', $current_settings ); |
|
68
|
|
|
|
|
69
|
|
|
GravityView_Render_Settings::render_setting_row( 'edit_redirect_url', $current_settings ); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Add Edit Link as a default field, outside those set in the Gravity Form form |
|
74
|
|
|
* @param array $entry_default_fields Existing fields |
|
75
|
|
|
* @param string|array $form form_ID or form object |
|
76
|
|
|
* @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
77
|
|
|
*/ |
|
78
|
|
|
function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
if( $zone !== 'edit' ) { |
|
81
|
|
|
|
|
82
|
|
|
$entry_default_fields['edit_link'] = array( |
|
83
|
|
|
'label' => __('Edit Entry', 'gravityview'), |
|
84
|
|
|
'type' => 'edit_link', |
|
85
|
|
|
'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $entry_default_fields; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Change wording for the Edit context to read Entry Creator |
|
95
|
|
|
* |
|
96
|
|
|
* @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
97
|
|
|
* @param string $field_type Type of field options to render (`field` or `widget`) |
|
|
|
|
|
|
98
|
|
|
* @param string $template_id Table slug |
|
99
|
|
|
* @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
100
|
|
|
* @param string $context What context are we in? Example: `single` or `directory` |
|
101
|
|
|
* @param string $input_type (textarea, list, select, etc.) |
|
102
|
|
|
* @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
103
|
|
|
*/ |
|
104
|
|
|
function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$caps = $visibility_caps; |
|
107
|
|
|
|
|
108
|
|
|
// If we're configuring fields in the edit context, we want a limited selection |
|
109
|
|
|
if( $context === 'edit' ) { |
|
110
|
|
|
|
|
111
|
|
|
// Remove other built-in caps. |
|
112
|
|
|
unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
113
|
|
|
|
|
114
|
|
|
$caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return $caps; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Add "Edit Link Text" setting to the edit_link field settings |
|
122
|
|
|
* @param [type] $field_options [description] |
|
|
|
|
|
|
123
|
|
|
* @param [type] $template_id [description] |
|
|
|
|
|
|
124
|
|
|
* @param [type] $field_id [description] |
|
|
|
|
|
|
125
|
|
|
* @param [type] $context [description] |
|
|
|
|
|
|
126
|
|
|
* @param [type] $input_type [description] |
|
|
|
|
|
|
127
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
128
|
|
|
*/ |
|
129
|
|
|
function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
// Always a link, never a filter |
|
132
|
|
|
unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
133
|
|
|
|
|
134
|
|
|
// Edit Entry link should only appear to visitors capable of editing entries |
|
135
|
|
|
unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
136
|
|
|
|
|
137
|
|
|
$add_option['edit_link'] = array( |
|
|
|
|
|
|
138
|
|
|
'type' => 'text', |
|
139
|
|
|
'label' => __( 'Edit Link Text', 'gravityview' ), |
|
140
|
|
|
'desc' => NULL, |
|
141
|
|
|
'value' => __('Edit Entry', 'gravityview'), |
|
142
|
|
|
'merge_tags' => true, |
|
143
|
|
|
); |
|
144
|
|
|
|
|
145
|
|
|
return array_merge( $add_option, $field_options ); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Add tooltips |
|
150
|
|
|
* @param array $tooltips Existing tooltips |
|
151
|
|
|
* @return array Modified tooltips |
|
152
|
|
|
*/ |
|
153
|
|
|
function tooltips( $tooltips ) { |
|
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
$return = $tooltips; |
|
156
|
|
|
|
|
157
|
|
|
$return['allow_edit_cap'] = array( |
|
158
|
|
|
'title' => __('Limiting Edit Access', 'gravityview'), |
|
159
|
|
|
'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
160
|
|
|
); |
|
161
|
|
|
|
|
162
|
|
|
return $return; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Manipulate the fields' options for the EDIT ENTRY screen |
|
167
|
|
|
* @param [type] $field_options [description] |
|
|
|
|
|
|
168
|
|
|
* @param [type] $template_id [description] |
|
|
|
|
|
|
169
|
|
|
* @param [type] $field_id [description] |
|
|
|
|
|
|
170
|
|
|
* @param [type] $context [description] |
|
|
|
|
|
|
171
|
|
|
* @param [type] $input_type [description] |
|
|
|
|
|
|
172
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
173
|
|
|
*/ |
|
174
|
|
|
public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) { |
|
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
// We only want to modify the settings for the edit context |
|
177
|
|
|
if( 'edit' !== $context ) { |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @since 1.8.4 |
|
181
|
|
|
*/ |
|
182
|
|
|
$field_options['new_window'] = array( |
|
183
|
|
|
'type' => 'checkbox', |
|
184
|
|
|
'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
185
|
|
|
'value' => false, |
|
186
|
|
|
); |
|
187
|
|
|
|
|
188
|
|
|
return $field_options; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
// Entry field is only for logged in users |
|
192
|
|
|
unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
193
|
|
|
|
|
194
|
|
|
$add_options = array( |
|
195
|
|
|
'allow_edit_cap' => array( |
|
196
|
|
|
'type' => 'select', |
|
197
|
|
|
'label' => __( 'Make field editable to:', 'gravityview' ), |
|
198
|
|
|
'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
199
|
|
|
'tooltip' => 'allow_edit_cap', |
|
200
|
|
|
'class' => 'widefat', |
|
201
|
|
|
'value' => 'read', // Default: entry creator |
|
202
|
|
|
), |
|
203
|
|
|
); |
|
204
|
|
|
|
|
205
|
|
|
return array_merge( $field_options, $add_options ); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
} // end class |
|
210
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.