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