GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-entry-approval.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file class-gravityview-entry-approval.php
4  * @package GravityView
5  * @license GPL2+
6  * @author GravityView <[email protected]>
7  * @link https://gravityview.co
8  * @copyright Copyright 2016, Katz Web Services, Inc.
9  *
10  * @since 1.18
11  */
12 
13 /** If this file is called directly, abort. */
14 if ( ! defined( 'ABSPATH' ) ) {
15  die;
16 }
17 
18 /**
19  * Generate linked list output for a list of entries.
20  *
21  * @since 1.18
22  */
24 
25  /**
26  * @var string Key used to store approval status in the Gravity Forms entry meta table
27  */
28  const meta_key = 'is_approved';
29 
30  public function __construct() {
31  $this->add_hooks();
32  }
33 
34  /**
35  * Add actions and filters related to entry approval
36  *
37  * @return void
38  */
39  private function add_hooks() {
40 
41  // in case entry is edited (on admin or frontend)
42  add_action( 'gform_after_update_entry', array( $this, 'after_update_entry_update_approved_meta' ), 10, 2);
43 
44  // when using the User opt-in field, check on entry submission
45  add_action( 'gform_after_submission', array( $this, 'after_submission' ), 10, 2 );
46 
47  // process ajax approve entry requests
48  add_action('wp_ajax_gv_update_approved', array( $this, 'ajax_update_approved'));
49 
50  // autounapprove
51  add_action( 'gravityview/edit_entry/after_update', array( __CLASS__, 'autounapprove' ), 10, 4 );
52 
53  add_filter( 'gform_notification_events', array( __CLASS__, 'add_approval_notification_events' ), 10, 2 );
54 
55  add_action( 'gravityview/approve_entries/approved', array( $this, '_trigger_notifications' ) );
56  add_action( 'gravityview/approve_entries/disapproved', array( $this, '_trigger_notifications' ) );
57  add_action( 'gravityview/approve_entries/unapproved', array( $this, '_trigger_notifications' ) );
58  add_action( 'gravityview/approve_entries/updated', array( $this, '_trigger_notifications' ) );
59  }
60 
61  /**
62  * Passes approval notification and action hook to the send_notifications method
63  *
64  * @see GravityView_Entry_Approval::send_notifications()
65  *
66  * @internal Developers, do not use!
67  *
68  * @since 2.1
69  *
70  * @param int $entry_id ID of entry being updated
71  *
72  * @return void
73  */
74  public function _trigger_notifications( $entry_id = 0 ) {
75  if ( did_action( 'gform_entry_created' ) && 'gravityview/approve_entries/updated' === current_action() ) {
76  return;
77  }
78 
79  $this->_send_notifications( $entry_id, current_action() );
80  }
81 
82  /**
83  * Passes along notification triggers to GFAPI::send_notifications()
84  *
85  * @since 2.1
86  *
87  * @param int $entry_id ID of entry being updated
88  * @param string $event Hook that triggered the notification. This is used as the key in the GF notifications array.
89  *
90  * @return void
91  */
92  private function _send_notifications( $entry_id = '', $event = '' ) {
93 
94  $entry = GFAPI::get_entry( $entry_id );
95 
96  if ( ! $entry || is_wp_error( $entry ) ) {
97  gravityview()->log->error( 'Entry not found at ID #{entry_id}', array( 'entry_id' => $entry_id ) );
98  return;
99  }
100 
101  $form = GFAPI::get_form( $entry['form_id'] );
102 
103  if ( ! $form ) {
104  gravityview()->log->error( 'Form not found at ID #{form_id} for entry #{entry_id}', array( 'form_id' => $entry['form_id'], 'entry_id' => $entry_id ) );
105  return;
106  }
107 
108  GFAPI::send_notifications( $form, $entry, $event );
109  }
110 
111  /**
112  * Adds entry approval status change custom notification events
113  *
114  * @since 2.1
115  *
116  * @param array $notification_events The notification events.
117  * @param array $form The current form.
118  */
119  public static function add_approval_notification_events( $notification_events = array(), $form = array() ) {
120 
121  $notification_events['gravityview/approve_entries/approved'] = 'GravityView - ' . esc_html_x( 'Entry is approved', 'The title for an event in a notifications drop down list.', 'gk-gravityview' );
122  $notification_events['gravityview/approve_entries/disapproved'] = 'GravityView - ' . esc_html_x( 'Entry is disapproved', 'The title for an event in a notifications drop down list.', 'gk-gravityview' );
123  $notification_events['gravityview/approve_entries/unapproved'] = 'GravityView - ' . esc_html_x( 'Entry approval is reset', 'The title for an event in a notifications drop down list.', 'gk-gravityview' );
124  $notification_events['gravityview/approve_entries/updated'] = 'GravityView - ' . esc_html_x( 'Entry approval is changed', 'The title for an event in a notifications drop down list.', 'gk-gravityview' );
125 
126  return $notification_events;
127  }
128 
129  /**
130  * Get the approval status for an entry
131  *
132  * @since 1.18
133  * @uses GVCommon::get_entry_id() Accepts entry slug or entry ID
134  *
135  * @param array|int|string $entry Entry array, entry slug, or entry ID
136  * @param string $value_or_label "value" or "label" (default: "label")
137  *
138  * @return bool|string Return the label or value of entry approval
139  */
140  public static function get_entry_status( $entry, $value_or_label = 'label' ) {
141 
142  $entry_id = is_array( $entry ) ? $entry['id'] : GVCommon::get_entry_id( $entry, true );
143 
144  $status = gform_get_meta( $entry_id, self::meta_key );
145 
147 
148  if( 'value' === $value_or_label ) {
149  return $status;
150  }
151 
153  }
154 
155  /**
156  * Approve/Disapprove entries using the × or ✓ icons in the GF Entries screen
157  *
158  * @uses wp_send_json_error()
159  * @uses wp_send_json_success()
160  *
161  * Expects a $_POST request with the following $_POST keys and values:
162  *
163  * @global array $_POST {
164  * @type int $form_id ID of the form connected to the entry being updated
165  * @type string|int $entry_slug The ID or slug of the entry being updated
166  * @type string $approved The value of the entry approval status {@see GravityView_Entry_Approval_Status::is_valid() }
167  * }
168  *
169  * @return void Prints result using wp_send_json_success() and wp_send_json_error()
170  */
171  public function ajax_update_approved() {
172 
173  $form_id = intval( \GV\Utils::_POST( 'form_id' ) );
174 
175  // We always want requests from the admin to allow entry IDs, but not from the frontend
176  // There's another nonce sent when approving entries in the admin that we check
177  $force_entry_ids = \GV\Utils::_POST( 'admin_nonce' ) && wp_verify_nonce( \GV\Utils::_POST( 'admin_nonce' ), 'gravityview_admin_entry_approval' );
178 
179  $entry_id = GVCommon::get_entry_id( \GV\Utils::_POST( 'entry_slug' ), $force_entry_ids );
180 
181  $approval_status = \GV\Utils::_POST( 'approved' );
182 
183  $nonce = \GV\Utils::_POST( 'nonce' );
184 
185  // Valid status
186  if( ! GravityView_Entry_Approval_Status::is_valid( $approval_status ) ) {
187 
188  gravityview()->log->error( 'Invalid approval status', array( 'data' => $_POST ) );
189 
190  $result = new WP_Error( 'invalid_status', __( 'The request was invalid. Refresh the page and try again.', 'gk-gravityview' ) );
191 
192  }
193 
194  // Valid values
195  elseif ( empty( $entry_id ) || empty( $form_id ) ) {
196 
197  gravityview()->log->error( 'entry_id or form_id are empty.', array( 'data' => $_POST ) );
198 
199  $result = new WP_Error( 'empty_details', __( 'The request was invalid. Refresh the page and try again.', 'gk-gravityview' ) );
200 
201  }
202 
203  // Valid nonce
204  else if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'gravityview_entry_approval' ) ) {
205 
206  gravityview()->log->error( 'Security check failed.', array( 'data' => $_POST ) );
207 
208  $result = new WP_Error( 'invalid_nonce', __( 'The request was invalid. Refresh the page and try again.', 'gk-gravityview' ) );
209 
210  }
211 
212  // Has capability
213  elseif ( ! GVCommon::has_cap( 'gravityview_moderate_entries', $entry_id ) ) {
214 
215  gravityview()->log->error( 'User does not have the `gravityview_moderate_entries` capability.' );
216 
217  $result = new WP_Error( 'Missing Cap: gravityview_moderate_entries', __( 'You do not have permission to edit this entry.', 'gk-gravityview') );
218 
219  }
220 
221  // All checks passed
222  else {
223 
224  $result = self::update_approved( $entry_id, $approval_status, $form_id );
225 
226  }
227 
228  if ( is_wp_error( $result ) ) {
229  gravityview()->log->error( 'Error updating approval: {error}', array( 'error' => $result->get_error_message() ) );
230 
231  wp_send_json_error( $result );
232  }
233 
234  $current_status = self::get_entry_status( $entry_id, 'value' );
235 
236  wp_send_json_success( array(
237  'status' => $current_status
238  ) );
239  }
240 
241  /**
242  * Update the is_approved meta whenever the entry is submitted (and it contains a User Opt-in field)
243  *
244  * @since 1.16.6
245  * @since 2.0.14 Set the default approval `is_approved` value upon submission
246  *
247  * @param $entry array Gravity Forms entry object
248  * @param $form array Gravity Forms form object
249  */
250  public function after_submission( $entry, $form ) {
251 
252  /**
253  * @filter `gravityview/approve_entries/after_submission` Modify whether to run the after_submission process
254  * @since 2.3
255  * @param bool $process_after_submission default: true
256  */
257  $process_after_submission = apply_filters( 'gravityview/approve_entries/after_submission', true );
258 
259  if ( ! $process_after_submission ) {
260  return;
261  }
262 
264 
265  /**
266  * @filter `gravityview/approve_entries/after_submission/default_status` Modify the default approval status for newly submitted entries
267  * @since 2.0.14
268  * @param int $default_status See GravityView_Entry_Approval_Status() for valid statuses.
269  */
270  $filtered_status = apply_filters( 'gravityview/approve_entries/after_submission/default_status', $default_status );
271 
272  if ( GravityView_Entry_Approval_Status::is_valid( $filtered_status ) ) {
273  $default_status = $filtered_status;
274  } else {
275  gravityview()->log->error( 'Invalid approval status returned by `gravityview/approve_entries/after_submission/default_status` filter: {status}', array( 'status' => $filtered_status ) );
276  }
277 
278  // Set default
279  self::update_approved_meta( $entry['id'], $default_status, $entry['form_id'] );
280 
281  // Then check for if there is an approval column, and use that value instead
283  }
284 
285  /**
286  * Update the is_approved meta whenever the entry is updated
287  *
288  * @since 1.7.6.1 Was previously named `update_approved_meta`
289  *
290  * @param array $form Gravity Forms form array
291  * @param int $entry_id ID of the Gravity Forms entry
292  * @return void
293  */
294  public function after_update_entry_update_approved_meta( $form, $entry_id = NULL ) {
295 
296  $approved_column = self::get_approved_column( $form['id'] );
297 
298  /**
299  * If the form doesn't contain the approve field, don't assume anything.
300  */
301  if( empty( $approved_column ) ) {
302  return;
303  }
304 
305  $entry = GFAPI::get_entry( $entry_id );
306 
307  // If the checkbox is blank, it's disapproved, regardless of the label
308  if ( '' === \GV\Utils::get( $entry, $approved_column ) ) {
310  } else {
311  // If the checkbox is not blank, it's approved
313  }
314 
315  /**
316  * @filter `gravityview/approve_entries/update_unapproved_meta` Filter the approval status on entry update.
317  * @param string $value The approval status.
318  * @param array $form The form.
319  * @param array $entry The entry.
320  */
321  $value = apply_filters( 'gravityview/approve_entries/update_unapproved_meta', $value, $form, $entry );
322 
323  self::update_approved_meta( $entry_id, $value, $form['id'] );
324  }
325 
326  /**
327  * Process a bulk of entries to update the approve field/property
328  *
329  * @since 1.18 Moved to GravityView_Entry_Approval
330  * @since 1.18 Made public
331  *
332  * @static
333  * @param array|boolean $entries If array, array of entry IDs that are to be updated. If true: update all entries.
334  * @param int $approved Approved status. If `0`: unapproved, if not empty, `Approved`
335  * @param int $form_id The Gravity Forms Form ID
336  * @return boolean|null True: successfully updated all entries. False: there was an error updating at least one entry. NULL: an error occurred (see log)
337  */
338  public static function update_bulk( $entries = array(), $approved = 0, $form_id = 0 ) {
339 
340  if( empty($entries) || ( $entries !== true && !is_array($entries) ) ) {
341  gravityview()->log->error( 'Entries were empty or malformed.', array( 'data' => $entries ) );
342  return NULL;
343  }
344 
345  if( ! GVCommon::has_cap( 'gravityview_moderate_entries' ) ) {
346  gravityview()->log->error( 'User does not have the `gravityview_moderate_entries` capability.' );
347  return NULL;
348  }
349 
350 
351  if ( ! GravityView_Entry_Approval_Status::is_valid( $approved ) ) {
352  gravityview()->log->error( 'Invalid approval status', array( 'data' => $approved ) );
353  return NULL;
354  }
355 
356  // calculate approved field id once instead of looping through in the update_approved() method
357  $approved_column_id = self::get_approved_column( $form_id );
358 
359  $success = true;
360  foreach( $entries as $entry_id ) {
361  $update_success = self::update_approved( (int)$entry_id, $approved, $form_id, $approved_column_id );
362 
363  if( ! $update_success ) {
364  $success = false;
365  }
366  }
367 
368  return $success;
369  }
370 
371  /**
372  * update_approved function.
373  *
374  * @since 1.18 Moved to GravityView_Entry_Approval class
375  *
376  * @static
377  * @param int $entry_id (default: 0)
378  * @param int $approved (default: 2)
379  * @param int $form_id (default: 0)
380  * @param int $approvedcolumn (default: 0)
381  *
382  * @return boolean True: It worked; False: it failed
383  */
384  public static function update_approved( $entry_id = 0, $approved = 2, $form_id = 0, $approvedcolumn = 0 ) {
385 
386  if( !class_exists( 'GFAPI' ) ) {
387  gravityview()->log->error( 'GFAPI does not exist' );
388  return false;
389  }
390 
391  if( ! GravityView_Entry_Approval_Status::is_valid( $approved ) ) {
392  gravityview()->log->error( 'Not a valid approval value.' );
393  return false;
394  }
395 
397 
398  $entry = GFAPI::get_entry( $entry_id );
399 
400  if ( is_wp_error( $entry ) ) {
401  gravityview()->log->error( 'Entry does not exist' );
402  return false;
403  }
404 
405  // If the form has an Approve/Reject field, update that value
406  $result = self::update_approved_column( $entry_id, $approved, $form_id, $approvedcolumn );
407 
408  if( is_wp_error( $result ) ) {
409  gravityview()->log->error( 'Entry approval not updated: {error}', array( 'error' => $result->get_error_message() ) );
410  return false;
411  }
412 
413  $form_id = intval( $form_id );
414 
415  // Update the entry meta
416  self::update_approved_meta( $entry_id, $approved, $form_id );
417 
418  // add note to entry if approval field updating worked or there was no approved field
419  // There's no validation for the meta
420  if( true === $result ) {
421 
422  // Add an entry note
423  self::add_approval_status_updated_note( $entry_id, $approved );
424 
425  /**
426  * Destroy the cache for this form
427  * @see class-cache.php
428  * @since 1.5.1
429  */
430  do_action( 'gravityview_clear_form_cache', $form_id );
431 
432  }
433 
434  return $result;
435  }
436 
437  /**
438  * Add a note when an entry is approved
439  *
440  * @see GravityView_Entry_Approval::update_approved
441  *
442  * @since 1.18
443  *
444  * @param int $entry_id Gravity Forms entry ID
445  * @param int $approved Approval status
446  *
447  * @return false|int|WP_Error Note ID if successful; WP_Error if error when adding note, FALSE if note not updated because of `gravityview/approve_entries/add-note` filter or `GravityView_Entry_Notes` class not existing
448  */
449  private static function add_approval_status_updated_note( $entry_id, $approved = 0 ) {
450  $note = '';
451 
452  switch ( $approved ) {
454  $note = __( 'Approved the Entry for GravityView', 'gk-gravityview' );
455  break;
457  $note = __( 'Reset Entry approval for GravityView', 'gk-gravityview' );
458  break;
460  $note = __( 'Disapproved the Entry for GravityView', 'gk-gravityview' );
461  break;
462  }
463 
464  /**
465  * @filter `gravityview/approve_entries/add-note` Add a note when the entry has been approved or disapproved?
466  * @since 1.16.3
467  * @param bool $add_note True: Yep, add that note! False: Do not, under any circumstances, add that note!
468  */
469  $add_note = apply_filters( 'gravityview/approve_entries/add-note', true );
470 
471  $note_id = false;
472 
473  if( $add_note && class_exists( 'GravityView_Entry_Notes' ) ) {
474 
475  $current_user = wp_get_current_user();
476 
477  $note_id = GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $current_user->display_name, $note );
478  }
479 
480  return $note_id;
481  }
482 
483  /**
484  * Update the Approve/Disapproved field value
485  *
486  * @param int $entry_id ID of the Gravity Forms entry
487  * @param string $status String whether entry is approved or not. `0` for not approved, `Approved` for approved.
488  * @param int $form_id ID of the form of the entry being updated. Improves query performance.
489  * @param string $approvedcolumn Gravity Forms Field ID
490  *
491  * @return true|WP_Error
492  */
493  private static function update_approved_column( $entry_id = 0, $status = '0', $form_id = 0, $approvedcolumn = 0 ) {
494 
495  if( empty( $approvedcolumn ) ) {
496  $approvedcolumn = self::get_approved_column( $form_id );
497  }
498 
499  if ( empty( $approvedcolumn ) ) {
500  return true;
501  }
502 
503  if ( ! GravityView_Entry_Approval_Status::is_valid( $status ) ) {
504  return new WP_Error( 'invalid_status', 'Invalid entry approval status', $status );
505  }
506 
507  //get the entry
508  $entry = GFAPI::get_entry( $entry_id );
509 
510  // Entry doesn't exist
511  if ( is_wp_error( $entry ) ) {
512  return $entry;
513  }
514 
516 
517  $new_value = '';
519  $new_value = self::get_approved_column_input_label( $form_id, $approvedcolumn );
520  }
521 
522  //update entry
523  $entry["{$approvedcolumn}"] = $new_value;
524 
525  /**
526  * Note: GFAPI::update_entry() doesn't trigger `gform_after_update_entry`, so we trigger updating the meta ourselves
527  * @see GravityView_Entry_Approval::after_update_entry_update_approved_meta
528  * @var true|WP_Error $result
529  */
530  $result = GFAPI::update_entry( $entry );
531 
532  return $result;
533  }
534 
535  /**
536  * Get the value for the approved field checkbox
537  *
538  * When approving a field via the entry meta, use the correct value for the new approved column input
539  *
540  * @since 1.19
541  *
542  * @param array|int $form Form ID or form array
543  * @param string $approved_column Approved column field ID
544  *
545  * @return string|null
546  */
547  private static function get_approved_column_input_label( $form, $approved_column ) {
548 
549  $field = gravityview_get_field( $form, $approved_column );
550 
551  // If the user has enabled a different value than the label (for some reason), use it.
552  // This is highly unlikely
553  if ( is_array( $field->choices ) && ! empty( $field->choices ) ) {
554  return isset( $field->choices[0]['value'] ) ? $field->choices[0]['value'] : $field->choices[0]['text'];
555  }
556 
557  // Otherwise, fall back on the inputs array
558  if ( is_array( $field->inputs ) && ! empty( $field->inputs ) ) {
559  return $field->inputs[0]['label'];
560  }
561 
562  return null;
563  }
564 
565  /**
566  * Update the `is_approved` entry meta value
567  *
568  * @since 1.7.6.1 `after_update_entry_update_approved_meta` was previously to be named `update_approved_meta`
569  * @since 1.17.1 Added $form_id parameter
570  *
571  * @param int $entry_id ID of the Gravity Forms entry
572  * @param string $status String whether entry is approved or not. `0` for not approved, `Approved` for approved.
573  * @param int $form_id ID of the form of the entry being updated. Improves query performance.
574  *
575  * @return void
576  */
577  private static function update_approved_meta( $entry_id, $status, $form_id = 0 ) {
578 
579  if ( ! GravityView_Entry_Approval_Status::is_valid( $status ) ) {
580  gravityview()->log->error( '$is_approved not valid value', array( 'data' => $status ) );
581  return;
582  }
583 
584  if ( ! function_exists( 'gform_update_meta' ) ) {
585  gravityview()->log->error( '`gform_update_meta` does not exist.' );
586  return;
587  }
588 
590 
591  // update entry meta
592  gform_update_meta( $entry_id, self::meta_key, $status, $form_id );
593 
594  /**
595  * @action `gravityview/approve_entries/updated` Triggered when an entry approval is updated
596  * @since 1.7.6.1
597  * @param int $entry_id ID of the Gravity Forms entry
598  * @param string|int $status String whether entry is approved or not. See GravityView_Entry_Approval_Status for valid statuses.
599  */
600  do_action( 'gravityview/approve_entries/updated', $entry_id, $status );
601 
602  $action = GravityView_Entry_Approval_Status::get_key( $status );
603 
604  /**
605  * @action `gravityview/approve_entries/{$action}` Triggered when an entry approval is set. {$action} can be 'approved', 'unapproved', or 'disapproved'
606  * Note: If you want this to work with Bulk Actions, run in a plugin rather than a theme; the bulk updates hook runs before themes are loaded.
607  * @since 1.7.6.1
608  * @since 1.18 Added "unapproved"
609  * @param int $entry_id ID of the Gravity Forms entry
610  */
611  do_action( 'gravityview/approve_entries/' . $action , $entry_id );
612  }
613 
614  /**
615  * Calculate the approve field.input id
616  *
617  * @static
618  * @param mixed $form GF Form or Form ID
619  * @return false|null|string Returns the input ID of the approved field. Returns NULL if no approved fields were found. Returns false if $form_id wasn't set.
620  */
621  static public function get_approved_column( $form ) {
622 
623  if( empty( $form ) ) {
624  return null;
625  }
626 
627  if( !is_array( $form ) ) {
629  }
630 
631  $approved_column_id = null;
632 
633  /**
634  * @var string $key
635  * @var GF_Field $field
636  */
637  foreach( $form['fields'] as $key => $field ) {
638 
639  $inputs = $field->get_entry_inputs();
640 
641  if( !empty( $field->gravityview_approved ) ) {
642  if ( ! empty( $inputs ) && !empty( $inputs[0]['id'] ) ) {
643  $approved_column_id = $inputs[0]['id'];
644  break;
645  }
646  }
647 
648  // Note: This is just for backward compatibility from GF Directory plugin and old GV versions - when using i18n it may not work..
649  if( 'checkbox' === $field->type && ! empty( $inputs ) ) {
650  foreach ( $inputs as $input ) {
651  if ( 'approved' === strtolower( $input['label'] ) ) {
652  $approved_column_id = $input['id'];
653  break;
654  }
655  }
656  }
657  }
658 
659  return $approved_column_id;
660  }
661 
662  /**
663  * Maybe unapprove entry on edit.
664  *
665  * Called from gravityview/edit_entry/after_update
666  *
667  * @param array $form Gravity Forms form array
668  * @param string $entry_id Numeric ID of the entry that was updated
669  * @param GravityView_Edit_Entry_Render $edit This object
670  * @param GravityView_View_Data $gv_data The View data
671  *
672  * @return void
673  */
674  public static function autounapprove( $form, $entry_id, $edit, $gv_data ) {
675 
676  $view_keys = array_keys( $gv_data->get_views() );
677 
678  $view = \GV\View::by_id( $view_keys[0] );
679 
680  if ( ! $view->settings->get( 'unapprove_edit' ) ) {
681  return;
682  }
683 
684  if ( GVCommon::has_cap( 'gravityview_moderate_entries' ) ) {
685  return;
686  }
687 
688  /**
689  * @filter `gravityview/approve_entries/autounapprove/status`
690  * @since 2.2.2
691  * @param int|false $approval_status Approval status integer, or false if you want to not update status. Use GravityView_Entry_Approval_Status constants. Default: 3 (GravityView_Entry_Approval_Status::UNAPPROVED)
692  * @param array $form Gravity Forms form array
693  * @param string $entry_id Numeric ID of the entry that was updated
694  * @param \GV\View $view Current View where the entry was edited
695  */
696  $approval_status = apply_filters( 'gravityview/approve_entries/autounapprove/status', GravityView_Entry_Approval_Status::UNAPPROVED, $form, $entry_id, $view );
697 
698  // Allow returning false to exit
699  if ( false === $approval_status ) {
700  return;
701  }
702 
703  if( ! GravityView_Entry_Approval_Status::is_valid( $approval_status ) ) {
705  }
706 
707  self::update_approved_meta( $entry_id, $approval_status, $form['id'] );
708  }
709 
710  /**
711  * Where should the popover be placed?
712  *
713  * @since 2.3.1
714  *
715  * @return string Where to place the popover; 'right' (default ltr), 'left' (default rtl), 'top', or 'bottom'
716  */
717  public static function get_popover_placement() {
718 
719  $placement = is_rtl() ? 'left' : 'right';
720 
721  /**
722  * @filter `gravityview/approve_entries/popover_placement` Where should the popover be placed?
723  * @since 2.3.1
724  * @param string $placement Where to place the popover; 'right' (default ltr), 'left' (default rtl), 'top', or 'bottom'
725  */
726  $placement = apply_filters( 'gravityview/approve_entries/popover_placement', $placement );
727 
728  return $placement;
729  }
730 
731  /**
732  * Get HTML template for a popover used to display approval statuses
733  *
734  * @since 2.3.1
735  *
736  * @internal For internal use only!
737  *
738  * @return string HTML code
739  */
740  public static function get_popover_template() {
741 
743 
744  return <<<TEMPLATE
745 <a href="#" data-approved="{$choices['approved']['value']}" aria-role="button" aria-live="polite" class="gv-approval-toggle gv-approval-approved popover" title="{$choices['approved']['action']}"><span class="screen-reader-text">{$choices['approved']['action']}</span></a>
746 <a href="#" data-approved="{$choices['disapproved']['value']}" aria-role="button" aria-live="polite" class="gv-approval-toggle gv-approval-disapproved popover" title="{$choices['disapproved']['action']}"><span class="screen-reader-text">{$choices['disapproved']['action']}</span></a>
747 <a href="#" data-approved="{$choices['unapproved']['value']}" aria-role="button" aria-live="polite" class="gv-approval-toggle gv-approval-unapproved popover" title="{$choices['unapproved']['action']}"><span class="screen-reader-text">{$choices['unapproved']['action']}</span></a>
748 TEMPLATE;
749  }
750 }
751 
__construct()
_trigger_notifications( $entry_id=0)
Passes approval notification and action hook to the send_notifications method.
static add_approval_status_updated_note( $entry_id, $approved=0)
Add a note when an entry is approved.
new GravityView_Entry_Approval
static get_popover_placement()
Where should the popover be placed?
$entries
after_submission( $entry, $form)
Update the is_approved meta whenever the entry is submitted (and it contains a User Opt-in field) ...
If this file is called directly, abort.
static update_bulk( $entries=array(), $approved=0, $form_id=0)
Process a bulk of entries to update the approve field/property.
static get_key( $value)
Get the status key for a value.
if(gravityview() ->plugin->is_GF_25()) $form
$current_status
static get_entry_id( $entry_id_or_slug='', $force_allow_ids=false)
Get the entry ID from a string that may be the Entry ID or the Entry Slug.
after_update_entry_update_approved_meta( $form, $entry_id=NULL)
Update the is_approved meta whenever the entry is updated.
static is_valid( $value=NULL)
Check whether the passed value is one of the defined values for entry approval.
gravityview_get_field( $form, $field_id)
Returns the field details array of a specific form given the field id.
const APPROVED
static autounapprove( $form, $entry_id, $edit, $gv_data)
Maybe unapprove entry on edit.
ajax_update_approved()
Approve/Disapprove entries using the × or ✓ icons in the GF Entries screen.
static by_id( $post_id)
Construct a instance from a post ID.
static maybe_convert_status( $old_value='')
Convert previously-used values to the current values, for backward compatibility. ...
static update_approved( $entry_id=0, $approved=2, $form_id=0, $approvedcolumn=0)
update_approved function.
static get_entry_status( $entry, $value_or_label='label')
Get the approval status for an entry.
static get_approved_column_input_label( $form, $approved_column)
Get the value for the approved field checkbox.
const DISAPPROVED
add_hooks()
Add actions and filters related to entry approval.
_send_notifications( $entry_id='', $event='')
Passes along notification triggers to GFAPI::send_notifications()
if(empty( $created_by)) $form_id
const UNAPPROVED
static add_note( $lead_id, $user_id, $user_name, $note='', $note_type='gravityview')
Alias for GFFormsModel::add_note() with default note_type of &#39;gravityview&#39;.
gravityview()
The main GravityView wrapper function.
static update_approved_meta( $entry_id, $status, $form_id=0)
Update the is_approved entry meta value.
static get_popover_template()
Get HTML template for a popover used to display approval statuses.
static get_all()
Return array of status options.
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
$entry
Definition: notes.php:27
static get_form( $form_id)
Returns the form object for a given Form ID.
const meta_key
static add_approval_notification_events( $notification_events=array(), $form=array())
Adds entry approval status change custom notification events.
static _POST( $name, $default=null)
Grab a value from the _POST superglobal or default.
static get_label( $value_or_key)
Get the label for a specific approval value.