PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
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 5.6.1 All 34 releases
← All changes | integrations/wordpress/triggers/anonymous-view-post-taxonomy.php +144 -0 5.7.8 → 6.0.3 View file →
@@ -1,0 +1,144 @@
1 +<?php
2 +/**
3 + * Anonymous View Post Taxonomy
4 + *
5 + * @package AutomatorWP\Integrations\WordPress\Triggers\Anonymous_View_Post_Taxonomy
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_WordPress_Anonymous_View_Post_Taxonomy extends AutomatorWP_Integration_Trigger {
13 +
14 + /**
15 + * Initialize the trigger
16 + *
17 + * @since 1.0.0
18 + */
19 + public function __construct( $integration ) {
20 +
21 + $this->integration = $integration;
22 + $this->trigger = $integration . '_anonymous_view_post_taxonomy';
23 +
24 + parent::__construct();
25 +
26 + }
27 +
28 + /**
29 + * Register the trigger
30 + *
31 + * @since 1.0.0
32 + */
33 + public function register() {
34 +
35 + automatorwp_register_trigger( $this->trigger, array(
36 + 'integration' => $this->integration,
37 + 'anonymous' => true,
38 + 'label' => __( 'Guest views a post of a taxonomy', 'automatorwp' ),
39 + 'select_option' => __( 'Guest views a post of <strong>a taxonomy</strong>', 'automatorwp' ),
40 + /* translators: %1$s: Term title. %2$s: Number of times. */
41 + 'edit_label' => sprintf( __( 'Guest views a post of %1$s %2$s time(s)', 'automatorwp' ), '{term}', '{times}' ),
42 + /* translators: %1$s: Term title. */
43 + 'log_label' => sprintf( __( 'Guest views a post of %1$s', 'automatorwp' ), '{term}' ),
44 + 'action' => 'template_redirect',
45 + 'function' => array( $this, 'listener' ),
46 + 'priority' => 10,
47 + 'accepted_args' => 1,
48 + 'options' => array(
49 + 'term' => automatorwp_utilities_taxonomy_option(),
50 + 'times' => automatorwp_utilities_times_option(),
51 + ),
52 + 'tags' => array_merge(
53 + automatorwp_utilities_post_tags(),
54 + automatorwp_utilities_times_tag()
55 + )
56 + ) );
57 +
58 + }
59 +
60 + /**
61 + * Trigger listener
62 + *
63 + * @since 1.0.0
64 + */
65 + public function listener() {
66 +
67 + global $post;
68 +
69 + // Bail if in admin area
70 + if( is_admin() ) {
71 + return;
72 + }
73 +
74 + // Bail if not post instanced
75 + if( ! $post instanceof WP_Post ) {
76 + return;
77 + }
78 +
79 + $taxonomies = get_object_taxonomies( $post->post_type );
80 +
81 + foreach( $taxonomies as $taxonomy ) {
82 +
83 + $terms_ids = automatorwp_get_term_ids( $post->ID, $taxonomy );
84 +
85 + // Bail if post isn't assigned to any category
86 + if( empty( $terms_ids ) ) {
87 + continue;
88 + }
89 +
90 + $user_id = get_current_user_id();
91 +
92 + // Bail if user is logged in
93 + if( $user_id !== 0 ) {
94 + return;
95 + }
96 +
97 + automatorwp_trigger_event( array(
98 + 'trigger' => $this->trigger,
99 + 'post_id' => $post->ID,
100 + 'taxonomy' => $taxonomy,
101 + 'terms_ids' => $terms_ids,
102 + ) );
103 + }
104 +
105 + }
106 +
107 + /**
108 + * Anonymous deserves check
109 + *
110 + * @since 1.0.0
111 + *
112 + * @param bool $deserves_trigger True if anonymous deserves trigger, false otherwise
113 + * @param stdClass $trigger The trigger object
114 + * @param array $event Event information
115 + * @param array $trigger_options The trigger's stored options
116 + * @param stdClass $automation The trigger's automation object
117 + *
118 + * @return bool True if anonymous deserves trigger, false otherwise
119 + */
120 + public function anonymous_deserves_trigger( $deserves_trigger, $trigger, $event, $trigger_options, $automation ) {
121 +
122 + // Don't deserve if post, taxonomy and terms IDs are not received
123 + if( ! isset( $event['post_id'] ) && ! isset( $event['taxonomy'] ) && ! isset( $event['terms_ids'] ) ) {
124 + return false;
125 + }
126 +
127 + // Don't deserve if taxonomy doesn't match with the trigger option
128 + if( $trigger_options['taxonomy'] !== 'any' && $trigger_options['taxonomy'] !== $event['taxonomy'] ) {
129 + return false;
130 + }
131 +
132 + // Don't deserve if term doesn't match with the trigger option
133 + if( ! automatorwp_terms_matches( $event['terms_ids'], $trigger_options['term'] ) ) {
134 + return false;
135 + }
136 +
137 + return $deserves_trigger;
138 +
139 + }
140 +
141 +}
142 +
143 +new AutomatorWP_WordPress_Anonymous_View_Post_Taxonomy( 'wordpress' );
144 +new AutomatorWP_WordPress_Anonymous_View_Post_Taxonomy( 'posts' );