Passed
Pull Request — master (#161)
by
unknown
04:10
created
classes/salesforce_push.php 1 patch
Spacing   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @file
6 6
  */
7 7
 
8
-if ( ! class_exists( 'Object_Sync_Salesforce' ) ) {
8
+if ( ! class_exists('Object_Sync_Salesforce')) {
9 9
 	die();
10 10
 }
11 11
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	* @param array $schedulable_classes
43 43
 	* @throws \Object_Sync_Sf_Exception
44 44
 	*/
45
-	public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes ) {
45
+	public function __construct($wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes) {
46 46
 		$this->wpdb                = $wpdb;
47 47
 		$this->version             = $version;
48 48
 		$this->login_credentials   = $login_credentials;
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		$this->schedule      = $this->schedule();
58 58
 		$this->add_actions();
59 59
 
60
-		$this->debug = get_option( 'object_sync_for_salesforce_debug_mode', false );
60
+		$this->debug = get_option('object_sync_for_salesforce_debug_mode', false);
61 61
 
62 62
 	}
63 63
 
@@ -67,30 +67,30 @@  discard block
 block discarded – undo
67 67
 	*
68 68
 	*/
69 69
 	private function add_actions() {
70
-		$db_version = get_option( 'object_sync_for_salesforce_db_version', false );
71
-		if ( $db_version === $this->version ) {
72
-			foreach ( $this->mappings->get_fieldmaps() as $mapping ) {
70
+		$db_version = get_option('object_sync_for_salesforce_db_version', false);
71
+		if ($db_version === $this->version) {
72
+			foreach ($this->mappings->get_fieldmaps() as $mapping) {
73 73
 				$object_type = $mapping['wordpress_object'];
74
-				if ( 'user' === $object_type ) {
75
-					add_action( 'user_register', array( $this, 'add_user' ), 11, 1 );
76
-					add_action( 'profile_update', array( $this, 'edit_user' ), 11, 2 );
77
-					add_action( 'delete_user', array( $this, 'delete_user' ) );
78
-				} elseif ( 'post' === $object_type ) {
79
-					add_action( 'save_post', array( $this, 'post_actions' ), 11, 2 );
80
-				} elseif ( 'attachment' === $object_type ) {
81
-					add_action( 'add_attachment', array( $this, 'add_attachment' ) );
82
-					add_action( 'edit_attachment', array( $this, 'edit_attachment' ) );
83
-					add_action( 'delete_attachment', array( $this, 'delete_attachment' ) );
84
-				} elseif ( 'category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type ) {
85
-					add_action( 'create_term', array( $this, 'add_term' ), 11, 3 );
86
-					add_action( 'edit_terms', array( $this, 'edit_term' ), 11, 2 );
87
-					add_action( 'delete_term', array( $this, 'delete_term' ), 10, 4 );
88
-				} elseif ( 'comment' === $object_type ) {
89
-					add_action( 'comment_post', array( $this, 'add_comment' ), 11, 3 );
90
-					add_action( 'edit_comment', array( $this, 'edit_comment' ) );
91
-					add_action( 'delete_comment', array( $this, 'delete_comment' ) ); // to be clear: this only runs when the comment gets deleted from the trash, either manually or automatically
74
+				if ('user' === $object_type) {
75
+					add_action('user_register', array($this, 'add_user'), 11, 1);
76
+					add_action('profile_update', array($this, 'edit_user'), 11, 2);
77
+					add_action('delete_user', array($this, 'delete_user'));
78
+				} elseif ('post' === $object_type) {
79
+					add_action('save_post', array($this, 'post_actions'), 11, 2);
80
+				} elseif ('attachment' === $object_type) {
81
+					add_action('add_attachment', array($this, 'add_attachment'));
82
+					add_action('edit_attachment', array($this, 'edit_attachment'));
83
+					add_action('delete_attachment', array($this, 'delete_attachment'));
84
+				} elseif ('category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type) {
85
+					add_action('create_term', array($this, 'add_term'), 11, 3);
86
+					add_action('edit_terms', array($this, 'edit_term'), 11, 2);
87
+					add_action('delete_term', array($this, 'delete_term'), 10, 4);
88
+				} elseif ('comment' === $object_type) {
89
+					add_action('comment_post', array($this, 'add_comment'), 11, 3);
90
+					add_action('edit_comment', array($this, 'edit_comment'));
91
+					add_action('delete_comment', array($this, 'delete_comment')); // to be clear: this only runs when the comment gets deleted from the trash, either manually or automatically
92 92
 				} else { // this is for custom post types
93
-					add_action( 'save_post_' . $object_type, array( $this, 'post_actions' ), 11, 2 );
93
+					add_action('save_post_' . $object_type, array($this, 'post_actions'), 11, 2);
94 94
 				}
95 95
 			}
96 96
 		}
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	* @param string $type
104 104
 	*
105 105
 	*/
106
-	public function manual_object_update( $object, $type ) {
107
-		$this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update, true );
106
+	public function manual_object_update($object, $type) {
107
+		$this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_update, true);
108 108
 	}
109 109
 
110 110
 	/**
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	*
113 113
 	* @param string $user_id
114 114
 	*/
115
-	public function add_user( $user_id ) {
116
-		$user = $this->wordpress->get_wordpress_object_data( 'user', $user_id );
117
-		$this->object_insert( $user, 'user' );
115
+	public function add_user($user_id) {
116
+		$user = $this->wordpress->get_wordpress_object_data('user', $user_id);
117
+		$this->object_insert($user, 'user');
118 118
 	}
119 119
 
120 120
 	/**
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 	* @param string $user_id
124 124
 	* @param object $old_user_data
125 125
 	*/
126
-	public function edit_user( $user_id, $old_user_data ) {
127
-		$user = $this->wordpress->get_wordpress_object_data( 'user', $user_id );
128
-		$this->object_update( $user, 'user' );
126
+	public function edit_user($user_id, $old_user_data) {
127
+		$user = $this->wordpress->get_wordpress_object_data('user', $user_id);
128
+		$this->object_update($user, 'user');
129 129
 	}
130 130
 
131 131
 	/**
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 	*
134 134
 	* @param string $user_id
135 135
 	*/
136
-	public function delete_user( $user_id ) {
137
-		$user = $this->wordpress->get_wordpress_object_data( 'user', $user_id );
138
-		$this->object_delete( $user, 'user' );
136
+	public function delete_user($user_id) {
137
+		$user = $this->wordpress->get_wordpress_object_data('user', $user_id);
138
+		$this->object_delete($user, 'user');
139 139
 	}
140 140
 
141 141
 	/**
@@ -145,48 +145,48 @@  discard block
 block discarded – undo
145 145
 	* @param string $post_id
146 146
 	* @param object $post
147 147
 	*/
148
-	public function post_actions( $post_id, $post ) {
148
+	public function post_actions($post_id, $post) {
149 149
 
150 150
 		$post_type = $post->post_type;
151 151
 
152
-		if ( isset( $post->post_status ) && 'auto-draft' === $post->post_status ) {
152
+		if (isset($post->post_status) && 'auto-draft' === $post->post_status) {
153 153
 			return;
154 154
 		}
155 155
 		// this plugin does not sync log or revision posts with salesforce
156
-		if ( isset( $post->post_type ) && in_array( $post->post_type, array( 'wp_log', 'revision' ), true ) ) {
156
+		if (isset($post->post_type) && in_array($post->post_type, array('wp_log', 'revision'), true)) {
157 157
 			return;
158 158
 		}
159
-		if ( $post->post_modified_gmt === $post->post_date_gmt && 'trash' !== $post->post_status ) {
159
+		if ($post->post_modified_gmt === $post->post_date_gmt && 'trash' !== $post->post_status) {
160 160
 			$update = 0;
161 161
 			$delete = 0;
162
-		} elseif ( 'trash' !== $post->post_status ) {
162
+		} elseif ('trash' !== $post->post_status) {
163 163
 			$update = 1;
164 164
 			$delete = 0;
165
-		} elseif ( 'trash' === $post->post_status ) {
165
+		} elseif ('trash' === $post->post_status) {
166 166
 			$update = 0;
167 167
 			$delete = 1;
168 168
 		}
169 169
 
170 170
 		// add support for woocommerce if it is installed
171
-		if ( defined( 'WC_VERSION' ) ) {
171
+		if (defined('WC_VERSION')) {
172 172
 			// statuses to ignore
173
-			if ( isset( $post->post_status ) && in_array( $post->post_status, array( 'wc-pending' ), true ) ) {
173
+			if (isset($post->post_status) && in_array($post->post_status, array('wc-pending'), true)) {
174 174
 				return;
175 175
 			}
176 176
 			// statuses to count as new. note that the api will also check to see if it already has been mapped before saving.
177
-			if ( isset( $post->post_status ) && in_array( $post->post_status, array( 'wc-on-hold', 'wc-processing' ), true ) ) {
177
+			if (isset($post->post_status) && in_array($post->post_status, array('wc-on-hold', 'wc-processing'), true)) {
178 178
 				$update = 0;
179 179
 				$delete = 0;
180 180
 			}
181 181
 		}
182 182
 
183
-		$post = $this->wordpress->get_wordpress_object_data( $post->post_type, $post_id );
184
-		if ( 1 === $update ) {
185
-			$this->object_update( $post, $post_type );
186
-		} elseif ( 1 === $delete ) {
187
-			$this->object_delete( $post, $post_type );
183
+		$post = $this->wordpress->get_wordpress_object_data($post->post_type, $post_id);
184
+		if (1 === $update) {
185
+			$this->object_update($post, $post_type);
186
+		} elseif (1 === $delete) {
187
+			$this->object_delete($post, $post_type);
188 188
 		} else {
189
-			$this->object_insert( $post, $post_type );
189
+			$this->object_insert($post, $post_type);
190 190
 		}
191 191
 	}
192 192
 
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 	*
196 196
 	* @param string $post_id
197 197
 	*/
198
-	public function add_attachment( $post_id ) {
199
-		$attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id );
200
-		$this->object_insert( $attachment, 'attachment' );
198
+	public function add_attachment($post_id) {
199
+		$attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id);
200
+		$this->object_insert($attachment, 'attachment');
201 201
 	}
202 202
 
203 203
 	/**
@@ -205,9 +205,9 @@  discard block
 block discarded – undo
205 205
 	*
206 206
 	* @param string $post_id
207 207
 	*/
208
-	public function edit_attachment( $post_id ) {
209
-		$attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id );
210
-		$this->object_update( $attachment, 'attachment' );
208
+	public function edit_attachment($post_id) {
209
+		$attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id);
210
+		$this->object_update($attachment, 'attachment');
211 211
 	}
212 212
 
213 213
 	/**
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
 	*
216 216
 	* @param string $post_id
217 217
 	*/
218
-	public function delete_attachment( $post_id ) {
219
-		$attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id );
220
-		$this->object_delete( $attachment, 'attachment' );
218
+	public function delete_attachment($post_id) {
219
+		$attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id);
220
+		$this->object_delete($attachment, 'attachment');
221 221
 	}
222 222
 
223 223
 	/**
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 	* @param string $tt_id
228 228
 	* @param string $taxonomy
229 229
 	*/
230
-	public function add_term( $term_id, $tt_id, $taxonomy ) {
231
-		$term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id );
232
-		$this->object_insert( $term, $taxonomy );
230
+	public function add_term($term_id, $tt_id, $taxonomy) {
231
+		$term = $this->wordpress->get_wordpress_object_data($taxonomy, $term_id);
232
+		$this->object_insert($term, $taxonomy);
233 233
 	}
234 234
 
235 235
 	/**
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	* @param string $term_id
239 239
 	* @param string $taxonomy
240 240
 	*/
241
-	public function edit_term( $term_id, $taxonomy ) {
242
-		$term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id );
243
-		$this->object_update( $term, $taxonomy );
241
+	public function edit_term($term_id, $taxonomy) {
242
+		$term = $this->wordpress->get_wordpress_object_data($taxonomy, $term_id);
243
+		$this->object_update($term, $taxonomy);
244 244
 	}
245 245
 
246 246
 	/**
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
 	* @param string $taxonomy (slug)
252 252
 	* @param object $deleted_term
253 253
 	*/
254
-	public function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) {
254
+	public function delete_term($term, $tt_id, $taxonomy, $deleted_term) {
255 255
 		$deleted_term = (array) $deleted_term;
256 256
 		$type         = $deleted_term['taxonomy'];
257
-		$this->object_delete( $deleted_term, $type );
257
+		$this->object_delete($deleted_term, $type);
258 258
 	}
259 259
 
260 260
 	/**
@@ -264,9 +264,9 @@  discard block
 block discarded – undo
264 264
 	* @param int|string comment_approved
265 265
 	* @param array $commentdata
266 266
 	*/
267
-	public function add_comment( $comment_id, $comment_approved, $commentdata = array() ) {
268
-		$comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id );
269
-		$this->object_insert( $comment, 'comment' );
267
+	public function add_comment($comment_id, $comment_approved, $commentdata = array()) {
268
+		$comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id);
269
+		$this->object_insert($comment, 'comment');
270 270
 	}
271 271
 
272 272
 	/**
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
 	*
275 275
 	* @param string $comment_id
276 276
 	*/
277
-	public function edit_comment( $comment_id ) {
278
-		$comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id );
279
-		$this->object_update( $comment, 'comment' );
277
+	public function edit_comment($comment_id) {
278
+		$comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id);
279
+		$this->object_update($comment, 'comment');
280 280
 	}
281 281
 
282 282
 	/**
@@ -284,33 +284,33 @@  discard block
 block discarded – undo
284 284
 	*
285 285
 	* @param string $comment_id
286 286
 	*/
287
-	public function delete_comment( $comment_id ) {
288
-		$comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id );
289
-		$this->object_delete( $comment, 'comment' );
287
+	public function delete_comment($comment_id) {
288
+		$comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id);
289
+		$this->object_delete($comment, 'comment');
290 290
 	}
291 291
 
292 292
 	/**
293 293
 	* Insert a new object
294 294
 	* This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
295 295
 	*/
296
-	private function object_insert( $object, $type ) {
297
-		$this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_create );
296
+	private function object_insert($object, $type) {
297
+		$this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_create);
298 298
 	}
299 299
 
300 300
 	/**
301 301
 	* Update an existing object
302 302
 	* This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
303 303
 	*/
304
-	private function object_update( $object, $type ) {
305
-		$this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update );
304
+	private function object_update($object, $type) {
305
+		$this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_update);
306 306
 	}
307 307
 
308 308
 	/**
309 309
 	* Delete an existing object
310 310
 	* This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
311 311
 	*/
312
-	private function object_delete( $object, $type ) {
313
-		$this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_delete );
312
+	private function object_delete($object, $type) {
313
+		$this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_delete);
314 314
 	}
315 315
 
316 316
 	/**
@@ -327,50 +327,50 @@  discard block
 block discarded – undo
327 327
 	*   Are we calling this manually?
328 328
 	*
329 329
 	*/
330
-	private function salesforce_push_object_crud( $object_type, $object, $sf_sync_trigger, $manual = false ) {
330
+	private function salesforce_push_object_crud($object_type, $object, $sf_sync_trigger, $manual = false) {
331 331
 
332
-		$structure       = $this->wordpress->get_wordpress_table_structure( $object_type );
332
+		$structure       = $this->wordpress->get_wordpress_table_structure($object_type);
333 333
 		$object_id_field = $structure['id_field'];
334 334
 
335 335
 		// there is a WordPress object to push
336
-		if ( isset( $object[ $object_id_field ] ) ) {
337
-			$mapping_object = $this->mappings->load_by_wordpress( $object_type, $object[ $object_id_field ] );
336
+		if (isset($object[$object_id_field])) {
337
+			$mapping_object = $this->mappings->load_by_wordpress($object_type, $object[$object_id_field]);
338 338
 
339 339
 			// there is already a mapping object for this WordPress object
340
-			if ( isset( $mapping_object['id'] ) ) {
340
+			if (isset($mapping_object['id'])) {
341 341
 				$mapping_object_id_transient = $mapping_object['id'];
342 342
 			} else {
343 343
 				// there is not a mapping object for this WordPress object id yet
344 344
 				// check for that transient with the currently pulling id
345
-				$mapping_object_id_transient = (int) get_transient( 'salesforce_pulling_object_id' );
345
+				$mapping_object_id_transient = (int) get_transient('salesforce_pulling_object_id');
346 346
 			}
347 347
 
348
-			$salesforce_pulling = (int) get_transient( 'salesforce_pulling_' . $mapping_object_id_transient );
349
-			if ( 1 === $salesforce_pulling ) {
350
-				delete_transient( 'salesforce_pulling_' . $mapping_object_id_transient );
351
-				$pulling_id = get_transient( 'salesforce_pulling_object_id' );
352
-				if ( $pulling_id === $mapping_object_id_transient ) {
353
-					delete_transient( 'salesforce_pulling_object_id' );
348
+			$salesforce_pulling = (int) get_transient('salesforce_pulling_' . $mapping_object_id_transient);
349
+			if (1 === $salesforce_pulling) {
350
+				delete_transient('salesforce_pulling_' . $mapping_object_id_transient);
351
+				$pulling_id = get_transient('salesforce_pulling_object_id');
352
+				if ($pulling_id === $mapping_object_id_transient) {
353
+					delete_transient('salesforce_pulling_object_id');
354 354
 				}
355 355
 				return false;
356 356
 			}
357 357
 		} else {
358 358
 			// if we don't have a WordPress object id, we've got no business doing stuff in Salesforce
359 359
 			$status = 'error';
360
-			if ( isset( $this->logging ) ) {
360
+			if (isset($this->logging)) {
361 361
 				$logging = $this->logging;
362
-			} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
363
-				$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
362
+			} elseif (class_exists('Object_Sync_Sf_Logging')) {
363
+				$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
364 364
 			}
365 365
 
366 366
 			// translators: placeholder is the name of the WordPress id field
367
-			$title = sprintf( esc_html__( 'Error: Salesforce Push: unable to process queue item because it has no WordPress %1$s.', 'object-sync-for-salesforce' ),
368
-				esc_attr( $object_id_field )
367
+			$title = sprintf(esc_html__('Error: Salesforce Push: unable to process queue item because it has no WordPress %1$s.', 'object-sync-for-salesforce'),
368
+				esc_attr($object_id_field)
369 369
 			);
370 370
 
371 371
 			$logging->setup(
372 372
 				$title,
373
-				print_r( $object, true ), // print this array because if this happens, something weird has happened and we want to log whatever we have
373
+				print_r($object, true), // print this array because if this happens, something weird has happened and we want to log whatever we have
374 374
 				$sf_sync_trigger,
375 375
 				0, // parent id goes here but we don't have one, so make it 0
376 376
 				$status
@@ -387,14 +387,14 @@  discard block
 block discarded – undo
387 387
 			)
388 388
 		);
389 389
 
390
-		foreach ( $sf_mappings as $mapping ) { // for each mapping of this object
390
+		foreach ($sf_mappings as $mapping) { // for each mapping of this object
391 391
 			$map_sync_triggers = $mapping['sync_triggers'];
392 392
 
393 393
 			// these are bit operators, so we leave out the strict
394
-			if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event
394
+			if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event
395 395
 
396 396
 				// hook to allow other plugins to prevent a push per-mapping.
397
-				$push_allowed = apply_filters( 'object_sync_for_salesforce_push_object_allowed', true, $object_type, $object, $sf_sync_trigger, $mapping );
397
+				$push_allowed = apply_filters('object_sync_for_salesforce_push_object_allowed', true, $object_type, $object, $sf_sync_trigger, $mapping);
398 398
 
399 399
 				// example to keep from pushing the user with id of 1
400 400
 				/*
@@ -407,17 +407,17 @@  discard block
 block discarded – undo
407 407
 				}
408 408
 				*/
409 409
 
410
-				if ( false === $push_allowed ) {
410
+				if (false === $push_allowed) {
411 411
 					continue;
412 412
 				}
413 413
 
414 414
 				// push drafts if the setting says so
415 415
 				// post status is draft, or post status is inherit and post type is not attachment
416
-				if ( ( ! isset( $mapping['push_drafts'] ) || '1' !== $mapping['push_drafts'] ) && isset( $object['post_status'] ) && ( 'draft' === $object['post_status'] || ( 'inherit' === $object['post_status'] && 'attachment' !== $object['post_type'] ) ) ) {
416
+				if (( ! isset($mapping['push_drafts']) || '1' !== $mapping['push_drafts']) && isset($object['post_status']) && ('draft' === $object['post_status'] || ('inherit' === $object['post_status'] && 'attachment' !== $object['post_type']))) {
417 417
 					// skip this object if it is a draft and the fieldmap settings told us to ignore it
418 418
 					continue;
419 419
 				}
420
-				if ( isset( $mapping['push_async'] ) && ( '1' === $mapping['push_async'] ) && false === $manual ) {
420
+				if (isset($mapping['push_async']) && ('1' === $mapping['push_async']) && false === $manual) {
421 421
 					// this item is async and we want to save it to the queue
422 422
 					$data = array(
423 423
 						'object_type'     => $object_type,
@@ -428,24 +428,24 @@  discard block
 block discarded – undo
428 428
 
429 429
 					// create new schedule based on the options for this current class
430 430
 					// this will use the existing schedule if it already exists; otherwise it'll create one
431
-					$this->schedule->use_schedule( $this->schedule_name );
432
-					$this->schedule->push_to_queue( $data );
431
+					$this->schedule->use_schedule($this->schedule_name);
432
+					$this->schedule->push_to_queue($data);
433 433
 					$this->schedule->save()->dispatch();
434 434
 
435 435
 				} else {
436 436
 					// this one is not async. do it immediately.
437
-					$push = $this->salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger );
437
+					$push = $this->salesforce_push_sync_rest($object_type, $object, $mapping, $sf_sync_trigger);
438 438
 				} // End if().
439 439
 			} // End if(). if the trigger does not match our requirements, skip it
440 440
 		} // End foreach().
441 441
 	}
442 442
 
443 443
 	private function schedule() {
444
-		if ( ! class_exists( 'Object_Sync_Sf_Schedule' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) {
445
-			require_once plugin_dir_path( __FILE__ ) . '../vendor/autoload.php';
446
-			require_once plugin_dir_path( __FILE__ ) . '../classes/schedule.php';
444
+		if ( ! class_exists('Object_Sync_Sf_Schedule') && file_exists(plugin_dir_path(__FILE__) . '../vendor/autoload.php')) {
445
+			require_once plugin_dir_path(__FILE__) . '../vendor/autoload.php';
446
+			require_once plugin_dir_path(__FILE__) . '../classes/schedule.php';
447 447
 		}
448
-		$schedule       = new Object_Sync_Sf_Schedule( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->schedule_name, $this->logging, $this->schedulable_classes );
448
+		$schedule       = new Object_Sync_Sf_Schedule($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->schedule_name, $this->logging, $this->schedulable_classes);
449 449
 		$this->schedule = $schedule;
450 450
 		return $schedule;
451 451
 	}
@@ -465,25 +465,25 @@  discard block
 block discarded – undo
465 465
 	* @return true or exit the method
466 466
 	*
467 467
 	*/
468
-	public function salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ) {
468
+	public function salesforce_push_sync_rest($object_type, $object, $mapping, $sf_sync_trigger) {
469 469
 
470 470
 		// If Salesforce is not authorized, don't do anything.
471 471
 		// it's unclear to me if we need to do something else here or if this is sufficient. This is all Drupal does.
472
-		if ( true !== $this->salesforce['is_authorized'] ) {
472
+		if (true !== $this->salesforce['is_authorized']) {
473 473
 			return;
474 474
 		}
475 475
 
476 476
 		$sfapi = $this->salesforce['sfapi'];
477 477
 
478 478
 		// we need to get the WordPress id here so we can check to see if the object already has a map
479
-		$structure = $this->wordpress->get_wordpress_table_structure( $object_type );
479
+		$structure = $this->wordpress->get_wordpress_table_structure($object_type);
480 480
 		$object_id = $structure['id_field'];
481 481
 
482 482
 		// this returns the row that maps the individual WordPress row to the individual Salesfoce row
483
-		$mapping_object = $this->mappings->load_by_wordpress( $object_type, $object[ "$object_id" ] );
483
+		$mapping_object = $this->mappings->load_by_wordpress($object_type, $object["$object_id"]);
484 484
 
485 485
 		// hook to allow other plugins to define or alter the mapping object
486
-		$mapping_object = apply_filters( 'object_sync_for_salesforce_push_mapping_object', $mapping_object, $object, $mapping );
486
+		$mapping_object = apply_filters('object_sync_for_salesforce_push_mapping_object', $mapping_object, $object, $mapping);
487 487
 
488 488
 		// we already have the data from WordPress at this point; we just need to work with it in Salesforce
489 489
 		$synced_object = array(
@@ -497,84 +497,84 @@  discard block
 block discarded – undo
497 497
 
498 498
 		// deleting mapped objects
499 499
 		// these are bit operators, so we leave out the strict
500
-		if ( $sf_sync_trigger == $this->mappings->sync_wordpress_delete ) {
501
-			if ( isset( $mapping_object['id'] ) ) {
500
+		if ($sf_sync_trigger == $this->mappings->sync_wordpress_delete) {
501
+			if (isset($mapping_object['id'])) {
502 502
 				$op = 'Delete';
503 503
 
504
-				$salesforce_check = $this->mappings->load_by_salesforce( $mapping_object['salesforce_id'] );
504
+				$salesforce_check = $this->mappings->load_by_salesforce($mapping_object['salesforce_id']);
505 505
 
506
-				if ( count( $salesforce_check ) === count( $salesforce_check, COUNT_RECURSIVE ) ) {
506
+				if (count($salesforce_check) === count($salesforce_check, COUNT_RECURSIVE)) {
507 507
 					try {
508
-						$result = $sfapi->object_delete( $mapping['salesforce_object'], $mapping_object['salesforce_id'] );
509
-					} catch ( Object_Sync_Sf_Exception $e ) {
508
+						$result = $sfapi->object_delete($mapping['salesforce_object'], $mapping_object['salesforce_id']);
509
+					} catch (Object_Sync_Sf_Exception $e) {
510 510
 						$status = 'error';
511 511
 						// create log entry for failed delete
512
-						if ( isset( $this->logging ) ) {
512
+						if (isset($this->logging)) {
513 513
 							$logging = $this->logging;
514
-						} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
515
-							$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
514
+						} elseif (class_exists('Object_Sync_Sf_Logging')) {
515
+							$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
516 516
 						}
517 517
 
518 518
 						// translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value
519
-						$title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ),
520
-							esc_attr( $op ),
521
-							esc_attr( $mapping['salesforce_object'] ),
522
-							esc_attr( $mapping_object['salesforce_id'] ),
523
-							esc_attr( $mapping['wordpress_object'] ),
524
-							esc_attr( $object_id ),
525
-							esc_attr( $object[ "$object_id" ] )
519
+						$title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'),
520
+							esc_attr($op),
521
+							esc_attr($mapping['salesforce_object']),
522
+							esc_attr($mapping_object['salesforce_id']),
523
+							esc_attr($mapping['wordpress_object']),
524
+							esc_attr($object_id),
525
+							esc_attr($object["$object_id"])
526 526
 						);
527 527
 
528 528
 						$logging->setup(
529 529
 							$title,
530 530
 							$e->getMessage(),
531 531
 							$sf_sync_trigger,
532
-							$object[ "$object_id" ],
532
+							$object["$object_id"],
533 533
 							$status
534 534
 						);
535 535
 
536 536
 						// hook for push fail
537
-						do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object, $object_id );
537
+						do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object, $object_id);
538 538
 
539 539
 					}
540 540
 
541
-					if ( ! isset( $e ) ) {
541
+					if ( ! isset($e)) {
542 542
 						// create log entry for successful delete if the result had no errors
543 543
 						$status = 'success';
544
-						if ( isset( $this->logging ) ) {
544
+						if (isset($this->logging)) {
545 545
 							$logging = $this->logging;
546
-						} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
547
-							$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
546
+						} elseif (class_exists('Object_Sync_Sf_Logging')) {
547
+							$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
548 548
 						}
549 549
 
550 550
 						// translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value
551
-						$title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ),
552
-							esc_attr( $op ),
553
-							esc_attr( $mapping['salesforce_object'] ),
554
-							esc_attr( $mapping_object['salesforce_id'] ),
555
-							esc_attr( $mapping['wordpress_object'] ),
556
-							esc_attr( $object_id ),
557
-							esc_attr( $object[ "$object_id" ] )
551
+						$title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'),
552
+							esc_attr($op),
553
+							esc_attr($mapping['salesforce_object']),
554
+							esc_attr($mapping_object['salesforce_id']),
555
+							esc_attr($mapping['wordpress_object']),
556
+							esc_attr($object_id),
557
+							esc_attr($object["$object_id"])
558 558
 						);
559 559
 
560 560
 						$logging->setup(
561 561
 							$title,
562 562
 							'',
563 563
 							$sf_sync_trigger,
564
-							$object[ "$object_id" ],
564
+							$object["$object_id"],
565 565
 							$status
566 566
 						);
567 567
 
568 568
 						// hook for push success
569
-						do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id );
569
+						do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id);
570 570
 					}
571 571
 				} else {
572 572
 					$more_ids = '<p>The Salesforce record was not deleted because there are multiple WordPress IDs that match this Salesforce ID. They are: ';
573 573
 					$i        = 0;
574
-					foreach ( $salesforce_check as $match ) {
574
+					foreach ($salesforce_check as $match) {
575 575
 						$i++;
576 576
 						$more_ids .= $match['wordpress_id'];
577
-						if ( count( $salesforce_check ) !== $i ) {
577
+						if (count($salesforce_check) !== $i) {
578 578
 							$more_ids .= ', ';
579 579
 						} else {
580 580
 							$more_ids .= '.</p>';
@@ -584,34 +584,34 @@  discard block
 block discarded – undo
584 584
 					$more_ids .= '<p>The map row between this WordPress object and the Salesforce object, as stored in the WordPress database, will be deleted, and this WordPress object has been deleted, but Salesforce will remain untouched.</p>';
585 585
 
586 586
 					$status = 'notice';
587
-					if ( isset( $this->logging ) ) {
587
+					if (isset($this->logging)) {
588 588
 						$logging = $this->logging;
589
-					} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
590
-						$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
589
+					} elseif (class_exists('Object_Sync_Sf_Logging')) {
590
+						$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
591 591
 					}
592 592
 
593 593
 					// translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value
594
-					$title = sprintf( esc_html__( 'Notice: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s did not delete the Salesforce item.)', 'object-sync-for-salesforce' ),
595
-						esc_attr( $op ),
596
-						esc_attr( $mapping['salesforce_object'] ),
597
-						esc_attr( $mapping_object['salesforce_id'] ),
598
-						esc_attr( $mapping['wordpress_object'] ),
599
-						esc_attr( $object_id ),
600
-						esc_attr( $object[ "$object_id" ] )
594
+					$title = sprintf(esc_html__('Notice: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s did not delete the Salesforce item.)', 'object-sync-for-salesforce'),
595
+						esc_attr($op),
596
+						esc_attr($mapping['salesforce_object']),
597
+						esc_attr($mapping_object['salesforce_id']),
598
+						esc_attr($mapping['wordpress_object']),
599
+						esc_attr($object_id),
600
+						esc_attr($object["$object_id"])
601 601
 					);
602 602
 
603 603
 					$logging->setup(
604 604
 						$title,
605 605
 						$more_ids,
606 606
 						$sf_sync_trigger,
607
-						$object[ "$object_id" ],
607
+						$object["$object_id"],
608 608
 						$status
609 609
 					);
610 610
 				} // End if().
611 611
 
612 612
 				// delete the map row from WordPress after the Salesforce row has been deleted
613 613
 				// we delete the map row even if the Salesforce delete failed, because the WordPress object is gone
614
-				$this->mappings->delete_object_map( $mapping_object['id'] );
614
+				$this->mappings->delete_object_map($mapping_object['id']);
615 615
 
616 616
 			} // End if(). there is no map row
617 617
 
@@ -619,51 +619,51 @@  discard block
 block discarded – undo
619 619
 		} // End if().
620 620
 
621 621
 		// are these objects already connected in WordPress?
622
-		if ( isset( $mapping_object['id'] ) ) {
622
+		if (isset($mapping_object['id'])) {
623 623
 			$is_new = false;
624 624
 		} else {
625 625
 			$is_new = true;
626 626
 		}
627 627
 
628 628
 		// map the WordPress values to salesforce fields
629
-		$params = $this->mappings->map_params( $mapping, $object, $sf_sync_trigger, false, $is_new );
629
+		$params = $this->mappings->map_params($mapping, $object, $sf_sync_trigger, false, $is_new);
630 630
 
631 631
 		// hook to allow other plugins to modify the $params array
632 632
 		// use hook to map fields between the WordPress and Salesforce objects
633 633
 		// returns $params.
634
-		$params = apply_filters( 'object_sync_for_salesforce_push_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new );
634
+		$params = apply_filters('object_sync_for_salesforce_push_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new);
635 635
 
636 636
 		// if we don't get any params, there are no fields that should be sent to Salesforce
637
-		if ( empty( $params ) ) {
637
+		if (empty($params)) {
638 638
 			return;
639 639
 		}
640 640
 
641 641
 		// if there is a prematch WordPress field - ie email - on the fieldmap object
642
-		if ( isset( $params['prematch'] ) && is_array( $params['prematch'] ) ) {
642
+		if (isset($params['prematch']) && is_array($params['prematch'])) {
643 643
 			$prematch_field_wordpress  = $params['prematch']['wordpress_field'];
644 644
 			$prematch_field_salesforce = $params['prematch']['salesforce_field'];
645 645
 			$prematch_value            = $params['prematch']['value'];
646
-			unset( $params['prematch'] );
646
+			unset($params['prematch']);
647 647
 		}
648 648
 
649 649
 		// if there is an external key field in Salesforce - ie mailchimp user id - on the fieldmap object
650
-		if ( isset( $params['key'] ) && is_array( $params['key'] ) ) {
650
+		if (isset($params['key']) && is_array($params['key'])) {
651 651
 			$key_field_wordpress  = $params['key']['wordpress_field'];
652 652
 			$key_field_salesforce = $params['key']['salesforce_field'];
653 653
 			$key_value            = $params['key']['value'];
654
-			unset( $params['key'] );
654
+			unset($params['key']);
655 655
 		}
656 656
 
657
-		$seconds = $this->schedule->get_schedule_frequency_seconds( $this->schedule_name ) + 60;
657
+		$seconds = $this->schedule->get_schedule_frequency_seconds($this->schedule_name) + 60;
658 658
 
659
-		if ( true === $is_new ) {
659
+		if (true === $is_new) {
660 660
 
661 661
 			// right here we should set the pushing transient
662 662
 			// this means we have to create the mapping object here as well, and update it with the correct IDs after successful response
663 663
 			// create the mapping object between the rows
664
-			$mapping_object_id = $this->create_object_map( $object, $object_id, $this->mappings->generate_temporary_id( 'push' ), $mapping, true );
665
-			set_transient( 'salesforce_pushing_' . $mapping_object_id, 1, $seconds );
666
-			set_transient( 'salesforce_pushing_object_id', $mapping_object_id );
664
+			$mapping_object_id = $this->create_object_map($object, $object_id, $this->mappings->generate_temporary_id('push'), $mapping, true);
665
+			set_transient('salesforce_pushing_' . $mapping_object_id, 1, $seconds);
666
+			set_transient('salesforce_pushing_object_id', $mapping_object_id);
667 667
 			$mapping_object = $this->mappings->get_object_maps(
668 668
 				array(
669 669
 					'id' => $mapping_object_id,
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 
673 673
 			// setup SF record type. CampaignMember objects get their Campaign's type
674 674
 			// i am still a bit confused about this
675
-			if ( $mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty( $params['RecordTypeId'] ) && ( 'CampaignMember' !== $mapping['salesforce_object'] ) ) {
675
+			if ($mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty($params['RecordTypeId']) && ('CampaignMember' !== $mapping['salesforce_object'])) {
676 676
 				$params['RecordTypeId'] = $mapping['salesforce_record_type_default'];
677 677
 			}
678 678
 
@@ -684,61 +684,61 @@  discard block
 block discarded – undo
684 684
 				// returns a $salesforce_id.
685 685
 				// it should keep NULL if there is no match
686 686
 				// the function that calls this hook needs to check the mapping to make sure the WordPress object is the right type
687
-				$salesforce_id = apply_filters( 'object_sync_for_salesforce_find_sf_object_match', null, $object, $mapping, 'push' );
687
+				$salesforce_id = apply_filters('object_sync_for_salesforce_find_sf_object_match', null, $object, $mapping, 'push');
688 688
 
689 689
 				// hook to allow other plugins to do something right before Salesforce data is saved
690 690
 				// ex: run WordPress methods on an object if it exists, or do something in preparation for it if it doesn't
691
-				do_action( 'object_sync_for_salesforce_pre_push', $salesforce_id, $mapping, $object, $object_id, $params );
691
+				do_action('object_sync_for_salesforce_pre_push', $salesforce_id, $mapping, $object, $object_id, $params);
692 692
 
693 693
 				// hook to allow other plugins to change params on update actions only
694 694
 				// use hook to map fields between the WordPress and Salesforce objects
695 695
 				// returns $params.
696
-				$params = apply_filters( 'object_sync_for_salesforce_push_update_params_modify', $params, $salesforce_id, $mapping, $object );
696
+				$params = apply_filters('object_sync_for_salesforce_push_update_params_modify', $params, $salesforce_id, $mapping, $object);
697 697
 
698
-				if ( isset( $prematch_field_wordpress ) || isset( $key_field_wordpress ) || null !== $salesforce_id ) {
698
+				if (isset($prematch_field_wordpress) || isset($key_field_wordpress) || null !== $salesforce_id) {
699 699
 
700 700
 					// if either prematch criteria exists, make the values queryable
701 701
 
702
-					if ( isset( $prematch_field_wordpress ) ) {
702
+					if (isset($prematch_field_wordpress)) {
703 703
 						// a prematch has been specified, attempt an upsert().
704 704
 						// prematch values with punctuation need to be escaped
705
-						$encoded_prematch_value = rawurlencode( $prematch_value );
705
+						$encoded_prematch_value = rawurlencode($prematch_value);
706 706
 						// for at least 'email' fields, periods also need to be escaped:
707 707
 						// https://developer.salesforce.com/forums?id=906F000000099xPIAQ
708
-						$encoded_prematch_value = str_replace( '.', '%2E', $encoded_prematch_value );
708
+						$encoded_prematch_value = str_replace('.', '%2E', $encoded_prematch_value);
709 709
 					}
710 710
 
711
-					if ( isset( $key_field_wordpress ) ) {
711
+					if (isset($key_field_wordpress)) {
712 712
 						// an external key has been specified, attempt an upsert().
713 713
 						// external key values with punctuation need to be escaped
714
-						$encoded_key_value = rawurlencode( $key_value );
714
+						$encoded_key_value = rawurlencode($key_value);
715 715
 						// for at least 'email' fields, periods also need to be escaped:
716 716
 						// https://developer.salesforce.com/forums?id=906F000000099xPIAQ
717
-						$encoded_key_value = str_replace( '.', '%2E', $encoded_key_value );
717
+						$encoded_key_value = str_replace('.', '%2E', $encoded_key_value);
718 718
 					}
719 719
 
720
-					if ( isset( $prematch_field_wordpress ) ) {
720
+					if (isset($prematch_field_wordpress)) {
721 721
 						$upsert_key   = $prematch_field_salesforce;
722 722
 						$upsert_value = $encoded_prematch_value;
723
-					} elseif ( isset( $key_field_wordpress ) ) {
723
+					} elseif (isset($key_field_wordpress)) {
724 724
 						$upsert_key   = $key_field_salesforce;
725 725
 						$upsert_value = $encoded_key_value;
726 726
 					}
727 727
 
728
-					if ( null !== $salesforce_id ) {
728
+					if (null !== $salesforce_id) {
729 729
 						$upsert_key   = 'Id';
730 730
 						$upsert_value = $salesforce_id;
731 731
 					}
732 732
 
733 733
 					$op = 'Upsert';
734 734
 
735
-					$result = $sfapi->object_upsert( $mapping['salesforce_object'], $upsert_key, $upsert_value, $params );
735
+					$result = $sfapi->object_upsert($mapping['salesforce_object'], $upsert_key, $upsert_value, $params);
736 736
 
737 737
 					// Handle upsert responses.
738
-					switch ( $sfapi->response['code'] ) {
738
+					switch ($sfapi->response['code']) {
739 739
 						// On Upsert:update retrieved object.
740 740
 						case '204':
741
-							$sf_object             = $sfapi->object_readby_external_id( $mapping['salesforce_object'], $upsert_key, $upsert_value );
741
+							$sf_object             = $sfapi->object_readby_external_id($mapping['salesforce_object'], $upsert_key, $upsert_value);
742 742
 							$salesforce_data['id'] = $sf_object['data']['Id'];
743 743
 							break;
744 744
 						// Handle duplicate records.
@@ -749,43 +749,43 @@  discard block
 block discarded – undo
749 749
 				} else {
750 750
 					// No key or prematch field exists on this field map object, create a new object in Salesforce.
751 751
 					$op     = 'Create';
752
-					$result = $sfapi->object_create( $mapping['salesforce_object'], $params );
752
+					$result = $sfapi->object_create($mapping['salesforce_object'], $params);
753 753
 				} // End if().
754
-			} catch ( Object_Sync_Sf_Exception $e ) {
754
+			} catch (Object_Sync_Sf_Exception $e) {
755 755
 				// create log entry for failed create or upsert
756 756
 				$status = 'error';
757 757
 
758
-				if ( isset( $this->logging ) ) {
758
+				if (isset($this->logging)) {
759 759
 					$logging = $this->logging;
760
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
761
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
760
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
761
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
762 762
 				}
763 763
 
764 764
 				// translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value if there is one, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value
765
-				$title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ),
766
-					esc_attr( $op ),
767
-					esc_attr( $mapping['salesforce_object'] ),
768
-					isset( $salesforce_id ) ? ' ' . esc_attr( $salesforce_id ) : '',
769
-					esc_attr( $mapping['wordpress_object'] ),
770
-					esc_attr( $object_id ),
771
-					esc_attr( $object[ "$object_id" ] )
765
+				$title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'),
766
+					esc_attr($op),
767
+					esc_attr($mapping['salesforce_object']),
768
+					isset($salesforce_id) ? ' ' . esc_attr($salesforce_id) : '',
769
+					esc_attr($mapping['wordpress_object']),
770
+					esc_attr($object_id),
771
+					esc_attr($object["$object_id"])
772 772
 				);
773 773
 
774 774
 				$logging->setup(
775 775
 					$title,
776 776
 					$e->getMessage(),
777 777
 					$sf_sync_trigger,
778
-					$object[ "$object_id" ],
778
+					$object["$object_id"],
779 779
 					$status
780 780
 				);
781 781
 
782 782
 				// hook for push fail
783
-				do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object );
783
+				do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object);
784 784
 
785 785
 				return;
786 786
 			} // End try().
787 787
 
788
-			if ( ! isset( $salesforce_data ) ) {
788
+			if ( ! isset($salesforce_data)) {
789 789
 				// if we didn't set $salesforce_data already, set it now to api call result
790 790
 				$salesforce_data = $result['data'];
791 791
 			}
@@ -794,78 +794,78 @@  discard block
 block discarded – undo
794 794
 			// this means the object has already been created/updated in Salesforce
795 795
 			// this is not redundant because this is where it creates the object mapping rows in WordPress if the object does not already have one (we are still inside $is_new === TRUE here)
796 796
 
797
-			if ( empty( $result['errorCode'] ) ) {
797
+			if (empty($result['errorCode'])) {
798 798
 				$salesforce_id = $salesforce_data['id'];
799 799
 				$status        = 'success';
800 800
 
801
-				if ( isset( $this->logging ) ) {
801
+				if (isset($this->logging)) {
802 802
 					$logging = $this->logging;
803
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
804
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
803
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
804
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
805 805
 				}
806 806
 
807 807
 				// translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value
808
-				$title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ),
809
-					esc_attr( $op ),
810
-					esc_attr( $mapping['salesforce_object'] ),
811
-					esc_attr( $salesforce_id ),
812
-					esc_attr( $mapping['wordpress_object'] ),
813
-					esc_attr( $object_id ),
814
-					esc_attr( $object[ "$object_id" ] )
808
+				$title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'),
809
+					esc_attr($op),
810
+					esc_attr($mapping['salesforce_object']),
811
+					esc_attr($salesforce_id),
812
+					esc_attr($mapping['wordpress_object']),
813
+					esc_attr($object_id),
814
+					esc_attr($object["$object_id"])
815 815
 				);
816 816
 
817 817
 				$logging->setup(
818 818
 					$title,
819 819
 					'',
820 820
 					$sf_sync_trigger,
821
-					$object[ "$object_id" ],
821
+					$object["$object_id"],
822 822
 					$status
823 823
 				);
824 824
 
825 825
 				// update that mapping object
826 826
 				$mapping_object['salesforce_id']     = $salesforce_id;
827
-				$mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__;
828
-				$mapping_object                      = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] );
827
+				$mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__;
828
+				$mapping_object                      = $this->mappings->update_object_map($mapping_object, $mapping_object['id']);
829 829
 
830 830
 				// hook for push success
831
-				do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id );
831
+				do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id);
832 832
 			} else {
833 833
 
834 834
 				// create log entry for failed create or upsert
835 835
 				// this is part of the drupal module but i am failing to understand when it would ever fire, since the catch should catch the errors
836 836
 				// if we see this in the log entries, we can understand what it does, but probably not until then
837 837
 				$status = 'error';
838
-				if ( isset( $this->logging ) ) {
838
+				if (isset($this->logging)) {
839 839
 					$logging = $this->logging;
840
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
841
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
840
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
841
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
842 842
 				}
843 843
 
844 844
 				// translators: placeholders are: 1) error code the Salesforce API returned, 2) what operation is happening, 3) the name of the WordPress object type, 4) the WordPress id field name, 5) the WordPress object id value
845
-				$title = sprintf( esc_html__( '%1$s error syncing: %2$s to Salesforce (WordPress %3$s with %4$s of %5$s)', 'object-sync-for-salesforce' ),
846
-					absint( $salesforce_data['errorCode'] ),
847
-					esc_attr( $op ),
848
-					esc_attr( $mapping['wordpress_object'] ),
849
-					esc_attr( $object_id ),
850
-					esc_attr( $object[ "$object_id" ] )
845
+				$title = sprintf(esc_html__('%1$s error syncing: %2$s to Salesforce (WordPress %3$s with %4$s of %5$s)', 'object-sync-for-salesforce'),
846
+					absint($salesforce_data['errorCode']),
847
+					esc_attr($op),
848
+					esc_attr($mapping['wordpress_object']),
849
+					esc_attr($object_id),
850
+					esc_attr($object["$object_id"])
851 851
 				);
852 852
 
853 853
 				// translators: placeholders are 1) the name of the Salesforce object type, 2) the error message returned from the Salesforce APIs
854
-				$body = sprintf( '<p>' . esc_html__( 'Object: %1$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Message: %2$s', 'object-sync-for-salesforce' ) . '</p>',
855
-					esc_attr( $mapping['salesforce_object'] ),
856
-					esc_html( $salesforce_data['message'] )
854
+				$body = sprintf('<p>' . esc_html__('Object: %1$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Message: %2$s', 'object-sync-for-salesforce') . '</p>',
855
+					esc_attr($mapping['salesforce_object']),
856
+					esc_html($salesforce_data['message'])
857 857
 				);
858 858
 
859 859
 				$logging->setup(
860 860
 					$title,
861 861
 					$body,
862 862
 					$sf_sync_trigger,
863
-					$object[ "$object_id" ],
863
+					$object["$object_id"],
864 864
 					$status
865 865
 				);
866 866
 
867 867
 				// hook for push fail
868
-				do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object );
868
+				do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object);
869 869
 
870 870
 				return;
871 871
 			} // End if().
@@ -873,41 +873,41 @@  discard block
 block discarded – undo
873 873
 			// $is_new is false here; we are updating an already mapped object
874 874
 
875 875
 			// right here we should set the pushing transient
876
-			set_transient( 'salesforce_pushing_' . $mapping_object['id'], 1, $seconds );
877
-			set_transient( 'salesforce_pushing_object_id', $mapping_object['id'] );
876
+			set_transient('salesforce_pushing_' . $mapping_object['id'], 1, $seconds);
877
+			set_transient('salesforce_pushing_object_id', $mapping_object['id']);
878 878
 
879 879
 			// there is an existing object link
880 880
 			// if the last sync is greater than the last time this object was updated, skip it
881 881
 			// this keeps us from doing redundant syncs
882
-			$mapping_object['object_updated'] = current_time( 'mysql' );
883
-			if ( $mapping_object['last_sync'] > $mapping_object['object_updated'] ) {
882
+			$mapping_object['object_updated'] = current_time('mysql');
883
+			if ($mapping_object['last_sync'] > $mapping_object['object_updated']) {
884 884
 				$status = 'notice';
885
-				if ( isset( $this->logging ) ) {
885
+				if (isset($this->logging)) {
886 886
 					$logging = $this->logging;
887
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
888
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
887
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
888
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
889 889
 				}
890 890
 
891 891
 				// translators: placeholders are: 1) what operation is happening, 2) the name of the WordPress object type, 3) the WordPress id field name, 4) the WordPress object id value, 5) the Salesforce Id value
892
-				$title = sprintf( esc_html__( 'Notice: %1$s: Did not sync WordPress %2$s with %3$s of %4$s with Salesforce Id %5$s because the last sync timestamp was greater than the object updated timestamp.', 'object-sync-for-salesforce' ),
893
-					esc_attr( $op ),
894
-					esc_attr( $mapping['wordpress_object'] ),
895
-					esc_attr( $object_id ),
896
-					esc_attr( $object[ "$object_id" ] ),
897
-					esc_attr( $mapping_object['salesforce_id'] )
892
+				$title = sprintf(esc_html__('Notice: %1$s: Did not sync WordPress %2$s with %3$s of %4$s with Salesforce Id %5$s because the last sync timestamp was greater than the object updated timestamp.', 'object-sync-for-salesforce'),
893
+					esc_attr($op),
894
+					esc_attr($mapping['wordpress_object']),
895
+					esc_attr($object_id),
896
+					esc_attr($object["$object_id"]),
897
+					esc_attr($mapping_object['salesforce_id'])
898 898
 				);
899 899
 
900 900
 				// translators: placeholders are 1) when a sync on this mapping last occured, 2) when the object was last updated
901
-				$body = sprintf( '<p>' . esc_html__( 'Last sync time: %1$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Object updated time: %2$s', 'object-sync-for-salesforce' ) . '</p>',
902
-					esc_attr( $mapping_object['last_sync'] ),
903
-					esc_html( $mapping_object['object_updated'] )
901
+				$body = sprintf('<p>' . esc_html__('Last sync time: %1$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Object updated time: %2$s', 'object-sync-for-salesforce') . '</p>',
902
+					esc_attr($mapping_object['last_sync']),
903
+					esc_html($mapping_object['object_updated'])
904 904
 				);
905 905
 
906 906
 				$logging->setup(
907 907
 					$title,
908 908
 					$body,
909 909
 					$sf_sync_trigger,
910
-					$object[ "$object_id" ],
910
+					$object["$object_id"],
911 911
 					$status
912 912
 				);
913 913
 				return;
@@ -918,71 +918,71 @@  discard block
 block discarded – undo
918 918
 
919 919
 				// hook to allow other plugins to do something right before Salesforce data is saved
920 920
 				// ex: run WordPress methods on an object if it exists, or do something in preparation for it if it doesn't
921
-				do_action( 'object_sync_for_salesforce_pre_push', $mapping_object['salesforce_id'], $mapping, $object, $object_id, $params );
921
+				do_action('object_sync_for_salesforce_pre_push', $mapping_object['salesforce_id'], $mapping, $object, $object_id, $params);
922 922
 
923 923
 				// hook to allow other plugins to change params on update actions only
924 924
 				// use hook to map fields between the WordPress and Salesforce objects
925 925
 				// returns $params.
926
-				$params = apply_filters( 'object_sync_for_salesforce_push_update_params_modify', $params, $mapping_object['salesforce_id'], $mapping, $object );
926
+				$params = apply_filters('object_sync_for_salesforce_push_update_params_modify', $params, $mapping_object['salesforce_id'], $mapping, $object);
927 927
 
928 928
 				$op     = 'Update';
929
-				$result = $sfapi->object_update( $mapping['salesforce_object'], $mapping_object['salesforce_id'], $params );
929
+				$result = $sfapi->object_update($mapping['salesforce_object'], $mapping_object['salesforce_id'], $params);
930 930
 
931 931
 				$mapping_object['last_sync_status']  = $this->mappings->status_success;
932
-				$mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__;
932
+				$mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__;
933 933
 
934 934
 				$status = 'success';
935
-				if ( isset( $this->logging ) ) {
935
+				if (isset($this->logging)) {
936 936
 					$logging = $this->logging;
937
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
938
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
937
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
938
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
939 939
 				}
940 940
 
941 941
 				// translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value
942
-				$title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ),
943
-					esc_attr( $op ),
944
-					esc_attr( $mapping['salesforce_object'] ),
945
-					esc_attr( $mapping_object['salesforce_id'] ),
946
-					esc_attr( $mapping['wordpress_object'] ),
947
-					esc_attr( $object_id ),
948
-					esc_attr( $object[ "$object_id" ] )
942
+				$title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'),
943
+					esc_attr($op),
944
+					esc_attr($mapping['salesforce_object']),
945
+					esc_attr($mapping_object['salesforce_id']),
946
+					esc_attr($mapping['wordpress_object']),
947
+					esc_attr($object_id),
948
+					esc_attr($object["$object_id"])
949 949
 				);
950 950
 
951 951
 				$logging->setup(
952 952
 					$title,
953 953
 					'',
954 954
 					$sf_sync_trigger,
955
-					$object[ "$object_id" ],
955
+					$object["$object_id"],
956 956
 					$status
957 957
 				);
958 958
 
959 959
 				// hook for push success
960
-				do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id );
960
+				do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id);
961 961
 
962
-			} catch ( Object_Sync_Sf_Exception $e ) {
962
+			} catch (Object_Sync_Sf_Exception $e) {
963 963
 				// create log entry for failed update
964 964
 				$status = 'error';
965
-				if ( isset( $this->logging ) ) {
965
+				if (isset($this->logging)) {
966 966
 					$logging = $this->logging;
967
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
968
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
967
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
968
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
969 969
 				}
970 970
 
971 971
 				// translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value
972
-				$title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ),
973
-					esc_attr( $op ),
974
-					esc_attr( $mapping['salesforce_object'] ),
975
-					esc_attr( $mapping_object['salesforce_id'] ),
976
-					esc_attr( $mapping['wordpress_object'] ),
977
-					esc_attr( $object_id ),
978
-					esc_attr( $object[ "$object_id" ] )
972
+				$title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'),
973
+					esc_attr($op),
974
+					esc_attr($mapping['salesforce_object']),
975
+					esc_attr($mapping_object['salesforce_id']),
976
+					esc_attr($mapping['wordpress_object']),
977
+					esc_attr($object_id),
978
+					esc_attr($object["$object_id"])
979 979
 				);
980 980
 
981 981
 				$logging->setup(
982 982
 					$title,
983 983
 					$e->getMessage(),
984 984
 					$sf_sync_trigger,
985
-					$object[ "$object_id" ],
985
+					$object["$object_id"],
986 986
 					$status
987 987
 				);
988 988
 
@@ -990,16 +990,16 @@  discard block
 block discarded – undo
990 990
 				$mapping_object['last_sync_message'] = $e->getMessage();
991 991
 
992 992
 				// hook for push fail
993
-				do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object );
993
+				do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object);
994 994
 
995 995
 			} // End try().
996 996
 
997 997
 			// tell the mapping object - whether it is new or already existed - how we just used it
998 998
 			$mapping_object['last_sync_action'] = 'push';
999
-			$mapping_object['last_sync']        = current_time( 'mysql' );
999
+			$mapping_object['last_sync']        = current_time('mysql');
1000 1000
 
1001 1001
 			// update that mapping object
1002
-			$result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] );
1002
+			$result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']);
1003 1003
 
1004 1004
 		} // End if(). this is the end of the if is_new stuff
1005 1005
 
@@ -1021,9 +1021,9 @@  discard block
 block discarded – undo
1021 1021
 	*   This is the database row for the map object
1022 1022
 	*
1023 1023
 	*/
1024
-	private function create_object_map( $wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false ) {
1024
+	private function create_object_map($wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false) {
1025 1025
 
1026
-		if ( true === $pending ) {
1026
+		if (true === $pending) {
1027 1027
 			$action = 'pending';
1028 1028
 		} else {
1029 1029
 			$action = 'created';
@@ -1032,15 +1032,15 @@  discard block
 block discarded – undo
1032 1032
 		// Create object map and save it
1033 1033
 		$mapping_object = $this->mappings->create_object_map(
1034 1034
 			array(
1035
-				'wordpress_id'      => $wordpress_object[ $id_field_name ], // wordpress unique id
1035
+				'wordpress_id'      => $wordpress_object[$id_field_name], // wordpress unique id
1036 1036
 				'salesforce_id'     => $salesforce_id, // salesforce unique id. we don't care what kind of object it is at this point
1037 1037
 				'wordpress_object'  => $field_mapping['wordpress_object'], // keep track of what kind of wp object this is
1038
-				'last_sync'         => current_time( 'mysql' ),
1038
+				'last_sync'         => current_time('mysql'),
1039 1039
 				'last_sync_action'  => 'push',
1040 1040
 				'last_sync_status'  => $this->mappings->status_success,
1041 1041
 				// translators: placeholder is for the action that occurred on the mapping object (pending or created)
1042
-				'last_sync_message' => sprintf( esc_html__( 'Mapping object %1$s via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__,
1043
-					esc_attr( $action )
1042
+				'last_sync_message' => sprintf(esc_html__('Mapping object %1$s via function: ', 'object-sync-for-salesforce') . __FUNCTION__,
1043
+					esc_attr($action)
1044 1044
 				),
1045 1045
 				'action'            => $action,
1046 1046
 			)
Please login to merge, or discard this patch.