PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.1.33
OttoKit: All-in-One Automation Platform v1.1.33
1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Integrations / wpadverts / wpadverts.php
suretriggers / src / Integrations / wpadverts Last commit date
triggers 3 months ago wpadverts.php 3 months ago
wpadverts.php
187 lines
1 <?php
2 /**
3 * WPAdverts core integrations file
4 *
5 * @since 1.0.0
6 * @package SureTrigger
7 */
8
9 namespace SureTriggers\Integrations\WPAdverts;
10
11 use SureTriggers\Controllers\IntegrationsController;
12 use SureTriggers\Integrations\Integrations;
13 use SureTriggers\Traits\SingletonLoader;
14
15 /**
16 * Class SureTrigger
17 *
18 * @package SureTriggers\Integrations\WPAdverts
19 */
20 class WPAdverts extends Integrations {
21
22 use SingletonLoader;
23
24 /**
25 * ID
26 *
27 * @var string
28 */
29 protected $id = 'WPAdverts';
30
31 /**
32 * SureTrigger constructor.
33 */
34 public function __construct() {
35 $this->name = __( 'WP Adverts', 'suretriggers' );
36 $this->description = __( 'WPAdverts is the lightest plugin to create a classifieds or job board on your WordPress site.', 'suretriggers' );
37 $this->icon_url = SURE_TRIGGERS_URL . 'assets/icons/wpadverts.svg';
38
39 parent::__construct();
40 }
41
42 /**
43 * Is Plugin depended plugin is installed or not.
44 *
45 * @return bool
46 */
47 public function is_plugin_installed() {
48 return defined( 'ADVERTS_FILE' );
49 }
50
51 /**
52 * Get advert context data.
53 *
54 * @param int $post_id Advert post ID.
55 * @return array
56 */
57 public static function get_advert_context( $post_id ) {
58 $post = get_post( $post_id );
59
60 if ( ! $post instanceof \WP_Post ) {
61 return [];
62 }
63
64 $context = [
65 'advert_id' => $post->ID,
66 'advert_title' => $post->post_title,
67 'advert_content' => $post->post_content,
68 'advert_status' => $post->post_status,
69 'advert_url' => get_permalink( $post->ID ),
70 'advert_date' => $post->post_date,
71 'advert_author' => $post->post_author,
72 ];
73
74 $person = get_post_meta( $post_id, 'adverts_person', true );
75 if ( ! empty( $person ) ) {
76 $context['advert_contact_name'] = $person;
77 }
78
79 $email = get_post_meta( $post_id, 'adverts_email', true );
80 if ( ! empty( $email ) ) {
81 $context['advert_contact_email'] = $email;
82 }
83
84 $phone = get_post_meta( $post_id, 'adverts_phone', true );
85 if ( ! empty( $phone ) ) {
86 $context['advert_contact_phone'] = $phone;
87 }
88
89 $price = get_post_meta( $post_id, 'adverts_price', true );
90 if ( ! empty( $price ) ) {
91 $context['advert_price'] = $price;
92 }
93
94 $location = get_post_meta( $post_id, 'adverts_location', true );
95 if ( ! empty( $location ) ) {
96 $context['advert_location'] = $location;
97 }
98
99 $featured_image = wp_get_attachment_image_src( (int) get_post_thumbnail_id( $post->ID ), 'full' );
100 if ( ! empty( $featured_image ) && is_array( $featured_image ) ) {
101 $context['advert_featured_image'] = $featured_image[0];
102 }
103
104 $categories = get_the_terms( $post->ID, 'advert_category' );
105 if ( ! empty( $categories ) && is_array( $categories ) ) {
106 $cat_names = [];
107 $cat_ids = [];
108 foreach ( $categories as $category ) {
109 $cat_names[] = $category->name;
110 $cat_ids[] = $category->term_id;
111 }
112 $context['advert_categories'] = implode( ', ', $cat_names );
113 $context['advert_category_ids'] = implode( ', ', $cat_ids );
114 }
115
116 $expiration = get_post_meta( $post_id, '_expiration_date', true );
117 if ( ! empty( $expiration ) ) {
118 $context['advert_expiration_date'] = is_numeric( $expiration ) ? gmdate( 'Y-m-d H:i:s', absint( $expiration ) ) : '';
119 }
120
121 return $context;
122 }
123
124 /**
125 * Get payment context data.
126 *
127 * @param \WP_Post $payment Payment post object.
128 * @return array
129 */
130 public static function get_payment_context( $payment ) {
131 if ( ! $payment instanceof \WP_Post ) {
132 return [];
133 }
134
135 $context = [
136 'payment_id' => $payment->ID,
137 'payment_title' => $payment->post_title,
138 'payment_status' => $payment->post_status,
139 'payment_date' => $payment->post_date,
140 ];
141
142 $object_id = get_post_meta( $payment->ID, '_adverts_object_id', true );
143 if ( ! empty( $object_id ) ) {
144 $context['payment_advert_id'] = $object_id;
145 }
146
147 $paid = get_post_meta( $payment->ID, '_adverts_payment_paid', true );
148 if ( '' !== $paid ) {
149 $context['payment_amount_paid'] = $paid;
150 }
151
152 $total = get_post_meta( $payment->ID, '_adverts_payment_total', true );
153 if ( '' !== $total ) {
154 $context['payment_amount_total'] = $total;
155 }
156
157 $gateway = get_post_meta( $payment->ID, '_adverts_payment_gateway', true );
158 if ( ! empty( $gateway ) ) {
159 $context['payment_gateway'] = $gateway;
160 }
161
162 $payment_type = get_post_meta( $payment->ID, '_adverts_payment_type', true );
163 if ( ! empty( $payment_type ) ) {
164 $context['payment_type'] = $payment_type;
165 }
166
167 $buyer_name = get_post_meta( $payment->ID, 'adverts_person', true );
168 if ( ! empty( $buyer_name ) ) {
169 $context['payment_buyer_name'] = $buyer_name;
170 }
171
172 $buyer_email = get_post_meta( $payment->ID, 'adverts_email', true );
173 if ( ! empty( $buyer_email ) ) {
174 $context['payment_buyer_email'] = $buyer_email;
175 }
176
177 $user_id = get_post_meta( $payment->ID, '_adverts_user_id', true );
178 if ( ! empty( $user_id ) ) {
179 $context['payment_user_id'] = $user_id;
180 }
181
182 return $context;
183 }
184 }
185
186 IntegrationsController::register( WPAdverts::class );
187