|
@@ -39,13 +39,13 @@ discard block |
|
|
block discarded – undo |
|
39
|
39
|
private function add_hooks() { |
|
40
|
40
|
|
|
41
|
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); |
|
|
42
|
+ add_action( 'gform_after_update_entry', array( $this, 'after_update_entry_update_approved_meta' ), 10, 2 ); |
|
43
|
43
|
|
|
44
|
44
|
// when using the User opt-in field, check on entry submission |
|
45
|
45
|
add_action( 'gform_after_submission', array( $this, 'after_submission' ), 10, 2 ); |
|
46
|
46
|
|
|
47
|
47
|
// process ajax approve entry requests |
|
48
|
|
- add_action('wp_ajax_gv_update_approved', array( $this, 'ajax_update_approved')); |
|
|
48
|
+ add_action( 'wp_ajax_gv_update_approved', array( $this, 'ajax_update_approved' ) ); |
|
49
|
49
|
|
|
50
|
50
|
// autounapprove |
|
51
|
51
|
add_action( 'gravityview/edit_entry/after_update', array( __CLASS__, 'autounapprove' ), 10, 4 ); |
|
@@ -94,10 +94,10 @@ discard block |
|
|
block discarded – undo |
|
94
|
94
|
return; |
|
95
|
95
|
} |
|
96
|
96
|
|
|
97
|
|
- $form = GFAPI::get_form( $entry['form_id'] ); |
|
|
97
|
+ $form = GFAPI::get_form( $entry[ 'form_id' ] ); |
|
98
|
98
|
|
|
99
|
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 ) ); |
|
|
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
|
101
|
return; |
|
102
|
102
|
} |
|
103
|
103
|
|
|
@@ -114,10 +114,10 @@ discard block |
|
|
block discarded – undo |
|
114
|
114
|
*/ |
|
115
|
115
|
public static function add_approval_notification_events( $notification_events = array(), $form = array() ) { |
|
116
|
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' ); |
|
|
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
|
121
|
|
|
122
|
122
|
return $notification_events; |
|
123
|
123
|
} |
|
@@ -135,13 +135,13 @@ discard block |
|
|
block discarded – undo |
|
135
|
135
|
*/ |
|
136
|
136
|
public static function get_entry_status( $entry, $value_or_label = 'label' ) { |
|
137
|
137
|
|
|
138
|
|
- $entry_id = is_array( $entry ) ? $entry['id'] : GVCommon::get_entry_id( $entry, true ); |
|
|
138
|
+ $entry_id = is_array( $entry ) ? $entry[ 'id' ] : GVCommon::get_entry_id( $entry, true ); |
|
139
|
139
|
|
|
140
|
140
|
$status = gform_get_meta( $entry_id, self::meta_key ); |
|
141
|
141
|
|
|
142
|
142
|
$status = GravityView_Entry_Approval_Status::maybe_convert_status( $status ); |
|
143
|
143
|
|
|
144
|
|
- if( 'value' === $value_or_label ) { |
|
|
144
|
+ if ( 'value' === $value_or_label ) { |
|
145
|
145
|
return $status; |
|
146
|
146
|
} |
|
147
|
147
|
|
|
@@ -179,7 +179,7 @@ discard block |
|
|
block discarded – undo |
|
179
|
179
|
$nonce = \GV\Utils::_POST( 'nonce' ); |
|
180
|
180
|
|
|
181
|
181
|
// Valid status |
|
182
|
|
- if( ! GravityView_Entry_Approval_Status::is_valid( $approval_status ) ) { |
|
|
182
|
+ if ( ! GravityView_Entry_Approval_Status::is_valid( $approval_status ) ) { |
|
183
|
183
|
|
|
184
|
184
|
gravityview()->log->error( 'Invalid approval status', array( 'data' => $_POST ) ); |
|
185
|
185
|
|
|
@@ -210,7 +210,7 @@ discard block |
|
|
block discarded – undo |
|
210
|
210
|
|
|
211
|
211
|
gravityview()->log->error( 'User does not have the `gravityview_moderate_entries` capability.' ); |
|
212
|
212
|
|
|
213
|
|
- $result = new WP_Error( 'Missing Cap: gravityview_moderate_entries', __( 'You do not have permission to edit this entry.', 'gravityview') ); |
|
|
213
|
+ $result = new WP_Error( 'Missing Cap: gravityview_moderate_entries', __( 'You do not have permission to edit this entry.', 'gravityview' ) ); |
|
214
|
214
|
|
|
215
|
215
|
} |
|
216
|
216
|
|
|
@@ -261,10 +261,10 @@ discard block |
|
|
block discarded – undo |
|
261
|
261
|
} |
|
262
|
262
|
|
|
263
|
263
|
// Set default |
|
264
|
|
- self::update_approved_meta( $entry['id'], $default_status, $entry['form_id'] ); |
|
|
264
|
+ self::update_approved_meta( $entry[ 'id' ], $default_status, $entry[ 'form_id' ] ); |
|
265
|
265
|
|
|
266
|
266
|
// Then check for if there is an approval column, and use that value instead |
|
267
|
|
- $this->after_update_entry_update_approved_meta( $form , $entry['id'] ); |
|
|
267
|
+ $this->after_update_entry_update_approved_meta( $form, $entry[ 'id' ] ); |
|
268
|
268
|
} |
|
269
|
269
|
|
|
270
|
270
|
/** |
|
@@ -278,12 +278,12 @@ discard block |
|
|
block discarded – undo |
|
278
|
278
|
*/ |
|
279
|
279
|
public function after_update_entry_update_approved_meta( $form, $entry_id = NULL ) { |
|
280
|
280
|
|
|
281
|
|
- $approved_column = self::get_approved_column( $form['id'] ); |
|
|
281
|
+ $approved_column = self::get_approved_column( $form[ 'id' ] ); |
|
282
|
282
|
|
|
283
|
283
|
/** |
|
284
|
284
|
* If the form doesn't contain the approve field, don't assume anything. |
|
285
|
285
|
*/ |
|
286
|
|
- if( empty( $approved_column ) ) { |
|
|
286
|
+ if ( empty( $approved_column ) ) { |
|
287
|
287
|
return; |
|
288
|
288
|
} |
|
289
|
289
|
|
|
@@ -297,7 +297,7 @@ discard block |
|
|
block discarded – undo |
|
297
|
297
|
$value = GravityView_Entry_Approval_Status::APPROVED; |
|
298
|
298
|
} |
|
299
|
299
|
|
|
300
|
|
- self::update_approved_meta( $entry_id, $value, $form['id'] ); |
|
|
300
|
+ self::update_approved_meta( $entry_id, $value, $form[ 'id' ] ); |
|
301
|
301
|
} |
|
302
|
302
|
|
|
303
|
303
|
/** |
|
@@ -315,12 +315,12 @@ discard block |
|
|
block discarded – undo |
|
315
|
315
|
*/ |
|
316
|
316
|
public static function update_bulk( $entries = array(), $approved, $form_id ) { |
|
317
|
317
|
|
|
318
|
|
- if( empty($entries) || ( $entries !== true && !is_array($entries) ) ) { |
|
|
318
|
+ if ( empty( $entries ) || ( $entries !== true && ! is_array( $entries ) ) ) { |
|
319
|
319
|
gravityview()->log->error( 'Entries were empty or malformed.', array( 'data' => $entries ) ); |
|
320
|
320
|
return NULL; |
|
321
|
321
|
} |
|
322
|
322
|
|
|
323
|
|
- if( ! GVCommon::has_cap( 'gravityview_moderate_entries' ) ) { |
|
|
323
|
+ if ( ! GVCommon::has_cap( 'gravityview_moderate_entries' ) ) { |
|
324
|
324
|
gravityview()->log->error( 'User does not have the `gravityview_moderate_entries` capability.' ); |
|
325
|
325
|
return NULL; |
|
326
|
326
|
} |
|
@@ -335,10 +335,10 @@ discard block |
|
|
block discarded – undo |
|
335
|
335
|
$approved_column_id = self::get_approved_column( $form_id ); |
|
336
|
336
|
|
|
337
|
337
|
$success = true; |
|
338
|
|
- foreach( $entries as $entry_id ) { |
|
|
338
|
+ foreach ( $entries as $entry_id ) { |
|
339
|
339
|
$update_success = self::update_approved( (int)$entry_id, $approved, $form_id, $approved_column_id ); |
|
340
|
340
|
|
|
341
|
|
- if( ! $update_success ) { |
|
|
341
|
+ if ( ! $update_success ) { |
|
342
|
342
|
$success = false; |
|
343
|
343
|
} |
|
344
|
344
|
} |
|
@@ -362,12 +362,12 @@ discard block |
|
|
block discarded – undo |
|
362
|
362
|
*/ |
|
363
|
363
|
public static function update_approved( $entry_id = 0, $approved = 2, $form_id = 0, $approvedcolumn = 0 ) { |
|
364
|
364
|
|
|
365
|
|
- if( !class_exists( 'GFAPI' ) ) { |
|
|
365
|
+ if ( ! class_exists( 'GFAPI' ) ) { |
|
366
|
366
|
gravityview()->log->error( 'GFAPI does not exist' ); |
|
367
|
367
|
return false; |
|
368
|
368
|
} |
|
369
|
369
|
|
|
370
|
|
- if( ! GravityView_Entry_Approval_Status::is_valid( $approved ) ) { |
|
|
370
|
+ if ( ! GravityView_Entry_Approval_Status::is_valid( $approved ) ) { |
|
371
|
371
|
gravityview()->log->error( 'Not a valid approval value.' ); |
|
372
|
372
|
return false; |
|
373
|
373
|
} |
|
@@ -384,7 +384,7 @@ discard block |
|
|
block discarded – undo |
|
384
|
384
|
// If the form has an Approve/Reject field, update that value |
|
385
|
385
|
$result = self::update_approved_column( $entry_id, $approved, $form_id, $approvedcolumn ); |
|
386
|
386
|
|
|
387
|
|
- if( is_wp_error( $result ) ) { |
|
|
387
|
+ if ( is_wp_error( $result ) ) { |
|
388
|
388
|
gravityview()->log->error( 'Entry approval not updated: {error}', array( 'error' => $result->get_error_message() ) ); |
|
389
|
389
|
return false; |
|
390
|
390
|
} |
|
@@ -396,7 +396,7 @@ discard block |
|
|
block discarded – undo |
|
396
|
396
|
|
|
397
|
397
|
// add note to entry if approval field updating worked or there was no approved field |
|
398
|
398
|
// There's no validation for the meta |
|
399
|
|
- if( true === $result ) { |
|
|
399
|
+ if ( true === $result ) { |
|
400
|
400
|
|
|
401
|
401
|
// Add an entry note |
|
402
|
402
|
self::add_approval_status_updated_note( $entry_id, $approved ); |
|
@@ -449,7 +449,7 @@ discard block |
|
|
block discarded – undo |
|
449
|
449
|
|
|
450
|
450
|
$note_id = false; |
|
451
|
451
|
|
|
452
|
|
- if( $add_note && class_exists( 'GravityView_Entry_Notes' ) ) { |
|
|
452
|
+ if ( $add_note && class_exists( 'GravityView_Entry_Notes' ) ) { |
|
453
|
453
|
|
|
454
|
454
|
$current_user = wp_get_current_user(); |
|
455
|
455
|
|
|
@@ -471,7 +471,7 @@ discard block |
|
|
block discarded – undo |
|
471
|
471
|
*/ |
|
472
|
472
|
private static function update_approved_column( $entry_id = 0, $status = '0', $form_id = 0, $approvedcolumn = 0 ) { |
|
473
|
473
|
|
|
474
|
|
- if( empty( $approvedcolumn ) ) { |
|
|
474
|
+ if ( empty( $approvedcolumn ) ) { |
|
475
|
475
|
$approvedcolumn = self::get_approved_column( $form_id ); |
|
476
|
476
|
} |
|
477
|
477
|
|
|
@@ -494,12 +494,12 @@ discard block |
|
|
block discarded – undo |
|
494
|
494
|
$status = GravityView_Entry_Approval_Status::maybe_convert_status( $status ); |
|
495
|
495
|
|
|
496
|
496
|
$new_value = ''; |
|
497
|
|
- if( GravityView_Entry_Approval_Status::APPROVED === $status ) { |
|
|
497
|
+ if ( GravityView_Entry_Approval_Status::APPROVED === $status ) { |
|
498
|
498
|
$new_value = self::get_approved_column_input_label( $form_id, $approvedcolumn ); |
|
499
|
499
|
} |
|
500
|
500
|
|
|
501
|
501
|
//update entry |
|
502
|
|
- $entry["{$approvedcolumn}"] = $new_value; |
|
|
502
|
+ $entry[ "{$approvedcolumn}" ] = $new_value; |
|
503
|
503
|
|
|
504
|
504
|
/** |
|
505
|
505
|
* Note: GFAPI::update_entry() doesn't trigger `gform_after_update_entry`, so we trigger updating the meta ourselves |
|
@@ -530,12 +530,12 @@ discard block |
|
|
block discarded – undo |
|
530
|
530
|
// If the user has enabled a different value than the label (for some reason), use it. |
|
531
|
531
|
// This is highly unlikely |
|
532
|
532
|
if ( is_array( $field->choices ) && ! empty( $field->choices ) ) { |
|
533
|
|
- return isset( $field->choices[0]['value'] ) ? $field->choices[0]['value'] : $field->choices[0]['text']; |
|
|
533
|
+ return isset( $field->choices[ 0 ][ 'value' ] ) ? $field->choices[ 0 ][ 'value' ] : $field->choices[ 0 ][ 'text' ]; |
|
534
|
534
|
} |
|
535
|
535
|
|
|
536
|
536
|
// Otherwise, fall back on the inputs array |
|
537
|
537
|
if ( is_array( $field->inputs ) && ! empty( $field->inputs ) ) { |
|
538
|
|
- return $field->inputs[0]['label']; |
|
|
538
|
+ return $field->inputs[ 0 ][ 'label' ]; |
|
539
|
539
|
} |
|
540
|
540
|
|
|
541
|
541
|
return null; |
|
@@ -587,7 +587,7 @@ discard block |
|
|
block discarded – undo |
|
587
|
587
|
* @since 1.18 Added "unapproved" |
|
588
|
588
|
* @param int $entry_id ID of the Gravity Forms entry |
|
589
|
589
|
*/ |
|
590
|
|
- do_action( 'gravityview/approve_entries/' . $action , $entry_id ); |
|
|
590
|
+ do_action( 'gravityview/approve_entries/' . $action, $entry_id ); |
|
591
|
591
|
} |
|
592
|
592
|
|
|
593
|
593
|
/** |
|
@@ -600,11 +600,11 @@ discard block |
|
|
block discarded – undo |
|
600
|
600
|
*/ |
|
601
|
601
|
static public function get_approved_column( $form ) { |
|
602
|
602
|
|
|
603
|
|
- if( empty( $form ) ) { |
|
|
603
|
+ if ( empty( $form ) ) { |
|
604
|
604
|
return null; |
|
605
|
605
|
} |
|
606
|
606
|
|
|
607
|
|
- if( !is_array( $form ) ) { |
|
|
607
|
+ if ( ! is_array( $form ) ) { |
|
608
|
608
|
$form = GVCommon::get_form( $form ); |
|
609
|
609
|
} |
|
610
|
610
|
|
|
@@ -614,22 +614,22 @@ discard block |
|
|
block discarded – undo |
|
614
|
614
|
* @var string $key |
|
615
|
615
|
* @var GF_Field $field |
|
616
|
616
|
*/ |
|
617
|
|
- foreach( $form['fields'] as $key => $field ) { |
|
|
617
|
+ foreach ( $form[ 'fields' ] as $key => $field ) { |
|
618
|
618
|
|
|
619
|
619
|
$inputs = $field->get_entry_inputs(); |
|
620
|
620
|
|
|
621
|
|
- if( !empty( $field->gravityview_approved ) ) { |
|
622
|
|
- if ( ! empty( $inputs ) && !empty( $inputs[0]['id'] ) ) { |
|
623
|
|
- $approved_column_id = $inputs[0]['id']; |
|
|
621
|
+ if ( ! empty( $field->gravityview_approved ) ) { |
|
|
622
|
+ if ( ! empty( $inputs ) && ! empty( $inputs[ 0 ][ 'id' ] ) ) { |
|
|
623
|
+ $approved_column_id = $inputs[ 0 ][ 'id' ]; |
|
624
|
624
|
break; |
|
625
|
625
|
} |
|
626
|
626
|
} |
|
627
|
627
|
|
|
628
|
628
|
// Note: This is just for backward compatibility from GF Directory plugin and old GV versions - when using i18n it may not work.. |
|
629
|
|
- if( 'checkbox' === $field->type && ! empty( $inputs ) ) { |
|
|
629
|
+ if ( 'checkbox' === $field->type && ! empty( $inputs ) ) { |
|
630
|
630
|
foreach ( $inputs as $input ) { |
|
631
|
|
- if ( 'approved' === strtolower( $input['label'] ) ) { |
|
632
|
|
- $approved_column_id = $input['id']; |
|
|
631
|
+ if ( 'approved' === strtolower( $input[ 'label' ] ) ) { |
|
|
632
|
+ $approved_column_id = $input[ 'id' ]; |
|
633
|
633
|
break; |
|
634
|
634
|
} |
|
635
|
635
|
} |
|
@@ -655,7 +655,7 @@ discard block |
|
|
block discarded – undo |
|
655
|
655
|
|
|
656
|
656
|
$view_keys = array_keys( $gv_data->get_views() ); |
|
657
|
657
|
|
|
658
|
|
- $view = \GV\View::by_id( $view_keys[0] ); |
|
|
658
|
+ $view = \GV\View::by_id( $view_keys[ 0 ] ); |
|
659
|
659
|
|
|
660
|
660
|
if ( ! $view->settings->get( 'unapprove_edit' ) ) { |
|
661
|
661
|
return; |
|
@@ -680,11 +680,11 @@ discard block |
|
|
block discarded – undo |
|
680
|
680
|
return; |
|
681
|
681
|
} |
|
682
|
682
|
|
|
683
|
|
- if( ! GravityView_Entry_Approval_Status::is_valid( $approval_status ) ) { |
|
|
683
|
+ if ( ! GravityView_Entry_Approval_Status::is_valid( $approval_status ) ) { |
|
684
|
684
|
$approval_status = GravityView_Entry_Approval_Status::UNAPPROVED; |
|
685
|
685
|
} |
|
686
|
686
|
|
|
687
|
|
- self::update_approved_meta( $entry_id, $approval_status, $form['id'] ); |
|
|
687
|
+ self::update_approved_meta( $entry_id, $approval_status, $form[ 'id' ] ); |
|
688
|
688
|
} |
|
689
|
689
|
|
|
690
|
690
|
} |