| 1 |
<?php |
| 2 |
/** |
| 3 |
* Anonymous Entry Approved |
| 4 |
* |
| 5 |
* @package AutomatorWP\Integrations\Gravity_Kit\Triggers\Anonymous_Entry_Approved |
| 6 |
* @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
class AutomatorWP_Gravity_Kit_Anonymous_Entry_Approved extends AutomatorWP_Integration_Trigger { |
| 13 |
|
| 14 |
public $integration = 'gravity_kit'; |
| 15 |
public $trigger = 'gravity_kit_anonymous_entry_approved'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Register the trigger |
| 19 |
* |
| 20 |
* @since 1.0.0 |
| 21 |
*/ |
| 22 |
public function register() { |
| 23 |
|
| 24 |
automatorwp_register_trigger( $this->trigger, array( |
| 25 |
'integration' => $this->integration, |
| 26 |
'anonymous' => true, |
| 27 |
'label' => __( 'Guest gets entry approved in form', 'automatorwp' ), |
| 28 |
'select_option' => __( 'Guest gets entry approved in <strong>form</strong>', 'automatorwp' ), |
| 29 |
/* translators: %1$s: Post title. %2$s: Number of times. */ |
| 30 |
'edit_label' => sprintf( __( 'Guest gets entry approved in %1$s %2$s time(s)', 'automatorwp' ), '{post}', '{times}' ), |
| 31 |
/* translators: %1$s: Post title. */ |
| 32 |
'log_label' => sprintf( __( 'Guest gets entry approved in %1$s', 'automatorwp' ), '{post}' ), |
| 33 |
'action' => 'gravityview/approve_entries/approved', |
| 34 |
'function' => array( $this, 'listener' ), |
| 35 |
'priority' => 10, |
| 36 |
'accepted_args' => 1, |
| 37 |
'options' => array( |
| 38 |
'post' => automatorwp_utilities_ajax_selector_option( array( |
| 39 |
'field' => 'post', |
| 40 |
'name' => __( 'Form:', 'automatorwp' ), |
| 41 |
'option_none_value' => 'any', |
| 42 |
'option_none_label' => __( 'any form', 'automatorwp' ), |
| 43 |
'action_cb' => 'automatorwp_gravity_kit_get_forms', |
| 44 |
'options_cb' => 'automatorwp_gravity_kit_options_cb_form', |
| 45 |
'default' => 'any' |
| 46 |
) ), |
| 47 |
'times' => automatorwp_utilities_times_option(), |
| 48 |
), |
| 49 |
'tags' => array( |
| 50 |
automatorwp_utilities_times_tag() |
| 51 |
) |
| 52 |
) ); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Trigger listener |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* |
| 61 |
* @param int $entry_id ID of entry |
| 62 |
*/ |
| 63 |
public function listener( $entry_id ) { |
| 64 |
|
| 65 |
$user_id = automatorwp_gravity_kit_get_entry_user ( $entry_id ); |
| 66 |
|
| 67 |
//Bail if empty user |
| 68 |
if ( ! empty( $user_id ) ) { |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
$form_id = automatorwp_gravity_kit_get_entry_form( $entry_id ); |
| 73 |
|
| 74 |
// Trigger submit form event |
| 75 |
automatorwp_trigger_event( array( |
| 76 |
'trigger' => $this->trigger, |
| 77 |
'form_id' => $form_id, |
| 78 |
) ); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* User deserves check |
| 84 |
* |
| 85 |
* @since 1.0.0 |
| 86 |
* |
| 87 |
* @param bool $deserves_trigger True if user deserves trigger, false otherwise |
| 88 |
* @param stdClass $trigger The trigger object |
| 89 |
* @param array $event Event information |
| 90 |
* @param array $trigger_options The trigger's stored options |
| 91 |
* @param stdClass $automation The trigger's automation object |
| 92 |
* |
| 93 |
* @return bool True if user deserves trigger, false otherwise |
| 94 |
*/ |
| 95 |
public function anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation ) { |
| 96 |
|
| 97 |
// Don't deserve if post is not received |
| 98 |
if( ! isset( $event['form_id'] ) ) { |
| 99 |
return false; |
| 100 |
} |
| 101 |
|
| 102 |
// Bail if post doesn't match with the trigger option |
| 103 |
if( $trigger_options['post'] !== 'any' && absint( $event['form_id'] ) !== absint( $trigger_options['post'] ) ) { |
| 104 |
return false; |
| 105 |
} |
| 106 |
|
| 107 |
return $deserves_trigger; |
| 108 |
|
| 109 |
} |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
new AutomatorWP_Gravity_Kit_Anonymous_Entry_Approved(); |