Passed
Pull Request — master (#159)
by Jonathan
06:13
created
classes/salesforce_push.php 2 patches
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -24,24 +24,24 @@  discard block
 block discarded – undo
24 24
 	protected $schedulable_classes;
25 25
 
26 26
 	/**
27
-	* @var string
28
-	*/
27
+	 * @var string
28
+	 */
29 29
 	public $schedule_name; // allow for naming the queue in case there are multiple queues
30 30
 
31 31
 	/**
32
-	* Constructor which sets up push schedule
33
-	*
34
-	* @param object $wpdb
35
-	* @param string $version
36
-	* @param array $login_credentials
37
-	* @param string $slug
38
-	* @param object $wordpress
39
-	* @param object $salesforce
40
-	* @param object $mappings
41
-	* @param object $logging
42
-	* @param array $schedulable_classes
43
-	* @throws \Object_Sync_Sf_Exception
44
-	*/
32
+	 * Constructor which sets up push schedule
33
+	 *
34
+	 * @param object $wpdb
35
+	 * @param string $version
36
+	 * @param array $login_credentials
37
+	 * @param string $slug
38
+	 * @param object $wordpress
39
+	 * @param object $salesforce
40
+	 * @param object $mappings
41
+	 * @param object $logging
42
+	 * @param array $schedulable_classes
43
+	 * @throws \Object_Sync_Sf_Exception
44
+	 */
45 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;
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 	}
63 63
 
64 64
 	/**
65
-	* Create the action hooks based on what object maps exist from the admin settings.
66
-	* We do not have any actions for blogroll at this time.
67
-	*
68
-	*/
65
+	 * Create the action hooks based on what object maps exist from the admin settings.
66
+	 * We do not have any actions for blogroll at this time.
67
+	 *
68
+	 */
69 69
 	private function add_actions() {
70 70
 		$db_version = get_option( 'object_sync_for_salesforce_db_version', false );
71 71
 		if ( $db_version === $this->version ) {
@@ -97,54 +97,54 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 
99 99
 	/**
100
-	* Method for ajax hooks to call for pushing manually
101
-	*
102
-	* @param array $object
103
-	* @param string $type
104
-	*
105
-	*/
100
+	 * Method for ajax hooks to call for pushing manually
101
+	 *
102
+	 * @param array $object
103
+	 * @param string $type
104
+	 *
105
+	 */
106 106
 	public function manual_object_update( $object, $type ) {
107 107
 		$this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update, true );
108 108
 	}
109 109
 
110 110
 	/**
111
-	* Callback method for adding a user
112
-	*
113
-	* @param string $user_id
114
-	*/
111
+	 * Callback method for adding a user
112
+	 *
113
+	 * @param string $user_id
114
+	 */
115 115
 	public function add_user( $user_id ) {
116 116
 		$user = $this->wordpress->get_wordpress_object_data( 'user', $user_id );
117 117
 		$this->object_insert( $user, 'user' );
118 118
 	}
119 119
 
120 120
 	/**
121
-	* Callback method for editing a user
122
-	*
123
-	* @param string $user_id
124
-	* @param object $old_user_data
125
-	*/
121
+	 * Callback method for editing a user
122
+	 *
123
+	 * @param string $user_id
124
+	 * @param object $old_user_data
125
+	 */
126 126
 	public function edit_user( $user_id, $old_user_data ) {
127 127
 		$user = $this->wordpress->get_wordpress_object_data( 'user', $user_id );
128 128
 		$this->object_update( $user, 'user' );
129 129
 	}
130 130
 
131 131
 	/**
132
-	* Callback method for deleting a user
133
-	*
134
-	* @param string $user_id
135
-	*/
132
+	 * Callback method for deleting a user
133
+	 *
134
+	 * @param string $user_id
135
+	 */
136 136
 	public function delete_user( $user_id ) {
137 137
 		$user = $this->wordpress->get_wordpress_object_data( 'user', $user_id );
138 138
 		$this->object_delete( $user, 'user' );
139 139
 	}
140 140
 
141 141
 	/**
142
-	* Callback method for posts of any type
143
-	* This can handle create, update, and delete actions
144
-	*
145
-	* @param string $post_id
146
-	* @param object $post
147
-	*/
142
+	 * Callback method for posts of any type
143
+	 * This can handle create, update, and delete actions
144
+	 *
145
+	 * @param string $post_id
146
+	 * @param object $post
147
+	 */
148 148
 	public function post_actions( $post_id, $post ) {
149 149
 
150 150
 		$post_type = $post->post_type;
@@ -191,66 +191,66 @@  discard block
 block discarded – undo
191 191
 	}
192 192
 
193 193
 	/**
194
-	* Callback method for adding an attachment
195
-	*
196
-	* @param string $post_id
197
-	*/
194
+	 * Callback method for adding an attachment
195
+	 *
196
+	 * @param string $post_id
197
+	 */
198 198
 	public function add_attachment( $post_id ) {
199 199
 		$attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id );
200 200
 		$this->object_insert( $attachment, 'attachment' );
201 201
 	}
202 202
 
203 203
 	/**
204
-	* Callback method for editing an attachment
205
-	*
206
-	* @param string $post_id
207
-	*/
204
+	 * Callback method for editing an attachment
205
+	 *
206
+	 * @param string $post_id
207
+	 */
208 208
 	public function edit_attachment( $post_id ) {
209 209
 		$attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id );
210 210
 		$this->object_update( $attachment, 'attachment' );
211 211
 	}
212 212
 
213 213
 	/**
214
-	* Callback method for editing an attachment
215
-	*
216
-	* @param string $post_id
217
-	*/
214
+	 * Callback method for editing an attachment
215
+	 *
216
+	 * @param string $post_id
217
+	 */
218 218
 	public function delete_attachment( $post_id ) {
219 219
 		$attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id );
220 220
 		$this->object_delete( $attachment, 'attachment' );
221 221
 	}
222 222
 
223 223
 	/**
224
-	* Callback method for adding a term
225
-	*
226
-	* @param string $term_id
227
-	* @param string $tt_id
228
-	* @param string $taxonomy
229
-	*/
224
+	 * Callback method for adding a term
225
+	 *
226
+	 * @param string $term_id
227
+	 * @param string $tt_id
228
+	 * @param string $taxonomy
229
+	 */
230 230
 	public function add_term( $term_id, $tt_id, $taxonomy ) {
231 231
 		$term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id );
232 232
 		$this->object_insert( $term, $taxonomy );
233 233
 	}
234 234
 
235 235
 	/**
236
-	* Callback method for editing a term
237
-	*
238
-	* @param string $term_id
239
-	* @param string $taxonomy
240
-	*/
236
+	 * Callback method for editing a term
237
+	 *
238
+	 * @param string $term_id
239
+	 * @param string $taxonomy
240
+	 */
241 241
 	public function edit_term( $term_id, $taxonomy ) {
242 242
 		$term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id );
243 243
 		$this->object_update( $term, $taxonomy );
244 244
 	}
245 245
 
246 246
 	/**
247
-	* Callback method for deleting a term
248
-	*
249
-	* @param int $term (id)
250
-	* @param int $term_taxonomy_id
251
-	* @param string $taxonomy (slug)
252
-	* @param object $deleted_term
253
-	*/
247
+	 * Callback method for deleting a term
248
+	 *
249
+	 * @param int $term (id)
250
+	 * @param int $term_taxonomy_id
251
+	 * @param string $taxonomy (slug)
252
+	 * @param object $deleted_term
253
+	 */
254 254
 	public function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) {
255 255
 		$deleted_term = (array) $deleted_term;
256 256
 		$type         = $deleted_term['taxonomy'];
@@ -258,75 +258,75 @@  discard block
 block discarded – undo
258 258
 	}
259 259
 
260 260
 	/**
261
-	* Callback method for adding a comment
262
-	*
263
-	* @param string $comment_id
264
-	* @param int|string comment_approved
265
-	* @param array $commentdata
266
-	*/
261
+	 * Callback method for adding a comment
262
+	 *
263
+	 * @param string $comment_id
264
+	 * @param int|string comment_approved
265
+	 * @param array $commentdata
266
+	 */
267 267
 	public function add_comment( $comment_id, $comment_approved, $commentdata = array() ) {
268 268
 		$comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id );
269 269
 		$this->object_insert( $comment, 'comment' );
270 270
 	}
271 271
 
272 272
 	/**
273
-	* Callback method for editing a comment
274
-	*
275
-	* @param string $comment_id
276
-	*/
273
+	 * Callback method for editing a comment
274
+	 *
275
+	 * @param string $comment_id
276
+	 */
277 277
 	public function edit_comment( $comment_id ) {
278 278
 		$comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id );
279 279
 		$this->object_update( $comment, 'comment' );
280 280
 	}
281 281
 
282 282
 	/**
283
-	* Callback method for deleting a comment
284
-	*
285
-	* @param string $comment_id
286
-	*/
283
+	 * Callback method for deleting a comment
284
+	 *
285
+	 * @param string $comment_id
286
+	 */
287 287
 	public function delete_comment( $comment_id ) {
288 288
 		$comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id );
289 289
 		$this->object_delete( $comment, 'comment' );
290 290
 	}
291 291
 
292 292
 	/**
293
-	* Insert a new object
294
-	* This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
295
-	*/
293
+	 * Insert a new object
294
+	 * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
295
+	 */
296 296
 	private function object_insert( $object, $type ) {
297 297
 		$this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_create );
298 298
 	}
299 299
 
300 300
 	/**
301
-	* Update an existing object
302
-	* This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
303
-	*/
301
+	 * Update an existing object
302
+	 * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
303
+	 */
304 304
 	private function object_update( $object, $type ) {
305 305
 		$this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update );
306 306
 	}
307 307
 
308 308
 	/**
309
-	* Delete an existing object
310
-	* This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
311
-	*/
309
+	 * Delete an existing object
310
+	 * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class
311
+	 */
312 312
 	private function object_delete( $object, $type ) {
313 313
 		$this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_delete );
314 314
 	}
315 315
 
316 316
 	/**
317
-	* Push objects to Salesforce.
318
-	* This method decides whether to do the processing immediately or queue it to the schedule class (or skip it based on another plugin's activity)
319
-	*
320
-	* @param string $object_type
321
-	*   Type of WordPress object.
322
-	* @param array $object
323
-	*   The WordPress data that needs to be sent to Salesforce.
324
-	* @param int $sf_sync_trigger
325
-	*   The trigger being responded to.
326
-	* @param bool $manual
327
-	*   Are we calling this manually?
328
-	*
329
-	*/
317
+	 * Push objects to Salesforce.
318
+	 * This method decides whether to do the processing immediately or queue it to the schedule class (or skip it based on another plugin's activity)
319
+	 *
320
+	 * @param string $object_type
321
+	 *   Type of WordPress object.
322
+	 * @param array $object
323
+	 *   The WordPress data that needs to be sent to Salesforce.
324
+	 * @param int $sf_sync_trigger
325
+	 *   The trigger being responded to.
326
+	 * @param bool $manual
327
+	 *   Are we calling this manually?
328
+	 *
329
+	 */
330 330
 	private function salesforce_push_object_crud( $object_type, $object, $sf_sync_trigger, $manual = false ) {
331 331
 
332 332
 		$structure       = $this->wordpress->get_wordpress_table_structure( $object_type );
@@ -451,20 +451,20 @@  discard block
 block discarded – undo
451 451
 	}
452 452
 
453 453
 	/**
454
-	* Sync WordPress objects and Salesforce objects using the REST API.
455
-	*
456
-	* @param string $object_type
457
-	*   Type of WordPress object.
458
-	* @param object $object
459
-	*   The object object.
460
-	* @param object $mapping
461
-	*   Salesforce mapping object.
462
-	* @param int $sf_sync_trigger
463
-	*   Trigger for this sync.
464
-	*
465
-	* @return true or exit the method
466
-	*
467
-	*/
454
+	 * Sync WordPress objects and Salesforce objects using the REST API.
455
+	 *
456
+	 * @param string $object_type
457
+	 *   Type of WordPress object.
458
+	 * @param object $object
459
+	 *   The object object.
460
+	 * @param object $mapping
461
+	 *   Salesforce mapping object.
462
+	 * @param int $sf_sync_trigger
463
+	 *   Trigger for this sync.
464
+	 *
465
+	 * @return true or exit the method
466
+	 *
467
+	 */
468 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.
@@ -1006,21 +1006,21 @@  discard block
 block discarded – undo
1006 1006
 	}
1007 1007
 
1008 1008
 	/**
1009
-	* Create an object map between a WordPress object and a Salesforce object
1010
-	*
1011
-	* @param array $wordpress_object
1012
-	*   Array of the WordPress object's data
1013
-	* @param string $id_field_name
1014
-	*   How this object names its primary field. ie Id or comment_id or whatever
1015
-	* @param string $salesforce_id
1016
-	*   Unique identifier for the Salesforce object
1017
-	* @param array $field_mapping
1018
-	*   The row that maps the object types together, including which fields match which other fields
1019
-	*
1020
-	* @return int $wpdb->insert_id
1021
-	*   This is the database row for the map object
1022
-	*
1023
-	*/
1009
+	 * Create an object map between a WordPress object and a Salesforce object
1010
+	 *
1011
+	 * @param array $wordpress_object
1012
+	 *   Array of the WordPress object's data
1013
+	 * @param string $id_field_name
1014
+	 *   How this object names its primary field. ie Id or comment_id or whatever
1015
+	 * @param string $salesforce_id
1016
+	 *   Unique identifier for the Salesforce object
1017
+	 * @param array $field_mapping
1018
+	 *   The row that maps the object types together, including which fields match which other fields
1019
+	 *
1020
+	 * @return int $wpdb->insert_id
1021
+	 *   This is the database row for the map object
1022
+	 *
1023
+	 */
1024 1024
 	private function create_object_map( $wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false ) {
1025 1025
 
1026 1026
 		if ( true === $pending ) {
Please login to merge, or discard this 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.
classes/deactivate.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -18,13 +18,13 @@  discard block
 block discarded – undo
18 18
 	protected $version;
19 19
 
20 20
 	/**
21
-	* Constructor which sets up deactivate hooks
22
-	* @param object $wpdb
23
-	* @param string $version
24
-	* @param string $slug
25
-	* @param array $schedulable_classes
26
-	*
27
-	*/
21
+	 * Constructor which sets up deactivate hooks
22
+	 * @param object $wpdb
23
+	 * @param string $version
24
+	 * @param string $slug
25
+	 * @param array $schedulable_classes
26
+	 *
27
+	 */
28 28
 	public function __construct( $wpdb, $version, $slug, $schedulable_classes ) {
29 29
 		$this->wpdb                = $wpdb;
30 30
 		$this->version             = $version;
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 	}
43 43
 
44 44
 	/**
45
-	* Drop database tables for Salesforce
46
-	* This removes the tables for fieldmaps (between types of objects) and object maps (between indidual instances of objects)
47
-	*
48
-	*/
45
+	 * Drop database tables for Salesforce
46
+	 * This removes the tables for fieldmaps (between types of objects) and object maps (between indidual instances of objects)
47
+	 *
48
+	 */
49 49
 	public function wordpress_salesforce_drop_tables() {
50 50
 		$field_map_table  = $this->wpdb->prefix . 'object_sync_sf_field_map';
51 51
 		$object_map_table = $this->wpdb->prefix . 'object_sync_sf_object_map';
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 	}
56 56
 
57 57
 	/**
58
-	* Clear the scheduled tasks
59
-	* This removes all the scheduled tasks that are included in the plugin's $schedulable_classes array
60
-	*
61
-	*/
58
+	 * Clear the scheduled tasks
59
+	 * This removes all the scheduled tasks that are included in the plugin's $schedulable_classes array
60
+	 *
61
+	 */
62 62
 	public function clear_schedule() {
63 63
 		foreach ( $this->schedulable_classes as $key => $value ) {
64 64
 			wp_clear_scheduled_hook( $key );
@@ -66,21 +66,21 @@  discard block
 block discarded – undo
66 66
 	}
67 67
 
68 68
 	/**
69
-	* Delete the log post type
70
-	* This removes the log post type
71
-	*
72
-	*/
69
+	 * Delete the log post type
70
+	 * This removes the log post type
71
+	 *
72
+	 */
73 73
 	public function delete_log_post_type() {
74 74
 		unregister_post_type( 'wp_log' );
75 75
 	}
76 76
 
77 77
 	/**
78
-	* Remove roles and capabilities
79
-	* This removes the configure_salesforce capability from the admin role
80
-	*
81
-	* It also allows other plugins to remove the capability from other roles
82
-	*
83
-	*/
78
+	 * Remove roles and capabilities
79
+	 * This removes the configure_salesforce capability from the admin role
80
+	 *
81
+	 * It also allows other plugins to remove the capability from other roles
82
+	 *
83
+	 */
84 84
 	public function remove_roles_capabilities() {
85 85
 
86 86
 		// by default, only administrators can configure the plugin
@@ -100,18 +100,18 @@  discard block
 block discarded – undo
100 100
 	}
101 101
 
102 102
 	/**
103
-	* Flush the plugin cache
104
-	*
105
-	*/
103
+	 * Flush the plugin cache
104
+	 *
105
+	 */
106 106
 	public function flush_plugin_cache() {
107 107
 		$sfwp_transients = new Object_Sync_Sf_WordPress_Transient( 'sfwp_transients' );
108 108
 		$sfwp_transients->flush();
109 109
 	}
110 110
 
111 111
 	/**
112
-	* Clear the plugin options
113
-	*
114
-	*/
112
+	 * Clear the plugin options
113
+	 *
114
+	 */
115 115
 	public function delete_plugin_options() {
116 116
 		$table          = $this->wpdb->prefix . 'options';
117 117
 		$plugin_options = $this->wpdb->get_results( 'SELECT option_name FROM ' . $table . ' WHERE option_name LIKE "object_sync_for_salesforce_%"', ARRAY_A );
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 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
 
@@ -25,19 +25,19 @@  discard block
 block discarded – undo
25 25
 	* @param array $schedulable_classes
26 26
 	*
27 27
 	*/
28
-	public function __construct( $wpdb, $version, $slug, $schedulable_classes ) {
28
+	public function __construct($wpdb, $version, $slug, $schedulable_classes) {
29 29
 		$this->wpdb                = $wpdb;
30 30
 		$this->version             = $version;
31 31
 		$this->schedulable_classes = $schedulable_classes;
32
-		$delete_data               = (int) get_option( 'object_sync_for_salesforce_delete_data_on_uninstall', 0 );
33
-		if ( 1 === $delete_data ) {
34
-			register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'wordpress_salesforce_drop_tables' ) );
35
-			register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'clear_schedule' ) );
36
-			register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'delete_log_post_type' ) );
37
-			register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'remove_roles_capabilities' ) );
38
-			register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'flush_plugin_cache' )
32
+		$delete_data               = (int) get_option('object_sync_for_salesforce_delete_data_on_uninstall', 0);
33
+		if (1 === $delete_data) {
34
+			register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'wordpress_salesforce_drop_tables'));
35
+			register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'clear_schedule'));
36
+			register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'delete_log_post_type'));
37
+			register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'remove_roles_capabilities'));
38
+			register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'flush_plugin_cache')
39 39
 			);
40
-			register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'delete_plugin_options' ) );
40
+			register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'delete_plugin_options'));
41 41
 		}
42 42
 	}
43 43
 
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	public function wordpress_salesforce_drop_tables() {
50 50
 		$field_map_table  = $this->wpdb->prefix . 'object_sync_sf_field_map';
51 51
 		$object_map_table = $this->wpdb->prefix . 'object_sync_sf_object_map';
52
-		$this->wpdb->query( 'DROP TABLE IF EXISTS ' . $field_map_table );
53
-		$this->wpdb->query( 'DROP TABLE IF EXISTS ' . $object_map_table );
54
-		delete_option( 'object_sync_for_salesforce_db_version' );
52
+		$this->wpdb->query('DROP TABLE IF EXISTS ' . $field_map_table);
53
+		$this->wpdb->query('DROP TABLE IF EXISTS ' . $object_map_table);
54
+		delete_option('object_sync_for_salesforce_db_version');
55 55
 	}
56 56
 
57 57
 	/**
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	*
61 61
 	*/
