14 if ( ! defined(
'ABSPATH' ) ) {
42 add_action(
'gform_after_update_entry', array( $this,
'after_update_entry_update_approved_meta' ), 10, 2);
45 add_action(
'gform_after_submission', array( $this,
'after_submission' ), 10, 2 );
48 add_action(
'wp_ajax_gv_update_approved', array( $this,
'ajax_update_approved'));
51 add_action(
'gravityview/edit_entry/after_update', array( __CLASS__,
'autounapprove' ), 10, 4 );
53 add_filter(
'gform_notification_events', array( __CLASS__,
'add_approval_notification_events' ), 10, 2 );
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' ) );
75 if ( did_action(
'gform_entry_created' ) &&
'gravityview/approve_entries/updated' === current_action() ) {
94 $entry = GFAPI::get_entry( $entry_id );
97 gravityview()->log->error(
'Entry not found at ID #{entry_id}', array(
'entry_id' => $entry_id ) );
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 ) );
108 GFAPI::send_notifications(
$form,
$entry, $event );
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' );
126 return $notification_events;
144 $status = gform_get_meta( $entry_id, self::meta_key );
148 if(
'value' === $value_or_label ) {
173 $form_id = intval( \
GV\Utils::_POST(
'form_id' ) );
177 $force_entry_ids =
\GV\Utils::_POST(
'admin_nonce' ) && wp_verify_nonce( \
GV\Utils::_POST(
'admin_nonce' ),
'gravityview_admin_entry_approval' );
188 gravityview()->log->error(
'Invalid approval status', array(
'data' => $_POST ) );
190 $result =
new WP_Error(
'invalid_status', __(
'The request was invalid. Refresh the page and try again.',
'gk-gravityview' ) );
195 elseif ( empty( $entry_id ) || empty(
$form_id ) ) {
197 gravityview()->log->error(
'entry_id or form_id are empty.', array(
'data' => $_POST ) );
199 $result =
new WP_Error(
'empty_details', __(
'The request was invalid. Refresh the page and try again.',
'gk-gravityview' ) );
204 else if ( empty( $nonce ) || ! wp_verify_nonce( $nonce,
'gravityview_entry_approval' ) ) {
206 gravityview()->log->error(
'Security check failed.', array(
'data' => $_POST ) );
208 $result =
new WP_Error(
'invalid_nonce', __(
'The request was invalid. Refresh the page and try again.',
'gk-gravityview' ) );
215 gravityview()->log->error(
'User does not have the `gravityview_moderate_entries` capability.' );
217 $result =
new WP_Error(
'Missing Cap: gravityview_moderate_entries', __(
'You do not have permission to edit this entry.',
'gk-gravityview') );
224 $result = self::update_approved( $entry_id, $approval_status,
$form_id );
228 if ( is_wp_error( $result ) ) {
229 gravityview()->log->error(
'Error updating approval: {error}', array(
'error' => $result->get_error_message() ) );
231 wp_send_json_error( $result );
236 wp_send_json_success( array(
257 $process_after_submission = apply_filters(
'gravityview/approve_entries/after_submission',
true );
259 if ( ! $process_after_submission ) {
270 $filtered_status = apply_filters(
'gravityview/approve_entries/after_submission/default_status', $default_status );
273 $default_status = $filtered_status;
275 gravityview()->log->error(
'Invalid approval status returned by `gravityview/approve_entries/after_submission/default_status` filter: {status}', array(
'status' => $filtered_status ) );
279 self::update_approved_meta(
$entry[
'id'], $default_status,
$entry[
'form_id'] );
296 $approved_column = self::get_approved_column(
$form[
'id'] );
301 if( empty( $approved_column ) ) {
305 $entry = GFAPI::get_entry( $entry_id );
308 if (
'' === \
GV\Utils::get(
$entry, $approved_column ) ) {
323 self::update_approved_meta( $entry_id,
$value,
$form[
'id'] );
341 gravityview()->log->error(
'Entries were empty or malformed.', array(
'data' =>
$entries ) );
346 gravityview()->log->error(
'User does not have the `gravityview_moderate_entries` capability.' );
352 gravityview()->log->error(
'Invalid approval status', array(
'data' => $approved ) );
357 $approved_column_id = self::get_approved_column(
$form_id );
361 $update_success = self::update_approved( (
int)$entry_id, $approved,
$form_id, $approved_column_id );
363 if( ! $update_success ) {
386 if( !class_exists(
'GFAPI' ) ) {
387 gravityview()->log->error(
'GFAPI does not exist' );
392 gravityview()->log->error(
'Not a valid approval value.' );
398 $entry = GFAPI::get_entry( $entry_id );
400 if ( is_wp_error(
$entry ) ) {
401 gravityview()->log->error(
'Entry does not exist' );
406 $result = self::update_approved_column( $entry_id, $approved,
$form_id, $approvedcolumn );
408 if( is_wp_error( $result ) ) {
409 gravityview()->log->error(
'Entry approval not updated: {error}', array(
'error' => $result->get_error_message() ) );
416 self::update_approved_meta( $entry_id, $approved,
$form_id );
420 if(
true === $result ) {
423 self::add_approval_status_updated_note( $entry_id, $approved );
430 do_action(
'gravityview_clear_form_cache',
$form_id );
452 switch ( $approved ) {
454 $note = __(
'Approved the Entry for GravityView',
'gk-gravityview' );
457 $note = __(
'Reset Entry approval for GravityView',
'gk-gravityview' );
460 $note = __(
'Disapproved the Entry for GravityView',
'gk-gravityview' );
469 $add_note = apply_filters(
'gravityview/approve_entries/add-note',
true );
473 if( $add_note && class_exists(
'GravityView_Entry_Notes' ) ) {
475 $current_user = wp_get_current_user();
493 private static function update_approved_column( $entry_id = 0, $status =
'0',
$form_id = 0, $approvedcolumn = 0 ) {
495 if( empty( $approvedcolumn ) ) {
496 $approvedcolumn = self::get_approved_column(
$form_id );
499 if ( empty( $approvedcolumn ) ) {
504 return new WP_Error(
'invalid_status',
'Invalid entry approval status', $status );
508 $entry = GFAPI::get_entry( $entry_id );
511 if ( is_wp_error(
$entry ) ) {
519 $new_value = self::get_approved_column_input_label(
$form_id, $approvedcolumn );
523 $entry[
"{$approvedcolumn}"] = $new_value;
530 $result = GFAPI::update_entry(
$entry );
553 if ( is_array(
$field->choices ) && ! empty(
$field->choices ) ) {
554 return isset(
$field->choices[0][
'value'] ) ?
$field->choices[0][
'value'] :
$field->choices[0][
'text'];
558 if ( is_array(
$field->inputs ) && ! empty(
$field->inputs ) ) {
559 return $field->inputs[0][
'label'];
580 gravityview()->log->error(
'$is_approved not valid value', array(
'data' => $status ) );
584 if ( ! function_exists(
'gform_update_meta' ) ) {
585 gravityview()->log->error(
'`gform_update_meta` does not exist.' );
592 gform_update_meta( $entry_id, self::meta_key, $status,
$form_id );
600 do_action(
'gravityview/approve_entries/updated', $entry_id, $status );
611 do_action(
'gravityview/approve_entries/' . $action , $entry_id );
621 static public function get_approved_column(
$form ) {
623 if( empty(
$form ) ) {
627 if( !is_array(
$form ) ) {
631 $approved_column_id = null;
639 $inputs =
$field->get_entry_inputs();
641 if( !empty(
$field->gravityview_approved ) ) {
642 if ( ! empty( $inputs ) && !empty( $inputs[0][
'id'] ) ) {
643 $approved_column_id = $inputs[0][
'id'];
649 if(
'checkbox' ===
$field->type && ! empty( $inputs ) ) {
650 foreach ( $inputs as $input ) {
651 if (
'approved' === strtolower( $input[
'label'] ) ) {
652 $approved_column_id = $input[
'id'];
659 return $approved_column_id;
676 $view_keys = array_keys( $gv_data->get_views() );
680 if ( ! $view->settings->get(
'unapprove_edit' ) ) {
699 if (
false === $approval_status ) {
707 self::update_approved_meta( $entry_id, $approval_status,
$form[
'id'] );
719 $placement = is_rtl() ?
'left' :
'right';
726 $placement = apply_filters(
'gravityview/approve_entries/popover_placement', $placement );
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>
_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?
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
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.
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.
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
static add_note( $lead_id, $user_id, $user_name, $note='', $note_type='gravityview')
Alias for GFFormsModel::add_note() with default note_type of 'gravityview'.
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()
static get_form( $form_id)
Returns the form object for a given Form ID.
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.