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