← All changes
|
integrations/advanced-ads/includes/triggers/ad-published.php
+81
-0
5.8.2
→
6.0.4
View file →
| @@ -1,0 +1,81 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Ad Published | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Integrations\Advanced_Ads\Triggers\Ad_Published | |
| 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_Advanced_Ads_Ad_Published extends AutomatorWP_Integration_Trigger { | |
| 13 | + | |
| 14 | + public $integration = 'advanced_ads'; | |
| 15 | + public $trigger = 'advanced_ads_ad_published'; | |
| 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 ad gets published', 'automatorwp' ), | |
| 27 | + 'select_option' => __( 'User ad gets <strong>published</strong>', 'automatorwp' ), | |
| 28 | + /* translators: %1$s: Number of times. */ | |
| 29 | + 'edit_label' => sprintf( __( 'User ad gets published %1$s time(s)', 'automatorwp' ), '{times}' ), | |
| 30 | + 'log_label' => __( 'User ad gets published', 'automatorwp' ), | |
| 31 | + 'action' => 'advanced-ads-ad-status-published', | |
| 32 | + 'function' => array( $this, 'listener' ), | |
| 33 | + 'priority' => 10, | |
| 34 | + 'accepted_args' => 1, | |
| 35 | + 'options' => array( | |
| 36 | + 'times' => automatorwp_utilities_times_option(), | |
| 37 | + ), | |
| 38 | + 'tags' => array_merge( | |
| 39 | + automatorwp_utilities_post_tags(), | |
| 40 | + automatorwp_utilities_times_tag() | |
| 41 | + ) | |
| 42 | + ) ); | |
| 43 | + | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Trigger listener | |
| 48 | + * | |
| 49 | + * @since 1.0.0 | |
| 50 | + * | |
| 51 | + * @param Advanced_Ads_Ad $ad | |
| 52 | + */ | |
| 53 | + public function listener( $ad ) { | |
| 54 | + | |
| 55 | + $ad_id = $ad->get_id( $ad ); | |
| 56 | + | |
| 57 | + $post = get_post( $ad_id ); | |
| 58 | + | |
| 59 | + // Bail if post does not exists | |
| 60 | + if( ! $post ) { | |
| 61 | + return; | |
| 62 | + } | |
| 63 | + | |
| 64 | + $user_id = absint( $post->post_author ); | |
| 65 | + | |
| 66 | + // Bail if post does not has an author assigned | |
| 67 | + if( absint( $user_id === 0 ) ) { | |
| 68 | + return; | |
| 69 | + } | |
| 70 | + | |
| 71 | + automatorwp_trigger_event( array( | |
| 72 | + 'trigger' => $this->trigger, | |
| 73 | + 'user_id' => $user_id, | |
| 74 | + 'post_id' => $ad_id, | |
| 75 | + ) ); | |
| 76 | + | |
| 77 | + } | |
| 78 | + | |
| 79 | +} | |
| 80 | + | |
| 81 | +new AutomatorWP_Advanced_Ads_Ad_Published(); | |