listing-deleted.php
3 weeks ago
listing-published.php
3 weeks ago
listing-updated.php
3 weeks ago
new-listing-submitted.php
3 weeks ago
new-review-submitted.php
3 weeks ago
review-published.php
3 weeks ago
listing-published.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * ListingPublished |
| 4 | * |
| 5 | * @package SureTriggers |
| 6 | * @category Integration |
| 7 | * @author BSF |
| 8 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 9 | * @link https://www.brainstormforce.com/ |
| 10 | * @since 1.1.26 |
| 11 | */ |
| 12 | |
| 13 | namespace SureTriggers\Integrations\DirectoriesPro\Triggers; |
| 14 | |
| 15 | use SureTriggers\Controllers\AutomationController; |
| 16 | use SureTriggers\Integrations\DirectoriesPro\DirectoriesPro; |
| 17 | use SureTriggers\Traits\SingletonLoader; |
| 18 | |
| 19 | if ( ! class_exists( 'ListingPublished' ) ) : |
| 20 | |
| 21 | /** |
| 22 | * ListingPublished |
| 23 | * |
| 24 | * @category ListingPublished |
| 25 | * @package SureTriggers |
| 26 | * @author BSF <username@example.com> |
| 27 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 28 | * @link https://www.brainstormforce.com/ |
| 29 | * @since 1.1.26 |
| 30 | */ |
| 31 | class ListingPublished { |
| 32 | |
| 33 | use SingletonLoader; |
| 34 | |
| 35 | /** |
| 36 | * Integration name. |
| 37 | * |
| 38 | * @var string |
| 39 | */ |
| 40 | public $integration = 'DirectoriesPro'; |
| 41 | |
| 42 | /** |
| 43 | * Trigger name. |
| 44 | * |
| 45 | * @var string |
| 46 | */ |
| 47 | public $trigger = 'directories_pro_listing_published'; |
| 48 | |
| 49 | /** |
| 50 | * Constructor. |
| 51 | */ |
| 52 | public function __construct() { |
| 53 | add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Register trigger. |
| 58 | * |
| 59 | * @param array $triggers Registered triggers. |
| 60 | * @return array Modified triggers. |
| 61 | */ |
| 62 | public function register( $triggers ) { |
| 63 | $triggers[ $this->integration ][ $this->trigger ] = [ |
| 64 | 'label' => __( 'Listing Published', 'suretriggers' ), |
| 65 | 'action' => $this->trigger, |
| 66 | 'common_action' => 'transition_post_status', |
| 67 | 'function' => [ $this, 'trigger_listener' ], |
| 68 | 'priority' => 10, |
| 69 | 'accepted_args' => 3, |
| 70 | ]; |
| 71 | |
| 72 | return $triggers; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Trigger listener. |
| 77 | * |
| 78 | * @param string $new_status New post status. |
| 79 | * @param string $old_status Old post status. |
| 80 | * @param \WP_Post $post Post object. |
| 81 | * @return void |
| 82 | */ |
| 83 | public function trigger_listener( $new_status, $old_status, $post ) { |
| 84 | if ( 'publish' !== $new_status || 'publish' === $old_status || empty( $post ) ) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | $bundle = DirectoriesPro::get_bundle( $post->post_type ); |
| 89 | if ( ! DirectoriesPro::is_listing_bundle( $bundle ) ) { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | $context = DirectoriesPro::build_entity_context( $post, $bundle ); |
| 94 | |
| 95 | AutomationController::sure_trigger_handle_trigger( |
| 96 | [ |
| 97 | 'trigger' => $this->trigger, |
| 98 | 'context' => $context, |
| 99 | ] |
| 100 | ); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | ListingPublished::get_instance(); |
| 105 | |
| 106 | endif; |
| 107 |