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
automatorwp / integrations / wp-job-manager / includes / triggers / publish-job.php

publish-job.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.4, at integrations/wp-job-manager/includes/triggers/publish-job.php

123 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Publish Job
4 *
5 * @package AutomatorWP\Integrations\WP_Job_Manager\Triggers\Publish_Job
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_WP_Job_Manager_Publish_Job extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'wp_job_manager';
15 public $trigger = 'wp_job_manager_publish_job';
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 publishes a job of a type', 'automatorwp' ),
27 'select_option' => __( 'User publishes <strong>a job</strong> of a type', 'automatorwp' ),
28 /* translators: %1$s: Term title. %2$s: Number of times. */
29 'edit_label' => sprintf( __( 'User publishes a job of %1$s %2$s time(s)', 'automatorwp' ), '{term}', '{times}' ),
30 /* translators: %1$s: Term title. */
31 'log_label' => sprintf( __( 'User publishes a job of %1$s', 'automatorwp' ), '{term}' ),
32 'action' => 'transition_post_status',
33 'function' => array( $this, 'listener' ),
34 'priority' => 10,
35 'accepted_args' => 3,
36 'options' => array(
37 'term' => automatorwp_utilities_term_option( array(
38 'name' => __( 'Type:', 'automatorwp' ),
39 'option_none_label' => __( 'any type', 'automatorwp' ),
40 'taxonomy' => 'job_listing_type',
41 ) ),
42 'times' => automatorwp_utilities_times_option(),
43 ),
44 'tags' => array_merge(
45 automatorwp_utilities_post_tags( __( 'Job', 'automatorwp' ) ),
46 automatorwp_utilities_times_tag()
47 )
48 ) );
49
50 }
51
52 /**
53 * Trigger listener
54 *
55 * @since 1.0.0
56 *
57 * @param string $new_status The new post status
58 * @param string $old_status The old post status
59 * @param WP_Post $post The post
60 */
61 public function listener( $new_status, $old_status, $post ) {
62
63 // Bail if post type is not a job
64 if( $post->post_type !== 'job_listing' ) {
65 return;
66 }
67
68 // Bail if post is already published
69 if( $old_status === 'publish' ) {
70 return;
71 }
72
73 // Bail if post is not published
74 if( $new_status !== 'publish' ) {
75 return;
76 }
77
78 $terms_ids = automatorwp_get_term_ids( $post->ID, 'job_listing_type' );
79
80 $user_id = get_current_user_id();
81
82 automatorwp_trigger_event( array(
83 'trigger' => $this->trigger,
84 'user_id' => $user_id,
85 'post_id' => $post->ID,
86 'terms_ids' => $terms_ids,
87 ) );
88
89 }
90
91 /**
92 * User deserves check
93 *
94 * @since 1.0.0
95 *
96 * @param bool $deserves_trigger True if user deserves trigger, false otherwise
97 * @param stdClass $trigger The trigger object
98 * @param int $user_id The user ID
99 * @param array $event Event information
100 * @param array $trigger_options The trigger's stored options
101 * @param stdClass $automation The trigger's automation object
102 *
103 * @return bool True if user deserves trigger, false otherwise
104 */
105 public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
106
107 // Don't deserve if post and terms IDs are not received
108 if( ! isset( $event['post_id'] ) && ! isset( $event['terms_ids'] ) ) {
109 return false;
110 }
111
112 // Don't deserve if term doesn't match with the trigger option
113 if( ! automatorwp_terms_matches( $event['terms_ids'], $trigger_options['term'] ) ) {
114 return false;
115 }
116
117 return $deserves_trigger;
118
119 }
120
121 }
122
123 new AutomatorWP_WP_Job_Manager_Publish_Job();