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/shortlinkspro/includes/triggers/click-link.php +161 -0 5.8.4 → 6.0.4 View file →
@@ -1,0 +1,161 @@
1 +<?php
2 +/**
3 + * Click a Link
4 + *
5 + * @package AutomatorWP\Integrations\ShortLinksPro\Triggers\Click_Link
6 + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 + * @since 1.0.0
8 + */
9 +// Exit if accessed directly
10 +if( !defined( 'ABSPATH' ) ) exit;
11 +
12 +class AutomatorWP_ShortLinksPro_Click_Link extends AutomatorWP_Integration_Trigger {
13 +
14 + public $integration = 'shortlinkspro';
15 + public $trigger = 'shortlinkspro_click_link';
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 + 'label' => __( 'User clicks a link', 'automatorwp' ),
27 + 'select_option' => __( 'User clicks <strong>a link</strong>', 'automatorwp' ),
28 + /* translators: %1$s: Link title. %2$s: Number of times. */
29 + 'edit_label' => sprintf( __( 'User clicks %1$s %2$s time(s)', 'automatorwp' ), '{post}', '{times}' ),
30 + /* translators: %1$s: Link title. */
31 + 'log_label' => sprintf( __( 'User clicks %1$s', 'automatorwp' ), '{post}' ),
32 + 'action' => 'shortlinkspro_before_redirect',
33 + 'function' => array( $this, 'listener' ),
34 + 'priority' => 10,
35 + 'accepted_args' => 3,
36 + 'options' => array(
37 + 'post' => automatorwp_utilities_ajax_selector_option( array(
38 + 'field' => 'post',
39 + 'name' => __( 'Link:', 'automatorwp' ),
40 + 'option_none_value' => 'any',
41 + 'option_none_label' => __( 'any link', 'automatorwp' ),
42 + 'action_cb' => 'automatorwp_shortlinkspro_get_links',
43 + 'options_cb' => 'automatorwp_shortlinkspro_options_cb_link',
44 + 'default' => 'any'
45 + ) ),
46 + 'times' => automatorwp_utilities_times_option(),
47 + ),
48 + 'tags' => array_merge(
49 + automatorwp_shortlinkspro_get_link_tags(),
50 + automatorwp_utilities_times_tag()
51 + )
52 +
53 + ) );
54 + }
55 +
56 + /**
57 + * Trigger listener
58 + *
59 + * @since 1.0.0
60 + *
61 + * @param stdClass $link Link object
62 + * @param string $parameters The query parameters
63 + * @param string $url URL to redirect
64 + */
65 + public function listener( $link, $parameters, $url ) {
66 +
67 + $user_id = get_current_user_id();
68 +
69 + // Login is required
70 + if ( $user_id === 0 ) {
71 + return;
72 + }
73 +
74 + // Shorthand
75 + $link_id = $link->id;
76 + $link_slug = $link->slug;
77 +
78 + // Trigger submit form event
79 + automatorwp_trigger_event( array(
80 + 'trigger' => $this->trigger,
81 + 'user_id' => $user_id,
82 + 'link_id' => $link_id,
83 + 'link_slug' => $link_slug,
84 + ) );
85 +
86 + }
87 +
88 + /**
89 + * User deserves check
90 + *
91 + * @since 1.0.0
92 + *
93 + * @param bool $deserves_trigger True if user deserves trigger, false otherwise
94 + * @param stdClass $trigger The trigger object
95 + * @param int $user_id The user ID
96 + * @param array $event Event information
97 + * @param array $trigger_options The trigger's stored options
98 + * @param stdClass $automation The trigger's automation object
99 + *
100 + * @return bool True if user deserves trigger, false otherwise
101 + */
102 + public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
103 +
104 + // Don't deserve if post is not received
105 + if( ! isset( $event['link_id'] ) ) {
106 + return false;
107 + }
108 +
109 + // Bail if post doesn't match with the trigger option
110 + if( $trigger_options['post'] !== 'any' && absint( $event['link_id'] ) !== absint( $trigger_options['post'] ) ) {
111 + return false;
112 + }
113 +
114 + return $deserves_trigger;
115 +
116 + }
117 +
118 + /**
119 + * Register the required hooks
120 + *
121 + * @since 1.0.0
122 + */
123 + public function hooks() {
124 +
125 + // Log meta data
126 + add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
127 +
128 + parent::hooks();
129 + }
130 +
131 + /**
132 + * Trigger custom log meta
133 + *
134 + * @since 1.0.0
135 + *
136 + * @param array $log_meta Log meta data
137 + * @param stdClass $trigger The trigger object
138 + * @param int $user_id The user ID
139 + * @param array $event Event information
140 + * @param array $trigger_options The trigger's stored options
141 + * @param stdClass $automation The trigger's automation object
142 + *
143 + * @return array
144 + */
145 + function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
146 +
147 + // Bail if action type don't match this action
148 + if( $trigger->type !== $this->trigger ) {
149 + return $log_meta;
150 + }
151 +
152 + $log_meta['link_slug'] = ( isset( $event['link_slug'] ) ? $event['link_slug'] : '' );
153 +
154 + return $log_meta;
155 +
156 + }
157 +
158 +}
159 +
160 +
161 +new AutomatorWP_ShortLinksPro_Click_Link();