1 | <?php |
||
19 | class GravityView_Edit_Entry { |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | static $file; |
||
25 | |||
26 | static $instance; |
||
27 | |||
28 | /** |
||
29 | * Component instances. |
||
30 | * @var array |
||
31 | */ |
||
32 | public $instances = array(); |
||
33 | |||
34 | |||
35 | 3 | function __construct() { |
|
54 | |||
55 | |||
56 | 4 | static function getInstance() { |
|
64 | |||
65 | |||
66 | 3 | private function load_components( $component ) { |
|
80 | |||
81 | 3 | private function add_hooks() { |
|
95 | |||
96 | /** |
||
97 | * Trigger hooks that are normally run in the admin for Addons, but need to be triggered manually because we're not in the admin |
||
98 | * @return void |
||
99 | */ |
||
100 | 3 | private function addon_specific_hooks() { |
|
107 | |||
108 | /** |
||
109 | * Include this extension templates path |
||
110 | * @param array $file_paths List of template paths ordered |
||
111 | */ |
||
112 | 25 | public function add_template_path( $file_paths ) { |
|
119 | |||
120 | /** |
||
121 | * |
||
122 | * Return a well formatted nonce key according to GravityView Edit Entry protocol |
||
123 | * |
||
124 | * @param $view_id int GravityView view id |
||
125 | * @param $form_id int Gravity Forms form id |
||
126 | * @param $entry_id int Gravity Forms entry id |
||
127 | * @return string |
||
128 | */ |
||
129 | 5 | public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
132 | |||
133 | |||
134 | /** |
||
135 | * The edit entry link creates a secure link with a nonce |
||
136 | * |
||
137 | * It also mimics the URL structure Gravity Forms expects to have so that |
||
138 | * it formats the display of the edit form like it does in the backend, like |
||
139 | * "You can edit this post from the post page" fields, for example. |
||
140 | * |
||
141 | * @param $entry array Gravity Forms entry object |
||
142 | * @param $view_id int GravityView view id |
||
143 | * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
||
144 | * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } |
||
145 | * @return string |
||
146 | */ |
||
147 | 3 | public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
179 | |||
180 | /** |
||
181 | * Edit mode doesn't allow certain field types. |
||
182 | * @param array $fields Existing blacklist fields |
||
183 | * @param string|null $context Context |
||
184 | * @return array If not edit context, original field blacklist. Otherwise, blacklist including post fields. |
||
185 | */ |
||
186 | public function modify_field_blacklist( $fields = array(), $context = NULL ) { |
||
196 | |||
197 | /** |
||
198 | * Returns array of field types that should not be displayed in Edit Entry |
||
199 | * |
||
200 | * @since 1.20 |
||
201 | * |
||
202 | * @param array $entry Gravity Forms entry array |
||
203 | * |
||
204 | * @return array Blacklist of field types |
||
205 | */ |
||
206 | 3 | function get_field_blacklist( $entry = array() ) { |
|
207 | |||
208 | $fields = array( |
||
209 | 3 | 'page', |
|
210 | 'payment_status', |
||
211 | 'payment_date', |
||
212 | 'payment_amount', |
||
213 | 'is_fulfilled', |
||
214 | 'transaction_id', |
||
215 | 'transaction_type', |
||
216 | 'captcha', |
||
217 | 'honeypot', |
||
218 | ); |
||
219 | |||
220 | /** |
||
221 | * @filter `gravityview/edit_entry/field_blacklist` Array of fields that should not be displayed in Edit Entry |
||
222 | * @since 1.20 |
||
223 | * @param array $fields Blacklist field type array |
||
224 | * @param array $entry Gravity Forms entry array |
||
225 | */ |
||
226 | 3 | $fields = apply_filters( 'gravityview/edit_entry/field_blacklist', $fields, $entry ); |
|
227 | |||
228 | 3 | return $fields; |
|
229 | } |
||
230 | |||
231 | |||
232 | /** |
||
233 | * checks if user has permissions to edit a specific entry |
||
234 | * |
||
235 | * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
||
236 | * |
||
237 | * @param array $entry Gravity Forms entry array |
||
238 | * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2}. Required since 2.0 |
||
239 | * @return bool |
||
240 | */ |
||
241 | 5 | public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { |
|
308 | |||
309 | |||
310 | |||
311 | } // end class |
||
312 | |||
316 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.