62 62
 	public function clear_schedule() {
63
-		foreach ( $this->schedulable_classes as $key => $value ) {
64
-			wp_clear_scheduled_hook( $key );
63
+		foreach ($this->schedulable_classes as $key => $value) {
64
+			wp_clear_scheduled_hook($key);
65 65
 		}
66 66
 	}
67 67
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	*
72 72
 	*/
73 73
 	public function delete_log_post_type() {
74
-		unregister_post_type( 'wp_log' );
74
+		unregister_post_type('wp_log');
75 75
 	}
76 76
 
77 77
 	/**
@@ -84,16 +84,16 @@  discard block
 block discarded – undo
84 84
 	public function remove_roles_capabilities() {
85 85
 
86 86
 		// by default, only administrators can configure the plugin
87
-		$role = get_role( 'administrator' );
88
-		$role->remove_cap( 'configure_salesforce' );
87
+		$role = get_role('administrator');
88
+		$role->remove_cap('configure_salesforce');
89 89
 
90 90
 		// hook that allows other roles to configure the plugin as well
91
-		$roles = apply_filters( 'object_sync_for_salesforce_roles_configure_salesforce', null );
91
+		$roles = apply_filters('object_sync_for_salesforce_roles_configure_salesforce', null);
92 92
 
93 93
 		// for each role that we have, remove the configure salesforce capability
94
-		if ( null !== $roles ) {
95
-			foreach ( $roles as $role ) {
96
-				$role->remove_cap( 'configure_salesforce' );
94
+		if (null !== $roles) {
95
+			foreach ($roles as $role) {
96
+				$role->remove_cap('configure_salesforce');
97 97
 			}
98 98
 		}
99 99
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	*
105 105
 	*/
106 106
 	public function flush_plugin_cache() {
107
-		$sfwp_transients = new Object_Sync_Sf_WordPress_Transient( 'sfwp_transients' );
107
+		$sfwp_transients = new Object_Sync_Sf_WordPress_Transient('sfwp_transients');
108 108
 		$sfwp_transients->flush();
109 109
 	}
110 110
 
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 	*/
115 115
 	public function delete_plugin_options() {
116 116
 		$table          = $this->wpdb->prefix . 'options';
117
-		$plugin_options = $this->wpdb->get_results( 'SELECT option_name FROM ' . $table . ' WHERE option_name LIKE "object_sync_for_salesforce_%"', ARRAY_A );
118
-		foreach ( $plugin_options as $option ) {
119
-			delete_option( $option['option_name'] );
117
+		$plugin_options = $this->wpdb->get_results('SELECT option_name FROM ' . $table . ' WHERE option_name LIKE "object_sync_for_salesforce_%"', ARRAY_A);
118
+		foreach ($plugin_options as $option) {
119
+			delete_option($option['option_name']);
120 120
 		}
121 121
 	}
122 122
 
Please login to merge, or discard this patch.
classes/logging.php 1 patch
Spacing   +57 added lines, -57 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
 
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
 	 * @param string $version The version of this plugin.
29 29
 	 * @throws \Exception
30 30
 	 */
31
-	public function __construct( $wpdb, $version ) {
31
+	public function __construct($wpdb, $version) {
32 32
 		$this->wpdb    = $wpdb;
33 33
 		$this->version = $version;
34 34
 
35
-		$this->enabled         = get_option( 'object_sync_for_salesforce_enable_logging', false );
36
-		$this->statuses_to_log = get_option( 'object_sync_for_salesforce_statuses_to_log', array() );
35
+		$this->enabled         = get_option('object_sync_for_salesforce_enable_logging', false);
36
+		$this->statuses_to_log = get_option('object_sync_for_salesforce_statuses_to_log', array());
37 37
 
38 38
 		$this->schedule_name = 'wp_logging_prune_routine';
39 39
 
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
 	 * @throws \Exception
48 48
 	 */
49 49
 	private function init() {
50
-		if ( '1' === $this->enabled ) {
51
-			add_filter( 'cron_schedules', array( $this, 'add_prune_interval' ) );
52
-			add_filter( 'wp_log_types', array( $this, 'set_log_types' ), 10, 1 );
53
-			add_filter( 'wp_logging_should_we_prune', array( $this, 'set_prune_option' ), 10, 1 );
54
-			add_filter( 'wp_logging_prune_when', array( $this, 'set_prune_age' ), 10, 1 );
55
-			add_filter( 'wp_logging_prune_query_args', array( $this, 'set_prune_args' ), 10, 1 );
56
-			add_filter( 'wp_logging_post_type_args', array( $this, 'set_log_visibility' ), 10, 1 );
57
-
58
-			$schedule_unit = get_option( 'object_sync_for_salesforce_logs_how_often_unit', '' );
59
-			$schedule_number = get_option( 'object_sync_for_salesforce_logs_how_often_number', '' );
60
-			$frequency = $this->get_schedule_frequency( $schedule_unit, $schedule_number );
50
+		if ('1' === $this->enabled) {
51
+			add_filter('cron_schedules', array($this, 'add_prune_interval'));
52
+			add_filter('wp_log_types', array($this, 'set_log_types'), 10, 1);
53
+			add_filter('wp_logging_should_we_prune', array($this, 'set_prune_option'), 10, 1);
54
+			add_filter('wp_logging_prune_when', array($this, 'set_prune_age'), 10, 1);
55
+			add_filter('wp_logging_prune_query_args', array($this, 'set_prune_args'), 10, 1);
56
+			add_filter('wp_logging_post_type_args', array($this, 'set_log_visibility'), 10, 1);
57
+
58
+			$schedule_unit = get_option('object_sync_for_salesforce_logs_how_often_unit', '');
59
+			$schedule_number = get_option('object_sync_for_salesforce_logs_how_often_number', '');
60
+			$frequency = $this->get_schedule_frequency($schedule_unit, $schedule_number);
61 61
 			$key = $frequency['key'];
62 62
 
63
-			if ( ! wp_next_scheduled( $this->schedule_name ) ) {
64
-				wp_schedule_event( time(), $key, $this->schedule_name );
63
+			if ( ! wp_next_scheduled($this->schedule_name)) {
64
+				wp_schedule_event(time(), $key, $this->schedule_name);
65 65
 			}
66 66
 		}
67 67
 	}
68 68
 
69
-	public function set_log_visibility( $log_args ) {
69
+	public function set_log_visibility($log_args) {
70 70
 		// set public to true overrides the WP_DEBUG setting that is the default on the class
71 71
 		// capabilities makes it so (currently) only admin users can see the log posts in their admin view
72 72
 		// note: there is no actual "public" view for this post type
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 			'read_private_posts' => 'configure_salesforce',
83 83
 		);
84 84
 
85
-		$log_args = apply_filters( 'object_sync_for_salesforce_logging_post_type_args', $log_args );
85
+		$log_args = apply_filters('object_sync_for_salesforce_logging_post_type_args', $log_args);
86 86
 
87 87
 		return $log_args;
88 88
 	}
@@ -93,15 +93,15 @@  discard block
 block discarded – undo
93 93
 	 * @param array $schedules An array of scheduled cron items.
94 94
 	 * @return array $frequency
95 95
 	 */
96
-	public function add_prune_interval( $schedules ) {
96
+	public function add_prune_interval($schedules) {
97 97
 
98
-		$schedule_unit   = get_option( 'object_sync_for_salesforce_logs_how_often_unit', '' );
99
-		$schedule_number = get_option( 'object_sync_for_salesforce_logs_how_often_number', '' );
100
-		$frequency       = $this->get_schedule_frequency( $schedule_unit, $schedule_number );
98
+		$schedule_unit   = get_option('object_sync_for_salesforce_logs_how_often_unit', '');
99
+		$schedule_number = get_option('object_sync_for_salesforce_logs_how_often_number', '');
100
+		$frequency       = $this->get_schedule_frequency($schedule_unit, $schedule_number);
101 101
 		$key             = $frequency['key'];
102 102
 		$seconds         = $frequency['seconds'];
103 103
 
104
-		$schedules[ $key ] = array(
104
+		$schedules[$key] = array(
105 105
 			'interval' => $seconds * $schedule_number,
106 106
 			'display'  => 'Every ' . $schedule_number . ' ' . $schedule_unit,
107 107
 		);
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
 	 * @param number $number The number of those units.
119 119
 	 * @return array
120 120
 	 */
121
-	public function get_schedule_frequency( $unit, $number ) {
121
+	public function get_schedule_frequency($unit, $number) {
122 122
 
123
-		switch ( $unit ) {
123
+		switch ($unit) {
124 124
 			case 'minutes':
125 125
 				$seconds = 60;
126 126
 				break;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @param array $terms An array of string log types in the WP_Logging class.
150 150
 	 * @return array $terms
151 151
 	 */
152
-	public function set_log_types( $terms ) {
152
+	public function set_log_types($terms) {
153 153
 		$terms[] = 'salesforce';
154 154
 		return $terms;
155 155
 	}
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 	 * @param string $should_we_prune Whether to prune old log items.
161 161
 	 * @return string $should_we_prune Whether to prune old log items.
162 162
 	 */
163
-	public function set_prune_option( $should_we_prune ) {
164
-		$should_we_prune = get_option( 'object_sync_for_salesforce_prune_logs', $should_we_prune );
165
-		if ( '1' === $should_we_prune ) {
163
+	public function set_prune_option($should_we_prune) {
164
+		$should_we_prune = get_option('object_sync_for_salesforce_prune_logs', $should_we_prune);
165
+		if ('1' === $should_we_prune) {
166 166
 			$should_we_prune = true;
167 167
 		}
168 168
 		return $should_we_prune;
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 	 * @param string $how_old How old the oldest non-pruned log items should be allowed to be.
175 175
 	 * @return string $how_old
176 176
 	 */
177
-	public function set_prune_age( $how_old ) {
178
-		$value = get_option( 'object_sync_for_salesforce_logs_how_old', '' ) . ' ago';
179
-		if ( '' !== $value ) {
177
+	public function set_prune_age($how_old) {
178
+		$value = get_option('object_sync_for_salesforce_logs_how_old', '') . ' ago';
179
+		if ('' !== $value) {
180 180
 			return $value;
181 181
 		} else {
182 182
 			return $how_old;
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @param array $args Argument array for get_posts determining what posts are eligible for pruning.
190 190
 	 * @return array $args
191 191
 	 */
192
-	public function set_prune_args( $args ) {
192
+	public function set_prune_args($args) {
193 193
 		$args['wp_log_type'] = 'salesforce';
194 194
 		return $args;
195 195
 	}
@@ -213,12 +213,12 @@  discard block
 block discarded – undo
213 213
 	 *
214 214
 	 * @return      void
215 215
 	 */
216
-	public function setup( $title, $message, $trigger = 0, $parent = 0, $status ) {
217
-		if ( '1' === $this->enabled && in_array( $status, maybe_unserialize( $this->statuses_to_log ), true ) ) {
218
-			$triggers_to_log = get_option( 'object_sync_for_salesforce_triggers_to_log', array() );
216
+	public function setup($title, $message, $trigger = 0, $parent = 0, $status) {
217
+		if ('1' === $this->enabled && in_array($status, maybe_unserialize($this->statuses_to_log), true)) {
218
+			$triggers_to_log = get_option('object_sync_for_salesforce_triggers_to_log', array());
219 219
 			// if we force strict on this in_array, it fails because the mapping triggers are bit operators, as indicated in Object_Sync_Sf_Mapping class's method __construct()
220
-			if ( in_array( $trigger, maybe_unserialize( $triggers_to_log ) ) || 0 === $trigger ) {
221
-				$this->add( $title, $message, $parent );
220
+			if (in_array($trigger, maybe_unserialize($triggers_to_log)) || 0 === $trigger) {
221
+				$this->add($title, $message, $parent);
222 222
 			}
223 223
 		}
224 224
 	}
@@ -241,16 +241,16 @@  discard block
 block discarded – undo
241 241
 	 *
242 242
 	 * @return      int The ID of the new log entry
243 243
 	 */
244
-	public static function add( $title = '', $message = '', $parent = 0, $type = 'salesforce' ) {
244
+	public static function add($title = '', $message = '', $parent = 0, $type = 'salesforce') {
245 245
 
246 246
 		$log_data = array(
247
-			'post_title'   => esc_html( $title ),
248
-			'post_content' => wp_kses_post( $message ),
249
-			'post_parent'  => absint( $parent ),
250
-			'log_type'     => esc_attr( $type ),
247
+			'post_title'   => esc_html($title),
248
+			'post_content' => wp_kses_post($message),
249
+			'post_parent'  => absint($parent),
250
+			'log_type'     => esc_attr($type),
251 251
 		);
252 252
 
253
-		return self::insert_log( $log_data );
253
+		return self::insert_log($log_data);
254 254
 
255 255
 	}
256 256
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return      array
271 271
 	 */
272
-	public static function get_logs( $object_id = 0, $type = 'salesforce', $paged = null ) {
272
+	public static function get_logs($object_id = 0, $type = 'salesforce', $paged = null) {
273 273
 		return self::get_connected_logs(
274 274
 			array(
275 275
 				'post_parent' => (int) $object_id,
@@ -297,20 +297,20 @@  discard block
 block discarded – undo
297 297
 	 *
298 298
 	 * @return  array / false
299 299
 	 */
300
-	public static function get_connected_logs( $args = array() ) {
300
+	public static function get_connected_logs($args = array()) {
301 301
 
302 302
 		$defaults = array(
303 303
 			'post_parent'    => 0,
304 304
 			'post_type'      => 'wp_log',
305 305
 			'posts_per_page' => 10,
306 306
 			'post_status'    => 'publish',
307
-			'paged'          => get_query_var( 'paged' ),
307
+			'paged'          => get_query_var('paged'),
308 308
 			'log_type'       => 'salesforce',
309 309
 		);
310 310
 
311
-		$query_args = wp_parse_args( $args, $defaults );
311
+		$query_args = wp_parse_args($args, $defaults);
312 312
 
313
-		if ( $query_args['log_type'] && self::valid_type( $query_args['log_type'] ) ) {
313
+		if ($query_args['log_type'] && self::valid_type($query_args['log_type'])) {
314 314
 
315 315
 			$query_args['tax_query'] = array(
316 316
 				array(
@@ -322,9 +322,9 @@  discard block
 block discarded – undo
322 322
 
323 323
 		}
324 324
 
325
-		$logs = get_posts( $query_args );
325
+		$logs = get_posts($query_args);
326 326
 
327
-		if ( $logs ) {
327
+		if ($logs) {
328 328
 			return $logs;
329 329
 		}
330 330
 
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 	 *
350 350
 	 * @return  int
351 351
 	 */
352
-	public static function get_log_count( $object_id = 0, $type = 'salesforce', $meta_query = null ) {
352
+	public static function get_log_count($object_id = 0, $type = 'salesforce', $meta_query = null) {
353 353
 
354 354
 		$query_args = array(
355 355
 			'post_parent'    => (int) $object_id,
@@ -358,23 +358,23 @@  discard block
 block discarded – undo
358 358
 			'post_status'    => 'publish',
359 359
 		);
360 360
 
361
-		if ( ! empty( $type ) && self::valid_type( $type ) ) {
361
+		if ( ! empty($type) && self::valid_type($type)) {
362 362
 
363 363
 			$query_args['tax_query'] = array(
364 364
 				array(
365 365
 					'taxonomy' => 'wp_log_type',
366 366
 					'field'    => 'slug',
367
-					'terms'    => sanitize_key( $type ),
367
+					'terms'    => sanitize_key($type),
368 368
 				),
369 369
 			);
370 370
 
371 371
 		}
372 372
 
373
-		if ( ! empty( $meta_query ) ) {
373
+		if ( ! empty($meta_query)) {
374 374
 			$query_args['meta_query'] = $meta_query;
375 375
 		}
376 376
 
377
-		$logs = new WP_Query( $query_args );
377
+		$logs = new WP_Query($query_args);
378 378
 
379 379
 		return (int) $logs->post_count;
380 380
 
Please login to merge, or discard this patch.
classes/schedule.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -25,18 +25,18 @@  discard block
 block discarded – undo
25 25
 	protected $logging;
26 26
 
27 27
 	/**
28
-	* Constructor which sets up schedule and handler for when schedule runs
29
-	*
30
-	* @param object $wpdb
31
-	* @param string $version
32
-	* @param array $login_credentials
33
-	* @param string $slug
34
-	* @param object $wordpress
35
-	* @param object $salesforce
36
-	* @param object $mappings
37
-	* @param string $schedule_name
38
-	* @throws \Exception
39
-	*/
28
+	 * Constructor which sets up schedule and handler for when schedule runs
29
+	 *
30
+	 * @param object $wpdb
31
+	 * @param string $version
32
+	 * @param array $login_credentials
33
+	 * @param string $slug
34
+	 * @param object $wordpress
35
+	 * @param object $salesforce
36
+	 * @param object $mappings
37
+	 * @param string $schedule_name
38
+	 * @throws \Exception
39
+	 */
40 40
 
41 41
 	public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $schedule_name, $logging, $schedulable_classes ) {
42 42
 
@@ -59,18 +59,18 @@  discard block
 block discarded – undo
59 59
 	}
60 60
 
61 61
 	/**
62
-	* Create the filters we need to run
63
-	*
64
-	*/
62
+	 * Create the filters we need to run
63
+	 *
64
+	 */
65 65
 	public function add_filters() {
66 66
 		add_filter( 'cron_schedules', array( $this, 'set_schedule_frequency' ) );
67 67
 	}
68 68
 
69 69
 	/**
70
-	* Convert the schedule frequency from the admin settings into an array
71
-	* interval must be in seconds for the class to use it
72
-	*
73
-	*/
70
+	 * Convert the schedule frequency from the admin settings into an array
71
+	 * interval must be in seconds for the class to use it
72
+	 *
73
+	 */
74 74
 	public function set_schedule_frequency( $schedules ) {
75 75
 
76 76
 		// create an option in the core schedules array for each one the plugin defines
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 	}
109 109
 
110 110
 	/**
111
-	* Convert the schedule frequency from the admin settings into an array
112
-	* interval must be in seconds for the class to use it
113
-	*
114
-	*/
111
+	 * Convert the schedule frequency from the admin settings into an array
112
+	 * interval must be in seconds for the class to use it
113
+	 *
114
+	 */
115 115
 	public function get_schedule_frequency_key( $name = '' ) {
116 116
 
117 117
 		$schedule_number = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_number', '' );
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
 	}
139 139
 
140 140
 	/**
141
-	* Convert the schedule frequency from the admin settings into seconds
142
-	*
143
-	*/
141
+	 * Convert the schedule frequency from the admin settings into seconds
142
+	 *
143
+	 */
144 144
 	public function get_schedule_frequency_seconds( $name = '' ) {
145 145
 
146 146
 		$schedule_number = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_number', '' );
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 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
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	* @throws \Exception
39 39
 	*/
40 40
 
41
-	public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $schedule_name, $logging, $schedulable_classes ) {
41
+	public function __construct($wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $schedule_name, $logging, $schedulable_classes) {
42 42
 
43 43
 		$this->wpdb                = $wpdb;
44 44
 		$this->version             = $version;
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		$this->identifier = $this->schedule_name;
55 55
 
56 56
 		$this->add_filters();
57
-		add_action( $this->schedule_name, array( $this, 'maybe_handle' ) ); // run the handle method
57
+		add_action($this->schedule_name, array($this, 'maybe_handle')); // run the handle method
58 58
 
59 59
 	}
60 60
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	*
64 64
 	*/
65 65
 	public function add_filters() {
66
-		add_filter( 'cron_schedules', array( $this, 'set_schedule_frequency' ) );
66
+		add_filter('cron_schedules', array($this, 'set_schedule_frequency'));
67 67
 	}
68 68
 
69 69
 	/**
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 	* interval must be in seconds for the class to use it
72 72
 	*
73 73
 	*/
74
-	public function set_schedule_frequency( $schedules ) {
74
+	public function set_schedule_frequency($schedules) {
75 75
 
76 76
 		// create an option in the core schedules array for each one the plugin defines
77
-		foreach ( $this->schedulable_classes as $key => $value ) {
78
-			$schedule_number = absint( get_option( 'object_sync_for_salesforce_' . $key . '_schedule_number', '' ) );
79
-			$schedule_unit   = get_option( 'object_sync_for_salesforce_' . $key . '_schedule_unit', '' );
77
+		foreach ($this->schedulable_classes as $key => $value) {
78
+			$schedule_number = absint(get_option('object_sync_for_salesforce_' . $key . '_schedule_number', ''));
79
+			$schedule_unit   = get_option('object_sync_for_salesforce_' . $key . '_schedule_unit', '');
80 80
 
81
-			switch ( $schedule_unit ) {
81
+			switch ($schedule_unit) {
82 82
 				case 'minutes':
83 83
 					$seconds = 60;
84 84
 					break;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 
95 95
 			$key = $schedule_unit . '_' . $schedule_number;
96 96
 
97
-			$schedules[ $key ] = array(
97
+			$schedules[$key] = array(
98 98
 				'interval' => $seconds * $schedule_number,
99 99
 				'display'  => 'Every ' . $schedule_number . ' ' . $schedule_unit,
100 100
 			);
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 	* interval must be in seconds for the class to use it
113 113
 	*
114 114
 	*/
115
-	public function get_schedule_frequency_key( $name = '' ) {
115
+	public function get_schedule_frequency_key($name = '') {
116 116
 
117
-		$schedule_number = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_number', '' );
118
-		$schedule_unit   = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_unit', '' );
117
+		$schedule_number = get_option('object_sync_for_salesforce_' . $name . '_schedule_number', '');
118
+		$schedule_unit   = get_option('object_sync_for_salesforce_' . $name . '_schedule_unit', '');
119 119
 
120
-		switch ( $schedule_unit ) {
120
+		switch ($schedule_unit) {
121 121
 			case 'minutes':
122 122
 				$seconds = 60;
123 123
 				break;
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
 	* Convert the schedule frequency from the admin settings into seconds
142 142
 	*
143 143
 	*/
144
-	public function get_schedule_frequency_seconds( $name = '' ) {
144
+	public function get_schedule_frequency_seconds($name = '') {
145 145
 
146
-		$schedule_number = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_number', '' );
147
-		$schedule_unit   = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_unit', '' );
146
+		$schedule_number = get_option('object_sync_for_salesforce_' . $name . '_schedule_number', '');
147
+		$schedule_unit   = get_option('object_sync_for_salesforce_' . $name . '_schedule_unit', '');
148 148
 
149
-		switch ( $schedule_unit ) {
149
+		switch ($schedule_unit) {
150 150
 			case 'minutes':
151 151
 				$seconds = 60;
152 152
 				break;
@@ -172,18 +172,18 @@  discard block
 block discarded – undo
172 172
 	 *
173 173
 	 * @return void
174 174
 	 */
175
-	public function use_schedule( $name = '' ) {
175
+	public function use_schedule($name = '') {
176 176
 
177
-		if ( '' !== $name ) {
177
+		if ('' !== $name) {
178 178
 			$schedule_name = $name;
179 179
 		} else {
180 180
 			$schedule_name = $this->schedule_name;
181 181
 		}
182 182
 
183
-		$schedule_frequency = $this->get_schedule_frequency_key( $name );
183
+		$schedule_frequency = $this->get_schedule_frequency_key($name);
184 184
 
185
-		if ( ! wp_next_scheduled( $schedule_name ) ) {
186
-			wp_schedule_event( time(), $schedule_frequency, $schedule_name );
185
+		if ( ! wp_next_scheduled($schedule_name)) {
186
+			wp_schedule_event(time(), $schedule_frequency, $schedule_name);
187 187
 		}
188 188
 
189 189
 	}
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 	 *
201 201
 	 * @return mixed
202 202
 	 */
203
-	protected function task( $data ) {
204
-		if ( is_array( $this->schedulable_classes[ $this->schedule_name ] ) ) {
205
-			$schedule = $this->schedulable_classes[ $this->schedule_name ];
206
-			if ( isset( $schedule['class'] ) ) {
207
-				$class  = new $schedule['class']( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes );
203
+	protected function task($data) {
204
+		if (is_array($this->schedulable_classes[$this->schedule_name])) {
205
+			$schedule = $this->schedulable_classes[$this->schedule_name];
206
+			if (isset($schedule['class'])) {
207
+				$class  = new $schedule['class']($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes);
208 208
 				$method = $schedule['callback'];
209
-				$task   = $class->$method( $data['object_type'], $data['object'], $data['mapping'], $data['sf_sync_trigger'] );
209
+				$task   = $class->$method($data['object_type'], $data['object'], $data['mapping'], $data['sf_sync_trigger']);
210 210
 			}
211 211
 		}
212 212
 		return false;
@@ -222,17 +222,17 @@  discard block
 block discarded – undo
222 222
 	 * @return $data
223 223
 	 */
224 224
 	protected function check_for_data() {
225
-		if ( is_array( $this->schedulable_classes[ $this->schedule_name ] ) ) {
226
-			$schedule = $this->schedulable_classes[ $this->schedule_name ];
227
-			if ( isset( $schedule['class'] ) ) {
228
-				$class  = new $schedule['class']( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes );
225
+		if (is_array($this->schedulable_classes[$this->schedule_name])) {
226
+			$schedule = $this->schedulable_classes[$this->schedule_name];
227
+			if (isset($schedule['class'])) {
228
+				$class  = new $schedule['class']($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes);
229 229
 				$method = $schedule['initializer'];
230 230
 				$task   = $class->$method();
231 231
 			}
232 232
 		}
233 233
 		// we have checked for data and it's in the queue if it exists
234 234
 		// now run maybe_handle again to see if it nees to be processed
235
-		$this->maybe_handle( true );
235
+		$this->maybe_handle(true);
236 236
 	}
237 237
 
238 238
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 * Checks whether data exists within the queue and that
242 242
 	 * the process is not already running.
243 243
 	 */
244
-	public function maybe_handle( $already_checked = false, $ajax = false ) {
245
-		if ( $this->is_process_running() ) {
244
+	public function maybe_handle($already_checked = false, $ajax = false) {
245
+		if ($this->is_process_running()) {
246 246
 			// Background process already running.
247 247
 			wp_die();
248 248
 		}
@@ -251,19 +251,19 @@  discard block
 block discarded – undo
251 251
 		// it should call its corresponding class method that saves data to the queue
252 252
 		// it should then run maybe_handle() again
253 253
 
254
-		$check_for_data_first = isset( $this->schedulable_classes[ $this->schedule_name ]['initializer'] ) ? true : false;
254
+		$check_for_data_first = isset($this->schedulable_classes[$this->schedule_name]['initializer']) ? true : false;
255 255
 
256
-		if ( false === $already_checked && true === $check_for_data_first ) {
256
+		if (false === $already_checked && true === $check_for_data_first) {
257 257
 			$this->check_for_data();
258 258
 		}
259 259
 
260
-		if ( $this->is_queue_empty() ) {
260
+		if ($this->is_queue_empty()) {
261 261
 			// No data to process.
262 262
 			wp_die();
263 263
 		}
264 264
 
265
-		if ( true === $ajax ) {
266
-			check_ajax_referer( $this->identifier, 'nonce' );
265
+		if (true === $ajax) {
266
+			check_ajax_referer($this->identifier, 'nonce');
267 267
 		}
268 268
 
269 269
 		$this->handle();
@@ -275,15 +275,15 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * This is modeled off the cancel_process method in wp-background-process but that one doesn't seem to work when we need to specify the queue name
277 277
 	 */
278
-	public function cancel_by_name( $name ) {
279
-		if ( ! isset( $name ) ) {
278
+	public function cancel_by_name($name) {
279
+		if ( ! isset($name)) {
280 280
 			$name = $this->identifier . '_cron';
281 281
 		}
282
-		if ( ! $this->is_queue_empty() ) {
283
-			while ( $this->count_queue_items() > 0 ) {
282
+		if ( ! $this->is_queue_empty()) {
283
+			while ($this->count_queue_items() > 0) {
284 284
 				$batch = $this->get_batch();
285
-				$this->delete( $batch->key );
286
-				wp_clear_scheduled_hook( $name );
285
+				$this->delete($batch->key);
286
+				wp_clear_scheduled_hook($name);
287 287
 			}
288 288
 		}
289 289
 	}
@@ -294,28 +294,28 @@  discard block
 block discarded – undo
294 294
 	 *
295 295
 	 * @return bool
296 296
 	 */
297
-	public function count_queue_items( $schedule_name = '' ) {
297
+	public function count_queue_items($schedule_name = '') {
298 298
 		$wpdb = $this->wpdb;
299 299
 
300 300
 		$table  = $wpdb->options;
301 301
 		$column = 'option_name';
302 302
 
303
-		if ( is_multisite() ) {
303
+		if (is_multisite()) {
304 304
 			$table  = $wpdb->sitemeta;
305 305
 			$column = 'meta_key';
306 306
 		}
307 307
 
308
-		if ( '' === $schedule_name ) {
308
+		if ('' === $schedule_name) {
309 309
 			$key = $this->identifier . '_batch_%';
310 310
 		} else {
311 311
 			$key = $schedule_name . '_batch_%';
312 312
 		}
313 313
 
314
-		$count = $wpdb->get_var( $wpdb->prepare( "
314
+		$count = $wpdb->get_var($wpdb->prepare("
315 315
 			SELECT COUNT(*)
316 316
 			FROM {$table}
317 317
 			WHERE {$column} LIKE %s
318
-		", $key ) );
318
+		", $key));
319 319
 
320 320
 		return $count;
321 321
 	}
Please login to merge, or discard this patch.
classes/salesforce_soap_partner.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@
 block discarded – undo
22 22
 	public $wsdl;
23 23
 
24 24
 	/**
25
-	* Constructor which loads the SOAP client
26
-	*
27
-	*/
25
+	 * Constructor which loads the SOAP client
26
+	 *
27
+	 */
28 28
 	public function __construct( Object_Sync_Sf_Salesforce $sfapi, $wsdl = null ) {
29 29
 		if ( ! class_exists( 'SforceBaseClient' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) {
30 30
 			require_once plugin_dir_path( __FILE__ ) . '../vendor/developerforce/force.com-toolkit-for-php/soapclient/SforcePartnerClient.php';
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 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
 
@@ -25,33 +25,33 @@  discard block
 block discarded – undo
25 25
 	* Constructor which loads the SOAP client
26 26
 	*
27 27
 	*/
28
-	public function __construct( Object_Sync_Sf_Salesforce $sfapi, $wsdl = null ) {
29
-		if ( ! class_exists( 'SforceBaseClient' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) {
30
-			require_once plugin_dir_path( __FILE__ ) . '../vendor/developerforce/force.com-toolkit-for-php/soapclient/SforcePartnerClient.php';
28
+	public function __construct(Object_Sync_Sf_Salesforce $sfapi, $wsdl = null) {
29
+		if ( ! class_exists('SforceBaseClient') && file_exists(plugin_dir_path(__FILE__) . '../vendor/autoload.php')) {
30
+			require_once plugin_dir_path(__FILE__) . '../vendor/developerforce/force.com-toolkit-for-php/soapclient/SforcePartnerClient.php';
31 31
 		}
32 32
 		parent::__construct();
33
-		if ( empty( $wsdl ) ) {
34
-			$wsdl = plugin_dir_path( __FILE__ ) . '../vendor/developerforce/force.com-toolkit-for-php/soapclient/partner.wsdl.xml';
33
+		if (empty($wsdl)) {
34
+			$wsdl = plugin_dir_path(__FILE__) . '../vendor/developerforce/force.com-toolkit-for-php/soapclient/partner.wsdl.xml';
35 35
 		}
36
-		$this->set_authorized( false );
37
-		$this->createConnection( $wsdl );
36
+		$this->set_authorized(false);
37
+		$this->createConnection($wsdl);
38 38
 		$this->salesforce_api = $sfapi;
39 39
 
40
-		if ( $this->salesforce_api->is_authorized() ) {
40
+		if ($this->salesforce_api->is_authorized()) {
41 41
 			$token = $this->salesforce_api->get_access_token();
42
-			if ( ! $token ) {
42
+			if ( ! $token) {
43 43
 				$token = $this->salesforce_api->refresh_token();
44 44
 			}
45
-			$this->setSessionHeader( $token );
46
-			$this->setEndPoint( $this->salesforce_api->get_api_endpoint( 'partner' ) );
47
-			$this->set_authorized( true );
45
+			$this->setSessionHeader($token);
46
+			$this->setEndPoint($this->salesforce_api->get_api_endpoint('partner'));
47
+			$this->set_authorized(true);
48 48
 		} else {
49
-			error_log( 'salesforce is not authorized so we cannot use soap' );
50
-			$this->set_authorized( false );
49
+			error_log('salesforce is not authorized so we cannot use soap');
50
+			$this->set_authorized(false);
51 51
 		}
52 52
 	}
53 53
 
54
-	protected function set_authorized( $is_authorized ) {
54
+	protected function set_authorized($is_authorized) {
55 55
 		$this->is_authorized = $is_authorized;
56 56
 	}
57 57
 
@@ -59,35 +59,35 @@  discard block
 block discarded – undo
59 59
 		return $this->is_authorized;
60 60
 	}
61 61
 
62
-	public function try_soap( $function ) {
62
+	public function try_soap($function) {
63 63
 		$args = func_get_args();
64
-		array_shift( $args );
64
+		array_shift($args);
65 65
 		try {
66
-			$results = call_user_func_array( array( $this, $function ), $args );
66
+			$results = call_user_func_array(array($this, $function), $args);
67 67
 			// If returned without exceptions, reset the refreshed flag.
68 68
 			$this->refreshed = false;
69 69
 			return $results;
70
-		} catch ( SoapFault $e ) {
70
+		} catch (SoapFault $e) {
71 71
 			// sf:INVALID_SESSION_ID is thrown on expired login (and other reasons).
72 72
 			// Our only recourse is to try refreshing our auth token. If we get any
73 73
 			// other exception, bubble it up.
74
-			if ( 'sf:INVALID_SESSION_ID' !== $e->faultcode ) {
74
+			if ('sf:INVALID_SESSION_ID' !== $e->faultcode) {
75 75
 				throw $e;
76 76
 			}
77 77
 
78
-			if ( ! $this->refreshed ) {
78
+			if ( ! $this->refreshed) {
79 79
 				// If we got an invalid session exception, try to refresh the auth
80 80
 				// token through REST API. The "refreshed" flag will make sure we retry
81 81
 				// only once.
82 82
 				$this->refreshed = true;
83 83
 				$this->salesforce_api->refresh_token();
84
-				return $this->trySoap( $function, $args );
84
+				return $this->trySoap($function, $args);
85 85
 			}
86 86
 
87 87
 			// If we've already tried a refresh, this refresh token is probably
88 88
 			// invalid. Kill it, log, and bubble the exception.
89
-			$this->set_authorized( false );
90
-			error_log( 'website is not authorized to connect to salesforce. visit authorize page.' );
89
+			$this->set_authorized(false);
90
+			error_log('website is not authorized to connect to salesforce. visit authorize page.');
91 91
 			throw $e;
92 92
 
93 93
 		}
Please login to merge, or discard this patch.
classes/salesforce.php 2 patches
Indentation   +406 added lines, -406 removed lines patch added patch discarded remove patch
@@ -17,31 +17,31 @@  discard block
 block discarded – undo
17 17
 	public $response;
18 18
 
19 19
 	/**
20
-	* Constructor which initializes the Salesforce APIs.
21
-	*
22
-	* @param string $consumer_key
23
-	*   Salesforce key to connect to your Salesforce instance.
24
-	* @param string $consumer_secret
25
-	*   Salesforce secret to connect to your Salesforce instance.
26
-	* @param string $login_url
27
-	*   Login URL for Salesforce auth requests - differs for production and sandbox
28
-	* @param string $callback_url
29
-	*   WordPress URL where Salesforce should send you after authentication
30
-	* @param string $authorize_path
31
-	*   Oauth path that Salesforce wants
32
-	* @param string $token_path
33
-	*   Path Salesforce uses to give you a token
34
-	* @param string $rest_api_version
35
-	*   What version of the Salesforce REST API to use
36
-	* @param object $wordpress
37
-	*   Object for doing things to WordPress - retrieving data, cache, etc.
38
-	* @param string $slug
39
-	*   Slug for this plugin. Can be used for file including, especially
40
-	* @param object $logging
41
-	*   Logging object for this plugin.
42
-	* @param array $schedulable_classes
43
-	*   array of classes that can have scheduled tasks specific to them
44
-	*/
20
+	 * Constructor which initializes the Salesforce APIs.
21
+	 *
22
+	 * @param string $consumer_key
23
+	 *   Salesforce key to connect to your Salesforce instance.
24
+	 * @param string $consumer_secret
25
+	 *   Salesforce secret to connect to your Salesforce instance.
26
+	 * @param string $login_url
27
+	 *   Login URL for Salesforce auth requests - differs for production and sandbox
28
+	 * @param string $callback_url
29
+	 *   WordPress URL where Salesforce should send you after authentication
30
+	 * @param string $authorize_path
31
+	 *   Oauth path that Salesforce wants
32
+	 * @param string $token_path
33
+	 *   Path Salesforce uses to give you a token
34
+	 * @param string $rest_api_version
35
+	 *   What version of the Salesforce REST API to use
36
+	 * @param object $wordpress
37
+	 *   Object for doing things to WordPress - retrieving data, cache, etc.
38
+	 * @param string $slug
39
+	 *   Slug for this plugin. Can be used for file including, especially
40
+	 * @param object $logging
41
+	 *   Logging object for this plugin.
42
+	 * @param array $schedulable_classes
43
+	 *   array of classes that can have scheduled tasks specific to them
44
+	 */
45 45
 	public function __construct( $consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $logging, $schedulable_classes ) {
46 46
 		$this->consumer_key        = $consumer_key;
47 47
 		$this->consumer_secret     = $consumer_secret;
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 	}
71 71
 
72 72
 	/**
73
-	* Converts a 15-character case-sensitive Salesforce ID to 18-character
74
-	* case-insensitive ID. If input is not 15-characters, return input unaltered.
75
-	*
76
-	* @param string $sf_id_15
77
-	*   15-character case-sensitive Salesforce ID
78
-	* @return string
79
-	*   18-character case-insensitive Salesforce ID
80
-	*/
73
+	 * Converts a 15-character case-sensitive Salesforce ID to 18-character
74
+	 * case-insensitive ID. If input is not 15-characters, return input unaltered.
75
+	 *
76
+	 * @param string $sf_id_15
77
+	 *   15-character case-sensitive Salesforce ID
78
+	 * @return string
79
+	 *   18-character case-insensitive Salesforce ID
80
+	 */
81 81
 	public static function convert_id( $sf_id_15 ) {
82 82
 		if ( strlen( $sf_id_15 ) !== 15 ) {
83 83
 			return $sf_id_15;
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 
99 99
 	/**
100
-	* Given a Salesforce ID, return the corresponding SObject name. (Based on
101
-	*  keyPrefix from object definition, @see
102
-	*  https://developer.salesforce.com/forums/?id=906F0000000901ZIAQ )
103
-	*
104
-	* @param string $sf_id
105
-	*   15- or 18-character Salesforce ID
106
-	* @return string
107
-	*   sObject name, e.g. "Account", "Contact", "my__Custom_Object__c" or FALSE
108
-	*   if no match could be found.
109
-	* @throws Object_Sync_Sf_Exception
110
-	*/
100
+	 * Given a Salesforce ID, return the corresponding SObject name. (Based on
101
+	 *  keyPrefix from object definition, @see
102
+	 *  https://developer.salesforce.com/forums/?id=906F0000000901ZIAQ )
103
+	 *
104
+	 * @param string $sf_id
105
+	 *   15- or 18-character Salesforce ID
106
+	 * @return string
107
+	 *   sObject name, e.g. "Account", "Contact", "my__Custom_Object__c" or FALSE
108
+	 *   if no match could be found.
109
+	 * @throws Object_Sync_Sf_Exception
110
+	 */
111 111
 	public function get_sobject_type( $sf_id ) {
112 112
 		$objects = $this->objects(
113 113
 			array(
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
 	}
125 125
 
126 126
 	/**
127
-	* Determine if this SF instance is fully configured.
128
-	*
129
-	*/
127
+	 * Determine if this SF instance is fully configured.
128
+	 *
129
+	 */
130 130
 	public function is_authorized() {
131 131
 		return ! empty( $this->consumer_key ) && ! empty( $this->consumer_secret ) && $this->get_refresh_token();
132 132
 	}
133 133
 
134 134
 	/**
135
-	* Get REST API versions available on this Salesforce organization
136
-	* This is not an authenticated call, so it would not be a helpful test
137
-	*/
135
+	 * Get REST API versions available on this Salesforce organization
136
+	 * This is not an authenticated call, so it would not be a helpful test
137
+	 */
138 138
 	public function get_api_versions() {
139 139
 		$options = array(
140 140
 			'authenticated' => false,
@@ -144,26 +144,26 @@  discard block
 block discarded – undo
144 144
 	}
145 145
 
146 146
 	/**
147
-	* Make a call to the Salesforce REST API.
148
-	*
149
-	* @param string $path
150
-	*   Path to resource.
151
-	* @param array $params
152
-	*   Parameters to provide.
153
-	* @param string $method
154
-	*   Method to initiate the call, such as GET or POST. Defaults to GET.
155
-	* @param array $options
156
-	*   Any method can supply options for the API call, and they'll be preserved as far as the curl request
157
-	*   They get merged with the class options
158
-	* @param string $type
159
-	*   Type of call. Defaults to 'rest' - currently we don't support other types.
160
-	*   Other exammple in Drupal is 'apexrest'
161
-	*
162
-	* @return mixed
163
-	*   The requested response.
164
-	*
165
-	* @throws Object_Sync_Sf_Exception
166
-	*/
147
+	 * Make a call to the Salesforce REST API.
148
+	 *
149
+	 * @param string $path
150
+	 *   Path to resource.
151
+	 * @param array $params
152
+	 *   Parameters to provide.
153
+	 * @param string $method
154
+	 *   Method to initiate the call, such as GET or POST. Defaults to GET.
155
+	 * @param array $options
156
+	 *   Any method can supply options for the API call, and they'll be preserved as far as the curl request
157
+	 *   They get merged with the class options
158
+	 * @param string $type
159
+	 *   Type of call. Defaults to 'rest' - currently we don't support other types.
160
+	 *   Other exammple in Drupal is 'apexrest'
161
+	 *
162
+	 * @return mixed
163
+	 *   The requested response.
164
+	 *
165
+	 * @throws Object_Sync_Sf_Exception
166
+	 */
167 167
 	public function api_call( $path, $params = array(), $method = 'GET', $options = array(), $type = 'rest' ) {
168 168
 		if ( ! $this->get_access_token() ) {
169 169
 			$this->refresh_token();
@@ -214,25 +214,25 @@  discard block
 block discarded – undo
214 214
 	}
215 215
 
216 216
 	/**
217
-	* Private helper to issue an SF API request.
218
-	* This method is the only place where we read to or write from the cache
219
-	*
220
-	* @param string $path
221
-	*   Path to resource.
222
-	* @param array $params
223
-	*   Parameters to provide.
224
-	* @param string $method
225
-	*   Method to initiate the call, such as GET or POST.  Defaults to GET.
226
-	* @param array $options
227
-	*   This is the options array from the api_call method
228
-	*   This is where it gets merged with $this->options
229
-	* @param string $type
230
-	*   Type of call. Defaults to 'rest' - currently we don't support other types
231
-	*   Other exammple in Drupal is 'apexrest'
232
-	*
233
-	* @return array
234
-	*   The requested data.
235
-	*/
217
+	 * Private helper to issue an SF API request.
218
+	 * This method is the only place where we read to or write from the cache
219
+	 *
220
+	 * @param string $path
221
+	 *   Path to resource.
222
+	 * @param array $params
223
+	 *   Parameters to provide.
224
+	 * @param string $method
225
+	 *   Method to initiate the call, such as GET or POST.  Defaults to GET.
226
+	 * @param array $options
227
+	 *   This is the options array from the api_call method
228
+	 *   This is where it gets merged with $this->options
229
+	 * @param string $type
230
+	 *   Type of call. Defaults to 'rest' - currently we don't support other types
231
+	 *   Other exammple in Drupal is 'apexrest'
232
+	 *
233
+	 * @return array
234
+	 *   The requested data.
235
+	 */
236 236
 	protected function api_http_request( $path, $params, $method, $options = array(), $type = 'rest' ) {
237 237
 		$options = array_merge( $this->options, $options ); // this will override a value in $this->options with the one in $options if there is a matching key
238 238
 		$url     = $this->get_api_endpoint( $type ) . $path;
@@ -310,22 +310,22 @@  discard block
 block discarded – undo
310 310
 	}
311 311
 
312 312
 	/**
313
-	* Make the HTTP request. Wrapper around curl().
314
-	*
315
-	* @param string $url
316
-	*   Path to make request from.
317
-	* @param array $data
318
-	*   The request body.
319
-	* @param array $headers
320
-	*   Request headers to send as name => value.
321
-	* @param string $method
322
-	*   Method to initiate the call, such as GET or POST. Defaults to GET.
323
-	* @param array $options
324
-	*   This is the options array from the api_http_request method
325
-	*
326
-	* @return array
327
-	*   Salesforce response object.
328
-	*/
313
+	 * Make the HTTP request. Wrapper around curl().
314
+	 *
315
+	 * @param string $url
316
+	 *   Path to make request from.
317
+	 * @param array $data
318
+	 *   The request body.
319
+	 * @param array $headers
320
+	 *   Request headers to send as name => value.
321
+	 * @param string $method
322
+	 *   Method to initiate the call, such as GET or POST. Defaults to GET.
323
+	 * @param array $options
324
+	 *   This is the options array from the api_http_request method
325
+	 *
326
+	 * @return array
327
+	 *   Salesforce response object.
328
+	 */
329 329
 	protected function http_request( $url, $data, $headers = array(), $method = 'GET', $options = array() ) {
330 330
 		// Build the request, including path and headers. Internal use.
331 331
 
@@ -460,14 +460,14 @@  discard block
 block discarded – undo
460 460
 	}
461 461
 
462 462
 	/**
463
-	* Get the API end point for a given type of the API.
464
-	*
465
-	* @param string $api_type
466
-	*   E.g., rest, partner, enterprise.
467
-	*
468
-	* @return string
469
-	*   Complete URL endpoint for API access.
470
-	*/
463
+	 * Get the API end point for a given type of the API.
464
+	 *
465
+	 * @param string $api_type
466
+	 *   E.g., rest, partner, enterprise.
467
+	 *
468
+	 * @return string
469
+	 *   Complete URL endpoint for API access.
470
+	 */
471 471
 	public function get_api_endpoint( $api_type = 'rest' ) {
472 472
 		// Special handling for apexrest, since it's not in the identity object.
473 473
 		if ( 'apexrest' === $api_type ) {
@@ -483,67 +483,67 @@  discard block
 block discarded – undo
483 483
 	}
484 484
 
485 485
 	/**
486
-	* Get the SF instance URL. Useful for linking to objects.
487
-	*/
486
+	 * Get the SF instance URL. Useful for linking to objects.
487
+	 */
488 488
 	public function get_instance_url() {
489 489
 		return get_option( 'object_sync_for_salesforce_instance_url', '' );
490 490
 	}
491 491
 
492 492
 	/**
493
-	* Set the SF instanc URL.
494
-	*
495
-	* @param string $url
496
-	*   URL to set.
497
-	*/
493
+	 * Set the SF instanc URL.
494
+	 *
495
+	 * @param string $url
496
+	 *   URL to set.
497
+	 */
498 498
 	protected function set_instance_url( $url ) {
499 499
 		update_option( 'object_sync_for_salesforce_instance_url', $url );
500 500
 	}
501 501
 
502 502
 	/**
503
-	* Get the access token.
504
-	*/
503
+	 * Get the access token.
504
+	 */
505 505
 	public function get_access_token() {
506 506
 		return get_option( 'object_sync_for_salesforce_access_token', '' );
507 507
 	}
508 508
 
509 509
 	/**
510
-	* Set the access token.
511
-	*
512
-	* It is stored in session.
513
-	*
514
-	* @param string $token
515
-	*   Access token from Salesforce.
516
-	*/
510
+	 * Set the access token.
511
+	 *
512
+	 * It is stored in session.
513
+	 *
514
+	 * @param string $token
515
+	 *   Access token from Salesforce.
516
+	 */
517 517
 	protected function set_access_token( $token ) {
518 518
 		update_option( 'object_sync_for_salesforce_access_token', $token );
519 519
 	}
520 520
 
521 521
 	/**
522
-	* Get refresh token.
523
-	*/
522
+	 * Get refresh token.
523
+	 */
524 524
 	protected function get_refresh_token() {
525 525
 		return get_option( 'object_sync_for_salesforce_refresh_token', '' );
526 526
 	}
527 527
 
528 528
 	/**
529
-	* Set refresh token.
530
-	*
531
-	* @param string $token
532
-	*   Refresh token from Salesforce.
533
-	*/
529
+	 * Set refresh token.
530
+	 *
531
+	 * @param string $token
532
+	 *   Refresh token from Salesforce.
533
+	 */
534 534
 	protected function set_refresh_token( $token ) {
535 535
 		update_option( 'object_sync_for_salesforce_refresh_token', $token );
536 536
 	}
537 537
 
538 538
 	/**
539
-	* Refresh access token based on the refresh token. Updates session variable.
540
-	*
541
-	* todo: figure out how to do this as part of the schedule class
542
-	* this is a scheduleable class and so we could add a method from this class to run every 24 hours, but it's unclear to me that we need it. salesforce seems to refresh itself as it needs to.
543
-	* but it could be a performance boost to do it at scheduleable intervals instead.
544
-	*
545
-	* @throws Object_Sync_Sf_Exception
546
-	*/
539
+	 * Refresh access token based on the refresh token. Updates session variable.
540
+	 *
541
+	 * todo: figure out how to do this as part of the schedule class
542
+	 * this is a scheduleable class and so we could add a method from this class to run every 24 hours, but it's unclear to me that we need it. salesforce seems to refresh itself as it needs to.
543
+	 * but it could be a performance boost to do it at scheduleable intervals instead.
544
+	 *
545
+	 * @throws Object_Sync_Sf_Exception
546
+	 */
547 547
 	protected function refresh_token() {
548 548
 		$refresh_token = $this->get_refresh_token();
549 549
 		if ( empty( $refresh_token ) ) {
@@ -590,13 +590,13 @@  discard block
 block discarded – undo
590 590
 	}
591 591
 
592 592
 	/**
593
-	* Retrieve and store the Salesforce identity given an ID url.
594
-	*
595
-	* @param string $id
596
-	*   Identity URL.
597
-	*
598
-	* @throws Object_Sync_Sf_Exception
599
-	*/
593
+	 * Retrieve and store the Salesforce identity given an ID url.
594
+	 *
595
+	 * @param string $id
596
+	 *   Identity URL.
597
+	 *
598
+	 * @throws Object_Sync_Sf_Exception
599
+	 */
600 600
 	protected function set_identity( $id ) {
601 601
 		$headers  = array(
602 602
 			'Authorization'   => 'Authorization: OAuth ' . $this->get_access_token(),
@@ -612,18 +612,18 @@  discard block
 block discarded – undo
612 612
 	}
613 613
 
614 614
 	/**
615
-	* Return the Salesforce identity, which is stored in a variable.
616
-	*
617
-	* @return array
618
-	*   Returns FALSE if no identity has been stored.
619
-	*/
615
+	 * Return the Salesforce identity, which is stored in a variable.
616
+	 *
617
+	 * @return array
618
+	 *   Returns FALSE if no identity has been stored.
619
+	 */
620 620
 	public function get_identity() {
621 621
 		return get_option( 'object_sync_for_salesforce_identity', false );
622 622
 	}
623 623
 
624 624
 	/**
625
-	* OAuth step 1: Redirect to Salesforce and request and authorization code.
626
-	*/
625
+	 * OAuth step 1: Redirect to Salesforce and request and authorization code.
626
+	 */
627 627
 	public function get_authorization_code() {
628 628
 		$url = add_query_arg(
629 629
 			array(
@@ -637,11 +637,11 @@  discard block
 block discarded – undo
637 637
 	}
638 638
 
639 639
 	/**
640
-	* OAuth step 2: Exchange an authorization code for an access token.
641
-	*
642
-	* @param string $code
643
-	*   Code from Salesforce.
644
-	*/
640
+	 * OAuth step 2: Exchange an authorization code for an access token.
641
+	 *
642
+	 * @param string $code
643
+	 *   Code from Salesforce.
644
+	 */
645 645
 	public function request_token( $code ) {
646 646
 		$data = array(
647 647
 			'code'          => $code,
@@ -686,22 +686,22 @@  discard block
 block discarded – undo
686 686
 	/* Core API calls */
687 687
 
688 688
 	/**
689
-	* Available objects and their metadata for your organization's data.
690
-	*
691
-	* @param array $conditions
692
-	*   Associative array of filters to apply to the returned objects. Filters
693
-	*   are applied after the list is returned from Salesforce.
694
-	* @param bool $reset
695
-	*   Whether to reset the cache and retrieve a fresh version from Salesforce.
696
-	*
697
-	* @return array
698
-	*   Available objects and metadata.
699
-	*
700
-	* part of core API calls. this call does require authentication, and the basic url it becomes is like this:
701
-	* https://instance.salesforce.com/services/data/v#.0/sobjects
702
-	*
703
-	* updateable is really how the api spells it
704
-	*/
689
+	 * Available objects and their metadata for your organization's data.
690
+	 *
691
+	 * @param array $conditions
692
+	 *   Associative array of filters to apply to the returned objects. Filters
693
+	 *   are applied after the list is returned from Salesforce.
694
+	 * @param bool $reset
695
+	 *   Whether to reset the cache and retrieve a fresh version from Salesforce.
696
+	 *
697
+	 * @return array
698
+	 *   Available objects and metadata.
699
+	 *
700
+	 * part of core API calls. this call does require authentication, and the basic url it becomes is like this:
701
+	 * https://instance.salesforce.com/services/data/v#.0/sobjects
702
+	 *
703
+	 * updateable is really how the api spells it
704
+	 */
705 705
 	public function objects(
706 706
 		$conditions = array(
707 707
 			'updateable'  => true,
@@ -731,22 +731,22 @@  discard block
 block discarded – undo
731 731
 	}
732 732
 
733 733
 	/**
734
-	* Use SOQL to get objects based on query string.
735
-	*
736
-	* @param string $query
737
-	*   The SOQL query.
738
-	* @param array $options
739
-	*   Allow for the query to have options based on what the user needs from it, ie caching, read/write, etc.
740
-	* @param boolean $all
741
-	*   Whether this should get all results for the query
742
-	* @param boolean $explain
743
-	*   If set, Salesforce will return feedback on the query performance
744
-	*
745
-	* @return array
746
-	*   Array of Salesforce objects that match the query.
747
-	*
748
-	* part of core API calls
749
-	*/
734
+	 * Use SOQL to get objects based on query string.
735
+	 *
736
+	 * @param string $query
737
+	 *   The SOQL query.
738
+	 * @param array $options
739
+	 *   Allow for the query to have options based on what the user needs from it, ie caching, read/write, etc.
740
+	 * @param boolean $all
741
+	 *   Whether this should get all results for the query
742
+	 * @param boolean $explain
743
+	 *   If set, Salesforce will return feedback on the query performance
744
+	 *
745
+	 * @return array
746
+	 *   Array of Salesforce objects that match the query.
747
+	 *
748
+	 * part of core API calls
749
+	 */
750 750
 	public function query( $query, $options = array(), $all = false, $explain = false ) {
751 751
 		$search_data = [
752 752
 			'q' => (string) $query,
@@ -766,19 +766,19 @@  discard block
 block discarded – undo
766 766
 	}
767 767
 
768 768
 	/**
769
-	* Retrieve all the metadata for an object.
770
-	*
771
-	* @param string $name
772
-	*   Object type name, E.g., Contact, Account, etc.
773
-	* @param bool $reset
774
-	*   Whether to reset the cache and retrieve a fresh version from Salesforce.
775
-	*
776
-	* @return array
777
-	*   All the metadata for an object, including information about each field,
778
-	*   URLs, and child relationships.
779
-	*
780
-	* part of core API calls
781
-	*/
769
+	 * Retrieve all the metadata for an object.
770
+	 *
771
+	 * @param string $name
772
+	 *   Object type name, E.g., Contact, Account, etc.
773
+	 * @param bool $reset
774
+	 *   Whether to reset the cache and retrieve a fresh version from Salesforce.
775
+	 *
776
+	 * @return array
777
+	 *   All the metadata for an object, including information about each field,
778
+	 *   URLs, and child relationships.
779
+	 *
780
+	 * part of core API calls
781
+	 */
782 782
 	public function object_describe( $name, $reset = false ) {
783 783
 		if ( empty( $name ) ) {
784 784
 			return array();
@@ -806,26 +806,26 @@  discard block
 block discarded – undo
806 806
 	}
807 807
 
808 808
 	/**
809
-	* Create a new object of the given type.
810
-	*
811
-	* @param string $name
812
-	*   Object type name, E.g., Contact, Account, etc.
813
-	* @param array $params
814
-	*   Values of the fields to set for the object.
815
-	*
816
-	* @return array
817
-	*   json: {"id":"00190000001pPvHAAU","success":true,"errors":[]}
818
-	*   code: 201
819
-	*   data:
820
-	*     "id" : "00190000001pPvHAAU",
821
-	*     "success" : true
822
-	*     "errors" : [ ],
823
-	*   from_cache:
824
-	*   cached:
825
-	*   is_redo:
826
-	*
827
-	* part of core API calls
828
-	*/
809
+	 * Create a new object of the given type.
810
+	 *
811
+	 * @param string $name
812
+	 *   Object type name, E.g., Contact, Account, etc.
813
+	 * @param array $params
814
+	 *   Values of the fields to set for the object.
815
+	 *
816
+	 * @return array
817
+	 *   json: {"id":"00190000001pPvHAAU","success":true,"errors":[]}
818
+	 *   code: 201
819
+	 *   data:
820
+	 *     "id" : "00190000001pPvHAAU",
821
+	 *     "success" : true
822
+	 *     "errors" : [ ],
823
+	 *   from_cache:
824
+	 *   cached:
825
+	 *   is_redo:
826
+	 *
827
+	 * part of core API calls
828
+	 */
829 829
 	public function object_create( $name, $params ) {
830 830
 		$options = array(
831 831
 			'type' => 'write',
@@ -835,34 +835,34 @@  discard block
 block discarded – undo
835 835
 	}
836 836
 
837 837
 	/**
838
-	* Create new records or update existing records.
839
-	*
840
-	* The new records or updated records are based on the value of the specified
841
-	* field.  If the value is not unique, REST API returns a 300 response with
842
-	* the list of matching records.
843
-	*
844
-	* @param string $name
845
-	*   Object type name, E.g., Contact, Account.
846
-	* @param string $key
847
-	*   The field to check if this record should be created or updated.
848
-	* @param string $value
849
-	*   The value for this record of the field specified for $key.
850
-	* @param array $params
851
-	*   Values of the fields to set for the object.
852
-	*
853
-	* @return array
854
-	*   json: {"id":"00190000001pPvHAAU","success":true,"errors":[]}
855
-	*   code: 201
856
-	*   data:
857
-	*     "id" : "00190000001pPvHAAU",
858
-	*     "success" : true
859
-	*     "errors" : [ ],
860
-	*   from_cache:
861
-	*   cached:
862
-	*   is_redo:
863
-	*
864
-	* part of core API calls
865
-	*/
838
+	 * Create new records or update existing records.
839
+	 *
840
+	 * The new records or updated records are based on the value of the specified
841
+	 * field.  If the value is not unique, REST API returns a 300 response with
842
+	 * the list of matching records.
843
+	 *
844
+	 * @param string $name
845
+	 *   Object type name, E.g., Contact, Account.
846
+	 * @param string $key
847
+	 *   The field to check if this record should be created or updated.
848
+	 * @param string $value
849
+	 *   The value for this record of the field specified for $key.
850
+	 * @param array $params
851
+	 *   Values of the fields to set for the object.
852
+	 *
853
+	 * @return array
854
+	 *   json: {"id":"00190000001pPvHAAU","success":true,"errors":[]}
855
+	 *   code: 201
856
+	 *   data:
857
+	 *     "id" : "00190000001pPvHAAU",
858
+	 *     "success" : true
859
+	 *     "errors" : [ ],
860
+	 *   from_cache:
861
+	 *   cached:
862
+	 *   is_redo:
863
+	 *
864
+	 * part of core API calls
865
+	 */
866 866
 	public function object_upsert( $name, $key, $value, $params ) {
867 867
 		$options = array(
868 868
 			'type' => 'write',
@@ -884,27 +884,27 @@  discard block
 block discarded – undo
884 884
 	}
885 885
 
886 886
 	/**
887
-	* Update an existing object.
888
-	*
889
-	* @param string $name
890
-	*   Object type name, E.g., Contact, Account.
891
-	* @param string $id
892
-	*   Salesforce id of the object.
893
-	* @param array $params
894
-	*   Values of the fields to set for the object.
895
-	*
896
-	* part of core API calls
897
-	*
898
-	* @return array
899
-	*   json: {"success":true,"body":""}
900
-	*   code: 204
901
-	*   data:
887
+	 * Update an existing object.
888
+	 *
889
+	 * @param string $name
890
+	 *   Object type name, E.g., Contact, Account.
891
+	 * @param string $id
892
+	 *   Salesforce id of the object.
893
+	 * @param array $params
894
+	 *   Values of the fields to set for the object.
895
+	 *
896
+	 * part of core API calls
897
+	 *
898
+	 * @return array
899
+	 *   json: {"success":true,"body":""}
900
+	 *   code: 204
901
+	 *   data:
902 902
 		success: 1
903 903
 		body:
904
-	*   from_cache:
905
-	*   cached:
906
-	*   is_redo:
907
-	*/
904
+	 *   from_cache:
905
+	 *   cached:
906
+	 *   is_redo:
907
+	 */
908 908
 	public function object_update( $name, $id, $params ) {
909 909
 		$options = array(
910 910
 			'type' => 'write',
@@ -914,62 +914,62 @@  discard block
 block discarded – undo
914 914
 	}
915 915
 
916 916
 	/**
917
-	* Return a full loaded Salesforce object.
918
-	*
919
-	* @param string $name
920
-	*   Object type name, E.g., Contact, Account.
921
-	* @param string $id
922
-	*   Salesforce id of the object.
923
-	*
924
-	* @return object
925
-	*   Object of the requested Salesforce object.
926
-	*
927
-	* part of core API calls
928
-	*/
917
+	 * Return a full loaded Salesforce object.
918
+	 *
919
+	 * @param string $name
920
+	 *   Object type name, E.g., Contact, Account.
921
+	 * @param string $id
922
+	 *   Salesforce id of the object.
923
+	 *
924
+	 * @return object
925
+	 *   Object of the requested Salesforce object.
926
+	 *
927
+	 * part of core API calls
928
+	 */
929 929
 	public function object_read( $name, $id ) {
930 930
 		return $this->api_call( "sobjects/{$name}/{$id}", array(), 'GET' );
931 931
 	}
932 932
 
933 933
 	/**
934
-	* Make a call to the Analytics API
935
-	*
936
-	* @param string $name
937
-	*   Object type name, E.g., Report
938
-	* @param string $id
939
-	*   Salesforce id of the object.
940
-	* @param string $route
941
-	*   What comes after the ID? E.g. instances, ?includeDetails=True
942
-	* @param array $params
943
-	*   Params to put with the request
944
-	* @param string $method
945
-	*   GET or POST
946
-	*
947
-	* @return object
948
-	*   Object of the requested Salesforce object.
949
-	*
950
-	* part of core API calls
951
-	*/
934
+	 * Make a call to the Analytics API
935
+	 *
936
+	 * @param string $name
937
+	 *   Object type name, E.g., Report
938
+	 * @param string $id
939
+	 *   Salesforce id of the object.
940
+	 * @param string $route
941
+	 *   What comes after the ID? E.g. instances, ?includeDetails=True
942
+	 * @param array $params
943
+	 *   Params to put with the request
944
+	 * @param string $method
945
+	 *   GET or POST
946
+	 *
947
+	 * @return object
948
+	 *   Object of the requested Salesforce object.
949
+	 *
950
+	 * part of core API calls
951
+	 */
952 952
 	public function analytics_api( $name, $id, $route = '', $params = array(), $method = 'GET' ) {
953 953
 		return $this->api_call( "analytics/{$name}/{$id}/{$route}", $params, $method );
954 954
 	}
955 955
 
956 956
 	/**
957
-	* Run a specific Analytics report
958
-	*
959
-	* @param string $id
960
-	*   Salesforce id of the object.
961
-	* @param bool $async
962
-	*   Whether the report is asynchronous
963
-	* @param array $params
964
-	*   Params to put with the request
965
-	* @param string $method
966
-	*   GET or POST
967
-	*
968
-	* @return object
969
-	*   Object of the requested Salesforce object.
970
-	*
971
-	* part of core API calls
972
-	*/
957
+	 * Run a specific Analytics report
958
+	 *
959
+	 * @param string $id
960
+	 *   Salesforce id of the object.
961
+	 * @param bool $async
962
+	 *   Whether the report is asynchronous
963
+	 * @param array $params
964
+	 *   Params to put with the request
965
+	 * @param string $method
966
+	 *   GET or POST
967
+	 *
968
+	 * @return object
969
+	 *   Object of the requested Salesforce object.
970
+	 *
971
+	 * part of core API calls
972
+	 */
973 973
 	public function run_analytics_report( $id, $async = true, $clear_cache = false, $params = array(), $method = 'GET', $report_cache_expiration = '', $cache_instance = true, $instance_cache_expiration = '' ) {
974 974
 
975 975
 		$id         = $this->convert_id( $id );
@@ -1055,36 +1055,36 @@  discard block
 block discarded – undo
1055 1055
 	}
1056 1056
 
1057 1057
 	/**
1058
-	* Return a full loaded Salesforce object from External ID.
1059
-	*
1060
-	* @param string $name
1061
-	*   Object type name, E.g., Contact, Account.
1062
-	* @param string $field
1063
-	*   Salesforce external id field name.
1064
-	* @param string $value
1065
-	*   Value of external id.
1066
-	*
1067
-	* @return object
1068
-	*   Object of the requested Salesforce object.
1069
-	*
1070
-	* part of core API calls
1071
-	*/
1058
+	 * Return a full loaded Salesforce object from External ID.
1059
+	 *
1060
+	 * @param string $name
1061
+	 *   Object type name, E.g., Contact, Account.
1062
+	 * @param string $field
1063
+	 *   Salesforce external id field name.
1064
+	 * @param string $value
1065
+	 *   Value of external id.
1066
+	 *
1067
+	 * @return object
1068
+	 *   Object of the requested Salesforce object.
1069
+	 *
1070
+	 * part of core API calls
1071
+	 */
1072 1072
 	public function object_readby_external_id( $name, $field, $value ) {
1073 1073
 		return $this->api_call( "sobjects/{$name}/{$field}/{$value}" );
1074 1074
 	}
1075 1075
 
1076 1076
 	/**
1077
-	* Delete a Salesforce object.
1078
-	*
1079
-	* @param string $name
1080
-	*   Object type name, E.g., Contact, Account.
1081
-	* @param string $id
1082
-	*   Salesforce id of the object.
1083
-	*
1084
-	* @return array
1085
-	*
1086
-	* part of core API calls
1087
-	*/
1077
+	 * Delete a Salesforce object.
1078
+	 *
1079
+	 * @param string $name
1080
+	 *   Object type name, E.g., Contact, Account.
1081
+	 * @param string $id
1082
+	 *   Salesforce id of the object.
1083
+	 *
1084
+	 * @return array
1085
+	 *
1086
+	 * part of core API calls
1087
+	 */
1088 1088
 	public function object_delete( $name, $id ) {
1089 1089
 		$options = array(
1090 1090
 			'type' => 'write',
@@ -1094,17 +1094,17 @@  discard block
 block discarded – undo
1094 1094
 	}
1095 1095
 
1096 1096
 	/**
1097
-	* Retrieves the list of individual objects that have been deleted within the
1098
-	* given timespan for a specified object type.
1099
-	*
1100
-	* @param string $type
1101
-	*   Object type name, E.g., Contact, Account.
1102
-	* @param string $startDate
1103
-	*   Start date to check for deleted objects (in ISO 8601 format).
1104
-	* @param string $endDate
1105
-	*   End date to check for deleted objects (in ISO 8601 format).
1106
-	* @return GetDeletedResult
1107
-	*/
1097
+	 * Retrieves the list of individual objects that have been deleted within the
1098
+	 * given timespan for a specified object type.
1099
+	 *
1100
+	 * @param string $type
1101
+	 *   Object type name, E.g., Contact, Account.
1102
+	 * @param string $startDate
1103
+	 *   Start date to check for deleted objects (in ISO 8601 format).
1104
+	 * @param string $endDate
1105
+	 *   End date to check for deleted objects (in ISO 8601 format).
1106
+	 * @return GetDeletedResult
1107
+	 */
1108 1108
 	public function get_deleted( $type, $start_date, $end_date ) {
1109 1109
 		$options = array(
1110 1110
 			'cache' => false,
@@ -1114,13 +1114,13 @@  discard block
 block discarded – undo
1114 1114
 
1115 1115
 
1116 1116
 	/**
1117
-	* Return a list of available resources for the configured API version.
1118
-	*
1119
-	* @return array
1120
-	*   Associative array keyed by name with a URI value.
1121
-	*
1122
-	* part of core API calls
1123
-	*/
1117
+	 * Return a list of available resources for the configured API version.
1118
+	 *
1119
+	 * @return array
1120
+	 *   Associative array keyed by name with a URI value.
1121
+	 *
1122
+	 * part of core API calls
1123
+	 */
1124 1124
 	public function list_resources() {
1125 1125
 		$resources = $this->api_call( '' );
1126 1126
 		foreach ( $resources as $key => $path ) {
@@ -1130,31 +1130,31 @@  discard block
 block discarded – undo
1130 1130
 	}
1131 1131
 
1132 1132
 	/**
1133
-	* Return a list of SFIDs for the given object, which have been created or
1134
-	* updated in the given timeframe.
1135
-	*
1136
-	* @param string $type
1137
-	*   Object type name, E.g., Contact, Account.
1138
-	*
1139
-	* @param int $start
1140
-	*   unix timestamp for older timeframe for updates.
1141
-	*   Defaults to "-29 days" if empty.
1142
-	*
1143
-	* @param int $end
1144
-	*   unix timestamp for end of timeframe for updates.
1145
-	*   Defaults to now if empty
1146
-	*
1147
-	* @return array
1148
-	*   return array has 2 indexes:
1149
-	*     "ids": a list of SFIDs of those records which have been created or
1150
-	*       updated in the given timeframe.
1151
-	*     "latestDateCovered": ISO 8601 format timestamp (UTC) of the last date
1152
-	*       covered in the request.
1153
-	*
1154
-	* @see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_getupdated.htm
1155
-	*
1156
-	* part of core API calls
1157
-	*/
1133
+	 * Return a list of SFIDs for the given object, which have been created or
1134
+	 * updated in the given timeframe.
1135
+	 *
1136
+	 * @param string $type
1137
+	 *   Object type name, E.g., Contact, Account.
1138
+	 *
1139
+	 * @param int $start
1140
+	 *   unix timestamp for older timeframe for updates.
1141
+	 *   Defaults to "-29 days" if empty.
1142
+	 *
1143
+	 * @param int $end
1144
+	 *   unix timestamp for end of timeframe for updates.
1145
+	 *   Defaults to now if empty
1146
+	 *
1147
+	 * @return array
1148
+	 *   return array has 2 indexes:
1149
+	 *     "ids": a list of SFIDs of those records which have been created or
1150
+	 *       updated in the given timeframe.
1151
+	 *     "latestDateCovered": ISO 8601 format timestamp (UTC) of the last date
1152
+	 *       covered in the request.
1153
+	 *
1154
+	 * @see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_getupdated.htm
1155
+	 *
1156
+	 * part of core API calls
1157
+	 */
1158 1158
 	public function get_updated( $type, $start = null, $end = null ) {
1159 1159
 		if ( empty( $start ) ) {
1160 1160
 			$start = strtotime( '-29 days' );
@@ -1173,19 +1173,19 @@  discard block
 block discarded – undo
1173 1173
 	}
1174 1174
 
1175 1175
 	/**
1176
-	* Given a DeveloperName and SObject Name, return the SFID of the
1177
-	* corresponding RecordType. DeveloperName doesn't change between Salesforce
1178
-	* environments, so it's safer to rely on compared to SFID.
1179
-	*
1180
-	* @param string $name
1181
-	*   Object type name, E.g., Contact, Account.
1182
-	*
1183
-	* @param string $devname
1184
-	*   RecordType DeveloperName, e.g. Donation, Membership, etc.
1185
-	*
1186
-	* @return string SFID
1187
-	*   The Salesforce ID of the given Record Type, or null.
1188
-	*/
1176
+	 * Given a DeveloperName and SObject Name, return the SFID of the
1177
+	 * corresponding RecordType. DeveloperName doesn't change between Salesforce
1178
+	 * environments, so it's safer to rely on compared to SFID.
1179
+	 *
1180
+	 * @param string $name
1181
+	 *   Object type name, E.g., Contact, Account.
1182
+	 *
1183
+	 * @param string $devname
1184
+	 *   RecordType DeveloperName, e.g. Donation, Membership, etc.
1185
+	 *
1186
+	 * @return string SFID
1187
+	 *   The Salesforce ID of the given Record Type, or null.
1188
+	 */
1189 1189
 
1190 1190
 	public function get_record_type_id_by_developer_name( $name, $devname, $reset = false ) {
1191 1191
 
@@ -1213,10 +1213,10 @@  discard block
 block discarded – undo
1213 1213
 	}
1214 1214
 
1215 1215
 	/**
1216
-	* If there is a WordPress setting for how long to keep the cache, return it and set the object property
1217
-	* Otherwise, return seconds in 24 hours
1218
-	*
1219
-	*/
1216
+	 * If there is a WordPress setting for how long to keep the cache, return it and set the object property
1217
+	 * Otherwise, return seconds in 24 hours
1218
+	 *
1219
+	 */
1220 1220
 	private function cache_expiration() {
1221 1221
 		$cache_expiration = $this->wordpress->cache_expiration( 'object_sync_for_salesforce_cache_expiration', 86400 );
1222 1222
 		return $cache_expiration;
Please login to merge, or discard this patch.
Spacing   +232 added lines, -232 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
 	*   array of classes that can have scheduled tasks specific to them
44 44
 	*/
45
-	public function __construct( $consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $logging, $schedulable_classes ) {
45
+	public function __construct($consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $logging, $schedulable_classes) {
46 46
 		$this->consumer_key        = $consumer_key;
47 47
 		$this->consumer_secret     = $consumer_secret;
48 48
 		$this->login_url           = $login_url;
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
 			'type'             => 'read',
61 61
 		);
62 62
 
63
-		$this->success_codes              = array( 200, 201, 204 );
63
+		$this->success_codes              = array(200, 201, 204);
64 64
 		$this->refresh_code               = 401;
65 65
 		$this->success_or_refresh_codes   = $this->success_codes;
66 66
 		$this->success_or_refresh_codes[] = $this->refresh_code;
67 67
 
68
-		$this->debug = get_option( 'object_sync_for_salesforce_debug_mode', false );
68
+		$this->debug = get_option('object_sync_for_salesforce_debug_mode', false);
69 69
 
70 70
 	}
71 71
 
@@ -78,20 +78,20 @@  discard block
 block discarded – undo
78 78
 	* @return string
79 79
 	*   18-character case-insensitive Salesforce ID
80 80
 	*/
81
-	public static function convert_id( $sf_id_15 ) {
82
-		if ( strlen( $sf_id_15 ) !== 15 ) {
81
+	public static function convert_id($sf_id_15) {
82
+		if (strlen($sf_id_15) !== 15) {
83 83
 			return $sf_id_15;
84 84
 		}
85
-		$chunks = str_split( $sf_id_15, 5 );
85
+		$chunks = str_split($sf_id_15, 5);
86 86
 		$extra  = '';
87
-		foreach ( $chunks as $chunk ) {
88
-			$chars = str_split( $chunk, 1 );
87
+		foreach ($chunks as $chunk) {
88
+			$chars = str_split($chunk, 1);
89 89
 			$bits  = '';
90
-			foreach ( $chars as $char ) {
91
-				$bits .= ( ! is_numeric( $char ) && strtoupper( $char ) === $char ) ? '1' : '0';
90
+			foreach ($chars as $char) {
91
+				$bits .= ( ! is_numeric($char) && strtoupper($char) === $char) ? '1' : '0';
92 92
 			}
93 93
 			$map    = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345';
94
-			$extra .= substr( $map, base_convert( strrev( $bits ), 2, 10 ), 1 );
94
+			$extra .= substr($map, base_convert(strrev($bits), 2, 10), 1);
95 95
 		}
96 96
 		return $sf_id_15 . $extra;
97 97
 	}
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
 	*   if no match could be found.
109 109
 	* @throws Object_Sync_Sf_Exception
110 110
 	*/
111
-	public function get_sobject_type( $sf_id ) {
111
+	public function get_sobject_type($sf_id) {
112 112
 		$objects = $this->objects(
113 113
 			array(
114
-				'keyPrefix' => substr( $sf_id, 0, 3 ),
114
+				'keyPrefix' => substr($sf_id, 0, 3),
115 115
 			)
116 116
 		);
117
-		if ( 1 === count( $objects ) ) {
117
+		if (1 === count($objects)) {
118 118
 			// keyPrefix is unique across objects. If there is exactly one return value from objects(), then we have a match.
119
-			$object = reset( $objects );
119
+			$object = reset($objects);
120 120
 			return $object['name'];
121 121
 		}
122 122
 		// Otherwise, we did not find a match.
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	*
129 129
 	*/
130 130
 	public function is_authorized() {
131
-		return ! empty( $this->consumer_key ) && ! empty( $this->consumer_secret ) && $this->get_refresh_token();
131
+		return ! empty($this->consumer_key) && ! empty($this->consumer_secret) && $this->get_refresh_token();
132 132
 	}
133 133
 
134 134
 	/**
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 			'authenticated' => false,
141 141
 			'full_url'      => true,
142 142
 		);
143
-		return $this->api_call( $this->get_instance_url() . '/services/data', [], 'GET', $options );
143
+		return $this->api_call($this->get_instance_url() . '/services/data', [], 'GET', $options);
144 144
 	}
145 145
 
146 146
 	/**
@@ -164,50 +164,50 @@  discard block
 block discarded – undo
164 164
 	*
165 165
 	* @throws Object_Sync_Sf_Exception
166 166
 	*/
167
-	public function api_call( $path, $params = array(), $method = 'GET', $options = array(), $type = 'rest' ) {
168
-		if ( ! $this->get_access_token() ) {
167
+	public function api_call($path, $params = array(), $method = 'GET', $options = array(), $type = 'rest') {
168
+		if ( ! $this->get_access_token()) {
169 169
 			$this->refresh_token();
170 170
 		}
171
-		$this->response = $this->api_http_request( $path, $params, $method, $options, $type );
171
+		$this->response = $this->api_http_request($path, $params, $method, $options, $type);
172 172
 
173 173
 		// analytic calls that are expired return 404s for some absurd reason
174
-		if ( $this->response['code'] && 'run_analytics_report' === debug_backtrace()[1]['function'] ) {
174
+		if ($this->response['code'] && 'run_analytics_report' === debug_backtrace()[1]['function']) {
175 175
 			return $this->response;
176 176
 		}
177 177
 
178
-		switch ( $this->response['code'] ) {
178
+		switch ($this->response['code']) {
179 179
 			// The session ID or OAuth token used has expired or is invalid.
180 180
 			case $this->response['code'] === $this->refresh_code:
181 181
 				// Refresh token.
182 182
 				$this->refresh_token();
183 183
 				// Rebuild our request and repeat request.
184 184
 				$options['is_redo'] = true;
185
-				$this->response     = $this->api_http_request( $path, $params, $method, $options, $type );
185
+				$this->response     = $this->api_http_request($path, $params, $method, $options, $type);
186 186
 				// Throw an error if we still have bad response.
187
-				if ( ! in_array( $this->response['code'], $this->success_codes, true ) ) {
188
-					throw new Object_Sync_Sf_Exception( $this->response['data'][0]['message'], $this->response['code'] );
187
+				if ( ! in_array($this->response['code'], $this->success_codes, true)) {
188
+					throw new Object_Sync_Sf_Exception($this->response['data'][0]['message'], $this->response['code']);
189 189
 				}
190 190
 				break;
191
-			case in_array( $this->response['code'], $this->success_codes, true ):
191
+			case in_array($this->response['code'], $this->success_codes, true):
192 192
 				// All clear.
193 193
 				break;
194 194
 			default:
195 195
 				// We have problem and no specific Salesforce error provided.
196
-				if ( empty( $this->response['data'] ) ) {
197
-					throw new Object_Sync_Sf_Exception( $this->response['error'], $this->response['code'] );
196
+				if (empty($this->response['data'])) {
197
+					throw new Object_Sync_Sf_Exception($this->response['error'], $this->response['code']);
198 198
 				}
199 199
 		}
200 200
 
201
-		if ( ! empty( $this->response['data'][0] ) && 1 === count( $this->response['data'] ) ) {
201
+		if ( ! empty($this->response['data'][0]) && 1 === count($this->response['data'])) {
202 202
 			$this->response['data'] = $this->response['data'][0];
203 203
 		}
204 204
 
205
-		if ( isset( $this->response['data']['error'] ) ) {
206
-			throw new Object_Sync_Sf_Exception( $this->response['data']['error_description'], $this->response['data']['error'] );
205
+		if (isset($this->response['data']['error'])) {
206
+			throw new Object_Sync_Sf_Exception($this->response['data']['error_description'], $this->response['data']['error']);
207 207
 		}
208 208
 
209
-		if ( ! empty( $this->response['data']['errorCode'] ) ) {
210
-			throw new Object_Sync_Sf_Exception( $this->response['data']['message'], $this->response['code'] );
209
+		if ( ! empty($this->response['data']['errorCode'])) {
210
+			throw new Object_Sync_Sf_Exception($this->response['data']['message'], $this->response['code']);
211 211
 		}
212 212
 
213 213
 		return $this->response;
@@ -233,73 +233,73 @@  discard block
 block discarded – undo
233 233
 	* @return array
234 234
 	*   The requested data.
235 235
 	*/
236
-	protected function api_http_request( $path, $params, $method, $options = array(), $type = 'rest' ) {
237
-		$options = array_merge( $this->options, $options ); // this will override a value in $this->options with the one in $options if there is a matching key
238
-		$url     = $this->get_api_endpoint( $type ) . $path;
239
-		if ( isset( $options['full_url'] ) && true === $options['full_url'] ) {
236
+	protected function api_http_request($path, $params, $method, $options = array(), $type = 'rest') {
237
+		$options = array_merge($this->options, $options); // this will override a value in $this->options with the one in $options if there is a matching key
238
+		$url     = $this->get_api_endpoint($type) . $path;
239
+		if (isset($options['full_url']) && true === $options['full_url']) {
240 240
 			$url = $path;
241 241
 		}
242 242
 		$headers = array(
243 243
 			'Authorization'   => 'Authorization: OAuth ' . $this->get_access_token(),
244 244
 			'Accept-Encoding' => 'Accept-Encoding: gzip, deflate',
245 245
 		);
246
-		if ( 'POST' === $method || 'PATCH' === $method ) {
246
+		if ('POST' === $method || 'PATCH' === $method) {
247 247
 			$headers['Content-Type'] = 'Content-Type: application/json';
248 248
 		}
249
-		if ( isset( $options['authenticated'] ) && true === $options['authenticated'] ) {
249
+		if (isset($options['authenticated']) && true === $options['authenticated']) {
250 250
 			$headers = false;
251 251
 		}
252 252
 		// if this request should be cached, see if it already exists
253 253
 		// if it is already cached, load it. if not, load it and then cache it if it should be cached
254 254
 		// add parameters to the array so we can tell if it was cached or not
255
-		if ( true === $options['cache'] && 'write' !== $options['type'] ) {
256
-			$cached = $this->wordpress->cache_get( $url, $params );
255
+		if (true === $options['cache'] && 'write' !== $options['type']) {
256
+			$cached = $this->wordpress->cache_get($url, $params);
257 257
 			// some api calls can send a reset option, in which case we should redo the request anyway
258
-			if ( is_array( $cached ) && ( ! isset( $options['reset'] ) || true !== $options['reset'] ) ) {
258
+			if (is_array($cached) && ( ! isset($options['reset']) || true !== $options['reset'])) {
259 259
 				$result               = $cached;
260 260
 				$result['from_cache'] = true;
261 261
 				$result['cached']     = true;
262 262
 			} else {
263
-				$data   = wp_json_encode( $params );
264
-				$result = $this->http_request( $url, $data, $headers, $method, $options );
265
-				if ( in_array( $result['code'], $this->success_codes, true ) ) {
266
-					$result['cached'] = $this->wordpress->cache_set( $url, $params, $result, $options['cache_expiration'] );
263
+				$data   = wp_json_encode($params);
264
+				$result = $this->http_request($url, $data, $headers, $method, $options);
265
+				if (in_array($result['code'], $this->success_codes, true)) {
266
+					$result['cached'] = $this->wordpress->cache_set($url, $params, $result, $options['cache_expiration']);
267 267
 				} else {
268 268
 					$result['cached'] = false;
269 269
 				}
270 270
 				$result['from_cache'] = false;
271 271
 			}
272 272
 		} else {
273
-			$data                 = wp_json_encode( $params );
274
-			$result               = $this->http_request( $url, $data, $headers, $method, $options );
273
+			$data                 = wp_json_encode($params);
274
+			$result               = $this->http_request($url, $data, $headers, $method, $options);
275 275
 			$result['from_cache'] = false;
276 276
 			$result['cached']     = false;
277 277
 		}
278 278
 
279
-		if ( isset( $options['is_redo'] ) && true === $options['is_redo'] ) {
279
+		if (isset($options['is_redo']) && true === $options['is_redo']) {
280 280
 			$result['is_redo'] = true;
281 281
 		} else {
282 282
 			$result['is_redo'] = false;
283 283
 		}
284 284
 
285 285
 		// it would be very unfortunate to ever have to do this in a production site
286
-		if ( 1 === (int) $this->debug ) {
286
+		if (1 === (int) $this->debug) {
287 287
 			// create log entry for the api call if debug is true
288 288
 			$status = 'debug';
289
-			if ( isset( $this->logging ) ) {
289
+			if (isset($this->logging)) {
290 290
 				$logging = $this->logging;
291
-			} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
292
-				$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
291
+			} elseif (class_exists('Object_Sync_Sf_Logging')) {
292
+				$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
293 293
 			}
294 294
 
295 295
 			// translators: placeholder is the URL of the Salesforce API request
296
-			$title = sprintf( esc_html__( 'Debug: on Salesforce API HTTP Request to URL: %1$s.', 'object-sync-for-salesforce' ),
297
-				esc_url( $url )
296
+			$title = sprintf(esc_html__('Debug: on Salesforce API HTTP Request to URL: %1$s.', 'object-sync-for-salesforce'),
297
+				esc_url($url)
298 298
 			);
299 299
 
300 300
 			$logging->setup(
301 301
 				$title,
302
-				print_r( $result, true ), // log the result because we are debugging the whole api call
302
+				print_r($result, true), // log the result because we are debugging the whole api call
303 303
 				0,
304 304
 				0,
305 305
 				$status
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	* @return array
327 327
 	*   Salesforce response object.
328 328
 	*/
329
-	protected function http_request( $url, $data, $headers = array(), $method = 'GET', $options = array() ) {
329
+	protected function http_request($url, $data, $headers = array(), $method = 'GET', $options = array()) {
330 330
 		// Build the request, including path and headers. Internal use.
331 331
 
332 332
 		/*
@@ -335,60 +335,60 @@  discard block
 block discarded – undo
335 335
 		*/
336 336
 
337 337
 		$curl = curl_init();
338
-		curl_setopt( $curl, CURLOPT_URL, $url );
339
-		curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
340
-		curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
341
-		if ( false !== $headers ) {
342
-			curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
338
+		curl_setopt($curl, CURLOPT_URL, $url);
339
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
340
+		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
341
+		if (false !== $headers) {
342
+			curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
343 343
 		} else {
344
-			curl_setopt( $curl, CURLOPT_HEADER, false );
344
+			curl_setopt($curl, CURLOPT_HEADER, false);
345 345
 		}
346 346
 
347
-		if ( 'POST' === $method ) {
348
-			curl_setopt( $curl, CURLOPT_POST, true );
349
-			curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
350
-		} elseif ( 'PATCH' === $method || 'DELETE' === $method ) {
351
-			curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, $method );
352
-			curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
347
+		if ('POST' === $method) {
348
+			curl_setopt($curl, CURLOPT_POST, true);
349
+			curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
350
+		} elseif ('PATCH' === $method || 'DELETE' === $method) {
351
+			curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
352
+			curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
353 353
 		}
354
-		$json_response = curl_exec( $curl ); // this is possibly gzipped json data
355
-		$code          = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
354
+		$json_response = curl_exec($curl); // this is possibly gzipped json data
355
+		$code          = curl_getinfo($curl, CURLINFO_HTTP_CODE);
356 356
 
357
-		if ( ( 'PATCH' === $method || 'DELETE' === $method ) && '' === $json_response && 204 === $code ) {
357
+		if (('PATCH' === $method || 'DELETE' === $method) && '' === $json_response && 204 === $code) {
358 358
 			// delete and patch requests return a 204 with an empty body upon success for whatever reason
359 359
 			$data = array(
360 360
 				'success' => true,
361 361
 				'body'    => '',
362 362
 			);
363
-			curl_close( $curl );
363
+			curl_close($curl);
364 364
 			return array(
365
-				'json' => wp_json_encode( $data ),
365
+				'json' => wp_json_encode($data),
366 366
 				'code' => $code,
367 367
 				'data' => $data,
368 368
 			);
369 369
 		}
370 370
 
371
-		if ( ( ord( $json_response[0] ) == 0x1f ) && ( ord( $json_response[1] ) == 0x8b ) ) {
371
+		if ((ord($json_response[0]) == 0x1f) && (ord($json_response[1]) == 0x8b)) {
372 372
 			// skip header and ungzip the data
373
-			$json_response = gzinflate( substr( $json_response, 10 ) );
373
+			$json_response = gzinflate(substr($json_response, 10));
374 374
 		}
375
-		$data = json_decode( $json_response, true ); // decode it into an array
375
+		$data = json_decode($json_response, true); // decode it into an array
376 376
 
377 377
 		// don't use the exception if the status is a success one, or if it just needs a refresh token (salesforce uses 401 for this)
378
-		if ( ! in_array( $code, $this->success_or_refresh_codes, true ) ) {
379
-			$curl_error = curl_error( $curl );
380
-			if ( '' !== $curl_error ) {
378
+		if ( ! in_array($code, $this->success_or_refresh_codes, true)) {
379
+			$curl_error = curl_error($curl);
380
+			if ('' !== $curl_error) {
381 381
 				// create log entry for failed curl
382 382
 				$status = 'error';
383
-				if ( isset( $this->logging ) ) {
383
+				if (isset($this->logging)) {
384 384
 					$logging = $this->logging;
385
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
386
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
385
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
386
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
387 387
 				}
388 388
 
389 389
 				// translators: placeholder is the URL of the Salesforce API request
390
-				$title = sprintf( esc_html__( 'Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce' ),
391
-					esc_attr( $code )
390
+				$title = sprintf(esc_html__('Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce'),
391
+					esc_attr($code)
392 392
 				);
393 393
 
394 394
 				$logging->setup(
@@ -398,25 +398,25 @@  discard block
 block discarded – undo
398 398
 					0,
399 399
 					$status
400 400
 				);
401
-			} elseif ( isset( $data[0]['errorCode'] ) && '' !== $data[0]['errorCode'] ) { // salesforce uses this structure to return errors
401
+			} elseif (isset($data[0]['errorCode']) && '' !== $data[0]['errorCode']) { // salesforce uses this structure to return errors
402 402
 				// create log entry for failed curl
403 403
 				$status = 'error';
404
-				if ( isset( $this->logging ) ) {
404
+				if (isset($this->logging)) {
405 405
 					$logging = $this->logging;
406
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
407
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
406
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
407
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
408 408
 				}
409 409
 
410 410
 				// translators: placeholder is the server code returned by the api
411
-				$title = sprintf( esc_html__( 'Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce' ),
412
-					absint( $code )
411
+				$title = sprintf(esc_html__('Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce'),
412
+					absint($code)
413 413
 				);
414 414
 
415 415
 				// translators: placeholders are: 1) the URL requested, 2) the message returned by the error, 3) the server code returned
416
-				$body = sprintf( '<p>' . esc_html__( 'URL: %1$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Message: %2$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Code: %3$s', 'object-sync-for-salesforce' ),
417
-					esc_attr( $url ),
418
-					esc_html( $data[0]['message'] ),
419
-					absint( $code )
416
+				$body = sprintf('<p>' . esc_html__('URL: %1$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Message: %2$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Code: %3$s', 'object-sync-for-salesforce'),
417
+					esc_attr($url),
418
+					esc_html($data[0]['message']),
419
+					absint($code)
420 420
 				);
421 421
 
422 422
 				$logging->setup(
@@ -429,20 +429,20 @@  discard block
 block discarded – undo
429 429
 			} else {
430 430
 				// create log entry for failed curl
431 431
 				$status = 'error';
432
-				if ( isset( $this->logging ) ) {
432
+				if (isset($this->logging)) {
433 433
 					$logging = $this->logging;
434
-				} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
435
-					$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
434
+				} elseif (class_exists('Object_Sync_Sf_Logging')) {
435
+					$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
436 436
 				}
437 437
 
438 438
 				// translators: placeholder is the server code returned by Salesforce
439
-				$title = sprintf( esc_html__( 'Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce' ),
440
-					absint( $code )
439
+				$title = sprintf(esc_html__('Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce'),
440
+					absint($code)
441 441
 				);
442 442
 
443 443
 				$logging->setup(
444 444
 					$title,
445
-					print_r( $data, true ), // log the result because we are debugging the whole api call
445
+					print_r($data, true), // log the result because we are debugging the whole api call
446 446
 					0,
447 447
 					0,
448 448
 					$status
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 			} // End if().
451 451
 		} // End if().
452 452
 
453
-		curl_close( $curl );
453
+		curl_close($curl);
454 454
 
455 455
 		return array(
456 456
 			'json' => $json_response,
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
 	* @return string
469 469
 	*   Complete URL endpoint for API access.
470 470
 	*/
471
-	public function get_api_endpoint( $api_type = 'rest' ) {
471
+	public function get_api_endpoint($api_type = 'rest') {
472 472
 		// Special handling for apexrest, since it's not in the identity object.
473
-		if ( 'apexrest' === $api_type ) {
473
+		if ('apexrest' === $api_type) {
474 474
 			$url = $this->get_instance_url() . '/services/apexrest/';
475 475
 		} else {
476 476
 			$identity = $this->get_identity();
477
-			$url      = str_replace( '{version}', $this->rest_api_version, $identity['urls'][ $api_type ] );
478
-			if ( '' === $identity ) {
477
+			$url      = str_replace('{version}', $this->rest_api_version, $identity['urls'][$api_type]);
478
+			if ('' === $identity) {
479 479
 				$url = $this->get_instance_url() . '/services/data/v' . $this->rest_api_version . '/';
480 480
 			}
481 481
 		}
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 	* Get the SF instance URL. Useful for linking to objects.
487 487
 	*/
488 488
 	public function get_instance_url() {
489
-		return get_option( 'object_sync_for_salesforce_instance_url', '' );
489
+		return get_option('object_sync_for_salesforce_instance_url', '');
490 490
 	}
491 491
 
492 492
 	/**
@@ -495,15 +495,15 @@  discard block
 block discarded – undo
495 495
 	* @param string $url
496 496
 	*   URL to set.
497 497
 	*/
498
-	protected function set_instance_url( $url ) {
499
-		update_option( 'object_sync_for_salesforce_instance_url', $url );
498
+	protected function set_instance_url($url) {
499
+		update_option('object_sync_for_salesforce_instance_url', $url);
500 500
 	}
501 501
 
502 502
 	/**
503 503
 	* Get the access token.
504 504
 	*/
505 505
 	public function get_access_token() {
506
-		return get_option( 'object_sync_for_salesforce_access_token', '' );
506
+		return get_option('object_sync_for_salesforce_access_token', '');
507 507
 	}
508 508
 
509 509
 	/**
@@ -514,15 +514,15 @@  discard block
 block discarded – undo
514 514
 	* @param string $token
515 515
 	*   Access token from Salesforce.
516 516
 	*/
517
-	protected function set_access_token( $token ) {
518
-		update_option( 'object_sync_for_salesforce_access_token', $token );
517
+	protected function set_access_token($token) {
518
+		update_option('object_sync_for_salesforce_access_token', $token);
519 519
 	}
520 520
 
521 521
 	/**
522 522
 	* Get refresh token.
523 523
 	*/
524 524
 	protected function get_refresh_token() {
525
-		return get_option( 'object_sync_for_salesforce_refresh_token', '' );
525
+		return get_option('object_sync_for_salesforce_refresh_token', '');
526 526
 	}
527 527
 
528 528
 	/**
@@ -531,8 +531,8 @@  discard block
 block discarded – undo
531 531
 	* @param string $token
532 532
 	*   Refresh token from Salesforce.
533 533
 	*/
534
-	protected function set_refresh_token( $token ) {
535
-		update_option( 'object_sync_for_salesforce_refresh_token', $token );
534
+	protected function set_refresh_token($token) {
535
+		update_option('object_sync_for_salesforce_refresh_token', $token);
536 536
 	}
537 537
 
538 538
 	/**
@@ -546,8 +546,8 @@  discard block
 block discarded – undo
546 546
 	*/
547 547
 	protected function refresh_token() {
548 548
 		$refresh_token = $this->get_refresh_token();
549
-		if ( empty( $refresh_token ) ) {
550
-			throw new Object_Sync_Sf_Exception( esc_html__( 'There is no refresh token.', 'object-sync-for-salesforce' ) );
549
+		if (empty($refresh_token)) {
550
+			throw new Object_Sync_Sf_Exception(esc_html__('There is no refresh token.', 'object-sync-for-salesforce'));
551 551
 		}
552 552
 
553 553
 		$data = array(
@@ -565,13 +565,13 @@  discard block
 block discarded – undo
565 565
 			'Authorization'   => 'Authorization: OAuth ' . $this->get_access_token(),
566 566
 		);
567 567
 		$headers  = false;
568
-		$response = $this->http_request( $url, $data, $headers, 'POST' );
568
+		$response = $this->http_request($url, $data, $headers, 'POST');
569 569
 
570
-		if ( 200 !== $response['code'] ) {
570
+		if (200 !== $response['code']) {
571 571
 			throw new Object_Sync_Sf_Exception(
572 572
 				esc_html(
573 573
 					sprintf(
574
-						__( 'Unable to get a Salesforce access token. Salesforce returned the following errorCode: ', 'object-sync-for-salesforce' ) . $response['code']
574
+						__('Unable to get a Salesforce access token. Salesforce returned the following errorCode: ', 'object-sync-for-salesforce') . $response['code']
575 575
 					)
576 576
 				),
577 577
 				$response['code']
@@ -580,13 +580,13 @@  discard block
 block discarded – undo
580 580
 
581 581
 		$data = $response['data'];
582 582
 
583
-		if ( is_array( $data ) && isset( $data['error'] ) ) {
584
-			throw new Object_Sync_Sf_Exception( $data['error_description'], $data['error'] );
583
+		if (is_array($data) && isset($data['error'])) {
584
+			throw new Object_Sync_Sf_Exception($data['error_description'], $data['error']);
585 585
 		}
586 586
 
587
-		$this->set_access_token( $data['access_token'] );
588
-		$this->set_identity( $data['id'] );
589
-		$this->set_instance_url( $data['instance_url'] );
587
+		$this->set_access_token($data['access_token']);
588
+		$this->set_identity($data['id']);
589
+		$this->set_instance_url($data['instance_url']);
590 590
 	}
591 591
 
592 592
 	/**
@@ -597,18 +597,18 @@  discard block
 block discarded – undo
597 597
 	*
598 598
 	* @throws Object_Sync_Sf_Exception
599 599
 	*/
600
-	protected function set_identity( $id ) {
601
-		$headers  = array(
600
+	protected function set_identity($id) {
601
+		$headers = array(
602 602
 			'Authorization'   => 'Authorization: OAuth ' . $this->get_access_token(),
603 603
 			//'Content-type'  => 'application/json',
604 604
 			'Accept-Encoding' => 'Accept-Encoding: gzip, deflate',
605 605
 		);
606
-		$response = $this->http_request( $id, null, $headers );
607
-		if ( 200 !== $response['code'] ) {
608
-			throw new Object_Sync_Sf_Exception( esc_html__( 'Unable to access identity service.', 'object-sync-for-salesforce' ), $response['code'] );
606
+		$response = $this->http_request($id, null, $headers);
607
+		if (200 !== $response['code']) {
608
+			throw new Object_Sync_Sf_Exception(esc_html__('Unable to access identity service.', 'object-sync-for-salesforce'), $response['code']);
609 609
 		}
610 610
 		$data = $response['data'];
611
-		update_option( 'object_sync_for_salesforce_identity', $data );
611
+		update_option('object_sync_for_salesforce_identity', $data);
612 612
 	}
613 613
 
614 614
 	/**
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 	*   Returns FALSE if no identity has been stored.
619 619
 	*/
620 620
 	public function get_identity() {
621
-		return get_option( 'object_sync_for_salesforce_identity', false );
621
+		return get_option('object_sync_for_salesforce_identity', false);
622 622
 	}
623 623
 
624 624
 	/**
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
 	* @param string $code
643 643
 	*   Code from Salesforce.
644 644
 	*/
645
-	public function request_token( $code ) {
645
+	public function request_token($code) {
646 646
 		$data = array(
647 647
 			'code'          => $code,
648 648
 			'grant_type'    => 'authorization_code',
@@ -657,28 +657,28 @@  discard block
 block discarded – undo
657 657
 			//'Content-Type'  => 'application/x-www-form-urlencoded',
658 658
 			'Accept-Encoding' => 'Accept-Encoding: gzip, deflate',
659 659
 		);
660
-		$response = $this->http_request( $url, $data, $headers, 'POST' );
660
+		$response = $this->http_request($url, $data, $headers, 'POST');
661 661
 
662 662
 		$data = $response['data'];
663 663
 
664
-		if ( 200 !== $response['code'] ) {
665
-			$error = isset( $data['error_description'] ) ? $data['error_description'] : $response['error'];
666
-			throw new Object_Sync_Sf_Exception( $error, $response['code'] );
664
+		if (200 !== $response['code']) {
665
+			$error = isset($data['error_description']) ? $data['error_description'] : $response['error'];
666
+			throw new Object_Sync_Sf_Exception($error, $response['code']);
667 667
 		}
668 668
 
669 669
 		// Ensure all required attributes are returned. They can be omitted if the
670 670
 		// OAUTH scope is inadequate.
671
-		$required = array( 'refresh_token', 'access_token', 'id', 'instance_url' );
672
-		foreach ( $required as $key ) {
673
-			if ( ! isset( $data[ $key ] ) ) {
671
+		$required = array('refresh_token', 'access_token', 'id', 'instance_url');
672
+		foreach ($required as $key) {
673
+			if ( ! isset($data[$key])) {
674 674
 				return false;
675 675
 			}
676 676
 		}
677 677
 
678
-		$this->set_refresh_token( $data['refresh_token'] );
679
-		$this->set_access_token( $data['access_token'] );
680
-		$this->set_identity( $data['id'] );
681
-		$this->set_instance_url( $data['instance_url'] );
678
+		$this->set_refresh_token($data['refresh_token']);
679
+		$this->set_access_token($data['access_token']);
680
+		$this->set_identity($data['id']);
681
+		$this->set_instance_url($data['instance_url']);
682 682
 
683 683
 		return true;
684 684
 	}
@@ -713,19 +713,19 @@  discard block
 block discarded – undo
713 713
 		$options = array(
714 714
 			'reset' => $reset,
715 715
 		);
716
-		$result  = $this->api_call( 'sobjects', array(), 'GET', $options );
716
+		$result  = $this->api_call('sobjects', array(), 'GET', $options);
717 717
 
718
-		if ( ! empty( $conditions ) ) {
719
-			foreach ( $result['data']['sobjects'] as $key => $object ) {
720
-				foreach ( $conditions as $condition => $value ) {
721
-					if ( $object[ $condition ] !== $value ) {
722
-						unset( $result['data']['sobjects'][ $key ] );
718
+		if ( ! empty($conditions)) {
719
+			foreach ($result['data']['sobjects'] as $key => $object) {
720
+				foreach ($conditions as $condition => $value) {
721
+					if ($object[$condition] !== $value) {
722
+						unset($result['data']['sobjects'][$key]);
723 723
 					}
724 724
 				}
725 725
 			}
726 726
 		}
727 727
 
728
-		ksort( $result['data']['sobjects'] );
728
+		ksort($result['data']['sobjects']);
729 729
 
730 730
 		return $result['data']['sobjects'];
731 731
 	}
@@ -747,21 +747,21 @@  discard block
 block discarded – undo
747 747
 	*
748 748
 	* part of core API calls
749 749
 	*/
750
-	public function query( $query, $options = array(), $all = false, $explain = false ) {
750
+	public function query($query, $options = array(), $all = false, $explain = false) {
751 751
 		$search_data = [
752 752
 			'q' => (string) $query,
753 753
 		];
754
-		if ( true === $explain ) {
754
+		if (true === $explain) {
755 755
 			$search_data['explain'] = $search_data['q'];
756
-			unset( $search_data['q'] );
756
+			unset($search_data['q']);
757 757
 		}
758 758
 		// all is a search through deleted and merged data as well
759
-		if ( true === $all ) {
759
+		if (true === $all) {
760 760
 			$path = 'queryAll';
761 761
 		} else {
762 762
 			$path = 'query';
763 763
 		}
764
-		$result = $this->api_call( $path . '?' . http_build_query( $search_data ), array(), 'GET', $options );
764
+		$result = $this->api_call($path . '?' . http_build_query($search_data), array(), 'GET', $options);
765 765
 		return $result;
766 766
 	}
767 767
 
@@ -779,28 +779,28 @@  discard block
 block discarded – undo
779 779
 	*
780 780
 	* part of core API calls
781 781
 	*/
782
-	public function object_describe( $name, $reset = false ) {
783
-		if ( empty( $name ) ) {
782
+	public function object_describe($name, $reset = false) {
783
+		if (empty($name)) {
784 784
 			return array();
785 785
 		}
786 786
 		$options = array(
787 787
 			'reset' => $reset,
788 788
 		);
789
-		$object  = $this->api_call( "sobjects/{$name}/describe", array(), 'GET', $options );
789
+		$object  = $this->api_call("sobjects/{$name}/describe", array(), 'GET', $options);
790 790
 		// Sort field properties, because salesforce API always provides them in a
791 791
 		// random order. We sort them so that stored and exported data are
792 792
 		// standardized and predictable.
793 793
 		$fields = array();
794
-		foreach ( $object['data']['fields'] as &$field ) {
795
-			ksort( $field );
796
-			if ( ! empty( $field['picklistValues'] ) ) {
797
-				foreach ( $field['picklistValues'] as &$picklist_value ) {
798
-					ksort( $picklist_value );
794
+		foreach ($object['data']['fields'] as &$field) {
795
+			ksort($field);
796
+			if ( ! empty($field['picklistValues'])) {
797
+				foreach ($field['picklistValues'] as &$picklist_value) {
798
+					ksort($picklist_value);
799 799
 				}
800 800
 			}
801
-			$fields[ $field['name'] ] = $field;
801
+			$fields[$field['name']] = $field;
802 802
 		}
803
-		ksort( $fields );
803
+		ksort($fields);
804 804
 		$object['fields'] = $fields;
805 805
 		return $object;
806 806
 	}
@@ -826,11 +826,11 @@  discard block
 block discarded – undo
826 826
 	*
827 827
 	* part of core API calls
828 828
 	*/
829
-	public function object_create( $name, $params ) {
829
+	public function object_create($name, $params) {
830 830
 		$options = array(
831 831
 			'type' => 'write',
832 832
 		);
833
-		$result  = $this->api_call( "sobjects/{$name}", $params, 'POST', $options );
833
+		$result  = $this->api_call("sobjects/{$name}", $params, 'POST', $options);
834 834
 		return $result;
835 835
 	}
836 836
 
@@ -863,22 +863,22 @@  discard block
 block discarded – undo
863 863
 	*
864 864
 	* part of core API calls
865 865
 	*/
866
-	public function object_upsert( $name, $key, $value, $params ) {
866
+	public function object_upsert($name, $key, $value, $params) {
867 867
 		$options = array(
868 868
 			'type' => 'write',
869 869
 		);
870 870
 		// If key is set, remove from $params to avoid UPSERT errors.
871
-		if ( isset( $params[ $key ] ) ) {
872
-			unset( $params[ $key ] );
871
+		if (isset($params[$key])) {
872
+			unset($params[$key]);
873 873
 		}
874 874
 
875 875
 		// allow developers to change both the key and value by which objects should be matched
876
-		$key   = apply_filters( 'object_sync_for_salesforce_modify_upsert_key', $key );
877
-		$value = apply_filters( 'object_sync_for_salesforce_modify_upsert_value', $value );
876
+		$key   = apply_filters('object_sync_for_salesforce_modify_upsert_key', $key);
877
+		$value = apply_filters('object_sync_for_salesforce_modify_upsert_value', $value);
878 878
 
879
-		$data = $this->api_call( "sobjects/{$name}/{$key}/{$value}", $params, 'PATCH', $options );
880
-		if ( 300 === $this->response['code'] ) {
881
-			$data['message'] = esc_html( 'The value provided is not unique.' );
879
+		$data = $this->api_call("sobjects/{$name}/{$key}/{$value}", $params, 'PATCH', $options);
880
+		if (300 === $this->response['code']) {
881
+			$data['message'] = esc_html('The value provided is not unique.');
882 882
 		}
883 883
 		return $data;
884 884
 	}
@@ -905,11 +905,11 @@  discard block
 block discarded – undo
905 905
 	*   cached:
906 906
 	*   is_redo:
907 907
 	*/
908
-	public function object_update( $name, $id, $params ) {
908
+	public function object_update($name, $id, $params) {
909 909
 		$options = array(
910 910
 			'type' => 'write',
911 911
 		);
912
-		$result  = $this->api_call( "sobjects/{$name}/{$id}", $params, 'PATCH', $options );
912
+		$result  = $this->api_call("sobjects/{$name}/{$id}", $params, 'PATCH', $options);
913 913
 		return $result;
914 914
 	}
915 915
 
@@ -926,8 +926,8 @@  discard block
 block discarded – undo
926 926
 	*
927 927
 	* part of core API calls
928 928
 	*/
929
-	public function object_read( $name, $id ) {
930
-		return $this->api_call( "sobjects/{$name}/{$id}", array(), 'GET' );
929
+	public function object_read($name, $id) {
930
+		return $this->api_call("sobjects/{$name}/{$id}", array(), 'GET');
931 931
 	}
932 932
 
933 933
 	/**
@@ -949,8 +949,8 @@  discard block
 block discarded – undo
949 949
 	*
950 950
 	* part of core API calls
951 951
 	*/
952
-	public function analytics_api( $name, $id, $route = '', $params = array(), $method = 'GET' ) {
953
-		return $this->api_call( "analytics/{$name}/{$id}/{$route}", $params, $method );
952
+	public function analytics_api($name, $id, $route = '', $params = array(), $method = 'GET') {
953
+		return $this->api_call("analytics/{$name}/{$id}/{$route}", $params, $method);
954 954
 	}
955 955
 
956 956
 	/**
@@ -970,19 +970,19 @@  discard block
 block discarded – undo
970 970
 	*
971 971
 	* part of core API calls
972 972
 	*/
973
-	public function run_analytics_report( $id, $async = true, $clear_cache = false, $params = array(), $method = 'GET', $report_cache_expiration = '', $cache_instance = true, $instance_cache_expiration = '' ) {
973
+	public function run_analytics_report($id, $async = true, $clear_cache = false, $params = array(), $method = 'GET', $report_cache_expiration = '', $cache_instance = true, $instance_cache_expiration = '') {
974 974
 
975
-		$id         = $this->convert_id( $id );
975
+		$id         = $this->convert_id($id);
976 976
 		$report_url = 'analytics/reports/' . $id . '/' . 'instances';
977 977
 
978
-		if ( true === $clear_cache ) {
979
-			delete_transient( $report_url );
978
+		if (true === $clear_cache) {
979
+			delete_transient($report_url);
980 980
 		}
981 981
 
982
-		$instance_id = $this->wordpress->cache_get( $report_url, '' );
982
+		$instance_id = $this->wordpress->cache_get($report_url, '');
983 983
 
984 984
 		// there is no stored instance id or this is synchronous; retrieve the results for that instance
985
-		if ( false === $async || false === $instance_id ) {
985
+		if (false === $async || false === $instance_id) {
986 986
 
987 987
 			$result = $this->analytics_api(
988 988
 				'reports',
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 				'GET'
993 993
 			);
994 994
 			// if we get a reportmetadata array out of this, continue
995
-			if ( is_array( $result['data']['reportMetadata'] ) ) {
995
+			if (is_array($result['data']['reportMetadata'])) {
996 996
 				$params = array(
997 997
 					'reportMetadata' => $result['data']['reportMetadata'],
998 998
 				);
@@ -1004,48 +1004,48 @@  discard block
 block discarded – undo
1004 1004
 					'POST'
1005 1005
 				);
1006 1006
 				// if we get an id from the post, that is the instance id
1007
-				if ( isset( $report['data']['id'] ) ) {
1007
+				if (isset($report['data']['id'])) {
1008 1008
 					$instance_id = $report['data']['id'];
1009 1009
 				} else {
1010 1010
 					// run the call again if we don't have an instance id
1011 1011
 					//error_log('run report again. we have no instance id.');
1012
-					$this->run_analytics_report( $id, true );
1012
+					$this->run_analytics_report($id, true);
1013 1013
 				}
1014 1014
 
1015 1015
 				// cache the instance id so we can get the report results if they are applicable
1016
-				if ( '' === $report_cache_expiration ) {
1016
+				if ('' === $report_cache_expiration) {
1017 1017
 					$report_cache_expiration = $this->cache_expiration();
1018 1018
 				}
1019
-				$this->wordpress->cache_set( $report_url, '', $instance_id, $report_cache_expiration );
1019
+				$this->wordpress->cache_set($report_url, '', $instance_id, $report_cache_expiration);
1020 1020
 			} else {
1021 1021
 				// run the call again if we don't have a reportMetadata array
1022 1022
 				//error_log('run report again. we have no reportmetadata.');
1023
-				$this->run_analytics_report( $id, true );
1023
+				$this->run_analytics_report($id, true);
1024 1024
 			}
1025 1025
 		} // End if().
1026 1026
 
1027
-		$result = $this->api_call( $report_url . "/{$instance_id}", array(), $method );
1027
+		$result = $this->api_call($report_url . "/{$instance_id}", array(), $method);
1028 1028
 
1029 1029
 		// the report instance is expired. rerun it.
1030
-		if ( 404 === $result['code'] ) {
1030
+		if (404 === $result['code']) {
1031 1031
 			//error_log('run report again. it expired.');
1032
-			$this->run_analytics_report( $id, true, true );
1032
+			$this->run_analytics_report($id, true, true);
1033 1033
 		}
1034 1034
 
1035 1035
 		// cache the instance results as a long fallback if the setting says so
1036 1036
 		// do this because salesforce will have errors if the instance has expired or is currently running
1037 1037
 		// remember: the result of the above api_call is already cached (or not) according to the plugin's generic settings
1038 1038
 		// this is fine I think, although it is a bit of redundancy in this case
1039
-		if ( true === $cache_instance ) {
1040
-			$cached = $this->wordpress->cache_get( $report_url . '_instance_cached', '' );
1041
-			if ( is_array( $cached ) ) {
1039
+		if (true === $cache_instance) {
1040
+			$cached = $this->wordpress->cache_get($report_url . '_instance_cached', '');
1041
+			if (is_array($cached)) {
1042 1042
 				$result = $cached;
1043 1043
 			} else {
1044
-				if ( 'Success' === $result['data']['attributes']['status'] ) {
1045
-					if ( '' === $instance_cache_expiration ) {
1044
+				if ('Success' === $result['data']['attributes']['status']) {
1045
+					if ('' === $instance_cache_expiration) {
1046 1046
 						$instance_cache_expiration = $this->cache_expiration();
1047 1047
 					}
1048
-					$this->wordpress->cache_set( $report_url . '_instance_cached', '', $result, $instance_cache_expiration );
1048
+					$this->wordpress->cache_set($report_url . '_instance_cached', '', $result, $instance_cache_expiration);
1049 1049
 				}
1050 1050
 			}
1051 1051
 		}
@@ -1069,8 +1069,8 @@  discard block
 block discarded – undo
1069 1069
 	*
1070 1070
 	* part of core API calls
1071 1071
 	*/
1072
-	public function object_readby_external_id( $name, $field, $value ) {
1073
-		return $this->api_call( "sobjects/{$name}/{$field}/{$value}" );
1072
+	public function object_readby_external_id($name, $field, $value) {
1073
+		return $this->api_call("sobjects/{$name}/{$field}/{$value}");
1074 1074
 	}
1075 1075
 
1076 1076
 	/**
@@ -1085,11 +1085,11 @@  discard block
 block discarded – undo
1085 1085
 	*
1086 1086
 	* part of core API calls
1087 1087
 	*/
1088
-	public function object_delete( $name, $id ) {
1088
+	public function object_delete($name, $id) {
1089 1089
 		$options = array(
1090 1090
 			'type' => 'write',
1091 1091
 		);
1092
-		$result  = $this->api_call( "sobjects/{$name}/{$id}", array(), 'DELETE', $options );
1092
+		$result  = $this->api_call("sobjects/{$name}/{$id}", array(), 'DELETE', $options);
1093 1093
 		return $result;
1094 1094
 	}
1095 1095
 
@@ -1105,11 +1105,11 @@  discard block
 block discarded – undo
1105 1105
 	*   End date to check for deleted objects (in ISO 8601 format).
1106 1106
 	* @return GetDeletedResult
1107 1107
 	*/
1108
-	public function get_deleted( $type, $start_date, $end_date ) {
1108
+	public function get_deleted($type, $start_date, $end_date) {
1109 1109
 		$options = array(
1110 1110
 			'cache' => false,
1111 1111
 		); // this is timestamp level specific; probably should not cache it
1112
-		return $this->api_call( "sobjects/{$type}/deleted/?start={$start_date}&end={$end_date}", array(), 'GET', $options );
1112
+		return $this->api_call("sobjects/{$type}/deleted/?start={$start_date}&end={$end_date}", array(), 'GET', $options);
1113 1113
 	}
1114 1114
 
1115 1115
 
@@ -1122,9 +1122,9 @@  discard block
 block discarded – undo
1122 1122
 	* part of core API calls
1123 1123
 	*/
1124 1124
 	public function list_resources() {
1125
-		$resources = $this->api_call( '' );
1126
-		foreach ( $resources as $key => $path ) {
1127
-			$items[ $key ] = $path;
1125
+		$resources = $this->api_call('');
1126
+		foreach ($resources as $key => $path) {
1127
+			$items[$key] = $path;
1128 1128
 		}
1129 1129
 		return $items;
1130 1130
 	}
@@ -1155,21 +1155,21 @@  discard block
 block discarded – undo
1155 1155
 	*
1156 1156
 	* part of core API calls
1157 1157
 	*/
1158
-	public function get_updated( $type, $start = null, $end = null ) {
1159
-		if ( empty( $start ) ) {
1160
-			$start = strtotime( '-29 days' );
1158
+	public function get_updated($type, $start = null, $end = null) {
1159
+		if (empty($start)) {
1160
+			$start = strtotime('-29 days');
1161 1161
 		}
1162
-		$start = rawurlencode( gmdate( DATE_ATOM, $start ) );
1162
+		$start = rawurlencode(gmdate(DATE_ATOM, $start));
1163 1163
 
1164
-		if ( empty( $end ) ) {
1164
+		if (empty($end)) {
1165 1165
 			$end = time();
1166 1166
 		}
1167
-		$end = rawurlencode( gmdate( DATE_ATOM, $end ) );
1167
+		$end = rawurlencode(gmdate(DATE_ATOM, $end));
1168 1168
 
1169 1169
 		$options = array(
1170 1170
 			'cache' => false,
1171 1171
 		); // this is timestamp level specific; probably should not cache it
1172
-		return $this->api_call( "sobjects/{$type}/updated/?start=$start&end=$end", array(), 'GET', $options );
1172
+		return $this->api_call("sobjects/{$type}/updated/?start=$start&end=$end", array(), 'GET', $options);
1173 1173
 	}
1174 1174
 
1175 1175
 	/**
@@ -1187,28 +1187,28 @@  discard block
 block discarded – undo
1187 1187
 	*   The Salesforce ID of the given Record Type, or null.
1188 1188
 	*/
1189 1189
 
1190
-	public function get_record_type_id_by_developer_name( $name, $devname, $reset = false ) {
1190
+	public function get_record_type_id_by_developer_name($name, $devname, $reset = false) {
1191 1191
 
1192 1192
 		// example of how this runs: $this->get_record_type_id_by_developer_name( 'Account', 'HH_Account' );
1193 1193
 
1194
-		$cached = $this->wordpress->cache_get( 'salesforce_record_types', '' );
1195
-		if ( is_array( $cached ) && ( ! isset( $reset ) || true !== $reset ) ) {
1196
-			return ! empty( $cached[ $name ][ $devname ] ) ? $cached[ $name ][ $devname ]['Id'] : null;
1194
+		$cached = $this->wordpress->cache_get('salesforce_record_types', '');
1195
+		if (is_array($cached) && ( ! isset($reset) || true !== $reset)) {
1196
+			return ! empty($cached[$name][$devname]) ? $cached[$name][$devname]['Id'] : null;
1197 1197
 		}
1198 1198
 
1199
-		$query         = new Object_Sync_Sf_Salesforce_Select_Query( 'RecordType' );
1200
-		$query->fields = array( 'Id', 'Name', 'DeveloperName', 'SobjectType' );
1199
+		$query         = new Object_Sync_Sf_Salesforce_Select_Query('RecordType');
1200
+		$query->fields = array('Id', 'Name', 'DeveloperName', 'SobjectType');
1201 1201
 
1202
-		$result       = $this->query( $query );
1202
+		$result       = $this->query($query);
1203 1203
 		$record_types = array();
1204 1204
 
1205
-		foreach ( $result['data']['records'] as $record_type ) {
1206
-			$record_types[ $record_type['SobjectType'] ][ $record_type['DeveloperName'] ] = $record_type;
1205
+		foreach ($result['data']['records'] as $record_type) {
1206
+			$record_types[$record_type['SobjectType']][$record_type['DeveloperName']] = $record_type;
1207 1207
 		}
1208 1208
 
1209
-		$cached = $this->wordpress->cache_set( 'salesforce_record_types', '', $record_types, $this->options['cache_expiration'] );
1209
+		$cached = $this->wordpress->cache_set('salesforce_record_types', '', $record_types, $this->options['cache_expiration']);
1210 1210
 
1211
-		return ! empty( $record_types[ $name ][ $devname ] ) ? $record_types[ $name ][ $devname ]['Id'] : null;
1211
+		return ! empty($record_types[$name][$devname]) ? $record_types[$name][$devname]['Id'] : null;
1212 1212
 
1213 1213
 	}
1214 1214
 
@@ -1218,7 +1218,7 @@  discard block
 block discarded – undo
1218 1218
 	*
1219 1219
 	*/
1220 1220
 	private function cache_expiration() {
1221
-		$cache_expiration = $this->wordpress->cache_expiration( 'object_sync_for_salesforce_cache_expiration', 86400 );
1221
+		$cache_expiration = $this->wordpress->cache_expiration('object_sync_for_salesforce_cache_expiration', 86400);
1222 1222
 		return $cache_expiration;
1223 1223
 	}
1224 1224
 
Please login to merge, or discard this patch.
classes/salesforce_mapping.php 1 patch
Spacing   +230 added lines, -230 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
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @param object $logging Object_Sync_Sf_Logging.
61 61
 	 * @throws \Exception
62 62
 	 */
63
-	public function __construct( $wpdb, $version, $slug, $logging ) {
63
+	public function __construct($wpdb, $version, $slug, $logging) {
64 64
 		$this->wpdb    = $wpdb;
65 65
 		$this->version = $version;
66 66
 		$this->slug    = $slug;
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
 		$this->sync_sf_delete        = 0x0020;
84 84
 
85 85
 		// Define which events are initialized by which system.
86
-		$this->wordpress_events  = array( $this->sync_wordpress_create, $this->sync_wordpress_update, $this->sync_wordpress_delete );
87
-		$this->salesforce_events = array( $this->sync_sf_create, $this->sync_sf_update, $this->sync_sf_delete );
86
+		$this->wordpress_events  = array($this->sync_wordpress_create, $this->sync_wordpress_update, $this->sync_wordpress_delete);
87
+		$this->salesforce_events = array($this->sync_sf_create, $this->sync_sf_update, $this->sync_sf_delete);
88 88
 
89 89
 		// Constants for the directions to map things.
90 90
 		$this->direction_wordpress_sf = 'wp_sf';
91 91
 		$this->direction_sf_wordpress = 'sf_wp';
92 92
 		$this->direction_sync         = 'sync';
93 93
 
94
-		$this->direction_wordpress  = array( $this->direction_wordpress_sf, $this->direction_sync );
95
-		$this->direction_salesforce = array( $this->direction_sf_wordpress, $this->direction_sync );
94
+		$this->direction_wordpress  = array($this->direction_wordpress_sf, $this->direction_sync);
95
+		$this->direction_salesforce = array($this->direction_sf_wordpress, $this->direction_sync);
96 96
 
97 97
 		// This is used when we map a record with default or Master.
98 98
 		$this->salesforce_default_record_type = 'default';
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
 		// Salesforce has multipicklists and they have a delimiter.
101 101
 		$this->array_delimiter = ';';
102 102
 		// What data types in Salesforce should be an array?
103
-		$this->array_types_from_salesforce = array( 'multipicklist' );
103
+		$this->array_types_from_salesforce = array('multipicklist');
104 104
 		// What data types in Salesforce should be a date field?
105
-		$this->date_types_from_salesforce = array( 'date', 'datetime' );
105
+		$this->date_types_from_salesforce = array('date', 'datetime');
106 106
 		// What data types in Salesforce should be an integer?
107
-		$this->int_types_from_salesforce = array( 'integer', 'boolean' );
107
+		$this->int_types_from_salesforce = array('integer', 'boolean');
108 108
 
109 109
 		// Max length for a mapping field.
110 110
 		$this->name_length = 128;
@@ -123,13 +123,13 @@  discard block
 block discarded – undo
123 123
 	 * @param array $salesforce_fields The fields for the Salesforce side of the mapping.
124 124
 	 * @throws \Exception
125 125
 	 */
126
-	public function create_fieldmap( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array() ) {
127
-		$data = $this->setup_fieldmap_data( $posted, $wordpress_fields, $salesforce_fields );
128
-		if ( version_compare( $this->version, '1.2.5', '>=' ) ) {
126
+	public function create_fieldmap($posted = array(), $wordpress_fields = array(), $salesforce_fields = array()) {
127
+		$data = $this->setup_fieldmap_data($posted, $wordpress_fields, $salesforce_fields);
128
+		if (version_compare($this->version, '1.2.5', '>=')) {
129 129
 			$data['version'] = $this->version;
130 130
 		}
131
-		$insert = $this->wpdb->insert( $this->fieldmap_table, $data );
132
-		if ( 1 === $insert ) {
131
+		$insert = $this->wpdb->insert($this->fieldmap_table, $data);
132
+		if (1 === $insert) {
133 133
 			return $this->wpdb->insert_id;
134 134
 		} else {
135 135
 			return false;
@@ -145,29 +145,29 @@  discard block
 block discarded – undo
145 145
 	 * @return Array $map a single mapping or $mappings, an array of mappings.
146 146
 	 * @throws \Exception
147 147
 	 */
148
-	public function get_fieldmaps( $id = null, $conditions = array(), $reset = false ) {
148
+	public function get_fieldmaps($id = null, $conditions = array(), $reset = false) {
149 149
 		$table = $this->fieldmap_table;
150
-		if ( null !== $id ) { // get one fieldmap.
151
-			$map                                    = $this->wpdb->get_row( 'SELECT * FROM ' . $table . ' WHERE id = ' . $id, ARRAY_A );
152
-			$map['salesforce_record_types_allowed'] = maybe_unserialize( $map['salesforce_record_types_allowed'] );
150
+		if (null !== $id) { // get one fieldmap.
151
+			$map                                    = $this->wpdb->get_row('SELECT * FROM ' . $table . ' WHERE id = ' . $id, ARRAY_A);
152
+			$map['salesforce_record_types_allowed'] = maybe_unserialize($map['salesforce_record_types_allowed']);
153 153
 
154
-			$map['fields']        = maybe_unserialize( $map['fields'] );
155
-			$map['sync_triggers'] = maybe_unserialize( $map['sync_triggers'] );
154
+			$map['fields']        = maybe_unserialize($map['fields']);
155
+			$map['sync_triggers'] = maybe_unserialize($map['sync_triggers']);
156 156
 			return $map;
157
-		} elseif ( ! empty( $conditions ) ) { // get multiple but with a limitation.
157
+		} elseif ( ! empty($conditions)) { // get multiple but with a limitation.
158 158
 			$mappings    = array();
159 159
 			$record_type = '';
160 160
 
161 161
 			// Assemble the SQL.
162
-			if ( ! empty( $conditions ) ) {
162
+			if ( ! empty($conditions)) {
163 163
 				$where = ' WHERE ';
164 164
 				$i     = 0;
165
-				foreach ( $conditions as $key => $value ) {
166
-					if ( 'salesforce_record_type' === $key ) {
167
-						$record_type = sanitize_text_field( $value );
165
+				foreach ($conditions as $key => $value) {
166
+					if ('salesforce_record_type' === $key) {
167
+						$record_type = sanitize_text_field($value);
168 168
 					} else {
169 169
 						$i++;
170
-						if ( $i > 1 ) {
170
+						if ($i > 1) {
171 171
 							$where .= ' AND ';
172 172
 						}
173 173
 						$where .= '`' . $key . '` = "' . $value . '"';
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
 				$where = '';
178 178
 			}
179 179
 
180
-			$mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $where . ' ORDER BY `weight`', ARRAY_A );
180
+			$mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $where . ' ORDER BY `weight`', ARRAY_A);
181 181
 
182
-			if ( ! empty( $mappings ) ) {
183
-				$mappings = $this->prepare_fieldmap_data( $mappings, $record_type );
182
+			if ( ! empty($mappings)) {
183
+				$mappings = $this->prepare_fieldmap_data($mappings, $record_type);
184 184
 			}
185 185
 
186 186
 			return $mappings;
@@ -188,14 +188,14 @@  discard block
 block discarded – undo
188 188
 		} else { // get all of the mappings. ALL THE MAPPINGS.
189 189
 
190 190
 			// if the version is greater than or equal to 1.2.5, the fieldmap table has a version column
191
-			if ( version_compare( $this->version, '1.2.5', '>=' ) ) {
192
-				$mappings = $this->wpdb->get_results( "SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight`, `version` FROM $table", ARRAY_A );
191
+			if (version_compare($this->version, '1.2.5', '>=')) {
192
+				$mappings = $this->wpdb->get_results("SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight`, `version` FROM $table", ARRAY_A);
193 193
 			} else {
194
-				$mappings = $this->wpdb->get_results( "SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight` FROM $table", ARRAY_A );
194
+				$mappings = $this->wpdb->get_results("SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight` FROM $table", ARRAY_A);
195 195
 			}
196 196
 
197
-			if ( ! empty( $mappings ) ) {
198
-				$mappings = $this->prepare_fieldmap_data( $mappings );
197
+			if ( ! empty($mappings)) {
198
+				$mappings = $this->prepare_fieldmap_data($mappings);
199 199
 			}
200 200
 
201 201
 			return $mappings;
@@ -211,29 +211,29 @@  discard block
 block discarded – undo
211 211
 	 *
212 212
 	 * @return Array of mapped fields
213 213
 	 */
214
-	public function get_mapped_fields( $mapping, $directions = array() ) {
214
+	public function get_mapped_fields($mapping, $directions = array()) {
215 215
 		$mapped_fields = array();
216
-		foreach ( $mapping['fields'] as $fields ) {
217
-			if ( empty( $directions ) || in_array( $fields['direction'], $directions, true ) ) {
216
+		foreach ($mapping['fields'] as $fields) {
217
+			if (empty($directions) || in_array($fields['direction'], $directions, true)) {
218 218
 
219
-				if ( version_compare( $this->version, '1.2.0', '>=' ) && isset( $fields['salesforce_field']['name'] ) ) {
219
+				if (version_compare($this->version, '1.2.0', '>=') && isset($fields['salesforce_field']['name'])) {
220 220
 					$array_key = 'name';
221 221
 				} else {
222 222
 					$array_key = 'label';
223 223
 				}
224 224
 
225 225
 				// Some field map types (Relation) store a collection of SF objects.
226
-				if ( is_array( $fields['salesforce_field'] ) && ! isset( $fields['salesforce_field'][ $array_key ] ) ) {
227
-					foreach ( $fields['salesforce_field'] as $sf_field ) {
228
-						$mapped_fields[ $sf_field[ $array_key ] ] = $sf_field[ $array_key ];
226
+				if (is_array($fields['salesforce_field']) && ! isset($fields['salesforce_field'][$array_key])) {
227
+					foreach ($fields['salesforce_field'] as $sf_field) {
228
+						$mapped_fields[$sf_field[$array_key]] = $sf_field[$array_key];
229 229
 					}
230 230
 				} else { // The rest are just a name/value pair.
231
-					$mapped_fields[ $fields['salesforce_field'][ $array_key ] ] = $fields['salesforce_field'][ $array_key ];
231
+					$mapped_fields[$fields['salesforce_field'][$array_key]] = $fields['salesforce_field'][$array_key];
232 232
 				}
233 233
 			}
234 234
 		}
235 235
 
236
-		if ( ! empty( $this->get_mapped_record_types ) ) {
236
+		if ( ! empty($this->get_mapped_record_types)) {
237 237
 			$mapped_fields['RecordTypeId'] = 'RecordTypeId';
238 238
 		}
239 239
 
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 	 * @param Array $mapping A mapping from which we wish to estract the record type.
247 247
 	 * @return Array of mappings. Empty if the mapping's record type is default, else full of the record types.
248 248
 	 */
249
-	public function get_mapped_record_types( $mapping ) {
250
-		return $mapping['salesforce_record_type_default'] === $this->salesforce_default_record_type ? array() : array_filter( maybe_unserialize( $mapping['salesforce_record_types_allowed'] ) );
249
+	public function get_mapped_record_types($mapping) {
250
+		return $mapping['salesforce_record_type_default'] === $this->salesforce_default_record_type ? array() : array_filter(maybe_unserialize($mapping['salesforce_record_types_allowed']));
251 251
 	}
252 252
 
253 253
 	/**
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	 * @return $map
261 261
 	 * @throws \Exception
262 262
 	 */
263
-	public function update_fieldmap( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array(), $id = '' ) {
264
-		$data = $this->setup_fieldmap_data( $posted, $wordpress_fields, $salesforce_fields );
265
-		if ( version_compare( $this->version, '1.2.5', '>=' ) && ! isset( $data['updated'] ) ) {
263
+	public function update_fieldmap($posted = array(), $wordpress_fields = array(), $salesforce_fields = array(), $id = '') {
264
+		$data = $this->setup_fieldmap_data($posted, $wordpress_fields, $salesforce_fields);
265
+		if (version_compare($this->version, '1.2.5', '>=') && ! isset($data['updated'])) {
266 266
 			$data['version'] = $this->version;
267 267
 		}
268 268
 		$update = $this->wpdb->update(
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 				'id' => $id,
273 273
 			)
274 274
 		);
275
-		if ( false === $update ) {
275
+		if (false === $update) {
276 276
 			return false;
277 277
 		} else {
278 278
 			return true;
@@ -288,76 +288,76 @@  discard block
 block discarded – undo
288 288
 	 * @param array $salesforce_fields The fields for the Salesforce side of the mapping.
289 289
 	 * @return $data
290 290
 	 */
291
-	private function setup_fieldmap_data( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array() ) {
291
+	private function setup_fieldmap_data($posted = array(), $wordpress_fields = array(), $salesforce_fields = array()) {
292 292
 		$data = array(
293 293
 			'label'             => $posted['label'],
294
-			'name'              => sanitize_title( $posted['label'] ),
294
+			'name'              => sanitize_title($posted['label']),
295 295
 			'salesforce_object' => $posted['salesforce_object'],
296 296
 			'wordpress_object'  => $posted['wordpress_object'],
297 297
 		);
298
-		if ( isset( $posted['wordpress_field'] ) && is_array( $posted['wordpress_field'] ) && isset( $posted['salesforce_field'] ) && is_array( $posted['salesforce_field'] ) ) {
298
+		if (isset($posted['wordpress_field']) && is_array($posted['wordpress_field']) && isset($posted['salesforce_field']) && is_array($posted['salesforce_field'])) {
299 299
 			$setup['fields'] = array();
300
-			foreach ( $posted['wordpress_field'] as $key => $value ) {
301
-				$method_key = array_search( $value, array_column( $wordpress_fields, 'key' ), true );
302
-				if ( ! isset( $posted['direction'][ $key ] ) ) {
303
-					$posted['direction'][ $key ] = 'sync';
300
+			foreach ($posted['wordpress_field'] as $key => $value) {
301
+				$method_key = array_search($value, array_column($wordpress_fields, 'key'), true);
302
+				if ( ! isset($posted['direction'][$key])) {
303
+					$posted['direction'][$key] = 'sync';
304 304
 				}
305
-				if ( ! isset( $posted['is_prematch'][ $key ] ) ) {
306
-					$posted['is_prematch'][ $key ] = false;
305
+				if ( ! isset($posted['is_prematch'][$key])) {
306
+					$posted['is_prematch'][$key] = false;
307 307
 				}
308
-				if ( ! isset( $posted['is_key'][ $key ] ) ) {
309
-					$posted['is_key'][ $key ] = false;
308
+				if ( ! isset($posted['is_key'][$key])) {
309
+					$posted['is_key'][$key] = false;
310 310
 				}
311
-				if ( ! isset( $posted['is_delete'][ $key ] ) ) {
312
-					$posted['is_delete'][ $key ] = false;
311
+				if ( ! isset($posted['is_delete'][$key])) {
312
+					$posted['is_delete'][$key] = false;
313 313
 				}
314
-				if ( false === $posted['is_delete'][ $key ] ) {
314
+				if (false === $posted['is_delete'][$key]) {
315 315
 
316
-					$updateable_key = array_search( $posted['salesforce_field'][ $key ], array_column( $salesforce_fields, 'name' ), true );
316
+					$updateable_key = array_search($posted['salesforce_field'][$key], array_column($salesforce_fields, 'name'), true);
317 317
 
318 318
 					$salesforce_field_attributes = array();
319
-					foreach ( $salesforce_fields[ $updateable_key ] as $sf_key => $sf_value ) {
320
-						if ( isset( $sf_value ) && ! is_array( $sf_value ) ) {
321
-							$salesforce_field_attributes[ $sf_key ] = esc_attr( $sf_value );
322
-						} elseif ( ! empty( $sf_value ) && is_array( $sf_value ) ) {
323
-							$salesforce_field_attributes[ $sf_key ] = maybe_unserialize( $sf_value );
319
+					foreach ($salesforce_fields[$updateable_key] as $sf_key => $sf_value) {
320
+						if (isset($sf_value) && ! is_array($sf_value)) {
321
+							$salesforce_field_attributes[$sf_key] = esc_attr($sf_value);
322
+						} elseif ( ! empty($sf_value) && is_array($sf_value)) {
323
+							$salesforce_field_attributes[$sf_key] = maybe_unserialize($sf_value);
324 324
 						} else {
325
-							$salesforce_field_attributes[ $sf_key ] = '';
325
+							$salesforce_field_attributes[$sf_key] = '';
326 326
 						}
327 327
 					}
328 328
 
329
-					$setup['fields'][ $key ] = array(
329
+					$setup['fields'][$key] = array(
330 330
 						'wordpress_field'  => array(
331
-							'label'   => sanitize_text_field( $posted['wordpress_field'][ $key ] ),
332
-							'methods' => maybe_unserialize( $wordpress_fields[ $method_key ]['methods'] ),
333
-							'type'    => isset( $wordpress_fields[ $method_key ]['type'] ) ? sanitize_text_field( $wordpress_fields[ $method_key ]['type'] ) : 'text',
331
+							'label'   => sanitize_text_field($posted['wordpress_field'][$key]),
332
+							'methods' => maybe_unserialize($wordpress_fields[$method_key]['methods']),
333
+							'type'    => isset($wordpress_fields[$method_key]['type']) ? sanitize_text_field($wordpress_fields[$method_key]['type']) : 'text',
334 334
 						),
335 335
 						'salesforce_field' => $salesforce_field_attributes,
336
-						'is_prematch'      => sanitize_text_field( $posted['is_prematch'][ $key ] ),
337
-						'is_key'           => sanitize_text_field( $posted['is_key'][ $key ] ),
338
-						'direction'        => sanitize_text_field( $posted['direction'][ $key ] ),
339
-						'is_delete'        => sanitize_text_field( $posted['is_delete'][ $key ] ),
336
+						'is_prematch'      => sanitize_text_field($posted['is_prematch'][$key]),
337
+						'is_key'           => sanitize_text_field($posted['is_key'][$key]),
338
+						'direction'        => sanitize_text_field($posted['direction'][$key]),
339
+						'is_delete'        => sanitize_text_field($posted['is_delete'][$key]),
340 340
 					);
341 341
 
342 342
 					// If the WordPress key or the Salesforce key are blank, remove this incomplete mapping.
343 343
 					// This prevents https://github.com/MinnPost/object-sync-for-salesforce/issues/82 .
344 344
 					if (
345
-						empty( $setup['fields'][ $key ]['wordpress_field']['label'] )
345
+						empty($setup['fields'][$key]['wordpress_field']['label'])
346 346
 						||
347
-						empty( $setup['fields'][ $key ]['salesforce_field']['name'] )
347
+						empty($setup['fields'][$key]['salesforce_field']['name'])
348 348
 					) {
349
-						unset( $setup['fields'][ $key ] );
349
+						unset($setup['fields'][$key]);
350 350
 					}
351 351
 				}
352 352
 			} // End foreach() on WordPress fields.
353
-			$data['fields'] = maybe_serialize( $setup['fields'] );
354
-		} elseif ( isset( $posted['fields'] ) && is_array( $posted['fields'] ) ) {
353
+			$data['fields'] = maybe_serialize($setup['fields']);
354
+		} elseif (isset($posted['fields']) && is_array($posted['fields'])) {
355 355
 			// if $posted['fields'] is already set, use that
356
-			$data['fields'] = maybe_serialize( $posted['fields'] );
356
+			$data['fields'] = maybe_serialize($posted['fields']);
357 357
 		} // End if() WordPress fields are present.
358 358
 
359
-		if ( isset( $posted['salesforce_record_types_allowed'] ) ) {
360
-			$data['salesforce_record_types_allowed'] = maybe_serialize( $posted['salesforce_record_types_allowed'] );
359
+		if (isset($posted['salesforce_record_types_allowed'])) {
360
+			$data['salesforce_record_types_allowed'] = maybe_serialize($posted['salesforce_record_types_allowed']);
361 361
 		} else {
362 362
 			$data['salesforce_record_types_allowed'] = maybe_serialize(
363 363
 				array(
@@ -365,29 +365,29 @@  discard block
 block discarded – undo
365 365
 				)
366 366
 			);
367 367
 		}
368
-		if ( isset( $posted['salesforce_record_type_default'] ) ) {
368
+		if (isset($posted['salesforce_record_type_default'])) {
369 369
 			$data['salesforce_record_type_default'] = $posted['salesforce_record_type_default'];
370 370
 		} else {
371
-			$data['salesforce_record_type_default'] = maybe_serialize( $this->salesforce_default_record_type );
371
+			$data['salesforce_record_type_default'] = maybe_serialize($this->salesforce_default_record_type);
372 372
 		}
373
-		if ( isset( $posted['pull_trigger_field'] ) ) {
373
+		if (isset($posted['pull_trigger_field'])) {
374 374
 			$data['pull_trigger_field'] = $posted['pull_trigger_field'];
375 375
 		}
376
-		if ( isset( $posted['sync_triggers'] ) && is_array( $posted['sync_triggers'] ) ) {
376
+		if (isset($posted['sync_triggers']) && is_array($posted['sync_triggers'])) {
377 377
 			$setup['sync_triggers'] = array();
378
-			foreach ( $posted['sync_triggers'] as $key => $value ) {
379
-				$setup['sync_triggers'][ $key ] = esc_html( $posted['sync_triggers'][ $key ] );
378
+			foreach ($posted['sync_triggers'] as $key => $value) {
379
+				$setup['sync_triggers'][$key] = esc_html($posted['sync_triggers'][$key]);
380 380
 			}
381 381
 		} else {
382 382
 			$setup['sync_triggers'] = array();
383 383
 		}
384
-		$data['sync_triggers'] = maybe_serialize( $setup['sync_triggers'] );
385
-		if ( isset( $posted['pull_trigger_field'] ) ) {
384
+		$data['sync_triggers'] = maybe_serialize($setup['sync_triggers']);
385
+		if (isset($posted['pull_trigger_field'])) {
386 386
 			$data['pull_trigger_field'] = $posted['pull_trigger_field'];
387 387
 		}
388
-		$data['push_async']  = isset( $posted['push_async'] ) ? $posted['push_async'] : '';
389
-		$data['push_drafts'] = isset( $posted['push_drafts'] ) ? $posted['push_drafts'] : '';
390
-		$data['weight']      = isset( $posted['weight'] ) ? $posted['weight'] : '';
388
+		$data['push_async']  = isset($posted['push_async']) ? $posted['push_async'] : '';
389
+		$data['push_drafts'] = isset($posted['push_drafts']) ? $posted['push_drafts'] : '';
390
+		$data['weight']      = isset($posted['weight']) ? $posted['weight'] : '';
391 391
 		return $data;
392 392
 	}
393 393
 
@@ -398,12 +398,12 @@  discard block
 block discarded – undo
398 398
 	 * @return Boolean
399 399
 	 * @throws \Exception
400 400
 	 */
401
-	public function delete_fieldmap( $id = '' ) {
401
+	public function delete_fieldmap($id = '') {
402 402
 		$data   = array(
403 403
 			'id' => $id,
404 404
 		);
405
-		$delete = $this->wpdb->delete( $this->fieldmap_table, $data );
406
-		if ( 1 === $delete ) {
405
+		$delete = $this->wpdb->delete($this->fieldmap_table, $data);
406
+		if (1 === $delete) {
407 407
 			return true;
408 408
 		} else {
409 409
 			return false;
@@ -417,27 +417,27 @@  discard block
 block discarded – undo
417 417
 	 * @return false|Int of field mapping between WordPress and Salesforce objects
418 418
 	 * @throws \Exception
419 419
 	 */
420
-	public function create_object_map( $posted = array() ) {
421
-		$data            = $this->setup_object_map_data( $posted );
422
-		$data['created'] = current_time( 'mysql' );
420
+	public function create_object_map($posted = array()) {
421
+		$data            = $this->setup_object_map_data($posted);
422
+		$data['created'] = current_time('mysql');
423 423
 		// Check to see if we don't know the salesforce id and it is not a temporary id, or if this is pending.
424 424
 		// If it is using a temporary id, the map will get updated after it finishes running; it won't call this method unless there's an error, which we should log.
425
-		if ( substr( $data['salesforce_id'], 0, 7 ) !== 'tmp_sf_' || 'pending' === $data['action'] ) {
426
-			unset( $data['action'] );
427
-			$insert = $this->wpdb->insert( $this->object_map_table, $data );
425
+		if (substr($data['salesforce_id'], 0, 7) !== 'tmp_sf_' || 'pending' === $data['action']) {
426
+			unset($data['action']);
427
+			$insert = $this->wpdb->insert($this->object_map_table, $data);
428 428
 		} else {
429 429
 			$status = 'error';
430
-			if ( isset( $this->logging ) ) {
430
+			if (isset($this->logging)) {
431 431
 				$logging = $this->logging;
432
-			} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
433
-				$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
432
+			} elseif (class_exists('Object_Sync_Sf_Logging')) {
433
+				$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
434 434
 			}
435 435
 			$logging->setup(
436 436
 				sprintf(
437 437
 					// translators: %1$s is the name of a WordPress object. %2$s is the id of that object.
438
-					esc_html__( 'Error Mapping: error caused by trying to map the WordPress %1$s with ID of %2$s to Salesforce ID starting with "tmp_sf_", which is invalid.', 'object-sync-for-salesforce' ),
439
-					esc_attr( $data['wordpress_object'] ),
440
-					absint( $data['wordpress_id'] )
438
+					esc_html__('Error Mapping: error caused by trying to map the WordPress %1$s with ID of %2$s to Salesforce ID starting with "tmp_sf_", which is invalid.', 'object-sync-for-salesforce'),
439
+					esc_attr($data['wordpress_object']),
440
+					absint($data['wordpress_id'])
441 441
 				),
442 442
 				'',
443 443
 				0,
@@ -446,23 +446,23 @@  discard block
 block discarded – undo
446 446
 			);
447 447
 			return false;
448 448
 		}
449
-		if ( 1 === $insert ) {
449
+		if (1 === $insert) {
450 450
 			return $this->wpdb->insert_id;
451
-		} elseif ( false !== strpos( $this->wpdb->last_error, 'Duplicate entry' ) ) {
452
-			$mapping = $this->load_by_salesforce( $data['salesforce_id'] );
451
+		} elseif (false !== strpos($this->wpdb->last_error, 'Duplicate entry')) {
452
+			$mapping = $this->load_by_salesforce($data['salesforce_id']);
453 453
 			$id      = $mapping['id'];
454 454
 			$status  = 'error';
455
-			if ( isset( $this->logging ) ) {
455
+			if (isset($this->logging)) {
456 456
 				$logging = $this->logging;
457
-			} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
458
-				$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
457
+			} elseif (class_exists('Object_Sync_Sf_Logging')) {
458
+				$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
459 459
 			}
460 460
 			$logging->setup(
461 461
 				sprintf(
462 462
 					// translators: %1$s is the status word "Error". %1$s is the Id of a Salesforce object. %2$s is the ID of a mapping object.
463
-					esc_html__( 'Error: Mapping: there is already a WordPress object mapped to the Salesforce object %1$s and the mapping object ID is %2$s', 'object-sync-for-salesforce' ),
464
-					esc_attr( $data['salesforce_id'] ),
465
-					absint( $id )
463
+					esc_html__('Error: Mapping: there is already a WordPress object mapped to the Salesforce object %1$s and the mapping object ID is %2$s', 'object-sync-for-salesforce'),
464
+					esc_attr($data['salesforce_id']),
465
+					absint($id)
466 466
 				),
467 467
 				'',
468 468
 				0,
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 	 * @return $map or $mappings
484 484
 	 * @throws \Exception
485 485
 	 */
486
-	public function get_object_maps( $conditions = array(), $reset = false ) {
486
+	public function get_object_maps($conditions = array(), $reset = false) {
487 487
 		$table = $this->object_map_table;
488 488
 		$order = ' ORDER BY object_updated, created';
489
-		if ( ! empty( $conditions ) ) { // get multiple but with a limitation.
489
+		if ( ! empty($conditions)) { // get multiple but with a limitation.
490 490
 			$mappings = array();
491 491
 
492
-			if ( ! empty( $conditions ) ) {
492
+			if ( ! empty($conditions)) {
493 493
 				$where = ' WHERE ';
494 494
 				$i     = 0;
495
-				foreach ( $conditions as $key => $value ) {
495
+				foreach ($conditions as $key => $value) {
496 496
 					$i++;
497
-					if ( $i > 1 ) {
497
+					if ($i > 1) {
498 498
 						$where .= ' AND ';
499 499
 					}
500 500
 					$where .= '`' . $key . '` = "' . $value . '"';
@@ -503,13 +503,13 @@  discard block
 block discarded – undo
503 503
 				$where = '';
504 504
 			}
505 505
 
506
-			$mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $where . $order, ARRAY_A );
507
-			if ( ! empty( $mappings ) && 1 === $this->wpdb->num_rows ) {
506
+			$mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $where . $order, ARRAY_A);
507
+			if ( ! empty($mappings) && 1 === $this->wpdb->num_rows) {
508 508
 				$mappings = $mappings[0];
509 509
 			}
510 510
 		} else { // get all of the mappings. ALL THE MAPPINGS.
511
-			$mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $order, ARRAY_A );
512
-			if ( ! empty( $mappings ) && 1 === $this->wpdb->num_rows ) {
511
+			$mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $order, ARRAY_A);
512
+			if ( ! empty($mappings) && 1 === $this->wpdb->num_rows) {
513 513
 				$mappings = $mappings[0];
514 514
 			}
515 515
 		}
@@ -526,10 +526,10 @@  discard block
 block discarded – undo
526 526
 	 * @return $map
527 527
 	 * @throws \Exception
528 528
 	 */
529
-	public function update_object_map( $posted = array(), $id = '' ) {
530
-		$data = $this->setup_object_map_data( $posted );
531
-		if ( ! isset( $data['object_updated'] ) ) {
532
-			$data['object_updated'] = current_time( 'mysql' );
529
+	public function update_object_map($posted = array(), $id = '') {
530
+		$data = $this->setup_object_map_data($posted);
531
+		if ( ! isset($data['object_updated'])) {
532
+			$data['object_updated'] = current_time('mysql');
533 533
 		}
534 534
 		$update = $this->wpdb->update(
535 535
 			$this->object_map_table,
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 				'id' => $id,
539 539
 			)
540 540
 		);
541
-		if ( false === $update ) {
541
+		if (false === $update) {
542 542
 			return false;
543 543
 		} else {
544 544
 			return true;
@@ -551,11 +551,11 @@  discard block
 block discarded – undo
551 551
 	 * @param array $posted It's $_POST.
552 552
 	 * @return $data Filtered array with only the keys that are in the object map database table. Strips out things from WordPress form if they're present.
553 553
 	 */
554
-	private function setup_object_map_data( $posted = array() ) {
555
-		$allowed_fields   = $this->wpdb->get_col( "DESC {$this->object_map_table}", 0 );
554
+	private function setup_object_map_data($posted = array()) {
555
+		$allowed_fields   = $this->wpdb->get_col("DESC {$this->object_map_table}", 0);
556 556
 		$allowed_fields[] = 'action'; // we use this in both directions even though it isn't in the database; we remove it from the array later if it is present
557 557
 
558
-		$data = array_intersect_key( $posted, array_flip( $allowed_fields ) );
558
+		$data = array_intersect_key($posted, array_flip($allowed_fields));
559 559
 		return $data;
560 560
 	}
561 561
 
@@ -565,12 +565,12 @@  discard block
 block discarded – undo
565 565
 	 * @param array $id The ID of the object map row.
566 566
 	 * @throws \Exception
567 567
 	 */
568
-	public function delete_object_map( $id = '' ) {
568
+	public function delete_object_map($id = '') {
569 569
 		$data   = array(
570 570
 			'id' => $id,
571 571
 		);
572
-		$delete = $this->wpdb->delete( $this->object_map_table, $data );
573
-		if ( 1 === $delete ) {
572
+		$delete = $this->wpdb->delete($this->object_map_table, $data);
573
+		if (1 === $delete) {
574 574
 			return true;
575 575
 		} else {
576 576
 			return false;
@@ -583,13 +583,13 @@  discard block
 block discarded – undo
583 583
 	 * @param string $direction Whether this is part of a push or pull action
584 584
 	 * @return $id is a temporary string that will be replaced if the modification is successful
585 585
 	 */
586
-	public function generate_temporary_id( $direction ) {
587
-		if ( 'push' === $direction ) {
586
+	public function generate_temporary_id($direction) {
587
+		if ('push' === $direction) {
588 588
 			$prefix = 'tmp_sf_';
589
-		} elseif ( 'pull' === $direction ) {
589
+		} elseif ('pull' === $direction) {
590 590
 			$prefix = 'tmp_wp_';
591 591
 		}
592
-		$id = uniqid( $prefix, true );
592
+		$id = uniqid($prefix, true);
593 593
 		return $id;
594 594
 	}
595 595
 
@@ -603,12 +603,12 @@  discard block
 block discarded – undo
603 603
 	 * @return SalesforceMappingObject
604 604
 	 *   The requested SalesforceMappingObject or FALSE if none was found.
605 605
 	 */
606
-	public function load_by_wordpress( $object_type, $object_id, $reset = false ) {
606
+	public function load_by_wordpress($object_type, $object_id, $reset = false) {
607 607
 		$conditions = array(
608 608
 			'wordpress_id'     => $object_id,
609 609
 			'wordpress_object' => $object_type,
610 610
 		);
611
-		return $this->get_object_maps( $conditions, $reset );
611
+		return $this->get_object_maps($conditions, $reset);
612 612
 	}
613 613
 
614 614
 	/**
@@ -620,24 +620,24 @@  discard block
 block discarded – undo
620 620
 	 * @return array $map
621 621
 	 *   The most recent fieldmap
622 622
 	 */
623
-	public function load_by_salesforce( $salesforce_id, $reset = false ) {
623
+	public function load_by_salesforce($salesforce_id, $reset = false) {
624 624
 		$conditions = array(
625 625
 			'salesforce_id' => $salesforce_id,
626 626
 		);
627 627
 
628
-		$map = $this->get_object_maps( $conditions, $reset );
628
+		$map = $this->get_object_maps($conditions, $reset);
629 629
 
630
-		if ( isset( $map[0] ) && is_array( $map[0] ) && count( $map ) > 1 ) {
630
+		if (isset($map[0]) && is_array($map[0]) && count($map) > 1) {
631 631
 			$status = 'notice';
632 632
 			$log    = '';
633 633
 			$log   .= 'Mapping: there is more than one mapped WordPress object for the Salesforce object ' . $salesforce_id . '. These WordPress IDs are: ';
634 634
 			$i      = 0;
635
-			foreach ( $map as $mapping ) {
635
+			foreach ($map as $mapping) {
636 636
 				$i++;
637
-				if ( isset( $mapping['wordpress_id'] ) ) {
637
+				if (isset($mapping['wordpress_id'])) {
638 638
 					$log .= 'object type: ' . $mapping['wordpress_object'] . ', id: ' . $mapping['wordpress_id'];
639 639
 				}
640
-				if ( count( $map ) !== $i ) {
640
+				if (count($map) !== $i) {
641 641
 					$log .= '; ';
642 642
 				} else {
643 643
 					$log .= '.';
@@ -645,16 +645,16 @@  discard block
 block discarded – undo
645 645
 			}
646 646
 			$map = $map[0];
647 647
 			// Create log entry for multiple maps.
648
-			if ( isset( $this->logging ) ) {
648
+			if (isset($this->logging)) {
649 649
 				$logging = $this->logging;
650
-			} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
651
-				$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
650
+			} elseif (class_exists('Object_Sync_Sf_Logging')) {
651
+				$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
652 652
 			}
653 653
 			$logging->setup(
654 654
 				sprintf(
655 655
 					// translators: %1$s is the Id of a Salesforce object.
656
-					esc_html__( 'Notice: Mapping: there is more than one mapped WordPress object for the Salesforce object %2$s', 'object-sync-for-salesforce' ),
657
-					esc_attr( $salesforce_id )
656
+					esc_html__('Notice: Mapping: there is more than one mapped WordPress object for the Salesforce object %2$s', 'object-sync-for-salesforce'),
657
+					esc_attr($salesforce_id)
658 658
 				),
659 659
 				$log,
660 660
 				0,
@@ -677,32 +677,32 @@  discard block
 block discarded – undo
677 677
 	 *
678 678
 	 * @return array Associative array of key value pairs.
679 679
 	 */
680
-	public function map_params( $mapping, $object, $trigger, $use_soap = false, $is_new = true ) {
680
+	public function map_params($mapping, $object, $trigger, $use_soap = false, $is_new = true) {
681 681
 
682 682
 		$params = array();
683 683
 
684
-		foreach ( $mapping['fields'] as $fieldmap ) {
684
+		foreach ($mapping['fields'] as $fieldmap) {
685 685
 
686
-			$wordpress_haystack  = array_values( $this->wordpress_events );
687
-			$salesforce_haystack = array_values( $this->salesforce_events );
686
+			$wordpress_haystack  = array_values($this->wordpress_events);
687
+			$salesforce_haystack = array_values($this->salesforce_events);
688 688
 
689
-			$fieldmap['wordpress_field']['methods'] = maybe_unserialize( $fieldmap['wordpress_field']['methods'] );
689
+			$fieldmap['wordpress_field']['methods'] = maybe_unserialize($fieldmap['wordpress_field']['methods']);
690 690
 
691 691
 			// skip fields that aren't being pushed to Salesforce.
692
-			if ( in_array( $trigger, $wordpress_haystack, true ) && ! in_array( $fieldmap['direction'], array_values( $this->direction_wordpress ), true ) ) {
692
+			if (in_array($trigger, $wordpress_haystack, true) && ! in_array($fieldmap['direction'], array_values($this->direction_wordpress), true)) {
693 693
 				// The trigger is a WordPress trigger, but the fieldmap direction is not a WordPress direction.
694 694
 				continue;
695 695
 			}
696 696
 
697 697
 			// skip fields that aren't being pulled from Salesforce.
698
-			if ( in_array( $trigger, $salesforce_haystack, true ) && ! in_array( $fieldmap['direction'], array_values( $this->direction_salesforce ), true ) ) {
698
+			if (in_array($trigger, $salesforce_haystack, true) && ! in_array($fieldmap['direction'], array_values($this->direction_salesforce), true)) {
699 699
 				// The trigger is a Salesforce trigger, but the fieldmap direction is not a Salesforce direction.
700 700
 				continue;
701 701
 			}
702 702
 
703 703
 			$wordpress_field = $fieldmap['wordpress_field']['label'];
704 704
 
705
-			if ( version_compare( $this->version, '1.2.0', '>=' ) && isset( $fieldmap['salesforce_field']['name'] ) ) {
705
+			if (version_compare($this->version, '1.2.0', '>=') && isset($fieldmap['salesforce_field']['name'])) {
706 706
 				$salesforce_field = $fieldmap['salesforce_field']['name'];
707 707
 				// Load the type of the Salesforce field. We can use this to handle Salesforce field value issues that come up based on what the field sends into WordPress or expects from WordPress.
708 708
 				$salesforce_field_type = $fieldmap['salesforce_field']['type'];
@@ -711,114 +711,114 @@  discard block
 block discarded – undo
711 711
 			}
712 712
 
713 713
 			// A WordPress event caused this.
714
-			if ( in_array( $trigger, array_values( $wordpress_haystack ), true ) ) {
714
+			if (in_array($trigger, array_values($wordpress_haystack), true)) {
715 715
 
716 716
 				// Skip fields that aren't updateable when mapping params because Salesforce will error otherwise.
717
-				if ( 1 !== (int) $fieldmap['salesforce_field']['updateable'] ) {
717
+				if (1 !== (int) $fieldmap['salesforce_field']['updateable']) {
718 718
 					continue;
719 719
 				}
720 720
 
721 721
 				// Is the field in WordPress an array, if we unserialize it? Salesforce wants it to be an imploded string.
722
-				if ( is_array( maybe_unserialize( $object[ $wordpress_field ] ) ) ) {
723
-					$object[ $wordpress_field ] = implode( $this->array_delimiter, $object[ $wordpress_field ] );
722
+				if (is_array(maybe_unserialize($object[$wordpress_field]))) {
723
+					$object[$wordpress_field] = implode($this->array_delimiter, $object[$wordpress_field]);
724 724
 				}
725 725
 
726
-				if ( isset( $salesforce_field_type ) ) {
726
+				if (isset($salesforce_field_type)) {
727 727
 					// Is the Salesforce field a date, and is the WordPress value a valid date?
728 728
 					// According to https://salesforce.stackexchange.com/questions/57032/date-format-with-salesforce-rest-api
729
-					if ( in_array( $salesforce_field_type, $this->date_types_from_salesforce ) ) {
730
-						if ( '' === $object[ $wordpress_field ] ) {
731
-							$object[ $wordpress_field ] = null;
729
+					if (in_array($salesforce_field_type, $this->date_types_from_salesforce)) {
730
+						if ('' === $object[$wordpress_field]) {
731
+							$object[$wordpress_field] = null;
732 732
 						} else {
733
-							if ( false !== strtotime( $object[ $wordpress_field ] ) ) {
734
-								$timestamp = strtotime( $object[ $wordpress_field ] );
733
+							if (false !== strtotime($object[$wordpress_field])) {
734
+								$timestamp = strtotime($object[$wordpress_field]);
735 735
 							} else {
736
-								$timestamp = $object[ $wordpress_field ];
736
+								$timestamp = $object[$wordpress_field];
737 737
 							}
738
-							if ( 'datetime' === $salesforce_field_type ) {
739
-								$object[ $wordpress_field ] = date_i18n( 'c', $timestamp );
738
+							if ('datetime' === $salesforce_field_type) {
739
+								$object[$wordpress_field] = date_i18n('c', $timestamp);
740 740
 							} else {
741
-								$object[ $wordpress_field ] = date_i18n( 'Y-m-d', $timestamp );
741
+								$object[$wordpress_field] = date_i18n('Y-m-d', $timestamp);
742 742
 							}
743 743
 						}
744 744
 					}
745 745
 
746 746
 					// Boolean SF fields only want real boolean values. NULL is also not allowed.
747
-					if ( 'boolean' === $salesforce_field_type ) {
748
-						$object[ $wordpress_field ] = (bool) $object[ $wordpress_field ];
747
+					if ('boolean' === $salesforce_field_type) {
748
+						$object[$wordpress_field] = (bool) $object[$wordpress_field];
749 749
 					}
750 750
 				}
751 751
 
752
-				$params[ $salesforce_field ] = $object[ $wordpress_field ];
752
+				$params[$salesforce_field] = $object[$wordpress_field];
753 753
 
754 754
 				// If the field is a key in salesforce, remove it from $params to avoid upsert errors from salesforce,
755 755
 				// but still put its name in the params array so we can check for it later.
756
-				if ( '1' === $fieldmap['is_key'] ) {
757
-					if ( ! $use_soap ) {
758
-						unset( $params[ $salesforce_field ] );
756
+				if ('1' === $fieldmap['is_key']) {
757
+					if ( ! $use_soap) {
758
+						unset($params[$salesforce_field]);
759 759
 					}
760 760
 					$params['key'] = array(
761 761
 						'salesforce_field' => $salesforce_field,
762 762
 						'wordpress_field'  => $wordpress_field,
763
-						'value'            => $object[ $wordpress_field ],
763
+						'value'            => $object[$wordpress_field],
764 764
 					);
765 765
 				}
766 766
 
767 767
 				// If the field is a prematch in salesforce, put its name in the params array so we can check for it later.
768
-				if ( '1' === $fieldmap['is_prematch'] ) {
768
+				if ('1' === $fieldmap['is_prematch']) {
769 769
 					$params['prematch'] = array(
770 770
 						'salesforce_field' => $salesforce_field,
771 771
 						'wordpress_field'  => $wordpress_field,
772
-						'value'            => $object[ $wordpress_field ],
772
+						'value'            => $object[$wordpress_field],
773 773
 					);
774 774
 				}
775
-			} elseif ( in_array( $trigger, $salesforce_haystack, true ) ) {
775
+			} elseif (in_array($trigger, $salesforce_haystack, true)) {
776 776
 
777 777
 				// A salesforce event caused this.
778 778
 
779
-				if ( isset( $salesforce_field_type ) ) {
779
+				if (isset($salesforce_field_type)) {
780 780
 					// Salesforce provides multipicklist values as a delimited string. If the
781 781
 					// destination field in WordPress accepts multiple values, explode the string
782 782
 					// into an array and then serialize it.
783
-					if ( in_array( $salesforce_field_type, $this->array_types_from_salesforce ) ) {
784
-						$object[ $salesforce_field ] = explode( $this->array_delimiter, $object[ $salesforce_field ] );
783
+					if (in_array($salesforce_field_type, $this->array_types_from_salesforce)) {
784
+						$object[$salesforce_field] = explode($this->array_delimiter, $object[$salesforce_field]);
785 785
 					}
786 786
 
787 787
 					// Handle specific data types from Salesforce.
788
-					switch ( $salesforce_field_type ) {
789
-						case ( in_array( $salesforce_field_type, $this->date_types_from_salesforce ) ):
790
-							$format = get_option( 'date_format', 'U' );
791
-							if ( isset( $fieldmap['wordpress_field']['type'] ) && 'datetime' === $fieldmap['wordpress_field']['type'] ) {
788
+					switch ($salesforce_field_type) {
789
+						case (in_array($salesforce_field_type, $this->date_types_from_salesforce)):
790
+							$format = get_option('date_format', 'U');
791
+							if (isset($fieldmap['wordpress_field']['type']) && 'datetime' === $fieldmap['wordpress_field']['type']) {
792 792
 								$format = 'Y-m-d H:i:s';
793 793
 							}
794
-							$object[ $salesforce_field ] = date_i18n( $format, strtotime( $object[ $salesforce_field ] ) );
794
+							$object[$salesforce_field] = date_i18n($format, strtotime($object[$salesforce_field]));
795 795
 							break;
796
-						case ( in_array( $salesforce_field_type, $this->int_types_from_salesforce ) ):
797
-							$object[ $salesforce_field ] = isset( $object[ $salesforce_field ] ) ? (int) $object[ $salesforce_field ] : 0;
796
+						case (in_array($salesforce_field_type, $this->int_types_from_salesforce)):
797
+							$object[$salesforce_field] = isset($object[$salesforce_field]) ? (int) $object[$salesforce_field] : 0;
798 798
 							break;
799 799
 						case 'text':
800
-							$object[ $salesforce_field ] = (string) $object[ $salesforce_field ];
800
+							$object[$salesforce_field] = (string) $object[$salesforce_field];
801 801
 							break;
802 802
 						case 'url':
803
-							$object[ $salesforce_field ] = esc_url_raw( $object[ $salesforce_field ] );
803
+							$object[$salesforce_field] = esc_url_raw($object[$salesforce_field]);
804 804
 							break;
805 805
 					}
806 806
 				}
807 807
 
808 808
 				// Make an array because we need to store the methods for each field as well.
809
-				$params[ $wordpress_field ]          = array();
810
-				$params[ $wordpress_field ]['value'] = $object[ $salesforce_field ];
809
+				$params[$wordpress_field]          = array();
810
+				$params[$wordpress_field]['value'] = $object[$salesforce_field];
811 811
 
812 812
 				// If the field is a key in salesforce, remove it from $params to avoid upsert errors from salesforce,
813 813
 				// but still put its name in the params array so we can check for it later.
814
-				if ( '1' === $fieldmap['is_key'] ) {
815
-					if ( ! $use_soap ) {
816
-						unset( $params[ $wordpress_field ] );
814
+				if ('1' === $fieldmap['is_key']) {
815
+					if ( ! $use_soap) {
816
+						unset($params[$wordpress_field]);
817 817
 					}
818 818
 					$params['key'] = array(
819 819
 						'salesforce_field' => $salesforce_field,
820 820
 						'wordpress_field'  => $wordpress_field,
821
-						'value'            => $object[ $salesforce_field ],
821
+						'value'            => $object[$salesforce_field],
822 822
 						'method_read'      => $fieldmap['wordpress_field']['methods']['read'],
823 823
 						'method_create'    => $fieldmap['wordpress_field']['methods']['create'],
824 824
 						'method_update'    => $fieldmap['wordpress_field']['methods']['update'],
@@ -826,30 +826,30 @@  discard block
 block discarded – undo
826 826
 				}
827 827
 
828 828
 				// If the field is a prematch in salesforce, put its name in the params array so we can check for it later.
829
-				if ( '1' === $fieldmap['is_prematch'] ) {
829
+				if ('1' === $fieldmap['is_prematch']) {
830 830
 					$params['prematch'] = array(
831 831
 						'salesforce_field' => $salesforce_field,
832 832
 						'wordpress_field'  => $wordpress_field,
833
-						'value'            => $object[ $salesforce_field ],
833
+						'value'            => $object[$salesforce_field],
834 834
 						'method_read'      => $fieldmap['wordpress_field']['methods']['read'],
835 835
 						'method_create'    => $fieldmap['wordpress_field']['methods']['create'],
836 836
 						'method_update'    => $fieldmap['wordpress_field']['methods']['update'],
837 837
 					);
838 838
 				}
839 839
 
840
-				switch ( $trigger ) {
840
+				switch ($trigger) {
841 841
 					case $this->sync_sf_create:
842
-						$params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['create'];
842
+						$params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['create'];
843 843
 						break;
844 844
 					case $this->sync_sf_update:
845
-						$params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['update'];
845
+						$params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['update'];
846 846
 						break;
847 847
 					case $this->sync_sf_delete:
848
-						$params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['delete'];
848
+						$params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['delete'];
849 849
 						break;
850 850
 				}
851 851
 
852
-				$params[ $wordpress_field ]['method_read'] = $fieldmap['wordpress_field']['methods']['read'];
852
+				$params[$wordpress_field]['method_read'] = $fieldmap['wordpress_field']['methods']['read'];
853 853
 
854 854
 			} // End if().
855 855
 		} // End foreach().
@@ -866,14 +866,14 @@  discard block
 block discarded – undo
866 866
 	 *
867 867
 	 * @return array $mappings Associative array of field maps ready to use
868 868
 	 */
869
-	private function prepare_fieldmap_data( $mappings, $record_type = '' ) {
870
-
871
-		foreach ( $mappings as $id => $mapping ) {
872
-			$mappings[ $id ]['salesforce_record_types_allowed'] = maybe_unserialize( $mapping['salesforce_record_types_allowed'] );
873
-			$mappings[ $id ]['fields']                          = maybe_unserialize( $mapping['fields'] );
874
-			$mappings[ $id ]['sync_triggers']                   = maybe_unserialize( $mapping['sync_triggers'] );
875
-			if ( '' !== $record_type && ! in_array( $record_type, $mappings[ $id ]['salesforce_record_types_allowed'], true ) ) {
876
-				unset( $mappings[ $id ] );
869
+	private function prepare_fieldmap_data($mappings, $record_type = '') {
870
+
871
+		foreach ($mappings as $id => $mapping) {
872
+			$mappings[$id]['salesforce_record_types_allowed'] = maybe_unserialize($mapping['salesforce_record_types_allowed']);
873
+			$mappings[$id]['fields']                          = maybe_unserialize($mapping['fields']);
874
+			$mappings[$id]['sync_triggers']                   = maybe_unserialize($mapping['sync_triggers']);
875
+			if ('' !== $record_type && ! in_array($record_type, $mappings[$id]['salesforce_record_types_allowed'], true)) {
876
+				unset($mappings[$id]);
877 877
 			}
878 878
 		}
879 879
 
@@ -889,12 +889,12 @@  discard block
 block discarded – undo
889 889
 	public function get_failed_object_maps() {
890 890
 		$table       = $this->object_map_table;
891 891
 		$errors      = array();
892
-		$push_errors = $this->wpdb->get_results( 'SELECT * FROM ' . $table . ' WHERE salesforce_id LIKE "tmp_sf_%"', ARRAY_A );
893
-		$pull_errors = $this->wpdb->get_results( 'SELECT * FROM ' . $table . ' WHERE wordpress_id LIKE "tmp_wp_%"', ARRAY_A );
894
-		if ( ! empty( $push_errors ) ) {
892
+		$push_errors = $this->wpdb->get_results('SELECT * FROM ' . $table . ' WHERE salesforce_id LIKE "tmp_sf_%"', ARRAY_A);
893
+		$pull_errors = $this->wpdb->get_results('SELECT * FROM ' . $table . ' WHERE wordpress_id LIKE "tmp_wp_%"', ARRAY_A);
894
+		if ( ! empty($push_errors)) {
895 895
 			$errors['push_errors'] = $push_errors;
896 896
 		}
897
-		if ( ! empty( $pull_errors ) ) {
897
+		if ( ! empty($pull_errors)) {
898 898
 			$errors['pull_errors'] = $pull_errors;
899 899
 		}
900 900
 		return $errors;
@@ -907,11 +907,11 @@  discard block
 block discarded – undo
907 907
 	 *
908 908
 	 * @return array $error Associative array of single row that failed to finish based on id
909 909
 	 */
910
-	public function get_failed_object_map( $id ) {
910
+	public function get_failed_object_map($id) {
911 911
 		$table     = $this->object_map_table;
912 912
 		$error     = array();
913
-		$error_row = $this->wpdb->get_row( 'SELECT * FROM ' . $table . ' WHERE id = "' . $id . '"', ARRAY_A );
914
-		if ( ! empty( $error_row ) ) {
913
+		$error_row = $this->wpdb->get_row('SELECT * FROM ' . $table . ' WHERE id = "' . $id . '"', ARRAY_A);
914
+		if ( ! empty($error_row)) {
915 915
 			$error = $error_row;
916 916
 		}
917 917
 		return $error;
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
5 5
  * @package Object_Sync_Salesforce
6 6
  */
7 7
 
8
-$_tests_dir = getenv( 'WP_TESTS_DIR' );
9
-if ( ! $_tests_dir ) {
8
+$_tests_dir = getenv('WP_TESTS_DIR');
9
+if ( ! $_tests_dir) {
10 10
 	$_tests_dir = '/tmp/wordpress-tests-lib';
11 11
 }
12 12
 
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
  * Manually load the plugin being tested.
18 18
  */
19 19
 function _manually_load_plugin() {
20
-	require dirname( dirname( __FILE__ ) ) . '/object-sync-for-salesforce.php';
20
+	require dirname(dirname(__FILE__)) . '/object-sync-for-salesforce.php';
21 21
 }
22
-tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
22
+tests_add_filter('muplugins_loaded', '_manually_load_plugin');
23 23
 
24 24
 // Start up the WP testing environment.
25 25
 require $_tests_dir . '/includes/bootstrap.php';
Please login to merge, or discard this patch.
tests/test-sample.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,6 +15,6 @@
 block discarded – undo
15 15
 	 */
16 16
 	function test_sample() {
17 17
 		// Replace this with some actual testing code.
18
-		$this->assertTrue( true );
18
+		$this->assertTrue(true);
19 19
 	}
20 20
 }
Please login to merge, or discard this patch.