PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.4
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.4
6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 All 35 releases
← All changes | integrations/geodirectory/includes/triggers/anonymous-comment-posted.php +115 -0 5.7.3 → 6.0.4 View file →
@@ -1,0 +1,115 @@
1 +<?php
2 +
3 +/**
4 + * Anonymous user reviews a place
5 + *
6 + * @package AutomatorWP\Integrations\GeoDirectory\Triggers\Anonymous_Comment_Posted
7 + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
8 + * @since 1.0.0
9 + */
10 +// Exit if accessed directly
11 +if (!defined('ABSPATH')) exit;
12 +
13 +class AutomatorWP_GeoDirectory_Anonymous_Comment_Posted extends AutomatorWP_Integration_Trigger
14 +{
15 +
16 + public $integration = 'geodirectory';
17 + public $trigger = 'geodirectory_anonymous_comment_posted';
18 +
19 + /**
20 + * Register the trigger
21 + *
22 + * @since 1.0.0
23 + */
24 + public function register()
25 + {
26 +
27 + automatorwp_register_trigger($this->trigger, array(
28 + 'integration' => $this->integration,
29 + 'anonymous' => true,
30 + 'label' => __('Guest reviews a place', 'automatorwp'),
31 + 'select_option' => __('Guest <strong>reviews</strong> a place', 'automatorwp'),
32 + /* translators: %1$s: Place name. %2$s: Number of times. */
33 + 'edit_label' => sprintf(__('Guest reviews %1$s %2$s time(s)', 'automatorwp'), '{post}', '{times}'),
34 + /* translators: %1$s: Place name. */
35 + 'log_label' => sprintf(__('Guest reviews %1$s', 'automatorwp'), '{post}'),
36 + 'action' => 'geodir_update_post_rating',
37 + 'function' => array($this, 'listener'),
38 + 'priority' => 10,
39 + 'accepted_args' => 1,
40 + 'options' => array(
41 + 'post' => automatorwp_utilities_post_option(array(
42 + 'name' => __('Place:', 'automatorwp'),
43 + 'option_none_label' => __('any place', 'automatorwp'),
44 + 'post_type' => 'gd_place'
45 + )),
46 + 'times' => automatorwp_utilities_times_option(),
47 + ),
48 + 'tags' => array_merge(
49 + automatorwp_utilities_post_tags(),
50 + automatorwp_utilities_times_tag()
51 + )
52 + ));
53 + }
54 +
55 + /**
56 + * Trigger listener
57 + *
58 + * @since 1.0.0
59 + *
60 + * @param array $review
61 + */
62 + public function listener( $review )
63 + {
64 +
65 + // Bail if place id is not provided
66 + if ( empty( $review ) ) {
67 + return;
68 + }
69 +
70 + $user_id = get_current_user_id();
71 +
72 + // Bail if user is logged
73 + if ( $user_id !== 0 ) {
74 + return;
75 + }
76 +
77 + $post_id = $review['comment_post_ID'];
78 +
79 + automatorwp_trigger_event (array(
80 + 'trigger' => $this->trigger,
81 + 'post_id' => $post_id,
82 + ) );
83 + }
84 +
85 + /**
86 + * User deserves check
87 + *
88 + * @since 1.0.0
89 + *
90 + * @param bool $deserves_trigger True if user deserves trigger, false otherwise
91 + * @param stdClass $trigger The trigger object
92 + * @param int $user_id The user ID
93 + * @param array $event Event information
94 + * @param array $trigger_options The trigger's stored options
95 + * @param stdClass $automation The trigger's automation object
96 + *
97 + * @return bool True if user deserves trigger, false otherwise
98 + */
99 + public function user_deserves_trigger($deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation)
100 + {
101 + // Don't deserve if post is not received
102 + if ( !isset( $event['post_id'] ) ) {
103 + return false;
104 + }
105 +
106 + // Don't deserve if post doesn't match with the trigger option
107 + if( ! automatorwp_posts_matches( $event['post_id'], $trigger_options['post'] ) ) {
108 + return false;
109 + }
110 +
111 + return $deserves_trigger;
112 + }
113 +}
114 +
115 +new AutomatorWP_GeoDirectory_Anonymous_Comment_Posted();