@@ -5,7 +5,7 @@ discard block |
||
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 | |
@@ -30,26 +30,26 @@ discard block |
||
30 | 30 | * @param object $logging a Object_Sync_Sf_Logging instance. |
31 | 31 | * @throws \Exception |
32 | 32 | */ |
33 | - public function __construct( $wpdb, $version, $slug, $mappings, $logging ) { |
|
33 | + public function __construct($wpdb, $version, $slug, $mappings, $logging) { |
|
34 | 34 | $this->wpdb = $wpdb; |
35 | 35 | $this->version = $version; |
36 | 36 | $this->slug = $slug; |
37 | 37 | $this->mappings = $mappings; |
38 | 38 | $this->logging = $logging; |
39 | 39 | |
40 | - add_action( 'admin_init', function() { |
|
40 | + add_action('admin_init', function() { |
|
41 | 41 | $this->wordpress_objects = $this->get_object_types(); |
42 | 42 | } ); |
43 | 43 | |
44 | 44 | $this->options = array( |
45 | 45 | 'cache' => true, |
46 | - 'cache_expiration' => $this->cache_expiration( 'wordpress_data_cache', 86400 ), |
|
46 | + 'cache_expiration' => $this->cache_expiration('wordpress_data_cache', 86400), |
|
47 | 47 | 'type' => 'read', |
48 | 48 | ); |
49 | 49 | |
50 | - $this->sfwp_transients = new Object_Sync_Sf_WordPress_Transient( 'sfwp_transients' ); |
|
50 | + $this->sfwp_transients = new Object_Sync_Sf_WordPress_Transient('sfwp_transients'); |
|
51 | 51 | |
52 | - $this->debug = get_option( 'object_sync_for_salesforce_debug_mode', false ); |
|
52 | + $this->debug = get_option('object_sync_for_salesforce_debug_mode', false); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
@@ -77,20 +77,20 @@ discard block |
||
77 | 77 | */ |
78 | 78 | |
79 | 79 | // this should include the available object types and send them to the hook |
80 | - $wordpress_types_not_posts_include = array( 'user', 'comment', 'category', 'tag' ); |
|
81 | - $wordpress_objects = array_merge( get_post_types(), $wordpress_types_not_posts_include ); |
|
80 | + $wordpress_types_not_posts_include = array('user', 'comment', 'category', 'tag'); |
|
81 | + $wordpress_objects = array_merge(get_post_types(), $wordpress_types_not_posts_include); |
|
82 | 82 | // this should be all the objects |
83 | - $wordpress_objects = apply_filters( 'object_sync_for_salesforce_add_more_wordpress_types', $wordpress_objects ); |
|
83 | + $wordpress_objects = apply_filters('object_sync_for_salesforce_add_more_wordpress_types', $wordpress_objects); |
|
84 | 84 | |
85 | 85 | // by default, only remove the log type we use in this plugin |
86 | - $types_to_remove = apply_filters( 'object_sync_for_salesforce_remove_wordpress_types', array( 'wp_log' ) ); |
|
86 | + $types_to_remove = apply_filters('object_sync_for_salesforce_remove_wordpress_types', array('wp_log')); |
|
87 | 87 | |
88 | 88 | // if the hook filters out any types, remove them from the visible list |
89 | - if ( ! empty( $types_to_remove ) ) { |
|
90 | - $wordpress_objects = array_diff( $wordpress_objects, $types_to_remove ); |
|
89 | + if ( ! empty($types_to_remove)) { |
|
90 | + $wordpress_objects = array_diff($wordpress_objects, $types_to_remove); |
|
91 | 91 | } |
92 | 92 | |
93 | - sort( $wordpress_objects ); |
|
93 | + sort($wordpress_objects); |
|
94 | 94 | return $wordpress_objects; |
95 | 95 | } |
96 | 96 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @param string $object_type The type of object. |
101 | 101 | * @return array $object_table_structure The table structure. |
102 | 102 | */ |
103 | - public function get_wordpress_table_structure( $object_type ) { |
|
104 | - if ( 'attachment' === $object_type ) { |
|
103 | + public function get_wordpress_table_structure($object_type) { |
|
104 | + if ('attachment' === $object_type) { |
|
105 | 105 | $object_table_structure = array( |
106 | 106 | 'object_name' => 'post', |
107 | 107 | 'content_methods' => array( |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | 'where' => 'AND ' . $this->wpdb->prefix . 'posts.post_type = "' . $object_type . '"', |
124 | 124 | 'ignore_keys' => array(), |
125 | 125 | ); |
126 | - } elseif ( 'user' === $object_type ) { |
|
126 | + } elseif ('user' === $object_type) { |
|
127 | 127 | // User meta fields need to use update_user_meta for create as well, otherwise it'll just get created twice because apparently when the post is created it's already there. |
128 | 128 | $object_table_structure = array( |
129 | 129 | 'object_name' => 'user', |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'session_tokens', |
151 | 151 | ), |
152 | 152 | ); |
153 | - } elseif ( 'post' === $object_type ) { |
|
153 | + } elseif ('post' === $object_type) { |
|
154 | 154 | $object_table_structure = array( |
155 | 155 | 'object_name' => 'post', |
156 | 156 | 'content_methods' => array( |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | 'where' => 'AND ' . $this->wpdb->prefix . 'posts.post_type = "' . $object_type . '"', |
173 | 173 | 'ignore_keys' => array(), |
174 | 174 | ); |
175 | - } elseif ( 'category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type ) { |
|
175 | + } elseif ('category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type) { |
|
176 | 176 | // I am unsure why post_tag wasn't here for so long, but i figure it probably needs to be there. |
177 | 177 | $object_table_structure = array( |
178 | 178 | 'object_name' => 'term', |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | ), |
191 | 191 | 'content_table' => $this->wpdb->prefix . 'terms', |
192 | 192 | 'id_field' => 'term_id', |
193 | - 'meta_table' => array( $this->wpdb->prefix . 'termmeta', $this->wpdb->prefix . 'term_taxonomy' ), |
|
193 | + 'meta_table' => array($this->wpdb->prefix . 'termmeta', $this->wpdb->prefix . 'term_taxonomy'), |
|
194 | 194 | 'meta_join_field' => 'term_id', |
195 | 195 | 'where' => '', |
196 | 196 | 'ignore_keys' => array(), |
197 | 197 | ); |
198 | - } elseif ( 'comment' === $object_type ) { |
|
198 | + } elseif ('comment' === $object_type) { |
|
199 | 199 | $object_table_structure = array( |
200 | 200 | 'object_name' => 'comment', |
201 | 201 | 'content_methods' => array( |
@@ -251,14 +251,14 @@ discard block |
||
251 | 251 | * @param string $id_field The field of that object that corresponds with its ID in the database. |
252 | 252 | * @return array $object_fields |
253 | 253 | */ |
254 | - public function get_wordpress_object_fields( $wordpress_object, $id_field = 'ID' ) { |
|
254 | + public function get_wordpress_object_fields($wordpress_object, $id_field = 'ID') { |
|
255 | 255 | |
256 | - $object_table_structure = $this->get_wordpress_table_structure( $wordpress_object ); |
|
256 | + $object_table_structure = $this->get_wordpress_table_structure($wordpress_object); |
|
257 | 257 | |
258 | 258 | $meta_table = $object_table_structure['meta_table']; |
259 | - $meta_methods = maybe_unserialize( $object_table_structure['meta_methods'] ); |
|
259 | + $meta_methods = maybe_unserialize($object_table_structure['meta_methods']); |
|
260 | 260 | $content_table = $object_table_structure['content_table']; |
261 | - $content_methods = maybe_unserialize( $object_table_structure['content_methods'] ); |
|
261 | + $content_methods = maybe_unserialize($object_table_structure['content_methods']); |
|
262 | 262 | $id_field = $object_table_structure['id_field']; |
263 | 263 | $object_name = $object_table_structure['object_name']; |
264 | 264 | $where = $object_table_structure['where']; |
@@ -267,23 +267,23 @@ discard block |
||
267 | 267 | $object_fields = array(); |
268 | 268 | |
269 | 269 | // Try to find the object fields in cache before acquiring it from other source. |
270 | - if ( true === $this->options['cache'] && 'write' !== $this->options['cache'] ) { |
|
271 | - $cached = $this->cache_get( $wordpress_object, array( 'data', 'meta' ) ); |
|
272 | - if ( is_array( $cached ) ) { |
|
270 | + if (true === $this->options['cache'] && 'write' !== $this->options['cache']) { |
|
271 | + $cached = $this->cache_get($wordpress_object, array('data', 'meta')); |
|
272 | + if (is_array($cached)) { |
|
273 | 273 | $object_fields['data'] = $cached; |
274 | 274 | $object_fields['from_cache'] = true; |
275 | 275 | $object_fields['cached'] = true; |
276 | 276 | } else { |
277 | - $object_fields['data'] = $this->object_fields( $object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys ); |
|
278 | - if ( ! empty( $object_fields['data'] ) ) { |
|
279 | - $object_fields['cached'] = $this->cache_set( $wordpress_object, array( 'data', 'meta' ), $object_fields['data'], $this->options['cache_expiration'] ); |
|
277 | + $object_fields['data'] = $this->object_fields($object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys); |
|
278 | + if ( ! empty($object_fields['data'])) { |
|
279 | + $object_fields['cached'] = $this->cache_set($wordpress_object, array('data', 'meta'), $object_fields['data'], $this->options['cache_expiration']); |
|
280 | 280 | } else { |
281 | 281 | $object_fields['cached'] = false; |
282 | 282 | } |
283 | 283 | $object_fields['from_cache'] = false; |
284 | 284 | } |
285 | 285 | } else { |
286 | - $object_fields['data'] = $this->object_fields( $object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys ); |
|
286 | + $object_fields['data'] = $this->object_fields($object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys); |
|
287 | 287 | $object_fields['from_cache'] = false; |
288 | 288 | $object_fields['cached'] = false; |
289 | 289 | } |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * $object_fields = array( 'data' => array(), 'from_cache' => bool, 'cached' => bool ); |
295 | 295 | * This is useful for custom objects that do not use the normal metadata table structure. |
296 | 296 | */ |
297 | - $object_fields = apply_filters( 'object_sync_for_salesforce_wordpress_object_fields', $object_fields, $wordpress_object ); |
|
297 | + $object_fields = apply_filters('object_sync_for_salesforce_wordpress_object_fields', $object_fields, $wordpress_object); |
|
298 | 298 | |
299 | 299 | return $object_fields['data']; |
300 | 300 | |
@@ -307,36 +307,36 @@ discard block |
||
307 | 307 | * @param string $object_id The ID of the object. |
308 | 308 | * @return array $wordpress_object |
309 | 309 | */ |
310 | - public function get_wordpress_object_data( $object_type, $object_id ) { |
|
310 | + public function get_wordpress_object_data($object_type, $object_id) { |
|
311 | 311 | |
312 | 312 | $wordpress_object = array(); |
313 | - $object_table_structure = $this->get_wordpress_table_structure( $object_type ); |
|
313 | + $object_table_structure = $this->get_wordpress_table_structure($object_type); |
|
314 | 314 | |
315 | 315 | $meta_table = $object_table_structure['meta_table']; |
316 | - $meta_methods = maybe_unserialize( $object_table_structure['meta_methods'] ); |
|
316 | + $meta_methods = maybe_unserialize($object_table_structure['meta_methods']); |
|
317 | 317 | $content_table = $object_table_structure['content_table']; |
318 | - $content_methods = maybe_unserialize( $object_table_structure['content_methods'] ); |
|
318 | + $content_methods = maybe_unserialize($object_table_structure['content_methods']); |
|
319 | 319 | $id_field = $object_table_structure['id_field']; |
320 | 320 | $object_name = $object_table_structure['object_name']; |
321 | 321 | $where = $object_table_structure['where']; |
322 | 322 | $ignore_keys = $object_table_structure['ignore_keys']; |
323 | 323 | |
324 | - if ( 'user' === $object_type ) { |
|
325 | - $data = get_userdata( $object_id ); |
|
326 | - } elseif ( 'post' === $object_type || 'attachment' === $object_type ) { |
|
327 | - $data = get_post( $object_id ); |
|
328 | - } elseif ( 'category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type ) { |
|
329 | - $data = get_term( $object_id ); |
|
330 | - } elseif ( 'comment' === $object_type ) { |
|
331 | - $data = get_comment( $object_id ); |
|
324 | + if ('user' === $object_type) { |
|
325 | + $data = get_userdata($object_id); |
|
326 | + } elseif ('post' === $object_type || 'attachment' === $object_type) { |
|
327 | + $data = get_post($object_id); |
|
328 | + } elseif ('category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type) { |
|
329 | + $data = get_term($object_id); |
|
330 | + } elseif ('comment' === $object_type) { |
|
331 | + $data = get_comment($object_id); |
|
332 | 332 | } else { // This is for custom post types. |
333 | - $data = get_post( $object_id ); |
|
333 | + $data = get_post($object_id); |
|
334 | 334 | } |
335 | 335 | |
336 | - $fields = $this->get_wordpress_object_fields( $object_type ); |
|
337 | - foreach ( $fields as $key => $value ) { |
|
336 | + $fields = $this->get_wordpress_object_fields($object_type); |
|
337 | + foreach ($fields as $key => $value) { |
|
338 | 338 | $field = $value['key']; |
339 | - $wordpress_object[ $field ] = $data->{$field}; |
|
339 | + $wordpress_object[$field] = $data->{$field}; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /* |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | } |
353 | 353 | */ |
354 | 354 | |
355 | - $wordpress_object = apply_filters( 'object_sync_for_salesforce_wordpress_object_data', $wordpress_object ); |
|
355 | + $wordpress_object = apply_filters('object_sync_for_salesforce_wordpress_object_data', $wordpress_object); |
|
356 | 356 | |
357 | 357 | return $wordpress_object; |
358 | 358 | |
@@ -366,16 +366,16 @@ discard block |
||
366 | 366 | * @param array $args The arguents of the API call. |
367 | 367 | * @return $this->sfwp_transients->get $cachekey |
368 | 368 | */ |
369 | - public function cache_get( $url, $args ) { |
|
370 | - if ( is_array( $args ) ) { |
|
369 | + public function cache_get($url, $args) { |
|
370 | + if (is_array($args)) { |
|
371 | 371 | $args[] = $url; |
372 | - array_multisort( $args ); |
|
372 | + array_multisort($args); |
|
373 | 373 | } else { |
374 | 374 | $args .= $url; |
375 | 375 | } |
376 | 376 | |
377 | - $cachekey = md5( wp_json_encode( $args ) ); |
|
378 | - return $this->sfwp_transients->get( $cachekey ); |
|
377 | + $cachekey = md5(wp_json_encode($args)); |
|
378 | + return $this->sfwp_transients->get($cachekey); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
@@ -388,20 +388,20 @@ discard block |
||
388 | 388 | * @return Bool whether or not the value was set |
389 | 389 | * @link https://wordpress.stackexchange.com/questions/174330/transient-storage-location-database-xcache-w3total-cache |
390 | 390 | */ |
391 | - public function cache_set( $url, $args, $data, $cache_expiration = '' ) { |
|
392 | - if ( is_array( $args ) ) { |
|
391 | + public function cache_set($url, $args, $data, $cache_expiration = '') { |
|
392 | + if (is_array($args)) { |
|
393 | 393 | $args[] = $url; |
394 | - array_multisort( $args ); |
|
394 | + array_multisort($args); |
|
395 | 395 | } else { |
396 | 396 | $args .= $url; |
397 | 397 | } |
398 | - $cachekey = md5( wp_json_encode( $args ) ); |
|
398 | + $cachekey = md5(wp_json_encode($args)); |
|
399 | 399 | // Cache_expiration is how long it should be stored in the cache. |
400 | 400 | // If we didn't give a custom one, use the default. |
401 | - if ( '' === $cache_expiration ) { |
|
401 | + if ('' === $cache_expiration) { |
|
402 | 402 | $cache_expiration = $this->options['cache_expiration']; |
403 | 403 | } |
404 | - return $this->sfwp_transients->set( $cachekey, $data, $cache_expiration ); |
|
404 | + return $this->sfwp_transients->set($cachekey, $data, $cache_expiration); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | * @param int $expire The default time after which to expire the cache. |
413 | 413 | * @return The cache expiration saved in the database. |
414 | 414 | */ |
415 | - public function cache_expiration( $option_key, $expire ) { |
|
416 | - $cache_expiration = get_option( $option_key, $expire ); |
|
415 | + public function cache_expiration($option_key, $expire) { |
|
416 | + $cache_expiration = get_option($option_key, $expire); |
|
417 | 417 | return $cache_expiration; |
418 | 418 | } |
419 | 419 | |
@@ -434,15 +434,15 @@ discard block |
||
434 | 434 | * @param array $ignore_keys Fields to ignore from the database. |
435 | 435 | * @return array $all_fields The fields for the object. |
436 | 436 | */ |
437 | - private function object_fields( $object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys ) { |
|
437 | + private function object_fields($object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys) { |
|
438 | 438 | // These two queries load all the fields from the specified object unless they have been specified as ignore fields. |
439 | 439 | // They also load the fields that are meta_keys from the specified object's meta table. |
440 | 440 | // Maybe a box for a custom query, since custom fields get done in so many ways. |
441 | 441 | // Eventually this would be the kind of thing we could use fields api for, if it ever gets done. |
442 | - $data_fields = $this->wpdb->get_col( "DESC {$content_table}", 0 ); |
|
443 | - $data_field_types = $this->wpdb->get_col( "DESC {$content_table}", 1 ); // get the database field types |
|
442 | + $data_fields = $this->wpdb->get_col("DESC {$content_table}", 0); |
|
443 | + $data_field_types = $this->wpdb->get_col("DESC {$content_table}", 1); // get the database field types |
|
444 | 444 | |
445 | - if ( is_array( $meta_table ) ) { |
|
445 | + if (is_array($meta_table)) { |
|
446 | 446 | $tax_table = $meta_table[1]; |
447 | 447 | $meta_table = $meta_table[0]; |
448 | 448 | } |
@@ -454,39 +454,39 @@ discard block |
||
454 | 454 | WHERE ' . $meta_table . '.meta_key != "" |
455 | 455 | ' . $where . ' |
456 | 456 | '; |
457 | - $meta_fields = $this->wpdb->get_results( $select_meta ); |
|
457 | + $meta_fields = $this->wpdb->get_results($select_meta); |
|
458 | 458 | $all_fields = array(); |
459 | 459 | |
460 | - foreach ( $data_fields as $key => $value ) { |
|
461 | - if ( ! in_array( $value, $ignore_keys, true ) ) { |
|
460 | + foreach ($data_fields as $key => $value) { |
|
461 | + if ( ! in_array($value, $ignore_keys, true)) { |
|
462 | 462 | $all_fields[] = array( |
463 | 463 | 'key' => $value, |
464 | 464 | 'table' => $content_table, |
465 | - 'methods' => serialize( $content_methods ), |
|
466 | - 'type' => $data_field_types[ $key ], |
|
465 | + 'methods' => serialize($content_methods), |
|
466 | + 'type' => $data_field_types[$key], |
|
467 | 467 | ); |
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
471 | - foreach ( $meta_fields as $key => $value ) { |
|
472 | - if ( ! in_array( $value->meta_key, $ignore_keys, true ) ) { |
|
471 | + foreach ($meta_fields as $key => $value) { |
|
472 | + if ( ! in_array($value->meta_key, $ignore_keys, true)) { |
|
473 | 473 | $all_fields[] = array( |
474 | 474 | 'key' => $value->meta_key, |
475 | 475 | 'table' => $meta_table, |
476 | - 'methods' => serialize( $meta_methods ), |
|
476 | + 'methods' => serialize($meta_methods), |
|
477 | 477 | ); |
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | - if ( 'term' === $object_name ) { |
|
482 | - $taxonomy = $this->wpdb->get_col( "DESC {$tax_table}", 0 ); |
|
483 | - foreach ( $taxonomy as $key => $value ) { |
|
484 | - $exists = array_search( $value, array_column( $all_fields, 'key' ), true ); |
|
485 | - if ( 0 !== $exists ) { |
|
481 | + if ('term' === $object_name) { |
|
482 | + $taxonomy = $this->wpdb->get_col("DESC {$tax_table}", 0); |
|
483 | + foreach ($taxonomy as $key => $value) { |
|
484 | + $exists = array_search($value, array_column($all_fields, 'key'), true); |
|
485 | + if (0 !== $exists) { |
|
486 | 486 | $all_fields[] = array( |
487 | 487 | 'key' => $value, |
488 | 488 | 'table' => $tax_table, |
489 | - 'methods' => serialize( $content_methods ), |
|
489 | + 'methods' => serialize($content_methods), |
|
490 | 490 | ); |
491 | 491 | } |
492 | 492 | } |
@@ -513,28 +513,28 @@ discard block |
||
513 | 513 | * |
514 | 514 | * part of CRUD for WordPress objects |
515 | 515 | */ |
516 | - public function object_create( $name, $params ) { |
|
516 | + public function object_create($name, $params) { |
|
517 | 517 | |
518 | - $structure = $this->get_wordpress_table_structure( $name ); |
|
518 | + $structure = $this->get_wordpress_table_structure($name); |
|
519 | 519 | $id_field = $structure['id_field']; |
520 | 520 | |
521 | - switch ( $name ) { |
|
521 | + switch ($name) { |
|
522 | 522 | case 'user': |
523 | - $result = $this->user_create( $params, $id_field ); |
|
523 | + $result = $this->user_create($params, $id_field); |
|
524 | 524 | break; |
525 | 525 | case 'post': |
526 | - $result = $this->post_create( $params, $id_field ); |
|
526 | + $result = $this->post_create($params, $id_field); |
|
527 | 527 | break; |
528 | 528 | case 'attachment': |
529 | - $result = $this->attachment_create( $params, $id_field ); |
|
529 | + $result = $this->attachment_create($params, $id_field); |
|
530 | 530 | break; |
531 | 531 | case 'category': |
532 | 532 | case 'tag': |
533 | 533 | case 'post_tag': |
534 | - $result = $this->term_create( $params, $name, $id_field ); |
|
534 | + $result = $this->term_create($params, $name, $id_field); |
|
535 | 535 | break; |
536 | 536 | case 'comment': |
537 | - $result = $this->comment_create( $params, $id_field ); |
|
537 | + $result = $this->comment_create($params, $id_field); |
|
538 | 538 | break; |
539 | 539 | default: |
540 | 540 | /* |
@@ -547,14 +547,14 @@ discard block |
||
547 | 547 | * the one param is: array( 'name' => objecttype, 'params' => array_of_params, 'id_field' => idfield ) |
548 | 548 | */ |
549 | 549 | // Check to see if someone is calling the filter, and apply it if so. |
550 | - if ( ! has_filter( 'object_sync_for_salesforce_create_custom_wordpress_item' ) ) { |
|
551 | - $result = $this->post_create( $params, $id_field, $name ); |
|
550 | + if ( ! has_filter('object_sync_for_salesforce_create_custom_wordpress_item')) { |
|
551 | + $result = $this->post_create($params, $id_field, $name); |
|
552 | 552 | } else { |
553 | - $result = apply_filters( 'object_sync_for_salesforce_create_custom_wordpress_item', array( |
|
553 | + $result = apply_filters('object_sync_for_salesforce_create_custom_wordpress_item', array( |
|
554 | 554 | 'params' => $params, |
555 | 555 | 'name' => $name, |
556 | 556 | 'id_field' => $id_field, |
557 | - ) ); |
|
557 | + )); |
|
558 | 558 | } |
559 | 559 | break; |
560 | 560 | } // End switch(). |
@@ -590,37 +590,37 @@ discard block |
||
590 | 590 | * |
591 | 591 | * part of CRUD for WordPress objects |
592 | 592 | */ |
593 | - public function object_upsert( $name, $key, $value, $methods = array(), $params, $push_drafts = false, $check_only = false ) { |
|
593 | + public function object_upsert($name, $key, $value, $methods = array(), $params, $push_drafts = false, $check_only = false) { |
|
594 | 594 | |
595 | - $structure = $this->get_wordpress_table_structure( $name ); |
|
595 | + $structure = $this->get_wordpress_table_structure($name); |
|
596 | 596 | $id_field = $structure['id_field']; |
597 | 597 | |
598 | 598 | // If key is set, remove from $params to avoid SQL errors. |
599 | - if ( isset( $params[ $key ] ) ) { |
|
600 | - unset( $params[ $key ] ); |
|
599 | + if (isset($params[$key])) { |
|
600 | + unset($params[$key]); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | // Allow developers to change both the key and value by which objects should be matched. |
604 | - $key = apply_filters( 'object_sync_for_salesforce_modify_upsert_key', $key ); |
|
605 | - $value = apply_filters( 'object_sync_for_salesforce_modify_upsert_value', $value ); |
|
604 | + $key = apply_filters('object_sync_for_salesforce_modify_upsert_key', $key); |
|
605 | + $value = apply_filters('object_sync_for_salesforce_modify_upsert_value', $value); |
|
606 | 606 | |
607 | - switch ( $name ) { |
|
607 | + switch ($name) { |
|
608 | 608 | case 'user': |
609 | - $result = $this->user_upsert( $key, $value, $methods, $params, $id_field, $push_drafts, $check_only ); |
|
609 | + $result = $this->user_upsert($key, $value, $methods, $params, $id_field, $push_drafts, $check_only); |
|
610 | 610 | break; |
611 | 611 | case 'post': |
612 | - $result = $this->post_upsert( $key, $value, $methods, $params, $id_field, $push_drafts, $name, $check_only ); |
|
612 | + $result = $this->post_upsert($key, $value, $methods, $params, $id_field, $push_drafts, $name, $check_only); |
|
613 | 613 | break; |
614 | 614 | case 'attachment': |
615 | - $result = $this->attachment_upsert( $key, $value, $methods, $params, $id_field, $check_only ); |
|
615 | + $result = $this->attachment_upsert($key, $value, $methods, $params, $id_field, $check_only); |
|
616 | 616 | break; |
617 | 617 | case 'category': |
618 | 618 | case 'tag': |
619 | 619 | case 'post_tag': |
620 | - $result = $this->term_upsert( $key, $value, $methods, $params, $name, $id_field, $push_drafts, $check_only ); |
|
620 | + $result = $this->term_upsert($key, $value, $methods, $params, $name, $id_field, $push_drafts, $check_only); |
|
621 | 621 | break; |
622 | 622 | case 'comment': |
623 | - $result = $this->comment_upsert( $key, $value, $methods, $params, $id_field, $push_drafts, $check_only ); |
|
623 | + $result = $this->comment_upsert($key, $value, $methods, $params, $id_field, $push_drafts, $check_only); |
|
624 | 624 | break; |
625 | 625 | default: |
626 | 626 | /* |
@@ -635,10 +635,10 @@ discard block |
||
635 | 635 | * array( 'key' => key, 'value' => value, 'methods' => methods, 'params' => array_of_params, 'id_field' => idfield, 'push_drafts' => pushdrafts, 'name' => name, 'check_only' => $check_only ) |
636 | 636 | */ |
637 | 637 | // Check to see if someone is calling the filter, and apply it if so. |
638 | - if ( ! has_filter( 'object_sync_for_salesforce_upsert_custom_wordpress_item' ) ) { |
|
639 | - $result = $this->post_upsert( $key, $value, $methods, $params, $id_field, $push_drafts, $name, $check_only ); |
|
638 | + if ( ! has_filter('object_sync_for_salesforce_upsert_custom_wordpress_item')) { |
|
639 | + $result = $this->post_upsert($key, $value, $methods, $params, $id_field, $push_drafts, $name, $check_only); |
|
640 | 640 | } else { |
641 | - $result = apply_filters( 'object_sync_for_salesforce_upsert_custom_wordpress_item', array( |
|
641 | + $result = apply_filters('object_sync_for_salesforce_upsert_custom_wordpress_item', array( |
|
642 | 642 | 'key' => $key, |
643 | 643 | 'value' => $value, |
644 | 644 | 'methods' => $methods, |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | 'push_drafts' => $push_drafts, |
648 | 648 | 'name' => $name, |
649 | 649 | 'check_only' => $check_only, |
650 | - ) ); |
|
650 | + )); |
|
651 | 651 | } |
652 | 652 | break; |
653 | 653 | } // End switch(). |
@@ -673,29 +673,29 @@ discard block |
||
673 | 673 | * cached: |
674 | 674 | * is_redo: |
675 | 675 | */ |
676 | - public function object_update( $name, $id, $params ) { |
|
676 | + public function object_update($name, $id, $params) { |
|
677 | 677 | |
678 | - $structure = $this->get_wordpress_table_structure( $name ); |
|
678 | + $structure = $this->get_wordpress_table_structure($name); |
|
679 | 679 | $id_field = $structure['id_field']; |
680 | 680 | |
681 | - switch ( $name ) { |
|
681 | + switch ($name) { |
|
682 | 682 | case 'user': |
683 | 683 | // User id does not come through by default, but we need it to pass to wp method. |
684 | - $result = $this->user_update( $id, $params, $id_field ); |
|
684 | + $result = $this->user_update($id, $params, $id_field); |
|
685 | 685 | break; |
686 | 686 | case 'post': |
687 | - $result = $this->post_update( $id, $params, $id_field ); |
|
687 | + $result = $this->post_update($id, $params, $id_field); |
|
688 | 688 | break; |
689 | 689 | case 'attachment': |
690 | - $result = $this->attachment_update( $id, $params, $id_field ); |
|
690 | + $result = $this->attachment_update($id, $params, $id_field); |
|
691 | 691 | break; |
692 | 692 | case 'category': |
693 | 693 | case 'tag': |
694 | 694 | case 'post_tag': |
695 | - $result = $this->term_update( $id, $params, $name, $id_field ); |
|
695 | + $result = $this->term_update($id, $params, $name, $id_field); |
|
696 | 696 | break; |
697 | 697 | case 'comment': |
698 | - $result = $this->comment_update( $id, $params, $id_field ); |
|
698 | + $result = $this->comment_update($id, $params, $id_field); |
|
699 | 699 | break; |
700 | 700 | default: |
701 | 701 | /* |
@@ -710,15 +710,15 @@ discard block |
||
710 | 710 | * array( 'key' => key, 'value' => value, 'name' => objecttype, 'params' => array_of_params, 'push_drafts' => pushdrafts, 'methods' => methods ) |
711 | 711 | */ |
712 | 712 | // Check to see if someone is calling the filter, and apply it if so. |
713 | - if ( ! has_filter( 'object_sync_for_salesforce_update_custom_wordpress_item' ) ) { |
|
714 | - $result = $this->post_update( $id, $params, $id_field, $name ); |
|
713 | + if ( ! has_filter('object_sync_for_salesforce_update_custom_wordpress_item')) { |
|
714 | + $result = $this->post_update($id, $params, $id_field, $name); |
|
715 | 715 | } else { |
716 | - $result = apply_filters( 'object_sync_for_salesforce_update_custom_wordpress_item', array( |
|
716 | + $result = apply_filters('object_sync_for_salesforce_update_custom_wordpress_item', array( |
|
717 | 717 | 'id' => $id, |
718 | 718 | 'params' => $params, |
719 | 719 | 'name' => $name, |
720 | 720 | 'id_field' => $id_field, |
721 | - ) ); |
|
721 | + )); |
|
722 | 722 | } |
723 | 723 | break; |
724 | 724 | } // End switch(). |
@@ -739,27 +739,27 @@ discard block |
||
739 | 739 | * |
740 | 740 | * part of CRUD for WordPress objects |
741 | 741 | */ |
742 | - public function object_delete( $name, $id ) { |
|
743 | - $structure = $this->get_wordpress_table_structure( $name ); |
|
742 | + public function object_delete($name, $id) { |
|
743 | + $structure = $this->get_wordpress_table_structure($name); |
|
744 | 744 | $id_field = $structure['id_field']; |
745 | 745 | |
746 | - switch ( $name ) { |
|
746 | + switch ($name) { |
|
747 | 747 | case 'user': |
748 | - $success = $this->user_delete( $id ); |
|
748 | + $success = $this->user_delete($id); |
|
749 | 749 | break; |
750 | 750 | case 'post': |
751 | - $success = $this->post_delete( $id ); |
|
751 | + $success = $this->post_delete($id); |
|
752 | 752 | break; |
753 | 753 | case 'attachment': |
754 | - $success = $this->attachment_delete( $id ); |
|
754 | + $success = $this->attachment_delete($id); |
|
755 | 755 | break; |
756 | 756 | case 'category': |
757 | 757 | case 'tag': |
758 | 758 | case 'post_tag': |
759 | - $success = $this->term_delete( $id, $name ); |
|
759 | + $success = $this->term_delete($id, $name); |
|
760 | 760 | break; |
761 | 761 | case 'comment': |
762 | - $success = $this->comment_delete( $id ); |
|
762 | + $success = $this->comment_delete($id); |
|
763 | 763 | break; |
764 | 764 | default: |
765 | 765 | /* |
@@ -771,16 +771,16 @@ discard block |
||
771 | 771 | * array( 'id' => id, 'name' => objecttype ) |
772 | 772 | */ |
773 | 773 | // Check to see if someone is calling the filter, and apply it if so. |
774 | - if ( ! has_filter( 'object_sync_for_salesforce_delete_custom_wordpress_item' ) ) { |
|
775 | - $success = $this->post_delete( $id ); |
|
774 | + if ( ! has_filter('object_sync_for_salesforce_delete_custom_wordpress_item')) { |
|
775 | + $success = $this->post_delete($id); |
|
776 | 776 | } else { |
777 | - $success = apply_filters( 'object_sync_for_salesforce_delete_custom_wordpress_item', array( |
|
777 | + $success = apply_filters('object_sync_for_salesforce_delete_custom_wordpress_item', array( |
|
778 | 778 | 'id' => $id, |
779 | 779 | 'name' => $name, |
780 | - ) ); |
|
780 | + )); |
|
781 | 781 | } |
782 | 782 | |
783 | - $success = $this->post_delete( $id ); |
|
783 | + $success = $this->post_delete($id); |
|
784 | 784 | break; |
785 | 785 | } // End switch(). |
786 | 786 | |
@@ -805,13 +805,13 @@ discard block |
||
805 | 805 | * success: 1 |
806 | 806 | * "errors" : [ ], |
807 | 807 | */ |
808 | - private function user_create( $params, $id_field = 'ID' ) { |
|
808 | + private function user_create($params, $id_field = 'ID') { |
|
809 | 809 | |
810 | 810 | // Allow username to be email address or username. |
811 | 811 | // The username could be autogenerated before this point for the sake of URLs. |
812 | 812 | $username = $params['user_email']['value']; |
813 | 813 | $email_address = $params['user_email']['value']; |
814 | - if ( isset( $params['user_login']['value'] ) ) { // User_login is used by username_exists. |
|
814 | + if (isset($params['user_login']['value'])) { // User_login is used by username_exists. |
|
815 | 815 | $username = $params['user_login']['value']; |
816 | 816 | } else { |
817 | 817 | $params['user_login'] = array( |
@@ -822,44 +822,44 @@ discard block |
||
822 | 822 | } |
823 | 823 | |
824 | 824 | // This is a new user. |
825 | - if ( false === username_exists( $username ) ) { |
|
825 | + if (false === username_exists($username)) { |
|
826 | 826 | |
827 | 827 | // Create the user |
828 | 828 | // WordPress sends a password reset link so this password doesn't get used, but it does exist in the database, which is helpful to prevent access before the user uses their password reset email. |
829 | 829 | $params['user_pass'] = array( |
830 | - 'value' => wp_generate_password( 12, false ), |
|
830 | + 'value' => wp_generate_password(12, false), |
|
831 | 831 | 'method_modify' => 'wp_insert_user', |
832 | 832 | 'method_read' => 'get_user_by', |
833 | 833 | ); |
834 | 834 | // Load all params with a method_modify of the object structure's content_method into $content |
835 | 835 | $content = array(); |
836 | - $structure = $this->get_wordpress_table_structure( 'user' ); |
|
837 | - foreach ( $params as $key => $value ) { |
|
838 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) ) { |
|
839 | - $content[ $key ] = $value['value']; |
|
840 | - unset( $params[ $key ] ); |
|
836 | + $structure = $this->get_wordpress_table_structure('user'); |
|
837 | + foreach ($params as $key => $value) { |
|
838 | + if (in_array($value['method_modify'], $structure['content_methods'])) { |
|
839 | + $content[$key] = $value['value']; |
|
840 | + unset($params[$key]); |
|
841 | 841 | } |
842 | 842 | } |
843 | 843 | |
844 | - $user_id = wp_insert_user( $content ); |
|
844 | + $user_id = wp_insert_user($content); |
|
845 | 845 | |
846 | - if ( is_wp_error( $user_id ) ) { |
|
846 | + if (is_wp_error($user_id)) { |
|
847 | 847 | $success = false; |
848 | 848 | $errors = $user_id; |
849 | 849 | } else { |
850 | 850 | $success = true; |
851 | 851 | $errors = array(); |
852 | - foreach ( $params as $key => $value ) { |
|
852 | + foreach ($params as $key => $value) { |
|
853 | 853 | $method = $value['method_modify']; |
854 | 854 | // we need to provide a way for passing the values in a custom order here |
855 | - $meta_id = $method( $user_id, $key, $value['value'] ); |
|
856 | - if ( false === $meta_id ) { |
|
855 | + $meta_id = $method($user_id, $key, $value['value']); |
|
856 | + if (false === $meta_id) { |
|
857 | 857 | $success = false; |
858 | 858 | $errors[] = array( |
859 | 859 | 'message' => sprintf( |
860 | 860 | // translators: %1$s is a method name. |
861 | - esc_html__( 'Tried to upsert meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
862 | - esc_html( $method ) |
|
861 | + esc_html__('Tried to upsert meta with method %1$s.', 'object-sync-for-salesforce'), |
|
862 | + esc_html($method) |
|
863 | 863 | ), |
864 | 864 | 'key' => $key, |
865 | 865 | 'value' => $value, |
@@ -868,18 +868,18 @@ discard block |
||
868 | 868 | } |
869 | 869 | |
870 | 870 | // Developers can use this hook to set any other user data - permissions, etc. |
871 | - do_action( 'object_sync_for_salesforce_set_more_user_data', $user_id, $params, 'create' ); |
|
871 | + do_action('object_sync_for_salesforce_set_more_user_data', $user_id, $params, 'create'); |
|
872 | 872 | |
873 | 873 | // Send notification of new user. |
874 | 874 | // todo: Figure out what permissions ought to get notifications for this and make sure it works the right way. |
875 | - wp_new_user_notification( $user_id, null, 'admin user' ); |
|
875 | + wp_new_user_notification($user_id, null, 'admin user'); |
|
876 | 876 | |
877 | 877 | } |
878 | 878 | } else { |
879 | - $user_id = username_exists( $username ); |
|
879 | + $user_id = username_exists($username); |
|
880 | 880 | } // End if(). |
881 | 881 | |
882 | - if ( is_wp_error( $user_id ) ) { |
|
882 | + if (is_wp_error($user_id)) { |
|
883 | 883 | $success = false; |
884 | 884 | $errors = $user_id; |
885 | 885 | } else { |
@@ -916,47 +916,47 @@ discard block |
||
916 | 916 | * success: 1 |
917 | 917 | * "errors" : [ ], |
918 | 918 | */ |
919 | - private function user_upsert( $key, $value, $methods = array(), $params, $id_field = 'ID', $push_drafts = false, $check_only = false ) { |
|
919 | + private function user_upsert($key, $value, $methods = array(), $params, $id_field = 'ID', $push_drafts = false, $check_only = false) { |
|
920 | 920 | |
921 | 921 | // If the key is user_email, we need to make it just email because that is how the WordPress method reads it. |
922 | 922 | $method = $methods['method_match']; |
923 | - if ( '' !== $method ) { |
|
923 | + if ('' !== $method) { |
|
924 | 924 | // This should give us the user object. |
925 | - $user = $method( str_replace( 'user_', '', $key ), $value ); |
|
926 | - if ( isset( $user->{$id_field} ) ) { |
|
925 | + $user = $method(str_replace('user_', '', $key), $value); |
|
926 | + if (isset($user->{$id_field} )) { |
|
927 | 927 | // User does exist after checking the matching value. we want its id. |
928 | 928 | $user_id = $user->{$id_field}; |
929 | 929 | |
930 | - if ( true === $check_only ) { |
|
930 | + if (true === $check_only) { |
|
931 | 931 | // We are just checking to see if there is a match. |
932 | 932 | return $user_id; |
933 | 933 | } |
934 | 934 | |
935 | 935 | // On the prematch fields, we specify the method_update param. |
936 | - if ( isset( $methods['method_update'] ) ) { |
|
936 | + if (isset($methods['method_update'])) { |
|
937 | 937 | $method = $methods['method_update']; |
938 | 938 | } else { |
939 | 939 | $method = $methods['method_modify']; |
940 | 940 | } |
941 | - $params[ $key ] = array( |
|
941 | + $params[$key] = array( |
|
942 | 942 | 'value' => $value, |
943 | 943 | 'method_modify' => $method, |
944 | 944 | 'method_read' => $methods['method_read'], |
945 | 945 | ); |
946 | - } elseif ( false === $check_only ) { |
|
946 | + } elseif (false === $check_only) { |
|
947 | 947 | // User does not exist after checking the matching value. create it. |
948 | 948 | // On the prematch fields, we specify the method_create param. |
949 | - if ( isset( $methods['method_create'] ) ) { |
|
949 | + if (isset($methods['method_create'])) { |
|
950 | 950 | $method = $methods['method_create']; |
951 | 951 | } else { |
952 | 952 | $method = $methods['method_modify']; |
953 | 953 | } |
954 | - $params[ $key ] = array( |
|
954 | + $params[$key] = array( |
|
955 | 955 | 'value' => $value, |
956 | 956 | 'method_modify' => $method, |
957 | 957 | 'method_read' => $methods['method_read'], |
958 | 958 | ); |
959 | - $result = $this->user_create( $params ); |
|
959 | + $result = $this->user_create($params); |
|
960 | 960 | return $result; |
961 | 961 | } else { |
962 | 962 | // Check only is true but there's not a user yet. |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | } // End if(). |
965 | 965 | } else { |
966 | 966 | // There is no method by which to check the user. we can check other ways here. |
967 | - $params[ $key ] = array( |
|
967 | + $params[$key] = array( |
|
968 | 968 | 'value' => $value, |
969 | 969 | 'method_modify' => $methods['method_modify'], |
970 | 970 | 'method_read' => $methods['method_read'], |
@@ -972,21 +972,21 @@ discard block |
||
972 | 972 | |
973 | 973 | // Allow username to be email address or username. |
974 | 974 | // The username could be autogenerated before this point for the sake of URLs. |
975 | - if ( isset( $params['user_email']['value'] ) ) { |
|
975 | + if (isset($params['user_email']['value'])) { |
|
976 | 976 | $username = $params['user_email']['value']; |
977 | 977 | $email_address = $params['user_email']['value']; |
978 | 978 | } |
979 | - if ( isset( $params['user_login']['value'] ) ) { // user_login is used by username_exists. |
|
979 | + if (isset($params['user_login']['value'])) { // user_login is used by username_exists. |
|
980 | 980 | $username = $params['user_login']['value']; |
981 | 981 | } |
982 | 982 | |
983 | - $existing_id = username_exists( $username ); // Returns an id if there is a result. |
|
983 | + $existing_id = username_exists($username); // Returns an id if there is a result. |
|
984 | 984 | |
985 | 985 | // User does not exist after more checking. we want to create it. |
986 | - if ( false === $existing_id && false === $check_only ) { |
|
987 | - $result = $this->user_create( $params ); |
|
986 | + if (false === $existing_id && false === $check_only) { |
|
987 | + $result = $this->user_create($params); |
|
988 | 988 | return $result; |
989 | - } elseif ( true === $check_only ) { |
|
989 | + } elseif (true === $check_only) { |
|
990 | 990 | // We are just checking to see if there is a match. |
991 | 991 | return $existing_id; |
992 | 992 | } else { |
@@ -995,23 +995,23 @@ discard block |
||
995 | 995 | } |
996 | 996 | } // End if(). |
997 | 997 | |
998 | - if ( isset( $user_id ) ) { |
|
999 | - foreach ( $params as $key => $value ) { |
|
1000 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
998 | + if (isset($user_id)) { |
|
999 | + foreach ($params as $key => $value) { |
|
1000 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
1001 | 1001 | } |
1002 | - $result = $this->user_update( $user_id, $params ); |
|
1002 | + $result = $this->user_update($user_id, $params); |
|
1003 | 1003 | return $result; |
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | // Create log entry for lack of a user id. |
1007 | - if ( isset( $this->logging ) ) { |
|
1007 | + if (isset($this->logging)) { |
|
1008 | 1008 | $logging = $this->logging; |
1009 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1010 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1009 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1010 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1011 | 1011 | } |
1012 | 1012 | $logging->setup( |
1013 | 1013 | // todo: can we get any more specific about this? |
1014 | - esc_html__( 'Error: Users: Tried to run user_upsert, and ended up without a user id', 'object-sync-for-salesforce' ), |
|
1014 | + esc_html__('Error: Users: Tried to run user_upsert, and ended up without a user id', 'object-sync-for-salesforce'), |
|
1015 | 1015 | '', |
1016 | 1016 | 0, |
1017 | 1017 | 0, |
@@ -1032,28 +1032,28 @@ discard block |
||
1032 | 1032 | * success: 1 |
1033 | 1033 | * "errors" : [ ], |
1034 | 1034 | */ |
1035 | - private function user_update( $user_id, $params, $id_field = 'ID' ) { |
|
1035 | + private function user_update($user_id, $params, $id_field = 'ID') { |
|
1036 | 1036 | $content = array(); |
1037 | - $content[ $id_field ] = $user_id; |
|
1038 | - foreach ( $params as $key => $value ) { |
|
1039 | - if ( 'wp_update_user' === $value['method_modify'] ) { |
|
1040 | - $content[ $key ] = $value['value']; |
|
1041 | - unset( $params[ $key ] ); |
|
1037 | + $content[$id_field] = $user_id; |
|
1038 | + foreach ($params as $key => $value) { |
|
1039 | + if ('wp_update_user' === $value['method_modify']) { |
|
1040 | + $content[$key] = $value['value']; |
|
1041 | + unset($params[$key]); |
|
1042 | 1042 | } |
1043 | 1043 | } |
1044 | 1044 | |
1045 | - $user_id = wp_update_user( $content ); |
|
1045 | + $user_id = wp_update_user($content); |
|
1046 | 1046 | |
1047 | - if ( is_wp_error( $user_id ) ) { |
|
1047 | + if (is_wp_error($user_id)) { |
|
1048 | 1048 | $success = false; |
1049 | 1049 | $errors = $user_id; |
1050 | 1050 | } else { |
1051 | 1051 | $success = true; |
1052 | 1052 | $errors = array(); |
1053 | - foreach ( $params as $key => $value ) { |
|
1053 | + foreach ($params as $key => $value) { |
|
1054 | 1054 | $method = $value['method_modify']; |
1055 | - $meta_id = $method( $user_id, $key, $value['value'] ); |
|
1056 | - if ( false === $meta_id ) { |
|
1055 | + $meta_id = $method($user_id, $key, $value['value']); |
|
1056 | + if (false === $meta_id) { |
|
1057 | 1057 | $success = false; |
1058 | 1058 | $errors[] = array( |
1059 | 1059 | 'key' => $key, |
@@ -1063,7 +1063,7 @@ discard block |
||
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | // Developers can use this hook to set any other user data - permissions, etc. |
1066 | - do_action( 'object_sync_for_salesforce_set_more_user_data', $user_id, $params, 'update' ); |
|
1066 | + do_action('object_sync_for_salesforce_set_more_user_data', $user_id, $params, 'update'); |
|
1067 | 1067 | |
1068 | 1068 | } |
1069 | 1069 | |
@@ -1085,10 +1085,10 @@ discard block |
||
1085 | 1085 | * |
1086 | 1086 | * @return boolean true if successful |
1087 | 1087 | */ |
1088 | - private function user_delete( $id, $reassign = null ) { |
|
1088 | + private function user_delete($id, $reassign = null) { |
|
1089 | 1089 | // According to https://codex.wordpress.org/Function_Reference/wp_delete_user we have to include user.php first; otherwise it throws undefined error. |
1090 | - require_once( './wp-admin/includes/user.php' ); |
|
1091 | - $result = wp_delete_user( $id, $reassign ); |
|
1090 | + require_once('./wp-admin/includes/user.php'); |
|
1091 | + $result = wp_delete_user($id, $reassign); |
|
1092 | 1092 | return $result; |
1093 | 1093 | } |
1094 | 1094 | |
@@ -1105,18 +1105,18 @@ discard block |
||
1105 | 1105 | * success: 1 |
1106 | 1106 | * "errors" : [ ], |
1107 | 1107 | */ |
1108 | - private function post_create( $params, $id_field = 'ID', $post_type = 'post' ) { |
|
1108 | + private function post_create($params, $id_field = 'ID', $post_type = 'post') { |
|
1109 | 1109 | // Load all params with a method_modify of the object structure's content_method into $content |
1110 | 1110 | $content = array(); |
1111 | - $structure = $this->get_wordpress_table_structure( $post_type ); |
|
1112 | - foreach ( $params as $key => $value ) { |
|
1113 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) ) { |
|
1114 | - $content[ $key ] = $value['value']; |
|
1115 | - unset( $params[ $key ] ); |
|
1111 | + $structure = $this->get_wordpress_table_structure($post_type); |
|
1112 | + foreach ($params as $key => $value) { |
|
1113 | + if (in_array($value['method_modify'], $structure['content_methods'])) { |
|
1114 | + $content[$key] = $value['value']; |
|
1115 | + unset($params[$key]); |
|
1116 | 1116 | } |
1117 | 1117 | } |
1118 | 1118 | |
1119 | - if ( '' !== $post_type ) { |
|
1119 | + if ('' !== $post_type) { |
|
1120 | 1120 | $content['post_type'] = $post_type; |
1121 | 1121 | } |
1122 | 1122 | |
@@ -1124,31 +1124,31 @@ discard block |
||
1124 | 1124 | // I think we should allow this to happen and not make users' data decisions, so |
1125 | 1125 | // if we're receiving nothing for either of these, create a blank one so it doesn't fail |
1126 | 1126 | // here we have to use $content because $params has already been unset |
1127 | - if ( ! isset( $content['post_title'] ) ) { |
|
1127 | + if ( ! isset($content['post_title'])) { |
|
1128 | 1128 | $content['post_title'] = ' '; |
1129 | 1129 | } |
1130 | - if ( ! isset( $content['post_content'] ) ) { |
|
1130 | + if ( ! isset($content['post_content'])) { |
|
1131 | 1131 | $content['post_content'] = ' '; |
1132 | 1132 | } |
1133 | 1133 | |
1134 | - $post_id = wp_insert_post( $content, true ); // return an error instead of a 0 id |
|
1134 | + $post_id = wp_insert_post($content, true); // return an error instead of a 0 id |
|
1135 | 1135 | |
1136 | - if ( is_wp_error( $post_id ) ) { |
|
1136 | + if (is_wp_error($post_id)) { |
|
1137 | 1137 | $success = false; |
1138 | 1138 | $errors = $post_id; |
1139 | 1139 | } else { |
1140 | 1140 | $success = true; |
1141 | 1141 | $errors = array(); |
1142 | 1142 | // If it's a custom post type, fix the methods. |
1143 | - if ( isset( $params['RecordTypeId']['value'] ) ) { |
|
1143 | + if (isset($params['RecordTypeId']['value'])) { |
|
1144 | 1144 | $params['RecordTypeId']['method_modify'] = 'update_post_meta'; |
1145 | 1145 | $params['RecordTypeId']['method_read'] = 'get_post_meta'; |
1146 | 1146 | } |
1147 | - if ( is_array( $params ) && ! empty( $params ) ) { |
|
1148 | - foreach ( $params as $key => $value ) { |
|
1147 | + if (is_array($params) && ! empty($params)) { |
|
1148 | + foreach ($params as $key => $value) { |
|
1149 | 1149 | $method = $value['method_modify']; |
1150 | - $meta_id = $method( $post_id, $key, $value['value'] ); |
|
1151 | - if ( false === $meta_id ) { |
|
1150 | + $meta_id = $method($post_id, $key, $value['value']); |
|
1151 | + if (false === $meta_id) { |
|
1152 | 1152 | $success = false; |
1153 | 1153 | $errors[] = array( |
1154 | 1154 | 'key' => $key, |
@@ -1159,11 +1159,11 @@ discard block |
||
1159 | 1159 | } |
1160 | 1160 | |
1161 | 1161 | // Developers can use this hook to set any other post data. |
1162 | - do_action( 'object_sync_for_salesforce_set_more_post_data', $post_id, $params, 'create' ); |
|
1162 | + do_action('object_sync_for_salesforce_set_more_post_data', $post_id, $params, 'create'); |
|
1163 | 1163 | |
1164 | 1164 | } |
1165 | 1165 | |
1166 | - if ( is_wp_error( $post_id ) ) { |
|
1166 | + if (is_wp_error($post_id)) { |
|
1167 | 1167 | $success = false; |
1168 | 1168 | $errors = $post_id; |
1169 | 1169 | } else { |
@@ -1201,68 +1201,68 @@ discard block |
||
1201 | 1201 | * success: 1 |
1202 | 1202 | * "errors" : [ ], |
1203 | 1203 | */ |
1204 | - private function post_upsert( $key, $value, $methods = array(), $params, $id_field = 'ID', $push_drafts = false, $post_type = 'post', $check_only = false ) { |
|
1204 | + private function post_upsert($key, $value, $methods = array(), $params, $id_field = 'ID', $push_drafts = false, $post_type = 'post', $check_only = false) { |
|
1205 | 1205 | |
1206 | 1206 | $method = $methods['method_match']; |
1207 | 1207 | |
1208 | - if ( '' !== $method ) { |
|
1208 | + if ('' !== $method) { |
|
1209 | 1209 | // By default, posts use get_posts as the method. args can be like this. |
1210 | 1210 | // The args don't really make sense, and are inconsistently documented. |
1211 | 1211 | // This should give us the post object. |
1212 | 1212 | $args = array(); |
1213 | - if ( 'post_title' === $key ) { |
|
1213 | + if ('post_title' === $key) { |
|
1214 | 1214 | $params['post_title'] = array( |
1215 | 1215 | 'value' => $value, |
1216 | 1216 | 'method_modify' => $method, |
1217 | 1217 | 'method_read' => $methods['method_read'], |
1218 | 1218 | ); |
1219 | - $args['name'] = sanitize_title( $value ); |
|
1219 | + $args['name'] = sanitize_title($value); |
|
1220 | 1220 | } else { |
1221 | - $args[ $key ] = $value; |
|
1221 | + $args[$key] = $value; |
|
1222 | 1222 | } |
1223 | 1223 | $args['post_type'] = $post_type; |
1224 | - $post_statuses = array( 'publish' ); |
|
1225 | - if ( true === $push_drafts ) { |
|
1224 | + $post_statuses = array('publish'); |
|
1225 | + if (true === $push_drafts) { |
|
1226 | 1226 | $post_statuses[] = 'draft'; |
1227 | 1227 | } |
1228 | 1228 | $args['post_status'] = $post_statuses; |
1229 | 1229 | |
1230 | - $posts = $method( $args ); |
|
1230 | + $posts = $method($args); |
|
1231 | 1231 | |
1232 | - if ( isset( $posts[0]->{$id_field} ) ) { |
|
1232 | + if (isset($posts[0]->{$id_field} )) { |
|
1233 | 1233 | // Post does exist after checking the matching value. We want its id. |
1234 | 1234 | $post_id = $posts[0]->{$id_field}; |
1235 | 1235 | |
1236 | - if ( true === $check_only ) { |
|
1236 | + if (true === $check_only) { |
|
1237 | 1237 | // We are just checking to see if there is a match. |
1238 | 1238 | return $post_id; |
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | // On the prematch fields, we specify the method_update param. |
1242 | - if ( isset( $methods['method_update'] ) ) { |
|
1242 | + if (isset($methods['method_update'])) { |
|
1243 | 1243 | $method = $methods['method_update']; |
1244 | 1244 | } else { |
1245 | 1245 | $method = $methods['method_modify']; |
1246 | 1246 | } |
1247 | - $params[ $key ] = array( |
|
1247 | + $params[$key] = array( |
|
1248 | 1248 | 'value' => $value, |
1249 | 1249 | 'method_modify' => $method, |
1250 | 1250 | 'method_read' => $methods['method_read'], |
1251 | 1251 | ); |
1252 | - } elseif ( false === $check_only ) { |
|
1252 | + } elseif (false === $check_only) { |
|
1253 | 1253 | // Post does not exist after checking the matching value. create it. |
1254 | 1254 | // On the prematch fields, we specify the method_create param. |
1255 | - if ( isset( $methods['method_create'] ) ) { |
|
1255 | + if (isset($methods['method_create'])) { |
|
1256 | 1256 | $method = $methods['method_create']; |
1257 | 1257 | } else { |
1258 | 1258 | $method = $methods['method_modify']; |
1259 | 1259 | } |
1260 | - $params[ $key ] = array( |
|
1260 | + $params[$key] = array( |
|
1261 | 1261 | 'value' => $value, |
1262 | 1262 | 'method_modify' => $method, |
1263 | 1263 | 'method_read' => $methods['method_read'], |
1264 | 1264 | ); |
1265 | - $result = $this->post_create( $params, $id_field, $post_type ); |
|
1265 | + $result = $this->post_create($params, $id_field, $post_type); |
|
1266 | 1266 | return $result; |
1267 | 1267 | } else { |
1268 | 1268 | // Check only is true but there's not a post yet. |
@@ -1270,38 +1270,38 @@ discard block |
||
1270 | 1270 | } // End if(). |
1271 | 1271 | } else { |
1272 | 1272 | // There is no method by which to check the post. we can check other ways here. |
1273 | - $params[ $key ] = array( |
|
1273 | + $params[$key] = array( |
|
1274 | 1274 | 'value' => $value, |
1275 | 1275 | 'method_modify' => $methods['method_modify'], |
1276 | 1276 | 'method_read' => $methods['method_read'], |
1277 | 1277 | ); |
1278 | 1278 | |
1279 | 1279 | // If we have a title, use it to check for existing post. |
1280 | - if ( isset( $params['post_title']['value'] ) ) { |
|
1280 | + if (isset($params['post_title']['value'])) { |
|
1281 | 1281 | $title = $params['post_title']['value']; |
1282 | 1282 | } |
1283 | 1283 | |
1284 | 1284 | // If we have content, use it to check for existing post. |
1285 | - if ( isset( $params['post_content']['value'] ) ) { |
|
1285 | + if (isset($params['post_content']['value'])) { |
|
1286 | 1286 | $content = $params['post_content']['value']; |
1287 | 1287 | } else { |
1288 | 1288 | $content = ''; |
1289 | 1289 | } |
1290 | 1290 | |
1291 | 1291 | // If we have a date, use it to check for existing post. |
1292 | - if ( isset( $params['post_date']['value'] ) ) { |
|
1292 | + if (isset($params['post_date']['value'])) { |
|
1293 | 1293 | $date = $params['post_date']['value']; |
1294 | 1294 | } else { |
1295 | 1295 | $date = ''; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | - $existing_id = post_exists( $title, $content, $date ); // Returns an id if there is a result. Returns 0 if not. |
|
1298 | + $existing_id = post_exists($title, $content, $date); // Returns an id if there is a result. Returns 0 if not. |
|
1299 | 1299 | |
1300 | 1300 | // Post does not exist after more checking. maybe we want to create it. |
1301 | - if ( 0 === $existing_id && false === $check_only ) { |
|
1302 | - $result = $this->post_create( $params, $id_field, $post_type ); |
|
1301 | + if (0 === $existing_id && false === $check_only) { |
|
1302 | + $result = $this->post_create($params, $id_field, $post_type); |
|
1303 | 1303 | return $result; |
1304 | - } elseif ( true === $check_only ) { |
|
1304 | + } elseif (true === $check_only) { |
|
1305 | 1305 | // We are just checking to see if there is a match. |
1306 | 1306 | return $existing_id; |
1307 | 1307 | } else { |
@@ -1313,22 +1313,22 @@ discard block |
||
1313 | 1313 | |
1314 | 1314 | } // End if(). |
1315 | 1315 | |
1316 | - if ( isset( $post_id ) ) { |
|
1317 | - foreach ( $params as $key => $value ) { |
|
1318 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
1316 | + if (isset($post_id)) { |
|
1317 | + foreach ($params as $key => $value) { |
|
1318 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
1319 | 1319 | } |
1320 | - $result = $this->post_update( $post_id, $params, $id_field, $post_type ); |
|
1320 | + $result = $this->post_update($post_id, $params, $id_field, $post_type); |
|
1321 | 1321 | return $result; |
1322 | 1322 | } |
1323 | 1323 | // Create log entry for lack of a post id. |
1324 | - if ( isset( $this->logging ) ) { |
|
1324 | + if (isset($this->logging)) { |
|
1325 | 1325 | $logging = $this->logging; |
1326 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1327 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1326 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1327 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1328 | 1328 | } |
1329 | 1329 | $logging->setup( |
1330 | 1330 | // todo: can we be more explicit here about what post upsert failed? |
1331 | - esc_html__( 'Error: Posts: Tried to run post_upsert, and ended up without a post id', 'object-sync-for-salesforce' ), |
|
1331 | + esc_html__('Error: Posts: Tried to run post_upsert, and ended up without a post id', 'object-sync-for-salesforce'), |
|
1332 | 1332 | '', |
1333 | 1333 | 0, |
1334 | 1334 | 0, |
@@ -1350,38 +1350,38 @@ discard block |
||
1350 | 1350 | * success: 1 |
1351 | 1351 | * "errors" : [ ], |
1352 | 1352 | */ |
1353 | - private function post_update( $post_id, $params, $id_field = 'ID', $post_type = '' ) { |
|
1353 | + private function post_update($post_id, $params, $id_field = 'ID', $post_type = '') { |
|
1354 | 1354 | $content = array(); |
1355 | - $content[ $id_field ] = $post_id; |
|
1356 | - foreach ( $params as $key => $value ) { |
|
1357 | - if ( 'wp_update_post' === $value['method_modify'] ) { |
|
1358 | - $content[ $key ] = $value['value']; |
|
1359 | - unset( $params[ $key ] ); |
|
1355 | + $content[$id_field] = $post_id; |
|
1356 | + foreach ($params as $key => $value) { |
|
1357 | + if ('wp_update_post' === $value['method_modify']) { |
|
1358 | + $content[$key] = $value['value']; |
|
1359 | + unset($params[$key]); |
|
1360 | 1360 | } |
1361 | 1361 | } |
1362 | 1362 | |
1363 | - if ( '' !== $post_type ) { |
|
1363 | + if ('' !== $post_type) { |
|
1364 | 1364 | $content['post_type'] = $post_type; |
1365 | 1365 | } |
1366 | 1366 | |
1367 | - $post_id = wp_update_post( $content, true ); // return an error instead of a 0 id |
|
1367 | + $post_id = wp_update_post($content, true); // return an error instead of a 0 id |
|
1368 | 1368 | |
1369 | - if ( is_wp_error( $post_id ) ) { |
|
1369 | + if (is_wp_error($post_id)) { |
|
1370 | 1370 | $success = false; |
1371 | 1371 | $errors = $post_id; |
1372 | 1372 | } else { |
1373 | 1373 | $success = true; |
1374 | 1374 | $errors = array(); |
1375 | 1375 | // If it's a custom post type, fix the methods. |
1376 | - if ( isset( $params['RecordTypeId']['value'] ) ) { |
|
1376 | + if (isset($params['RecordTypeId']['value'])) { |
|
1377 | 1377 | $params['RecordTypeId']['method_modify'] = 'update_post_meta'; |
1378 | 1378 | $params['RecordTypeId']['method_read'] = 'get_post_meta'; |
1379 | 1379 | } |
1380 | - if ( is_array( $params ) && ! empty( $params ) ) { |
|
1381 | - foreach ( $params as $key => $value ) { |
|
1380 | + if (is_array($params) && ! empty($params)) { |
|
1381 | + foreach ($params as $key => $value) { |
|
1382 | 1382 | $method = $value['method_modify']; |
1383 | - $meta_id = $method( $post_id, $key, $value['value'] ); |
|
1384 | - if ( false === $meta_id ) { |
|
1383 | + $meta_id = $method($post_id, $key, $value['value']); |
|
1384 | + if (false === $meta_id) { |
|
1385 | 1385 | $success = false; |
1386 | 1386 | $errors[] = array( |
1387 | 1387 | 'key' => $key, |
@@ -1392,7 +1392,7 @@ discard block |
||
1392 | 1392 | } |
1393 | 1393 | |
1394 | 1394 | // Developers can use this hook to set any other post data. |
1395 | - do_action( 'object_sync_for_salesforce_set_more_post_data', $post_id, $params, 'update' ); |
|
1395 | + do_action('object_sync_for_salesforce_set_more_post_data', $post_id, $params, 'update'); |
|
1396 | 1396 | |
1397 | 1397 | } |
1398 | 1398 | |
@@ -1414,8 +1414,8 @@ discard block |
||
1414 | 1414 | * |
1415 | 1415 | * @return mixed post object if successful, false if failed |
1416 | 1416 | */ |
1417 | - private function post_delete( $id, $force_delete = false ) { |
|
1418 | - $result = wp_delete_post( $id, $force_delete ); |
|
1417 | + private function post_delete($id, $force_delete = false) { |
|
1418 | + $result = wp_delete_post($id, $force_delete); |
|
1419 | 1419 | return $result; |
1420 | 1420 | } |
1421 | 1421 | |
@@ -1431,56 +1431,56 @@ discard block |
||
1431 | 1431 | * success: 1 |
1432 | 1432 | * "errors" : [ ], |
1433 | 1433 | */ |
1434 | - private function attachment_create( $params, $id_field = 'ID' ) { |
|
1434 | + private function attachment_create($params, $id_field = 'ID') { |
|
1435 | 1435 | // Load all params with a method_modify of the object structure's content_method into $content |
1436 | 1436 | $content = array(); |
1437 | - $structure = $this->get_wordpress_table_structure( 'attachment' ); |
|
1437 | + $structure = $this->get_wordpress_table_structure('attachment'); |
|
1438 | 1438 | // WP requires post_title, post_content (can be empty), post_status, and post_mime_type to create an attachment. |
1439 | - foreach ( $params as $key => $value ) { |
|
1440 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) ) { |
|
1441 | - $content[ $key ] = $value['value']; |
|
1442 | - unset( $params[ $key ] ); |
|
1439 | + foreach ($params as $key => $value) { |
|
1440 | + if (in_array($value['method_modify'], $structure['content_methods'])) { |
|
1441 | + $content[$key] = $value['value']; |
|
1442 | + unset($params[$key]); |
|
1443 | 1443 | } |
1444 | 1444 | } |
1445 | 1445 | |
1446 | 1446 | // Developers can use this hook to pass filename and parent data for the attachment. |
1447 | - $params = apply_filters( 'object_sync_for_salesforce_set_initial_attachment_data', $params ); |
|
1447 | + $params = apply_filters('object_sync_for_salesforce_set_initial_attachment_data', $params); |
|
1448 | 1448 | |
1449 | - if ( isset( $params['filename']['value'] ) ) { |
|
1449 | + if (isset($params['filename']['value'])) { |
|
1450 | 1450 | $filename = $params['filename']['value']; |
1451 | 1451 | } else { |
1452 | 1452 | $filename = false; |
1453 | 1453 | } |
1454 | 1454 | |
1455 | - if ( isset( $params['parent']['value'] ) ) { |
|
1455 | + if (isset($params['parent']['value'])) { |
|
1456 | 1456 | $parent = $params['parent']['value']; |
1457 | 1457 | } else { |
1458 | 1458 | $parent = 0; |
1459 | 1459 | } |
1460 | 1460 | |
1461 | - $attachment_id = wp_insert_attachment( $content, $filename, $parent ); |
|
1461 | + $attachment_id = wp_insert_attachment($content, $filename, $parent); |
|
1462 | 1462 | |
1463 | - if ( is_wp_error( $attachment_id ) ) { |
|
1463 | + if (is_wp_error($attachment_id)) { |
|
1464 | 1464 | $success = false; |
1465 | 1465 | $errors = $attachment_id; |
1466 | 1466 | } else { |
1467 | 1467 | $success = true; |
1468 | 1468 | $errors = array(); |
1469 | 1469 | |
1470 | - if ( false !== $filename ) { |
|
1470 | + if (false !== $filename) { |
|
1471 | 1471 | // According to https://codex.wordpress.org/Function_Reference/wp_insert_attachment we need this file. |
1472 | - require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
1472 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1473 | 1473 | // Generate metadata for the attachment. |
1474 | - $attach_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
1475 | - wp_update_attachment_metadata( $attachment_id, $attach_data ); |
|
1474 | + $attach_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
1475 | + wp_update_attachment_metadata($attachment_id, $attach_data); |
|
1476 | 1476 | } |
1477 | 1477 | |
1478 | - if ( 0 !== $parent ) { |
|
1479 | - set_post_thumbnail( $parent_post_id, $attachment_id ); |
|
1478 | + if (0 !== $parent) { |
|
1479 | + set_post_thumbnail($parent_post_id, $attachment_id); |
|
1480 | 1480 | } |
1481 | 1481 | |
1482 | 1482 | // Developers can use this hook to set any other attachment data. |
1483 | - do_action( 'object_sync_for_salesforce_set_more_attachment_data', $attachment_id, $params, 'create' ); |
|
1483 | + do_action('object_sync_for_salesforce_set_more_attachment_data', $attachment_id, $params, 'create'); |
|
1484 | 1484 | |
1485 | 1485 | } |
1486 | 1486 | |
@@ -1512,64 +1512,64 @@ discard block |
||
1512 | 1512 | * success: 1 |
1513 | 1513 | * "errors" : [ ], |
1514 | 1514 | */ |
1515 | - private function attachment_upsert( $key, $value, $methods = array(), $params, $id_field = 'ID', $check_only = false ) { |
|
1515 | + private function attachment_upsert($key, $value, $methods = array(), $params, $id_field = 'ID', $check_only = false) { |
|
1516 | 1516 | |
1517 | 1517 | $method = $methods['method_match']; |
1518 | 1518 | |
1519 | - if ( '' !== $method ) { |
|
1519 | + if ('' !== $method) { |
|
1520 | 1520 | // Get_posts is more helpful here, so that is the method attachment uses for 'read'. |
1521 | 1521 | // By default, posts use get_posts as the method. args can be like this. |
1522 | 1522 | // The args don't really make sense, and are inconsistently documented. |
1523 | 1523 | // This should give us the post object. |
1524 | 1524 | $args = array(); |
1525 | - if ( 'post_title' === $key ) { |
|
1525 | + if ('post_title' === $key) { |
|
1526 | 1526 | $params['post_title'] = array( |
1527 | 1527 | 'value' => $value, |
1528 | 1528 | 'method_modify' => $method, |
1529 | 1529 | 'method_read' => $methods['method_read'], |
1530 | 1530 | ); |
1531 | - $args['name'] = sanitize_title( $value ); |
|
1531 | + $args['name'] = sanitize_title($value); |
|
1532 | 1532 | } else { |
1533 | - $args[ $key ] = $value; |
|
1533 | + $args[$key] = $value; |
|
1534 | 1534 | } |
1535 | 1535 | $args['post_type'] = 'attachment'; |
1536 | 1536 | |
1537 | - $posts = $method( $args ); |
|
1537 | + $posts = $method($args); |
|
1538 | 1538 | |
1539 | - if ( isset( $posts[0]->{$id_field} ) ) { |
|
1539 | + if (isset($posts[0]->{$id_field} )) { |
|
1540 | 1540 | // Attachment does exist after checking the matching value. we want its id. |
1541 | 1541 | $attachment_id = $posts[0]->{$id_field}; |
1542 | 1542 | |
1543 | - if ( true === $check_only ) { |
|
1543 | + if (true === $check_only) { |
|
1544 | 1544 | // We are just checking to see if there is a match. |
1545 | 1545 | return $attachment_id; |
1546 | 1546 | } |
1547 | 1547 | |
1548 | 1548 | // On the prematch fields, we specify the method_update param. |
1549 | - if ( isset( $methods['method_update'] ) ) { |
|
1549 | + if (isset($methods['method_update'])) { |
|
1550 | 1550 | $method = $methods['method_update']; |
1551 | 1551 | } else { |
1552 | 1552 | $method = $methods['method_modify']; |
1553 | 1553 | } |
1554 | - $params[ $key ] = array( |
|
1554 | + $params[$key] = array( |
|
1555 | 1555 | 'value' => $value, |
1556 | 1556 | 'method_modify' => $method, |
1557 | 1557 | 'method_read' => $methods['method_read'], |
1558 | 1558 | ); |
1559 | - } elseif ( false === $check_only ) { |
|
1559 | + } elseif (false === $check_only) { |
|
1560 | 1560 | // Attachment does not exist after checking the matching value. create it. |
1561 | 1561 | // On the prematch fields, we specify the method_create param. |
1562 | - if ( isset( $methods['method_create'] ) ) { |
|
1562 | + if (isset($methods['method_create'])) { |
|
1563 | 1563 | $method = $methods['method_create']; |
1564 | 1564 | } else { |
1565 | 1565 | $method = $methods['method_modify']; |
1566 | 1566 | } |
1567 | - $params[ $key ] = array( |
|
1567 | + $params[$key] = array( |
|
1568 | 1568 | 'value' => $value, |
1569 | 1569 | 'method_modify' => $method, |
1570 | 1570 | 'method_read' => $methods['method_read'], |
1571 | 1571 | ); |
1572 | - $result = $this->attachment_create( $params ); |
|
1572 | + $result = $this->attachment_create($params); |
|
1573 | 1573 | return $result; |
1574 | 1574 | } else { |
1575 | 1575 | // Check only is true but there's not an attachment yet. |
@@ -1577,38 +1577,38 @@ discard block |
||
1577 | 1577 | } // End if(). |
1578 | 1578 | } else { |
1579 | 1579 | // There is no method by which to check the post. we can check other ways here. |
1580 | - $params[ $key ] = array( |
|
1580 | + $params[$key] = array( |
|
1581 | 1581 | 'value' => $value, |
1582 | 1582 | 'method_modify' => $methods['method_modify'], |
1583 | 1583 | 'method_read' => $methods['method_read'], |
1584 | 1584 | ); |
1585 | 1585 | |
1586 | 1586 | // If we have a title, use it to check for existing post. |
1587 | - if ( isset( $params['post_title']['value'] ) ) { |
|
1587 | + if (isset($params['post_title']['value'])) { |
|
1588 | 1588 | $title = $params['post_title']['value']; |
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | // If we have content, use it to check for existing post. |
1592 | - if ( isset( $params['post_content']['value'] ) ) { |
|
1592 | + if (isset($params['post_content']['value'])) { |
|
1593 | 1593 | $content = $params['post_content']['value']; |
1594 | 1594 | } else { |
1595 | 1595 | $content = ''; |
1596 | 1596 | } |
1597 | 1597 | |
1598 | 1598 | // If we have a date, use it to check for existing post. |
1599 | - if ( isset( $params['post_date']['value'] ) ) { |
|
1599 | + if (isset($params['post_date']['value'])) { |
|
1600 | 1600 | $date = $params['post_date']['value']; |
1601 | 1601 | } else { |
1602 | 1602 | $date = ''; |
1603 | 1603 | } |
1604 | 1604 | |
1605 | - $existing_id = post_exists( $title, $content, $date ); // Returns an id if there is a result. Returns 0 if not. |
|
1605 | + $existing_id = post_exists($title, $content, $date); // Returns an id if there is a result. Returns 0 if not. |
|
1606 | 1606 | |
1607 | 1607 | // Attachment does not exist after more checking. maybe we want to create it. |
1608 | - if ( 0 === $existing_id && false === $check_only ) { |
|
1609 | - $result = $this->attachment_create( $params ); |
|
1608 | + if (0 === $existing_id && false === $check_only) { |
|
1609 | + $result = $this->attachment_create($params); |
|
1610 | 1610 | return $result; |
1611 | - } elseif ( true === $check_only ) { |
|
1611 | + } elseif (true === $check_only) { |
|
1612 | 1612 | // We are just checking to see if there is a match. |
1613 | 1613 | return $existing_id; |
1614 | 1614 | } else { |
@@ -1620,22 +1620,22 @@ discard block |
||
1620 | 1620 | |
1621 | 1621 | } // End if(). |
1622 | 1622 | |
1623 | - if ( isset( $attachment_id ) ) { |
|
1624 | - foreach ( $params as $key => $value ) { |
|
1625 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
1623 | + if (isset($attachment_id)) { |
|
1624 | + foreach ($params as $key => $value) { |
|
1625 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
1626 | 1626 | } |
1627 | - $result = $this->attachment_update( $attachment_id, $params ); |
|
1627 | + $result = $this->attachment_update($attachment_id, $params); |
|
1628 | 1628 | return $result; |
1629 | 1629 | } |
1630 | 1630 | |
1631 | 1631 | // Create log entry for lack of an attachment id. |
1632 | - if ( isset( $this->logging ) ) { |
|
1632 | + if (isset($this->logging)) { |
|
1633 | 1633 | $logging = $this->logging; |
1634 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1635 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1634 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1635 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1636 | 1636 | } |
1637 | 1637 | $logging->setup( |
1638 | - esc_html__( 'Error: Attachment: Tried to run attachment_upsert, and ended up without an attachment id', 'object-sync-for-salesforce' ), |
|
1638 | + esc_html__('Error: Attachment: Tried to run attachment_upsert, and ended up without an attachment id', 'object-sync-for-salesforce'), |
|
1639 | 1639 | '', |
1640 | 1640 | 0, |
1641 | 1641 | 0, |
@@ -1660,60 +1660,60 @@ discard block |
||
1660 | 1660 | * it does use wp_update_attachment_metadata for the meta fields, though. |
1661 | 1661 | * Developers should use hooks to change this, if it does not meet their needs. |
1662 | 1662 | */ |
1663 | - private function attachment_update( $attachment_id, $params, $id_field = 'ID' ) { |
|
1663 | + private function attachment_update($attachment_id, $params, $id_field = 'ID') { |
|
1664 | 1664 | $content = array(); |
1665 | - $content[ $id_field ] = $attachment_id; |
|
1666 | - foreach ( $params as $key => $value ) { |
|
1667 | - if ( 'wp_insert_attachment' === $value['method_modify'] ) { // Should also be insert attachment maybe. |
|
1668 | - $content[ $key ] = $value['value']; |
|
1669 | - unset( $params[ $key ] ); |
|
1665 | + $content[$id_field] = $attachment_id; |
|
1666 | + foreach ($params as $key => $value) { |
|
1667 | + if ('wp_insert_attachment' === $value['method_modify']) { // Should also be insert attachment maybe. |
|
1668 | + $content[$key] = $value['value']; |
|
1669 | + unset($params[$key]); |
|
1670 | 1670 | } |
1671 | 1671 | } |
1672 | 1672 | |
1673 | - if ( isset( $params['filename']['value'] ) ) { |
|
1673 | + if (isset($params['filename']['value'])) { |
|
1674 | 1674 | $filename = $params['filename']['value']; |
1675 | 1675 | } else { |
1676 | 1676 | $filename = false; |
1677 | 1677 | } |
1678 | 1678 | |
1679 | - if ( isset( $params['parent']['value'] ) ) { |
|
1679 | + if (isset($params['parent']['value'])) { |
|
1680 | 1680 | $parent = $params['parent']['value']; |
1681 | 1681 | } else { |
1682 | 1682 | $parent = 0; |
1683 | 1683 | } |
1684 | 1684 | |
1685 | - $attachment_id = wp_insert_attachment( $content, $filename, $parent ); |
|
1685 | + $attachment_id = wp_insert_attachment($content, $filename, $parent); |
|
1686 | 1686 | |
1687 | - if ( is_wp_error( $attachment_id ) ) { |
|
1687 | + if (is_wp_error($attachment_id)) { |
|
1688 | 1688 | $success = false; |
1689 | 1689 | $errors = $attachment_id; |
1690 | 1690 | } else { |
1691 | 1691 | $success = true; |
1692 | 1692 | $errors = array(); |
1693 | 1693 | |
1694 | - if ( false !== $filename ) { |
|
1694 | + if (false !== $filename) { |
|
1695 | 1695 | // According to https://codex.wordpress.org/Function_Reference/wp_insert_attachment we need this file. |
1696 | - require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
1696 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1697 | 1697 | // Generate metadata for the attachment. |
1698 | - $attach_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
1698 | + $attach_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
1699 | 1699 | } |
1700 | 1700 | |
1701 | 1701 | // Put the data from salesforce into the meta array. |
1702 | 1702 | $attach_new_data = array(); |
1703 | - foreach ( $params as $key => $value ) { |
|
1703 | + foreach ($params as $key => $value) { |
|
1704 | 1704 | $method = $value['method_modify']; |
1705 | - $attach_new_data[ $key ] = $value['value']; |
|
1705 | + $attach_new_data[$key] = $value['value']; |
|
1706 | 1706 | } |
1707 | 1707 | |
1708 | - if ( isset( $attach_data ) ) { |
|
1709 | - $attach_data = array_merge( $attach_data, $attach_new_data ); |
|
1708 | + if (isset($attach_data)) { |
|
1709 | + $attach_data = array_merge($attach_data, $attach_new_data); |
|
1710 | 1710 | } else { |
1711 | 1711 | $attach_data = $attach_new_data; |
1712 | 1712 | } |
1713 | 1713 | |
1714 | - $meta_updated = wp_update_attachment_metadata( $attachment_id, $attach_data ); |
|
1714 | + $meta_updated = wp_update_attachment_metadata($attachment_id, $attach_data); |
|
1715 | 1715 | |
1716 | - if ( false === $meta_updated ) { |
|
1716 | + if (false === $meta_updated) { |
|
1717 | 1717 | $success = false; |
1718 | 1718 | $errors[] = array( |
1719 | 1719 | 'key' => $key, |
@@ -1721,12 +1721,12 @@ discard block |
||
1721 | 1721 | ); |
1722 | 1722 | } |
1723 | 1723 | |
1724 | - if ( 0 !== $parent ) { |
|
1725 | - set_post_thumbnail( $parent_post_id, $attachment_id ); |
|
1724 | + if (0 !== $parent) { |
|
1725 | + set_post_thumbnail($parent_post_id, $attachment_id); |
|
1726 | 1726 | } |
1727 | 1727 | |
1728 | 1728 | // Developers can use this hook to set any other attachment data. |
1729 | - do_action( 'object_sync_for_salesforce_set_more_attachment_data', $attachment_id, $params, 'update' ); |
|
1729 | + do_action('object_sync_for_salesforce_set_more_attachment_data', $attachment_id, $params, 'update'); |
|
1730 | 1730 | |
1731 | 1731 | } // End if(). |
1732 | 1732 | |
@@ -1749,8 +1749,8 @@ discard block |
||
1749 | 1749 | * @return mixed |
1750 | 1750 | * attachment object if successful, false if failed |
1751 | 1751 | */ |
1752 | - private function attachment_delete( $id, $force_delete = false ) { |
|
1753 | - $result = wp_delete_attachment( $id, $force_delete ); |
|
1752 | + private function attachment_delete($id, $force_delete = false) { |
|
1753 | + $result = wp_delete_attachment($id, $force_delete); |
|
1754 | 1754 | return $result; |
1755 | 1755 | } |
1756 | 1756 | |
@@ -1767,45 +1767,45 @@ discard block |
||
1767 | 1767 | * success: 1 |
1768 | 1768 | * "errors" : [ ], |
1769 | 1769 | */ |
1770 | - private function term_create( $params, $taxonomy, $id_field = 'ID' ) { |
|
1771 | - if ( 'tag' === $taxonomy ) { |
|
1770 | + private function term_create($params, $taxonomy, $id_field = 'ID') { |
|
1771 | + if ('tag' === $taxonomy) { |
|
1772 | 1772 | $taxonomy = 'post_tag'; |
1773 | 1773 | } |
1774 | 1774 | // Load all params with a method_modify of the object structure's content_method into $content |
1775 | 1775 | $content = array(); |
1776 | - $structure = $this->get_wordpress_table_structure( $taxonomy ); |
|
1776 | + $structure = $this->get_wordpress_table_structure($taxonomy); |
|
1777 | 1777 | $args = array(); |
1778 | - foreach ( $params as $key => $value ) { |
|
1779 | - if ( 'name' === $key ) { |
|
1778 | + foreach ($params as $key => $value) { |
|
1779 | + if ('name' === $key) { |
|
1780 | 1780 | $name = $value['value']; |
1781 | - unset( $params[ $key ] ); |
|
1781 | + unset($params[$key]); |
|
1782 | 1782 | } |
1783 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) && 'name' !== $key ) { |
|
1784 | - $args[ $key ] = $value['value']; |
|
1785 | - unset( $params[ $key ] ); |
|
1783 | + if (in_array($value['method_modify'], $structure['content_methods']) && 'name' !== $key) { |
|
1784 | + $args[$key] = $value['value']; |
|
1785 | + unset($params[$key]); |
|
1786 | 1786 | } |
1787 | 1787 | } |
1788 | - if ( isset( $name ) ) { |
|
1789 | - $term = wp_insert_term( $name, $taxonomy, $args ); |
|
1788 | + if (isset($name)) { |
|
1789 | + $term = wp_insert_term($name, $taxonomy, $args); |
|
1790 | 1790 | } |
1791 | 1791 | |
1792 | - if ( is_wp_error( $term ) ) { |
|
1792 | + if (is_wp_error($term)) { |
|
1793 | 1793 | $success = false; |
1794 | 1794 | $errors = $term; |
1795 | 1795 | } else { |
1796 | - $term_id = $term[ "$id_field" ]; |
|
1796 | + $term_id = $term["$id_field"]; |
|
1797 | 1797 | $success = true; |
1798 | 1798 | $errors = array(); |
1799 | - foreach ( $params as $key => $value ) { |
|
1799 | + foreach ($params as $key => $value) { |
|
1800 | 1800 | $method = $value['method_modify']; |
1801 | - $meta_id = $method( $term_id, $key, $value['value'] ); |
|
1802 | - if ( false === $meta_id ) { |
|
1801 | + $meta_id = $method($term_id, $key, $value['value']); |
|
1802 | + if (false === $meta_id) { |
|
1803 | 1803 | $success = false; |
1804 | 1804 | $errors[] = array( |
1805 | 1805 | 'message' => sprintf( |
1806 | 1806 | // translators: %1$s is a method name. |
1807 | - esc_html__( 'Tried to upsert meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
1808 | - esc_html( $method ) |
|
1807 | + esc_html__('Tried to upsert meta with method %1$s.', 'object-sync-for-salesforce'), |
|
1808 | + esc_html($method) |
|
1809 | 1809 | ), |
1810 | 1810 | 'key' => $key, |
1811 | 1811 | 'value' => $value, |
@@ -1814,11 +1814,11 @@ discard block |
||
1814 | 1814 | } |
1815 | 1815 | |
1816 | 1816 | // Developers can use this hook to set any other term data. |
1817 | - do_action( 'object_sync_for_salesforce_set_more_term_data', $term_id, $params, 'create' ); |
|
1817 | + do_action('object_sync_for_salesforce_set_more_term_data', $term_id, $params, 'create'); |
|
1818 | 1818 | |
1819 | 1819 | } |
1820 | 1820 | |
1821 | - if ( is_wp_error( $term ) ) { |
|
1821 | + if (is_wp_error($term)) { |
|
1822 | 1822 | $success = false; |
1823 | 1823 | $errors = $term; |
1824 | 1824 | } else { |
@@ -1856,48 +1856,48 @@ discard block |
||
1856 | 1856 | * success: 1 |
1857 | 1857 | * "errors" : [ ], |
1858 | 1858 | */ |
1859 | - private function term_upsert( $key, $value, $methods = array(), $params, $taxonomy, $id_field = 'ID', $push_drafts = false, $check_only = false ) { |
|
1860 | - if ( 'tag' === $taxonomy ) { |
|
1859 | + private function term_upsert($key, $value, $methods = array(), $params, $taxonomy, $id_field = 'ID', $push_drafts = false, $check_only = false) { |
|
1860 | + if ('tag' === $taxonomy) { |
|
1861 | 1861 | $taxonomy = 'post_tag'; |
1862 | 1862 | } |
1863 | 1863 | $method = $methods['method_match']; |
1864 | - if ( '' !== $method ) { |
|
1864 | + if ('' !== $method) { |
|
1865 | 1865 | // This should give us the term object. |
1866 | - $term = $method( $key, $value, $taxonomy ); // We need to put the taxonomy in there probably. |
|
1867 | - if ( isset( $term->{$id_field} ) ) { |
|
1866 | + $term = $method($key, $value, $taxonomy); // We need to put the taxonomy in there probably. |
|
1867 | + if (isset($term->{$id_field} )) { |
|
1868 | 1868 | // Term does exist after checking the matching value. we want its id. |
1869 | 1869 | $term_id = $term->{$id_field}; |
1870 | 1870 | |
1871 | - if ( true === $check_only ) { |
|
1871 | + if (true === $check_only) { |
|
1872 | 1872 | // We are just checking to see if there is a match. |
1873 | 1873 | return $term_id; |
1874 | 1874 | } |
1875 | 1875 | |
1876 | 1876 | // On the prematch fields, we specify the method_update param. |
1877 | - if ( isset( $methods['method_update'] ) ) { |
|
1877 | + if (isset($methods['method_update'])) { |
|
1878 | 1878 | $method = $methods['method_update']; |
1879 | 1879 | } else { |
1880 | 1880 | $method = $methods['method_modify']; |
1881 | 1881 | } |
1882 | - $params[ $key ] = array( |
|
1882 | + $params[$key] = array( |
|
1883 | 1883 | 'value' => $value, |
1884 | 1884 | 'method_modify' => $method, |
1885 | 1885 | 'method_read' => $methods['method_read'], |
1886 | 1886 | ); |
1887 | - } elseif ( false === $check_only ) { |
|
1887 | + } elseif (false === $check_only) { |
|
1888 | 1888 | // Term does not exist after checking the matching value. Create it. |
1889 | 1889 | // On the prematch fields, we specify the method_create param. |
1890 | - if ( isset( $methods['method_create'] ) ) { |
|
1890 | + if (isset($methods['method_create'])) { |
|
1891 | 1891 | $method = $methods['method_create']; |
1892 | 1892 | } else { |
1893 | 1893 | $method = $methods['method_modify']; |
1894 | 1894 | } |
1895 | - $params[ $key ] = array( |
|
1895 | + $params[$key] = array( |
|
1896 | 1896 | 'value' => $value, |
1897 | 1897 | 'method_modify' => $method, |
1898 | 1898 | 'method_read' => $methods['method_read'], |
1899 | 1899 | ); |
1900 | - $result = $this->term_create( $params, $taxonomy, $id_field ); |
|
1900 | + $result = $this->term_create($params, $taxonomy, $id_field); |
|
1901 | 1901 | return $result; |
1902 | 1902 | } else { |
1903 | 1903 | // Check only is true but there's not a term yet. |
@@ -1905,17 +1905,17 @@ discard block |
||
1905 | 1905 | } // End if(). |
1906 | 1906 | } else { |
1907 | 1907 | // There is no method by which to check the term. we can check other ways here. |
1908 | - $params[ $key ] = array( |
|
1908 | + $params[$key] = array( |
|
1909 | 1909 | 'value' => $value, |
1910 | 1910 | 'method_modify' => $methods['method_modify'], |
1911 | 1911 | 'method_read' => $methods['method_read'], |
1912 | 1912 | ); |
1913 | 1913 | |
1914 | - if ( isset( $params['name']['value'] ) ) { |
|
1914 | + if (isset($params['name']['value'])) { |
|
1915 | 1915 | $term = $params['name']['value']; |
1916 | 1916 | } |
1917 | 1917 | |
1918 | - if ( isset( $params['parent']['value'] ) ) { |
|
1918 | + if (isset($params['parent']['value'])) { |
|
1919 | 1919 | $parent = $params['parent']['value']; |
1920 | 1920 | } else { |
1921 | 1921 | $parent = 0; |
@@ -1923,17 +1923,17 @@ discard block |
||
1923 | 1923 | |
1924 | 1924 | // Returns an id if there is a result. Returns null if it does not exist. |
1925 | 1925 | // wpcom_vip_term_exists is cached, and therefore preferred. |
1926 | - if ( function_exists( 'wpcom_vip_term_exists' ) ) { |
|
1927 | - $existing_id = wpcom_vip_term_exists( $term, $taxonomy, $parent ); |
|
1926 | + if (function_exists('wpcom_vip_term_exists')) { |
|
1927 | + $existing_id = wpcom_vip_term_exists($term, $taxonomy, $parent); |
|
1928 | 1928 | } else { |
1929 | - $existing_id = term_exists( $term, $taxonomy, $parent ); |
|
1929 | + $existing_id = term_exists($term, $taxonomy, $parent); |
|
1930 | 1930 | } |
1931 | 1931 | |
1932 | 1932 | // Term does not exist after more checking. maybe we want to create it. |
1933 | - if ( null === $existing_id && false === $check_only ) { |
|
1934 | - $result = $this->term_create( $params, $taxonomy, $id_field ); |
|
1933 | + if (null === $existing_id && false === $check_only) { |
|
1934 | + $result = $this->term_create($params, $taxonomy, $id_field); |
|
1935 | 1935 | return $result; |
1936 | - } elseif ( true === $check_only ) { |
|
1936 | + } elseif (true === $check_only) { |
|
1937 | 1937 | // We are just checking to see if there is a match. |
1938 | 1938 | return $existing_id; |
1939 | 1939 | } else { |
@@ -1942,21 +1942,21 @@ discard block |
||
1942 | 1942 | } |
1943 | 1943 | } // End if(). |
1944 | 1944 | |
1945 | - if ( isset( $term_id ) ) { |
|
1946 | - foreach ( $params as $key => $value ) { |
|
1947 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
1945 | + if (isset($term_id)) { |
|
1946 | + foreach ($params as $key => $value) { |
|
1947 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
1948 | 1948 | } |
1949 | - $result = $this->term_update( $term_id, $params, $taxonomy, $id_field ); |
|
1949 | + $result = $this->term_update($term_id, $params, $taxonomy, $id_field); |
|
1950 | 1950 | return $result; |
1951 | 1951 | } |
1952 | 1952 | // Create log entry for lack of a term id. |
1953 | - if ( isset( $this->logging ) ) { |
|
1953 | + if (isset($this->logging)) { |
|
1954 | 1954 | $logging = $this->logging; |
1955 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1956 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1955 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1956 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1957 | 1957 | } |
1958 | 1958 | $logging->setup( |
1959 | - esc_html__( 'Error: Terms: Tried to run term_upsert, and ended up without a term id', 'object-sync-for-salesforce' ), |
|
1959 | + esc_html__('Error: Terms: Tried to run term_upsert, and ended up without a term id', 'object-sync-for-salesforce'), |
|
1960 | 1960 | '', |
1961 | 1961 | 0, |
1962 | 1962 | 0, |
@@ -1978,36 +1978,36 @@ discard block |
||
1978 | 1978 | * success: 1 |
1979 | 1979 | * "errors" : [ ], |
1980 | 1980 | */ |
1981 | - private function term_update( $term_id, $params, $taxonomy, $id_field = 'ID' ) { |
|
1982 | - if ( 'tag' === $taxonomy ) { |
|
1981 | + private function term_update($term_id, $params, $taxonomy, $id_field = 'ID') { |
|
1982 | + if ('tag' === $taxonomy) { |
|
1983 | 1983 | $taxonomy = 'post_tag'; |
1984 | 1984 | } |
1985 | 1985 | $args = array(); |
1986 | - foreach ( $params as $key => $value ) { |
|
1987 | - if ( 'wp_update_term' === $value['method_modify'] ) { |
|
1988 | - $args[ $key ] = $value['value']; |
|
1989 | - unset( $params[ $key ] ); |
|
1986 | + foreach ($params as $key => $value) { |
|
1987 | + if ('wp_update_term' === $value['method_modify']) { |
|
1988 | + $args[$key] = $value['value']; |
|
1989 | + unset($params[$key]); |
|
1990 | 1990 | } |
1991 | 1991 | } |
1992 | - $term = wp_update_term( $term_id, $taxonomy, $args ); |
|
1992 | + $term = wp_update_term($term_id, $taxonomy, $args); |
|
1993 | 1993 | |
1994 | - if ( is_wp_error( $term ) ) { |
|
1994 | + if (is_wp_error($term)) { |
|
1995 | 1995 | $success = false; |
1996 | 1996 | $errors = $term; |
1997 | 1997 | } else { |
1998 | - $term_id = $term[ "$id_field" ]; |
|
1998 | + $term_id = $term["$id_field"]; |
|
1999 | 1999 | $success = true; |
2000 | 2000 | $errors = array(); |
2001 | - foreach ( $params as $key => $value ) { |
|
2001 | + foreach ($params as $key => $value) { |
|
2002 | 2002 | $method = $value['method_modify']; |
2003 | - $meta_id = $method( $term_id, $key, $value['value'] ); |
|
2004 | - if ( false === $meta_id ) { |
|
2003 | + $meta_id = $method($term_id, $key, $value['value']); |
|
2004 | + if (false === $meta_id) { |
|
2005 | 2005 | $success = false; |
2006 | 2006 | $errors[] = array( |
2007 | 2007 | 'message' => sprintf( |
2008 | 2008 | // translators: %1$s is a method name. |
2009 | - esc_html__( 'Tried to update meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
2010 | - esc_html( $method ) |
|
2009 | + esc_html__('Tried to update meta with method %1$s.', 'object-sync-for-salesforce'), |
|
2010 | + esc_html($method) |
|
2011 | 2011 | ), |
2012 | 2012 | 'key' => $key, |
2013 | 2013 | 'value' => $value, |
@@ -2016,11 +2016,11 @@ discard block |
||
2016 | 2016 | } |
2017 | 2017 | |
2018 | 2018 | // Developers can use this hook to set any other term data. |
2019 | - do_action( 'object_sync_for_salesforce_set_more_term_data', $term_id, $params, 'update' ); |
|
2019 | + do_action('object_sync_for_salesforce_set_more_term_data', $term_id, $params, 'update'); |
|
2020 | 2020 | |
2021 | 2021 | } |
2022 | 2022 | |
2023 | - if ( is_wp_error( $term ) ) { |
|
2023 | + if (is_wp_error($term)) { |
|
2024 | 2024 | $success = false; |
2025 | 2025 | $errors = $term; |
2026 | 2026 | } else { |
@@ -2048,11 +2048,11 @@ discard block |
||
2048 | 2048 | * |
2049 | 2049 | * @return bool True if successful, false if failed. |
2050 | 2050 | */ |
2051 | - private function term_delete( $term_id, $taxonomy ) { |
|
2052 | - if ( 'tag' === $taxonomy ) { |
|
2051 | + private function term_delete($term_id, $taxonomy) { |
|
2052 | + if ('tag' === $taxonomy) { |
|
2053 | 2053 | $taxonomy = 'post_tag'; |
2054 | 2054 | } |
2055 | - $result = wp_delete_term( $term_id, $taxonomy ); |
|
2055 | + $result = wp_delete_term($term_id, $taxonomy); |
|
2056 | 2056 | return $result; |
2057 | 2057 | } |
2058 | 2058 | |
@@ -2068,52 +2068,52 @@ discard block |
||
2068 | 2068 | * success: 1 |
2069 | 2069 | * "errors" : [ ], |
2070 | 2070 | */ |
2071 | - private function comment_create( $params, $id_field = 'comment_ID' ) { |
|
2071 | + private function comment_create($params, $id_field = 'comment_ID') { |
|
2072 | 2072 | // Load all params with a method_modify of the object structure's content_method into $content |
2073 | 2073 | $content = array(); |
2074 | - $structure = $this->get_wordpress_table_structure( 'comment' ); |
|
2075 | - foreach ( $params as $key => $value ) { |
|
2076 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) ) { |
|
2077 | - $content[ $key ] = $value['value']; |
|
2078 | - unset( $params[ $key ] ); |
|
2074 | + $structure = $this->get_wordpress_table_structure('comment'); |
|
2075 | + foreach ($params as $key => $value) { |
|
2076 | + if (in_array($value['method_modify'], $structure['content_methods'])) { |
|
2077 | + $content[$key] = $value['value']; |
|
2078 | + unset($params[$key]); |
|
2079 | 2079 | } |
2080 | 2080 | } |
2081 | 2081 | |
2082 | 2082 | // Fields that are required for comments, even if they are empty values. |
2083 | - if ( ! isset( $content['comment_author'] ) ) { |
|
2083 | + if ( ! isset($content['comment_author'])) { |
|
2084 | 2084 | $content['comment_author'] = ''; |
2085 | 2085 | } |
2086 | - if ( ! isset( $content['comment_author_IP'] ) ) { |
|
2086 | + if ( ! isset($content['comment_author_IP'])) { |
|
2087 | 2087 | $content['comment_author_IP'] = ''; |
2088 | 2088 | } |
2089 | - if ( ! isset( $content['comment_author_email'] ) ) { |
|
2089 | + if ( ! isset($content['comment_author_email'])) { |
|
2090 | 2090 | $content['comment_author_email'] = ''; |
2091 | 2091 | } |
2092 | - if ( ! isset( $content['comment_author_url'] ) ) { |
|
2092 | + if ( ! isset($content['comment_author_url'])) { |
|
2093 | 2093 | $content['comment_author_url'] = ''; |
2094 | 2094 | } |
2095 | - if ( ! isset( $content['comment_type'] ) ) { |
|
2095 | + if ( ! isset($content['comment_type'])) { |
|
2096 | 2096 | $content['comment_type'] = ''; |
2097 | 2097 | } |
2098 | 2098 | |
2099 | - $comment_id = wp_new_comment( $content ); |
|
2099 | + $comment_id = wp_new_comment($content); |
|
2100 | 2100 | |
2101 | - if ( is_wp_error( $comment_id ) ) { |
|
2101 | + if (is_wp_error($comment_id)) { |
|
2102 | 2102 | $success = false; |
2103 | 2103 | $errors = $comment_id; |
2104 | 2104 | } else { |
2105 | 2105 | $success = true; |
2106 | 2106 | $errors = array(); |
2107 | - foreach ( $params as $key => $value ) { |
|
2107 | + foreach ($params as $key => $value) { |
|
2108 | 2108 | $method = $value['method_modify']; |
2109 | - $meta_id = $method( $comment_id, $key, $value['value'] ); |
|
2110 | - if ( false === $meta_id ) { |
|
2109 | + $meta_id = $method($comment_id, $key, $value['value']); |
|
2110 | + if (false === $meta_id) { |
|
2111 | 2111 | $success = false; |
2112 | 2112 | $errors[] = array( |
2113 | 2113 | 'message' => sprintf( |
2114 | 2114 | // translators: %1$s is a method name. |
2115 | - esc_html__( 'Tried to add meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
2116 | - esc_html( $method ) |
|
2115 | + esc_html__('Tried to add meta with method %1$s.', 'object-sync-for-salesforce'), |
|
2116 | + esc_html($method) |
|
2117 | 2117 | ), |
2118 | 2118 | 'key' => $key, |
2119 | 2119 | 'value' => $value, |
@@ -2122,11 +2122,11 @@ discard block |
||
2122 | 2122 | } |
2123 | 2123 | |
2124 | 2124 | // Developers can use this hook to set any other comment data. |
2125 | - do_action( 'object_sync_for_salesforce_set_more_comment_data', $comment_id, $params, 'create' ); |
|
2125 | + do_action('object_sync_for_salesforce_set_more_comment_data', $comment_id, $params, 'create'); |
|
2126 | 2126 | |
2127 | 2127 | } |
2128 | 2128 | |
2129 | - if ( is_wp_error( $comment_id ) ) { |
|
2129 | + if (is_wp_error($comment_id)) { |
|
2130 | 2130 | $success = false; |
2131 | 2131 | $errors = $comment_id; |
2132 | 2132 | } else { |
@@ -2163,79 +2163,79 @@ discard block |
||
2163 | 2163 | * success: 1 |
2164 | 2164 | * "errors" : [ ], |
2165 | 2165 | */ |
2166 | - private function comment_upsert( $key, $value, $methods, $params, $id_field = 'comment_ID', $push_drafts = false, $check_only = false ) { |
|
2166 | + private function comment_upsert($key, $value, $methods, $params, $id_field = 'comment_ID', $push_drafts = false, $check_only = false) { |
|
2167 | 2167 | $method = $methods['method_match']; |
2168 | - if ( 'get_comment' === $method ) { |
|
2168 | + if ('get_comment' === $method) { |
|
2169 | 2169 | $method = 'get_comments'; |
2170 | 2170 | } |
2171 | - if ( '' !== $method ) { |
|
2171 | + if ('' !== $method) { |
|
2172 | 2172 | // This should give us the comment object. |
2173 | 2173 | $match = array(); |
2174 | - if ( 'comment_author' === $key ) { |
|
2175 | - $match['author__in'] = array( $value ); |
|
2174 | + if ('comment_author' === $key) { |
|
2175 | + $match['author__in'] = array($value); |
|
2176 | 2176 | } else { |
2177 | - $key = str_replace( 'comment_', '', $key ); |
|
2178 | - $match[ $key ] = $value; |
|
2177 | + $key = str_replace('comment_', '', $key); |
|
2178 | + $match[$key] = $value; |
|
2179 | 2179 | } |
2180 | - $comments = $method( $match ); |
|
2180 | + $comments = $method($match); |
|
2181 | 2181 | |
2182 | - if ( 1 === count( $comments ) ) { |
|
2182 | + if (1 === count($comments)) { |
|
2183 | 2183 | $comment = $comments[0]; |
2184 | 2184 | // Comment does exist after checking the matching value. we want its id. |
2185 | 2185 | $comment_id = $comment->{$id_field}; |
2186 | 2186 | |
2187 | - if ( true === $check_only ) { |
|
2187 | + if (true === $check_only) { |
|
2188 | 2188 | // We are just checking to see if there is a match. |
2189 | 2189 | return $comment_id; |
2190 | 2190 | } |
2191 | 2191 | |
2192 | 2192 | // On the prematch fields, we specify the method_update param. |
2193 | - if ( isset( $methods['method_update'] ) ) { |
|
2193 | + if (isset($methods['method_update'])) { |
|
2194 | 2194 | $method = $methods['method_update']; |
2195 | 2195 | } else { |
2196 | 2196 | $method = $methods['method_modify']; |
2197 | 2197 | } |
2198 | - $params[ $key ] = array( |
|
2198 | + $params[$key] = array( |
|
2199 | 2199 | 'value' => $value, |
2200 | 2200 | 'method_modify' => $method, |
2201 | 2201 | 'method_read' => $methods['method_read'], |
2202 | 2202 | ); |
2203 | - } elseif ( count( $comments ) > 1 ) { |
|
2203 | + } elseif (count($comments) > 1) { |
|
2204 | 2204 | $status = 'error'; |
2205 | 2205 | // Create log entry for multiple matches. |
2206 | - if ( isset( $this->logging ) ) { |
|
2206 | + if (isset($this->logging)) { |
|
2207 | 2207 | $logging = $this->logging; |
2208 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
2209 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
2208 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
2209 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
2210 | 2210 | } |
2211 | 2211 | $logging->setup( |
2212 | 2212 | sprintf( |
2213 | 2213 | // translators: %1$s is a number. %2$s is a key. %3$s is the value of that key. %4$s is a var_export'd array of comments. |
2214 | - esc_html__( 'Error: Comments: there are %1$s comment matches for the Salesforce key %2$s with the value of %3$s. Here they are: %4$s', 'object-sync-for-salesforce' ), |
|
2215 | - absint( count( $comments ) ), |
|
2216 | - esc_html( $key ), |
|
2217 | - esc_html( $value ), |
|
2218 | - esc_html( var_export( $comments ) ) // Debugging code in production because having useful error messages is good. |
|
2214 | + esc_html__('Error: Comments: there are %1$s comment matches for the Salesforce key %2$s with the value of %3$s. Here they are: %4$s', 'object-sync-for-salesforce'), |
|
2215 | + absint(count($comments)), |
|
2216 | + esc_html($key), |
|
2217 | + esc_html($value), |
|
2218 | + esc_html(var_export($comments)) // Debugging code in production because having useful error messages is good. |
|
2219 | 2219 | ), |
2220 | 2220 | '', |
2221 | 2221 | 0, |
2222 | 2222 | 0, |
2223 | 2223 | $status |
2224 | 2224 | ); |
2225 | - } elseif ( false === $check_only ) { |
|
2225 | + } elseif (false === $check_only) { |
|
2226 | 2226 | // Comment does not exist after checking the matching value. Create it. |
2227 | 2227 | // On the prematch fields, we specify the method_create param. |
2228 | - if ( isset( $methods['method_create'] ) ) { |
|
2228 | + if (isset($methods['method_create'])) { |
|
2229 | 2229 | $method = $methods['method_create']; |
2230 | 2230 | } else { |
2231 | 2231 | $method = $methods['method_modify']; |
2232 | 2232 | } |
2233 | - $params[ $key ] = array( |
|
2233 | + $params[$key] = array( |
|
2234 | 2234 | 'value' => $value, |
2235 | 2235 | 'method_modify' => $method, |
2236 | 2236 | 'method_read' => $methods['method_read'], |
2237 | 2237 | ); |
2238 | - $result = $this->comment_create( $params, $id_field ); |
|
2238 | + $result = $this->comment_create($params, $id_field); |
|
2239 | 2239 | return $result; |
2240 | 2240 | } else { |
2241 | 2241 | // Check only is true but there's not a comment yet. |
@@ -2243,33 +2243,33 @@ discard block |
||
2243 | 2243 | } // End if(). |
2244 | 2244 | } else { |
2245 | 2245 | // There is no method by which to check the comment. We can check other ways here. |
2246 | - $params[ $key ] = array( |
|
2246 | + $params[$key] = array( |
|
2247 | 2247 | 'value' => $value, |
2248 | 2248 | 'method_modify' => $methods['method_modify'], |
2249 | 2249 | 'method_read' => $methods['method_read'], |
2250 | 2250 | ); |
2251 | 2251 | |
2252 | - if ( isset( $params['comment_author']['value'] ) ) { |
|
2252 | + if (isset($params['comment_author']['value'])) { |
|
2253 | 2253 | $comment_author = $params['comment_author']['value']; |
2254 | 2254 | } |
2255 | 2255 | |
2256 | - if ( isset( $params['comment_date']['value'] ) ) { |
|
2256 | + if (isset($params['comment_date']['value'])) { |
|
2257 | 2257 | $comment_date = $params['comment_date']['value']; |
2258 | 2258 | } |
2259 | 2259 | |
2260 | - if ( isset( $params['timezone']['value'] ) ) { |
|
2260 | + if (isset($params['timezone']['value'])) { |
|
2261 | 2261 | $timezone = $params['timezone']['value']; |
2262 | 2262 | } else { |
2263 | 2263 | $timezone = 'blog'; |
2264 | 2264 | } |
2265 | 2265 | |
2266 | - $existing_id = comment_exists( $comment_author, $comment_date, $timezone ); // Returns an id if there is a result. Uses $wpdb->get_var, so it returns null if there is no value |
|
2266 | + $existing_id = comment_exists($comment_author, $comment_date, $timezone); // Returns an id if there is a result. Uses $wpdb->get_var, so it returns null if there is no value |
|
2267 | 2267 | |
2268 | 2268 | // Comment does not exist after more checking. We want to create it. |
2269 | - if ( null === $existing_id && false === $check_only ) { |
|
2270 | - $result = $this->comment_create( $params, $id_field ); |
|
2269 | + if (null === $existing_id && false === $check_only) { |
|
2270 | + $result = $this->comment_create($params, $id_field); |
|
2271 | 2271 | return $result; |
2272 | - } elseif ( true === $check_only ) { |
|
2272 | + } elseif (true === $check_only) { |
|
2273 | 2273 | // We are just checking to see if there is a match. |
2274 | 2274 | return $existing_id; |
2275 | 2275 | } else { |
@@ -2278,22 +2278,22 @@ discard block |
||
2278 | 2278 | } |
2279 | 2279 | } // End if() that sets up the parameters in the $params array. |
2280 | 2280 | |
2281 | - if ( isset( $comment_id ) ) { |
|
2282 | - foreach ( $params as $key => $value ) { |
|
2283 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
2281 | + if (isset($comment_id)) { |
|
2282 | + foreach ($params as $key => $value) { |
|
2283 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
2284 | 2284 | } |
2285 | - $result = $this->comment_update( $comment_id, $params, $id_field ); |
|
2285 | + $result = $this->comment_update($comment_id, $params, $id_field); |
|
2286 | 2286 | return $result; |
2287 | 2287 | } |
2288 | 2288 | |
2289 | 2289 | // Create log entry for lack of a comment id. |
2290 | - if ( isset( $this->logging ) ) { |
|
2290 | + if (isset($this->logging)) { |
|
2291 | 2291 | $logging = $this->logging; |
2292 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
2293 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
2292 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
2293 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
2294 | 2294 | } |
2295 | 2295 | $logging->setup( |
2296 | - esc_html__( 'Error: Comments: Tried to run comment_upsert, and ended up without a comment id', 'object-sync-for-salesforce' ), |
|
2296 | + esc_html__('Error: Comments: Tried to run comment_upsert, and ended up without a comment id', 'object-sync-for-salesforce'), |
|
2297 | 2297 | '', |
2298 | 2298 | 0, |
2299 | 2299 | 0, |
@@ -2314,34 +2314,34 @@ discard block |
||
2314 | 2314 | * success: 1 |
2315 | 2315 | * "errors" : [ ], |
2316 | 2316 | */ |
2317 | - private function comment_update( $comment_id, $params, $id_field = 'comment_ID' ) { |
|
2317 | + private function comment_update($comment_id, $params, $id_field = 'comment_ID') { |
|
2318 | 2318 | $content = array(); |
2319 | - $content[ $id_field ] = $comment_id; |
|
2320 | - foreach ( $params as $key => $value ) { |
|
2321 | - if ( 'wp_update_comment' === $value['method_modify'] ) { |
|
2322 | - $content[ $key ] = $value['value']; |
|
2323 | - unset( $params[ $key ] ); |
|
2319 | + $content[$id_field] = $comment_id; |
|
2320 | + foreach ($params as $key => $value) { |
|
2321 | + if ('wp_update_comment' === $value['method_modify']) { |
|
2322 | + $content[$key] = $value['value']; |
|
2323 | + unset($params[$key]); |
|
2324 | 2324 | } |
2325 | 2325 | } |
2326 | 2326 | |
2327 | - $updated = wp_update_comment( $content ); |
|
2327 | + $updated = wp_update_comment($content); |
|
2328 | 2328 | |
2329 | - if ( 0 === $updated ) { |
|
2329 | + if (0 === $updated) { |
|
2330 | 2330 | $success = false; |
2331 | 2331 | $errors = $updated; |
2332 | 2332 | } else { |
2333 | 2333 | $success = true; |
2334 | 2334 | $errors = array(); |
2335 | - foreach ( $params as $key => $value ) { |
|
2335 | + foreach ($params as $key => $value) { |
|
2336 | 2336 | $method = $value['method_modify']; |
2337 | - $meta_id = $method( $comment_id, $key, $value['value'] ); |
|
2338 | - if ( false === $meta_id ) { |
|
2337 | + $meta_id = $method($comment_id, $key, $value['value']); |
|
2338 | + if (false === $meta_id) { |
|
2339 | 2339 | $success = false; |
2340 | 2340 | $errors[] = array( |
2341 | 2341 | 'message' => sprintf( |
2342 | 2342 | // Translators: %1$s is a method name. |
2343 | - esc_html__( 'Tried to update meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
2344 | - esc_html( $method ) |
|
2343 | + esc_html__('Tried to update meta with method %1$s.', 'object-sync-for-salesforce'), |
|
2344 | + esc_html($method) |
|
2345 | 2345 | ), |
2346 | 2346 | 'key' => $key, |
2347 | 2347 | 'value' => $value, |
@@ -2350,11 +2350,11 @@ discard block |
||
2350 | 2350 | } |
2351 | 2351 | |
2352 | 2352 | // Developers can use this hook to set any other comment data. |
2353 | - do_action( 'object_sync_for_salesforce_set_more_comment_data', $comment_id, $params, 'update' ); |
|
2353 | + do_action('object_sync_for_salesforce_set_more_comment_data', $comment_id, $params, 'update'); |
|
2354 | 2354 | |
2355 | 2355 | } |
2356 | 2356 | |
2357 | - if ( is_wp_error( $updated ) ) { |
|
2357 | + if (is_wp_error($updated)) { |
|
2358 | 2358 | $success = false; |
2359 | 2359 | $errors = $updated; |
2360 | 2360 | } else { |
@@ -2382,8 +2382,8 @@ discard block |
||
2382 | 2382 | * |
2383 | 2383 | * @return boolean true if successful, false if failed. |
2384 | 2384 | */ |
2385 | - private function comment_delete( $id, $force_delete = false ) { |
|
2386 | - $result = wp_delete_comment( $id, $force_delete ); |
|
2385 | + private function comment_delete($id, $force_delete = false) { |
|
2386 | + $result = wp_delete_comment($id, $force_delete); |
|
2387 | 2387 | return $result; |
2388 | 2388 | } |
2389 | 2389 | |
@@ -2407,9 +2407,9 @@ discard block |
||
2407 | 2407 | * |
2408 | 2408 | * @param string $name The name of the field that lists all cache keys. |
2409 | 2409 | */ |
2410 | - public function __construct( $name ) { |
|
2410 | + public function __construct($name) { |
|
2411 | 2411 | $this->name = $name; |
2412 | - $this->cache_prefix = esc_sql( 'sfwp_' ); |
|
2412 | + $this->cache_prefix = esc_sql('sfwp_'); |
|
2413 | 2413 | } |
2414 | 2414 | |
2415 | 2415 | /** |
@@ -2418,7 +2418,7 @@ discard block |
||
2418 | 2418 | * @return mixed value of transient. False of empty, otherwise array. |
2419 | 2419 | */ |
2420 | 2420 | public function all_keys() { |
2421 | - return get_transient( $this->name ); |
|
2421 | + return get_transient($this->name); |
|
2422 | 2422 | } |
2423 | 2423 | |
2424 | 2424 | /** |
@@ -2429,16 +2429,16 @@ discard block |
||
2429 | 2429 | * @param int $cache_expiration. How long the plugin key cache, and this individual item cache, should last before expiring. |
2430 | 2430 | * @return mixed value of transient. False of empty, otherwise array. |
2431 | 2431 | */ |
2432 | - public function set( $cachekey, $value, $cache_expiration = 0 ) { |
|
2432 | + public function set($cachekey, $value, $cache_expiration = 0) { |
|
2433 | 2433 | |
2434 | 2434 | $prefix = $this->cache_prefix; |
2435 | 2435 | $cachekey = $prefix . $cachekey; |
2436 | 2436 | |
2437 | 2437 | $keys = $this->all_keys(); |
2438 | 2438 | $keys[] = $cachekey; |
2439 | - set_transient( $this->name, $keys, $cache_expiration ); |
|
2439 | + set_transient($this->name, $keys, $cache_expiration); |
|
2440 | 2440 | |
2441 | - return set_transient( $cachekey, $value, $cache_expiration ); |
|
2441 | + return set_transient($cachekey, $value, $cache_expiration); |
|
2442 | 2442 | } |
2443 | 2443 | |
2444 | 2444 | /** |
@@ -2447,10 +2447,10 @@ discard block |
||
2447 | 2447 | * @param string $cachekey the key for this cache item |
2448 | 2448 | * @return mixed value of transient. False of empty, otherwise array. |
2449 | 2449 | */ |
2450 | - public function get( $cachekey ) { |
|
2450 | + public function get($cachekey) { |
|
2451 | 2451 | $prefix = $this->cache_prefix; |
2452 | 2452 | $cachekey = $prefix . $cachekey; |
2453 | - return get_transient( $cachekey ); |
|
2453 | + return get_transient($cachekey); |
|
2454 | 2454 | } |
2455 | 2455 | |
2456 | 2456 | /** |
@@ -2459,10 +2459,10 @@ discard block |
||
2459 | 2459 | * @param string $cachekey the key for this cache item |
2460 | 2460 | * @return bool True if successful, false otherwise. |
2461 | 2461 | */ |
2462 | - public function delete( $cachekey ) { |
|
2462 | + public function delete($cachekey) { |
|
2463 | 2463 | $prefix = $this->cache_prefix; |
2464 | 2464 | $cachekey = $prefix . $cachekey; |
2465 | - return delete_transient( $cachekey ); |
|
2465 | + return delete_transient($cachekey); |
|
2466 | 2466 | } |
2467 | 2467 | |
2468 | 2468 | /** |
@@ -2473,10 +2473,10 @@ discard block |
||
2473 | 2473 | public function flush() { |
2474 | 2474 | $keys = $this->all_keys(); |
2475 | 2475 | $result = true; |
2476 | - foreach ( $keys as $key ) { |
|
2477 | - $result = delete_transient( $key ); |
|
2476 | + foreach ($keys as $key) { |
|
2477 | + $result = delete_transient($key); |
|
2478 | 2478 | } |
2479 | - $result = delete_transient( $this->name ); |
|
2479 | + $result = delete_transient($this->name); |
|
2480 | 2480 | return $result; |
2481 | 2481 | } |
2482 | 2482 |
@@ -1,35 +1,35 @@ discard block |
||
1 | -<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="fieldmap"> |
|
2 | - <input type="hidden" name="redirect_url_error" value="<?php echo esc_url( $error_url ); ?>" /> |
|
3 | - <input type="hidden" name="redirect_url_success" value="<?php echo esc_url( $success_url ); ?>" /> |
|
4 | - <?php if ( isset( $transient ) ) { ?> |
|
5 | - <input type="hidden" name="transient" value="<?php echo esc_html( $transient ); ?>" /> |
|
1 | +<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="fieldmap"> |
|
2 | + <input type="hidden" name="redirect_url_error" value="<?php echo esc_url($error_url); ?>" /> |
|
3 | + <input type="hidden" name="redirect_url_success" value="<?php echo esc_url($success_url); ?>" /> |
|
4 | + <?php if (isset($transient)) { ?> |
|
5 | + <input type="hidden" name="transient" value="<?php echo esc_html($transient); ?>" /> |
|
6 | 6 | <?php } ?> |
7 | 7 | <input type="hidden" name="action" value="post_fieldmap" > |
8 | - <input type="hidden" name="method" value="<?php echo esc_attr( $method ); ?>" /> |
|
9 | - <?php if ( 'edit' === $method ) { ?> |
|
10 | - <input type="hidden" name="id" value="<?php echo absint( $map['id'] ); ?>" /> |
|
8 | + <input type="hidden" name="method" value="<?php echo esc_attr($method); ?>" /> |
|
9 | + <?php if ('edit' === $method) { ?> |
|
10 | + <input type="hidden" name="id" value="<?php echo absint($map['id']); ?>" /> |
|
11 | 11 | <?php } ?> |
12 | 12 | <div class="fieldmap_label"> |
13 | - <label for="label"><?php echo esc_html__( 'Label', 'object-sync-for-salesforce' ); ?>: </label> |
|
14 | - <input type="text" id="label" name="label" required value="<?php echo isset( $label ) ? esc_html( $label ) : ''; ?>" /> |
|
13 | + <label for="label"><?php echo esc_html__('Label', 'object-sync-for-salesforce'); ?>: </label> |
|
14 | + <input type="text" id="label" name="label" required value="<?php echo isset($label) ? esc_html($label) : ''; ?>" /> |
|
15 | 15 | </div> |
16 | 16 | <fieldset class="wordpress_side"> |
17 | 17 | <div class="wordpress_object"> |
18 | - <label for="wordpress_object"><?php echo esc_html__( 'WordPress Object', 'object-sync-for-salesforce' ); ?>: </label> |
|
18 | + <label for="wordpress_object"><?php echo esc_html__('WordPress Object', 'object-sync-for-salesforce'); ?>: </label> |
|
19 | 19 | <select id="wordpress_object" name="wordpress_object" required> |
20 | - <option value="">- <?php echo esc_html__( 'Select object type', 'object-sync-for-salesforce' ); ?> -</option> |
|
20 | + <option value="">- <?php echo esc_html__('Select object type', 'object-sync-for-salesforce'); ?> -</option> |
|
21 | 21 | <?php |
22 | 22 | $wordpress_objects = $this->wordpress->wordpress_objects; |
23 | - foreach ( $wordpress_objects as $object ) { |
|
24 | - if ( isset( $wordpress_object ) && $wordpress_object === $object ) { |
|
23 | + foreach ($wordpress_objects as $object) { |
|
24 | + if (isset($wordpress_object) && $wordpress_object === $object) { |
|
25 | 25 | $selected = ' selected'; |
26 | 26 | } else { |
27 | 27 | $selected = ''; |
28 | 28 | } |
29 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
30 | - esc_html( $object ), |
|
31 | - esc_attr( $selected ), |
|
32 | - esc_html( $object ) |
|
29 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
30 | + esc_html($object), |
|
31 | + esc_attr($selected), |
|
32 | + esc_html($object) |
|
33 | 33 | ); |
34 | 34 | } |
35 | 35 | ?> |
@@ -38,31 +38,31 @@ discard block |
||
38 | 38 | </fieldset> |
39 | 39 | <fieldset class="salesforce_side"> |
40 | 40 | <div class="salesforce_object"> |
41 | - <label for="salesforce_object"><?php echo esc_html__( 'Salesforce Object', 'object-sync-for-salesforce' ); ?>: </label> |
|
41 | + <label for="salesforce_object"><?php echo esc_html__('Salesforce Object', 'object-sync-for-salesforce'); ?>: </label> |
|
42 | 42 | <div class="spinner"></div> |
43 | 43 | <select id="salesforce_object" name="salesforce_object" required> |
44 | - <option value="">- <?php echo esc_html__( 'Select object type', 'object-sync-for-salesforce' ); ?> -</option> |
|
44 | + <option value="">- <?php echo esc_html__('Select object type', 'object-sync-for-salesforce'); ?> -</option> |
|
45 | 45 | <?php |
46 | 46 | $sfapi = $this->salesforce['sfapi']; |
47 | - $object_filters = maybe_unserialize( get_option( 'salesforce_api_object_filters' ), array() ); |
|
47 | + $object_filters = maybe_unserialize(get_option('salesforce_api_object_filters'), array()); |
|
48 | 48 | $conditions = array(); |
49 | - if ( is_array( $object_filters ) && in_array( 'updateable', $object_filters, true ) ) { |
|
49 | + if (is_array($object_filters) && in_array('updateable', $object_filters, true)) { |
|
50 | 50 | $conditions['updateable'] = true; |
51 | 51 | } |
52 | - if ( is_array( $object_filters ) && in_array( 'triggerable', $object_filters, true ) ) { |
|
52 | + if (is_array($object_filters) && in_array('triggerable', $object_filters, true)) { |
|
53 | 53 | $conditions['triggerable'] = true; |
54 | 54 | } |
55 | - $salesforce_objects = $sfapi->objects( $conditions ); |
|
56 | - foreach ( $salesforce_objects as $object ) { |
|
57 | - if ( isset( $salesforce_object ) && $salesforce_object === $object['name'] ) { |
|
55 | + $salesforce_objects = $sfapi->objects($conditions); |
|
56 | + foreach ($salesforce_objects as $object) { |
|
57 | + if (isset($salesforce_object) && $salesforce_object === $object['name']) { |
|
58 | 58 | $selected = ' selected'; |
59 | 59 | } else { |
60 | 60 | $selected = ''; |
61 | 61 | } |
62 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
63 | - esc_html( $object['name'] ), |
|
64 | - esc_attr( $selected ), |
|
65 | - esc_html( $object['label'] ) |
|
62 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
63 | + esc_html($object['name']), |
|
64 | + esc_attr($selected), |
|
65 | + esc_html($object['label']) |
|
66 | 66 | ); |
67 | 67 | } |
68 | 68 | ?> |
@@ -70,30 +70,30 @@ discard block |
||
70 | 70 | </div> |
71 | 71 | <div class="salesforce_record_types_allowed"> |
72 | 72 | <?php |
73 | - if ( isset( $salesforce_record_types_allowed ) ) : |
|
73 | + if (isset($salesforce_record_types_allowed)) : |
|
74 | 74 | $record_types = $this->get_salesforce_object_description( |
75 | 75 | array( |
76 | 76 | 'salesforce_object' => $salesforce_object, |
77 | 77 | 'include' => 'recordTypeInfos', |
78 | 78 | ) |
79 | 79 | ); |
80 | - if ( isset( $record_types['recordTypeInfos'] ) ) : |
|
80 | + if (isset($record_types['recordTypeInfos'])) : |
|
81 | 81 | ?> |
82 | - <label for="salesforce_record_types_allowed"><?php echo __( 'Allowed Record Types', 'object-sync-for-salesforce' ); ?>:</label> |
|
82 | + <label for="salesforce_record_types_allowed"><?php echo __('Allowed Record Types', 'object-sync-for-salesforce'); ?>:</label> |
|
83 | 83 | <div class="checkboxes"> |
84 | - <?php foreach ( $record_types['recordTypeInfos'] as $key => $value ) : ?> |
|
84 | + <?php foreach ($record_types['recordTypeInfos'] as $key => $value) : ?> |
|
85 | 85 | <?php |
86 | - if ( in_array( $key, $salesforce_record_types_allowed, true ) ) { |
|
86 | + if (in_array($key, $salesforce_record_types_allowed, true)) { |
|
87 | 87 | $checked = ' checked'; |
88 | 88 | } else { |
89 | 89 | $checked = ''; |
90 | 90 | } |
91 | - echo sprintf( '<label><input type="checkbox" class="form-checkbox" value="%1$s" name="%2$s" id="%3$s"%4$s>%5$s</label>', |
|
92 | - esc_html( $key ), |
|
93 | - esc_attr( 'salesforce_record_types_allowed[' . $key . ']' ), |
|
94 | - esc_attr( 'salesforce_record_types_allowed-' . $key ), |
|
95 | - esc_html( $checked ), |
|
96 | - esc_html( $value ) |
|
91 | + echo sprintf('<label><input type="checkbox" class="form-checkbox" value="%1$s" name="%2$s" id="%3$s"%4$s>%5$s</label>', |
|
92 | + esc_html($key), |
|
93 | + esc_attr('salesforce_record_types_allowed[' . $key . ']'), |
|
94 | + esc_attr('salesforce_record_types_allowed-' . $key), |
|
95 | + esc_html($checked), |
|
96 | + esc_html($value) |
|
97 | 97 | ); |
98 | 98 | ?> |
99 | 99 | <?php endforeach; ?> |
@@ -103,29 +103,29 @@ discard block |
||
103 | 103 | </div> |
104 | 104 | <div class="salesforce_record_type_default"> |
105 | 105 | <?php |
106 | - if ( isset( $salesforce_record_type_default ) ) : |
|
106 | + if (isset($salesforce_record_type_default)) : |
|
107 | 107 | $record_types = $this->get_salesforce_object_description( |
108 | 108 | array( |
109 | 109 | 'salesforce_object' => $salesforce_object, |
110 | 110 | 'include' => 'recordTypeInfos', |
111 | 111 | ) |
112 | 112 | ); |
113 | - if ( isset( $record_types['recordTypeInfos'] ) ) : |
|
113 | + if (isset($record_types['recordTypeInfos'])) : |
|
114 | 114 | ?> |
115 | - <label for="salesforce_record_type_default"><?php echo __( 'Default Record Type', 'object-sync-for-salesforce' ); ?>:</label> |
|
116 | - <select id="salesforce_record_type_default" name="salesforce_record_type_default" required><option value="">- <?php echo __( 'Select record type', 'object-sync-for-salesforce' ); ?> -</option> |
|
115 | + <label for="salesforce_record_type_default"><?php echo __('Default Record Type', 'object-sync-for-salesforce'); ?>:</label> |
|
116 | + <select id="salesforce_record_type_default" name="salesforce_record_type_default" required><option value="">- <?php echo __('Select record type', 'object-sync-for-salesforce'); ?> -</option> |
|
117 | 117 | <?php |
118 | - foreach ( $record_types['recordTypeInfos'] as $key => $value ) : |
|
119 | - if ( isset( $salesforce_record_type_default ) && $salesforce_record_type_default === $key ) { |
|
118 | + foreach ($record_types['recordTypeInfos'] as $key => $value) : |
|
119 | + if (isset($salesforce_record_type_default) && $salesforce_record_type_default === $key) { |
|
120 | 120 | $selected = ' selected'; |
121 | 121 | } else { |
122 | 122 | $selected = ''; |
123 | 123 | } |
124 | - if ( ! isset( $salesforce_record_types_allowed ) || in_array( $key, $salesforce_record_types_allowed, true ) ) { |
|
125 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
126 | - esc_attr( $key ), |
|
127 | - esc_attr( $selected ), |
|
128 | - esc_html( $value ) |
|
124 | + if ( ! isset($salesforce_record_types_allowed) || in_array($key, $salesforce_record_types_allowed, true)) { |
|
125 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
126 | + esc_attr($key), |
|
127 | + esc_attr($selected), |
|
128 | + esc_html($value) |
|
129 | 129 | ); |
130 | 130 | } |
131 | 131 | endforeach; |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | ?> |
138 | 138 | </div> |
139 | 139 | <div class="pull_trigger_field"> |
140 | - <?php if ( isset( $pull_trigger_field ) ) : ?> |
|
141 | - <label for="pull_trigger_field"><?php echo __( 'Date field to trigger pull', 'object-sync-for-salesforce' ); ?>:</label> |
|
140 | + <?php if (isset($pull_trigger_field)) : ?> |
|
141 | + <label for="pull_trigger_field"><?php echo __('Date field to trigger pull', 'object-sync-for-salesforce'); ?>:</label> |
|
142 | 142 | <?php |
143 | 143 | $object_fields = $this->get_salesforce_object_fields( |
144 | 144 | array( |
@@ -149,35 +149,35 @@ discard block |
||
149 | 149 | ?> |
150 | 150 | <select name="pull_trigger_field" id="pull_trigger_field"> |
151 | 151 | <?php |
152 | - foreach ( $object_fields as $key => $value ) { |
|
153 | - if ( $pull_trigger_field === $value['name'] ) { |
|
152 | + foreach ($object_fields as $key => $value) { |
|
153 | + if ($pull_trigger_field === $value['name']) { |
|
154 | 154 | $selected = ' selected'; |
155 | 155 | } else { |
156 | 156 | $selected = ''; |
157 | 157 | } |
158 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
159 | - esc_attr( $value['name'] ), |
|
160 | - esc_attr( $selected ), |
|
161 | - esc_html( $value['label'] ) |
|
158 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
159 | + esc_attr($value['name']), |
|
160 | + esc_attr($selected), |
|
161 | + esc_html($value['label']) |
|
162 | 162 | ); |
163 | 163 | } |
164 | 164 | ?> |
165 | 165 | </select> |
166 | - <p class="description"><?php echo esc_html__( 'When the plugin checks for data to bring from Salesforce into WordPress, it will use the selected field to determine what relevant changes have occurred in Salesforce.', 'object-sync-for-salesforce' ); ?></p> |
|
166 | + <p class="description"><?php echo esc_html__('When the plugin checks for data to bring from Salesforce into WordPress, it will use the selected field to determine what relevant changes have occurred in Salesforce.', 'object-sync-for-salesforce'); ?></p> |
|
167 | 167 | <?php endif; ?> |
168 | 168 | </div> |
169 | 169 | </fieldset> |
170 | 170 | <fieldset class="fields"> |
171 | - <legend><?php echo esc_html__( 'Fieldmap', 'object-sync-for-salesforce' ); ?></legend> |
|
171 | + <legend><?php echo esc_html__('Fieldmap', 'object-sync-for-salesforce'); ?></legend> |
|
172 | 172 | <table class="wp-list-table widefat striped fields"> |
173 | 173 | <thead> |
174 | 174 | <tr> |
175 | - <th class="column-wordpress_field"><?php echo esc_html__( 'WordPress Field', 'object-sync-for-salesforce' ); ?></th> |
|
176 | - <th class="column-salesforce_field"><?php echo esc_html__( 'Salesforce Field', 'object-sync-for-salesforce' ); ?></th> |
|
177 | - <th class="column-is_prematch"><?php echo esc_html__( 'Prematch', 'object-sync-for-salesforce' ); ?></th> |
|
178 | - <th class="column-is_key"><?php echo esc_html__( 'Salesforce Key', 'object-sync-for-salesforce' ); ?></th> |
|
179 | - <th class="column-direction"><?php echo esc_html__( 'Direction', 'object-sync-for-salesforce' ); ?></th> |
|
180 | - <th class="column-is_delete"><?php echo esc_html__( 'Delete', 'object-sync-for-salesforce' ); ?></th> |
|
175 | + <th class="column-wordpress_field"><?php echo esc_html__('WordPress Field', 'object-sync-for-salesforce'); ?></th> |
|
176 | + <th class="column-salesforce_field"><?php echo esc_html__('Salesforce Field', 'object-sync-for-salesforce'); ?></th> |
|
177 | + <th class="column-is_prematch"><?php echo esc_html__('Prematch', 'object-sync-for-salesforce'); ?></th> |
|
178 | + <th class="column-is_key"><?php echo esc_html__('Salesforce Key', 'object-sync-for-salesforce'); ?></th> |
|
179 | + <th class="column-direction"><?php echo esc_html__('Direction', 'object-sync-for-salesforce'); ?></th> |
|
180 | + <th class="column-is_delete"><?php echo esc_html__('Delete', 'object-sync-for-salesforce'); ?></th> |
|
181 | 181 | </tr> |
182 | 182 | </thead> |
183 | 183 | <tfoot> |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | <p><small> |
187 | 187 | <?php |
188 | 188 | // translators: the placeholders refer to: 1) the cache clear link, 2) the cache clear link text |
189 | - echo sprintf( '<strong>' . esc_html__( 'Note:', 'object-sync-for-salesforce' ) . '</strong>' . esc_html__( ' to map a custom meta field (such as wp_postmeta, wp_usermeta, wp_termmeta, etc.), WordPress must have at least one value for that field. If you add a new meta field and want to map it, make sure to add a value for it and ', 'object-sync-for-salesforce' ) . '<a href="%1$s" id="clear-sfwp-cache">%2$s</a>' . esc_html__( ' to see the field listed here', 'object-sync-for-salesforce' ), |
|
190 | - esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=clear_cache' ) ), |
|
191 | - esc_html__( 'clear the plugin cache', 'object-sync-for-salesforce' ) |
|
189 | + echo sprintf('<strong>' . esc_html__('Note:', 'object-sync-for-salesforce') . '</strong>' . esc_html__(' to map a custom meta field (such as wp_postmeta, wp_usermeta, wp_termmeta, etc.), WordPress must have at least one value for that field. If you add a new meta field and want to map it, make sure to add a value for it and ', 'object-sync-for-salesforce') . '<a href="%1$s" id="clear-sfwp-cache">%2$s</a>' . esc_html__(' to see the field listed here', 'object-sync-for-salesforce'), |
|
190 | + esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=clear_cache')), |
|
191 | + esc_html__('clear the plugin cache', 'object-sync-for-salesforce') |
|
192 | 192 | ); |
193 | 193 | ?> |
194 | 194 | </small></p> |
@@ -197,26 +197,26 @@ discard block |
||
197 | 197 | </tfoot> |
198 | 198 | <tbody> |
199 | 199 | <?php |
200 | - if ( isset( $fieldmap_fields ) && null !== $fieldmap_fields && is_array( $fieldmap_fields ) ) { |
|
201 | - foreach ( $fieldmap_fields as $key => $value ) { |
|
202 | - $key = md5( $key . time() ); |
|
200 | + if (isset($fieldmap_fields) && null !== $fieldmap_fields && is_array($fieldmap_fields)) { |
|
201 | + foreach ($fieldmap_fields as $key => $value) { |
|
202 | + $key = md5($key . time()); |
|
203 | 203 | ?> |
204 | 204 | <tr> |
205 | 205 | <td class="column-wordpress_field"> |
206 | - <select name="wordpress_field[<?php echo esc_attr( $key ); ?>]" id="wordpress_field-<?php echo esc_attr( $key ); ?>"> |
|
207 | - <option value="">- <?php echo esc_html__( 'Select WordPress field', 'object-sync-for-salesforce' ); ?> -</option> |
|
206 | + <select name="wordpress_field[<?php echo esc_attr($key); ?>]" id="wordpress_field-<?php echo esc_attr($key); ?>"> |
|
207 | + <option value="">- <?php echo esc_html__('Select WordPress field', 'object-sync-for-salesforce'); ?> -</option> |
|
208 | 208 | <?php |
209 | - $wordpress_fields = $this->get_wordpress_object_fields( $wordpress_object ); |
|
210 | - foreach ( $wordpress_fields as $wordpress_field ) { |
|
211 | - if ( isset( $value['wordpress_field']['label'] ) && $value['wordpress_field']['label'] === $wordpress_field['key'] ) { |
|
209 | + $wordpress_fields = $this->get_wordpress_object_fields($wordpress_object); |
|
210 | + foreach ($wordpress_fields as $wordpress_field) { |
|
211 | + if (isset($value['wordpress_field']['label']) && $value['wordpress_field']['label'] === $wordpress_field['key']) { |
|
212 | 212 | $selected = ' selected'; |
213 | 213 | } else { |
214 | 214 | $selected = ''; |
215 | 215 | } |
216 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
217 | - esc_attr( $wordpress_field['key'] ), |
|
218 | - esc_attr( $selected ), |
|
219 | - esc_html( $wordpress_field['key'] ) |
|
216 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
217 | + esc_attr($wordpress_field['key']), |
|
218 | + esc_attr($selected), |
|
219 | + esc_html($wordpress_field['key']) |
|
220 | 220 | ); |
221 | 221 | } |
222 | 222 | ?> |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | |
225 | 225 | </td> |
226 | 226 | <td class="column-salesforce_field"> |
227 | - <select name="salesforce_field[<?php echo esc_attr( $key ); ?>]" id="salesforce_field-<?php echo esc_attr( $key ); ?>"> |
|
228 | - <option value="">- <?php echo esc_html__( 'Select Salesforce field', 'object-sync-for-salesforce' ); ?> -</option> |
|
227 | + <select name="salesforce_field[<?php echo esc_attr($key); ?>]" id="salesforce_field-<?php echo esc_attr($key); ?>"> |
|
228 | + <option value="">- <?php echo esc_html__('Select Salesforce field', 'object-sync-for-salesforce'); ?> -</option> |
|
229 | 229 | <?php |
230 | 230 | $salesforce_fields = $this->get_salesforce_object_fields( |
231 | 231 | array( |
@@ -233,25 +233,25 @@ discard block |
||
233 | 233 | ) |
234 | 234 | ); |
235 | 235 | // allow for api name or field label to be the display value in the <select> |
236 | - $display_value = get_option( $this->option_prefix . 'salesforce_field_display_value', 'field_label' ); |
|
237 | - foreach ( $salesforce_fields as $salesforce_field ) { |
|
238 | - if ( isset( $value['salesforce_field']['name'] ) && $value['salesforce_field']['name'] === $salesforce_field['name'] ) { |
|
236 | + $display_value = get_option($this->option_prefix . 'salesforce_field_display_value', 'field_label'); |
|
237 | + foreach ($salesforce_fields as $salesforce_field) { |
|
238 | + if (isset($value['salesforce_field']['name']) && $value['salesforce_field']['name'] === $salesforce_field['name']) { |
|
239 | 239 | $selected = ' selected'; |
240 | - } elseif ( isset( $value['salesforce_field']['label'] ) && $value['salesforce_field']['label'] === $salesforce_field['name'] ) { |
|
240 | + } elseif (isset($value['salesforce_field']['label']) && $value['salesforce_field']['label'] === $salesforce_field['name']) { |
|
241 | 241 | // this conditional is for versions up to 1.1.2, but i think it's fine to leave it for now. if we remove it, people's fieldmaps will not show correctly in the admin. |
242 | 242 | $selected = ' selected'; |
243 | 243 | } else { |
244 | 244 | $selected = ''; |
245 | 245 | } |
246 | 246 | |
247 | - if ( 'api_name' === $display_value ) { |
|
247 | + if ('api_name' === $display_value) { |
|
248 | 248 | $salesforce_field['label'] = $salesforce_field['name']; |
249 | 249 | } |
250 | 250 | |
251 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
252 | - esc_attr( $salesforce_field['name'] ), |
|
253 | - esc_attr( $selected ), |
|
254 | - esc_html( $salesforce_field['label'] ) |
|
251 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
252 | + esc_attr($salesforce_field['name']), |
|
253 | + esc_attr($selected), |
|
254 | + esc_html($salesforce_field['label']) |
|
255 | 255 | ); |
256 | 256 | } |
257 | 257 | ?> |
@@ -260,32 +260,32 @@ discard block |
||
260 | 260 | </td> |
261 | 261 | <td class="column-is_prematch"> |
262 | 262 | <?php |
263 | - if ( isset( $value['is_prematch'] ) && '1' === $value['is_prematch'] ) { |
|
263 | + if (isset($value['is_prematch']) && '1' === $value['is_prematch']) { |
|
264 | 264 | $checked = ' checked'; |
265 | 265 | } else { |
266 | 266 | $checked = ''; |
267 | 267 | } |
268 | 268 | ?> |
269 | - <input type="checkbox" name="is_prematch[<?php echo esc_attr( $key ); ?>]" id="is_prematch-<?php echo esc_attr( $key ); ?>" value="1" <?php echo esc_attr( $checked ); ?> title="<?php echo esc_html__( 'This pair should be checked for existing matches in Salesforce before adding', 'object-sync-for-salesforce' ); ?>" /> |
|
269 | + <input type="checkbox" name="is_prematch[<?php echo esc_attr($key); ?>]" id="is_prematch-<?php echo esc_attr($key); ?>" value="1" <?php echo esc_attr($checked); ?> title="<?php echo esc_html__('This pair should be checked for existing matches in Salesforce before adding', 'object-sync-for-salesforce'); ?>" /> |
|
270 | 270 | </td> |
271 | 271 | <td class="column-is_key"> |
272 | 272 | <?php |
273 | - if ( isset( $value['is_key'] ) && '1' === $value['is_key'] ) { |
|
273 | + if (isset($value['is_key']) && '1' === $value['is_key']) { |
|
274 | 274 | $checked = ' checked'; |
275 | 275 | } else { |
276 | 276 | $checked = ''; |
277 | 277 | } |
278 | 278 | ?> |
279 | - <input type="checkbox" name="is_key[<?php echo esc_attr( $key ); ?>]" id="is_key-<?php echo esc_attr( $key ); ?>" value="1" <?php echo esc_attr( $checked ); ?> title="<?php echo esc_html__( 'This Salesforce field is an External ID in Salesforce', 'object-sync-for-salesforce' ); ?>" /> |
|
279 | + <input type="checkbox" name="is_key[<?php echo esc_attr($key); ?>]" id="is_key-<?php echo esc_attr($key); ?>" value="1" <?php echo esc_attr($checked); ?> title="<?php echo esc_html__('This Salesforce field is an External ID in Salesforce', 'object-sync-for-salesforce'); ?>" /> |
|
280 | 280 | </td> |
281 | 281 | <td class="column-direction"> |
282 | 282 | <?php |
283 | - if ( isset( $value['direction'] ) ) { |
|
284 | - if ( 'sf_wp' === $value['direction'] ) { |
|
283 | + if (isset($value['direction'])) { |
|
284 | + if ('sf_wp' === $value['direction']) { |
|
285 | 285 | $checked_sf_wp = ' checked'; |
286 | 286 | $checked_wp_sf = ''; |
287 | 287 | $checked_sync = ''; |
288 | - } elseif ( 'wp_sf' === $value['direction'] ) { |
|
288 | + } elseif ('wp_sf' === $value['direction']) { |
|
289 | 289 | $checked_sf_wp = ''; |
290 | 290 | $checked_wp_sf = ' checked'; |
291 | 291 | $checked_sync = ''; |
@@ -301,29 +301,29 @@ discard block |
||
301 | 301 | } |
302 | 302 | ?> |
303 | 303 | <div class="radios"> |
304 | - <label><input type="radio" value="sf_wp" name="direction[<?php echo esc_attr( $key ); ?>]" id="direction-<?php echo esc_attr( $key ); ?>-sf-wp" <?php echo esc_attr( $checked_sf_wp ); ?> required> <?php echo esc_html__( 'Salesforce to WordPress', 'object-sync-for-salesforce' ); ?></label> |
|
305 | - <label><input type="radio" value="wp_sf" name="direction[<?php echo esc_attr( $key ); ?>]" id="direction-<?php echo esc_attr( $key ); ?>-wp-sf" <?php echo esc_attr( $checked_wp_sf ); ?> required> <?php echo esc_html__( 'WordPress to Salesforce', 'object-sync-for-salesforce' ); ?></label> |
|
306 | - <label><input type="radio" value="sync" name="direction[<?php echo esc_attr( $key ); ?>]" id="direction-<?php echo esc_attr( $key ); ?>-sync" <?php echo esc_attr( $checked_sync ); ?> required> <?php echo esc_html__( 'Sync', 'object-sync-for-salesforce' ); ?></label> |
|
304 | + <label><input type="radio" value="sf_wp" name="direction[<?php echo esc_attr($key); ?>]" id="direction-<?php echo esc_attr($key); ?>-sf-wp" <?php echo esc_attr($checked_sf_wp); ?> required> <?php echo esc_html__('Salesforce to WordPress', 'object-sync-for-salesforce'); ?></label> |
|
305 | + <label><input type="radio" value="wp_sf" name="direction[<?php echo esc_attr($key); ?>]" id="direction-<?php echo esc_attr($key); ?>-wp-sf" <?php echo esc_attr($checked_wp_sf); ?> required> <?php echo esc_html__('WordPress to Salesforce', 'object-sync-for-salesforce'); ?></label> |
|
306 | + <label><input type="radio" value="sync" name="direction[<?php echo esc_attr($key); ?>]" id="direction-<?php echo esc_attr($key); ?>-sync" <?php echo esc_attr($checked_sync); ?> required> <?php echo esc_html__('Sync', 'object-sync-for-salesforce'); ?></label> |
|
307 | 307 | </div> |
308 | 308 | </td> |
309 | 309 | <td class="column-is_delete"> |
310 | - <input type="checkbox" name="is_delete[<?php echo esc_attr( $key ); ?>]" id="is_delete-<?php echo esc_attr( $key ); ?>" value="1" /> |
|
310 | + <input type="checkbox" name="is_delete[<?php echo esc_attr($key); ?>]" id="is_delete-<?php echo esc_attr($key); ?>" value="1" /> |
|
311 | 311 | </td> |
312 | 312 | </tr> |
313 | 313 | <?php |
314 | 314 | } // End foreach(). |
315 | - } elseif ( isset( $wordpress_object ) && isset( $salesforce_object ) ) { |
|
315 | + } elseif (isset($wordpress_object) && isset($salesforce_object)) { |
|
316 | 316 | ?> |
317 | 317 | <tr> |
318 | 318 | <td class="column-wordpress_field"> |
319 | 319 | <select name="wordpress_field[0]" id="wordpress_field-0"> |
320 | - <option value="">- <?php echo esc_html__( 'Select WordPress field', 'object-sync-for-salesforce' ); ?> -</option> |
|
320 | + <option value="">- <?php echo esc_html__('Select WordPress field', 'object-sync-for-salesforce'); ?> -</option> |
|
321 | 321 | <?php |
322 | - $wordpress_fields = $this->get_wordpress_object_fields( $wordpress_object ); |
|
323 | - foreach ( $wordpress_fields as $wordpress_field ) { |
|
324 | - echo sprintf( '<option value="%1$s">%2$s</option>', |
|
325 | - esc_attr( $wordpress_field['key'] ), |
|
326 | - esc_html( $wordpress_field['key'] ) |
|
322 | + $wordpress_fields = $this->get_wordpress_object_fields($wordpress_object); |
|
323 | + foreach ($wordpress_fields as $wordpress_field) { |
|
324 | + echo sprintf('<option value="%1$s">%2$s</option>', |
|
325 | + esc_attr($wordpress_field['key']), |
|
326 | + esc_html($wordpress_field['key']) |
|
327 | 327 | ); |
328 | 328 | } |
329 | 329 | ?> |
@@ -331,17 +331,17 @@ discard block |
||
331 | 331 | </td> |
332 | 332 | <td class="column-salesforce_field"> |
333 | 333 | <select name="salesforce_field[0]" id="salesforce_field-0"> |
334 | - <option value="">- <?php echo esc_html__( 'Select Salesforce field', 'object-sync-for-salesforce' ); ?> -</option> |
|
334 | + <option value="">- <?php echo esc_html__('Select Salesforce field', 'object-sync-for-salesforce'); ?> -</option> |
|
335 | 335 | <?php |
336 | 336 | $salesforce_fields = $this->get_salesforce_object_fields( |
337 | 337 | array( |
338 | 338 | 'salesforce_object' => $salesforce_object, |
339 | 339 | ) |
340 | 340 | ); |
341 | - foreach ( $salesforce_fields as $salesforce_field ) { |
|
342 | - echo sprintf( '<option value="%1$s">%2$s</option>', |
|
343 | - esc_attr( $salesforce_field['name'] ), |
|
344 | - esc_html( $salesforce_field['label'] ) |
|
341 | + foreach ($salesforce_fields as $salesforce_field) { |
|
342 | + echo sprintf('<option value="%1$s">%2$s</option>', |
|
343 | + esc_attr($salesforce_field['name']), |
|
344 | + esc_html($salesforce_field['label']) |
|
345 | 345 | ); |
346 | 346 | } |
347 | 347 | ?> |
@@ -355,9 +355,9 @@ discard block |
||
355 | 355 | </td> |
356 | 356 | <td class="column-direction"> |
357 | 357 | <div class="radios"> |
358 | - <label><input type="radio" value="sf_wp" name="direction[0]" id="direction-0-sf-wp" required> <?php echo esc_html__( 'Salesforce to WordPress', 'object-sync-for-salesforce' ); ?></label> |
|
359 | - <label><input type="radio" value="wp_sf" name="direction[0]" id="direction-0-wp-sf" required> <?php echo esc_html__( 'WordPress to Salesforce', 'object-sync-for-salesforce' ); ?></label> |
|
360 | - <label><input type="radio" value="sync" name="direction[0]" id="direction-0-sync" required checked> <?php echo esc_html__( 'Sync', 'object-sync-for-salesforce' ); ?></label> |
|
358 | + <label><input type="radio" value="sf_wp" name="direction[0]" id="direction-0-sf-wp" required> <?php echo esc_html__('Salesforce to WordPress', 'object-sync-for-salesforce'); ?></label> |
|
359 | + <label><input type="radio" value="wp_sf" name="direction[0]" id="direction-0-wp-sf" required> <?php echo esc_html__('WordPress to Salesforce', 'object-sync-for-salesforce'); ?></label> |
|
360 | + <label><input type="radio" value="sync" name="direction[0]" id="direction-0-sync" required checked> <?php echo esc_html__('Sync', 'object-sync-for-salesforce'); ?></label> |
|
361 | 361 | </div> |
362 | 362 | </td> |
363 | 363 | <td class="column-is_delete"> |
@@ -371,17 +371,17 @@ discard block |
||
371 | 371 | </table> |
372 | 372 | <!--<div class="spinner"></div>--> |
373 | 373 | <?php |
374 | - if ( isset( $fieldmap_fields ) && null !== $fieldmap_fields ) { |
|
375 | - $add_button_label = esc_html__( 'Add another field mapping', 'object-sync-for-salesforce' ); |
|
374 | + if (isset($fieldmap_fields) && null !== $fieldmap_fields) { |
|
375 | + $add_button_label = esc_html__('Add another field mapping', 'object-sync-for-salesforce'); |
|
376 | 376 | } else { |
377 | - $add_button_label = esc_html__( 'Add field mapping', 'object-sync-for-salesforce' ); |
|
377 | + $add_button_label = esc_html__('Add field mapping', 'object-sync-for-salesforce'); |
|
378 | 378 | } |
379 | 379 | ?> |
380 | 380 | <p><button type="button" id="add-field-mapping" class="button button-secondary"><?php echo $add_button_label; ?></button></p> |
381 | - <p class="description"><?php echo esc_html__( 'Prematch tells the plugin to match records that have the same value before sending data to Salesforce. Salesforce Key indicates the Salesforce field is an External ID. If either of these is checked, the plugin will do an UPSERT to avoid duplicate data when possible.', 'object-sync-for-salesforce' ); ?></p> |
|
381 | + <p class="description"><?php echo esc_html__('Prematch tells the plugin to match records that have the same value before sending data to Salesforce. Salesforce Key indicates the Salesforce field is an External ID. If either of these is checked, the plugin will do an UPSERT to avoid duplicate data when possible.', 'object-sync-for-salesforce'); ?></p> |
|
382 | 382 | </fieldset> |
383 | 383 | <fieldset class="sync_triggers"> |
384 | - <legend><?php echo esc_html__( 'Action triggers', 'object-sync-for-salesforce' ); ?></legend> |
|
384 | + <legend><?php echo esc_html__('Action triggers', 'object-sync-for-salesforce'); ?></legend> |
|
385 | 385 | <div class="checkboxes"> |
386 | 386 | <?php |
387 | 387 | $wordpress_create_checked = ''; |
@@ -390,9 +390,9 @@ discard block |
||
390 | 390 | $salesforce_create_checked = ''; |
391 | 391 | $salesforce_update_checked = ''; |
392 | 392 | $salesforce_delete_checked = ''; |
393 | - if ( isset( $sync_triggers ) && is_array( $sync_triggers ) ) { |
|
394 | - foreach ( $sync_triggers as $trigger ) { |
|
395 | - switch ( $trigger ) { |
|
393 | + if (isset($sync_triggers) && is_array($sync_triggers)) { |
|
394 | + foreach ($sync_triggers as $trigger) { |
|
395 | + switch ($trigger) { |
|
396 | 396 | case $this->mappings->sync_wordpress_create: |
397 | 397 | $wordpress_create_checked = ' checked'; |
398 | 398 | break; |
@@ -415,31 +415,31 @@ discard block |
||
415 | 415 | } |
416 | 416 | } |
417 | 417 | ?> |
418 | - <label><input type="checkbox" value="<?php echo esc_html( $this->mappings->sync_wordpress_create ); ?>" name="sync_triggers[]" id="sync_triggers-wordpress-create" <?php echo esc_attr( $wordpress_create_checked ); ?>><?php echo esc_html__( 'WordPress create', 'object-sync-for-salesforce' ); ?></label> |
|
419 | - <label><input type="checkbox" value="<?php echo esc_html( $this->mappings->sync_wordpress_update ); ?>" name="sync_triggers[]" id="sync_triggers-wordpress-update" <?php echo esc_attr( $wordpress_update_checked ); ?>><?php echo esc_html__( 'WordPress update', 'object-sync-for-salesforce' ); ?></label> |
|
420 | - <label><input type="checkbox" value="<?php echo esc_html( $this->mappings->sync_wordpress_delete ); ?>" name="sync_triggers[]" id="sync_triggers-wordpress-delete" <?php echo esc_attr( $wordpress_delete_checked ); ?>><?php echo esc_html__( 'WordPress delete', 'object-sync-for-salesforce' ); ?></label> |
|
421 | - <label><input type="checkbox" value="<?php echo esc_html( $this->mappings->sync_sf_create ); ?>" name="sync_triggers[]" id="sync_triggers-salesforce-create" <?php echo esc_attr( $salesforce_create_checked ); ?>><?php echo esc_html__( 'Salesforce create', 'object-sync-for-salesforce' ); ?></label> |
|
422 | - <label><input type="checkbox" value="<?php echo esc_html( $this->mappings->sync_sf_update ); ?>" name="sync_triggers[]" id="sync_triggers-salesforce-update" <?php echo esc_attr( $salesforce_update_checked ); ?>><?php echo esc_html__( 'Salesforce update', 'object-sync-for-salesforce' ); ?></label> |
|
423 | - <label><input type="checkbox" value="<?php echo esc_html( $this->mappings->sync_sf_delete ); ?>" name="sync_triggers[]" id="sync_triggers-salesforce-delete" <?php echo esc_attr( $salesforce_delete_checked ); ?>><?php echo esc_html__( 'Salesforce delete', 'object-sync-for-salesforce' ); ?></label> |
|
418 | + <label><input type="checkbox" value="<?php echo esc_html($this->mappings->sync_wordpress_create); ?>" name="sync_triggers[]" id="sync_triggers-wordpress-create" <?php echo esc_attr($wordpress_create_checked); ?>><?php echo esc_html__('WordPress create', 'object-sync-for-salesforce'); ?></label> |
|
419 | + <label><input type="checkbox" value="<?php echo esc_html($this->mappings->sync_wordpress_update); ?>" name="sync_triggers[]" id="sync_triggers-wordpress-update" <?php echo esc_attr($wordpress_update_checked); ?>><?php echo esc_html__('WordPress update', 'object-sync-for-salesforce'); ?></label> |
|
420 | + <label><input type="checkbox" value="<?php echo esc_html($this->mappings->sync_wordpress_delete); ?>" name="sync_triggers[]" id="sync_triggers-wordpress-delete" <?php echo esc_attr($wordpress_delete_checked); ?>><?php echo esc_html__('WordPress delete', 'object-sync-for-salesforce'); ?></label> |
|
421 | + <label><input type="checkbox" value="<?php echo esc_html($this->mappings->sync_sf_create); ?>" name="sync_triggers[]" id="sync_triggers-salesforce-create" <?php echo esc_attr($salesforce_create_checked); ?>><?php echo esc_html__('Salesforce create', 'object-sync-for-salesforce'); ?></label> |
|
422 | + <label><input type="checkbox" value="<?php echo esc_html($this->mappings->sync_sf_update); ?>" name="sync_triggers[]" id="sync_triggers-salesforce-update" <?php echo esc_attr($salesforce_update_checked); ?>><?php echo esc_html__('Salesforce update', 'object-sync-for-salesforce'); ?></label> |
|
423 | + <label><input type="checkbox" value="<?php echo esc_html($this->mappings->sync_sf_delete); ?>" name="sync_triggers[]" id="sync_triggers-salesforce-delete" <?php echo esc_attr($salesforce_delete_checked); ?>><?php echo esc_html__('Salesforce delete', 'object-sync-for-salesforce'); ?></label> |
|
424 | 424 | <p class="description"> |
425 | 425 | <?php |
426 | 426 | // translators: placeholders are for the class names: salesforce_push and salesforce_pull |
427 | - echo sprintf( esc_html__( 'Select which actions on WordPress objects and Salesforce objects should trigger a synchronization. These settings are used by the %1$s and %2$s classes respectively.', 'object-sync-for-salesforce' ), '<code>salesforce_push</code>', '<code>salesforce_pull</code>' ); |
|
427 | + echo sprintf(esc_html__('Select which actions on WordPress objects and Salesforce objects should trigger a synchronization. These settings are used by the %1$s and %2$s classes respectively.', 'object-sync-for-salesforce'), '<code>salesforce_push</code>', '<code>salesforce_pull</code>'); |
|
428 | 428 | ?> |
429 | 429 | </p> |
430 | 430 | </div> |
431 | 431 | <div class="checkboxes"> |
432 | - <label><input type="checkbox" name="push_async" id="process-async" value="1" <?php echo isset( $push_async ) && '1' === $push_async ? ' checked' : ''; ?>><?php echo esc_html__( 'Process asynchronously', 'object-sync-for-salesforce' ); ?></label> |
|
432 | + <label><input type="checkbox" name="push_async" id="process-async" value="1" <?php echo isset($push_async) && '1' === $push_async ? ' checked' : ''; ?>><?php echo esc_html__('Process asynchronously', 'object-sync-for-salesforce'); ?></label> |
|
433 | 433 | <p class="description"> |
434 | 434 | <?php |
435 | 435 | // translators: placeholder is for WordPress cron method name |
436 | - echo sprintf( esc_html__( 'If selected, push data will be queued for processing and synchronized when %s is run. This may increase site performance, but changes will not be reflected in real time.', 'object-sync-for-salesforce' ), '<code>wp_cron</code>' ); |
|
436 | + echo sprintf(esc_html__('If selected, push data will be queued for processing and synchronized when %s is run. This may increase site performance, but changes will not be reflected in real time.', 'object-sync-for-salesforce'), '<code>wp_cron</code>'); |
|
437 | 437 | ?> |
438 | 438 | </p> |
439 | 439 | </div> |
440 | 440 | <div class="checkboxes"> |
441 | - <label><input type="checkbox" name="push_drafts" id="push-drafts" value="1" <?php echo isset( $push_drafts ) && '1' === $push_drafts ? ' checked' : ''; ?>><?php echo esc_html__( 'Push drafts', 'object-sync-for-salesforce' ); ?></label> |
|
442 | - <p class="description"><?php echo esc_html__( 'If selected, WordPress will send drafts of this object type (if it creates drafts for it) to Salesforce.', 'object-sync-for-salesforce' ); ?></p> |
|
441 | + <label><input type="checkbox" name="push_drafts" id="push-drafts" value="1" <?php echo isset($push_drafts) && '1' === $push_drafts ? ' checked' : ''; ?>><?php echo esc_html__('Push drafts', 'object-sync-for-salesforce'); ?></label> |
|
442 | + <p class="description"><?php echo esc_html__('If selected, WordPress will send drafts of this object type (if it creates drafts for it) to Salesforce.', 'object-sync-for-salesforce'); ?></p> |
|
443 | 443 | </div> |
444 | 444 | <?php |
445 | 445 | /* |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | <?php |
459 | 459 | submit_button( |
460 | 460 | // translators: the placeholder refers to the currently selected method (add, edit, or clone) |
461 | - sprintf( esc_html__( '%1$s fieldmap', 'object-sync-for-salesforce' ), ucfirst( $method ) ) |
|
461 | + sprintf(esc_html__('%1$s fieldmap', 'object-sync-for-salesforce'), ucfirst($method)) |
|
462 | 462 | ); |
463 | 463 | ?> |
464 | 464 | </form> |
@@ -27,63 +27,63 @@ discard block |
||
27 | 27 | protected $queue; |
28 | 28 | |
29 | 29 | /** |
30 | - * @var string |
|
31 | - * Default path for the Salesforce authorize URL |
|
32 | - */ |
|
30 | + * @var string |
|
31 | + * Default path for the Salesforce authorize URL |
|
32 | + */ |
|
33 | 33 | public $default_authorize_url_path; |
34 | 34 | |
35 | 35 | /** |
36 | - * @var string |
|
37 | - * Default path for the Salesforce token URL |
|
38 | - */ |
|
36 | + * @var string |
|
37 | + * Default path for the Salesforce token URL |
|
38 | + */ |
|
39 | 39 | public $default_token_url_path; |
40 | 40 | |
41 | 41 | /** |
42 | - * @var string |
|
43 | - * What version of the Salesforce API should be the default on the settings screen. |
|
44 | - * Users can edit this, but they won't see a correct list of all their available versions until WordPress has |
|
45 | - * been authenticated with Salesforce. |
|
46 | - */ |
|
42 | + * @var string |
|
43 | + * What version of the Salesforce API should be the default on the settings screen. |
|
44 | + * Users can edit this, but they won't see a correct list of all their available versions until WordPress has |
|
45 | + * been authenticated with Salesforce. |
|
46 | + */ |
|
47 | 47 | public $default_api_version; |
48 | 48 | |
49 | 49 | /** |
50 | - * @var bool |
|
51 | - * Default for whether to limit to triggerable items |
|
52 | - * Users can edit this |
|
53 | - */ |
|
50 | + * @var bool |
|
51 | + * Default for whether to limit to triggerable items |
|
52 | + * Users can edit this |
|
53 | + */ |
|
54 | 54 | public $default_triggerable; |
55 | 55 | |
56 | 56 | /** |
57 | - * @var bool |
|
58 | - * Default for whether to limit to updateable items |
|
59 | - * Users can edit this |
|
60 | - */ |
|
57 | + * @var bool |
|
58 | + * Default for whether to limit to updateable items |
|
59 | + * Users can edit this |
|
60 | + */ |
|
61 | 61 | public $default_updateable; |
62 | 62 | |
63 | 63 | /** |
64 | - * @var int |
|
65 | - * Default pull throttle for how often Salesforce can pull |
|
66 | - * Users can edit this |
|
67 | - */ |
|
64 | + * @var int |
|
65 | + * Default pull throttle for how often Salesforce can pull |
|
66 | + * Users can edit this |
|
67 | + */ |
|
68 | 68 | public $default_pull_throttle; |
69 | 69 | |
70 | 70 | /** |
71 | - * Constructor which sets up admin pages |
|
72 | - * |
|
73 | - * @param object $wpdb |
|
74 | - * @param string $version |
|
75 | - * @param array $login_credentials |
|
76 | - * @param string $slug |
|
77 | - * @param object $wordpress |
|
78 | - * @param object $salesforce |
|
79 | - * @param object $mappings |
|
80 | - * @param object $push |
|
81 | - * @param object $pull |
|
82 | - * @param object $logging |
|
83 | - * @param array $schedulable_classes |
|
84 | - * @param object $queue |
|
85 | - * @throws \Exception |
|
86 | - */ |
|
71 | + * Constructor which sets up admin pages |
|
72 | + * |
|
73 | + * @param object $wpdb |
|
74 | + * @param string $version |
|
75 | + * @param array $login_credentials |
|
76 | + * @param string $slug |
|
77 | + * @param object $wordpress |
|
78 | + * @param object $salesforce |
|
79 | + * @param object $mappings |
|
80 | + * @param object $push |
|
81 | + * @param object $pull |
|
82 | + * @param object $logging |
|
83 | + * @param array $schedulable_classes |
|
84 | + * @param object $queue |
|
85 | + * @throws \Exception |
|
86 | + */ |
|
87 | 87 | public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) { |
88 | 88 | $this->wpdb = $wpdb; |
89 | 89 | $this->version = $version; |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | - * Create the action hooks to create the admin page(s) |
|
124 | - * |
|
125 | - */ |
|
123 | + * Create the action hooks to create the admin page(s) |
|
124 | + * |
|
125 | + */ |
|
126 | 126 | public function add_actions() { |
127 | 127 | add_action( 'admin_init', array( $this, 'salesforce_settings_forms' ) ); |
128 | 128 | add_action( 'admin_init', array( $this, 'notices' ) ); |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | - * Recurring task to check Salesforce for data |
|
161 | - * |
|
162 | - */ |
|
160 | + * Recurring task to check Salesforce for data |
|
161 | + * |
|
162 | + */ |
|
163 | 163 | public function change_action_schedule( $old_schedule, $new_schedule, $option_name ) { |
164 | 164 | |
165 | 165 | // exit if nothing changed |
@@ -195,21 +195,21 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | - * Create WordPress admin options page |
|
199 | - * |
|
200 | - */ |
|
198 | + * Create WordPress admin options page |
|
199 | + * |
|
200 | + */ |
|
201 | 201 | public function create_admin_menu() { |
202 | 202 | $title = __( 'Salesforce', 'object-sync-for-salesforce' ); |
203 | 203 | add_options_page( $title, $title, 'configure_salesforce', 'object-sync-salesforce-admin', array( $this, 'show_admin_page' ) ); |
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Render full admin pages in WordPress |
|
208 | - * This allows other plugins to add tabs to the Salesforce settings screen |
|
209 | - * |
|
210 | - * todo: better front end: html, organization of html into templates, css, js |
|
211 | - * |
|
212 | - */ |
|
207 | + * Render full admin pages in WordPress |
|
208 | + * This allows other plugins to add tabs to the Salesforce settings screen |
|
209 | + * |
|
210 | + * todo: better front end: html, organization of html into templates, css, js |
|
211 | + * |
|
212 | + */ |
|
213 | 213 | public function show_admin_page() { |
214 | 214 | $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
215 | 215 | echo '<div class="wrap">'; |
@@ -419,10 +419,10 @@ discard block |
||
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
422 | - * Create default WordPress admin settings form for salesforce |
|
423 | - * This is for the Settings page/tab |
|
424 | - * |
|
425 | - */ |
|
422 | + * Create default WordPress admin settings form for salesforce |
|
423 | + * This is for the Settings page/tab |
|
424 | + * |
|
425 | + */ |
|
426 | 426 | public function salesforce_settings_forms() { |
427 | 427 | $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
428 | 428 | $page = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
@@ -447,13 +447,13 @@ discard block |
||
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Fields for the Settings tab |
|
451 | - * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
452 | - * |
|
453 | - * @param string $page |
|
454 | - * @param string $section |
|
455 | - * @param string $input_callback |
|
456 | - */ |
|
450 | + * Fields for the Settings tab |
|
451 | + * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
452 | + * |
|
453 | + * @param string $page |
|
454 | + * @param string $section |
|
455 | + * @param string $input_callback |
|
456 | + */ |
|
457 | 457 | private function fields_settings( $page, $section, $callbacks ) { |
458 | 458 | add_settings_section( $page, ucwords( $page ), null, $page ); |
459 | 459 | $salesforce_settings = array( |
@@ -687,25 +687,25 @@ discard block |
||
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
690 | - * Fields for the Fieldmaps tab |
|
691 | - * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
692 | - * |
|
693 | - * @param string $page |
|
694 | - * @param string $section |
|
695 | - * @param string $input_callback |
|
696 | - */ |
|
690 | + * Fields for the Fieldmaps tab |
|
691 | + * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
692 | + * |
|
693 | + * @param string $page |
|
694 | + * @param string $section |
|
695 | + * @param string $input_callback |
|
696 | + */ |
|
697 | 697 | private function fields_fieldmaps( $page, $section, $input_callback = '' ) { |
698 | 698 | add_settings_section( $page, ucwords( $page ), null, $page ); |
699 | 699 | } |
700 | 700 | |
701 | 701 | /** |
702 | - * Fields for the Scheduling tab |
|
703 | - * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
704 | - * |
|
705 | - * @param string $page |
|
706 | - * @param string $section |
|
707 | - * @param string $input_callback |
|
708 | - */ |
|
702 | + * Fields for the Scheduling tab |
|
703 | + * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
704 | + * |
|
705 | + * @param string $page |
|
706 | + * @param string $section |
|
707 | + * @param string $input_callback |
|
708 | + */ |
|
709 | 709 | private function fields_scheduling( $page, $section, $callbacks ) { |
710 | 710 | foreach ( $this->schedulable_classes as $key => $value ) { |
711 | 711 | add_settings_section( $key, $value['label'], null, $page ); |
@@ -784,13 +784,13 @@ discard block |
||
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
787 | - * Fields for the Log Settings tab |
|
788 | - * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
789 | - * |
|
790 | - * @param string $page |
|
791 | - * @param string $section |
|
792 | - * @param array $callbacks |
|
793 | - */ |
|
787 | + * Fields for the Log Settings tab |
|
788 | + * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
789 | + * |
|
790 | + * @param string $page |
|
791 | + * @param string $section |
|
792 | + * @param array $callbacks |
|
793 | + */ |
|
794 | 794 | private function fields_log_settings( $page, $section, $callbacks ) { |
795 | 795 | add_settings_section( $page, ucwords( str_replace( '_', ' ', $page ) ), null, $page ); |
796 | 796 | $log_settings = array( |
@@ -968,9 +968,9 @@ discard block |
||
968 | 968 | } |
969 | 969 | |
970 | 970 | /** |
971 | - * Create the notices, settings, and conditions by which admin notices should appear |
|
972 | - * |
|
973 | - */ |
|
971 | + * Create the notices, settings, and conditions by which admin notices should appear |
|
972 | + * |
|
973 | + */ |
|
974 | 974 | public function notices() { |
975 | 975 | |
976 | 976 | // before a notice is displayed, we should make sure we are on a page related to this plugin |
@@ -1043,14 +1043,14 @@ discard block |
||
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | /** |
1046 | - * Get all the Salesforce object settings for fieldmapping |
|
1047 | - * This takes either the $_POST array via ajax, or can be directly called with a $data array |
|
1048 | - * |
|
1049 | - * @param array $data |
|
1050 | - * data must contain a salesforce_object |
|
1051 | - * can optionally contain a type |
|
1052 | - * @return array $object_settings |
|
1053 | - */ |
|
1046 | + * Get all the Salesforce object settings for fieldmapping |
|
1047 | + * This takes either the $_POST array via ajax, or can be directly called with a $data array |
|
1048 | + * |
|
1049 | + * @param array $data |
|
1050 | + * data must contain a salesforce_object |
|
1051 | + * can optionally contain a type |
|
1052 | + * @return array $object_settings |
|
1053 | + */ |
|
1054 | 1054 | public function get_salesforce_object_description( $data = array() ) { |
1055 | 1055 | $ajax = false; |
1056 | 1056 | if ( empty( $data ) ) { |
@@ -1098,13 +1098,13 @@ discard block |
||
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | /** |
1101 | - * Get Salesforce object fields for fieldmapping |
|
1102 | - * |
|
1103 | - * @param array $data |
|
1104 | - * data must contain a salesforce_object |
|
1105 | - * can optionally contain a type for the field |
|
1106 | - * @return array $object_fields |
|
1107 | - */ |
|
1101 | + * Get Salesforce object fields for fieldmapping |
|
1102 | + * |
|
1103 | + * @param array $data |
|
1104 | + * data must contain a salesforce_object |
|
1105 | + * can optionally contain a type for the field |
|
1106 | + * @return array $object_fields |
|
1107 | + */ |
|
1108 | 1108 | public function get_salesforce_object_fields( $data = array() ) { |
1109 | 1109 | |
1110 | 1110 | if ( ! empty( $data['salesforce_object'] ) ) { |
@@ -1132,12 +1132,12 @@ discard block |
||
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | /** |
1135 | - * Get WordPress object fields for fieldmapping |
|
1136 | - * This takes either the $_POST array via ajax, or can be directly called with a $wordpress_object field |
|
1137 | - * |
|
1138 | - * @param string $wordpress_object |
|
1139 | - * @return array $object_fields |
|
1140 | - */ |
|
1135 | + * Get WordPress object fields for fieldmapping |
|
1136 | + * This takes either the $_POST array via ajax, or can be directly called with a $wordpress_object field |
|
1137 | + * |
|
1138 | + * @param string $wordpress_object |
|
1139 | + * @return array $object_fields |
|
1140 | + */ |
|
1141 | 1141 | public function get_wordpress_object_fields( $wordpress_object = '' ) { |
1142 | 1142 | $ajax = false; |
1143 | 1143 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
@@ -1156,13 +1156,13 @@ discard block |
||
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | /** |
1159 | - * Get WordPress and Salesforce object fields together for fieldmapping |
|
1160 | - * This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $salesforce_object fields |
|
1161 | - * |
|
1162 | - * @param string $wordpress_object |
|
1163 | - * @param string $salesforce_object |
|
1164 | - * @return array $object_fields |
|
1165 | - */ |
|
1159 | + * Get WordPress and Salesforce object fields together for fieldmapping |
|
1160 | + * This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $salesforce_object fields |
|
1161 | + * |
|
1162 | + * @param string $wordpress_object |
|
1163 | + * @param string $salesforce_object |
|
1164 | + * @return array $object_fields |
|
1165 | + */ |
|
1166 | 1166 | public function get_wp_sf_object_fields( $wordpress_object = '', $salesforce = '' ) { |
1167 | 1167 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1168 | 1168 | if ( empty( $wordpress_object ) ) { |
@@ -1187,12 +1187,12 @@ discard block |
||
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | /** |
1190 | - * Manually push the WordPress object to Salesforce |
|
1191 | - * This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $wordpress_id fields |
|
1192 | - * |
|
1193 | - * @param string $wordpress_object |
|
1194 | - * @param int $wordpress_id |
|
1195 | - */ |
|
1190 | + * Manually push the WordPress object to Salesforce |
|
1191 | + * This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $wordpress_id fields |
|
1192 | + * |
|
1193 | + * @param string $wordpress_object |
|
1194 | + * @param int $wordpress_id |
|
1195 | + */ |
|
1196 | 1196 | public function push_to_salesforce( $wordpress_object = '', $wordpress_id = '' ) { |
1197 | 1197 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1198 | 1198 | if ( empty( $wordpress_object ) && empty( $wordpress_id ) ) { |
@@ -1211,12 +1211,12 @@ discard block |
||
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | /** |
1214 | - * Manually pull the Salesforce object into WordPress |
|
1215 | - * This takes either the $_POST array via ajax, or can be directly called with $salesforce_id fields |
|
1216 | - * |
|
1217 | - * @param string $salesforce_id |
|
1218 | - * @param string $wordpress_object |
|
1219 | - */ |
|
1214 | + * Manually pull the Salesforce object into WordPress |
|
1215 | + * This takes either the $_POST array via ajax, or can be directly called with $salesforce_id fields |
|
1216 | + * |
|
1217 | + * @param string $salesforce_id |
|
1218 | + * @param string $wordpress_object |
|
1219 | + */ |
|
1220 | 1220 | public function pull_from_salesforce( $salesforce_id = '', $wordpress_object = '' ) { |
1221 | 1221 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1222 | 1222 | if ( empty( $wordpress_object ) && empty( $salesforce_id ) ) { |
@@ -1233,11 +1233,11 @@ discard block |
||
1233 | 1233 | } |
1234 | 1234 | |
1235 | 1235 | /** |
1236 | - * Manually pull the Salesforce object into WordPress |
|
1237 | - * This takes an id for a mapping object row |
|
1238 | - * |
|
1239 | - * @param int $mapping_id |
|
1240 | - */ |
|
1236 | + * Manually pull the Salesforce object into WordPress |
|
1237 | + * This takes an id for a mapping object row |
|
1238 | + * |
|
1239 | + * @param int $mapping_id |
|
1240 | + */ |
|
1241 | 1241 | public function refresh_mapped_data( $mapping_id = '' ) { |
1242 | 1242 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1243 | 1243 | if ( empty( $mapping_id ) ) { |
@@ -1256,13 +1256,13 @@ discard block |
||
1256 | 1256 | } |
1257 | 1257 | |
1258 | 1258 | /** |
1259 | - * Prepare fieldmap data and redirect after processing |
|
1260 | - * This runs when the create or update forms are submitted |
|
1261 | - * It is public because it depends on an admin hook |
|
1262 | - * It then calls the Object_Sync_Sf_Mapping class and sends prepared data over to it, then redirects to the correct page |
|
1263 | - * This method does include error handling, by loading the submission in a transient if there is an error, and then deleting it upon success |
|
1264 | - * |
|
1265 | - */ |
|
1259 | + * Prepare fieldmap data and redirect after processing |
|
1260 | + * This runs when the create or update forms are submitted |
|
1261 | + * It is public because it depends on an admin hook |
|
1262 | + * It then calls the Object_Sync_Sf_Mapping class and sends prepared data over to it, then redirects to the correct page |
|
1263 | + * This method does include error handling, by loading the submission in a transient if there is an error, and then deleting it upon success |
|
1264 | + * |
|
1265 | + */ |
|
1266 | 1266 | public function prepare_fieldmap_data() { |
1267 | 1267 | $error = false; |
1268 | 1268 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
@@ -1310,12 +1310,12 @@ discard block |
||
1310 | 1310 | } |
1311 | 1311 | |
1312 | 1312 | /** |
1313 | - * Delete fieldmap data and redirect after processing |
|
1314 | - * This runs when the delete link is clicked, after the user confirms |
|
1315 | - * It is public because it depends on an admin hook |
|
1316 | - * It then calls the Object_Sync_Sf_Mapping class and the delete method |
|
1317 | - * |
|
1318 | - */ |
|
1313 | + * Delete fieldmap data and redirect after processing |
|
1314 | + * This runs when the delete link is clicked, after the user confirms |
|
1315 | + * It is public because it depends on an admin hook |
|
1316 | + * It then calls the Object_Sync_Sf_Mapping class and the delete method |
|
1317 | + * |
|
1318 | + */ |
|
1319 | 1319 | public function delete_fieldmap() { |
1320 | 1320 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1321 | 1321 | if ( $post_data['id'] ) { |
@@ -1331,13 +1331,13 @@ discard block |
||
1331 | 1331 | } |
1332 | 1332 | |
1333 | 1333 | /** |
1334 | - * Prepare object data and redirect after processing |
|
1335 | - * This runs when the update form is submitted |
|
1336 | - * It is public because it depends on an admin hook |
|
1337 | - * It then calls the Object_Sync_Sf_Mapping class and sends prepared data over to it, then redirects to the correct page |
|
1338 | - * This method does include error handling, by loading the submission in a transient if there is an error, and then deleting it upon success |
|
1339 | - * |
|
1340 | - */ |
|
1334 | + * Prepare object data and redirect after processing |
|
1335 | + * This runs when the update form is submitted |
|
1336 | + * It is public because it depends on an admin hook |
|
1337 | + * It then calls the Object_Sync_Sf_Mapping class and sends prepared data over to it, then redirects to the correct page |
|
1338 | + * This method does include error handling, by loading the submission in a transient if there is an error, and then deleting it upon success |
|
1339 | + * |
|
1340 | + */ |
|
1341 | 1341 | public function prepare_object_map_data() { |
1342 | 1342 | $error = false; |
1343 | 1343 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
@@ -1376,12 +1376,12 @@ discard block |
||
1376 | 1376 | } |
1377 | 1377 | |
1378 | 1378 | /** |
1379 | - * Delete object map data and redirect after processing |
|
1380 | - * This runs when the delete link is clicked on an error row, after the user confirms |
|
1381 | - * It is public because it depends on an admin hook |
|
1382 | - * It then calls the Object_Sync_Sf_Mapping class and the delete method |
|
1383 | - * |
|
1384 | - */ |
|
1379 | + * Delete object map data and redirect after processing |
|
1380 | + * This runs when the delete link is clicked on an error row, after the user confirms |
|
1381 | + * It is public because it depends on an admin hook |
|
1382 | + * It then calls the Object_Sync_Sf_Mapping class and the delete method |
|
1383 | + * |
|
1384 | + */ |
|
1385 | 1385 | public function delete_object_map() { |
1386 | 1386 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1387 | 1387 | if ( $post_data['id'] ) { |
@@ -1397,9 +1397,9 @@ discard block |
||
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | /** |
1400 | - * Import a json file and use it for plugin data |
|
1401 | - * |
|
1402 | - */ |
|
1400 | + * Import a json file and use it for plugin data |
|
1401 | + * |
|
1402 | + */ |
|
1403 | 1403 | public function import_json_file() { |
1404 | 1404 | |
1405 | 1405 | if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_import'], 'object_sync_for_salesforce_nonce_import' ) ) { |
@@ -1497,9 +1497,9 @@ discard block |
||
1497 | 1497 | } |
1498 | 1498 | |
1499 | 1499 | /** |
1500 | - * Create a json file for exporting |
|
1501 | - * |
|
1502 | - */ |
|
1500 | + * Create a json file for exporting |
|
1501 | + * |
|
1502 | + */ |
|
1503 | 1503 | public function export_json_file() { |
1504 | 1504 | |
1505 | 1505 | if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_export'], 'object_sync_for_salesforce_nonce_export' ) ) { |
@@ -1528,10 +1528,10 @@ discard block |
||
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | /** |
1531 | - * Default display for <input> fields |
|
1532 | - * |
|
1533 | - * @param array $args |
|
1534 | - */ |
|
1531 | + * Default display for <input> fields |
|
1532 | + * |
|
1533 | + * @param array $args |
|
1534 | + */ |
|
1535 | 1535 | public function display_input_field( $args ) { |
1536 | 1536 | $type = $args['type']; |
1537 | 1537 | $id = $args['label_for']; |
@@ -1578,11 +1578,11 @@ discard block |
||
1578 | 1578 | } |
1579 | 1579 | |
1580 | 1580 | /** |
1581 | - * Display for multiple checkboxes |
|
1582 | - * Above method can handle a single checkbox as it is |
|
1583 | - * |
|
1584 | - * @param array $args |
|
1585 | - */ |
|
1581 | + * Display for multiple checkboxes |
|
1582 | + * Above method can handle a single checkbox as it is |
|
1583 | + * |
|
1584 | + * @param array $args |
|
1585 | + */ |
|
1586 | 1586 | public function display_checkboxes( $args ) { |
1587 | 1587 | $type = 'checkbox'; |
1588 | 1588 | $name = $args['name']; |
@@ -1616,10 +1616,10 @@ discard block |
||
1616 | 1616 | } |
1617 | 1617 | |
1618 | 1618 | /** |
1619 | - * Display for a dropdown |
|
1620 | - * |
|
1621 | - * @param array $args |
|
1622 | - */ |
|
1619 | + * Display for a dropdown |
|
1620 | + * |
|
1621 | + * @param array $args |
|
1622 | + */ |
|
1623 | 1623 | public function display_select( $args ) { |
1624 | 1624 | $type = $args['type']; |
1625 | 1625 | $id = $args['label_for']; |
@@ -1663,10 +1663,10 @@ discard block |
||
1663 | 1663 | } |
1664 | 1664 | |
1665 | 1665 | /** |
1666 | - * Dropdown formatted list of Salesforce API versions |
|
1667 | - * |
|
1668 | - * @return array $args |
|
1669 | - */ |
|
1666 | + * Dropdown formatted list of Salesforce API versions |
|
1667 | + * |
|
1668 | + * @return array $args |
|
1669 | + */ |
|
1670 | 1670 | private function version_options() { |
1671 | 1671 | $versions = $this->salesforce['sfapi']->get_api_versions(); |
1672 | 1672 | $args = array(); |
@@ -1680,10 +1680,10 @@ discard block |
||
1680 | 1680 | } |
1681 | 1681 | |
1682 | 1682 | /** |
1683 | - * Default display for <a href> links |
|
1684 | - * |
|
1685 | - * @param array $args |
|
1686 | - */ |
|
1683 | + * Default display for <a href> links |
|
1684 | + * |
|
1685 | + * @param array $args |
|
1686 | + */ |
|
1687 | 1687 | public function display_link( $args ) { |
1688 | 1688 | $label = $args['label']; |
1689 | 1689 | $desc = $args['desc']; |
@@ -1710,11 +1710,11 @@ discard block |
||
1710 | 1710 | } |
1711 | 1711 | |
1712 | 1712 | /** |
1713 | - * Allow for a standard sanitize/validate method. We could use more specific ones if need be, but this one provides a baseline. |
|
1714 | - * |
|
1715 | - * @param string $option |
|
1716 | - * @return string $option |
|
1717 | - */ |
|
1713 | + * Allow for a standard sanitize/validate method. We could use more specific ones if need be, but this one provides a baseline. |
|
1714 | + * |
|
1715 | + * @param string $option |
|
1716 | + * @return string $option |
|
1717 | + */ |
|
1718 | 1718 | public function sanitize_validate_text( $option ) { |
1719 | 1719 | if ( is_array( $option ) ) { |
1720 | 1720 | $options = array(); |
@@ -1728,10 +1728,10 @@ discard block |
||
1728 | 1728 | } |
1729 | 1729 | |
1730 | 1730 | /** |
1731 | - * Run a demo of Salesforce API call on the authenticate tab after WordPress has authenticated with it |
|
1732 | - * |
|
1733 | - * @param object $sfapi |
|
1734 | - */ |
|
1731 | + * Run a demo of Salesforce API call on the authenticate tab after WordPress has authenticated with it |
|
1732 | + * |
|
1733 | + * @param object $sfapi |
|
1734 | + */ |
|
1735 | 1735 | private function status( $sfapi ) { |
1736 | 1736 | |
1737 | 1737 | $versions = $sfapi->get_api_versions(); |
@@ -1790,10 +1790,10 @@ discard block |
||
1790 | 1790 | } |
1791 | 1791 | |
1792 | 1792 | /** |
1793 | - * Deauthorize WordPress from Salesforce. |
|
1794 | - * This deletes the tokens from the database; it does not currently do anything in Salesforce |
|
1795 | - * For this plugin at this time, that is the decision we are making: don't do any kind of authorization stuff inside Salesforce |
|
1796 | - */ |
|
1793 | + * Deauthorize WordPress from Salesforce. |
|
1794 | + * This deletes the tokens from the database; it does not currently do anything in Salesforce |
|
1795 | + * For this plugin at this time, that is the decision we are making: don't do any kind of authorization stuff inside Salesforce |
|
1796 | + */ |
|
1797 | 1797 | private function logout() { |
1798 | 1798 | $this->access_token = delete_option( $this->option_prefix . 'access_token' ); |
1799 | 1799 | $this->instance_url = delete_option( $this->option_prefix . 'instance_url' ); |
@@ -1805,8 +1805,8 @@ discard block |
||
1805 | 1805 | } |
1806 | 1806 | |
1807 | 1807 | /** |
1808 | - * Ajax call to clear the plugin cache. |
|
1809 | - */ |
|
1808 | + * Ajax call to clear the plugin cache. |
|
1809 | + */ |
|
1810 | 1810 | public function clear_sfwp_cache() { |
1811 | 1811 | $result = $this->clear_cache( true ); |
1812 | 1812 | $response = array( |
@@ -1817,9 +1817,9 @@ discard block |
||
1817 | 1817 | } |
1818 | 1818 | |
1819 | 1819 | /** |
1820 | - * Clear the plugin's cache. |
|
1821 | - * This uses the flush method contained in the WordPress cache to clear all of this plugin's cached data. |
|
1822 | - */ |
|
1820 | + * Clear the plugin's cache. |
|
1821 | + * This uses the flush method contained in the WordPress cache to clear all of this plugin's cached data. |
|
1822 | + */ |
|
1823 | 1823 | private function clear_cache( $ajax = false ) { |
1824 | 1824 | $result = (bool) $this->wordpress->sfwp_transients->flush(); |
1825 | 1825 | if ( true === $result ) { |
@@ -1839,9 +1839,9 @@ discard block |
||
1839 | 1839 | } |
1840 | 1840 | |
1841 | 1841 | /** |
1842 | - * Check WordPress Admin permissions |
|
1843 | - * Check if the current user is allowed to access the Salesforce plugin options |
|
1844 | - */ |
|
1842 | + * Check WordPress Admin permissions |
|
1843 | + * Check if the current user is allowed to access the Salesforce plugin options |
|
1844 | + */ |
|
1845 | 1845 | private function check_wordpress_admin_permissions() { |
1846 | 1846 | |
1847 | 1847 | // one programmatic way to give this capability to additional user roles is the |
@@ -1861,10 +1861,10 @@ discard block |
||
1861 | 1861 | } |
1862 | 1862 | |
1863 | 1863 | /** |
1864 | - * Show what we know about this user's relationship to a Salesforce object, if any |
|
1865 | - * @param object $user |
|
1866 | - * |
|
1867 | - */ |
|
1864 | + * Show what we know about this user's relationship to a Salesforce object, if any |
|
1865 | + * @param object $user |
|
1866 | + * |
|
1867 | + */ |
|
1868 | 1868 | public function show_salesforce_user_fields( $user ) { |
1869 | 1869 | $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
1870 | 1870 | if ( true === $this->check_wordpress_admin_permissions() ) { |
@@ -1888,10 +1888,10 @@ discard block |
||
1888 | 1888 | } |
1889 | 1889 | |
1890 | 1890 | /** |
1891 | - * If the user profile has been mapped to Salesforce, do it |
|
1892 | - * @param int $user_id |
|
1893 | - * |
|
1894 | - */ |
|
1891 | + * If the user profile has been mapped to Salesforce, do it |
|
1892 | + * @param int $user_id |
|
1893 | + * |
|
1894 | + */ |
|
1895 | 1895 | public function save_salesforce_user_fields( $user_id ) { |
1896 | 1896 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1897 | 1897 | if ( isset( $post_data['salesforce_update_mapped_user'] ) && '1' === rawurlencode( $post_data['salesforce_update_mapped_user'] ) ) { |
@@ -1916,10 +1916,10 @@ discard block |
||
1916 | 1916 | } |
1917 | 1917 | |
1918 | 1918 | /** |
1919 | - * Render tabs for settings pages in admin |
|
1920 | - * @param array $tabs |
|
1921 | - * @param string $tab |
|
1922 | - */ |
|
1919 | + * Render tabs for settings pages in admin |
|
1920 | + * @param array $tabs |
|
1921 | + * @param string $tab |
|
1922 | + */ |
|
1923 | 1923 | private function tabs( $tabs, $tab = '' ) { |
1924 | 1924 | |
1925 | 1925 | $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
@@ -1949,9 +1949,9 @@ discard block |
||
1949 | 1949 | } |
1950 | 1950 | |
1951 | 1951 | /** |
1952 | - * Clear schedule |
|
1953 | - * This clears the schedule if the user clicks the button |
|
1954 | - */ |
|
1952 | + * Clear schedule |
|
1953 | + * This clears the schedule if the user clicks the button |
|
1954 | + */ |
|
1955 | 1955 | private function clear_schedule( $schedule_name = '' ) { |
1956 | 1956 | if ( '' !== $schedule_name ) { |
1957 | 1957 | $schedule = $this->schedule( $schedule_name ); |
@@ -1973,8 +1973,8 @@ discard block |
||
1973 | 1973 | } |
1974 | 1974 | |
1975 | 1975 | /** |
1976 | - * Load the schedule class |
|
1977 | - */ |
|
1976 | + * Load the schedule class |
|
1977 | + */ |
|
1978 | 1978 | private function schedule( $schedule_name ) { |
1979 | 1979 | if ( ! class_exists( 'Object_Sync_Sf_Schedule' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) { |
1980 | 1980 | require_once plugin_dir_path( __FILE__ ) . '../vendor/autoload.php'; |
@@ -1986,21 +1986,21 @@ discard block |
||
1986 | 1986 | } |
1987 | 1987 | |
1988 | 1988 | /** |
1989 | - * Create an object map between a WordPress object and a Salesforce object |
|
1990 | - * |
|
1991 | - * @param int $wordpress_id |
|
1992 | - * Unique identifier for the WordPress object |
|
1993 | - * @param string $wordpress_object |
|
1994 | - * What kind of object is it? |
|
1995 | - * @param string $salesforce_id |
|
1996 | - * Unique identifier for the Salesforce object |
|
1997 | - * @param string $action |
|
1998 | - * Did we push or pull? |
|
1999 | - * |
|
2000 | - * @return int $wpdb->insert_id |
|
2001 | - * This is the database row for the map object |
|
2002 | - * |
|
2003 | - */ |
|
1989 | + * Create an object map between a WordPress object and a Salesforce object |
|
1990 | + * |
|
1991 | + * @param int $wordpress_id |
|
1992 | + * Unique identifier for the WordPress object |
|
1993 | + * @param string $wordpress_object |
|
1994 | + * What kind of object is it? |
|
1995 | + * @param string $salesforce_id |
|
1996 | + * Unique identifier for the Salesforce object |
|
1997 | + * @param string $action |
|
1998 | + * Did we push or pull? |
|
1999 | + * |
|
2000 | + * @return int $wpdb->insert_id |
|
2001 | + * This is the database row for the map object |
|
2002 | + * |
|
2003 | + */ |
|
2004 | 2004 | private function create_object_map( $wordpress_id, $wordpress_object, $salesforce_id, $action = '' ) { |
2005 | 2005 | // Create object map and save it |
2006 | 2006 | $mapping_object = $this->mappings->create_object_map( |
@@ -5,7 +5,7 @@ discard block |
||
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 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param object $queue |
85 | 85 | * @throws \Exception |
86 | 86 | */ |
87 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) { |
|
87 | + public function __construct($wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue) { |
|
88 | 88 | $this->wpdb = $wpdb; |
89 | 89 | $this->version = $version; |
90 | 90 | $this->login_credentials = $login_credentials; |
@@ -124,35 +124,35 @@ discard block |
||
124 | 124 | * |
125 | 125 | */ |
126 | 126 | public function add_actions() { |
127 | - add_action( 'admin_init', array( $this, 'salesforce_settings_forms' ) ); |
|
128 | - add_action( 'admin_init', array( $this, 'notices' ) ); |
|
129 | - add_action( 'admin_post_post_fieldmap', array( $this, 'prepare_fieldmap_data' ) ); |
|
130 | - |
|
131 | - add_action( 'admin_post_delete_fieldmap', array( $this, 'delete_fieldmap' ) ); |
|
132 | - add_action( 'wp_ajax_get_salesforce_object_description', array( $this, 'get_salesforce_object_description' ) ); |
|
133 | - add_action( 'wp_ajax_get_wordpress_object_description', array( $this, 'get_wordpress_object_fields' ) ); |
|
134 | - add_action( 'wp_ajax_get_wp_sf_object_fields', array( $this, 'get_wp_sf_object_fields' ) ); |
|
135 | - add_action( 'wp_ajax_push_to_salesforce', array( $this, 'push_to_salesforce' ) ); |
|
136 | - add_action( 'wp_ajax_pull_from_salesforce', array( $this, 'pull_from_salesforce' ) ); |
|
137 | - add_action( 'wp_ajax_refresh_mapped_data', array( $this, 'refresh_mapped_data' ) ); |
|
138 | - add_action( 'wp_ajax_clear_sfwp_cache', array( $this, 'clear_sfwp_cache' ) ); |
|
139 | - |
|
140 | - add_action( 'edit_user_profile', array( $this, 'show_salesforce_user_fields' ) ); |
|
141 | - add_action( 'personal_options_update', array( $this, 'save_salesforce_user_fields' ) ); |
|
142 | - add_action( 'edit_user_profile_update', array( $this, 'save_salesforce_user_fields' ) ); |
|
127 | + add_action('admin_init', array($this, 'salesforce_settings_forms')); |
|
128 | + add_action('admin_init', array($this, 'notices')); |
|
129 | + add_action('admin_post_post_fieldmap', array($this, 'prepare_fieldmap_data')); |
|
130 | + |
|
131 | + add_action('admin_post_delete_fieldmap', array($this, 'delete_fieldmap')); |
|
132 | + add_action('wp_ajax_get_salesforce_object_description', array($this, 'get_salesforce_object_description')); |
|
133 | + add_action('wp_ajax_get_wordpress_object_description', array($this, 'get_wordpress_object_fields')); |
|
134 | + add_action('wp_ajax_get_wp_sf_object_fields', array($this, 'get_wp_sf_object_fields')); |
|
135 | + add_action('wp_ajax_push_to_salesforce', array($this, 'push_to_salesforce')); |
|
136 | + add_action('wp_ajax_pull_from_salesforce', array($this, 'pull_from_salesforce')); |
|
137 | + add_action('wp_ajax_refresh_mapped_data', array($this, 'refresh_mapped_data')); |
|
138 | + add_action('wp_ajax_clear_sfwp_cache', array($this, 'clear_sfwp_cache')); |
|
139 | + |
|
140 | + add_action('edit_user_profile', array($this, 'show_salesforce_user_fields')); |
|
141 | + add_action('personal_options_update', array($this, 'save_salesforce_user_fields')); |
|
142 | + add_action('edit_user_profile_update', array($this, 'save_salesforce_user_fields')); |
|
143 | 143 | |
144 | 144 | // when either field for schedule settings changes |
145 | - foreach ( $this->schedulable_classes as $key => $value ) { |
|
146 | - add_filter( 'update_option_' . $this->option_prefix . $key . '_schedule_number', array( $this, 'change_action_schedule' ), 10, 3 ); |
|
147 | - add_filter( 'update_option_' . $this->option_prefix . $key . '_schedule_unit', array( $this, 'change_action_schedule' ), 10, 3 ); |
|
145 | + foreach ($this->schedulable_classes as $key => $value) { |
|
146 | + add_filter('update_option_' . $this->option_prefix . $key . '_schedule_number', array($this, 'change_action_schedule'), 10, 3); |
|
147 | + add_filter('update_option_' . $this->option_prefix . $key . '_schedule_unit', array($this, 'change_action_schedule'), 10, 3); |
|
148 | 148 | } |
149 | 149 | |
150 | - add_action( 'admin_post_delete_object_map', array( $this, 'delete_object_map' ) ); |
|
151 | - add_action( 'admin_post_post_object_map', array( $this, 'prepare_object_map_data' ) ); |
|
150 | + add_action('admin_post_delete_object_map', array($this, 'delete_object_map')); |
|
151 | + add_action('admin_post_post_object_map', array($this, 'prepare_object_map_data')); |
|
152 | 152 | |
153 | 153 | // import and export plugin data |
154 | - add_action( 'admin_post_object_sync_for_salesforce_import', array( $this, 'import_json_file' ) ); |
|
155 | - add_action( 'admin_post_object_sync_for_salesforce_export', array( $this, 'export_json_file' ) ); |
|
154 | + add_action('admin_post_object_sync_for_salesforce_import', array($this, 'import_json_file')); |
|
155 | + add_action('admin_post_object_sync_for_salesforce_export', array($this, 'export_json_file')); |
|
156 | 156 | |
157 | 157 | } |
158 | 158 | |
@@ -160,35 +160,35 @@ discard block |
||
160 | 160 | * Recurring task to check Salesforce for data |
161 | 161 | * |
162 | 162 | */ |
163 | - public function change_action_schedule( $old_schedule, $new_schedule, $option_name ) { |
|
163 | + public function change_action_schedule($old_schedule, $new_schedule, $option_name) { |
|
164 | 164 | |
165 | 165 | // exit if nothing changed |
166 | - if ( $old_schedule === $new_schedule ) { |
|
166 | + if ($old_schedule === $new_schedule) { |
|
167 | 167 | return; |
168 | 168 | } |
169 | 169 | |
170 | 170 | // get the current schedule name from the task, based on pattern in the foreach |
171 | - preg_match( '/' . $this->option_prefix . '(.*)_schedule/', $option_name, $matches ); |
|
171 | + preg_match('/' . $this->option_prefix . '(.*)_schedule/', $option_name, $matches); |
|
172 | 172 | $schedule_name = $matches[1]; |
173 | 173 | $action_group_name = $schedule_name . '_check_records'; |
174 | 174 | |
175 | 175 | // exit if there is no initializer property on this schedule |
176 | - if ( ! isset( $this->schedulable_classes[ $schedule_name ]['initializer'] ) ) { |
|
176 | + if ( ! isset($this->schedulable_classes[$schedule_name]['initializer'])) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // cancel previous task |
181 | 181 | $this->queue->cancel( |
182 | - $this->schedulable_classes[ $schedule_name ]['initializer'], |
|
182 | + $this->schedulable_classes[$schedule_name]['initializer'], |
|
183 | 183 | array(), |
184 | 184 | $action_group_name |
185 | 185 | ); |
186 | 186 | |
187 | 187 | // create new recurring task for action-scheduler to check for data to pull from salesforce |
188 | 188 | $this->queue->schedule_recurring( |
189 | - current_time( 'timestamp', true ), // plugin seems to expect UTC |
|
190 | - $this->queue->get_frequency( $schedule_name, 'seconds' ), |
|
191 | - $this->schedulable_classes[ $schedule_name ]['initializer'], |
|
189 | + current_time('timestamp', true), // plugin seems to expect UTC |
|
190 | + $this->queue->get_frequency($schedule_name, 'seconds'), |
|
191 | + $this->schedulable_classes[$schedule_name]['initializer'], |
|
192 | 192 | array(), |
193 | 193 | $action_group_name |
194 | 194 | ); |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * |
200 | 200 | */ |
201 | 201 | public function create_admin_menu() { |
202 | - $title = __( 'Salesforce', 'object-sync-for-salesforce' ); |
|
203 | - add_options_page( $title, $title, 'configure_salesforce', 'object-sync-salesforce-admin', array( $this, 'show_admin_page' ) ); |
|
202 | + $title = __('Salesforce', 'object-sync-for-salesforce'); |
|
203 | + add_options_page($title, $title, 'configure_salesforce', 'object-sync-salesforce-admin', array($this, 'show_admin_page')); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -211,114 +211,114 @@ discard block |
||
211 | 211 | * |
212 | 212 | */ |
213 | 213 | public function show_admin_page() { |
214 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
214 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
215 | 215 | echo '<div class="wrap">'; |
216 | - echo '<h1>' . esc_html( get_admin_page_title() ) . '</h1>'; |
|
216 | + echo '<h1>' . esc_html(get_admin_page_title()) . '</h1>'; |
|
217 | 217 | $allowed = $this->check_wordpress_admin_permissions(); |
218 | - if ( false === $allowed ) { |
|
218 | + if (false === $allowed) { |
|
219 | 219 | return; |
220 | 220 | } |
221 | 221 | $tabs = array( |
222 | - 'settings' => __( 'Settings', 'object-sync-for-salesforce' ), |
|
223 | - 'authorize' => __( 'Authorize', 'object-sync-for-salesforce' ), |
|
224 | - 'fieldmaps' => __( 'Fieldmaps', 'object-sync-for-salesforce' ), |
|
225 | - 'schedule' => __( 'Scheduling', 'object-sync-for-salesforce' ), |
|
226 | - 'import-export' => __( 'Import & Export', 'object-sync-for-salesforce' ), |
|
222 | + 'settings' => __('Settings', 'object-sync-for-salesforce'), |
|
223 | + 'authorize' => __('Authorize', 'object-sync-for-salesforce'), |
|
224 | + 'fieldmaps' => __('Fieldmaps', 'object-sync-for-salesforce'), |
|
225 | + 'schedule' => __('Scheduling', 'object-sync-for-salesforce'), |
|
226 | + 'import-export' => __('Import & Export', 'object-sync-for-salesforce'), |
|
227 | 227 | ); // this creates the tabs for the admin |
228 | 228 | |
229 | 229 | // optionally make tab(s) for logging and log settings |
230 | - $logging_enabled = get_option( $this->option_prefix . 'enable_logging', false ); |
|
231 | - $tabs['log_settings'] = __( 'Log Settings', 'object-sync-for-salesforce' ); |
|
230 | + $logging_enabled = get_option($this->option_prefix . 'enable_logging', false); |
|
231 | + $tabs['log_settings'] = __('Log Settings', 'object-sync-for-salesforce'); |
|
232 | 232 | |
233 | 233 | $mapping_errors = $this->mappings->get_failed_object_maps(); |
234 | - if ( ! empty( $mapping_errors ) ) { |
|
235 | - $tabs['mapping_errors'] = __( 'Mapping Errors', 'object-sync-for-salesforce' ); |
|
234 | + if ( ! empty($mapping_errors)) { |
|
235 | + $tabs['mapping_errors'] = __('Mapping Errors', 'object-sync-for-salesforce'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | // filter for extending the tabs available on the page |
239 | 239 | // currently it will go into the default switch case for $tab |
240 | - $tabs = apply_filters( 'object_sync_for_salesforce_settings_tabs', $tabs ); |
|
240 | + $tabs = apply_filters('object_sync_for_salesforce_settings_tabs', $tabs); |
|
241 | 241 | |
242 | - $tab = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
243 | - $this->tabs( $tabs, $tab ); |
|
242 | + $tab = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
243 | + $this->tabs($tabs, $tab); |
|
244 | 244 | |
245 | 245 | $consumer_key = $this->login_credentials['consumer_key']; |
246 | 246 | $consumer_secret = $this->login_credentials['consumer_secret']; |
247 | 247 | $callback_url = $this->login_credentials['callback_url']; |
248 | 248 | |
249 | - if ( true !== $this->salesforce['is_authorized'] ) { |
|
250 | - $url = esc_url( $callback_url ); |
|
251 | - $anchor = esc_html__( 'Authorize tab', 'object-sync-for-salesforce' ); |
|
252 | - $message = sprintf( 'Salesforce needs to be authorized to connect to this website. Use the <a href="%s">%s</a> to connect.', $url, $anchor ); |
|
253 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
249 | + if (true !== $this->salesforce['is_authorized']) { |
|
250 | + $url = esc_url($callback_url); |
|
251 | + $anchor = esc_html__('Authorize tab', 'object-sync-for-salesforce'); |
|
252 | + $message = sprintf('Salesforce needs to be authorized to connect to this website. Use the <a href="%s">%s</a> to connect.', $url, $anchor); |
|
253 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
254 | 254 | } |
255 | 255 | |
256 | - if ( 0 === count( $this->mappings->get_fieldmaps() ) ) { |
|
257 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps' ) ); |
|
258 | - $anchor = esc_html__( 'Fieldmaps tab', 'object-sync-for-salesforce' ); |
|
259 | - $message = sprintf( 'No fieldmaps exist yet. Use the <a href="%s">%s</a> to map WordPress and Salesforce objects to each other.', $url, $anchor ); |
|
260 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
256 | + if (0 === count($this->mappings->get_fieldmaps())) { |
|
257 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps')); |
|
258 | + $anchor = esc_html__('Fieldmaps tab', 'object-sync-for-salesforce'); |
|
259 | + $message = sprintf('No fieldmaps exist yet. Use the <a href="%s">%s</a> to map WordPress and Salesforce objects to each other.', $url, $anchor); |
|
260 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
261 | 261 | } |
262 | 262 | |
263 | - $push_schedule_number = get_option( $this->option_prefix . 'salesforce_push_schedule_number', '' ); |
|
264 | - $push_schedule_unit = get_option( $this->option_prefix . 'salesforce_push_schedule_unit', '' ); |
|
265 | - $pull_schedule_number = get_option( $this->option_prefix . 'salesforce_pull_schedule_number', '' ); |
|
266 | - $pull_schedule_unit = get_option( $this->option_prefix . 'salesforce_pull_schedule_unit', '' ); |
|
263 | + $push_schedule_number = get_option($this->option_prefix . 'salesforce_push_schedule_number', ''); |
|
264 | + $push_schedule_unit = get_option($this->option_prefix . 'salesforce_push_schedule_unit', ''); |
|
265 | + $pull_schedule_number = get_option($this->option_prefix . 'salesforce_pull_schedule_number', ''); |
|
266 | + $pull_schedule_unit = get_option($this->option_prefix . 'salesforce_pull_schedule_unit', ''); |
|
267 | 267 | |
268 | - if ( '' === $push_schedule_number && '' === $push_schedule_unit && '' === $pull_schedule_number && '' === $pull_schedule_unit ) { |
|
269 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=schedule' ) ); |
|
270 | - $anchor = esc_html__( 'Scheduling tab', 'object-sync-for-salesforce' ); |
|
271 | - $message = sprintf( 'Because the plugin schedule has not been saved, the plugin cannot run automatic operations. Use the <a href="%s">%s</a> to create schedules to run.', $url, $anchor ); |
|
272 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
268 | + if ('' === $push_schedule_number && '' === $push_schedule_unit && '' === $pull_schedule_number && '' === $pull_schedule_unit) { |
|
269 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=schedule')); |
|
270 | + $anchor = esc_html__('Scheduling tab', 'object-sync-for-salesforce'); |
|
271 | + $message = sprintf('Because the plugin schedule has not been saved, the plugin cannot run automatic operations. Use the <a href="%s">%s</a> to create schedules to run.', $url, $anchor); |
|
272 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | try { |
276 | - switch ( $tab ) { |
|
276 | + switch ($tab) { |
|
277 | 277 | case 'authorize': |
278 | - if ( isset( $get_data['code'] ) ) { |
|
278 | + if (isset($get_data['code'])) { |
|
279 | 279 | // this string is an oauth token |
280 | - $data = esc_html( wp_unslash( $get_data['code'] ) ); |
|
281 | - $is_authorized = $this->salesforce['sfapi']->request_token( $data ); |
|
280 | + $data = esc_html(wp_unslash($get_data['code'])); |
|
281 | + $is_authorized = $this->salesforce['sfapi']->request_token($data); |
|
282 | 282 | ?> |
283 | - <script>window.location = '<?php echo esc_url_raw( $callback_url ); ?>'</script> |
|
283 | + <script>window.location = '<?php echo esc_url_raw($callback_url); ?>'</script> |
|
284 | 284 | <?php |
285 | - } elseif ( true === $this->salesforce['is_authorized'] ) { |
|
286 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/authorized.php' ); |
|
287 | - $this->status( $this->salesforce['sfapi'] ); |
|
288 | - } elseif ( true === is_object( $this->salesforce['sfapi'] ) && isset( $consumer_key ) && isset( $consumer_secret ) ) { |
|
285 | + } elseif (true === $this->salesforce['is_authorized']) { |
|
286 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/authorized.php'); |
|
287 | + $this->status($this->salesforce['sfapi']); |
|
288 | + } elseif (true === is_object($this->salesforce['sfapi']) && isset($consumer_key) && isset($consumer_secret)) { |
|
289 | 289 | ?> |
290 | - <p><a class="button button-primary" href="<?php echo esc_url( $this->salesforce['sfapi']->get_authorization_code() ); ?>"><?php echo esc_html__( 'Connect to Salesforce', 'object-sync-for-salesforce' ); ?></a></p> |
|
290 | + <p><a class="button button-primary" href="<?php echo esc_url($this->salesforce['sfapi']->get_authorization_code()); ?>"><?php echo esc_html__('Connect to Salesforce', 'object-sync-for-salesforce'); ?></a></p> |
|
291 | 291 | <?php |
292 | 292 | } else { |
293 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=settings' ) ); |
|
294 | - $anchor = esc_html__( 'Settings', 'object-sync-for-salesforce' ); |
|
293 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=settings')); |
|
294 | + $anchor = esc_html__('Settings', 'object-sync-for-salesforce'); |
|
295 | 295 | // translators: placeholders are for the settings tab link: 1) the url, and 2) the anchor text |
296 | - $message = sprintf( esc_html__( 'Salesforce needs to be authorized to connect to this website but the credentials are missing. Use the <a href="%1$s">%2$s</a> tab to add them.', 'object-sync-salesforce' ), $url, $anchor ); |
|
297 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
296 | + $message = sprintf(esc_html__('Salesforce needs to be authorized to connect to this website but the credentials are missing. Use the <a href="%1$s">%2$s</a> tab to add them.', 'object-sync-salesforce'), $url, $anchor); |
|
297 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
298 | 298 | } |
299 | 299 | break; |
300 | 300 | case 'fieldmaps': |
301 | - if ( isset( $get_data['method'] ) ) { |
|
301 | + if (isset($get_data['method'])) { |
|
302 | 302 | |
303 | - $method = sanitize_key( $get_data['method'] ); |
|
304 | - $error_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps&method=' . $method ); |
|
305 | - $success_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps' ); |
|
303 | + $method = sanitize_key($get_data['method']); |
|
304 | + $error_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps&method=' . $method); |
|
305 | + $success_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps'); |
|
306 | 306 | |
307 | - if ( isset( $get_data['transient'] ) ) { |
|
308 | - $transient = sanitize_key( $get_data['transient'] ); |
|
309 | - $posted = $this->sfwp_transients->get( $transient ); |
|
307 | + if (isset($get_data['transient'])) { |
|
308 | + $transient = sanitize_key($get_data['transient']); |
|
309 | + $posted = $this->sfwp_transients->get($transient); |
|
310 | 310 | } |
311 | 311 | |
312 | - if ( isset( $posted ) && is_array( $posted ) ) { |
|
312 | + if (isset($posted) && is_array($posted)) { |
|
313 | 313 | $map = $posted; |
314 | - } elseif ( 'edit' === $method || 'clone' === $method || 'delete' === $method ) { |
|
315 | - $map = $this->mappings->get_fieldmaps( isset( $get_data['id'] ) ? sanitize_key( $get_data['id'] ) : '' ); |
|
314 | + } elseif ('edit' === $method || 'clone' === $method || 'delete' === $method) { |
|
315 | + $map = $this->mappings->get_fieldmaps(isset($get_data['id']) ? sanitize_key($get_data['id']) : ''); |
|
316 | 316 | } |
317 | 317 | |
318 | - if ( isset( $map ) && is_array( $map ) ) { |
|
318 | + if (isset($map) && is_array($map)) { |
|
319 | 319 | $label = $map['label']; |
320 | 320 | $salesforce_object = $map['salesforce_object']; |
321 | - $salesforce_record_types_allowed = maybe_unserialize( $map['salesforce_record_types_allowed'] ); |
|
321 | + $salesforce_record_types_allowed = maybe_unserialize($map['salesforce_record_types_allowed']); |
|
322 | 322 | $salesforce_record_type_default = $map['salesforce_record_type_default']; |
323 | 323 | $wordpress_object = $map['wordpress_object']; |
324 | 324 | $pull_trigger_field = $map['pull_trigger_field']; |
@@ -329,14 +329,14 @@ discard block |
||
329 | 329 | $weight = $map['weight']; |
330 | 330 | } |
331 | 331 | |
332 | - if ( 'add' === $method || 'edit' === $method || 'clone' === $method ) { |
|
333 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-add-edit-clone.php' ); |
|
334 | - } elseif ( 'delete' === $method ) { |
|
335 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-delete.php' ); |
|
332 | + if ('add' === $method || 'edit' === $method || 'clone' === $method) { |
|
333 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-add-edit-clone.php'); |
|
334 | + } elseif ('delete' === $method) { |
|
335 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-delete.php'); |
|
336 | 336 | } |
337 | 337 | } else { |
338 | 338 | $fieldmaps = $this->mappings->get_fieldmaps(); |
339 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-list.php' ); |
|
339 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-list.php'); |
|
340 | 340 | } // End if(). |
341 | 341 | break; |
342 | 342 | case 'logout': |
@@ -346,73 +346,73 @@ discard block |
||
346 | 346 | $this->clear_cache(); |
347 | 347 | break; |
348 | 348 | case 'clear_schedule': |
349 | - if ( isset( $get_data['schedule_name'] ) ) { |
|
350 | - $schedule_name = sanitize_key( $get_data['schedule_name'] ); |
|
349 | + if (isset($get_data['schedule_name'])) { |
|
350 | + $schedule_name = sanitize_key($get_data['schedule_name']); |
|
351 | 351 | } |
352 | - $this->clear_schedule( $schedule_name ); |
|
352 | + $this->clear_schedule($schedule_name); |
|
353 | 353 | break; |
354 | 354 | case 'settings': |
355 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/settings.php' ); |
|
355 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/settings.php'); |
|
356 | 356 | break; |
357 | 357 | case 'mapping_errors': |
358 | - if ( isset( $get_data['method'] ) ) { |
|
358 | + if (isset($get_data['method'])) { |
|
359 | 359 | |
360 | - $method = sanitize_key( $get_data['method'] ); |
|
361 | - $error_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors&method=' . $method ); |
|
362 | - $success_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors' ); |
|
360 | + $method = sanitize_key($get_data['method']); |
|
361 | + $error_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors&method=' . $method); |
|
362 | + $success_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors'); |
|
363 | 363 | |
364 | - if ( isset( $get_data['map_transient'] ) ) { |
|
365 | - $transient = sanitize_key( $get_data['map_transient'] ); |
|
366 | - $posted = $this->sfwp_transients->get( $transient ); |
|
364 | + if (isset($get_data['map_transient'])) { |
|
365 | + $transient = sanitize_key($get_data['map_transient']); |
|
366 | + $posted = $this->sfwp_transients->get($transient); |
|
367 | 367 | } |
368 | 368 | |
369 | - if ( isset( $posted ) && is_array( $posted ) ) { |
|
369 | + if (isset($posted) && is_array($posted)) { |
|
370 | 370 | $map_row = $posted; |
371 | - } elseif ( 'edit' === $method || 'delete' === $method ) { |
|
372 | - $map_row = $this->mappings->get_failed_object_map( isset( $get_data['id'] ) ? sanitize_key( $get_data['id'] ) : '' ); |
|
371 | + } elseif ('edit' === $method || 'delete' === $method) { |
|
372 | + $map_row = $this->mappings->get_failed_object_map(isset($get_data['id']) ? sanitize_key($get_data['id']) : ''); |
|
373 | 373 | } |
374 | 374 | |
375 | - if ( isset( $map_row ) && is_array( $map_row ) ) { |
|
375 | + if (isset($map_row) && is_array($map_row)) { |
|
376 | 376 | $salesforce_id = $map_row['salesforce_id']; |
377 | 377 | $wordpress_id = $map_row['wordpress_id']; |
378 | 378 | } |
379 | 379 | |
380 | - if ( 'edit' === $method ) { |
|
381 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors-edit.php' ); |
|
382 | - } elseif ( 'delete' === $method ) { |
|
383 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors-delete.php' ); |
|
380 | + if ('edit' === $method) { |
|
381 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors-edit.php'); |
|
382 | + } elseif ('delete' === $method) { |
|
383 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors-delete.php'); |
|
384 | 384 | } |
385 | 385 | } else { |
386 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors.php' ); |
|
386 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors.php'); |
|
387 | 387 | } |
388 | 388 | break; |
389 | 389 | case 'import-export': |
390 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/import-export.php' ); |
|
390 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/import-export.php'); |
|
391 | 391 | break; |
392 | 392 | default: |
393 | - $include_settings = apply_filters( 'object_sync_for_salesforce_settings_tab_include_settings', true, $tab ); |
|
394 | - $content_before = apply_filters( 'object_sync_for_salesforce_settings_tab_content_before', null, $tab ); |
|
395 | - $content_after = apply_filters( 'object_sync_for_salesforce_settings_tab_content_after', null, $tab ); |
|
396 | - if ( null !== $content_before ) { |
|
397 | - echo esc_html( $content_before ); |
|
393 | + $include_settings = apply_filters('object_sync_for_salesforce_settings_tab_include_settings', true, $tab); |
|
394 | + $content_before = apply_filters('object_sync_for_salesforce_settings_tab_content_before', null, $tab); |
|
395 | + $content_after = apply_filters('object_sync_for_salesforce_settings_tab_content_after', null, $tab); |
|
396 | + if (null !== $content_before) { |
|
397 | + echo esc_html($content_before); |
|
398 | 398 | } |
399 | - if ( true === $include_settings ) { |
|
400 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/settings.php' ); |
|
399 | + if (true === $include_settings) { |
|
400 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/settings.php'); |
|
401 | 401 | } |
402 | - if ( null !== $content_after ) { |
|
403 | - echo esc_html( $content_after ); |
|
402 | + if (null !== $content_after) { |
|
403 | + echo esc_html($content_after); |
|
404 | 404 | } |
405 | 405 | break; |
406 | 406 | } // End switch(). |
407 | - } catch ( SalesforceApiException $ex ) { |
|
408 | - echo sprintf( '<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
409 | - absint( $ex->getCode() ), |
|
410 | - esc_html( $ex->getMessage() ) |
|
407 | + } catch (SalesforceApiException $ex) { |
|
408 | + echo sprintf('<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
409 | + absint($ex->getCode()), |
|
410 | + esc_html($ex->getMessage()) |
|
411 | 411 | ); |
412 | - } catch ( Exception $ex ) { |
|
413 | - echo sprintf( '<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
414 | - absint( $ex->getCode() ), |
|
415 | - esc_html( $ex->getMessage() ) |
|
412 | + } catch (Exception $ex) { |
|
413 | + echo sprintf('<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
414 | + absint($ex->getCode()), |
|
415 | + esc_html($ex->getMessage()) |
|
416 | 416 | ); |
417 | 417 | } // End try(). |
418 | 418 | echo '</div>'; |
@@ -424,14 +424,14 @@ discard block |
||
424 | 424 | * |
425 | 425 | */ |
426 | 426 | public function salesforce_settings_forms() { |
427 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
428 | - $page = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
429 | - $section = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
427 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
428 | + $page = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
429 | + $section = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
430 | 430 | |
431 | - $input_callback_default = array( $this, 'display_input_field' ); |
|
432 | - $input_checkboxes_default = array( $this, 'display_checkboxes' ); |
|
433 | - $input_select_default = array( $this, 'display_select' ); |
|
434 | - $link_default = array( $this, 'display_link' ); |
|
431 | + $input_callback_default = array($this, 'display_input_field'); |
|
432 | + $input_checkboxes_default = array($this, 'display_checkboxes'); |
|
433 | + $input_select_default = array($this, 'display_select'); |
|
434 | + $link_default = array($this, 'display_link'); |
|
435 | 435 | |
436 | 436 | $all_field_callbacks = array( |
437 | 437 | 'text' => $input_callback_default, |
@@ -440,10 +440,10 @@ discard block |
||
440 | 440 | 'link' => $link_default, |
441 | 441 | ); |
442 | 442 | |
443 | - $this->fields_settings( 'settings', 'settings', $all_field_callbacks ); |
|
444 | - $this->fields_fieldmaps( 'fieldmaps', 'objects' ); |
|
445 | - $this->fields_scheduling( 'schedule', 'schedule', $all_field_callbacks ); |
|
446 | - $this->fields_log_settings( 'log_settings', 'log_settings', $all_field_callbacks ); |
|
443 | + $this->fields_settings('settings', 'settings', $all_field_callbacks); |
|
444 | + $this->fields_fieldmaps('fieldmaps', 'objects'); |
|
445 | + $this->fields_scheduling('schedule', 'schedule', $all_field_callbacks); |
|
446 | + $this->fields_log_settings('log_settings', 'log_settings', $all_field_callbacks); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -454,11 +454,11 @@ discard block |
||
454 | 454 | * @param string $section |
455 | 455 | * @param string $input_callback |
456 | 456 | */ |
457 | - private function fields_settings( $page, $section, $callbacks ) { |
|
458 | - add_settings_section( $page, ucwords( $page ), null, $page ); |
|
457 | + private function fields_settings($page, $section, $callbacks) { |
|
458 | + add_settings_section($page, ucwords($page), null, $page); |
|
459 | 459 | $salesforce_settings = array( |
460 | 460 | 'consumer_key' => array( |
461 | - 'title' => __( 'Consumer Key', 'object-sync-for-salesforce' ), |
|
461 | + 'title' => __('Consumer Key', 'object-sync-for-salesforce'), |
|
462 | 462 | 'callback' => $callbacks['text'], |
463 | 463 | 'page' => $page, |
464 | 464 | 'section' => $section, |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | |
472 | 472 | ), |
473 | 473 | 'consumer_secret' => array( |
474 | - 'title' => __( 'Consumer Secret', 'object-sync-for-salesforce' ), |
|
474 | + 'title' => __('Consumer Secret', 'object-sync-for-salesforce'), |
|
475 | 475 | 'callback' => $callbacks['text'], |
476 | 476 | 'page' => $page, |
477 | 477 | 'section' => $section, |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | ), |
484 | 484 | ), |
485 | 485 | 'callback_url' => array( |
486 | - 'title' => __( 'Callback URL', 'object-sync-for-salesforce' ), |
|
486 | + 'title' => __('Callback URL', 'object-sync-for-salesforce'), |
|
487 | 487 | 'callback' => $callbacks['text'], |
488 | 488 | 'page' => $page, |
489 | 489 | 'section' => $section, |
@@ -491,14 +491,14 @@ discard block |
||
491 | 491 | 'type' => 'url', |
492 | 492 | 'validate' => 'sanitize_validate_text', |
493 | 493 | // translators: %1$s is the admin URL for the Authorize tab |
494 | - 'desc' => sprintf( __( 'In most cases, you will want to use %1$s for this value.', 'object-sync-for-salesforce' ), |
|
495 | - get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize' ) |
|
494 | + 'desc' => sprintf(__('In most cases, you will want to use %1$s for this value.', 'object-sync-for-salesforce'), |
|
495 | + get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize') |
|
496 | 496 | ), |
497 | 497 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL', |
498 | 498 | ), |
499 | 499 | ), |
500 | 500 | 'login_base_url' => array( |
501 | - 'title' => __( 'Login Base URL', 'object-sync-for-salesforce' ), |
|
501 | + 'title' => __('Login Base URL', 'object-sync-for-salesforce'), |
|
502 | 502 | 'callback' => $callbacks['text'], |
503 | 503 | 'page' => $page, |
504 | 504 | 'section' => $section, |
@@ -506,22 +506,22 @@ discard block |
||
506 | 506 | 'type' => 'url', |
507 | 507 | 'validate' => 'sanitize_validate_text', |
508 | 508 | // translators: 1) production salesforce login, 2) sandbox salesforce login |
509 | - 'desc' => sprintf( __( 'For most Salesforce setups, you should use %1$s for production and %2$s for sandbox.', 'object-sync-for-salesforce' ), |
|
510 | - esc_url( 'https://login.salesforce.com' ), |
|
511 | - esc_url( 'https://test.salesforce.com' ) |
|
509 | + 'desc' => sprintf(__('For most Salesforce setups, you should use %1$s for production and %2$s for sandbox.', 'object-sync-for-salesforce'), |
|
510 | + esc_url('https://login.salesforce.com'), |
|
511 | + esc_url('https://test.salesforce.com') |
|
512 | 512 | ), |
513 | 513 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL', |
514 | 514 | ), |
515 | 515 | ), |
516 | 516 | 'authorize_url_path' => array( |
517 | - 'title' => __( 'Authorize URL Path', 'object-sync-for-salesforce' ), |
|
517 | + 'title' => __('Authorize URL Path', 'object-sync-for-salesforce'), |
|
518 | 518 | 'callback' => $callbacks['text'], |
519 | 519 | 'page' => $page, |
520 | 520 | 'section' => $section, |
521 | 521 | 'args' => array( |
522 | 522 | 'type' => 'text', |
523 | 523 | 'validate' => 'sanitize_validate_text', |
524 | - 'desc' => __( 'For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce' ), |
|
524 | + 'desc' => __('For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce'), |
|
525 | 525 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH', |
526 | 526 | 'default' => $this->default_authorize_url_path, |
527 | 527 | ), |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | 'args' => array( |
535 | 535 | 'type' => 'text', |
536 | 536 | 'validate' => 'sanitize_validate_text', |
537 | - 'desc' => __( 'For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce' ), |
|
537 | + 'desc' => __('For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce'), |
|
538 | 538 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH', |
539 | 539 | 'default' => $this->default_token_url_path, |
540 | 540 | ), |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | 'args' => array( |
561 | 561 | 'type' => 'checkboxes', |
562 | 562 | 'validate' => 'sanitize_validate_text', |
563 | - 'desc' => __( 'Allows you to limit which Salesforce objects can be mapped', 'object-sync-for-salesforce' ), |
|
563 | + 'desc' => __('Allows you to limit which Salesforce objects can be mapped', 'object-sync-for-salesforce'), |
|
564 | 564 | 'items' => array( |
565 | 565 | 'triggerable' => array( |
566 | 566 | 'text' => 'Only Triggerable objects', |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | 'constant' => '', |
590 | 590 | 'items' => array( |
591 | 591 | 'field_label' => array( |
592 | - 'text' => __( 'Field Label', 'object-sync-for-salesforce' ), |
|
592 | + 'text' => __('Field Label', 'object-sync-for-salesforce'), |
|
593 | 593 | 'value' => 'field_label', |
594 | 594 | ), |
595 | 595 | /*'field_name' => array( |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | 'value' => 'field_name', |
598 | 598 | ),*/ |
599 | 599 | 'api_name' => array( |
600 | - 'text' => __( 'API Name', 'object-sync-for-salesforce' ), |
|
600 | + 'text' => __('API Name', 'object-sync-for-salesforce'), |
|
601 | 601 | 'value' => 'api_name', |
602 | 602 | ), |
603 | 603 | ), |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | 'args' => array( |
612 | 612 | 'type' => 'number', |
613 | 613 | 'validate' => 'sanitize_validate_text', |
614 | - 'desc' => __( 'Number of seconds to wait between repeated salesforce pulls. Prevents the webserver from becoming overloaded in case of too many cron runs, or webhook usage.', 'object-sync-for-salesforce' ), |
|
614 | + 'desc' => __('Number of seconds to wait between repeated salesforce pulls. Prevents the webserver from becoming overloaded in case of too many cron runs, or webhook usage.', 'object-sync-for-salesforce'), |
|
615 | 615 | 'constant' => '', |
616 | 616 | 'default' => $this->default_pull_throttle, |
617 | 617 | ), |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | 'args' => array( |
625 | 625 | 'type' => 'checkbox', |
626 | 626 | 'validate' => 'sanitize_validate_text', |
627 | - 'desc' => __( 'Debug mode can, combined with the Log Settings, log things like Salesforce API requests. It can create a lot of entries if enabled; it is not recommended to use it in a production environment.', 'object-sync-for-salesforce' ), |
|
627 | + 'desc' => __('Debug mode can, combined with the Log Settings, log things like Salesforce API requests. It can create a lot of entries if enabled; it is not recommended to use it in a production environment.', 'object-sync-for-salesforce'), |
|
628 | 628 | 'constant' => '', |
629 | 629 | ), |
630 | 630 | ), |
@@ -636,13 +636,13 @@ discard block |
||
636 | 636 | 'args' => array( |
637 | 637 | 'type' => 'checkbox', |
638 | 638 | 'validate' => 'sanitize_validate_text', |
639 | - 'desc' => __( 'If checked, the plugin will delete the tables and other data it creates when you uninstall it. Unchecking this field can be useful if you need to reactivate the plugin for any reason without losing data.', 'object-sync-for-salesforce' ), |
|
639 | + 'desc' => __('If checked, the plugin will delete the tables and other data it creates when you uninstall it. Unchecking this field can be useful if you need to reactivate the plugin for any reason without losing data.', 'object-sync-for-salesforce'), |
|
640 | 640 | 'constant' => '', |
641 | 641 | ), |
642 | 642 | ), |
643 | 643 | ); |
644 | 644 | |
645 | - if ( true === is_object( $this->salesforce['sfapi'] ) && true === $this->salesforce['sfapi']->is_authorized() ) { |
|
645 | + if (true === is_object($this->salesforce['sfapi']) && true === $this->salesforce['sfapi']->is_authorized()) { |
|
646 | 646 | $salesforce_settings['api_version'] = array( |
647 | 647 | 'title' => 'Salesforce API Version', |
648 | 648 | 'callback' => $callbacks['select'], |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | ); |
659 | 659 | } |
660 | 660 | |
661 | - foreach ( $salesforce_settings as $key => $attributes ) { |
|
661 | + foreach ($salesforce_settings as $key => $attributes) { |
|
662 | 662 | $id = $this->option_prefix . $key; |
663 | 663 | $name = $this->option_prefix . $key; |
664 | 664 | $title = $attributes['title']; |
@@ -677,12 +677,12 @@ discard block |
||
677 | 677 | ); |
678 | 678 | |
679 | 679 | // if there is a constant and it is defined, don't run a validate function |
680 | - if ( isset( $attributes['args']['constant'] ) && defined( $attributes['args']['constant'] ) ) { |
|
680 | + if (isset($attributes['args']['constant']) && defined($attributes['args']['constant'])) { |
|
681 | 681 | $validate = ''; |
682 | 682 | } |
683 | 683 | |
684 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
685 | - register_setting( $page, $id, array( $this, $validate ) ); |
|
684 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
685 | + register_setting($page, $id, array($this, $validate)); |
|
686 | 686 | } |
687 | 687 | } |
688 | 688 | |
@@ -694,8 +694,8 @@ discard block |
||
694 | 694 | * @param string $section |
695 | 695 | * @param string $input_callback |
696 | 696 | */ |
697 | - private function fields_fieldmaps( $page, $section, $input_callback = '' ) { |
|
698 | - add_settings_section( $page, ucwords( $page ), null, $page ); |
|
697 | + private function fields_fieldmaps($page, $section, $input_callback = '') { |
|
698 | + add_settings_section($page, ucwords($page), null, $page); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | /** |
@@ -706,12 +706,12 @@ discard block |
||
706 | 706 | * @param string $section |
707 | 707 | * @param string $input_callback |
708 | 708 | */ |
709 | - private function fields_scheduling( $page, $section, $callbacks ) { |
|
710 | - foreach ( $this->schedulable_classes as $key => $value ) { |
|
711 | - add_settings_section( $key, $value['label'], null, $page ); |
|
709 | + private function fields_scheduling($page, $section, $callbacks) { |
|
710 | + foreach ($this->schedulable_classes as $key => $value) { |
|
711 | + add_settings_section($key, $value['label'], null, $page); |
|
712 | 712 | $schedule_settings = array( |
713 | 713 | $key . '_schedule_number' => array( |
714 | - 'title' => __( 'Run schedule every', 'object-sync-for-salesforce' ), |
|
714 | + 'title' => __('Run schedule every', 'object-sync-for-salesforce'), |
|
715 | 715 | 'callback' => $callbacks['text'], |
716 | 716 | 'page' => $page, |
717 | 717 | 'section' => $key, |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | ), |
724 | 724 | ), |
725 | 725 | $key . '_schedule_unit' => array( |
726 | - 'title' => __( 'Time unit', 'object-sync-for-salesforce' ), |
|
726 | + 'title' => __('Time unit', 'object-sync-for-salesforce'), |
|
727 | 727 | 'callback' => $callbacks['select'], |
728 | 728 | 'page' => $page, |
729 | 729 | 'section' => $key, |
@@ -733,15 +733,15 @@ discard block |
||
733 | 733 | 'desc' => '', |
734 | 734 | 'items' => array( |
735 | 735 | 'minutes' => array( |
736 | - 'text' => __( 'Minutes', 'object-sync-for-salesforce' ), |
|
736 | + 'text' => __('Minutes', 'object-sync-for-salesforce'), |
|
737 | 737 | 'value' => 'minutes', |
738 | 738 | ), |
739 | 739 | 'hours' => array( |
740 | - 'text' => __( 'Hours', 'object-sync-for-salesforce' ), |
|
740 | + 'text' => __('Hours', 'object-sync-for-salesforce'), |
|
741 | 741 | 'value' => 'hours', |
742 | 742 | ), |
743 | 743 | 'days' => array( |
744 | - 'text' => __( 'Days', 'object-sync-for-salesforce' ), |
|
744 | + 'text' => __('Days', 'object-sync-for-salesforce'), |
|
745 | 745 | 'value' => 'days', |
746 | 746 | ), |
747 | 747 | ), |
@@ -749,19 +749,19 @@ discard block |
||
749 | 749 | ), |
750 | 750 | $key . '_clear_button' => array( |
751 | 751 | // translators: $this->get_schedule_count is an integer showing how many items are in the current queue |
752 | - 'title' => sprintf( 'This queue has ' . _n( '%s item', '%s items', $this->get_schedule_count( $key ), 'object-sync-for-salesforce' ), $this->get_schedule_count( $key ) ), |
|
752 | + 'title' => sprintf('This queue has ' . _n('%s item', '%s items', $this->get_schedule_count($key), 'object-sync-for-salesforce'), $this->get_schedule_count($key)), |
|
753 | 753 | 'callback' => $callbacks['link'], |
754 | 754 | 'page' => $page, |
755 | 755 | 'section' => $key, |
756 | 756 | 'args' => array( |
757 | - 'label' => __( 'Clear this queue', 'object-sync-for-salesforce' ), |
|
757 | + 'label' => __('Clear this queue', 'object-sync-for-salesforce'), |
|
758 | 758 | 'desc' => '', |
759 | - 'url' => esc_url( '?page=object-sync-salesforce-admin&tab=clear_schedule&schedule_name=' . $key ), |
|
759 | + 'url' => esc_url('?page=object-sync-salesforce-admin&tab=clear_schedule&schedule_name=' . $key), |
|
760 | 760 | 'link_class' => 'button button-secondary', |
761 | 761 | ), |
762 | 762 | ), |
763 | 763 | ); |
764 | - foreach ( $schedule_settings as $key => $attributes ) { |
|
764 | + foreach ($schedule_settings as $key => $attributes) { |
|
765 | 765 | $id = $this->option_prefix . $key; |
766 | 766 | $name = $this->option_prefix . $key; |
767 | 767 | $title = $attributes['title']; |
@@ -777,8 +777,8 @@ discard block |
||
777 | 777 | 'name' => $name, |
778 | 778 | ) |
779 | 779 | ); |
780 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
781 | - register_setting( $page, $id ); |
|
780 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
781 | + register_setting($page, $id); |
|
782 | 782 | } |
783 | 783 | } // End foreach(). |
784 | 784 | } |
@@ -791,11 +791,11 @@ discard block |
||
791 | 791 | * @param string $section |
792 | 792 | * @param array $callbacks |
793 | 793 | */ |
794 | - private function fields_log_settings( $page, $section, $callbacks ) { |
|
795 | - add_settings_section( $page, ucwords( str_replace( '_', ' ', $page ) ), null, $page ); |
|
794 | + private function fields_log_settings($page, $section, $callbacks) { |
|
795 | + add_settings_section($page, ucwords(str_replace('_', ' ', $page)), null, $page); |
|
796 | 796 | $log_settings = array( |
797 | 797 | 'enable_logging' => array( |
798 | - 'title' => __( 'Enable Logging?', 'object-sync-for-salesforce' ), |
|
798 | + 'title' => __('Enable Logging?', 'object-sync-for-salesforce'), |
|
799 | 799 | 'callback' => $callbacks['text'], |
800 | 800 | 'page' => $page, |
801 | 801 | 'section' => $section, |
@@ -807,32 +807,32 @@ discard block |
||
807 | 807 | ), |
808 | 808 | ), |
809 | 809 | 'statuses_to_log' => array( |
810 | - 'title' => __( 'Statuses to log', 'object-sync-for-salesforce' ), |
|
810 | + 'title' => __('Statuses to log', 'object-sync-for-salesforce'), |
|
811 | 811 | 'callback' => $callbacks['checkboxes'], |
812 | 812 | 'page' => $page, |
813 | 813 | 'section' => $section, |
814 | 814 | 'args' => array( |
815 | 815 | 'type' => 'checkboxes', |
816 | 816 | 'validate' => 'sanitize_validate_text', |
817 | - 'desc' => __( 'these are the statuses to log', 'object-sync-for-salesforce' ), |
|
817 | + 'desc' => __('these are the statuses to log', 'object-sync-for-salesforce'), |
|
818 | 818 | 'items' => array( |
819 | 819 | 'error' => array( |
820 | - 'text' => __( 'Error', 'object-sync-for-salesforce' ), |
|
820 | + 'text' => __('Error', 'object-sync-for-salesforce'), |
|
821 | 821 | 'id' => 'error', |
822 | 822 | 'desc' => '', |
823 | 823 | ), |
824 | 824 | 'success' => array( |
825 | - 'text' => __( 'Success', 'object-sync-for-salesforce' ), |
|
825 | + 'text' => __('Success', 'object-sync-for-salesforce'), |
|
826 | 826 | 'id' => 'success', |
827 | 827 | 'desc' => '', |
828 | 828 | ), |
829 | 829 | 'notice' => array( |
830 | - 'text' => __( 'Notice', 'object-sync-for-salesforce' ), |
|
830 | + 'text' => __('Notice', 'object-sync-for-salesforce'), |
|
831 | 831 | 'id' => 'notice', |
832 | 832 | 'desc' => '', |
833 | 833 | ), |
834 | 834 | 'debug' => array( |
835 | - 'text' => __( 'Debug', 'object-sync-for-salesforce' ), |
|
835 | + 'text' => __('Debug', 'object-sync-for-salesforce'), |
|
836 | 836 | 'id' => 'debug', |
837 | 837 | 'desc' => '', |
838 | 838 | ), |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | ), |
841 | 841 | ), |
842 | 842 | 'prune_logs' => array( |
843 | - 'title' => __( 'Automatically delete old log entries?', 'object-sync-for-salesforce' ), |
|
843 | + 'title' => __('Automatically delete old log entries?', 'object-sync-for-salesforce'), |
|
844 | 844 | 'callback' => $callbacks['text'], |
845 | 845 | 'page' => $page, |
846 | 846 | 'section' => $section, |
@@ -852,20 +852,20 @@ discard block |
||
852 | 852 | ), |
853 | 853 | ), |
854 | 854 | 'logs_how_old' => array( |
855 | - 'title' => __( 'Age to delete log entries', 'object-sync-for-salesforce' ), |
|
855 | + 'title' => __('Age to delete log entries', 'object-sync-for-salesforce'), |
|
856 | 856 | 'callback' => $callbacks['text'], |
857 | 857 | 'page' => $page, |
858 | 858 | 'section' => $section, |
859 | 859 | 'args' => array( |
860 | 860 | 'type' => 'text', |
861 | 861 | 'validate' => 'sanitize_validate_text', |
862 | - 'desc' => __( 'If automatic deleting is enabled, it will affect logs this old.', 'object-sync-for-salesforce' ), |
|
862 | + 'desc' => __('If automatic deleting is enabled, it will affect logs this old.', 'object-sync-for-salesforce'), |
|
863 | 863 | 'default' => '2 weeks', |
864 | 864 | 'constant' => '', |
865 | 865 | ), |
866 | 866 | ), |
867 | 867 | 'logs_how_often_number' => array( |
868 | - 'title' => __( 'Check for old logs every', 'object-sync-for-salesforce' ), |
|
868 | + 'title' => __('Check for old logs every', 'object-sync-for-salesforce'), |
|
869 | 869 | 'callback' => $callbacks['text'], |
870 | 870 | 'page' => $page, |
871 | 871 | 'section' => $section, |
@@ -878,67 +878,67 @@ discard block |
||
878 | 878 | ), |
879 | 879 | ), |
880 | 880 | 'logs_how_often_unit' => array( |
881 | - 'title' => __( 'Time unit', 'object-sync-for-salesforce' ), |
|
881 | + 'title' => __('Time unit', 'object-sync-for-salesforce'), |
|
882 | 882 | 'callback' => $callbacks['select'], |
883 | 883 | 'page' => $page, |
884 | 884 | 'section' => $section, |
885 | 885 | 'args' => array( |
886 | 886 | 'type' => 'select', |
887 | 887 | 'validate' => 'sanitize_validate_text', |
888 | - 'desc' => __( 'These two fields are how often the site will check for logs to delete.', 'object-sync-for-salesforce' ), |
|
888 | + 'desc' => __('These two fields are how often the site will check for logs to delete.', 'object-sync-for-salesforce'), |
|
889 | 889 | 'items' => array( |
890 | 890 | 'minutes' => array( |
891 | - 'text' => __( 'Minutes', 'object-sync-for-salesforce' ), |
|
891 | + 'text' => __('Minutes', 'object-sync-for-salesforce'), |
|
892 | 892 | 'value' => 'minutes', |
893 | 893 | ), |
894 | 894 | 'hours' => array( |
895 | - 'text' => __( 'Hours', 'object-sync-for-salesforce' ), |
|
895 | + 'text' => __('Hours', 'object-sync-for-salesforce'), |
|
896 | 896 | 'value' => 'hours', |
897 | 897 | ), |
898 | 898 | 'days' => array( |
899 | - 'text' => __( 'Days', 'object-sync-for-salesforce' ), |
|
899 | + 'text' => __('Days', 'object-sync-for-salesforce'), |
|
900 | 900 | 'value' => 'days', |
901 | 901 | ), |
902 | 902 | ), |
903 | 903 | ), |
904 | 904 | ), |
905 | 905 | 'triggers_to_log' => array( |
906 | - 'title' => __( 'Triggers to log', 'object-sync-for-salesforce' ), |
|
906 | + 'title' => __('Triggers to log', 'object-sync-for-salesforce'), |
|
907 | 907 | 'callback' => $callbacks['checkboxes'], |
908 | 908 | 'page' => $page, |
909 | 909 | 'section' => $section, |
910 | 910 | 'args' => array( |
911 | 911 | 'type' => 'checkboxes', |
912 | 912 | 'validate' => 'sanitize_validate_text', |
913 | - 'desc' => __( 'these are the triggers to log', 'object-sync-for-salesforce' ), |
|
913 | + 'desc' => __('these are the triggers to log', 'object-sync-for-salesforce'), |
|
914 | 914 | 'items' => array( |
915 | 915 | $this->mappings->sync_wordpress_create => array( |
916 | - 'text' => __( 'WordPress create', 'object-sync-for-salesforce' ), |
|
916 | + 'text' => __('WordPress create', 'object-sync-for-salesforce'), |
|
917 | 917 | 'id' => 'wordpress_create', |
918 | 918 | 'desc' => '', |
919 | 919 | ), |
920 | 920 | $this->mappings->sync_wordpress_update => array( |
921 | - 'text' => __( 'WordPress update', 'object-sync-for-salesforce' ), |
|
921 | + 'text' => __('WordPress update', 'object-sync-for-salesforce'), |
|
922 | 922 | 'id' => 'wordpress_update', |
923 | 923 | 'desc' => '', |
924 | 924 | ), |
925 | 925 | $this->mappings->sync_wordpress_delete => array( |
926 | - 'text' => __( 'WordPress delete', 'object-sync-for-salesforce' ), |
|
926 | + 'text' => __('WordPress delete', 'object-sync-for-salesforce'), |
|
927 | 927 | 'id' => 'wordpress_delete', |
928 | 928 | 'desc' => '', |
929 | 929 | ), |
930 | 930 | $this->mappings->sync_sf_create => array( |
931 | - 'text' => __( 'Salesforce create', 'object-sync-for-salesforce' ), |
|
931 | + 'text' => __('Salesforce create', 'object-sync-for-salesforce'), |
|
932 | 932 | 'id' => 'sf_create', |
933 | 933 | 'desc' => '', |
934 | 934 | ), |
935 | 935 | $this->mappings->sync_sf_update => array( |
936 | - 'text' => __( 'Salesforce update', 'object-sync-for-salesforce' ), |
|
936 | + 'text' => __('Salesforce update', 'object-sync-for-salesforce'), |
|
937 | 937 | 'id' => 'sf_update', |
938 | 938 | 'desc' => '', |
939 | 939 | ), |
940 | 940 | $this->mappings->sync_sf_delete => array( |
941 | - 'text' => __( 'Salesforce delete', 'object-sync-for-salesforce' ), |
|
941 | + 'text' => __('Salesforce delete', 'object-sync-for-salesforce'), |
|
942 | 942 | 'id' => 'sf_delete', |
943 | 943 | 'desc' => '', |
944 | 944 | ), |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | ), |
947 | 947 | ), |
948 | 948 | ); |
949 | - foreach ( $log_settings as $key => $attributes ) { |
|
949 | + foreach ($log_settings as $key => $attributes) { |
|
950 | 950 | $id = $this->option_prefix . $key; |
951 | 951 | $name = $this->option_prefix . $key; |
952 | 952 | $title = $attributes['title']; |
@@ -962,8 +962,8 @@ discard block |
||
962 | 962 | 'name' => $name, |
963 | 963 | ) |
964 | 964 | ); |
965 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
966 | - register_setting( $page, $id ); |
|
965 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
966 | + register_setting($page, $id); |
|
967 | 967 | } |
968 | 968 | } |
969 | 969 | |
@@ -974,69 +974,69 @@ discard block |
||
974 | 974 | public function notices() { |
975 | 975 | |
976 | 976 | // before a notice is displayed, we should make sure we are on a page related to this plugin |
977 | - if ( ! isset( $_GET['page'] ) || 'object-sync-salesforce-admin' !== $_GET['page'] ) { |
|
977 | + if ( ! isset($_GET['page']) || 'object-sync-salesforce-admin' !== $_GET['page']) { |
|
978 | 978 | return; |
979 | 979 | } |
980 | 980 | |
981 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
982 | - require_once plugin_dir_path( __FILE__ ) . '../classes/admin-notice.php'; |
|
981 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
982 | + require_once plugin_dir_path(__FILE__) . '../classes/admin-notice.php'; |
|
983 | 983 | |
984 | 984 | $notices = array( |
985 | 985 | 'permission' => array( |
986 | 986 | 'condition' => false === $this->check_wordpress_admin_permissions(), |
987 | - 'message' => __( "Your account does not have permission to edit the Salesforce REST API plugin's settings.", 'object-sync-for-salesforce' ), |
|
987 | + 'message' => __("Your account does not have permission to edit the Salesforce REST API plugin's settings.", 'object-sync-for-salesforce'), |
|
988 | 988 | 'type' => 'error', |
989 | 989 | 'dismissible' => false, |
990 | 990 | ), |
991 | 991 | 'fieldmap' => array( |
992 | - 'condition' => isset( $get_data['transient'] ), |
|
993 | - 'message' => __( 'Errors kept this fieldmap from being saved.', 'object-sync-for-salesforce' ), |
|
992 | + 'condition' => isset($get_data['transient']), |
|
993 | + 'message' => __('Errors kept this fieldmap from being saved.', 'object-sync-for-salesforce'), |
|
994 | 994 | 'type' => 'error', |
995 | 995 | 'dismissible' => true, |
996 | 996 | ), |
997 | 997 | 'object_map' => array( |
998 | - 'condition' => isset( $get_data['map_transient'] ), |
|
999 | - 'message' => __( 'Errors kept this object map from being saved.', 'object-sync-for-salesforce' ), |
|
998 | + 'condition' => isset($get_data['map_transient']), |
|
999 | + 'message' => __('Errors kept this object map from being saved.', 'object-sync-for-salesforce'), |
|
1000 | 1000 | 'type' => 'error', |
1001 | 1001 | 'dismissible' => true, |
1002 | 1002 | ), |
1003 | 1003 | 'data_saved' => array( |
1004 | - 'condition' => isset( $get_data['data_saved'] ) && 'true' === $get_data['data_saved'], |
|
1005 | - 'message' => __( 'This data was successfully saved.', 'object-sync-for-salesforce' ), |
|
1004 | + 'condition' => isset($get_data['data_saved']) && 'true' === $get_data['data_saved'], |
|
1005 | + 'message' => __('This data was successfully saved.', 'object-sync-for-salesforce'), |
|
1006 | 1006 | 'type' => 'success', |
1007 | 1007 | 'dismissible' => true, |
1008 | 1008 | ), |
1009 | 1009 | 'data_save_error' => array( |
1010 | - 'condition' => isset( $get_data['data_saved'] ) && 'false' === $get_data['data_saved'], |
|
1011 | - 'message' => __( 'This data was not successfully saved. Try again.', 'object-sync-for-salesforce' ), |
|
1010 | + 'condition' => isset($get_data['data_saved']) && 'false' === $get_data['data_saved'], |
|
1011 | + 'message' => __('This data was not successfully saved. Try again.', 'object-sync-for-salesforce'), |
|
1012 | 1012 | 'type' => 'error', |
1013 | 1013 | 'dismissible' => true, |
1014 | 1014 | ), |
1015 | 1015 | ); |
1016 | 1016 | |
1017 | - foreach ( $notices as $key => $value ) { |
|
1017 | + foreach ($notices as $key => $value) { |
|
1018 | 1018 | |
1019 | 1019 | $condition = $value['condition']; |
1020 | 1020 | $message = $value['message']; |
1021 | 1021 | |
1022 | - if ( isset( $value['dismissible'] ) ) { |
|
1022 | + if (isset($value['dismissible'])) { |
|
1023 | 1023 | $dismissible = $value['dismissible']; |
1024 | 1024 | } else { |
1025 | 1025 | $dismissible = false; |
1026 | 1026 | } |
1027 | 1027 | |
1028 | - if ( isset( $value['type'] ) ) { |
|
1028 | + if (isset($value['type'])) { |
|
1029 | 1029 | $type = $value['type']; |
1030 | 1030 | } else { |
1031 | 1031 | $type = ''; |
1032 | 1032 | } |
1033 | 1033 | |
1034 | - if ( ! isset( $value['template'] ) ) { |
|
1034 | + if ( ! isset($value['template'])) { |
|
1035 | 1035 | $template = ''; |
1036 | 1036 | } |
1037 | 1037 | |
1038 | - if ( $condition ) { |
|
1039 | - new Object_Sync_Sf_Admin_Notice( $condition, $message, $dismissible, $type, $template ); |
|
1038 | + if ($condition) { |
|
1039 | + new Object_Sync_Sf_Admin_Notice($condition, $message, $dismissible, $type, $template); |
|
1040 | 1040 | } |
1041 | 1041 | } |
1042 | 1042 | |
@@ -1051,47 +1051,47 @@ discard block |
||
1051 | 1051 | * can optionally contain a type |
1052 | 1052 | * @return array $object_settings |
1053 | 1053 | */ |
1054 | - public function get_salesforce_object_description( $data = array() ) { |
|
1054 | + public function get_salesforce_object_description($data = array()) { |
|
1055 | 1055 | $ajax = false; |
1056 | - if ( empty( $data ) ) { |
|
1057 | - $data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1056 | + if (empty($data)) { |
|
1057 | + $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1058 | 1058 | $ajax = true; |
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | $object_description = array(); |
1062 | 1062 | |
1063 | - if ( ! empty( $data['salesforce_object'] ) ) { |
|
1064 | - $object = $this->salesforce['sfapi']->object_describe( esc_attr( $data['salesforce_object'] ) ); |
|
1063 | + if ( ! empty($data['salesforce_object'])) { |
|
1064 | + $object = $this->salesforce['sfapi']->object_describe(esc_attr($data['salesforce_object'])); |
|
1065 | 1065 | |
1066 | 1066 | $object_fields = array(); |
1067 | 1067 | $include_record_types = array(); |
1068 | 1068 | |
1069 | 1069 | // these can come from ajax |
1070 | - $include = isset( $data['include'] ) ? (array) $data['include'] : array(); |
|
1071 | - $include = array_map( 'esc_attr', $include ); |
|
1072 | - |
|
1073 | - if ( in_array( 'fields', $include, true ) || empty( $include ) ) { |
|
1074 | - $type = isset( $data['field_type'] ) ? esc_attr( $data['field_type'] ) : ''; // can come from ajax |
|
1075 | - foreach ( $object['data']['fields'] as $key => $value ) { |
|
1076 | - if ( '' === $type || $type === $value['type'] ) { |
|
1077 | - $object_fields[ $key ] = $value; |
|
1070 | + $include = isset($data['include']) ? (array) $data['include'] : array(); |
|
1071 | + $include = array_map('esc_attr', $include); |
|
1072 | + |
|
1073 | + if (in_array('fields', $include, true) || empty($include)) { |
|
1074 | + $type = isset($data['field_type']) ? esc_attr($data['field_type']) : ''; // can come from ajax |
|
1075 | + foreach ($object['data']['fields'] as $key => $value) { |
|
1076 | + if ('' === $type || $type === $value['type']) { |
|
1077 | + $object_fields[$key] = $value; |
|
1078 | 1078 | } |
1079 | 1079 | } |
1080 | 1080 | $object_description['fields'] = $object_fields; |
1081 | 1081 | } |
1082 | 1082 | |
1083 | - if ( in_array( 'recordTypeInfos', $include, true ) ) { |
|
1084 | - if ( isset( $object['data']['recordTypeInfos'] ) && count( $object['data']['recordTypeInfos'] ) > 1 ) { |
|
1085 | - foreach ( $object['data']['recordTypeInfos'] as $type ) { |
|
1086 | - $object_record_types[ $type['recordTypeId'] ] = $type['name']; |
|
1083 | + if (in_array('recordTypeInfos', $include, true)) { |
|
1084 | + if (isset($object['data']['recordTypeInfos']) && count($object['data']['recordTypeInfos']) > 1) { |
|
1085 | + foreach ($object['data']['recordTypeInfos'] as $type) { |
|
1086 | + $object_record_types[$type['recordTypeId']] = $type['name']; |
|
1087 | 1087 | } |
1088 | 1088 | $object_description['recordTypeInfos'] = $object_record_types; |
1089 | 1089 | } |
1090 | 1090 | } |
1091 | 1091 | } |
1092 | 1092 | |
1093 | - if ( true === $ajax ) { |
|
1094 | - wp_send_json_success( $object_description ); |
|
1093 | + if (true === $ajax) { |
|
1094 | + wp_send_json_success($object_description); |
|
1095 | 1095 | } else { |
1096 | 1096 | return $object_description; |
1097 | 1097 | } |
@@ -1105,23 +1105,23 @@ discard block |
||
1105 | 1105 | * can optionally contain a type for the field |
1106 | 1106 | * @return array $object_fields |
1107 | 1107 | */ |
1108 | - public function get_salesforce_object_fields( $data = array() ) { |
|
1108 | + public function get_salesforce_object_fields($data = array()) { |
|
1109 | 1109 | |
1110 | - if ( ! empty( $data['salesforce_object'] ) ) { |
|
1111 | - $object = $this->salesforce['sfapi']->object_describe( esc_attr( $data['salesforce_object'] ) ); |
|
1110 | + if ( ! empty($data['salesforce_object'])) { |
|
1111 | + $object = $this->salesforce['sfapi']->object_describe(esc_attr($data['salesforce_object'])); |
|
1112 | 1112 | $object_fields = array(); |
1113 | - $type = isset( $data['type'] ) ? esc_attr( $data['type'] ) : ''; |
|
1114 | - $include_record_types = isset( $data['include_record_types'] ) ? esc_attr( $data['include_record_types'] ) : false; |
|
1115 | - foreach ( $object['data']['fields'] as $key => $value ) { |
|
1116 | - if ( '' === $type || $type === $value['type'] ) { |
|
1117 | - $object_fields[ $key ] = $value; |
|
1113 | + $type = isset($data['type']) ? esc_attr($data['type']) : ''; |
|
1114 | + $include_record_types = isset($data['include_record_types']) ? esc_attr($data['include_record_types']) : false; |
|
1115 | + foreach ($object['data']['fields'] as $key => $value) { |
|
1116 | + if ('' === $type || $type === $value['type']) { |
|
1117 | + $object_fields[$key] = $value; |
|
1118 | 1118 | } |
1119 | 1119 | } |
1120 | - if ( true === $include_record_types ) { |
|
1120 | + if (true === $include_record_types) { |
|
1121 | 1121 | $object_record_types = array(); |
1122 | - if ( isset( $object['data']['recordTypeInfos'] ) && count( $object['data']['recordTypeInfos'] ) > 1 ) { |
|
1123 | - foreach ( $object['data']['recordTypeInfos'] as $type ) { |
|
1124 | - $object_record_types[ $type['recordTypeId'] ] = $type['name']; |
|
1122 | + if (isset($object['data']['recordTypeInfos']) && count($object['data']['recordTypeInfos']) > 1) { |
|
1123 | + foreach ($object['data']['recordTypeInfos'] as $type) { |
|
1124 | + $object_record_types[$type['recordTypeId']] = $type['name']; |
|
1125 | 1125 | } |
1126 | 1126 | } |
1127 | 1127 | } |
@@ -1138,18 +1138,18 @@ discard block |
||
1138 | 1138 | * @param string $wordpress_object |
1139 | 1139 | * @return array $object_fields |
1140 | 1140 | */ |
1141 | - public function get_wordpress_object_fields( $wordpress_object = '' ) { |
|
1141 | + public function get_wordpress_object_fields($wordpress_object = '') { |
|
1142 | 1142 | $ajax = false; |
1143 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1144 | - if ( empty( $wordpress_object ) ) { |
|
1145 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1143 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1144 | + if (empty($wordpress_object)) { |
|
1145 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1146 | 1146 | $ajax = true; |
1147 | 1147 | } |
1148 | 1148 | |
1149 | - $object_fields = $this->wordpress->get_wordpress_object_fields( $wordpress_object ); |
|
1149 | + $object_fields = $this->wordpress->get_wordpress_object_fields($wordpress_object); |
|
1150 | 1150 | |
1151 | - if ( true === $ajax ) { |
|
1152 | - wp_send_json_success( $object_fields ); |
|
1151 | + if (true === $ajax) { |
|
1152 | + wp_send_json_success($object_fields); |
|
1153 | 1153 | } else { |
1154 | 1154 | return $object_fields; |
1155 | 1155 | } |
@@ -1163,24 +1163,24 @@ discard block |
||
1163 | 1163 | * @param string $salesforce_object |
1164 | 1164 | * @return array $object_fields |
1165 | 1165 | */ |
1166 | - public function get_wp_sf_object_fields( $wordpress_object = '', $salesforce = '' ) { |
|
1167 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1168 | - if ( empty( $wordpress_object ) ) { |
|
1169 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1166 | + public function get_wp_sf_object_fields($wordpress_object = '', $salesforce = '') { |
|
1167 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1168 | + if (empty($wordpress_object)) { |
|
1169 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1170 | 1170 | } |
1171 | - if ( empty( $salesforce_object ) ) { |
|
1172 | - $salesforce_object = isset( $post_data['salesforce_object'] ) ? sanitize_text_field( wp_unslash( $post_data['salesforce_object'] ) ) : ''; |
|
1171 | + if (empty($salesforce_object)) { |
|
1172 | + $salesforce_object = isset($post_data['salesforce_object']) ? sanitize_text_field(wp_unslash($post_data['salesforce_object'])) : ''; |
|
1173 | 1173 | } |
1174 | 1174 | |
1175 | - $object_fields['wordpress'] = $this->get_wordpress_object_fields( $wordpress_object ); |
|
1175 | + $object_fields['wordpress'] = $this->get_wordpress_object_fields($wordpress_object); |
|
1176 | 1176 | $object_fields['salesforce'] = $this->get_salesforce_object_fields( |
1177 | 1177 | array( |
1178 | 1178 | 'salesforce_object' => $salesforce_object, |
1179 | 1179 | ) |
1180 | 1180 | ); |
1181 | 1181 | |
1182 | - if ( ! empty( $post_data ) ) { |
|
1183 | - wp_send_json_success( $object_fields ); |
|
1182 | + if ( ! empty($post_data)) { |
|
1183 | + wp_send_json_success($object_fields); |
|
1184 | 1184 | } else { |
1185 | 1185 | return $object_fields; |
1186 | 1186 | } |
@@ -1193,17 +1193,17 @@ discard block |
||
1193 | 1193 | * @param string $wordpress_object |
1194 | 1194 | * @param int $wordpress_id |
1195 | 1195 | */ |
1196 | - public function push_to_salesforce( $wordpress_object = '', $wordpress_id = '' ) { |
|
1197 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1198 | - if ( empty( $wordpress_object ) && empty( $wordpress_id ) ) { |
|
1199 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1200 | - $wordpress_id = isset( $post_data['wordpress_id'] ) ? absint( $post_data['wordpress_id'] ) : ''; |
|
1196 | + public function push_to_salesforce($wordpress_object = '', $wordpress_id = '') { |
|
1197 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1198 | + if (empty($wordpress_object) && empty($wordpress_id)) { |
|
1199 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1200 | + $wordpress_id = isset($post_data['wordpress_id']) ? absint($post_data['wordpress_id']) : ''; |
|
1201 | 1201 | } |
1202 | - $data = $this->wordpress->get_wordpress_object_data( $wordpress_object, $wordpress_id ); |
|
1203 | - $result = $this->push->manual_object_update( $data, $wordpress_object ); |
|
1202 | + $data = $this->wordpress->get_wordpress_object_data($wordpress_object, $wordpress_id); |
|
1203 | + $result = $this->push->manual_object_update($data, $wordpress_object); |
|
1204 | 1204 | |
1205 | - if ( ! empty( $post_data['wordpress_object'] ) && ! empty( $post_data['wordpress_id'] ) ) { |
|
1206 | - wp_send_json_success( $result ); |
|
1205 | + if ( ! empty($post_data['wordpress_object']) && ! empty($post_data['wordpress_id'])) { |
|
1206 | + wp_send_json_success($result); |
|
1207 | 1207 | } else { |
1208 | 1208 | return $result; |
1209 | 1209 | } |
@@ -1217,16 +1217,16 @@ discard block |
||
1217 | 1217 | * @param string $salesforce_id |
1218 | 1218 | * @param string $wordpress_object |
1219 | 1219 | */ |
1220 | - public function pull_from_salesforce( $salesforce_id = '', $wordpress_object = '' ) { |
|
1221 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1222 | - if ( empty( $wordpress_object ) && empty( $salesforce_id ) ) { |
|
1223 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1224 | - $salesforce_id = isset( $post_data['salesforce_id'] ) ? sanitize_text_field( wp_unslash( $post_data['salesforce_id'] ) ) : ''; |
|
1225 | - } |
|
1226 | - $type = $this->salesforce['sfapi']->get_sobject_type( $salesforce_id ); |
|
1227 | - $result = $this->pull->manual_pull( $type, $salesforce_id, $wordpress_object ); // we want the wp object to make sure we get the right fieldmap |
|
1228 | - if ( ! empty( $post_data ) ) { |
|
1229 | - wp_send_json_success( $result ); |
|
1220 | + public function pull_from_salesforce($salesforce_id = '', $wordpress_object = '') { |
|
1221 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1222 | + if (empty($wordpress_object) && empty($salesforce_id)) { |
|
1223 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1224 | + $salesforce_id = isset($post_data['salesforce_id']) ? sanitize_text_field(wp_unslash($post_data['salesforce_id'])) : ''; |
|
1225 | + } |
|
1226 | + $type = $this->salesforce['sfapi']->get_sobject_type($salesforce_id); |
|
1227 | + $result = $this->pull->manual_pull($type, $salesforce_id, $wordpress_object); // we want the wp object to make sure we get the right fieldmap |
|
1228 | + if ( ! empty($post_data)) { |
|
1229 | + wp_send_json_success($result); |
|
1230 | 1230 | } else { |
1231 | 1231 | return $result; |
1232 | 1232 | } |
@@ -1238,18 +1238,18 @@ discard block |
||
1238 | 1238 | * |
1239 | 1239 | * @param int $mapping_id |
1240 | 1240 | */ |
1241 | - public function refresh_mapped_data( $mapping_id = '' ) { |
|
1242 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1243 | - if ( empty( $mapping_id ) ) { |
|
1244 | - $mapping_id = isset( $post_data['mapping_id'] ) ? absint( $post_data['mapping_id'] ) : ''; |
|
1241 | + public function refresh_mapped_data($mapping_id = '') { |
|
1242 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1243 | + if (empty($mapping_id)) { |
|
1244 | + $mapping_id = isset($post_data['mapping_id']) ? absint($post_data['mapping_id']) : ''; |
|
1245 | 1245 | } |
1246 | 1246 | $result = $this->mappings->get_object_maps( |
1247 | 1247 | array( |
1248 | 1248 | 'id' => $mapping_id, |
1249 | 1249 | ) |
1250 | 1250 | ); |
1251 | - if ( ! empty( $post_data ) ) { |
|
1252 | - wp_send_json_success( $result ); |
|
1251 | + if ( ! empty($post_data)) { |
|
1252 | + wp_send_json_success($result); |
|
1253 | 1253 | } else { |
1254 | 1254 | return $result; |
1255 | 1255 | } |
@@ -1265,47 +1265,47 @@ discard block |
||
1265 | 1265 | */ |
1266 | 1266 | public function prepare_fieldmap_data() { |
1267 | 1267 | $error = false; |
1268 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1269 | - $cachekey = md5( wp_json_encode( $post_data ) ); |
|
1268 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1269 | + $cachekey = md5(wp_json_encode($post_data)); |
|
1270 | 1270 | |
1271 | - if ( ! isset( $post_data['label'] ) || ! isset( $post_data['salesforce_object'] ) || ! isset( $post_data['wordpress_object'] ) ) { |
|
1271 | + if ( ! isset($post_data['label']) || ! isset($post_data['salesforce_object']) || ! isset($post_data['wordpress_object'])) { |
|
1272 | 1272 | $error = true; |
1273 | 1273 | } |
1274 | - if ( true === $error ) { |
|
1275 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1276 | - if ( '' !== $cachekey ) { |
|
1277 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&transient=' . $cachekey; |
|
1274 | + if (true === $error) { |
|
1275 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1276 | + if ('' !== $cachekey) { |
|
1277 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&transient=' . $cachekey; |
|
1278 | 1278 | } |
1279 | 1279 | } else { // there are no errors |
1280 | 1280 | // send the row to the fieldmap class |
1281 | 1281 | // if it is add or clone, use the create method |
1282 | - $method = esc_attr( $post_data['method'] ); |
|
1282 | + $method = esc_attr($post_data['method']); |
|
1283 | 1283 | $salesforce_fields = $this->get_salesforce_object_fields( |
1284 | 1284 | array( |
1285 | 1285 | 'salesforce_object' => $post_data['salesforce_object'], |
1286 | 1286 | ) |
1287 | 1287 | ); |
1288 | - $wordpress_fields = $this->get_wordpress_object_fields( $post_data['wordpress_object'] ); |
|
1289 | - if ( 'add' === $method || 'clone' === $method ) { |
|
1290 | - $result = $this->mappings->create_fieldmap( $post_data, $wordpress_fields, $salesforce_fields ); |
|
1291 | - } elseif ( 'edit' === $method ) { // if it is edit, use the update method |
|
1292 | - $id = esc_attr( $post_data['id'] ); |
|
1293 | - $result = $this->mappings->update_fieldmap( $post_data, $wordpress_fields, $salesforce_fields, $id ); |
|
1288 | + $wordpress_fields = $this->get_wordpress_object_fields($post_data['wordpress_object']); |
|
1289 | + if ('add' === $method || 'clone' === $method) { |
|
1290 | + $result = $this->mappings->create_fieldmap($post_data, $wordpress_fields, $salesforce_fields); |
|
1291 | + } elseif ('edit' === $method) { // if it is edit, use the update method |
|
1292 | + $id = esc_attr($post_data['id']); |
|
1293 | + $result = $this->mappings->update_fieldmap($post_data, $wordpress_fields, $salesforce_fields, $id); |
|
1294 | 1294 | } |
1295 | - if ( false === $result ) { // if the database didn't save, it's still an error |
|
1296 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1297 | - if ( '' !== $cachekey ) { |
|
1298 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&transient=' . $cachekey; |
|
1295 | + if (false === $result) { // if the database didn't save, it's still an error |
|
1296 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1297 | + if ('' !== $cachekey) { |
|
1298 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&transient=' . $cachekey; |
|
1299 | 1299 | } |
1300 | 1300 | } else { |
1301 | - if ( isset( $post_data['transient'] ) ) { // there was previously an error saved. can delete it now. |
|
1302 | - $this->sfwp_transients->delete( esc_attr( $post_data['map_transient'] ) ); |
|
1301 | + if (isset($post_data['transient'])) { // there was previously an error saved. can delete it now. |
|
1302 | + $this->sfwp_transients->delete(esc_attr($post_data['map_transient'])); |
|
1303 | 1303 | } |
1304 | 1304 | // then send the user to the list of fieldmaps |
1305 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1305 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1306 | 1306 | } |
1307 | 1307 | } |
1308 | - wp_safe_redirect( $url ); |
|
1308 | + wp_safe_redirect($url); |
|
1309 | 1309 | exit(); |
1310 | 1310 | } |
1311 | 1311 | |
@@ -1317,15 +1317,15 @@ discard block |
||
1317 | 1317 | * |
1318 | 1318 | */ |
1319 | 1319 | public function delete_fieldmap() { |
1320 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1321 | - if ( $post_data['id'] ) { |
|
1322 | - $result = $this->mappings->delete_fieldmap( $post_data['id'] ); |
|
1323 | - if ( true === $result ) { |
|
1324 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1320 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1321 | + if ($post_data['id']) { |
|
1322 | + $result = $this->mappings->delete_fieldmap($post_data['id']); |
|
1323 | + if (true === $result) { |
|
1324 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1325 | 1325 | } else { |
1326 | - $url = esc_url_raw( $post_data['redirect_url_error'] . '&id=' . $post_data['id'] ); |
|
1326 | + $url = esc_url_raw($post_data['redirect_url_error'] . '&id=' . $post_data['id']); |
|
1327 | 1327 | } |
1328 | - wp_safe_redirect( $url ); |
|
1328 | + wp_safe_redirect($url); |
|
1329 | 1329 | exit(); |
1330 | 1330 | } |
1331 | 1331 | } |
@@ -1340,38 +1340,38 @@ discard block |
||
1340 | 1340 | */ |
1341 | 1341 | public function prepare_object_map_data() { |
1342 | 1342 | $error = false; |
1343 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1344 | - $cachekey = md5( wp_json_encode( $post_data ) ); |
|
1343 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1344 | + $cachekey = md5(wp_json_encode($post_data)); |
|
1345 | 1345 | |
1346 | - if ( ! isset( $post_data['wordpress_id'] ) || ! isset( $post_data['salesforce_id'] ) ) { |
|
1346 | + if ( ! isset($post_data['wordpress_id']) || ! isset($post_data['salesforce_id'])) { |
|
1347 | 1347 | $error = true; |
1348 | 1348 | } |
1349 | - if ( true === $error ) { |
|
1350 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1351 | - if ( '' !== $cachekey ) { |
|
1352 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&map_transient=' . $cachekey; |
|
1349 | + if (true === $error) { |
|
1350 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1351 | + if ('' !== $cachekey) { |
|
1352 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&map_transient=' . $cachekey; |
|
1353 | 1353 | } |
1354 | 1354 | } else { // there are no errors |
1355 | 1355 | // send the row to the object map class |
1356 | - $method = esc_attr( $post_data['method'] ); |
|
1357 | - if ( 'edit' === $method ) { // if it is edit, use the update method |
|
1358 | - $id = esc_attr( $post_data['id'] ); |
|
1359 | - $result = $this->mappings->update_object_map( $post_data, $id ); |
|
1356 | + $method = esc_attr($post_data['method']); |
|
1357 | + if ('edit' === $method) { // if it is edit, use the update method |
|
1358 | + $id = esc_attr($post_data['id']); |
|
1359 | + $result = $this->mappings->update_object_map($post_data, $id); |
|
1360 | 1360 | } |
1361 | - if ( false === $result ) { // if the database didn't save, it's still an error |
|
1362 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1363 | - if ( '' !== $cachekey ) { |
|
1364 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&map_transient=' . $cachekey; |
|
1361 | + if (false === $result) { // if the database didn't save, it's still an error |
|
1362 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1363 | + if ('' !== $cachekey) { |
|
1364 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&map_transient=' . $cachekey; |
|
1365 | 1365 | } |
1366 | 1366 | } else { |
1367 | - if ( isset( $post_data['map_transient'] ) ) { // there was previously an error saved. can delete it now. |
|
1368 | - $this->sfwp_transients->delete( esc_attr( $post_data['map_transient'] ) ); |
|
1367 | + if (isset($post_data['map_transient'])) { // there was previously an error saved. can delete it now. |
|
1368 | + $this->sfwp_transients->delete(esc_attr($post_data['map_transient'])); |
|
1369 | 1369 | } |
1370 | 1370 | // then send the user to the success redirect url |
1371 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1371 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1372 | 1372 | } |
1373 | 1373 | } |
1374 | - wp_safe_redirect( $url ); |
|
1374 | + wp_safe_redirect($url); |
|
1375 | 1375 | exit(); |
1376 | 1376 | } |
1377 | 1377 | |
@@ -1383,15 +1383,15 @@ discard block |
||
1383 | 1383 | * |
1384 | 1384 | */ |
1385 | 1385 | public function delete_object_map() { |
1386 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1387 | - if ( $post_data['id'] ) { |
|
1388 | - $result = $this->mappings->delete_object_map( $post_data['id'] ); |
|
1389 | - if ( true === $result ) { |
|
1390 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1386 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1387 | + if ($post_data['id']) { |
|
1388 | + $result = $this->mappings->delete_object_map($post_data['id']); |
|
1389 | + if (true === $result) { |
|
1390 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1391 | 1391 | } else { |
1392 | - $url = esc_url_raw( $post_data['redirect_url_error'] . '&id=' . $post_data['id'] ); |
|
1392 | + $url = esc_url_raw($post_data['redirect_url_error'] . '&id=' . $post_data['id']); |
|
1393 | 1393 | } |
1394 | - wp_safe_redirect( $url ); |
|
1394 | + wp_safe_redirect($url); |
|
1395 | 1395 | exit(); |
1396 | 1396 | } |
1397 | 1397 | } |
@@ -1402,95 +1402,95 @@ discard block |
||
1402 | 1402 | */ |
1403 | 1403 | public function import_json_file() { |
1404 | 1404 | |
1405 | - if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_import'], 'object_sync_for_salesforce_nonce_import' ) ) { |
|
1405 | + if ( ! wp_verify_nonce($_POST['object_sync_for_salesforce_nonce_import'], 'object_sync_for_salesforce_nonce_import')) { |
|
1406 | 1406 | return; |
1407 | 1407 | } |
1408 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1408 | + if ( ! current_user_can('manage_options')) { |
|
1409 | 1409 | return; |
1410 | 1410 | } |
1411 | 1411 | $path = $_FILES['import_file']['name']; |
1412 | - $extension = pathinfo( $path, PATHINFO_EXTENSION ); |
|
1413 | - if ( 'json' !== $extension ) { |
|
1414 | - wp_die( __( 'Please upload a valid .json file' ) ); |
|
1412 | + $extension = pathinfo($path, PATHINFO_EXTENSION); |
|
1413 | + if ('json' !== $extension) { |
|
1414 | + wp_die(__('Please upload a valid .json file')); |
|
1415 | 1415 | } |
1416 | 1416 | |
1417 | 1417 | $import_file = $_FILES['import_file']['tmp_name']; |
1418 | - if ( empty( $import_file ) ) { |
|
1419 | - wp_die( __( 'Please upload a file to import' ) ); |
|
1418 | + if (empty($import_file)) { |
|
1419 | + wp_die(__('Please upload a file to import')); |
|
1420 | 1420 | } |
1421 | 1421 | |
1422 | 1422 | // Retrieve the data from the file and convert the json object to an array. |
1423 | - $data = (array) json_decode( file_get_contents( $import_file ), true ); |
|
1423 | + $data = (array) json_decode(file_get_contents($import_file), true); |
|
1424 | 1424 | |
1425 | 1425 | // if there is only one object map, fix the array |
1426 | - if ( isset( $data['object_maps'] ) ) { |
|
1427 | - if ( count( $data['object_maps'] ) === count( $data['object_maps'], COUNT_RECURSIVE ) ) { |
|
1428 | - $data['object_maps'] = array( 0 => $data['object_maps'] ); |
|
1426 | + if (isset($data['object_maps'])) { |
|
1427 | + if (count($data['object_maps']) === count($data['object_maps'], COUNT_RECURSIVE)) { |
|
1428 | + $data['object_maps'] = array(0 => $data['object_maps']); |
|
1429 | 1429 | } |
1430 | 1430 | } |
1431 | 1431 | |
1432 | - $overwrite = isset( $_POST['overwrite'] ) ? esc_attr( $_POST['overwrite'] ) : ''; |
|
1433 | - if ( '1' === $overwrite ) { |
|
1434 | - if ( isset( $data['fieldmaps'] ) ) { |
|
1432 | + $overwrite = isset($_POST['overwrite']) ? esc_attr($_POST['overwrite']) : ''; |
|
1433 | + if ('1' === $overwrite) { |
|
1434 | + if (isset($data['fieldmaps'])) { |
|
1435 | 1435 | $fieldmaps = $this->mappings->get_fieldmaps(); |
1436 | - foreach ( $fieldmaps as $fieldmap ) { |
|
1436 | + foreach ($fieldmaps as $fieldmap) { |
|
1437 | 1437 | $id = $fieldmap['id']; |
1438 | - $delete = $this->mappings->delete_fieldmap( $id ); |
|
1438 | + $delete = $this->mappings->delete_fieldmap($id); |
|
1439 | 1439 | } |
1440 | 1440 | } |
1441 | - if ( isset( $data['object_maps'] ) ) { |
|
1441 | + if (isset($data['object_maps'])) { |
|
1442 | 1442 | $object_maps = $this->mappings->get_object_maps(); |
1443 | 1443 | |
1444 | 1444 | // if there is only one existing object map, fix the array |
1445 | - if ( count( $object_maps ) === count( $object_maps, COUNT_RECURSIVE ) ) { |
|
1446 | - $object_maps = array( 0 => $object_maps ); |
|
1445 | + if (count($object_maps) === count($object_maps, COUNT_RECURSIVE)) { |
|
1446 | + $object_maps = array(0 => $object_maps); |
|
1447 | 1447 | } |
1448 | 1448 | |
1449 | - foreach ( $object_maps as $object_map ) { |
|
1449 | + foreach ($object_maps as $object_map) { |
|
1450 | 1450 | $id = $object_map['id']; |
1451 | - $delete = $this->mappings->delete_object_map( $id ); |
|
1451 | + $delete = $this->mappings->delete_object_map($id); |
|
1452 | 1452 | } |
1453 | 1453 | } |
1454 | - if ( isset( $data['plugin_settings'] ) ) { |
|
1455 | - foreach ( $data['plugin_settings'] as $key => $value ) { |
|
1456 | - delete_option( $value['option_name'] ); |
|
1454 | + if (isset($data['plugin_settings'])) { |
|
1455 | + foreach ($data['plugin_settings'] as $key => $value) { |
|
1456 | + delete_option($value['option_name']); |
|
1457 | 1457 | } |
1458 | 1458 | } |
1459 | 1459 | } |
1460 | 1460 | |
1461 | 1461 | $success = true; |
1462 | 1462 | |
1463 | - if ( isset( $data['fieldmaps'] ) ) { |
|
1464 | - foreach ( $data['fieldmaps'] as $fieldmap ) { |
|
1465 | - unset( $fieldmap['id'] ); |
|
1466 | - $create = $this->mappings->create_fieldmap( $fieldmap ); |
|
1467 | - if ( false === $create ) { |
|
1463 | + if (isset($data['fieldmaps'])) { |
|
1464 | + foreach ($data['fieldmaps'] as $fieldmap) { |
|
1465 | + unset($fieldmap['id']); |
|
1466 | + $create = $this->mappings->create_fieldmap($fieldmap); |
|
1467 | + if (false === $create) { |
|
1468 | 1468 | $success = false; |
1469 | 1469 | } |
1470 | 1470 | } |
1471 | 1471 | } |
1472 | 1472 | |
1473 | - if ( isset( $data['object_maps'] ) ) { |
|
1474 | - foreach ( $data['object_maps'] as $object_map ) { |
|
1475 | - unset( $object_map['id'] ); |
|
1476 | - $create = $this->mappings->create_object_map( $object_map ); |
|
1477 | - if ( false === $create ) { |
|
1473 | + if (isset($data['object_maps'])) { |
|
1474 | + foreach ($data['object_maps'] as $object_map) { |
|
1475 | + unset($object_map['id']); |
|
1476 | + $create = $this->mappings->create_object_map($object_map); |
|
1477 | + if (false === $create) { |
|
1478 | 1478 | $success = false; |
1479 | 1479 | } |
1480 | 1480 | } |
1481 | 1481 | } |
1482 | 1482 | |
1483 | - if ( isset( $data['plugin_settings'] ) ) { |
|
1484 | - foreach ( $data['plugin_settings'] as $key => $value ) { |
|
1485 | - update_option( $value['option_name'], maybe_unserialize( $value['option_value'] ), $value['autoload'] ); |
|
1483 | + if (isset($data['plugin_settings'])) { |
|
1484 | + foreach ($data['plugin_settings'] as $key => $value) { |
|
1485 | + update_option($value['option_name'], maybe_unserialize($value['option_value']), $value['autoload']); |
|
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | |
1489 | - if ( true === $success ) { |
|
1490 | - wp_safe_redirect( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=true' ) ); |
|
1489 | + if (true === $success) { |
|
1490 | + wp_safe_redirect(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=true')); |
|
1491 | 1491 | exit; |
1492 | 1492 | } else { |
1493 | - wp_safe_redirect( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=false' ) ); |
|
1493 | + wp_safe_redirect(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=false')); |
|
1494 | 1494 | exit; |
1495 | 1495 | } |
1496 | 1496 | |
@@ -1502,28 +1502,28 @@ discard block |
||
1502 | 1502 | */ |
1503 | 1503 | public function export_json_file() { |
1504 | 1504 | |
1505 | - if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_export'], 'object_sync_for_salesforce_nonce_export' ) ) { |
|
1505 | + if ( ! wp_verify_nonce($_POST['object_sync_for_salesforce_nonce_export'], 'object_sync_for_salesforce_nonce_export')) { |
|
1506 | 1506 | return; |
1507 | 1507 | } |
1508 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1508 | + if ( ! current_user_can('manage_options')) { |
|
1509 | 1509 | return; |
1510 | 1510 | } |
1511 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1511 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1512 | 1512 | $export = array(); |
1513 | - if ( in_array( 'fieldmaps', $post_data['export'] ) ) { |
|
1513 | + if (in_array('fieldmaps', $post_data['export'])) { |
|
1514 | 1514 | $export['fieldmaps'] = $this->mappings->get_fieldmaps(); |
1515 | 1515 | } |
1516 | - if ( in_array( 'object_maps', $post_data['export'] ) ) { |
|
1516 | + if (in_array('object_maps', $post_data['export'])) { |
|
1517 | 1517 | $export['object_maps'] = $this->mappings->get_object_maps(); |
1518 | 1518 | } |
1519 | - if ( in_array( 'plugin_settings', $post_data['export'] ) ) { |
|
1520 | - $export['plugin_settings'] = $this->wpdb->get_results( 'SELECT * FROM ' . $this->wpdb->prefix . 'options' . ' WHERE option_name like "' . $this->option_prefix . '%"', ARRAY_A ); |
|
1519 | + if (in_array('plugin_settings', $post_data['export'])) { |
|
1520 | + $export['plugin_settings'] = $this->wpdb->get_results('SELECT * FROM ' . $this->wpdb->prefix . 'options' . ' WHERE option_name like "' . $this->option_prefix . '%"', ARRAY_A); |
|
1521 | 1521 | } |
1522 | 1522 | nocache_headers(); |
1523 | - header( 'Content-Type: application/json; charset=utf-8' ); |
|
1524 | - header( 'Content-Disposition: attachment; filename=object-sync-for-salesforce-data-export-' . date( 'm-d-Y' ) . '.json' ); |
|
1525 | - header( 'Expires: 0' ); |
|
1526 | - echo wp_json_encode( $export ); |
|
1523 | + header('Content-Type: application/json; charset=utf-8'); |
|
1524 | + header('Content-Disposition: attachment; filename=object-sync-for-salesforce-data-export-' . date('m-d-Y') . '.json'); |
|
1525 | + header('Expires: 0'); |
|
1526 | + echo wp_json_encode($export); |
|
1527 | 1527 | exit; |
1528 | 1528 | } |
1529 | 1529 | |
@@ -1532,7 +1532,7 @@ discard block |
||
1532 | 1532 | * |
1533 | 1533 | * @param array $args |
1534 | 1534 | */ |
1535 | - public function display_input_field( $args ) { |
|
1535 | + public function display_input_field($args) { |
|
1536 | 1536 | $type = $args['type']; |
1537 | 1537 | $id = $args['label_for']; |
1538 | 1538 | $name = $args['name']; |
@@ -1541,38 +1541,38 @@ discard block |
||
1541 | 1541 | |
1542 | 1542 | $class = 'regular-text'; |
1543 | 1543 | |
1544 | - if ( 'checkbox' === $type ) { |
|
1544 | + if ('checkbox' === $type) { |
|
1545 | 1545 | $class = 'checkbox'; |
1546 | 1546 | } |
1547 | 1547 | |
1548 | - if ( ! isset( $args['constant'] ) || ! defined( $args['constant'] ) ) { |
|
1549 | - $value = esc_attr( get_option( $id, '' ) ); |
|
1550 | - if ( 'checkbox' === $type ) { |
|
1551 | - if ( '1' === $value ) { |
|
1548 | + if ( ! isset($args['constant']) || ! defined($args['constant'])) { |
|
1549 | + $value = esc_attr(get_option($id, '')); |
|
1550 | + if ('checkbox' === $type) { |
|
1551 | + if ('1' === $value) { |
|
1552 | 1552 | $checked = 'checked '; |
1553 | 1553 | } |
1554 | 1554 | $value = 1; |
1555 | 1555 | } |
1556 | - if ( '' === $value && isset( $args['default'] ) && '' !== $args['default'] ) { |
|
1556 | + if ('' === $value && isset($args['default']) && '' !== $args['default']) { |
|
1557 | 1557 | $value = $args['default']; |
1558 | 1558 | } |
1559 | 1559 | |
1560 | - echo sprintf( '<input type="%1$s" value="%2$s" name="%3$s" id="%4$s" class="%5$s"%6$s>', |
|
1561 | - esc_attr( $type ), |
|
1562 | - esc_attr( $value ), |
|
1563 | - esc_attr( $name ), |
|
1564 | - esc_attr( $id ), |
|
1565 | - sanitize_html_class( $class . esc_html( ' code' ) ), |
|
1566 | - esc_html( $checked ) |
|
1560 | + echo sprintf('<input type="%1$s" value="%2$s" name="%3$s" id="%4$s" class="%5$s"%6$s>', |
|
1561 | + esc_attr($type), |
|
1562 | + esc_attr($value), |
|
1563 | + esc_attr($name), |
|
1564 | + esc_attr($id), |
|
1565 | + sanitize_html_class($class . esc_html(' code')), |
|
1566 | + esc_html($checked) |
|
1567 | 1567 | ); |
1568 | - if ( '' !== $desc ) { |
|
1569 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1570 | - esc_html( $desc ) |
|
1568 | + if ('' !== $desc) { |
|
1569 | + echo sprintf('<p class="description">%1$s</p>', |
|
1570 | + esc_html($desc) |
|
1571 | 1571 | ); |
1572 | 1572 | } |
1573 | 1573 | } else { |
1574 | - echo sprintf( '<p><code>%1$s</code></p>', |
|
1575 | - esc_html__( 'Defined in wp-config.php', 'object-sync-for-salesforce' ) |
|
1574 | + echo sprintf('<p><code>%1$s</code></p>', |
|
1575 | + esc_html__('Defined in wp-config.php', 'object-sync-for-salesforce') |
|
1576 | 1576 | ); |
1577 | 1577 | } |
1578 | 1578 | } |
@@ -1583,33 +1583,33 @@ discard block |
||
1583 | 1583 | * |
1584 | 1584 | * @param array $args |
1585 | 1585 | */ |
1586 | - public function display_checkboxes( $args ) { |
|
1586 | + public function display_checkboxes($args) { |
|
1587 | 1587 | $type = 'checkbox'; |
1588 | 1588 | $name = $args['name']; |
1589 | - $options = get_option( $name, array() ); |
|
1590 | - foreach ( $args['items'] as $key => $value ) { |
|
1589 | + $options = get_option($name, array()); |
|
1590 | + foreach ($args['items'] as $key => $value) { |
|
1591 | 1591 | $text = $value['text']; |
1592 | 1592 | $id = $value['id']; |
1593 | 1593 | $desc = $value['desc']; |
1594 | 1594 | $checked = ''; |
1595 | - if ( is_array( $options ) && in_array( (string) $key, $options, true ) ) { |
|
1595 | + if (is_array($options) && in_array((string) $key, $options, true)) { |
|
1596 | 1596 | $checked = 'checked'; |
1597 | - } elseif ( is_array( $options ) && empty( $options ) ) { |
|
1598 | - if ( isset( $value['default'] ) && true === $value['default'] ) { |
|
1597 | + } elseif (is_array($options) && empty($options)) { |
|
1598 | + if (isset($value['default']) && true === $value['default']) { |
|
1599 | 1599 | $checked = 'checked'; |
1600 | 1600 | } |
1601 | 1601 | } |
1602 | - echo sprintf( '<div class="checkbox"><label><input type="%1$s" value="%2$s" name="%3$s[]" id="%4$s"%5$s>%6$s</label></div>', |
|
1603 | - esc_attr( $type ), |
|
1604 | - esc_attr( $key ), |
|
1605 | - esc_attr( $name ), |
|
1606 | - esc_attr( $id ), |
|
1607 | - esc_html( $checked ), |
|
1608 | - esc_html( $text ) |
|
1602 | + echo sprintf('<div class="checkbox"><label><input type="%1$s" value="%2$s" name="%3$s[]" id="%4$s"%5$s>%6$s</label></div>', |
|
1603 | + esc_attr($type), |
|
1604 | + esc_attr($key), |
|
1605 | + esc_attr($name), |
|
1606 | + esc_attr($id), |
|
1607 | + esc_html($checked), |
|
1608 | + esc_html($text) |
|
1609 | 1609 | ); |
1610 | - if ( '' !== $desc ) { |
|
1611 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1612 | - esc_html( $desc ) |
|
1610 | + if ('' !== $desc) { |
|
1611 | + echo sprintf('<p class="description">%1$s</p>', |
|
1612 | + esc_html($desc) |
|
1613 | 1613 | ); |
1614 | 1614 | } |
1615 | 1615 | } |
@@ -1620,44 +1620,44 @@ discard block |
||
1620 | 1620 | * |
1621 | 1621 | * @param array $args |
1622 | 1622 | */ |
1623 | - public function display_select( $args ) { |
|
1623 | + public function display_select($args) { |
|
1624 | 1624 | $type = $args['type']; |
1625 | 1625 | $id = $args['label_for']; |
1626 | 1626 | $name = $args['name']; |
1627 | 1627 | $desc = $args['desc']; |
1628 | - if ( ! isset( $args['constant'] ) || ! defined( $args['constant'] ) ) { |
|
1629 | - $current_value = get_option( $name ); |
|
1628 | + if ( ! isset($args['constant']) || ! defined($args['constant'])) { |
|
1629 | + $current_value = get_option($name); |
|
1630 | 1630 | |
1631 | - echo sprintf( '<div class="select"><select id="%1$s" name="%2$s"><option value="">- ' . __( 'Select one', 'object-sync-for-salesforce' ) . ' -</option>', |
|
1632 | - esc_attr( $id ), |
|
1633 | - esc_attr( $name ) |
|
1631 | + echo sprintf('<div class="select"><select id="%1$s" name="%2$s"><option value="">- ' . __('Select one', 'object-sync-for-salesforce') . ' -</option>', |
|
1632 | + esc_attr($id), |
|
1633 | + esc_attr($name) |
|
1634 | 1634 | ); |
1635 | 1635 | |
1636 | - foreach ( $args['items'] as $key => $value ) { |
|
1636 | + foreach ($args['items'] as $key => $value) { |
|
1637 | 1637 | $text = $value['text']; |
1638 | 1638 | $value = $value['value']; |
1639 | 1639 | $selected = ''; |
1640 | - if ( $key === $current_value || $value === $current_value ) { |
|
1640 | + if ($key === $current_value || $value === $current_value) { |
|
1641 | 1641 | $selected = ' selected'; |
1642 | 1642 | } |
1643 | 1643 | |
1644 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
1645 | - esc_attr( $value ), |
|
1646 | - esc_attr( $selected ), |
|
1647 | - esc_html( $text ) |
|
1644 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
1645 | + esc_attr($value), |
|
1646 | + esc_attr($selected), |
|
1647 | + esc_html($text) |
|
1648 | 1648 | ); |
1649 | 1649 | |
1650 | 1650 | } |
1651 | 1651 | echo '</select>'; |
1652 | - if ( '' !== $desc ) { |
|
1653 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1654 | - esc_html( $desc ) |
|
1652 | + if ('' !== $desc) { |
|
1653 | + echo sprintf('<p class="description">%1$s</p>', |
|
1654 | + esc_html($desc) |
|
1655 | 1655 | ); |
1656 | 1656 | } |
1657 | 1657 | echo '</div>'; |
1658 | 1658 | } else { |
1659 | - echo sprintf( '<p><code>%1$s</code></p>', |
|
1660 | - esc_html__( 'Defined in wp-config.php', 'object-sync-for-salesforce' ) |
|
1659 | + echo sprintf('<p><code>%1$s</code></p>', |
|
1660 | + esc_html__('Defined in wp-config.php', 'object-sync-for-salesforce') |
|
1661 | 1661 | ); |
1662 | 1662 | } |
1663 | 1663 | } |
@@ -1670,7 +1670,7 @@ discard block |
||
1670 | 1670 | private function version_options() { |
1671 | 1671 | $versions = $this->salesforce['sfapi']->get_api_versions(); |
1672 | 1672 | $args = array(); |
1673 | - foreach ( $versions['data'] as $key => $value ) { |
|
1673 | + foreach ($versions['data'] as $key => $value) { |
|
1674 | 1674 | $args[] = array( |
1675 | 1675 | 'value' => $value['version'], |
1676 | 1676 | 'text' => $value['label'] . ' (' . $value['version'] . ')', |
@@ -1684,26 +1684,26 @@ discard block |
||
1684 | 1684 | * |
1685 | 1685 | * @param array $args |
1686 | 1686 | */ |
1687 | - public function display_link( $args ) { |
|
1687 | + public function display_link($args) { |
|
1688 | 1688 | $label = $args['label']; |
1689 | 1689 | $desc = $args['desc']; |
1690 | 1690 | $url = $args['url']; |
1691 | - if ( isset( $args['link_class'] ) ) { |
|
1692 | - echo sprintf( '<p><a class="%1$s" href="%2$s">%3$s</a></p>', |
|
1693 | - esc_attr( $args['link_class'] ), |
|
1694 | - esc_url( $url ), |
|
1695 | - esc_html( $label ) |
|
1691 | + if (isset($args['link_class'])) { |
|
1692 | + echo sprintf('<p><a class="%1$s" href="%2$s">%3$s</a></p>', |
|
1693 | + esc_attr($args['link_class']), |
|
1694 | + esc_url($url), |
|
1695 | + esc_html($label) |
|
1696 | 1696 | ); |
1697 | 1697 | } else { |
1698 | - echo sprintf( '<p><a href="%1$s">%2$s</a></p>', |
|
1699 | - esc_url( $url ), |
|
1700 | - esc_html( $label ) |
|
1698 | + echo sprintf('<p><a href="%1$s">%2$s</a></p>', |
|
1699 | + esc_url($url), |
|
1700 | + esc_html($label) |
|
1701 | 1701 | ); |
1702 | 1702 | } |
1703 | 1703 | |
1704 | - if ( '' !== $desc ) { |
|
1705 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1706 | - esc_html( $desc ) |
|
1704 | + if ('' !== $desc) { |
|
1705 | + echo sprintf('<p class="description">%1$s</p>', |
|
1706 | + esc_html($desc) |
|
1707 | 1707 | ); |
1708 | 1708 | } |
1709 | 1709 | |
@@ -1715,15 +1715,15 @@ discard block |
||
1715 | 1715 | * @param string $option |
1716 | 1716 | * @return string $option |
1717 | 1717 | */ |
1718 | - public function sanitize_validate_text( $option ) { |
|
1719 | - if ( is_array( $option ) ) { |
|
1718 | + public function sanitize_validate_text($option) { |
|
1719 | + if (is_array($option)) { |
|
1720 | 1720 | $options = array(); |
1721 | - foreach ( $option as $key => $value ) { |
|
1722 | - $options[ $key ] = sanitize_text_field( $value ); |
|
1721 | + foreach ($option as $key => $value) { |
|
1722 | + $options[$key] = sanitize_text_field($value); |
|
1723 | 1723 | } |
1724 | 1724 | return $options; |
1725 | 1725 | } |
1726 | - $option = sanitize_text_field( $option ); |
|
1726 | + $option = sanitize_text_field($option); |
|
1727 | 1727 | return $option; |
1728 | 1728 | } |
1729 | 1729 | |
@@ -1732,60 +1732,60 @@ discard block |
||
1732 | 1732 | * |
1733 | 1733 | * @param object $sfapi |
1734 | 1734 | */ |
1735 | - private function status( $sfapi ) { |
|
1735 | + private function status($sfapi) { |
|
1736 | 1736 | |
1737 | 1737 | $versions = $sfapi->get_api_versions(); |
1738 | 1738 | |
1739 | 1739 | // format this array into text so users can see the versions |
1740 | - if ( true === $versions['cached'] ) { |
|
1741 | - $versions_is_cached = esc_html__( 'This list is cached, and', 'object-sync-salesforce' ); |
|
1740 | + if (true === $versions['cached']) { |
|
1741 | + $versions_is_cached = esc_html__('This list is cached, and', 'object-sync-salesforce'); |
|
1742 | 1742 | } else { |
1743 | - $versions_is_cached = esc_html__( 'This list is not cached, but', 'object-sync-salesforce' ); |
|
1743 | + $versions_is_cached = esc_html__('This list is not cached, but', 'object-sync-salesforce'); |
|
1744 | 1744 | } |
1745 | 1745 | |
1746 | - if ( true === $versions['from_cache'] ) { |
|
1747 | - $versions_from_cache = esc_html__( 'items were loaded from the cache', 'object-sync-salesforce' ); |
|
1746 | + if (true === $versions['from_cache']) { |
|
1747 | + $versions_from_cache = esc_html__('items were loaded from the cache', 'object-sync-salesforce'); |
|
1748 | 1748 | } else { |
1749 | - $versions_from_cache = esc_html__( 'items were not loaded from the cache', 'object-sync-salesforce' ); |
|
1749 | + $versions_from_cache = esc_html__('items were not loaded from the cache', 'object-sync-salesforce'); |
|
1750 | 1750 | } |
1751 | 1751 | |
1752 | 1752 | // translators: 1) $versions_is_cached is the "This list is/is not cached, and/but" line, 2) $versions_from_cache is the "items were/were not loaded from the cache" line |
1753 | - $versions_apicall_summary = sprintf( esc_html__( 'Available Salesforce API versions. %1$s %2$s. This is not an authenticated request, so it does not touch the Salesforce token.', 'object-sync-for-salesforce' ), |
|
1753 | + $versions_apicall_summary = sprintf(esc_html__('Available Salesforce API versions. %1$s %2$s. This is not an authenticated request, so it does not touch the Salesforce token.', 'object-sync-for-salesforce'), |
|
1754 | 1754 | $versions_is_cached, |
1755 | 1755 | $versions_from_cache |
1756 | 1756 | ); |
1757 | 1757 | |
1758 | - $contacts = $sfapi->query( 'SELECT Name, Id from Contact LIMIT 100' ); |
|
1758 | + $contacts = $sfapi->query('SELECT Name, Id from Contact LIMIT 100'); |
|
1759 | 1759 | |
1760 | 1760 | // format this array into html so users can see the contacts |
1761 | - if ( true === $contacts['cached'] ) { |
|
1762 | - $contacts_is_cached = esc_html__( 'They are cached, and', 'object-sync-salesforce' ); |
|
1761 | + if (true === $contacts['cached']) { |
|
1762 | + $contacts_is_cached = esc_html__('They are cached, and', 'object-sync-salesforce'); |
|
1763 | 1763 | } else { |
1764 | - $contacts_is_cached = esc_html__( 'They are not cached, but', 'object-sync-salesforce' ); |
|
1764 | + $contacts_is_cached = esc_html__('They are not cached, but', 'object-sync-salesforce'); |
|
1765 | 1765 | } |
1766 | 1766 | |
1767 | - if ( true === $contacts['from_cache'] ) { |
|
1768 | - $contacts_from_cache = esc_html__( 'they were loaded from the cache', 'object-sync-salesforce' ); |
|
1767 | + if (true === $contacts['from_cache']) { |
|
1768 | + $contacts_from_cache = esc_html__('they were loaded from the cache', 'object-sync-salesforce'); |
|
1769 | 1769 | } else { |
1770 | - $contacts_from_cache = esc_html__( 'they were not loaded from the cache', 'object-sync-salesforce' ); |
|
1770 | + $contacts_from_cache = esc_html__('they were not loaded from the cache', 'object-sync-salesforce'); |
|
1771 | 1771 | } |
1772 | 1772 | |
1773 | - if ( true === $contacts['is_redo'] ) { |
|
1774 | - $contacts_refreshed_token = esc_html__( 'This request did require refreshing the Salesforce token', 'object-sync-salesforce' ); |
|
1773 | + if (true === $contacts['is_redo']) { |
|
1774 | + $contacts_refreshed_token = esc_html__('This request did require refreshing the Salesforce token', 'object-sync-salesforce'); |
|
1775 | 1775 | } else { |
1776 | - $contacts_refreshed_token = esc_html__( 'This request did not require refreshing the Salesforce token', 'object-sync-salesforce' ); |
|
1776 | + $contacts_refreshed_token = esc_html__('This request did not require refreshing the Salesforce token', 'object-sync-salesforce'); |
|
1777 | 1777 | } |
1778 | 1778 | |
1779 | 1779 | // translators: 1) $contacts['data']['totalSize'] is the number of items loaded, 2) $contacts['data']['records'][0]['attributes']['type'] is the name of the Salesforce object, 3) $contacts_is_cached is the "They are/are not cached, and/but" line, 4) $contacts_from_cache is the "they were/were not loaded from the cache" line, 5) is the "this request did/did not require refreshing the Salesforce token" line |
1780 | - $contacts_apicall_summary = sprintf( esc_html__( 'Salesforce successfully returned %1$s %2$s records. %3$s %4$s. %5$s.', 'object-sync-for-salesforce' ), |
|
1781 | - absint( $contacts['data']['totalSize'] ), |
|
1782 | - esc_html( $contacts['data']['records'][0]['attributes']['type'] ), |
|
1780 | + $contacts_apicall_summary = sprintf(esc_html__('Salesforce successfully returned %1$s %2$s records. %3$s %4$s. %5$s.', 'object-sync-for-salesforce'), |
|
1781 | + absint($contacts['data']['totalSize']), |
|
1782 | + esc_html($contacts['data']['records'][0]['attributes']['type']), |
|
1783 | 1783 | $contacts_is_cached, |
1784 | 1784 | $contacts_from_cache, |
1785 | 1785 | $contacts_refreshed_token |
1786 | 1786 | ); |
1787 | 1787 | |
1788 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/status.php' ); |
|
1788 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/status.php'); |
|
1789 | 1789 | |
1790 | 1790 | } |
1791 | 1791 | |
@@ -1795,12 +1795,12 @@ discard block |
||
1795 | 1795 | * For this plugin at this time, that is the decision we are making: don't do any kind of authorization stuff inside Salesforce |
1796 | 1796 | */ |
1797 | 1797 | private function logout() { |
1798 | - $this->access_token = delete_option( $this->option_prefix . 'access_token' ); |
|
1799 | - $this->instance_url = delete_option( $this->option_prefix . 'instance_url' ); |
|
1800 | - $this->refresh_token = delete_option( $this->option_prefix . 'refresh_token' ); |
|
1801 | - echo sprintf( '<p>You have been logged out. You can use the <a href="%1$s">%2$s</a> tab to log in again.</p>', |
|
1802 | - esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize' ) ), |
|
1803 | - esc_html__( 'Authorize', 'object-sync-for-salesforce' ) |
|
1798 | + $this->access_token = delete_option($this->option_prefix . 'access_token'); |
|
1799 | + $this->instance_url = delete_option($this->option_prefix . 'instance_url'); |
|
1800 | + $this->refresh_token = delete_option($this->option_prefix . 'refresh_token'); |
|
1801 | + echo sprintf('<p>You have been logged out. You can use the <a href="%1$s">%2$s</a> tab to log in again.</p>', |
|
1802 | + esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize')), |
|
1803 | + esc_html__('Authorize', 'object-sync-for-salesforce') |
|
1804 | 1804 | ); |
1805 | 1805 | } |
1806 | 1806 | |
@@ -1808,28 +1808,28 @@ discard block |
||
1808 | 1808 | * Ajax call to clear the plugin cache. |
1809 | 1809 | */ |
1810 | 1810 | public function clear_sfwp_cache() { |
1811 | - $result = $this->clear_cache( true ); |
|
1811 | + $result = $this->clear_cache(true); |
|
1812 | 1812 | $response = array( |
1813 | 1813 | 'message' => $result['message'], |
1814 | 1814 | 'success' => $result['success'], |
1815 | 1815 | ); |
1816 | - wp_send_json_success( $response ); |
|
1816 | + wp_send_json_success($response); |
|
1817 | 1817 | } |
1818 | 1818 | |
1819 | 1819 | /** |
1820 | 1820 | * Clear the plugin's cache. |
1821 | 1821 | * This uses the flush method contained in the WordPress cache to clear all of this plugin's cached data. |
1822 | 1822 | */ |
1823 | - private function clear_cache( $ajax = false ) { |
|
1823 | + private function clear_cache($ajax = false) { |
|
1824 | 1824 | $result = (bool) $this->wordpress->sfwp_transients->flush(); |
1825 | - if ( true === $result ) { |
|
1826 | - $message = __( 'The plugin cache has been cleared.', 'object-sync-for-salesforce' ); |
|
1825 | + if (true === $result) { |
|
1826 | + $message = __('The plugin cache has been cleared.', 'object-sync-for-salesforce'); |
|
1827 | 1827 | } else { |
1828 | - $message = __( 'There was an error clearing the plugin cache. Try refreshing this page.', 'object-sync-for-salesforce' ); |
|
1828 | + $message = __('There was an error clearing the plugin cache. Try refreshing this page.', 'object-sync-for-salesforce'); |
|
1829 | 1829 | } |
1830 | - if ( false === $ajax ) { |
|
1830 | + if (false === $ajax) { |
|
1831 | 1831 | // translators: parameter 1 is the result message |
1832 | - echo sprintf( '<p>%1$s</p>', $message ); |
|
1832 | + echo sprintf('<p>%1$s</p>', $message); |
|
1833 | 1833 | } else { |
1834 | 1834 | return array( |
1835 | 1835 | 'message' => $message, |
@@ -1852,7 +1852,7 @@ discard block |
||
1852 | 1852 | // alternatively, other roles can get this capability in whatever other way you like |
1853 | 1853 | // point is: to administer this plugin, you need this capability |
1854 | 1854 | |
1855 | - if ( ! current_user_can( 'configure_salesforce' ) ) { |
|
1855 | + if ( ! current_user_can('configure_salesforce')) { |
|
1856 | 1856 | return false; |
1857 | 1857 | } else { |
1858 | 1858 | return true; |
@@ -1865,23 +1865,23 @@ discard block |
||
1865 | 1865 | * @param object $user |
1866 | 1866 | * |
1867 | 1867 | */ |
1868 | - public function show_salesforce_user_fields( $user ) { |
|
1869 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
1870 | - if ( true === $this->check_wordpress_admin_permissions() ) { |
|
1871 | - $mapping = $this->mappings->load_by_wordpress( 'user', $user->ID ); |
|
1868 | + public function show_salesforce_user_fields($user) { |
|
1869 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
1870 | + if (true === $this->check_wordpress_admin_permissions()) { |
|
1871 | + $mapping = $this->mappings->load_by_wordpress('user', $user->ID); |
|
1872 | 1872 | $fieldmap = $this->mappings->get_fieldmaps( |
1873 | 1873 | null, // id field must be null for multiples |
1874 | 1874 | array( |
1875 | 1875 | 'wordpress_object' => 'user', |
1876 | 1876 | ) |
1877 | 1877 | ); |
1878 | - if ( isset( $mapping['id'] ) && ! isset( $get_data['edit_salesforce_mapping'] ) ) { |
|
1879 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce.php' ); |
|
1880 | - } elseif ( ! empty( $fieldmap ) ) { // is the user mapped to something already? |
|
1881 | - if ( isset( $get_data['edit_salesforce_mapping'] ) && 'true' === sanitize_key( $get_data['edit_salesforce_mapping'] ) ) { |
|
1882 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce-change.php' ); |
|
1878 | + if (isset($mapping['id']) && ! isset($get_data['edit_salesforce_mapping'])) { |
|
1879 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce.php'); |
|
1880 | + } elseif ( ! empty($fieldmap)) { // is the user mapped to something already? |
|
1881 | + if (isset($get_data['edit_salesforce_mapping']) && 'true' === sanitize_key($get_data['edit_salesforce_mapping'])) { |
|
1882 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce-change.php'); |
|
1883 | 1883 | } else { |
1884 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce-map.php' ); |
|
1884 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce-map.php'); |
|
1885 | 1885 | } |
1886 | 1886 | } |
1887 | 1887 | } |
@@ -1892,10 +1892,10 @@ discard block |
||
1892 | 1892 | * @param int $user_id |
1893 | 1893 | * |
1894 | 1894 | */ |
1895 | - public function save_salesforce_user_fields( $user_id ) { |
|
1896 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1897 | - if ( isset( $post_data['salesforce_update_mapped_user'] ) && '1' === rawurlencode( $post_data['salesforce_update_mapped_user'] ) ) { |
|
1898 | - $mapping_object = $this->mappings->get_object_maps( |
|
1895 | + public function save_salesforce_user_fields($user_id) { |
|
1896 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1897 | + if (isset($post_data['salesforce_update_mapped_user']) && '1' === rawurlencode($post_data['salesforce_update_mapped_user'])) { |
|
1898 | + $mapping_object = $this->mappings->get_object_maps( |
|
1899 | 1899 | array( |
1900 | 1900 | 'wordpress_id' => $user_id, |
1901 | 1901 | 'wordpress_object' => 'user', |
@@ -1903,14 +1903,14 @@ discard block |
||
1903 | 1903 | ); |
1904 | 1904 | $mapping_object['salesforce_id'] = $post_data['salesforce_id']; |
1905 | 1905 | |
1906 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1907 | - } elseif ( isset( $post_data['salesforce_create_mapped_user'] ) && '1' === rawurlencode( $post_data['salesforce_create_mapped_user'] ) ) { |
|
1906 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1907 | + } elseif (isset($post_data['salesforce_create_mapped_user']) && '1' === rawurlencode($post_data['salesforce_create_mapped_user'])) { |
|
1908 | 1908 | // if a Salesforce ID was entered |
1909 | - if ( isset( $post_data['salesforce_id'] ) && ! empty( $post_data['salesforce_id'] ) ) { |
|
1910 | - $mapping_object = $this->create_object_map( $user_id, 'user', $post_data['salesforce_id'] ); |
|
1911 | - } elseif ( isset( $post_data['push_new_user_to_salesforce'] ) ) { |
|
1909 | + if (isset($post_data['salesforce_id']) && ! empty($post_data['salesforce_id'])) { |
|
1910 | + $mapping_object = $this->create_object_map($user_id, 'user', $post_data['salesforce_id']); |
|
1911 | + } elseif (isset($post_data['push_new_user_to_salesforce'])) { |
|
1912 | 1912 | // otherwise, create a new record in Salesforce |
1913 | - $result = $this->push_to_salesforce( 'user', $user_id ); |
|
1913 | + $result = $this->push_to_salesforce('user', $user_id); |
|
1914 | 1914 | } |
1915 | 1915 | } |
1916 | 1916 | } |
@@ -1920,29 +1920,29 @@ discard block |
||
1920 | 1920 | * @param array $tabs |
1921 | 1921 | * @param string $tab |
1922 | 1922 | */ |
1923 | - private function tabs( $tabs, $tab = '' ) { |
|
1923 | + private function tabs($tabs, $tab = '') { |
|
1924 | 1924 | |
1925 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
1925 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
1926 | 1926 | $consumer_key = $this->login_credentials['consumer_key']; |
1927 | 1927 | $consumer_secret = $this->login_credentials['consumer_secret']; |
1928 | 1928 | $callback_url = $this->login_credentials['callback_url']; |
1929 | 1929 | |
1930 | 1930 | $current_tab = $tab; |
1931 | 1931 | echo '<h2 class="nav-tab-wrapper">'; |
1932 | - foreach ( $tabs as $tab_key => $tab_caption ) { |
|
1932 | + foreach ($tabs as $tab_key => $tab_caption) { |
|
1933 | 1933 | $active = $current_tab === $tab_key ? ' nav-tab-active' : ''; |
1934 | - if ( 'settings' === $tab_key || ( isset( $consumer_key ) && isset( $consumer_secret ) && ! empty( $consumer_key ) && ! empty( $consumer_secret ) ) ) { |
|
1935 | - echo sprintf( '<a class="nav-tab%1$s" href="%2$s">%3$s</a>', |
|
1936 | - esc_attr( $active ), |
|
1937 | - esc_url( '?page=object-sync-salesforce-admin&tab=' . $tab_key ), |
|
1938 | - esc_html( $tab_caption ) |
|
1934 | + if ('settings' === $tab_key || (isset($consumer_key) && isset($consumer_secret) && ! empty($consumer_key) && ! empty($consumer_secret))) { |
|
1935 | + echo sprintf('<a class="nav-tab%1$s" href="%2$s">%3$s</a>', |
|
1936 | + esc_attr($active), |
|
1937 | + esc_url('?page=object-sync-salesforce-admin&tab=' . $tab_key), |
|
1938 | + esc_html($tab_caption) |
|
1939 | 1939 | ); |
1940 | 1940 | } |
1941 | 1941 | } |
1942 | 1942 | echo '</h2>'; |
1943 | 1943 | |
1944 | - if ( isset( $get_data['tab'] ) ) { |
|
1945 | - $tab = sanitize_key( $get_data['tab'] ); |
|
1944 | + if (isset($get_data['tab'])) { |
|
1945 | + $tab = sanitize_key($get_data['tab']); |
|
1946 | 1946 | } else { |
1947 | 1947 | $tab = ''; |
1948 | 1948 | } |
@@ -1952,21 +1952,21 @@ discard block |
||
1952 | 1952 | * Clear schedule |
1953 | 1953 | * This clears the schedule if the user clicks the button |
1954 | 1954 | */ |
1955 | - private function clear_schedule( $schedule_name = '' ) { |
|
1956 | - if ( '' !== $schedule_name ) { |
|
1957 | - $schedule = $this->schedule( $schedule_name ); |
|
1958 | - $schedule->cancel_by_name( $schedule_name ); |
|
1955 | + private function clear_schedule($schedule_name = '') { |
|
1956 | + if ('' !== $schedule_name) { |
|
1957 | + $schedule = $this->schedule($schedule_name); |
|
1958 | + $schedule->cancel_by_name($schedule_name); |
|
1959 | 1959 | // translators: $schedule_name is the name of the current queue. Defaults: salesforce_pull, salesforce_push, salesforce |
1960 | - echo sprintf( esc_html__( 'You have cleared the %s schedule.', 'object-sync-for-salesforce' ), esc_html( $schedule_name ) ); |
|
1960 | + echo sprintf(esc_html__('You have cleared the %s schedule.', 'object-sync-for-salesforce'), esc_html($schedule_name)); |
|
1961 | 1961 | } else { |
1962 | - echo esc_html__( 'You need to specify the name of the schedule you want to clear.', 'object-sync-for-salesforce' ); |
|
1962 | + echo esc_html__('You need to specify the name of the schedule you want to clear.', 'object-sync-for-salesforce'); |
|
1963 | 1963 | } |
1964 | 1964 | } |
1965 | 1965 | |
1966 | - private function get_schedule_count( $schedule_name = '' ) { |
|
1967 | - if ( '' !== $schedule_name ) { |
|
1968 | - $schedule = $this->schedule( $schedule_name ); |
|
1969 | - return $this->schedule->count_queue_items( $schedule_name ); |
|
1966 | + private function get_schedule_count($schedule_name = '') { |
|
1967 | + if ('' !== $schedule_name) { |
|
1968 | + $schedule = $this->schedule($schedule_name); |
|
1969 | + return $this->schedule->count_queue_items($schedule_name); |
|
1970 | 1970 | } else { |
1971 | 1971 | return 'unknown'; |
1972 | 1972 | } |
@@ -1975,12 +1975,12 @@ discard block |
||
1975 | 1975 | /** |
1976 | 1976 | * Load the schedule class |
1977 | 1977 | */ |
1978 | - private function schedule( $schedule_name ) { |
|
1979 | - if ( ! class_exists( 'Object_Sync_Sf_Schedule' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) { |
|
1980 | - require_once plugin_dir_path( __FILE__ ) . '../vendor/autoload.php'; |
|
1981 | - require_once plugin_dir_path( __FILE__ ) . '../classes/schedule.php'; |
|
1978 | + private function schedule($schedule_name) { |
|
1979 | + if ( ! class_exists('Object_Sync_Sf_Schedule') && file_exists(plugin_dir_path(__FILE__) . '../vendor/autoload.php')) { |
|
1980 | + require_once plugin_dir_path(__FILE__) . '../vendor/autoload.php'; |
|
1981 | + require_once plugin_dir_path(__FILE__) . '../classes/schedule.php'; |
|
1982 | 1982 | } |
1983 | - $schedule = new Object_Sync_Sf_Schedule( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $schedule_name, $this->logging, $this->schedulable_classes ); |
|
1983 | + $schedule = new Object_Sync_Sf_Schedule($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $schedule_name, $this->logging, $this->schedulable_classes); |
|
1984 | 1984 | $this->schedule = $schedule; |
1985 | 1985 | return $schedule; |
1986 | 1986 | } |
@@ -2001,17 +2001,17 @@ discard block |
||
2001 | 2001 | * This is the database row for the map object |
2002 | 2002 | * |
2003 | 2003 | */ |
2004 | - private function create_object_map( $wordpress_id, $wordpress_object, $salesforce_id, $action = '' ) { |
|
2004 | + private function create_object_map($wordpress_id, $wordpress_object, $salesforce_id, $action = '') { |
|
2005 | 2005 | // Create object map and save it |
2006 | 2006 | $mapping_object = $this->mappings->create_object_map( |
2007 | 2007 | array( |
2008 | 2008 | 'wordpress_id' => $wordpress_id, // wordpress unique id |
2009 | 2009 | 'salesforce_id' => $salesforce_id, // salesforce unique id. we don't care what kind of object it is at this point |
2010 | 2010 | 'wordpress_object' => $wordpress_object, // keep track of what kind of wp object this is |
2011 | - 'last_sync' => current_time( 'mysql' ), |
|
2011 | + 'last_sync' => current_time('mysql'), |
|
2012 | 2012 | 'last_sync_action' => $action, |
2013 | 2013 | 'last_sync_status' => $this->mappings->status_success, |
2014 | - 'last_sync_message' => __( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
2014 | + 'last_sync_message' => __('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
2015 | 2015 | ) |
2016 | 2016 | ); |
2017 | 2017 |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | private $installed_version; |
22 | 22 | |
23 | 23 | /** |
24 | - * Constructor which sets up activate hooks |
|
25 | - * |
|
26 | - * @param object $wpdb |
|
27 | - * @param string $version |
|
28 | - * @param string $slug |
|
29 | - * |
|
30 | - */ |
|
24 | + * Constructor which sets up activate hooks |
|
25 | + * |
|
26 | + * @param object $wpdb |
|
27 | + * @param string $version |
|
28 | + * @param string $slug |
|
29 | + * |
|
30 | + */ |
|
31 | 31 | public function __construct( $wpdb, $version, $slug ) { |
32 | 32 | $this->wpdb = $wpdb; |
33 | 33 | $this->version = $version; |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Activation hooks |
|
43 | - */ |
|
42 | + * Activation hooks |
|
43 | + */ |
|
44 | 44 | private function add_actions() { |
45 | 45 | |
46 | 46 | // on initial activation, run these hooks |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | - * Check for the minimum required version of php |
|
57 | - */ |
|
56 | + * Check for the minimum required version of php |
|
57 | + */ |
|
58 | 58 | public function php_requirements() { |
59 | 59 | if ( version_compare( PHP_VERSION, '5.5', '<' ) ) { |
60 | 60 | deactivate_plugins( plugin_basename( __FILE__ ) ); |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | - * Create database tables for Salesforce |
|
67 | - * This creates tables for fieldmaps (between types of objects) and object maps (between indidual instances of objects) |
|
68 | - * |
|
69 | - */ |
|
66 | + * Create database tables for Salesforce |
|
67 | + * This creates tables for fieldmaps (between types of objects) and object maps (between indidual instances of objects) |
|
68 | + * |
|
69 | + */ |
|
70 | 70 | public function wordpress_salesforce_tables() { |
71 | 71 | |
72 | 72 | $charset_collate = $this->wpdb->get_charset_collate(); |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | - * Add roles and capabilities |
|
131 | - * This adds the configure_salesforce capability to the admin role |
|
132 | - * |
|
133 | - * It also allows other plugins to add the capability to other roles |
|
134 | - * |
|
135 | - */ |
|
130 | + * Add roles and capabilities |
|
131 | + * This adds the configure_salesforce capability to the admin role |
|
132 | + * |
|
133 | + * It also allows other plugins to add the capability to other roles |
|
134 | + * |
|
135 | + */ |
|
136 | 136 | public function add_roles_capabilities() { |
137 | 137 | |
138 | 138 | // by default, only administrators can configure the plugin |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | - * Check for database version on plugin upgrade |
|
157 | - * When the plugin is upgraded, if the database version does not match the current version, perform these methods |
|
158 | - * |
|
159 | - * @param object $upgrader_object |
|
160 | - * @param array $hook_extra |
|
161 | - * |
|
162 | - * See https://developer.wordpress.org/reference/hooks/upgrader_process_complete/ |
|
163 | - * |
|
164 | - */ |
|
156 | + * Check for database version on plugin upgrade |
|
157 | + * When the plugin is upgraded, if the database version does not match the current version, perform these methods |
|
158 | + * |
|
159 | + * @param object $upgrader_object |
|
160 | + * @param array $hook_extra |
|
161 | + * |
|
162 | + * See https://developer.wordpress.org/reference/hooks/upgrader_process_complete/ |
|
163 | + * |
|
164 | + */ |
|
165 | 165 | public function wordpress_salesforce_update_db_check( $upgrader_object, $hook_extra ) { |
166 | 166 | if ( get_site_option( 'object_sync_for_salesforce_db_version' ) !== $this->version ) { |
167 | 167 | $this->wordpress_salesforce_tables(); |
@@ -5,7 +5,7 @@ discard block |
||
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 |
||
28 | 28 | * @param string $slug |
29 | 29 | * |
30 | 30 | */ |
31 | - public function __construct( $wpdb, $version, $slug ) { |
|
31 | + public function __construct($wpdb, $version, $slug) { |
|
32 | 32 | $this->wpdb = $wpdb; |
33 | 33 | $this->version = $version; |
34 | 34 | $this->slug = $slug; |
35 | 35 | |
36 | - $this->installed_version = get_option( 'object_sync_for_salesforce_db_version', '' ); |
|
36 | + $this->installed_version = get_option('object_sync_for_salesforce_db_version', ''); |
|
37 | 37 | |
38 | 38 | $this->add_actions(); |
39 | 39 | } |
@@ -44,21 +44,21 @@ discard block |
||
44 | 44 | private function add_actions() { |
45 | 45 | |
46 | 46 | // on initial activation, run these hooks |
47 | - register_activation_hook( dirname( __DIR__ ) . '/' . $this->slug . '.php', array( $this, 'php_requirements' ) ); |
|
48 | - register_activation_hook( dirname( __DIR__ ) . '/' . $this->slug . '.php', array( $this, 'wordpress_salesforce_tables' ) ); |
|
49 | - register_activation_hook( dirname( __DIR__ ) . '/' . $this->slug . '.php', array( $this, 'add_roles_capabilities' ) ); |
|
47 | + register_activation_hook(dirname(__DIR__) . '/' . $this->slug . '.php', array($this, 'php_requirements')); |
|
48 | + register_activation_hook(dirname(__DIR__) . '/' . $this->slug . '.php', array($this, 'wordpress_salesforce_tables')); |
|
49 | + register_activation_hook(dirname(__DIR__) . '/' . $this->slug . '.php', array($this, 'add_roles_capabilities')); |
|
50 | 50 | |
51 | 51 | // when users upgrade the plugin, run these hooks |
52 | - add_action( 'upgrader_process_complete', array( $this, 'wordpress_salesforce_update_db_check' ), 10, 2 ); |
|
52 | + add_action('upgrader_process_complete', array($this, 'wordpress_salesforce_update_db_check'), 10, 2); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Check for the minimum required version of php |
57 | 57 | */ |
58 | 58 | public function php_requirements() { |
59 | - if ( version_compare( PHP_VERSION, '5.5', '<' ) ) { |
|
60 | - deactivate_plugins( plugin_basename( __FILE__ ) ); |
|
61 | - wp_die( '<strong>This plugin requires PHP Version 5.5</strong> <br />Please contact your host to upgrade PHP on your server, and then retry activating the plugin.' ); |
|
59 | + if (version_compare(PHP_VERSION, '5.5', '<')) { |
|
60 | + deactivate_plugins(plugin_basename(__FILE__)); |
|
61 | + wp_die('<strong>This plugin requires PHP Version 5.5</strong> <br />Please contact your host to upgrade PHP on your server, and then retry activating the plugin.'); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -111,18 +111,18 @@ discard block |
||
111 | 111 | KEY salesforce_object (salesforce_id) |
112 | 112 | ) $charset_collate"; |
113 | 113 | |
114 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
114 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
115 | 115 | |
116 | 116 | // Note: see https://wordpress.stackexchange.com/questions/67345/how-to-implement-wordpress-plugin-update-that-modifies-the-database |
117 | 117 | // When we run the dbDelta method below, "it checks if the table exists. What's more, it checks the column types. So if the table doesn't exist, it creates it, if it does, but some column types have changed it updates them, and if a column doesn't exists - it adds it." |
118 | 118 | // This does not remove columns if we remove columns, so we'll need to expand beyond this in the future if that happens, although I think the schema is pretty solid now. |
119 | - dbDelta( $field_map_sql ); |
|
120 | - dbDelta( $object_map_sql ); |
|
119 | + dbDelta($field_map_sql); |
|
120 | + dbDelta($object_map_sql); |
|
121 | 121 | |
122 | - update_option( 'object_sync_for_salesforce_db_version', $this->version ); |
|
122 | + update_option('object_sync_for_salesforce_db_version', $this->version); |
|
123 | 123 | |
124 | 124 | // store right now as the time for the plugin's activation |
125 | - update_option( 'object_sync_for_salesforce_activate_time', current_time( 'timestamp', true ) ); |
|
125 | + update_option('object_sync_for_salesforce_activate_time', current_time('timestamp', true)); |
|
126 | 126 | |
127 | 127 | } |
128 | 128 | |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | public function add_roles_capabilities() { |
137 | 137 | |
138 | 138 | // by default, only administrators can configure the plugin |
139 | - $role = get_role( 'administrator' ); |
|
140 | - $role->add_cap( 'configure_salesforce' ); |
|
139 | + $role = get_role('administrator'); |
|
140 | + $role->add_cap('configure_salesforce'); |
|
141 | 141 | |
142 | 142 | // hook that allows other roles to configure the plugin as well |
143 | - $roles = apply_filters( 'object_sync_for_salesforce_roles_configure_salesforce', null ); |
|
143 | + $roles = apply_filters('object_sync_for_salesforce_roles_configure_salesforce', null); |
|
144 | 144 | |
145 | 145 | // for each role that we have, give it the configure salesforce capability |
146 | - if ( null !== $roles ) { |
|
147 | - foreach ( $roles as $role ) { |
|
148 | - $role = get_role( $role ); |
|
149 | - $role->add_cap( 'configure_salesforce' ); |
|
146 | + if (null !== $roles) { |
|
147 | + foreach ($roles as $role) { |
|
148 | + $role = get_role($role); |
|
149 | + $role->add_cap('configure_salesforce'); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * See https://developer.wordpress.org/reference/hooks/upgrader_process_complete/ |
163 | 163 | * |
164 | 164 | */ |
165 | - public function wordpress_salesforce_update_db_check( $upgrader_object, $hook_extra ) { |
|
166 | - if ( get_site_option( 'object_sync_for_salesforce_db_version' ) !== $this->version ) { |
|
165 | + public function wordpress_salesforce_update_db_check($upgrader_object, $hook_extra) { |
|
166 | + if (get_site_option('object_sync_for_salesforce_db_version') !== $this->version) { |
|
167 | 167 | $this->wordpress_salesforce_tables(); |
168 | 168 | } |
169 | 169 | } |
@@ -25,25 +25,25 @@ discard block |
||
25 | 25 | protected $queue; |
26 | 26 | |
27 | 27 | /** |
28 | - * @var string |
|
29 | - */ |
|
28 | + * @var string |
|
29 | + */ |
|
30 | 30 | public $schedule_name; // allow for naming the queue in case there are multiple queues |
31 | 31 | |
32 | 32 | /** |
33 | - * Constructor which sets up push schedule |
|
34 | - * |
|
35 | - * @param object $wpdb |
|
36 | - * @param string $version |
|
37 | - * @param array $login_credentials |
|
38 | - * @param string $slug |
|
39 | - * @param object $wordpress |
|
40 | - * @param object $salesforce |
|
41 | - * @param object $mappings |
|
42 | - * @param object $logging |
|
43 | - * @param array $schedulable_classes |
|
44 | - * @param object $queue |
|
45 | - * @throws \Object_Sync_Sf_Exception |
|
46 | - */ |
|
33 | + * Constructor which sets up push schedule |
|
34 | + * |
|
35 | + * @param object $wpdb |
|
36 | + * @param string $version |
|
37 | + * @param array $login_credentials |
|
38 | + * @param string $slug |
|
39 | + * @param object $wordpress |
|
40 | + * @param object $salesforce |
|
41 | + * @param object $mappings |
|
42 | + * @param object $logging |
|
43 | + * @param array $schedulable_classes |
|
44 | + * @param object $queue |
|
45 | + * @throws \Object_Sync_Sf_Exception |
|
46 | + */ |
|
47 | 47 | public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
48 | 48 | $this->wpdb = $wpdb; |
49 | 49 | $this->version = $version; |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | - * Create the action hooks based on what object maps exist from the admin settings. |
|
70 | - * We do not have any actions for blogroll at this time. |
|
71 | - * |
|
72 | - */ |
|
69 | + * Create the action hooks based on what object maps exist from the admin settings. |
|
70 | + * We do not have any actions for blogroll at this time. |
|
71 | + * |
|
72 | + */ |
|
73 | 73 | public function add_actions() { |
74 | 74 | $db_version = get_option( 'object_sync_for_salesforce_db_version', false ); |
75 | 75 | if ( $db_version === $this->version ) { |
@@ -110,63 +110,63 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Method for ajax hooks to call for pushing manually |
|
114 | - * |
|
115 | - * @param array $object |
|
116 | - * @param string $type |
|
117 | - * |
|
118 | - */ |
|
113 | + * Method for ajax hooks to call for pushing manually |
|
114 | + * |
|
115 | + * @param array $object |
|
116 | + * @param string $type |
|
117 | + * |
|
118 | + */ |
|
119 | 119 | public function manual_object_update( $object, $type ) { |
120 | 120 | $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update, true ); |
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Callback method for adding a user |
|
125 | - * |
|
126 | - * @param string $user_id |
|
127 | - */ |
|
124 | + * Callback method for adding a user |
|
125 | + * |
|
126 | + * @param string $user_id |
|
127 | + */ |
|
128 | 128 | public function add_user( $user_id ) { |
129 | 129 | $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
130 | 130 | $this->object_insert( $user, 'user' ); |
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | - * Callback method for adding a user via the Ultimate Member plugin |
|
135 | - * |
|
136 | - * @param string $user_id |
|
137 | - */ |
|
134 | + * Callback method for adding a user via the Ultimate Member plugin |
|
135 | + * |
|
136 | + * @param string $user_id |
|
137 | + */ |
|
138 | 138 | public function um_add_user( $user_id, $form_data = array() ) { |
139 | 139 | $this->object_insert( $form_data, 'user' ); |
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | - * Callback method for editing a user |
|
144 | - * |
|
145 | - * @param string $user_id |
|
146 | - * @param object $old_user_data |
|
147 | - */ |
|
143 | + * Callback method for editing a user |
|
144 | + * |
|
145 | + * @param string $user_id |
|
146 | + * @param object $old_user_data |
|
147 | + */ |
|
148 | 148 | public function edit_user( $user_id, $old_user_data ) { |
149 | 149 | $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
150 | 150 | $this->object_update( $user, 'user' ); |
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
154 | - * Callback method for deleting a user |
|
155 | - * |
|
156 | - * @param string $user_id |
|
157 | - */ |
|
154 | + * Callback method for deleting a user |
|
155 | + * |
|
156 | + * @param string $user_id |
|
157 | + */ |
|
158 | 158 | public function delete_user( $user_id ) { |
159 | 159 | $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
160 | 160 | $this->object_delete( $user, 'user' ); |
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
164 | - * Callback method for posts of any type |
|
165 | - * This can handle create, update, and delete actions |
|
166 | - * |
|
167 | - * @param string $post_id |
|
168 | - * @param object $post |
|
169 | - */ |
|
164 | + * Callback method for posts of any type |
|
165 | + * This can handle create, update, and delete actions |
|
166 | + * |
|
167 | + * @param string $post_id |
|
168 | + * @param object $post |
|
169 | + */ |
|
170 | 170 | public function post_actions( $post_id, $post ) { |
171 | 171 | |
172 | 172 | $post_type = $post->post_type; |
@@ -213,66 +213,66 @@ discard block |
||
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
216 | - * Callback method for adding an attachment |
|
217 | - * |
|
218 | - * @param string $post_id |
|
219 | - */ |
|
216 | + * Callback method for adding an attachment |
|
217 | + * |
|
218 | + * @param string $post_id |
|
219 | + */ |
|
220 | 220 | public function add_attachment( $post_id ) { |
221 | 221 | $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
222 | 222 | $this->object_insert( $attachment, 'attachment' ); |
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
226 | - * Callback method for editing an attachment |
|
227 | - * |
|
228 | - * @param string $post_id |
|
229 | - */ |
|
226 | + * Callback method for editing an attachment |
|
227 | + * |
|
228 | + * @param string $post_id |
|
229 | + */ |
|
230 | 230 | public function edit_attachment( $post_id ) { |
231 | 231 | $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
232 | 232 | $this->object_update( $attachment, 'attachment' ); |
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
236 | - * Callback method for editing an attachment |
|
237 | - * |
|
238 | - * @param string $post_id |
|
239 | - */ |
|
236 | + * Callback method for editing an attachment |
|
237 | + * |
|
238 | + * @param string $post_id |
|
239 | + */ |
|
240 | 240 | public function delete_attachment( $post_id ) { |
241 | 241 | $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
242 | 242 | $this->object_delete( $attachment, 'attachment' ); |
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * Callback method for adding a term |
|
247 | - * |
|
248 | - * @param string $term_id |
|
249 | - * @param string $tt_id |
|
250 | - * @param string $taxonomy |
|
251 | - */ |
|
246 | + * Callback method for adding a term |
|
247 | + * |
|
248 | + * @param string $term_id |
|
249 | + * @param string $tt_id |
|
250 | + * @param string $taxonomy |
|
251 | + */ |
|
252 | 252 | public function add_term( $term_id, $tt_id, $taxonomy ) { |
253 | 253 | $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
254 | 254 | $this->object_insert( $term, $taxonomy ); |
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | - * Callback method for editing a term |
|
259 | - * |
|
260 | - * @param string $term_id |
|
261 | - * @param string $taxonomy |
|
262 | - */ |
|
258 | + * Callback method for editing a term |
|
259 | + * |
|
260 | + * @param string $term_id |
|
261 | + * @param string $taxonomy |
|
262 | + */ |
|
263 | 263 | public function edit_term( $term_id, $taxonomy ) { |
264 | 264 | $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
265 | 265 | $this->object_update( $term, $taxonomy ); |
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
269 | - * Callback method for deleting a term |
|
270 | - * |
|
271 | - * @param int $term (id) |
|
272 | - * @param int $term_taxonomy_id |
|
273 | - * @param string $taxonomy (slug) |
|
274 | - * @param object $deleted_term |
|
275 | - */ |
|
269 | + * Callback method for deleting a term |
|
270 | + * |
|
271 | + * @param int $term (id) |
|
272 | + * @param int $term_taxonomy_id |
|
273 | + * @param string $taxonomy (slug) |
|
274 | + * @param object $deleted_term |
|
275 | + */ |
|
276 | 276 | public function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) { |
277 | 277 | $deleted_term = (array) $deleted_term; |
278 | 278 | $type = $deleted_term['taxonomy']; |
@@ -280,75 +280,75 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
283 | - * Callback method for adding a comment |
|
284 | - * |
|
285 | - * @param string $comment_id |
|
286 | - * @param int|string comment_approved |
|
287 | - * @param array $commentdata |
|
288 | - */ |
|
283 | + * Callback method for adding a comment |
|
284 | + * |
|
285 | + * @param string $comment_id |
|
286 | + * @param int|string comment_approved |
|
287 | + * @param array $commentdata |
|
288 | + */ |
|
289 | 289 | public function add_comment( $comment_id, $comment_approved, $commentdata = array() ) { |
290 | 290 | $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
291 | 291 | $this->object_insert( $comment, 'comment' ); |
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
295 | - * Callback method for editing a comment |
|
296 | - * |
|
297 | - * @param string $comment_id |
|
298 | - */ |
|
295 | + * Callback method for editing a comment |
|
296 | + * |
|
297 | + * @param string $comment_id |
|
298 | + */ |
|
299 | 299 | public function edit_comment( $comment_id ) { |
300 | 300 | $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
301 | 301 | $this->object_update( $comment, 'comment' ); |
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | - * Callback method for deleting a comment |
|
306 | - * |
|
307 | - * @param string $comment_id |
|
308 | - */ |
|
305 | + * Callback method for deleting a comment |
|
306 | + * |
|
307 | + * @param string $comment_id |
|
308 | + */ |
|
309 | 309 | public function delete_comment( $comment_id ) { |
310 | 310 | $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
311 | 311 | $this->object_delete( $comment, 'comment' ); |
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
315 | - * Insert a new object |
|
316 | - * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
317 | - */ |
|
315 | + * Insert a new object |
|
316 | + * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
317 | + */ |
|
318 | 318 | private function object_insert( $object, $type ) { |
319 | 319 | $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_create ); |
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
323 | - * Update an existing object |
|
324 | - * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
325 | - */ |
|
323 | + * Update an existing object |
|
324 | + * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
325 | + */ |
|
326 | 326 | private function object_update( $object, $type ) { |
327 | 327 | $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update ); |
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
331 | - * Delete an existing object |
|
332 | - * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
333 | - */ |
|
331 | + * Delete an existing object |
|
332 | + * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
333 | + */ |
|
334 | 334 | private function object_delete( $object, $type ) { |
335 | 335 | $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_delete ); |
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
339 | - * Push objects to Salesforce. |
|
340 | - * 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) |
|
341 | - * |
|
342 | - * @param string $object_type |
|
343 | - * Type of WordPress object. |
|
344 | - * @param array $object |
|
345 | - * The WordPress data that needs to be sent to Salesforce. |
|
346 | - * @param int $sf_sync_trigger |
|
347 | - * The trigger being responded to. |
|
348 | - * @param bool $manual |
|
349 | - * Are we calling this manually? |
|
350 | - * |
|
351 | - */ |
|
339 | + * Push objects to Salesforce. |
|
340 | + * 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) |
|
341 | + * |
|
342 | + * @param string $object_type |
|
343 | + * Type of WordPress object. |
|
344 | + * @param array $object |
|
345 | + * The WordPress data that needs to be sent to Salesforce. |
|
346 | + * @param int $sf_sync_trigger |
|
347 | + * The trigger being responded to. |
|
348 | + * @param bool $manual |
|
349 | + * Are we calling this manually? |
|
350 | + * |
|
351 | + */ |
|
352 | 352 | private function salesforce_push_object_crud( $object_type, $object, $sf_sync_trigger, $manual = false ) { |
353 | 353 | |
354 | 354 | $structure = $this->wordpress->get_wordpress_table_structure( $object_type ); |
@@ -472,20 +472,20 @@ discard block |
||
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
475 | - * Sync WordPress objects and Salesforce objects using the REST API. |
|
476 | - * |
|
477 | - * @param string $object_type |
|
478 | - * Type of WordPress object. |
|
479 | - * @param array|int $object|$object_id |
|
480 | - * The WordPress object data or its ID. |
|
481 | - * @param array $mapping|$mapping_id |
|
482 | - * Salesforce field mapping data array or ID. |
|
483 | - * @param int $sf_sync_trigger |
|
484 | - * Trigger for this sync. |
|
485 | - * |
|
486 | - * @return true or exit the method |
|
487 | - * |
|
488 | - */ |
|
475 | + * Sync WordPress objects and Salesforce objects using the REST API. |
|
476 | + * |
|
477 | + * @param string $object_type |
|
478 | + * Type of WordPress object. |
|
479 | + * @param array|int $object|$object_id |
|
480 | + * The WordPress object data or its ID. |
|
481 | + * @param array $mapping|$mapping_id |
|
482 | + * Salesforce field mapping data array or ID. |
|
483 | + * @param int $sf_sync_trigger |
|
484 | + * Trigger for this sync. |
|
485 | + * |
|
486 | + * @return true or exit the method |
|
487 | + * |
|
488 | + */ |
|
489 | 489 | public function salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ) { |
490 | 490 | |
491 | 491 | if ( is_int( $object ) ) { |
@@ -1037,21 +1037,21 @@ discard block |
||
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | /** |
1040 | - * Create an object map between a WordPress object and a Salesforce object |
|
1041 | - * |
|
1042 | - * @param array $wordpress_object |
|
1043 | - * Array of the WordPress object's data |
|
1044 | - * @param string $id_field_name |
|
1045 | - * How this object names its primary field. ie Id or comment_id or whatever |
|
1046 | - * @param string $salesforce_id |
|
1047 | - * Unique identifier for the Salesforce object |
|
1048 | - * @param array $field_mapping |
|
1049 | - * The row that maps the object types together, including which fields match which other fields |
|
1050 | - * |
|
1051 | - * @return int $wpdb->insert_id |
|
1052 | - * This is the database row for the map object |
|
1053 | - * |
|
1054 | - */ |
|
1040 | + * Create an object map between a WordPress object and a Salesforce object |
|
1041 | + * |
|
1042 | + * @param array $wordpress_object |
|
1043 | + * Array of the WordPress object's data |
|
1044 | + * @param string $id_field_name |
|
1045 | + * How this object names its primary field. ie Id or comment_id or whatever |
|
1046 | + * @param string $salesforce_id |
|
1047 | + * Unique identifier for the Salesforce object |
|
1048 | + * @param array $field_mapping |
|
1049 | + * The row that maps the object types together, including which fields match which other fields |
|
1050 | + * |
|
1051 | + * @return int $wpdb->insert_id |
|
1052 | + * This is the database row for the map object |
|
1053 | + * |
|
1054 | + */ |
|
1055 | 1055 | private function create_object_map( $wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false ) { |
1056 | 1056 | |
1057 | 1057 | if ( true === $pending ) { |
@@ -5,7 +5,7 @@ discard block |
||
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 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param object $queue |
45 | 45 | * @throws \Object_Sync_Sf_Exception |
46 | 46 | */ |
47 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
|
47 | + public function __construct($wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue) { |
|
48 | 48 | $this->wpdb = $wpdb; |
49 | 49 | $this->version = $version; |
50 | 50 | $this->login_credentials = $login_credentials; |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | $this->schedule_name = 'salesforce_push'; |
60 | 60 | |
61 | 61 | // Create action hooks for WordPress objects. We run this after plugins are loaded in case something depends on another plugin. |
62 | - add_action( 'plugins_loaded', array( $this, 'add_actions' ) ); |
|
62 | + add_action('plugins_loaded', array($this, 'add_actions')); |
|
63 | 63 | |
64 | - $this->debug = get_option( 'object_sync_for_salesforce_debug_mode', false ); |
|
64 | + $this->debug = get_option('object_sync_for_salesforce_debug_mode', false); |
|
65 | 65 | |
66 | 66 | } |
67 | 67 | |
@@ -71,41 +71,41 @@ discard block |
||
71 | 71 | * |
72 | 72 | */ |
73 | 73 | public function add_actions() { |
74 | - $db_version = get_option( 'object_sync_for_salesforce_db_version', false ); |
|
75 | - if ( $db_version === $this->version ) { |
|
76 | - foreach ( $this->mappings->get_fieldmaps() as $mapping ) { |
|
74 | + $db_version = get_option('object_sync_for_salesforce_db_version', false); |
|
75 | + if ($db_version === $this->version) { |
|
76 | + foreach ($this->mappings->get_fieldmaps() as $mapping) { |
|
77 | 77 | $object_type = $mapping['wordpress_object']; |
78 | - if ( 'user' === $object_type ) { |
|
79 | - if ( defined( 'ultimatemember_plugin_name' ) ) { |
|
80 | - add_action( 'um_user_register', array( $this, 'um_add_user' ), 11, 2 ); |
|
78 | + if ('user' === $object_type) { |
|
79 | + if (defined('ultimatemember_plugin_name')) { |
|
80 | + add_action('um_user_register', array($this, 'um_add_user'), 11, 2); |
|
81 | 81 | } else { |
82 | - add_action( 'user_register', array( $this, 'add_user' ), 11, 1 ); |
|
82 | + add_action('user_register', array($this, 'add_user'), 11, 1); |
|
83 | 83 | } |
84 | - add_action( 'profile_update', array( $this, 'edit_user' ), 11, 2 ); |
|
85 | - add_action( 'delete_user', array( $this, 'delete_user' ) ); |
|
86 | - } elseif ( 'post' === $object_type ) { |
|
87 | - add_action( 'save_post', array( $this, 'post_actions' ), 11, 2 ); |
|
88 | - } elseif ( 'attachment' === $object_type ) { |
|
89 | - add_action( 'add_attachment', array( $this, 'add_attachment' ) ); |
|
90 | - add_action( 'edit_attachment', array( $this, 'edit_attachment' ) ); |
|
91 | - add_action( 'delete_attachment', array( $this, 'delete_attachment' ) ); |
|
92 | - } elseif ( 'category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type ) { |
|
93 | - add_action( 'create_term', array( $this, 'add_term' ), 11, 3 ); |
|
94 | - add_action( 'edit_terms', array( $this, 'edit_term' ), 11, 2 ); |
|
95 | - add_action( 'delete_term', array( $this, 'delete_term' ), 10, 4 ); |
|
96 | - } elseif ( 'comment' === $object_type ) { |
|
97 | - add_action( 'comment_post', array( $this, 'add_comment' ), 11, 3 ); |
|
98 | - add_action( 'edit_comment', array( $this, 'edit_comment' ) ); |
|
99 | - 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 |
|
84 | + add_action('profile_update', array($this, 'edit_user'), 11, 2); |
|
85 | + add_action('delete_user', array($this, 'delete_user')); |
|
86 | + } elseif ('post' === $object_type) { |
|
87 | + add_action('save_post', array($this, 'post_actions'), 11, 2); |
|
88 | + } elseif ('attachment' === $object_type) { |
|
89 | + add_action('add_attachment', array($this, 'add_attachment')); |
|
90 | + add_action('edit_attachment', array($this, 'edit_attachment')); |
|
91 | + add_action('delete_attachment', array($this, 'delete_attachment')); |
|
92 | + } elseif ('category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type) { |
|
93 | + add_action('create_term', array($this, 'add_term'), 11, 3); |
|
94 | + add_action('edit_terms', array($this, 'edit_term'), 11, 2); |
|
95 | + add_action('delete_term', array($this, 'delete_term'), 10, 4); |
|
96 | + } elseif ('comment' === $object_type) { |
|
97 | + add_action('comment_post', array($this, 'add_comment'), 11, 3); |
|
98 | + add_action('edit_comment', array($this, 'edit_comment')); |
|
99 | + 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 |
|
100 | 100 | } else { // this is for custom post types |
101 | 101 | // we still have to use save_post because save_post_type fails to pull in the metadata |
102 | - add_action( 'save_post', array( $this, 'post_actions' ), 11, 2 ); |
|
102 | + add_action('save_post', array($this, 'post_actions'), 11, 2); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | 107 | // hook that action-scheduler can call |
108 | - add_action( 'object_sync_for_salesforce_push_record', array( $this, 'salesforce_push_sync_rest' ), 10, 4 ); |
|
108 | + add_action('object_sync_for_salesforce_push_record', array($this, 'salesforce_push_sync_rest'), 10, 4); |
|
109 | 109 | |
110 | 110 | } |
111 | 111 | |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @param string $type |
117 | 117 | * |
118 | 118 | */ |
119 | - public function manual_object_update( $object, $type ) { |
|
120 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update, true ); |
|
119 | + public function manual_object_update($object, $type) { |
|
120 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_update, true); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param string $user_id |
127 | 127 | */ |
128 | - public function add_user( $user_id ) { |
|
129 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
130 | - $this->object_insert( $user, 'user' ); |
|
128 | + public function add_user($user_id) { |
|
129 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
130 | + $this->object_insert($user, 'user'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param string $user_id |
137 | 137 | */ |
138 | - public function um_add_user( $user_id, $form_data = array() ) { |
|
139 | - $this->object_insert( $form_data, 'user' ); |
|
138 | + public function um_add_user($user_id, $form_data = array()) { |
|
139 | + $this->object_insert($form_data, 'user'); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | * @param string $user_id |
146 | 146 | * @param object $old_user_data |
147 | 147 | */ |
148 | - public function edit_user( $user_id, $old_user_data ) { |
|
149 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
150 | - $this->object_update( $user, 'user' ); |
|
148 | + public function edit_user($user_id, $old_user_data) { |
|
149 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
150 | + $this->object_update($user, 'user'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @param string $user_id |
157 | 157 | */ |
158 | - public function delete_user( $user_id ) { |
|
159 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
160 | - $this->object_delete( $user, 'user' ); |
|
158 | + public function delete_user($user_id) { |
|
159 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
160 | + $this->object_delete($user, 'user'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,48 +167,48 @@ discard block |
||
167 | 167 | * @param string $post_id |
168 | 168 | * @param object $post |
169 | 169 | */ |
170 | - public function post_actions( $post_id, $post ) { |
|
170 | + public function post_actions($post_id, $post) { |
|
171 | 171 | |
172 | 172 | $post_type = $post->post_type; |
173 | 173 | |
174 | - if ( isset( $post->post_status ) && 'auto-draft' === $post->post_status ) { |
|
174 | + if (isset($post->post_status) && 'auto-draft' === $post->post_status) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | // this plugin does not sync log or revision posts with salesforce |
178 | - if ( isset( $post->post_type ) && in_array( $post->post_type, array( 'wp_log', 'revision' ), true ) ) { |
|
178 | + if (isset($post->post_type) && in_array($post->post_type, array('wp_log', 'revision'), true)) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | - if ( $post->post_modified_gmt === $post->post_date_gmt && 'trash' !== $post->post_status ) { |
|
181 | + if ($post->post_modified_gmt === $post->post_date_gmt && 'trash' !== $post->post_status) { |
|
182 | 182 | $update = 0; |
183 | 183 | $delete = 0; |
184 | - } elseif ( 'trash' !== $post->post_status ) { |
|
184 | + } elseif ('trash' !== $post->post_status) { |
|
185 | 185 | $update = 1; |
186 | 186 | $delete = 0; |
187 | - } elseif ( 'trash' === $post->post_status ) { |
|
187 | + } elseif ('trash' === $post->post_status) { |
|
188 | 188 | $update = 0; |
189 | 189 | $delete = 1; |
190 | 190 | } |
191 | 191 | |
192 | 192 | // add support for woocommerce if it is installed |
193 | - if ( defined( 'WC_VERSION' ) ) { |
|
193 | + if (defined('WC_VERSION')) { |
|
194 | 194 | // statuses to ignore |
195 | - if ( isset( $post->post_status ) && in_array( $post->post_status, array( 'wc-pending' ), true ) ) { |
|
195 | + if (isset($post->post_status) && in_array($post->post_status, array('wc-pending'), true)) { |
|
196 | 196 | return; |
197 | 197 | } |
198 | 198 | // statuses to count as new. note that the api will also check to see if it already has been mapped before saving. |
199 | - if ( isset( $post->post_status ) && in_array( $post->post_status, array( 'wc-on-hold', 'wc-processing' ), true ) ) { |
|
199 | + if (isset($post->post_status) && in_array($post->post_status, array('wc-on-hold', 'wc-processing'), true)) { |
|
200 | 200 | $update = 0; |
201 | 201 | $delete = 0; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - $post = $this->wordpress->get_wordpress_object_data( $post->post_type, $post_id ); |
|
206 | - if ( 1 === $update ) { |
|
207 | - $this->object_update( $post, $post_type ); |
|
208 | - } elseif ( 1 === $delete ) { |
|
209 | - $this->object_delete( $post, $post_type ); |
|
205 | + $post = $this->wordpress->get_wordpress_object_data($post->post_type, $post_id); |
|
206 | + if (1 === $update) { |
|
207 | + $this->object_update($post, $post_type); |
|
208 | + } elseif (1 === $delete) { |
|
209 | + $this->object_delete($post, $post_type); |
|
210 | 210 | } else { |
211 | - $this->object_insert( $post, $post_type ); |
|
211 | + $this->object_insert($post, $post_type); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
@@ -217,9 +217,9 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @param string $post_id |
219 | 219 | */ |
220 | - public function add_attachment( $post_id ) { |
|
221 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
222 | - $this->object_insert( $attachment, 'attachment' ); |
|
220 | + public function add_attachment($post_id) { |
|
221 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
222 | + $this->object_insert($attachment, 'attachment'); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @param string $post_id |
229 | 229 | */ |
230 | - public function edit_attachment( $post_id ) { |
|
231 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
232 | - $this->object_update( $attachment, 'attachment' ); |
|
230 | + public function edit_attachment($post_id) { |
|
231 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
232 | + $this->object_update($attachment, 'attachment'); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -237,9 +237,9 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @param string $post_id |
239 | 239 | */ |
240 | - public function delete_attachment( $post_id ) { |
|
241 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
242 | - $this->object_delete( $attachment, 'attachment' ); |
|
240 | + public function delete_attachment($post_id) { |
|
241 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
242 | + $this->object_delete($attachment, 'attachment'); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | * @param string $tt_id |
250 | 250 | * @param string $taxonomy |
251 | 251 | */ |
252 | - public function add_term( $term_id, $tt_id, $taxonomy ) { |
|
253 | - $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
|
254 | - $this->object_insert( $term, $taxonomy ); |
|
252 | + public function add_term($term_id, $tt_id, $taxonomy) { |
|
253 | + $term = $this->wordpress->get_wordpress_object_data($taxonomy, $term_id); |
|
254 | + $this->object_insert($term, $taxonomy); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | * @param string $term_id |
261 | 261 | * @param string $taxonomy |
262 | 262 | */ |
263 | - public function edit_term( $term_id, $taxonomy ) { |
|
264 | - $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
|
265 | - $this->object_update( $term, $taxonomy ); |
|
263 | + public function edit_term($term_id, $taxonomy) { |
|
264 | + $term = $this->wordpress->get_wordpress_object_data($taxonomy, $term_id); |
|
265 | + $this->object_update($term, $taxonomy); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -273,10 +273,10 @@ discard block |
||
273 | 273 | * @param string $taxonomy (slug) |
274 | 274 | * @param object $deleted_term |
275 | 275 | */ |
276 | - public function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) { |
|
276 | + public function delete_term($term, $tt_id, $taxonomy, $deleted_term) { |
|
277 | 277 | $deleted_term = (array) $deleted_term; |
278 | 278 | $type = $deleted_term['taxonomy']; |
279 | - $this->object_delete( $deleted_term, $type ); |
|
279 | + $this->object_delete($deleted_term, $type); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -286,9 +286,9 @@ discard block |
||
286 | 286 | * @param int|string comment_approved |
287 | 287 | * @param array $commentdata |
288 | 288 | */ |
289 | - public function add_comment( $comment_id, $comment_approved, $commentdata = array() ) { |
|
290 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
291 | - $this->object_insert( $comment, 'comment' ); |
|
289 | + public function add_comment($comment_id, $comment_approved, $commentdata = array()) { |
|
290 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
291 | + $this->object_insert($comment, 'comment'); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @param string $comment_id |
298 | 298 | */ |
299 | - public function edit_comment( $comment_id ) { |
|
300 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
301 | - $this->object_update( $comment, 'comment' ); |
|
299 | + public function edit_comment($comment_id) { |
|
300 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
301 | + $this->object_update($comment, 'comment'); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -306,33 +306,33 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @param string $comment_id |
308 | 308 | */ |
309 | - public function delete_comment( $comment_id ) { |
|
310 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
311 | - $this->object_delete( $comment, 'comment' ); |
|
309 | + public function delete_comment($comment_id) { |
|
310 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
311 | + $this->object_delete($comment, 'comment'); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Insert a new object |
316 | 316 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
317 | 317 | */ |
318 | - private function object_insert( $object, $type ) { |
|
319 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_create ); |
|
318 | + private function object_insert($object, $type) { |
|
319 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_create); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
323 | 323 | * Update an existing object |
324 | 324 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
325 | 325 | */ |
326 | - private function object_update( $object, $type ) { |
|
327 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update ); |
|
326 | + private function object_update($object, $type) { |
|
327 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_update); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
331 | 331 | * Delete an existing object |
332 | 332 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
333 | 333 | */ |
334 | - private function object_delete( $object, $type ) { |
|
335 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_delete ); |
|
334 | + private function object_delete($object, $type) { |
|
335 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_delete); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -349,50 +349,50 @@ discard block |
||
349 | 349 | * Are we calling this manually? |
350 | 350 | * |
351 | 351 | */ |
352 | - private function salesforce_push_object_crud( $object_type, $object, $sf_sync_trigger, $manual = false ) { |
|
352 | + private function salesforce_push_object_crud($object_type, $object, $sf_sync_trigger, $manual = false) { |
|
353 | 353 | |
354 | - $structure = $this->wordpress->get_wordpress_table_structure( $object_type ); |
|
354 | + $structure = $this->wordpress->get_wordpress_table_structure($object_type); |
|
355 | 355 | $object_id_field = $structure['id_field']; |
356 | 356 | |
357 | 357 | // there is a WordPress object to push |
358 | - if ( isset( $object[ $object_id_field ] ) ) { |
|
359 | - $mapping_object = $this->mappings->load_by_wordpress( $object_type, $object[ $object_id_field ] ); |
|
358 | + if (isset($object[$object_id_field])) { |
|
359 | + $mapping_object = $this->mappings->load_by_wordpress($object_type, $object[$object_id_field]); |
|
360 | 360 | |
361 | 361 | // there is already a mapping object for this WordPress object |
362 | - if ( isset( $mapping_object['id'] ) ) { |
|
362 | + if (isset($mapping_object['id'])) { |
|
363 | 363 | $mapping_object_id_transient = $mapping_object['id']; |
364 | 364 | } else { |
365 | 365 | // there is not a mapping object for this WordPress object id yet |
366 | 366 | // check for that transient with the currently pulling id |
367 | - $mapping_object_id_transient = (int) get_transient( 'salesforce_pulling_object_id' ); |
|
367 | + $mapping_object_id_transient = (int) get_transient('salesforce_pulling_object_id'); |
|
368 | 368 | } |
369 | 369 | |
370 | - $salesforce_pulling = (int) get_transient( 'salesforce_pulling_' . $mapping_object_id_transient ); |
|
371 | - if ( 1 === $salesforce_pulling ) { |
|
372 | - delete_transient( 'salesforce_pulling_' . $mapping_object_id_transient ); |
|
373 | - $pulling_id = get_transient( 'salesforce_pulling_object_id' ); |
|
374 | - if ( $pulling_id === $mapping_object_id_transient ) { |
|
375 | - delete_transient( 'salesforce_pulling_object_id' ); |
|
370 | + $salesforce_pulling = (int) get_transient('salesforce_pulling_' . $mapping_object_id_transient); |
|
371 | + if (1 === $salesforce_pulling) { |
|
372 | + delete_transient('salesforce_pulling_' . $mapping_object_id_transient); |
|
373 | + $pulling_id = get_transient('salesforce_pulling_object_id'); |
|
374 | + if ($pulling_id === $mapping_object_id_transient) { |
|
375 | + delete_transient('salesforce_pulling_object_id'); |
|
376 | 376 | } |
377 | 377 | return false; |
378 | 378 | } |
379 | 379 | } else { |
380 | 380 | // if we don't have a WordPress object id, we've got no business doing stuff in Salesforce |
381 | 381 | $status = 'error'; |
382 | - if ( isset( $this->logging ) ) { |
|
382 | + if (isset($this->logging)) { |
|
383 | 383 | $logging = $this->logging; |
384 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
385 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
384 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
385 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | // translators: placeholder is the name of the WordPress id field |
389 | - $title = sprintf( esc_html__( 'Error: Salesforce Push: unable to process queue item because it has no WordPress %1$s.', 'object-sync-for-salesforce' ), |
|
390 | - esc_attr( $object_id_field ) |
|
389 | + $title = sprintf(esc_html__('Error: Salesforce Push: unable to process queue item because it has no WordPress %1$s.', 'object-sync-for-salesforce'), |
|
390 | + esc_attr($object_id_field) |
|
391 | 391 | ); |
392 | 392 | |
393 | 393 | $logging->setup( |
394 | 394 | $title, |
395 | - print_r( $object, true ), // print this array because if this happens, something weird has happened and we want to log whatever we have |
|
395 | + print_r($object, true), // print this array because if this happens, something weird has happened and we want to log whatever we have |
|
396 | 396 | $sf_sync_trigger, |
397 | 397 | 0, // parent id goes here but we don't have one, so make it 0 |
398 | 398 | $status |
@@ -409,14 +409,14 @@ discard block |
||
409 | 409 | ) |
410 | 410 | ); |
411 | 411 | |
412 | - foreach ( $sf_mappings as $mapping ) { // for each mapping of this object |
|
412 | + foreach ($sf_mappings as $mapping) { // for each mapping of this object |
|
413 | 413 | $map_sync_triggers = $mapping['sync_triggers']; |
414 | 414 | |
415 | 415 | // these are bit operators, so we leave out the strict |
416 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
416 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
417 | 417 | |
418 | 418 | // hook to allow other plugins to prevent a push per-mapping. |
419 | - $push_allowed = apply_filters( 'object_sync_for_salesforce_push_object_allowed', true, $object_type, $object, $sf_sync_trigger, $mapping ); |
|
419 | + $push_allowed = apply_filters('object_sync_for_salesforce_push_object_allowed', true, $object_type, $object, $sf_sync_trigger, $mapping); |
|
420 | 420 | |
421 | 421 | // example to keep from pushing the user with id of 1 |
422 | 422 | /* |
@@ -429,18 +429,18 @@ discard block |
||
429 | 429 | } |
430 | 430 | */ |
431 | 431 | |
432 | - if ( false === $push_allowed ) { |
|
432 | + if (false === $push_allowed) { |
|
433 | 433 | continue; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // push drafts if the setting says so |
437 | 437 | // post status is draft, or post status is inherit and post type is not attachment |
438 | - 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'] ) ) ) { |
|
438 | + 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']))) { |
|
439 | 439 | // skip this object if it is a draft and the fieldmap settings told us to ignore it |
440 | 440 | continue; |
441 | 441 | } |
442 | 442 | |
443 | - if ( isset( $mapping['push_async'] ) && ( '1' === $mapping['push_async'] ) && false === $manual ) { |
|
443 | + if (isset($mapping['push_async']) && ('1' === $mapping['push_async']) && false === $manual) { |
|
444 | 444 | // this item is async and we want to save it to the queue |
445 | 445 | |
446 | 446 | // if we determine that the above does not perform well, worst case scenario is we could save $data to a custom table, and pass the id to the callback method. |
@@ -454,18 +454,18 @@ discard block |
||
454 | 454 | // add a queue action to push data to salesforce |
455 | 455 | // this means we don't need the frequency for this method anymore, i think |
456 | 456 | $this->queue->add( |
457 | - $this->schedulable_classes[ $this->schedule_name ]['callback'], |
|
457 | + $this->schedulable_classes[$this->schedule_name]['callback'], |
|
458 | 458 | array( |
459 | 459 | 'object_type' => $object_type, |
460 | - 'object' => filter_var( $object[ $object_id_field ], FILTER_VALIDATE_INT ), |
|
461 | - 'mapping' => filter_var( $mapping['id'], FILTER_VALIDATE_INT ), |
|
460 | + 'object' => filter_var($object[$object_id_field], FILTER_VALIDATE_INT), |
|
461 | + 'mapping' => filter_var($mapping['id'], FILTER_VALIDATE_INT), |
|
462 | 462 | 'sf_sync_trigger' => $sf_sync_trigger, |
463 | 463 | ), |
464 | 464 | $this->schedule_name |
465 | 465 | ); |
466 | 466 | } else { |
467 | 467 | // this one is not async. do it immediately. |
468 | - $push = $this->salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ); |
|
468 | + $push = $this->salesforce_push_sync_rest($object_type, $object, $mapping, $sf_sync_trigger); |
|
469 | 469 | } // End if(). |
470 | 470 | } // End if(). if the trigger does not match our requirements, skip it |
471 | 471 | } // End foreach(). |
@@ -486,35 +486,35 @@ discard block |
||
486 | 486 | * @return true or exit the method |
487 | 487 | * |
488 | 488 | */ |
489 | - public function salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ) { |
|
489 | + public function salesforce_push_sync_rest($object_type, $object, $mapping, $sf_sync_trigger) { |
|
490 | 490 | |
491 | - if ( is_int( $object ) ) { |
|
491 | + if (is_int($object)) { |
|
492 | 492 | $object_id = $object; |
493 | - $object = $this->wordpress->get_wordpress_object_data( $object_type, $object_id ); |
|
493 | + $object = $this->wordpress->get_wordpress_object_data($object_type, $object_id); |
|
494 | 494 | } |
495 | 495 | |
496 | - if ( is_int( $mapping ) ) { |
|
496 | + if (is_int($mapping)) { |
|
497 | 497 | $mapping_id = $mapping; |
498 | - $mapping = $this->mappings->get_fieldmaps( $mapping_id ); |
|
498 | + $mapping = $this->mappings->get_fieldmaps($mapping_id); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | // If Salesforce is not authorized, don't do anything. |
502 | 502 | // it's unclear to me if we need to do something else here or if this is sufficient. This is all Drupal does. |
503 | - if ( true !== $this->salesforce['is_authorized'] ) { |
|
503 | + if (true !== $this->salesforce['is_authorized']) { |
|
504 | 504 | return; |
505 | 505 | } |
506 | 506 | |
507 | 507 | $sfapi = $this->salesforce['sfapi']; |
508 | 508 | |
509 | 509 | // we need to get the WordPress id here so we can check to see if the object already has a map |
510 | - $structure = $this->wordpress->get_wordpress_table_structure( $object_type ); |
|
510 | + $structure = $this->wordpress->get_wordpress_table_structure($object_type); |
|
511 | 511 | $object_id = $structure['id_field']; |
512 | 512 | |
513 | 513 | // this returns the row that maps the individual WordPress row to the individual Salesfoce row |
514 | - $mapping_object = $this->mappings->load_by_wordpress( $object_type, $object[ "$object_id" ] ); |
|
514 | + $mapping_object = $this->mappings->load_by_wordpress($object_type, $object["$object_id"]); |
|
515 | 515 | |
516 | 516 | // hook to allow other plugins to define or alter the mapping object |
517 | - $mapping_object = apply_filters( 'object_sync_for_salesforce_push_mapping_object', $mapping_object, $object, $mapping ); |
|
517 | + $mapping_object = apply_filters('object_sync_for_salesforce_push_mapping_object', $mapping_object, $object, $mapping); |
|
518 | 518 | |
519 | 519 | // we already have the data from WordPress at this point; we just need to work with it in Salesforce |
520 | 520 | $synced_object = array( |
@@ -528,84 +528,84 @@ discard block |
||
528 | 528 | |
529 | 529 | // deleting mapped objects |
530 | 530 | // these are bit operators, so we leave out the strict |
531 | - if ( $sf_sync_trigger == $this->mappings->sync_wordpress_delete ) { |
|
532 | - if ( isset( $mapping_object['id'] ) ) { |
|
531 | + if ($sf_sync_trigger == $this->mappings->sync_wordpress_delete) { |
|
532 | + if (isset($mapping_object['id'])) { |
|
533 | 533 | $op = 'Delete'; |
534 | 534 | |
535 | - $salesforce_check = $this->mappings->load_by_salesforce( $mapping_object['salesforce_id'] ); |
|
535 | + $salesforce_check = $this->mappings->load_by_salesforce($mapping_object['salesforce_id']); |
|
536 | 536 | |
537 | - if ( count( $salesforce_check ) === count( $salesforce_check, COUNT_RECURSIVE ) ) { |
|
537 | + if (count($salesforce_check) === count($salesforce_check, COUNT_RECURSIVE)) { |
|
538 | 538 | try { |
539 | - $result = $sfapi->object_delete( $mapping['salesforce_object'], $mapping_object['salesforce_id'] ); |
|
540 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
539 | + $result = $sfapi->object_delete($mapping['salesforce_object'], $mapping_object['salesforce_id']); |
|
540 | + } catch (Object_Sync_Sf_Exception $e) { |
|
541 | 541 | $status = 'error'; |
542 | 542 | // create log entry for failed delete |
543 | - if ( isset( $this->logging ) ) { |
|
543 | + if (isset($this->logging)) { |
|
544 | 544 | $logging = $this->logging; |
545 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
546 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
545 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
546 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | // 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 |
550 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
551 | - esc_attr( $op ), |
|
552 | - esc_attr( $mapping['salesforce_object'] ), |
|
553 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
554 | - esc_attr( $mapping['wordpress_object'] ), |
|
555 | - esc_attr( $object_id ), |
|
556 | - esc_attr( $object[ "$object_id" ] ) |
|
550 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
551 | + esc_attr($op), |
|
552 | + esc_attr($mapping['salesforce_object']), |
|
553 | + esc_attr($mapping_object['salesforce_id']), |
|
554 | + esc_attr($mapping['wordpress_object']), |
|
555 | + esc_attr($object_id), |
|
556 | + esc_attr($object["$object_id"]) |
|
557 | 557 | ); |
558 | 558 | |
559 | 559 | $logging->setup( |
560 | 560 | $title, |
561 | 561 | $e->getMessage(), |
562 | 562 | $sf_sync_trigger, |
563 | - $object[ "$object_id" ], |
|
563 | + $object["$object_id"], |
|
564 | 564 | $status |
565 | 565 | ); |
566 | 566 | |
567 | 567 | // hook for push fail |
568 | - do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object, $object_id ); |
|
568 | + do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object, $object_id); |
|
569 | 569 | |
570 | 570 | } |
571 | 571 | |
572 | - if ( ! isset( $e ) ) { |
|
572 | + if ( ! isset($e)) { |
|
573 | 573 | // create log entry for successful delete if the result had no errors |
574 | 574 | $status = 'success'; |
575 | - if ( isset( $this->logging ) ) { |
|
575 | + if (isset($this->logging)) { |
|
576 | 576 | $logging = $this->logging; |
577 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
578 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
577 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
578 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | // 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 |
582 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
583 | - esc_attr( $op ), |
|
584 | - esc_attr( $mapping['salesforce_object'] ), |
|
585 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
586 | - esc_attr( $mapping['wordpress_object'] ), |
|
587 | - esc_attr( $object_id ), |
|
588 | - esc_attr( $object[ "$object_id" ] ) |
|
582 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
583 | + esc_attr($op), |
|
584 | + esc_attr($mapping['salesforce_object']), |
|
585 | + esc_attr($mapping_object['salesforce_id']), |
|
586 | + esc_attr($mapping['wordpress_object']), |
|
587 | + esc_attr($object_id), |
|
588 | + esc_attr($object["$object_id"]) |
|
589 | 589 | ); |
590 | 590 | |
591 | 591 | $logging->setup( |
592 | 592 | $title, |
593 | 593 | '', |
594 | 594 | $sf_sync_trigger, |
595 | - $object[ "$object_id" ], |
|
595 | + $object["$object_id"], |
|
596 | 596 | $status |
597 | 597 | ); |
598 | 598 | |
599 | 599 | // hook for push success |
600 | - do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
600 | + do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
601 | 601 | } |
602 | 602 | } else { |
603 | 603 | $more_ids = '<p>The Salesforce record was not deleted because there are multiple WordPress IDs that match this Salesforce ID. They are: '; |
604 | 604 | $i = 0; |
605 | - foreach ( $salesforce_check as $match ) { |
|
605 | + foreach ($salesforce_check as $match) { |
|
606 | 606 | $i++; |
607 | 607 | $more_ids .= $match['wordpress_id']; |
608 | - if ( count( $salesforce_check ) !== $i ) { |
|
608 | + if (count($salesforce_check) !== $i) { |
|
609 | 609 | $more_ids .= ', '; |
610 | 610 | } else { |
611 | 611 | $more_ids .= '.</p>'; |
@@ -615,34 +615,34 @@ discard block |
||
615 | 615 | $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>'; |
616 | 616 | |
617 | 617 | $status = 'notice'; |
618 | - if ( isset( $this->logging ) ) { |
|
618 | + if (isset($this->logging)) { |
|
619 | 619 | $logging = $this->logging; |
620 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
621 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
620 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
621 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | // 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 |
625 | - $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' ), |
|
626 | - esc_attr( $op ), |
|
627 | - esc_attr( $mapping['salesforce_object'] ), |
|
628 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
629 | - esc_attr( $mapping['wordpress_object'] ), |
|
630 | - esc_attr( $object_id ), |
|
631 | - esc_attr( $object[ "$object_id" ] ) |
|
625 | + $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'), |
|
626 | + esc_attr($op), |
|
627 | + esc_attr($mapping['salesforce_object']), |
|
628 | + esc_attr($mapping_object['salesforce_id']), |
|
629 | + esc_attr($mapping['wordpress_object']), |
|
630 | + esc_attr($object_id), |
|
631 | + esc_attr($object["$object_id"]) |
|
632 | 632 | ); |
633 | 633 | |
634 | 634 | $logging->setup( |
635 | 635 | $title, |
636 | 636 | $more_ids, |
637 | 637 | $sf_sync_trigger, |
638 | - $object[ "$object_id" ], |
|
638 | + $object["$object_id"], |
|
639 | 639 | $status |
640 | 640 | ); |
641 | 641 | } // End if(). |
642 | 642 | |
643 | 643 | // delete the map row from WordPress after the Salesforce row has been deleted |
644 | 644 | // we delete the map row even if the Salesforce delete failed, because the WordPress object is gone |
645 | - $this->mappings->delete_object_map( $mapping_object['id'] ); |
|
645 | + $this->mappings->delete_object_map($mapping_object['id']); |
|
646 | 646 | |
647 | 647 | } // End if(). there is no map row |
648 | 648 | |
@@ -650,52 +650,52 @@ discard block |
||
650 | 650 | } // End if(). |
651 | 651 | |
652 | 652 | // are these objects already connected in WordPress? |
653 | - if ( isset( $mapping_object['id'] ) ) { |
|
653 | + if (isset($mapping_object['id'])) { |
|
654 | 654 | $is_new = false; |
655 | 655 | } else { |
656 | 656 | $is_new = true; |
657 | 657 | } |
658 | 658 | |
659 | 659 | // map the WordPress values to salesforce fields |
660 | - $params = $this->mappings->map_params( $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
660 | + $params = $this->mappings->map_params($mapping, $object, $sf_sync_trigger, false, $is_new); |
|
661 | 661 | |
662 | 662 | // hook to allow other plugins to modify the $params array |
663 | 663 | // use hook to map fields between the WordPress and Salesforce objects |
664 | 664 | // returns $params. |
665 | - $params = apply_filters( 'object_sync_for_salesforce_push_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
665 | + $params = apply_filters('object_sync_for_salesforce_push_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new); |
|
666 | 666 | |
667 | 667 | // if we don't get any params, there are no fields that should be sent to Salesforce |
668 | - if ( empty( $params ) ) { |
|
668 | + if (empty($params)) { |
|
669 | 669 | return; |
670 | 670 | } |
671 | 671 | |
672 | 672 | // if there is a prematch WordPress field - ie email - on the fieldmap object |
673 | - if ( isset( $params['prematch'] ) && is_array( $params['prematch'] ) ) { |
|
673 | + if (isset($params['prematch']) && is_array($params['prematch'])) { |
|
674 | 674 | $prematch_field_wordpress = $params['prematch']['wordpress_field']; |
675 | 675 | $prematch_field_salesforce = $params['prematch']['salesforce_field']; |
676 | 676 | $prematch_value = $params['prematch']['value']; |
677 | - unset( $params['prematch'] ); |
|
677 | + unset($params['prematch']); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | // if there is an external key field in Salesforce - ie mailchimp user id - on the fieldmap object |
681 | - if ( isset( $params['key'] ) && is_array( $params['key'] ) ) { |
|
681 | + if (isset($params['key']) && is_array($params['key'])) { |
|
682 | 682 | $key_field_wordpress = $params['key']['wordpress_field']; |
683 | 683 | $key_field_salesforce = $params['key']['salesforce_field']; |
684 | 684 | $key_value = $params['key']['value']; |
685 | - unset( $params['key'] ); |
|
685 | + unset($params['key']); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | $frequencies = $this->queue->get_frequencies(); |
689 | - $seconds = reset( $frequencies )['frequency'] + 60; |
|
689 | + $seconds = reset($frequencies)['frequency'] + 60; |
|
690 | 690 | |
691 | - if ( true === $is_new ) { |
|
691 | + if (true === $is_new) { |
|
692 | 692 | |
693 | 693 | // right here we should set the pushing transient |
694 | 694 | // this means we have to create the mapping object here as well, and update it with the correct IDs after successful response |
695 | 695 | // create the mapping object between the rows |
696 | - $mapping_object_id = $this->create_object_map( $object, $object_id, $this->mappings->generate_temporary_id( 'push' ), $mapping, true ); |
|
697 | - set_transient( 'salesforce_pushing_' . $mapping_object_id, 1, $seconds ); |
|
698 | - set_transient( 'salesforce_pushing_object_id', $mapping_object_id ); |
|
696 | + $mapping_object_id = $this->create_object_map($object, $object_id, $this->mappings->generate_temporary_id('push'), $mapping, true); |
|
697 | + set_transient('salesforce_pushing_' . $mapping_object_id, 1, $seconds); |
|
698 | + set_transient('salesforce_pushing_object_id', $mapping_object_id); |
|
699 | 699 | $mapping_object = $this->mappings->get_object_maps( |
700 | 700 | array( |
701 | 701 | 'id' => $mapping_object_id, |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | |
705 | 705 | // setup SF record type. CampaignMember objects get their Campaign's type |
706 | 706 | // i am still a bit confused about this |
707 | - if ( $mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty( $params['RecordTypeId'] ) && ( 'CampaignMember' !== $mapping['salesforce_object'] ) ) { |
|
707 | + if ($mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty($params['RecordTypeId']) && ('CampaignMember' !== $mapping['salesforce_object'])) { |
|
708 | 708 | $params['RecordTypeId'] = $mapping['salesforce_record_type_default']; |
709 | 709 | } |
710 | 710 | |
@@ -716,61 +716,61 @@ discard block |
||
716 | 716 | // returns a $salesforce_id. |
717 | 717 | // it should keep NULL if there is no match |
718 | 718 | // the function that calls this hook needs to check the mapping to make sure the WordPress object is the right type |
719 | - $salesforce_id = apply_filters( 'object_sync_for_salesforce_find_sf_object_match', null, $object, $mapping, 'push' ); |
|
719 | + $salesforce_id = apply_filters('object_sync_for_salesforce_find_sf_object_match', null, $object, $mapping, 'push'); |
|
720 | 720 | |
721 | 721 | // hook to allow other plugins to do something right before Salesforce data is saved |
722 | 722 | // ex: run WordPress methods on an object if it exists, or do something in preparation for it if it doesn't |
723 | - do_action( 'object_sync_for_salesforce_pre_push', $salesforce_id, $mapping, $object, $object_id, $params ); |
|
723 | + do_action('object_sync_for_salesforce_pre_push', $salesforce_id, $mapping, $object, $object_id, $params); |
|
724 | 724 | |
725 | 725 | // hook to allow other plugins to change params on update actions only |
726 | 726 | // use hook to map fields between the WordPress and Salesforce objects |
727 | 727 | // returns $params. |
728 | - $params = apply_filters( 'object_sync_for_salesforce_push_update_params_modify', $params, $salesforce_id, $mapping, $object ); |
|
728 | + $params = apply_filters('object_sync_for_salesforce_push_update_params_modify', $params, $salesforce_id, $mapping, $object); |
|
729 | 729 | |
730 | - if ( isset( $prematch_field_wordpress ) || isset( $key_field_wordpress ) || null !== $salesforce_id ) { |
|
730 | + if (isset($prematch_field_wordpress) || isset($key_field_wordpress) || null !== $salesforce_id) { |
|
731 | 731 | |
732 | 732 | // if either prematch criteria exists, make the values queryable |
733 | 733 | |
734 | - if ( isset( $prematch_field_wordpress ) ) { |
|
734 | + if (isset($prematch_field_wordpress)) { |
|
735 | 735 | // a prematch has been specified, attempt an upsert(). |
736 | 736 | // prematch values with punctuation need to be escaped |
737 | - $encoded_prematch_value = rawurlencode( $prematch_value ); |
|
737 | + $encoded_prematch_value = rawurlencode($prematch_value); |
|
738 | 738 | // for at least 'email' fields, periods also need to be escaped: |
739 | 739 | // https://developer.salesforce.com/forums?id=906F000000099xPIAQ |
740 | - $encoded_prematch_value = str_replace( '.', '%2E', $encoded_prematch_value ); |
|
740 | + $encoded_prematch_value = str_replace('.', '%2E', $encoded_prematch_value); |
|
741 | 741 | } |
742 | 742 | |
743 | - if ( isset( $key_field_wordpress ) ) { |
|
743 | + if (isset($key_field_wordpress)) { |
|
744 | 744 | // an external key has been specified, attempt an upsert(). |
745 | 745 | // external key values with punctuation need to be escaped |
746 | - $encoded_key_value = rawurlencode( $key_value ); |
|
746 | + $encoded_key_value = rawurlencode($key_value); |
|
747 | 747 | // for at least 'email' fields, periods also need to be escaped: |
748 | 748 | // https://developer.salesforce.com/forums?id=906F000000099xPIAQ |
749 | - $encoded_key_value = str_replace( '.', '%2E', $encoded_key_value ); |
|
749 | + $encoded_key_value = str_replace('.', '%2E', $encoded_key_value); |
|
750 | 750 | } |
751 | 751 | |
752 | - if ( isset( $prematch_field_wordpress ) ) { |
|
752 | + if (isset($prematch_field_wordpress)) { |
|
753 | 753 | $upsert_key = $prematch_field_salesforce; |
754 | 754 | $upsert_value = $encoded_prematch_value; |
755 | - } elseif ( isset( $key_field_wordpress ) ) { |
|
755 | + } elseif (isset($key_field_wordpress)) { |
|
756 | 756 | $upsert_key = $key_field_salesforce; |
757 | 757 | $upsert_value = $encoded_key_value; |
758 | 758 | } |
759 | 759 | |
760 | - if ( null !== $salesforce_id ) { |
|
760 | + if (null !== $salesforce_id) { |
|
761 | 761 | $upsert_key = 'Id'; |
762 | 762 | $upsert_value = $salesforce_id; |
763 | 763 | } |
764 | 764 | |
765 | 765 | $op = 'Upsert'; |
766 | 766 | |
767 | - $result = $sfapi->object_upsert( $mapping['salesforce_object'], $upsert_key, $upsert_value, $params ); |
|
767 | + $result = $sfapi->object_upsert($mapping['salesforce_object'], $upsert_key, $upsert_value, $params); |
|
768 | 768 | |
769 | 769 | // Handle upsert responses. |
770 | - switch ( $sfapi->response['code'] ) { |
|
770 | + switch ($sfapi->response['code']) { |
|
771 | 771 | // On Upsert:update retrieved object. |
772 | 772 | case '204': |
773 | - $sf_object = $sfapi->object_readby_external_id( $mapping['salesforce_object'], $upsert_key, $upsert_value ); |
|
773 | + $sf_object = $sfapi->object_readby_external_id($mapping['salesforce_object'], $upsert_key, $upsert_value); |
|
774 | 774 | $salesforce_data['id'] = $sf_object['data']['Id']; |
775 | 775 | break; |
776 | 776 | // Handle duplicate records. |
@@ -781,43 +781,43 @@ discard block |
||
781 | 781 | } else { |
782 | 782 | // No key or prematch field exists on this field map object, create a new object in Salesforce. |
783 | 783 | $op = 'Create'; |
784 | - $result = $sfapi->object_create( $mapping['salesforce_object'], $params ); |
|
784 | + $result = $sfapi->object_create($mapping['salesforce_object'], $params); |
|
785 | 785 | } // End if(). |
786 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
786 | + } catch (Object_Sync_Sf_Exception $e) { |
|
787 | 787 | // create log entry for failed create or upsert |
788 | 788 | $status = 'error'; |
789 | 789 | |
790 | - if ( isset( $this->logging ) ) { |
|
790 | + if (isset($this->logging)) { |
|
791 | 791 | $logging = $this->logging; |
792 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
793 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
792 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
793 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | // 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 |
797 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
798 | - esc_attr( $op ), |
|
799 | - esc_attr( $mapping['salesforce_object'] ), |
|
800 | - isset( $salesforce_id ) ? ' ' . esc_attr( $salesforce_id ) : '', |
|
801 | - esc_attr( $mapping['wordpress_object'] ), |
|
802 | - esc_attr( $object_id ), |
|
803 | - esc_attr( $object[ "$object_id" ] ) |
|
797 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
798 | + esc_attr($op), |
|
799 | + esc_attr($mapping['salesforce_object']), |
|
800 | + isset($salesforce_id) ? ' ' . esc_attr($salesforce_id) : '', |
|
801 | + esc_attr($mapping['wordpress_object']), |
|
802 | + esc_attr($object_id), |
|
803 | + esc_attr($object["$object_id"]) |
|
804 | 804 | ); |
805 | 805 | |
806 | 806 | $logging->setup( |
807 | 807 | $title, |
808 | 808 | $e->getMessage(), |
809 | 809 | $sf_sync_trigger, |
810 | - $object[ "$object_id" ], |
|
810 | + $object["$object_id"], |
|
811 | 811 | $status |
812 | 812 | ); |
813 | 813 | |
814 | 814 | // hook for push fail |
815 | - do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object ); |
|
815 | + do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object); |
|
816 | 816 | |
817 | 817 | return; |
818 | 818 | } // End try(). |
819 | 819 | |
820 | - if ( ! isset( $salesforce_data ) ) { |
|
820 | + if ( ! isset($salesforce_data)) { |
|
821 | 821 | // if we didn't set $salesforce_data already, set it now to api call result |
822 | 822 | $salesforce_data = $result['data']; |
823 | 823 | } |
@@ -826,78 +826,78 @@ discard block |
||
826 | 826 | // this means the object has already been created/updated in Salesforce |
827 | 827 | // 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) |
828 | 828 | |
829 | - if ( empty( $result['errorCode'] ) ) { |
|
829 | + if (empty($result['errorCode'])) { |
|
830 | 830 | $salesforce_id = $salesforce_data['id']; |
831 | 831 | $status = 'success'; |
832 | 832 | |
833 | - if ( isset( $this->logging ) ) { |
|
833 | + if (isset($this->logging)) { |
|
834 | 834 | $logging = $this->logging; |
835 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
836 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
835 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
836 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | // 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 |
840 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
841 | - esc_attr( $op ), |
|
842 | - esc_attr( $mapping['salesforce_object'] ), |
|
843 | - esc_attr( $salesforce_id ), |
|
844 | - esc_attr( $mapping['wordpress_object'] ), |
|
845 | - esc_attr( $object_id ), |
|
846 | - esc_attr( $object[ "$object_id" ] ) |
|
840 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
841 | + esc_attr($op), |
|
842 | + esc_attr($mapping['salesforce_object']), |
|
843 | + esc_attr($salesforce_id), |
|
844 | + esc_attr($mapping['wordpress_object']), |
|
845 | + esc_attr($object_id), |
|
846 | + esc_attr($object["$object_id"]) |
|
847 | 847 | ); |
848 | 848 | |
849 | 849 | $logging->setup( |
850 | 850 | $title, |
851 | 851 | '', |
852 | 852 | $sf_sync_trigger, |
853 | - $object[ "$object_id" ], |
|
853 | + $object["$object_id"], |
|
854 | 854 | $status |
855 | 855 | ); |
856 | 856 | |
857 | 857 | // update that mapping object |
858 | 858 | $mapping_object['salesforce_id'] = $salesforce_id; |
859 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
860 | - $mapping_object = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
859 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
860 | + $mapping_object = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
861 | 861 | |
862 | 862 | // hook for push success |
863 | - do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
863 | + do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
864 | 864 | } else { |
865 | 865 | |
866 | 866 | // create log entry for failed create or upsert |
867 | 867 | // 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 |
868 | 868 | // if we see this in the log entries, we can understand what it does, but probably not until then |
869 | 869 | $status = 'error'; |
870 | - if ( isset( $this->logging ) ) { |
|
870 | + if (isset($this->logging)) { |
|
871 | 871 | $logging = $this->logging; |
872 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
873 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
872 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
873 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | // 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 |
877 | - $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' ), |
|
878 | - absint( $salesforce_data['errorCode'] ), |
|
879 | - esc_attr( $op ), |
|
880 | - esc_attr( $mapping['wordpress_object'] ), |
|
881 | - esc_attr( $object_id ), |
|
882 | - esc_attr( $object[ "$object_id" ] ) |
|
877 | + $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'), |
|
878 | + absint($salesforce_data['errorCode']), |
|
879 | + esc_attr($op), |
|
880 | + esc_attr($mapping['wordpress_object']), |
|
881 | + esc_attr($object_id), |
|
882 | + esc_attr($object["$object_id"]) |
|
883 | 883 | ); |
884 | 884 | |
885 | 885 | // translators: placeholders are 1) the name of the Salesforce object type, 2) the error message returned from the Salesforce APIs |
886 | - $body = sprintf( '<p>' . esc_html__( 'Object: %1$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Message: %2$s', 'object-sync-for-salesforce' ) . '</p>', |
|
887 | - esc_attr( $mapping['salesforce_object'] ), |
|
888 | - esc_html( $salesforce_data['message'] ) |
|
886 | + $body = sprintf('<p>' . esc_html__('Object: %1$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Message: %2$s', 'object-sync-for-salesforce') . '</p>', |
|
887 | + esc_attr($mapping['salesforce_object']), |
|
888 | + esc_html($salesforce_data['message']) |
|
889 | 889 | ); |
890 | 890 | |
891 | 891 | $logging->setup( |
892 | 892 | $title, |
893 | 893 | $body, |
894 | 894 | $sf_sync_trigger, |
895 | - $object[ "$object_id" ], |
|
895 | + $object["$object_id"], |
|
896 | 896 | $status |
897 | 897 | ); |
898 | 898 | |
899 | 899 | // hook for push fail |
900 | - do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object ); |
|
900 | + do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object); |
|
901 | 901 | |
902 | 902 | return; |
903 | 903 | } // End if(). |
@@ -905,41 +905,41 @@ discard block |
||
905 | 905 | // $is_new is false here; we are updating an already mapped object |
906 | 906 | |
907 | 907 | // right here we should set the pushing transient |
908 | - set_transient( 'salesforce_pushing_' . $mapping_object['id'], 1, $seconds ); |
|
909 | - set_transient( 'salesforce_pushing_object_id', $mapping_object['id'] ); |
|
908 | + set_transient('salesforce_pushing_' . $mapping_object['id'], 1, $seconds); |
|
909 | + set_transient('salesforce_pushing_object_id', $mapping_object['id']); |
|
910 | 910 | |
911 | 911 | // there is an existing object link |
912 | 912 | // if the last sync is greater than the last time this object was updated, skip it |
913 | 913 | // this keeps us from doing redundant syncs |
914 | - $mapping_object['object_updated'] = current_time( 'mysql' ); |
|
915 | - if ( $mapping_object['last_sync'] > $mapping_object['object_updated'] ) { |
|
914 | + $mapping_object['object_updated'] = current_time('mysql'); |
|
915 | + if ($mapping_object['last_sync'] > $mapping_object['object_updated']) { |
|
916 | 916 | $status = 'notice'; |
917 | - if ( isset( $this->logging ) ) { |
|
917 | + if (isset($this->logging)) { |
|
918 | 918 | $logging = $this->logging; |
919 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
920 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
919 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
920 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | // 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 |
924 | - $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' ), |
|
925 | - esc_attr( $op ), |
|
926 | - esc_attr( $mapping['wordpress_object'] ), |
|
927 | - esc_attr( $object_id ), |
|
928 | - esc_attr( $object[ "$object_id" ] ), |
|
929 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
924 | + $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'), |
|
925 | + esc_attr($op), |
|
926 | + esc_attr($mapping['wordpress_object']), |
|
927 | + esc_attr($object_id), |
|
928 | + esc_attr($object["$object_id"]), |
|
929 | + esc_attr($mapping_object['salesforce_id']) |
|
930 | 930 | ); |
931 | 931 | |
932 | 932 | // translators: placeholders are 1) when a sync on this mapping last occured, 2) when the object was last updated |
933 | - $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>', |
|
934 | - esc_attr( $mapping_object['last_sync'] ), |
|
935 | - esc_html( $mapping_object['object_updated'] ) |
|
933 | + $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>', |
|
934 | + esc_attr($mapping_object['last_sync']), |
|
935 | + esc_html($mapping_object['object_updated']) |
|
936 | 936 | ); |
937 | 937 | |
938 | 938 | $logging->setup( |
939 | 939 | $title, |
940 | 940 | $body, |
941 | 941 | $sf_sync_trigger, |
942 | - $object[ "$object_id" ], |
|
942 | + $object["$object_id"], |
|
943 | 943 | $status |
944 | 944 | ); |
945 | 945 | return; |
@@ -950,71 +950,71 @@ discard block |
||
950 | 950 | |
951 | 951 | // hook to allow other plugins to do something right before Salesforce data is saved |
952 | 952 | // ex: run WordPress methods on an object if it exists, or do something in preparation for it if it doesn't |
953 | - do_action( 'object_sync_for_salesforce_pre_push', $mapping_object['salesforce_id'], $mapping, $object, $object_id, $params ); |
|
953 | + do_action('object_sync_for_salesforce_pre_push', $mapping_object['salesforce_id'], $mapping, $object, $object_id, $params); |
|
954 | 954 | |
955 | 955 | // hook to allow other plugins to change params on update actions only |
956 | 956 | // use hook to map fields between the WordPress and Salesforce objects |
957 | 957 | // returns $params. |
958 | - $params = apply_filters( 'object_sync_for_salesforce_push_update_params_modify', $params, $mapping_object['salesforce_id'], $mapping, $object ); |
|
958 | + $params = apply_filters('object_sync_for_salesforce_push_update_params_modify', $params, $mapping_object['salesforce_id'], $mapping, $object); |
|
959 | 959 | |
960 | 960 | $op = 'Update'; |
961 | - $result = $sfapi->object_update( $mapping['salesforce_object'], $mapping_object['salesforce_id'], $params ); |
|
961 | + $result = $sfapi->object_update($mapping['salesforce_object'], $mapping_object['salesforce_id'], $params); |
|
962 | 962 | |
963 | 963 | $mapping_object['last_sync_status'] = $this->mappings->status_success; |
964 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
964 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
965 | 965 | |
966 | 966 | $status = 'success'; |
967 | - if ( isset( $this->logging ) ) { |
|
967 | + if (isset($this->logging)) { |
|
968 | 968 | $logging = $this->logging; |
969 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
970 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
969 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
970 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | // 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 |
974 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
975 | - esc_attr( $op ), |
|
976 | - esc_attr( $mapping['salesforce_object'] ), |
|
977 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
978 | - esc_attr( $mapping['wordpress_object'] ), |
|
979 | - esc_attr( $object_id ), |
|
980 | - esc_attr( $object[ "$object_id" ] ) |
|
974 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
975 | + esc_attr($op), |
|
976 | + esc_attr($mapping['salesforce_object']), |
|
977 | + esc_attr($mapping_object['salesforce_id']), |
|
978 | + esc_attr($mapping['wordpress_object']), |
|
979 | + esc_attr($object_id), |
|
980 | + esc_attr($object["$object_id"]) |
|
981 | 981 | ); |
982 | 982 | |
983 | 983 | $logging->setup( |
984 | 984 | $title, |
985 | 985 | '', |
986 | 986 | $sf_sync_trigger, |
987 | - $object[ "$object_id" ], |
|
987 | + $object["$object_id"], |
|
988 | 988 | $status |
989 | 989 | ); |
990 | 990 | |
991 | 991 | // hook for push success |
992 | - do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
992 | + do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
993 | 993 | |
994 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
994 | + } catch (Object_Sync_Sf_Exception $e) { |
|
995 | 995 | // create log entry for failed update |
996 | 996 | $status = 'error'; |
997 | - if ( isset( $this->logging ) ) { |
|
997 | + if (isset($this->logging)) { |
|
998 | 998 | $logging = $this->logging; |
999 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1000 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
999 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1000 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | // 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 |
1004 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
1005 | - esc_attr( $op ), |
|
1006 | - esc_attr( $mapping['salesforce_object'] ), |
|
1007 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
1008 | - esc_attr( $mapping['wordpress_object'] ), |
|
1009 | - esc_attr( $object_id ), |
|
1010 | - esc_attr( $object[ "$object_id" ] ) |
|
1004 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
1005 | + esc_attr($op), |
|
1006 | + esc_attr($mapping['salesforce_object']), |
|
1007 | + esc_attr($mapping_object['salesforce_id']), |
|
1008 | + esc_attr($mapping['wordpress_object']), |
|
1009 | + esc_attr($object_id), |
|
1010 | + esc_attr($object["$object_id"]) |
|
1011 | 1011 | ); |
1012 | 1012 | |
1013 | 1013 | $logging->setup( |
1014 | 1014 | $title, |
1015 | 1015 | $e->getMessage(), |
1016 | 1016 | $sf_sync_trigger, |
1017 | - $object[ "$object_id" ], |
|
1017 | + $object["$object_id"], |
|
1018 | 1018 | $status |
1019 | 1019 | ); |
1020 | 1020 | |
@@ -1022,16 +1022,16 @@ discard block |
||
1022 | 1022 | $mapping_object['last_sync_message'] = $e->getMessage(); |
1023 | 1023 | |
1024 | 1024 | // hook for push fail |
1025 | - do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object ); |
|
1025 | + do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object); |
|
1026 | 1026 | |
1027 | 1027 | } // End try(). |
1028 | 1028 | |
1029 | 1029 | // tell the mapping object - whether it is new or already existed - how we just used it |
1030 | 1030 | $mapping_object['last_sync_action'] = 'push'; |
1031 | - $mapping_object['last_sync'] = current_time( 'mysql' ); |
|
1031 | + $mapping_object['last_sync'] = current_time('mysql'); |
|
1032 | 1032 | |
1033 | 1033 | // update that mapping object |
1034 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1034 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1035 | 1035 | |
1036 | 1036 | } // End if(). this is the end of the if is_new stuff |
1037 | 1037 | |
@@ -1053,9 +1053,9 @@ discard block |
||
1053 | 1053 | * This is the database row for the map object |
1054 | 1054 | * |
1055 | 1055 | */ |
1056 | - private function create_object_map( $wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false ) { |
|
1056 | + private function create_object_map($wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false) { |
|
1057 | 1057 | |
1058 | - if ( true === $pending ) { |
|
1058 | + if (true === $pending) { |
|
1059 | 1059 | $action = 'pending'; |
1060 | 1060 | } else { |
1061 | 1061 | $action = 'created'; |
@@ -1064,15 +1064,15 @@ discard block |
||
1064 | 1064 | // Create object map and save it |
1065 | 1065 | $mapping_object = $this->mappings->create_object_map( |
1066 | 1066 | array( |
1067 | - 'wordpress_id' => $wordpress_object[ $id_field_name ], // wordpress unique id |
|
1067 | + 'wordpress_id' => $wordpress_object[$id_field_name], // wordpress unique id |
|
1068 | 1068 | 'salesforce_id' => $salesforce_id, // salesforce unique id. we don't care what kind of object it is at this point |
1069 | 1069 | 'wordpress_object' => $field_mapping['wordpress_object'], // keep track of what kind of wp object this is |
1070 | - 'last_sync' => current_time( 'mysql' ), |
|
1070 | + 'last_sync' => current_time('mysql'), |
|
1071 | 1071 | 'last_sync_action' => 'push', |
1072 | 1072 | 'last_sync_status' => $this->mappings->status_success, |
1073 | 1073 | // translators: placeholder is for the action that occurred on the mapping object (pending or created) |
1074 | - 'last_sync_message' => sprintf( esc_html__( 'Mapping object %1$s via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
1075 | - esc_attr( $action ) |
|
1074 | + 'last_sync_message' => sprintf(esc_html__('Mapping object %1$s via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
1075 | + esc_attr($action) |
|
1076 | 1076 | ), |
1077 | 1077 | 'action' => $action, |
1078 | 1078 | ) |
@@ -25,18 +25,18 @@ discard block |
||
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 | |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Create the actions to run |
|
64 | - * |
|
65 | - */ |
|
63 | + * Create the actions to run |
|
64 | + * |
|
65 | + */ |
|
66 | 66 | public function add_actions() { |
67 | 67 | |
68 | 68 | // create a recurring action for each schedulable item |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | - * Convert the schedule frequency from the admin settings into an array |
|
107 | - * interval must be in seconds for the class to use it |
|
108 | - * |
|
109 | - */ |
|
106 | + * Convert the schedule frequency from the admin settings into an array |
|
107 | + * interval must be in seconds for the class to use it |
|
108 | + * |
|
109 | + */ |
|
110 | 110 | public function set_schedule_frequency( $schedules ) { |
111 | 111 | |
112 | 112 | // create an option in the core schedules array for each one the plugin defines |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Convert the schedule frequency from the admin settings into an array |
|
148 | - * interval must be in seconds for the class to use it |
|
149 | - * |
|
150 | - */ |
|
147 | + * Convert the schedule frequency from the admin settings into an array |
|
148 | + * interval must be in seconds for the class to use it |
|
149 | + * |
|
150 | + */ |
|
151 | 151 | public function get_schedule_frequency_key( $name = '' ) { |
152 | 152 | |
153 | 153 | $schedule_number = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_number', '' ); |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Convert the schedule frequency from the admin settings into seconds |
|
178 | - * |
|
179 | - */ |
|
177 | + * Convert the schedule frequency from the admin settings into seconds |
|
178 | + * |
|
179 | + */ |
|
180 | 180 | public function get_schedule_frequency_seconds( $name = '' ) { |
181 | 181 | |
182 | 182 | $schedule_number = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_number', '' ); |
@@ -5,7 +5,7 @@ discard block |
||
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 |
||
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; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | //$this->add_actions(); |
57 | 57 | //add_action( $this->schedule_name, array( $this, 'maybe_handle' ) ); // run the handle method |
58 | - add_action( 'init', array( $this, 'add_actions' ) ); |
|
58 | + add_action('init', array($this, 'add_actions')); |
|
59 | 59 | |
60 | 60 | } |
61 | 61 | |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | public function add_actions() { |
67 | 67 | |
68 | 68 | // create a recurring action for each schedulable item |
69 | - foreach ( $this->schedulable_classes as $key => $value ) { |
|
69 | + foreach ($this->schedulable_classes as $key => $value) { |
|
70 | 70 | |
71 | - $schedule_number = absint( get_option( 'object_sync_for_salesforce_' . $key . '_schedule_number', '' ) ); |
|
72 | - $schedule_unit = get_option( 'object_sync_for_salesforce_' . $key . '_schedule_unit', '' ); |
|
71 | + $schedule_number = absint(get_option('object_sync_for_salesforce_' . $key . '_schedule_number', '')); |
|
72 | + $schedule_unit = get_option('object_sync_for_salesforce_' . $key . '_schedule_unit', ''); |
|
73 | 73 | |
74 | - switch ( $schedule_unit ) { |
|
74 | + switch ($schedule_unit) { |
|
75 | 75 | case 'minutes': |
76 | 76 | $seconds = 60; |
77 | 77 | break; |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | |
88 | 88 | $key = $schedule_unit . '_' . $schedule_number; |
89 | 89 | |
90 | - if ( isset( $value['initializer'] ) ) { |
|
90 | + if (isset($value['initializer'])) { |
|
91 | 91 | |
92 | - $time = current_time( 'timestamp' ); |
|
92 | + $time = current_time('timestamp'); |
|
93 | 93 | //$hook = $value['class']->$value['initializer']; |
94 | 94 | $hook = $value['class'] . '->' . $value['initializer']; |
95 | 95 | //echo 'hook is ' . $hook; |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | * interval must be in seconds for the class to use it |
108 | 108 | * |
109 | 109 | */ |
110 | - public function set_schedule_frequency( $schedules ) { |
|
110 | + public function set_schedule_frequency($schedules) { |
|
111 | 111 | |
112 | 112 | // create an option in the core schedules array for each one the plugin defines |
113 | - foreach ( $this->schedulable_classes as $key => $value ) { |
|
114 | - $schedule_number = absint( get_option( 'object_sync_for_salesforce_' . $key . '_schedule_number', '' ) ); |
|
115 | - $schedule_unit = get_option( 'object_sync_for_salesforce_' . $key . '_schedule_unit', '' ); |
|
113 | + foreach ($this->schedulable_classes as $key => $value) { |
|
114 | + $schedule_number = absint(get_option('object_sync_for_salesforce_' . $key . '_schedule_number', '')); |
|
115 | + $schedule_unit = get_option('object_sync_for_salesforce_' . $key . '_schedule_unit', ''); |
|
116 | 116 | |
117 | - switch ( $schedule_unit ) { |
|
117 | + switch ($schedule_unit) { |
|
118 | 118 | case 'minutes': |
119 | 119 | $seconds = 60; |
120 | 120 | break; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | $key = $schedule_unit . '_' . $schedule_number; |
132 | 132 | |
133 | - $schedules[ $key ] = array( |
|
133 | + $schedules[$key] = array( |
|
134 | 134 | 'interval' => $seconds * $schedule_number, |
135 | 135 | 'display' => 'Every ' . $schedule_number . ' ' . $schedule_unit, |
136 | 136 | ); |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | * interval must be in seconds for the class to use it |
149 | 149 | * |
150 | 150 | */ |
151 | - public function get_schedule_frequency_key( $name = '' ) { |
|
151 | + public function get_schedule_frequency_key($name = '') { |
|
152 | 152 | |
153 | - $schedule_number = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_number', '' ); |
|
154 | - $schedule_unit = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_unit', '' ); |
|
153 | + $schedule_number = get_option('object_sync_for_salesforce_' . $name . '_schedule_number', ''); |
|
154 | + $schedule_unit = get_option('object_sync_for_salesforce_' . $name . '_schedule_unit', ''); |
|
155 | 155 | |
156 | - switch ( $schedule_unit ) { |
|
156 | + switch ($schedule_unit) { |
|
157 | 157 | case 'minutes': |
158 | 158 | $seconds = 60; |
159 | 159 | break; |
@@ -177,12 +177,12 @@ discard block |
||
177 | 177 | * Convert the schedule frequency from the admin settings into seconds |
178 | 178 | * |
179 | 179 | */ |
180 | - public function get_schedule_frequency_seconds( $name = '' ) { |
|
180 | + public function get_schedule_frequency_seconds($name = '') { |
|
181 | 181 | |
182 | - $schedule_number = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_number', '' ); |
|
183 | - $schedule_unit = get_option( 'object_sync_for_salesforce_' . $name . '_schedule_unit', '' ); |
|
182 | + $schedule_number = get_option('object_sync_for_salesforce_' . $name . '_schedule_number', ''); |
|
183 | + $schedule_unit = get_option('object_sync_for_salesforce_' . $name . '_schedule_unit', ''); |
|
184 | 184 | |
185 | - switch ( $schedule_unit ) { |
|
185 | + switch ($schedule_unit) { |
|
186 | 186 | case 'minutes': |
187 | 187 | $seconds = 60; |
188 | 188 | break; |
@@ -208,18 +208,18 @@ discard block |
||
208 | 208 | * |
209 | 209 | * @return void |
210 | 210 | */ |
211 | - public function use_schedule( $name = '' ) { |
|
211 | + public function use_schedule($name = '') { |
|
212 | 212 | |
213 | - if ( '' !== $name ) { |
|
213 | + if ('' !== $name) { |
|
214 | 214 | $schedule_name = $name; |
215 | 215 | } else { |
216 | 216 | $schedule_name = $this->schedule_name; |
217 | 217 | } |
218 | 218 | |
219 | - $schedule_frequency = $this->get_schedule_frequency_key( $name ); |
|
219 | + $schedule_frequency = $this->get_schedule_frequency_key($name); |
|
220 | 220 | |
221 | - if ( ! wp_next_scheduled( $schedule_name ) ) { |
|
222 | - wp_schedule_event( time(), $schedule_frequency, $schedule_name ); |
|
221 | + if ( ! wp_next_scheduled($schedule_name)) { |
|
222 | + wp_schedule_event(time(), $schedule_frequency, $schedule_name); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | } |
@@ -236,13 +236,13 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return mixed |
238 | 238 | */ |
239 | - protected function task( $data ) { |
|
240 | - if ( is_array( $this->schedulable_classes[ $this->schedule_name ] ) ) { |
|
241 | - $schedule = $this->schedulable_classes[ $this->schedule_name ]; |
|
242 | - if ( isset( $schedule['class'] ) ) { |
|
243 | - $class = new $schedule['class']( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes ); |
|
239 | + protected function task($data) { |
|
240 | + if (is_array($this->schedulable_classes[$this->schedule_name])) { |
|
241 | + $schedule = $this->schedulable_classes[$this->schedule_name]; |
|
242 | + if (isset($schedule['class'])) { |
|
243 | + $class = new $schedule['class']($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes); |
|
244 | 244 | $method = $schedule['callback']; |
245 | - $task = $class->$method( $data['object_type'], $data['object'], $data['mapping'], $data['sf_sync_trigger'] ); |
|
245 | + $task = $class->$method($data['object_type'], $data['object'], $data['mapping'], $data['sf_sync_trigger']); |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | return false; |
@@ -258,17 +258,17 @@ discard block |
||
258 | 258 | * @return $data |
259 | 259 | */ |
260 | 260 | protected function check_for_data() { |
261 | - if ( is_array( $this->schedulable_classes[ $this->schedule_name ] ) ) { |
|
262 | - $schedule = $this->schedulable_classes[ $this->schedule_name ]; |
|
263 | - if ( isset( $schedule['class'] ) ) { |
|
264 | - $class = new $schedule['class']( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes ); |
|
261 | + if (is_array($this->schedulable_classes[$this->schedule_name])) { |
|
262 | + $schedule = $this->schedulable_classes[$this->schedule_name]; |
|
263 | + if (isset($schedule['class'])) { |
|
264 | + $class = new $schedule['class']($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes); |
|
265 | 265 | $method = $schedule['initializer']; |
266 | 266 | $task = $class->$method(); |
267 | 267 | } |
268 | 268 | } |
269 | 269 | // we have checked for data and it's in the queue if it exists |
270 | 270 | // now run maybe_handle again to see if it nees to be processed |
271 | - $this->maybe_handle( true ); |
|
271 | + $this->maybe_handle(true); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * Checks whether data exists within the queue and that |
278 | 278 | * the process is not already running. |
279 | 279 | */ |
280 | - public function maybe_handle( $already_checked = false, $ajax = false ) { |
|
281 | - if ( $this->is_process_running() ) { |
|
280 | + public function maybe_handle($already_checked = false, $ajax = false) { |
|
281 | + if ($this->is_process_running()) { |
|
282 | 282 | // Background process already running. |
283 | 283 | wp_die(); |
284 | 284 | } |
@@ -287,19 +287,19 @@ discard block |
||
287 | 287 | // it should call its corresponding class method that saves data to the queue |
288 | 288 | // it should then run maybe_handle() again |
289 | 289 | |
290 | - $check_for_data_first = isset( $this->schedulable_classes[ $this->schedule_name ]['initializer'] ) ? true : false; |
|
290 | + $check_for_data_first = isset($this->schedulable_classes[$this->schedule_name]['initializer']) ? true : false; |
|
291 | 291 | |
292 | - if ( false === $already_checked && true === $check_for_data_first ) { |
|
292 | + if (false === $already_checked && true === $check_for_data_first) { |
|
293 | 293 | $this->check_for_data(); |
294 | 294 | } |
295 | 295 | |
296 | - if ( $this->is_queue_empty() ) { |
|
296 | + if ($this->is_queue_empty()) { |
|
297 | 297 | // No data to process. |
298 | 298 | wp_die(); |
299 | 299 | } |
300 | 300 | |
301 | - if ( true === $ajax ) { |
|
302 | - check_ajax_referer( $this->identifier, 'nonce' ); |
|
301 | + if (true === $ajax) { |
|
302 | + check_ajax_referer($this->identifier, 'nonce'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | $this->handle(); |
@@ -311,15 +311,15 @@ discard block |
||
311 | 311 | * |
312 | 312 | * 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 |
313 | 313 | */ |
314 | - public function cancel_by_name( $name ) { |
|
315 | - if ( ! isset( $name ) ) { |
|
314 | + public function cancel_by_name($name) { |
|
315 | + if ( ! isset($name)) { |
|
316 | 316 | $name = $this->identifier . '_cron'; |
317 | 317 | } |
318 | - if ( ! $this->is_queue_empty() ) { |
|
319 | - while ( $this->count_queue_items() > 0 ) { |
|
318 | + if ( ! $this->is_queue_empty()) { |
|
319 | + while ($this->count_queue_items() > 0) { |
|
320 | 320 | $batch = $this->get_batch(); |
321 | - $this->delete( $batch->key ); |
|
322 | - wp_clear_scheduled_hook( $name ); |
|
321 | + $this->delete($batch->key); |
|
322 | + wp_clear_scheduled_hook($name); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | } |
@@ -330,28 +330,28 @@ discard block |
||
330 | 330 | * |
331 | 331 | * @return bool |
332 | 332 | */ |
333 | - public function count_queue_items( $schedule_name = '' ) { |
|
333 | + public function count_queue_items($schedule_name = '') { |
|
334 | 334 | $wpdb = $this->wpdb; |
335 | 335 | |
336 | 336 | $table = $wpdb->options; |
337 | 337 | $column = 'option_name'; |
338 | 338 | |
339 | - if ( is_multisite() ) { |
|
339 | + if (is_multisite()) { |
|
340 | 340 | $table = $wpdb->sitemeta; |
341 | 341 | $column = 'meta_key'; |
342 | 342 | } |
343 | 343 | |
344 | - if ( '' === $schedule_name ) { |
|
344 | + if ('' === $schedule_name) { |
|
345 | 345 | $key = $this->identifier . '_batch_%'; |
346 | 346 | } else { |
347 | 347 | $key = $schedule_name . '_batch_%'; |
348 | 348 | } |
349 | 349 | |
350 | - $count = $wpdb->get_var( $wpdb->prepare( " |
|
350 | + $count = $wpdb->get_var($wpdb->prepare(" |
|
351 | 351 | SELECT COUNT(*) |
352 | 352 | FROM {$table} |
353 | 353 | WHERE {$column} LIKE %s |
354 | - ", $key ) ); |
|
354 | + ", $key)); |
|
355 | 355 | |
356 | 356 | return $count; |
357 | 357 | } |
@@ -5,7 +5,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | // I think it's good to over-mention that updateable is really how the Salesforce api spells it. |
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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,20 +677,20 @@ discard block |
||
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 | $wordpress_field = $fieldmap['wordpress_field']['label']; |
692 | 692 | |
693 | - if ( version_compare( $this->version, '1.2.0', '>=' ) && isset( $fieldmap['salesforce_field']['name'] ) ) { |
|
693 | + if (version_compare($this->version, '1.2.0', '>=') && isset($fieldmap['salesforce_field']['name'])) { |
|
694 | 694 | $salesforce_field = $fieldmap['salesforce_field']['name']; |
695 | 695 | // 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. |
696 | 696 | $salesforce_field_type = $fieldmap['salesforce_field']['type']; |
@@ -699,113 +699,113 @@ discard block |
||
699 | 699 | } |
700 | 700 | |
701 | 701 | // A WordPress event caused this. |
702 | - if ( in_array( $trigger, array_values( $wordpress_haystack ), true ) ) { |
|
702 | + if (in_array($trigger, array_values($wordpress_haystack), true)) { |
|
703 | 703 | |
704 | 704 | // Is the field in WordPress an array, if we unserialize it? Salesforce wants it to be an imploded string. |
705 | - if ( is_array( maybe_unserialize( $object[ $wordpress_field ] ) ) ) { |
|
706 | - $object[ $wordpress_field ] = implode( $this->array_delimiter, $object[ $wordpress_field ] ); |
|
705 | + if (is_array(maybe_unserialize($object[$wordpress_field]))) { |
|
706 | + $object[$wordpress_field] = implode($this->array_delimiter, $object[$wordpress_field]); |
|
707 | 707 | } |
708 | 708 | |
709 | - if ( isset( $salesforce_field_type ) ) { |
|
709 | + if (isset($salesforce_field_type)) { |
|
710 | 710 | // Is the Salesforce field a date, and is the WordPress value a valid date? |
711 | 711 | // According to https://salesforce.stackexchange.com/questions/57032/date-format-with-salesforce-rest-api |
712 | - if ( in_array( $salesforce_field_type, $this->date_types_from_salesforce ) ) { |
|
713 | - if ( '' === $object[ $wordpress_field ] ) { |
|
714 | - $object[ $wordpress_field ] = null; |
|
712 | + if (in_array($salesforce_field_type, $this->date_types_from_salesforce)) { |
|
713 | + if ('' === $object[$wordpress_field]) { |
|
714 | + $object[$wordpress_field] = null; |
|
715 | 715 | } else { |
716 | - if ( false !== strtotime( $object[ $wordpress_field ] ) ) { |
|
717 | - $timestamp = strtotime( $object[ $wordpress_field ] ); |
|
716 | + if (false !== strtotime($object[$wordpress_field])) { |
|
717 | + $timestamp = strtotime($object[$wordpress_field]); |
|
718 | 718 | } else { |
719 | - $timestamp = $object[ $wordpress_field ]; |
|
719 | + $timestamp = $object[$wordpress_field]; |
|
720 | 720 | } |
721 | - if ( 'datetime' === $salesforce_field_type ) { |
|
722 | - $object[ $wordpress_field ] = date_i18n( 'c', $timestamp ); |
|
721 | + if ('datetime' === $salesforce_field_type) { |
|
722 | + $object[$wordpress_field] = date_i18n('c', $timestamp); |
|
723 | 723 | } else { |
724 | - $object[ $wordpress_field ] = date_i18n( 'Y-m-d', $timestamp ); |
|
724 | + $object[$wordpress_field] = date_i18n('Y-m-d', $timestamp); |
|
725 | 725 | } |
726 | 726 | } |
727 | 727 | } |
728 | 728 | |
729 | 729 | // Boolean SF fields only want real boolean values. NULL is also not allowed. |
730 | - if ( 'boolean' === $salesforce_field_type ) { |
|
731 | - $object[ $wordpress_field ] = (bool) $object[ $wordpress_field ]; |
|
730 | + if ('boolean' === $salesforce_field_type) { |
|
731 | + $object[$wordpress_field] = (bool) $object[$wordpress_field]; |
|
732 | 732 | } |
733 | 733 | } |
734 | 734 | |
735 | - $params[ $salesforce_field ] = $object[ $wordpress_field ]; |
|
735 | + $params[$salesforce_field] = $object[$wordpress_field]; |
|
736 | 736 | |
737 | 737 | // If the field is a key in Salesforce, remove it from $params to avoid upsert errors from Salesforce, |
738 | 738 | // but still put its name in the params array so we can check for it later. |
739 | - if ( '1' === $fieldmap['is_key'] ) { |
|
740 | - if ( ! $use_soap ) { |
|
741 | - unset( $params[ $salesforce_field ] ); |
|
739 | + if ('1' === $fieldmap['is_key']) { |
|
740 | + if ( ! $use_soap) { |
|
741 | + unset($params[$salesforce_field]); |
|
742 | 742 | } |
743 | 743 | $params['key'] = array( |
744 | 744 | 'salesforce_field' => $salesforce_field, |
745 | 745 | 'wordpress_field' => $wordpress_field, |
746 | - 'value' => $object[ $wordpress_field ], |
|
746 | + 'value' => $object[$wordpress_field], |
|
747 | 747 | ); |
748 | 748 | } |
749 | 749 | |
750 | 750 | // If the field is a prematch in Salesforce, put its name in the params array so we can check for it later. |
751 | - if ( '1' === $fieldmap['is_prematch'] ) { |
|
751 | + if ('1' === $fieldmap['is_prematch']) { |
|
752 | 752 | $params['prematch'] = array( |
753 | 753 | 'salesforce_field' => $salesforce_field, |
754 | 754 | 'wordpress_field' => $wordpress_field, |
755 | - 'value' => $object[ $wordpress_field ], |
|
755 | + 'value' => $object[$wordpress_field], |
|
756 | 756 | ); |
757 | 757 | } |
758 | 758 | |
759 | 759 | // Skip fields that aren't being pushed to Salesforce. |
760 | - if ( ! in_array( $fieldmap['direction'], array_values( $this->direction_wordpress ), true ) ) { |
|
760 | + if ( ! in_array($fieldmap['direction'], array_values($this->direction_wordpress), true)) { |
|
761 | 761 | // The trigger is a WordPress trigger, but the fieldmap direction is not a WordPress direction. |
762 | - unset( $params[ $salesforce_field ] ); |
|
762 | + unset($params[$salesforce_field]); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | // I think it's good to over-mention that updateable is really how the Salesforce api spells it. |
766 | 766 | // Skip fields that aren't updateable when mapping params because Salesforce will error otherwise. |
767 | 767 | // This happens after dealing with the field types because key and prematch should still be available to the plugin, even if the values are not updateable in Salesforce. |
768 | - if ( 1 !== (int) $fieldmap['salesforce_field']['updateable'] ) { |
|
769 | - unset( $params[ $salesforce_field ] ); |
|
768 | + if (1 !== (int) $fieldmap['salesforce_field']['updateable']) { |
|
769 | + unset($params[$salesforce_field]); |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | // we don't need a continue with the unset methods because there's no array being created down here |
773 | - } elseif ( in_array( $trigger, $salesforce_haystack, true ) ) { |
|
773 | + } elseif (in_array($trigger, $salesforce_haystack, true)) { |
|
774 | 774 | |
775 | 775 | // A Salesforce event caused this. |
776 | 776 | |
777 | - if ( isset( $salesforce_field_type ) && ! is_null( $object[ $salesforce_field ] ) ) { |
|
777 | + if (isset($salesforce_field_type) && ! is_null($object[$salesforce_field])) { |
|
778 | 778 | // Salesforce provides multipicklist values as a delimited string. If the |
779 | 779 | // destination field in WordPress accepts multiple values, explode the string into an array and then serialize it. |
780 | - if ( in_array( $salesforce_field_type, $this->array_types_from_salesforce ) ) { |
|
781 | - $object[ $salesforce_field ] = explode( $this->array_delimiter, $object[ $salesforce_field ] ); |
|
780 | + if (in_array($salesforce_field_type, $this->array_types_from_salesforce)) { |
|
781 | + $object[$salesforce_field] = explode($this->array_delimiter, $object[$salesforce_field]); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | // Handle specific data types from Salesforce. |
785 | - switch ( $salesforce_field_type ) { |
|
786 | - case ( in_array( $salesforce_field_type, $this->date_types_from_salesforce ) ): |
|
787 | - $format = get_option( 'date_format', 'U' ); |
|
788 | - if ( isset( $fieldmap['wordpress_field']['type'] ) && 'datetime' === $fieldmap['wordpress_field']['type'] ) { |
|
785 | + switch ($salesforce_field_type) { |
|
786 | + case (in_array($salesforce_field_type, $this->date_types_from_salesforce)): |
|
787 | + $format = get_option('date_format', 'U'); |
|
788 | + if (isset($fieldmap['wordpress_field']['type']) && 'datetime' === $fieldmap['wordpress_field']['type']) { |
|
789 | 789 | $format = 'Y-m-d H:i:s'; |
790 | 790 | } |
791 | - $object[ $salesforce_field ] = date_i18n( $format, strtotime( $object[ $salesforce_field ] ) ); |
|
791 | + $object[$salesforce_field] = date_i18n($format, strtotime($object[$salesforce_field])); |
|
792 | 792 | break; |
793 | - case ( in_array( $salesforce_field_type, $this->int_types_from_salesforce ) ): |
|
794 | - $object[ $salesforce_field ] = isset( $object[ $salesforce_field ] ) ? (int) $object[ $salesforce_field ] : 0; |
|
793 | + case (in_array($salesforce_field_type, $this->int_types_from_salesforce)): |
|
794 | + $object[$salesforce_field] = isset($object[$salesforce_field]) ? (int) $object[$salesforce_field] : 0; |
|
795 | 795 | break; |
796 | 796 | case 'text': |
797 | - $object[ $salesforce_field ] = (string) $object[ $salesforce_field ]; |
|
797 | + $object[$salesforce_field] = (string) $object[$salesforce_field]; |
|
798 | 798 | break; |
799 | 799 | case 'url': |
800 | - $object[ $salesforce_field ] = esc_url_raw( $object[ $salesforce_field ] ); |
|
800 | + $object[$salesforce_field] = esc_url_raw($object[$salesforce_field]); |
|
801 | 801 | break; |
802 | 802 | } |
803 | 803 | } |
804 | 804 | |
805 | 805 | // Make an array because we need to store the methods for each field as well. |
806 | - if ( '' !== $object[ $salesforce_field ] ) { |
|
807 | - $params[ $wordpress_field ] = array(); |
|
808 | - $params[ $wordpress_field ]['value'] = $object[ $salesforce_field ]; |
|
806 | + if ('' !== $object[$salesforce_field]) { |
|
807 | + $params[$wordpress_field] = array(); |
|
808 | + $params[$wordpress_field]['value'] = $object[$salesforce_field]; |
|
809 | 809 | } else { |
810 | 810 | // If we try to save certain fields with empty values, WordPress will silently start skipping stuff. This keeps that from happening. |
811 | 811 | continue; |
@@ -814,11 +814,11 @@ discard block |
||
814 | 814 | // If the field is a key in Salesforce, disregard since this is caused by a Salesforce event. We're setting up data to be stored in WordPress here, and WordPress is not concerned with external key designations in Salesforce. |
815 | 815 | |
816 | 816 | // If the field is a prematch in Salesforce, put its name in the params array so we can check for it later. |
817 | - if ( '1' === $fieldmap['is_prematch'] ) { |
|
817 | + if ('1' === $fieldmap['is_prematch']) { |
|
818 | 818 | $params['prematch'] = 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,26 +826,26 @@ discard block |
||
826 | 826 | } |
827 | 827 | |
828 | 828 | // Skip fields that aren't being pulled from Salesforce. |
829 | - if ( ! in_array( $fieldmap['direction'], array_values( $this->direction_salesforce ), true ) ) { |
|
829 | + if ( ! in_array($fieldmap['direction'], array_values($this->direction_salesforce), true)) { |
|
830 | 830 | // The trigger is a Salesforce trigger, but the fieldmap direction is not a Salesforce direction. |
831 | - unset( $params[ $wordpress_field ] ); |
|
831 | + unset($params[$wordpress_field]); |
|
832 | 832 | // we also need to continue here, so it doesn't create an empty array below for fields that are WordPress -> Salesforce only |
833 | 833 | continue; |
834 | 834 | } |
835 | 835 | |
836 | - switch ( $trigger ) { |
|
836 | + switch ($trigger) { |
|
837 | 837 | case $this->sync_sf_create: |
838 | - $params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['create']; |
|
838 | + $params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['create']; |
|
839 | 839 | break; |
840 | 840 | case $this->sync_sf_update: |
841 | - $params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['update']; |
|
841 | + $params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['update']; |
|
842 | 842 | break; |
843 | 843 | case $this->sync_sf_delete: |
844 | - $params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['delete']; |
|
844 | + $params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['delete']; |
|
845 | 845 | break; |
846 | 846 | } |
847 | 847 | |
848 | - $params[ $wordpress_field ]['method_read'] = $fieldmap['wordpress_field']['methods']['read']; |
|
848 | + $params[$wordpress_field]['method_read'] = $fieldmap['wordpress_field']['methods']['read']; |
|
849 | 849 | |
850 | 850 | } // End if(). |
851 | 851 | } // End foreach(). |
@@ -862,14 +862,14 @@ discard block |
||
862 | 862 | * |
863 | 863 | * @return array $mappings Associative array of field maps ready to use |
864 | 864 | */ |
865 | - private function prepare_fieldmap_data( $mappings, $record_type = '' ) { |
|
866 | - |
|
867 | - foreach ( $mappings as $id => $mapping ) { |
|
868 | - $mappings[ $id ]['salesforce_record_types_allowed'] = maybe_unserialize( $mapping['salesforce_record_types_allowed'] ); |
|
869 | - $mappings[ $id ]['fields'] = maybe_unserialize( $mapping['fields'] ); |
|
870 | - $mappings[ $id ]['sync_triggers'] = maybe_unserialize( $mapping['sync_triggers'] ); |
|
871 | - if ( '' !== $record_type && ! in_array( $record_type, $mappings[ $id ]['salesforce_record_types_allowed'], true ) ) { |
|
872 | - unset( $mappings[ $id ] ); |
|
865 | + private function prepare_fieldmap_data($mappings, $record_type = '') { |
|
866 | + |
|
867 | + foreach ($mappings as $id => $mapping) { |
|
868 | + $mappings[$id]['salesforce_record_types_allowed'] = maybe_unserialize($mapping['salesforce_record_types_allowed']); |
|
869 | + $mappings[$id]['fields'] = maybe_unserialize($mapping['fields']); |
|
870 | + $mappings[$id]['sync_triggers'] = maybe_unserialize($mapping['sync_triggers']); |
|
871 | + if ('' !== $record_type && ! in_array($record_type, $mappings[$id]['salesforce_record_types_allowed'], true)) { |
|
872 | + unset($mappings[$id]); |
|
873 | 873 | } |
874 | 874 | } |
875 | 875 | |
@@ -885,12 +885,12 @@ discard block |
||
885 | 885 | public function get_failed_object_maps() { |
886 | 886 | $table = $this->object_map_table; |
887 | 887 | $errors = array(); |
888 | - $push_errors = $this->wpdb->get_results( 'SELECT * FROM ' . $table . ' WHERE salesforce_id LIKE "tmp_sf_%"', ARRAY_A ); |
|
889 | - $pull_errors = $this->wpdb->get_results( 'SELECT * FROM ' . $table . ' WHERE wordpress_id LIKE "tmp_wp_%"', ARRAY_A ); |
|
890 | - if ( ! empty( $push_errors ) ) { |
|
888 | + $push_errors = $this->wpdb->get_results('SELECT * FROM ' . $table . ' WHERE salesforce_id LIKE "tmp_sf_%"', ARRAY_A); |
|
889 | + $pull_errors = $this->wpdb->get_results('SELECT * FROM ' . $table . ' WHERE wordpress_id LIKE "tmp_wp_%"', ARRAY_A); |
|
890 | + if ( ! empty($push_errors)) { |
|
891 | 891 | $errors['push_errors'] = $push_errors; |
892 | 892 | } |
893 | - if ( ! empty( $pull_errors ) ) { |
|
893 | + if ( ! empty($pull_errors)) { |
|
894 | 894 | $errors['pull_errors'] = $pull_errors; |
895 | 895 | } |
896 | 896 | return $errors; |
@@ -903,11 +903,11 @@ discard block |
||
903 | 903 | * |
904 | 904 | * @return array $error Associative array of single row that failed to finish based on id |
905 | 905 | */ |
906 | - public function get_failed_object_map( $id ) { |
|
906 | + public function get_failed_object_map($id) { |
|
907 | 907 | $table = $this->object_map_table; |
908 | 908 | $error = array(); |
909 | - $error_row = $this->wpdb->get_row( 'SELECT * FROM ' . $table . ' WHERE id = "' . $id . '"', ARRAY_A ); |
|
910 | - if ( ! empty( $error_row ) ) { |
|
909 | + $error_row = $this->wpdb->get_row('SELECT * FROM ' . $table . ' WHERE id = "' . $id . '"', ARRAY_A); |
|
910 | + if ( ! empty($error_row)) { |
|
911 | 911 | $error = $error_row; |
912 | 912 | } |
913 | 913 | return $error; |
@@ -25,25 +25,25 @@ discard block |
||
25 | 25 | protected $queue; |
26 | 26 | |
27 | 27 | /** |
28 | - * @var string |
|
29 | - */ |
|
28 | + * @var string |
|
29 | + */ |
|
30 | 30 | public $schedule_name; // allow for naming the queue in case there are multiple queues |
31 | 31 | |
32 | 32 | /** |
33 | - * Constructor which sets up pull schedule |
|
34 | - * |
|
35 | - * @param object $wpdb |
|
36 | - * @param string $version |
|
37 | - * @param array $login_credentials |
|
38 | - * @param string $slug |
|
39 | - * @param object $wordpress |
|
40 | - * @param object $salesforce |
|
41 | - * @param object $mappings |
|
42 | - * @param object $logging |
|
43 | - * @param array $schedulable_classes |
|
44 | - * @param object $queue |
|
45 | - * @throws \Exception |
|
46 | - */ |
|
33 | + * Constructor which sets up pull schedule |
|
34 | + * |
|
35 | + * @param object $wpdb |
|
36 | + * @param string $version |
|
37 | + * @param array $login_credentials |
|
38 | + * @param string $slug |
|
39 | + * @param object $wordpress |
|
40 | + * @param object $salesforce |
|
41 | + * @param object $mappings |
|
42 | + * @param object $logging |
|
43 | + * @param array $schedulable_classes |
|
44 | + * @param object $queue |
|
45 | + * @throws \Exception |
|
46 | + */ |
|
47 | 47 | public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
48 | 48 | $this->wpdb = $wpdb; |
49 | 49 | $this->version = $version; |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | - * Create the action hooks based on what object maps exist from the admin settings |
|
70 | - * |
|
71 | - */ |
|
69 | + * Create the action hooks based on what object maps exist from the admin settings |
|
70 | + * |
|
71 | + */ |
|
72 | 72 | public function add_actions() { |
73 | 73 | |
74 | 74 | // ajax hook |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | - * Ajax callback for salesforce pull. Returns status of 200 for successful |
|
84 | - * attempt or 403 for a failed pull attempt (SF not authorized, threshhold |
|
85 | - * reached, etc. |
|
86 | - * this is the ajax callback; not a cron run |
|
87 | - */ |
|
83 | + * Ajax callback for salesforce pull. Returns status of 200 for successful |
|
84 | + * attempt or 403 for a failed pull attempt (SF not authorized, threshhold |
|
85 | + * reached, etc. |
|
86 | + * this is the ajax callback; not a cron run |
|
87 | + */ |
|
88 | 88 | public function salesforce_pull_webhook() { |
89 | 89 | |
90 | 90 | if ( true === $this->salesforce_pull() ) { |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Callback for the standard pull process used by webhooks and cron. |
|
114 | - */ |
|
113 | + * Callback for the standard pull process used by webhooks and cron. |
|
114 | + */ |
|
115 | 115 | public function salesforce_pull() { |
116 | 116 | $sfapi = $this->salesforce['sfapi']; |
117 | 117 | |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | - * Determines if the Salesforce pull should be allowed, or throttled. |
|
135 | - * |
|
136 | - * Prevents too many pull processes from running at once. |
|
137 | - * |
|
138 | - * @return bool |
|
139 | - * Returns false if the time elapsed between recent pulls is too short. |
|
140 | - */ |
|
134 | + * Determines if the Salesforce pull should be allowed, or throttled. |
|
135 | + * |
|
136 | + * Prevents too many pull processes from running at once. |
|
137 | + * |
|
138 | + * @return bool |
|
139 | + * Returns false if the time elapsed between recent pulls is too short. |
|
140 | + */ |
|
141 | 141 | private function check_throttle() { |
142 | 142 | $pull_throttle = get_option( 'object_sync_for_salesforce_pull_throttle', 5 ); |
143 | 143 | $last_sync = get_option( 'object_sync_for_salesforce_pull_last_sync', 0 ); |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
153 | - * Pull updated records from Salesforce and place them in the queue. |
|
154 | - * |
|
155 | - * Executes a SOQL query based on defined mappings, loops through the results, |
|
156 | - * and places each updated SF object into the queue for later processing. |
|
157 | - * |
|
158 | - * We copy the convention from the Drupal module here, and run a separate SOQL query for each type of object in SF |
|
159 | - * |
|
160 | - */ |
|
153 | + * Pull updated records from Salesforce and place them in the queue. |
|
154 | + * |
|
155 | + * Executes a SOQL query based on defined mappings, loops through the results, |
|
156 | + * and places each updated SF object into the queue for later processing. |
|
157 | + * |
|
158 | + * We copy the convention from the Drupal module here, and run a separate SOQL query for each type of object in SF |
|
159 | + * |
|
160 | + */ |
|
161 | 161 | private function get_updated_records() { |
162 | 162 | $sfapi = $this->salesforce['sfapi']; |
163 | 163 | foreach ( $this->mappings->get_fieldmaps() as $salesforce_mapping ) { |
@@ -341,18 +341,18 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
344 | - * Given a SObject type name, build an SOQL query to include all fields for all |
|
345 | - * SalesforceMappings mapped to that SObject. |
|
346 | - * |
|
347 | - * @param string $type |
|
348 | - * e.g. "Contact", "Account", etc. |
|
349 | - * |
|
350 | - * @return Object_Sync_Sf_Salesforce_Select_Query or null if no mappings or no mapped fields |
|
351 | - * were found. |
|
352 | - * |
|
353 | - * @see Object_Sync_Sf_Mapping::get_mapped_fields |
|
354 | - * @see Object_Sync_Sf_Mapping::get_mapped_record_types |
|
355 | - */ |
|
344 | + * Given a SObject type name, build an SOQL query to include all fields for all |
|
345 | + * SalesforceMappings mapped to that SObject. |
|
346 | + * |
|
347 | + * @param string $type |
|
348 | + * e.g. "Contact", "Account", etc. |
|
349 | + * |
|
350 | + * @return Object_Sync_Sf_Salesforce_Select_Query or null if no mappings or no mapped fields |
|
351 | + * were found. |
|
352 | + * |
|
353 | + * @see Object_Sync_Sf_Mapping::get_mapped_fields |
|
354 | + * @see Object_Sync_Sf_Mapping::get_mapped_record_types |
|
355 | + */ |
|
356 | 356 | private function get_pull_query( $type, $salesforce_mapping = array() ) { |
357 | 357 | $mapped_fields = array(); |
358 | 358 | $mapped_record_types = array(); |
@@ -434,10 +434,10 @@ discard block |
||
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
437 | - * Get deleted records from salesforce. |
|
438 | - * Note that deletions can only be queried via REST with an API version >= 29.0. |
|
439 | - * |
|
440 | - */ |
|
437 | + * Get deleted records from salesforce. |
|
438 | + * Note that deletions can only be queried via REST with an API version >= 29.0. |
|
439 | + * |
|
440 | + */ |
|
441 | 441 | private function get_deleted_records() { |
442 | 442 | |
443 | 443 | $sfapi = $this->salesforce['sfapi']; |
@@ -538,13 +538,13 @@ discard block |
||
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
541 | - * Method for ajax hooks to call for pulling manually |
|
542 | - * |
|
543 | - * @param string $object_type |
|
544 | - * @param string $salesforce_id |
|
545 | - * @param string $wordpress_object |
|
546 | - * |
|
547 | - */ |
|
541 | + * Method for ajax hooks to call for pulling manually |
|
542 | + * |
|
543 | + * @param string $object_type |
|
544 | + * @param string $salesforce_id |
|
545 | + * @param string $wordpress_object |
|
546 | + * |
|
547 | + */ |
|
548 | 548 | public function manual_pull( $object_type, $salesforce_id, $wordpress_object ) { |
549 | 549 | $sfapi = $this->salesforce['sfapi']; |
550 | 550 | $object = $sfapi->api_call( 'sobjects/' . $object_type . '/' . $salesforce_id ); |
@@ -559,20 +559,20 @@ discard block |
||
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
562 | - * Sync WordPress objects and Salesforce objects from the queue using the REST API. |
|
563 | - * |
|
564 | - * @param string $object_type |
|
565 | - * Type of Salesforce object. |
|
566 | - * @param array|string $object |
|
567 | - * The Salesforce data or its Id value. |
|
568 | - * @param array|int $mapping |
|
569 | - * Salesforce/WP mapping data or its id. |
|
570 | - * @param int $sf_sync_trigger |
|
571 | - * Trigger for this sync. |
|
572 | - * |
|
573 | - * @return true or exit the method |
|
574 | - * |
|
575 | - */ |
|
562 | + * Sync WordPress objects and Salesforce objects from the queue using the REST API. |
|
563 | + * |
|
564 | + * @param string $object_type |
|
565 | + * Type of Salesforce object. |
|
566 | + * @param array|string $object |
|
567 | + * The Salesforce data or its Id value. |
|
568 | + * @param array|int $mapping |
|
569 | + * Salesforce/WP mapping data or its id. |
|
570 | + * @param int $sf_sync_trigger |
|
571 | + * Trigger for this sync. |
|
572 | + * |
|
573 | + * @return true or exit the method |
|
574 | + * |
|
575 | + */ |
|
576 | 576 | public function salesforce_pull_process_records( $object_type, $object, $mapping, $sf_sync_trigger ) { |
577 | 577 | |
578 | 578 | $sfapi = $this->salesforce['sfapi']; |
@@ -1301,19 +1301,19 @@ discard block |
||
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 | /** |
1304 | - * Create an object map between a Salesforce object and a WordPress object |
|
1305 | - * |
|
1306 | - * @param array $salesforce_object |
|
1307 | - * Array of the salesforce object's data |
|
1308 | - * @param string $wordpress_id |
|
1309 | - * Unique identifier for the WordPress object |
|
1310 | - * @param array $field_mapping |
|
1311 | - * The row that maps the object types together, including which fields match which other fields |
|
1312 | - * |
|
1313 | - * @return int $wpdb->insert_id |
|
1314 | - * This is the database row for the map object |
|
1315 | - * |
|
1316 | - */ |
|
1304 | + * Create an object map between a Salesforce object and a WordPress object |
|
1305 | + * |
|
1306 | + * @param array $salesforce_object |
|
1307 | + * Array of the salesforce object's data |
|
1308 | + * @param string $wordpress_id |
|
1309 | + * Unique identifier for the WordPress object |
|
1310 | + * @param array $field_mapping |
|
1311 | + * The row that maps the object types together, including which fields match which other fields |
|
1312 | + * |
|
1313 | + * @return int $wpdb->insert_id |
|
1314 | + * This is the database row for the map object |
|
1315 | + * |
|
1316 | + */ |
|
1317 | 1317 | private function create_object_map( $salesforce_object, $wordpress_id, $field_mapping ) { |
1318 | 1318 | // Create object map and save it |
1319 | 1319 | $mapping_object = $this->mappings->create_object_map( |
@@ -5,7 +5,7 @@ discard block |
||
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 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param object $queue |
45 | 45 | * @throws \Exception |
46 | 46 | */ |
47 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
|
47 | + public function __construct($wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue) { |
|
48 | 48 | $this->wpdb = $wpdb; |
49 | 49 | $this->version = $version; |
50 | 50 | $this->login_credentials = $login_credentials; |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | $this->schedule_name = 'salesforce_pull'; |
60 | 60 | |
61 | 61 | // Create action hooks for WordPress objects. We run this after plugins are loaded in case something depends on another plugin. |
62 | - add_action( 'plugins_loaded', array( $this, 'add_actions' ) ); |
|
62 | + add_action('plugins_loaded', array($this, 'add_actions')); |
|
63 | 63 | |
64 | - $this->debug = get_option( 'object_sync_for_salesforce_debug_mode', false ); |
|
64 | + $this->debug = get_option('object_sync_for_salesforce_debug_mode', false); |
|
65 | 65 | |
66 | 66 | } |
67 | 67 | |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | public function add_actions() { |
73 | 73 | |
74 | 74 | // ajax hook |
75 | - add_action( 'wp_ajax_salesforce_pull_webhook', array( $this, 'salesforce_pull_webhook' ) ); |
|
75 | + add_action('wp_ajax_salesforce_pull_webhook', array($this, 'salesforce_pull_webhook')); |
|
76 | 76 | |
77 | 77 | // action-scheduler needs two hooks: one to check for records, and one to process them |
78 | - add_action( 'object_sync_for_salesforce_pull_check_records', array( $this, 'salesforce_pull' ), 10 ); |
|
79 | - add_action( 'object_sync_for_salesforce_pull_process_records', array( $this, 'salesforce_pull_process_records' ), 10, 4 ); |
|
78 | + add_action('object_sync_for_salesforce_pull_check_records', array($this, 'salesforce_pull'), 10); |
|
79 | + add_action('object_sync_for_salesforce_pull_process_records', array($this, 'salesforce_pull_process_records'), 10, 4); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function salesforce_pull_webhook() { |
89 | 89 | |
90 | - if ( true === $this->salesforce_pull() ) { |
|
90 | + if (true === $this->salesforce_pull()) { |
|
91 | 91 | $code = '200'; |
92 | 92 | |
93 | 93 | // single task for action-scheduler to check for data |
94 | 94 | $this->queue->add( |
95 | - $this->schedulable_classes[ $this->schedule_name ]['initializer'], |
|
95 | + $this->schedulable_classes[$this->schedule_name]['initializer'], |
|
96 | 96 | array(), |
97 | 97 | $this->schedule_name |
98 | 98 | ); |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | $code = '403'; |
102 | 102 | } |
103 | 103 | |
104 | - if ( ! empty( $_POST ) ) { // linter flags this, but we're not doing anything with the array just checking to see if it is empty |
|
105 | - wp_send_json_success( $code ); |
|
104 | + if ( ! empty($_POST)) { // linter flags this, but we're not doing anything with the array just checking to see if it is empty |
|
105 | + wp_send_json_success($code); |
|
106 | 106 | } else { |
107 | 107 | return $code; |
108 | 108 | } |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | public function salesforce_pull() { |
116 | 116 | $sfapi = $this->salesforce['sfapi']; |
117 | 117 | |
118 | - if ( true === $this->salesforce['is_authorized'] && true === $this->check_throttle() ) { |
|
118 | + if (true === $this->salesforce['is_authorized'] && true === $this->check_throttle()) { |
|
119 | 119 | |
120 | 120 | $this->get_updated_records(); |
121 | 121 | $this->get_deleted_records(); |
122 | 122 | |
123 | 123 | // Store this request time for the throttle check. |
124 | - update_option( 'object_sync_for_salesforce_pull_last_sync', current_time( 'timestamp', true ) ); |
|
124 | + update_option('object_sync_for_salesforce_pull_last_sync', current_time('timestamp', true)); |
|
125 | 125 | return true; |
126 | 126 | |
127 | 127 | } else { |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | * Returns false if the time elapsed between recent pulls is too short. |
140 | 140 | */ |
141 | 141 | private function check_throttle() { |
142 | - $pull_throttle = get_option( 'object_sync_for_salesforce_pull_throttle', 5 ); |
|
143 | - $last_sync = get_option( 'object_sync_for_salesforce_pull_last_sync', 0 ); |
|
142 | + $pull_throttle = get_option('object_sync_for_salesforce_pull_throttle', 5); |
|
143 | + $last_sync = get_option('object_sync_for_salesforce_pull_last_sync', 0); |
|
144 | 144 | |
145 | - if ( current_time( 'timestamp', true ) > ( $last_sync + $pull_throttle ) ) { |
|
145 | + if (current_time('timestamp', true) > ($last_sync + $pull_throttle)) { |
|
146 | 146 | return true; |
147 | 147 | } else { |
148 | 148 | return false; |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | */ |
161 | 161 | private function get_updated_records() { |
162 | 162 | $sfapi = $this->salesforce['sfapi']; |
163 | - foreach ( $this->mappings->get_fieldmaps() as $salesforce_mapping ) { |
|
163 | + foreach ($this->mappings->get_fieldmaps() as $salesforce_mapping) { |
|
164 | 164 | $map_sync_triggers = $salesforce_mapping['sync_triggers']; // this sets which Salesforce triggers are allowed for the mapping |
165 | 165 | $type = $salesforce_mapping['salesforce_object']; // this sets the salesfore object type for the SOQL query |
166 | 166 | |
167 | - $soql = $this->get_pull_query( $type, $salesforce_mapping ); |
|
167 | + $soql = $this->get_pull_query($type, $salesforce_mapping); |
|
168 | 168 | |
169 | 169 | // get_pull_query returns null if it has no matching fields |
170 | - if ( null === $soql ) { |
|
170 | + if (null === $soql) { |
|
171 | 171 | continue; |
172 | 172 | } |
173 | 173 | |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | ); |
183 | 183 | |
184 | 184 | $response = $results['data']; |
185 | - $version_path = wp_parse_url( $sfapi->get_api_endpoint(), PHP_URL_PATH ); |
|
185 | + $version_path = wp_parse_url($sfapi->get_api_endpoint(), PHP_URL_PATH); |
|
186 | 186 | |
187 | - $sf_last_sync = get_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, null ); |
|
188 | - $last_sync = gmdate( 'Y-m-d\TH:i:s\Z', $sf_last_sync ); |
|
187 | + $sf_last_sync = get_option('object_sync_for_salesforce_pull_last_sync_' . $type, null); |
|
188 | + $last_sync = gmdate('Y-m-d\TH:i:s\Z', $sf_last_sync); |
|
189 | 189 | |
190 | - if ( ! isset( $response['errorCode'] ) ) { |
|
190 | + if ( ! isset($response['errorCode'])) { |
|
191 | 191 | // Write items to the queue. |
192 | - foreach ( $response['records'] as $result ) { |
|
192 | + foreach ($response['records'] as $result) { |
|
193 | 193 | |
194 | 194 | // if this record is new as of the last sync, use the create trigger |
195 | - if ( isset( $result['CreatedDate'] ) && $result['CreatedDate'] > $last_sync ) { |
|
195 | + if (isset($result['CreatedDate']) && $result['CreatedDate'] > $last_sync) { |
|
196 | 196 | $sf_sync_trigger = $this->mappings->sync_sf_create; |
197 | 197 | } else { |
198 | 198 | $sf_sync_trigger = $this->mappings->sync_sf_update; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | // Only queue when the record's trigger is configured for the mapping |
202 | 202 | // these are bit operators, so we leave out the strict |
203 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
203 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
204 | 204 | $data = array( |
205 | 205 | 'object_type' => $type, |
206 | 206 | 'object' => $result, |
@@ -212,16 +212,16 @@ discard block |
||
212 | 212 | $pull_allowed = true; |
213 | 213 | |
214 | 214 | // if the current fieldmap does not allow create, we need to check if there is a fieldmap for the Salesforce object Id. if not, set pull_allowed to false. |
215 | - if ( isset( $map_sync_triggers ) && ! in_array( $this->mappings->sync_sf_create, $map_sync_triggers ) ) { |
|
216 | - $object_map = $this->mappings->load_by_salesforce( $result['Id'] ); |
|
217 | - if ( empty( $object_map ) ) { |
|
215 | + if (isset($map_sync_triggers) && ! in_array($this->mappings->sync_sf_create, $map_sync_triggers)) { |
|
216 | + $object_map = $this->mappings->load_by_salesforce($result['Id']); |
|
217 | + if (empty($object_map)) { |
|
218 | 218 | $pull_allowed = false; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Hook to allow other plugins to prevent a pull per-mapping. |
223 | 223 | // Putting the pull_allowed hook here will keep the queue from storing data when it is not supposed to store it |
224 | - $pull_allowed = apply_filters( 'object_sync_for_salesforce_pull_object_allowed', $pull_allowed, $type, $result, $sf_sync_trigger, $salesforce_mapping ); |
|
224 | + $pull_allowed = apply_filters('object_sync_for_salesforce_pull_object_allowed', $pull_allowed, $type, $result, $sf_sync_trigger, $salesforce_mapping); |
|
225 | 225 | |
226 | 226 | // example to keep from pulling the Contact with id of abcdef |
227 | 227 | /* |
@@ -234,35 +234,35 @@ discard block |
||
234 | 234 | } |
235 | 235 | */ |
236 | 236 | |
237 | - if ( false === $pull_allowed ) { |
|
238 | - update_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, current_time( 'timestamp', true ) ); |
|
237 | + if (false === $pull_allowed) { |
|
238 | + update_option('object_sync_for_salesforce_pull_last_sync_' . $type, current_time('timestamp', true)); |
|
239 | 239 | continue; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // add a queue action to save data from salesforce |
243 | 243 | $this->queue->add( |
244 | - $this->schedulable_classes[ $this->schedule_name ]['callback'], |
|
244 | + $this->schedulable_classes[$this->schedule_name]['callback'], |
|
245 | 245 | array( |
246 | 246 | 'object_type' => $type, |
247 | 247 | 'object' => $result['Id'], |
248 | - 'mapping' => filter_var( $salesforce_mapping['id'], FILTER_VALIDATE_INT ), |
|
248 | + 'mapping' => filter_var($salesforce_mapping['id'], FILTER_VALIDATE_INT), |
|
249 | 249 | 'sf_sync_trigger' => $sf_sync_trigger, |
250 | 250 | ), |
251 | 251 | $this->schedule_name |
252 | 252 | ); |
253 | 253 | |
254 | 254 | // Update the last pull sync timestamp for this record type to avoid re-processing in case of error |
255 | - $last_sync_pull_trigger = DateTime::createFromFormat( 'Y-m-d\TH:i:s+', $result[ $salesforce_mapping['pull_trigger_field'] ], new DateTimeZone( 'UTC' ) ); |
|
256 | - update_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, $last_sync_pull_trigger->format( 'U' ) ); |
|
255 | + $last_sync_pull_trigger = DateTime::createFromFormat('Y-m-d\TH:i:s+', $result[$salesforce_mapping['pull_trigger_field']], new DateTimeZone('UTC')); |
|
256 | + update_option('object_sync_for_salesforce_pull_last_sync_' . $type, $last_sync_pull_trigger->format('U')); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | 260 | // Handle requests larger than the batch limit (usually 2000). |
261 | - $next_records_url = isset( $response['nextRecordsUrl'] ) ? str_replace( $version_path, '', $response['nextRecordsUrl'] ) : false; |
|
261 | + $next_records_url = isset($response['nextRecordsUrl']) ? str_replace($version_path, '', $response['nextRecordsUrl']) : false; |
|
262 | 262 | |
263 | - while ( $next_records_url ) { |
|
263 | + while ($next_records_url) { |
|
264 | 264 | // shouldn't cache this either. it's going into the queue if it exists anyway. |
265 | - $new_results = $sfapi->api_call( |
|
265 | + $new_results = $sfapi->api_call( |
|
266 | 266 | $next_records_url, |
267 | 267 | array(), |
268 | 268 | 'GET', |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | ) |
272 | 272 | ); |
273 | 273 | $new_response = $new_results['data']; |
274 | - if ( ! isset( $new_response['errorCode'] ) ) { |
|
274 | + if ( ! isset($new_response['errorCode'])) { |
|
275 | 275 | // Write items to the queue. |
276 | - foreach ( $new_response['records'] as $result ) { |
|
276 | + foreach ($new_response['records'] as $result) { |
|
277 | 277 | // if this record is new as of the last sync, use the create trigger |
278 | - if ( isset( $result['CreatedDate'] ) && $result['CreatedDate'] > $last_sync ) { |
|
278 | + if (isset($result['CreatedDate']) && $result['CreatedDate'] > $last_sync) { |
|
279 | 279 | $sf_sync_trigger = $this->mappings->sync_sf_create; |
280 | 280 | } else { |
281 | 281 | $sf_sync_trigger = $this->mappings->sync_sf_update; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | |
284 | 284 | // Only queue when the record's trigger is configured for the mapping |
285 | 285 | // these are bit operators, so we leave out the strict |
286 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
286 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
287 | 287 | $data = array( |
288 | 288 | 'object_type' => $type, |
289 | 289 | 'object' => $result, |
@@ -293,39 +293,39 @@ discard block |
||
293 | 293 | |
294 | 294 | // add a queue action to save data from salesforce |
295 | 295 | $this->queue->add( |
296 | - $this->schedulable_classes[ $this->schedule_name ]['callback'], |
|
296 | + $this->schedulable_classes[$this->schedule_name]['callback'], |
|
297 | 297 | array( |
298 | 298 | 'object_type' => $type, |
299 | 299 | 'object' => $result['Id'], |
300 | - 'mapping' => filter_var( $salesforce_mapping['id'], FILTER_VALIDATE_INT ), |
|
300 | + 'mapping' => filter_var($salesforce_mapping['id'], FILTER_VALIDATE_INT), |
|
301 | 301 | 'sf_sync_trigger' => $sf_sync_trigger, |
302 | 302 | ), |
303 | 303 | $this->schedule_name |
304 | 304 | ); |
305 | 305 | |
306 | 306 | // Update the last pull sync timestamp for this record type to avoid re-processing in case of error |
307 | - $last_sync_pull_trigger = DateTime::createFromFormat( 'Y-m-d\TH:i:s+', $result[ $salesforce_mapping['pull_trigger_field'] ], new DateTimeZone( 'UTC' ) ); |
|
308 | - update_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, $last_sync_pull_trigger->format( 'U' ) ); |
|
307 | + $last_sync_pull_trigger = DateTime::createFromFormat('Y-m-d\TH:i:s+', $result[$salesforce_mapping['pull_trigger_field']], new DateTimeZone('UTC')); |
|
308 | + update_option('object_sync_for_salesforce_pull_last_sync_' . $type, $last_sync_pull_trigger->format('U')); |
|
309 | 309 | } |
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - $next_records_url = isset( $new_response['nextRecordsUrl'] ) ? str_replace( $version_path, '', $new_response['nextRecordsUrl'] ) : false; |
|
313 | + $next_records_url = isset($new_response['nextRecordsUrl']) ? str_replace($version_path, '', $new_response['nextRecordsUrl']) : false; |
|
314 | 314 | } |
315 | 315 | } else { |
316 | 316 | |
317 | 317 | // create log entry for failed pull |
318 | 318 | $status = 'error'; |
319 | 319 | // translators: placeholders are: 1) the server error code, and 2) the name of the Salesforce object |
320 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s', 'object-sync-for-salesforce' ), |
|
321 | - absint( $response['errorCode'] ), |
|
322 | - esc_attr( $salesforce_mapping['salesforce_object'] ) |
|
320 | + $title = sprintf(esc_html__('Error: %1$s %2$s', 'object-sync-for-salesforce'), |
|
321 | + absint($response['errorCode']), |
|
322 | + esc_attr($salesforce_mapping['salesforce_object']) |
|
323 | 323 | ); |
324 | 324 | |
325 | - if ( isset( $this->logging ) ) { |
|
325 | + if (isset($this->logging)) { |
|
326 | 326 | $logging = $this->logging; |
327 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
328 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
327 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
328 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | $logging->setup( |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * @see Object_Sync_Sf_Mapping::get_mapped_fields |
354 | 354 | * @see Object_Sync_Sf_Mapping::get_mapped_record_types |
355 | 355 | */ |
356 | - private function get_pull_query( $type, $salesforce_mapping = array() ) { |
|
356 | + private function get_pull_query($type, $salesforce_mapping = array()) { |
|
357 | 357 | $mapped_fields = array(); |
358 | 358 | $mapped_record_types = array(); |
359 | 359 | |
@@ -365,35 +365,35 @@ discard block |
||
365 | 365 | ); |
366 | 366 | |
367 | 367 | // Iterate over each field mapping to determine our query parameters. |
368 | - foreach ( $mappings as $mapping ) { |
|
368 | + foreach ($mappings as $mapping) { |
|
369 | 369 | |
370 | 370 | // only use fields that come from Salesforce to WordPress, or that sync |
371 | 371 | $mapped_fields = array_merge( |
372 | 372 | $mapped_fields, |
373 | 373 | $this->mappings->get_mapped_fields( |
374 | 374 | $mapping, |
375 | - array( $this->mappings->direction_sync, $this->mappings->direction_sf_wordpress ) |
|
375 | + array($this->mappings->direction_sync, $this->mappings->direction_sf_wordpress) |
|
376 | 376 | ) |
377 | 377 | ); |
378 | 378 | |
379 | 379 | // If Record Type is specified, restrict query. |
380 | - $mapping_record_types = $this->mappings->get_mapped_record_types( $mapping ); |
|
380 | + $mapping_record_types = $this->mappings->get_mapped_record_types($mapping); |
|
381 | 381 | |
382 | 382 | // If Record Type is not specified for a given mapping, ensure query is unrestricted. |
383 | - if ( empty( $mapping_record_types ) ) { |
|
383 | + if (empty($mapping_record_types)) { |
|
384 | 384 | $mapped_record_types = false; |
385 | - } elseif ( is_array( $mapped_record_types ) ) { |
|
386 | - $mapped_record_types = array_merge( $mapped_record_types, $mapping_record_types ); |
|
385 | + } elseif (is_array($mapped_record_types)) { |
|
386 | + $mapped_record_types = array_merge($mapped_record_types, $mapping_record_types); |
|
387 | 387 | } |
388 | 388 | } // End foreach(). |
389 | 389 | |
390 | 390 | // There are no field mappings configured to pull data from Salesforce so |
391 | 391 | // move on to the next mapped object. Prevents querying unmapped data. |
392 | - if ( empty( $mapped_fields ) ) { |
|
392 | + if (empty($mapped_fields)) { |
|
393 | 393 | return null; |
394 | 394 | } |
395 | 395 | |
396 | - $soql = new Object_Sync_Sf_Salesforce_Select_Query( $type ); |
|
396 | + $soql = new Object_Sync_Sf_Salesforce_Select_Query($type); |
|
397 | 397 | |
398 | 398 | // Convert field mappings to SOQL. |
399 | 399 | $soql->fields = array_merge( |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | ); |
406 | 406 | |
407 | 407 | // these are bit operators, so we leave out the strict |
408 | - if ( in_array( $this->mappings->sync_sf_create, $salesforce_mapping['sync_triggers'] ) ) { |
|
408 | + if (in_array($this->mappings->sync_sf_create, $salesforce_mapping['sync_triggers'])) { |
|
409 | 409 | $soql->fields['CreatedDate'] = 'CreatedDate'; |
410 | 410 | } |
411 | 411 | |
@@ -413,14 +413,14 @@ discard block |
||
413 | 413 | // this should be what keeps it from getting all the records, whether or not they've ever been updated |
414 | 414 | // we also use the option for when the plugin was installed, and don't go back further than that by default |
415 | 415 | |
416 | - $sf_activate_time = get_option( 'object_sync_for_salesforce_activate_time', '' ); |
|
417 | - $sf_last_sync = get_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, null ); |
|
418 | - if ( $sf_last_sync ) { |
|
419 | - $last_sync = gmdate( 'Y-m-d\TH:i:s\Z', $sf_last_sync ); |
|
420 | - $soql->add_condition( $salesforce_mapping['pull_trigger_field'], $last_sync, '>' ); |
|
416 | + $sf_activate_time = get_option('object_sync_for_salesforce_activate_time', ''); |
|
417 | + $sf_last_sync = get_option('object_sync_for_salesforce_pull_last_sync_' . $type, null); |
|
418 | + if ($sf_last_sync) { |
|
419 | + $last_sync = gmdate('Y-m-d\TH:i:s\Z', $sf_last_sync); |
|
420 | + $soql->add_condition($salesforce_mapping['pull_trigger_field'], $last_sync, '>'); |
|
421 | 421 | } else { |
422 | - $activated = gmdate( 'Y-m-d\TH:i:s\Z', $sf_activate_time ); |
|
423 | - $soql->add_condition( $salesforce_mapping['pull_trigger_field'], $activated, '>' ); |
|
422 | + $activated = gmdate('Y-m-d\TH:i:s\Z', $sf_activate_time); |
|
423 | + $soql->add_condition($salesforce_mapping['pull_trigger_field'], $activated, '>'); |
|
424 | 424 | // put a hook in here to let devs go retroactive if they want, and sync data from before plugin was activated |
425 | 425 | } |
426 | 426 | |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | // we are not incorporating that part of this branch at this time |
447 | 447 | |
448 | 448 | // Load all unique SF record types that we have mappings for. |
449 | - foreach ( $this->mappings->get_fieldmaps() as $salesforce_mapping ) { |
|
449 | + foreach ($this->mappings->get_fieldmaps() as $salesforce_mapping) { |
|
450 | 450 | |
451 | 451 | $type = $salesforce_mapping['salesforce_object']; |
452 | 452 | |
@@ -458,37 +458,37 @@ discard block |
||
458 | 458 | ); |
459 | 459 | |
460 | 460 | // Iterate over each field mapping to determine our query parameters. |
461 | - foreach ( $mappings as $mapping ) { |
|
461 | + foreach ($mappings as $mapping) { |
|
462 | 462 | |
463 | - $last_delete_sync = get_option( 'object_sync_for_salesforce_pull_delete_last_' . $type, current_time( 'timestamp', true ) ); |
|
464 | - $now = current_time( 'timestamp', true ); |
|
465 | - update_option( 'object_sync_for_salesforce_pull_delete_last_' . $type, $now ); |
|
463 | + $last_delete_sync = get_option('object_sync_for_salesforce_pull_delete_last_' . $type, current_time('timestamp', true)); |
|
464 | + $now = current_time('timestamp', true); |
|
465 | + update_option('object_sync_for_salesforce_pull_delete_last_' . $type, $now); |
|
466 | 466 | |
467 | 467 | // get_deleted() constraint: startDate cannot be more than 30 days ago |
468 | 468 | // (using an incompatible date may lead to exceptions). |
469 | - $last_delete_sync = $last_delete_sync > ( current_time( 'timestamp', true ) - 2505600 ) ? $last_delete_sync : ( current_time( 'timestamp', true ) - 2505600 ); |
|
469 | + $last_delete_sync = $last_delete_sync > (current_time('timestamp', true) - 2505600) ? $last_delete_sync : (current_time('timestamp', true) - 2505600); |
|
470 | 470 | |
471 | 471 | // get_deleted() constraint: startDate must be at least one minute greater |
472 | 472 | // than endDate. |
473 | - $now = $now > ( $last_delete_sync + 60 ) ? $now : $now + 60; |
|
473 | + $now = $now > ($last_delete_sync + 60) ? $now : $now + 60; |
|
474 | 474 | |
475 | 475 | // need to be using gmdate for salesforce call |
476 | - $last_delete_sync_sf = gmdate( 'Y-m-d\TH:i:s\Z', $last_delete_sync ); |
|
477 | - $now_sf = gmdate( 'Y-m-d\TH:i:s\Z', $now ); |
|
476 | + $last_delete_sync_sf = gmdate('Y-m-d\TH:i:s\Z', $last_delete_sync); |
|
477 | + $now_sf = gmdate('Y-m-d\TH:i:s\Z', $now); |
|
478 | 478 | |
479 | 479 | // salesforce call |
480 | - $deleted = $sfapi->get_deleted( $type, $last_delete_sync_sf, $now_sf ); |
|
480 | + $deleted = $sfapi->get_deleted($type, $last_delete_sync_sf, $now_sf); |
|
481 | 481 | |
482 | - if ( empty( $deleted['data']['deletedRecords'] ) ) { |
|
482 | + if (empty($deleted['data']['deletedRecords'])) { |
|
483 | 483 | continue; |
484 | 484 | } |
485 | 485 | |
486 | - foreach ( $deleted['data']['deletedRecords'] as $result ) { |
|
486 | + foreach ($deleted['data']['deletedRecords'] as $result) { |
|
487 | 487 | |
488 | 488 | $sf_sync_trigger = $this->mappings->sync_sf_delete; |
489 | 489 | |
490 | 490 | // salesforce seriously returns Id for update requests and id for delete requests and this makes no sense but maybe one day they might change it somehow? |
491 | - if ( ! isset( $result['Id'] ) && isset( $result['id'] ) ) { |
|
491 | + if ( ! isset($result['Id']) && isset($result['id'])) { |
|
492 | 492 | $result['Id'] = $result['id']; |
493 | 493 | } |
494 | 494 | $data = array( |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | |
501 | 501 | // Hook to allow other plugins to prevent a pull per-mapping. |
502 | 502 | // Putting the pull_allowed hook here will keep the queue from storing data when it is not supposed to store it |
503 | - $pull_allowed = apply_filters( 'object_sync_for_salesforce_pull_object_allowed', true, $type, $result, $sf_sync_trigger, $salesforce_mapping ); |
|
503 | + $pull_allowed = apply_filters('object_sync_for_salesforce_pull_object_allowed', true, $type, $result, $sf_sync_trigger, $salesforce_mapping); |
|
504 | 504 | |
505 | 505 | // example to keep from pulling the Contact with id of abcdef |
506 | 506 | /* |
@@ -513,17 +513,17 @@ discard block |
||
513 | 513 | } |
514 | 514 | */ |
515 | 515 | |
516 | - if ( false === $pull_allowed ) { |
|
516 | + if (false === $pull_allowed) { |
|
517 | 517 | continue; |
518 | 518 | } |
519 | 519 | |
520 | 520 | // add a queue action to save data from salesforce |
521 | 521 | $this->queue->add( |
522 | - $this->schedulable_classes[ $this->schedule_name ]['callback'], |
|
522 | + $this->schedulable_classes[$this->schedule_name]['callback'], |
|
523 | 523 | array( |
524 | 524 | 'object_type' => $type, |
525 | 525 | 'object' => $result['Id'], |
526 | - 'mapping' => filter_var( $salesforce_mapping['id'], FILTER_VALIDATE_INT ), |
|
526 | + 'mapping' => filter_var($salesforce_mapping['id'], FILTER_VALIDATE_INT), |
|
527 | 527 | 'sf_sync_trigger' => $sf_sync_trigger, |
528 | 528 | ), |
529 | 529 | $this->schedule_name |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | |
532 | 532 | } |
533 | 533 | |
534 | - update_option( 'object_sync_for_salesforce_pull_delete_last_' . $type, current_time( 'timestamp', true ) ); |
|
534 | + update_option('object_sync_for_salesforce_pull_delete_last_' . $type, current_time('timestamp', true)); |
|
535 | 535 | |
536 | 536 | } // End foreach(). |
537 | 537 | } // End foreach(). |
@@ -545,9 +545,9 @@ discard block |
||
545 | 545 | * @param string $wordpress_object |
546 | 546 | * |
547 | 547 | */ |
548 | - public function manual_pull( $object_type, $salesforce_id, $wordpress_object ) { |
|
548 | + public function manual_pull($object_type, $salesforce_id, $wordpress_object) { |
|
549 | 549 | $sfapi = $this->salesforce['sfapi']; |
550 | - $object = $sfapi->api_call( 'sobjects/' . $object_type . '/' . $salesforce_id ); |
|
550 | + $object = $sfapi->api_call('sobjects/' . $object_type . '/' . $salesforce_id); |
|
551 | 551 | $mapping = $this->mappings->get_fieldmaps( |
552 | 552 | null, |
553 | 553 | array( |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | 'wordpress_object' => $wordpress_object, |
556 | 556 | ) |
557 | 557 | ); |
558 | - $this->salesforce_pull_process_records( $object_type, $object['data'], $mapping[0], $this->mappings->sync_sf_update ); |
|
558 | + $this->salesforce_pull_process_records($object_type, $object['data'], $mapping[0], $this->mappings->sync_sf_update); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
@@ -573,59 +573,59 @@ discard block |
||
573 | 573 | * @return true or exit the method |
574 | 574 | * |
575 | 575 | */ |
576 | - public function salesforce_pull_process_records( $object_type, $object, $mapping, $sf_sync_trigger ) { |
|
576 | + public function salesforce_pull_process_records($object_type, $object, $mapping, $sf_sync_trigger) { |
|
577 | 577 | |
578 | 578 | $sfapi = $this->salesforce['sfapi']; |
579 | 579 | |
580 | - if ( is_string( $object ) ) { |
|
580 | + if (is_string($object)) { |
|
581 | 581 | $object_id = $object; |
582 | - $object = $sfapi->object_read( $object_type, $object_id )['data']; |
|
582 | + $object = $sfapi->object_read($object_type, $object_id)['data']; |
|
583 | 583 | } |
584 | 584 | |
585 | - if ( is_int( $mapping ) ) { |
|
585 | + if (is_int($mapping)) { |
|
586 | 586 | $mapping_id = $mapping; |
587 | - $mapping = $this->mappings->get_fieldmaps( $mapping_id ); |
|
587 | + $mapping = $this->mappings->get_fieldmaps($mapping_id); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | $mapping_conditions = array( |
591 | 591 | 'salesforce_object' => $object_type, |
592 | 592 | ); |
593 | 593 | |
594 | - if ( isset( $object['RecordTypeId'] ) && $object['RecordTypeId'] !== $this->mappings->salesforce_default_record_type ) { |
|
594 | + if (isset($object['RecordTypeId']) && $object['RecordTypeId'] !== $this->mappings->salesforce_default_record_type) { |
|
595 | 595 | // use this condition to filter the mappings, at that time |
596 | 596 | $mapping_conditions['salesforce_record_type'] = $object['RecordTypeId']; |
597 | 597 | } |
598 | 598 | |
599 | - $salesforce_mappings = $this->mappings->get_fieldmaps( null, $mapping_conditions ); |
|
599 | + $salesforce_mappings = $this->mappings->get_fieldmaps(null, $mapping_conditions); |
|
600 | 600 | |
601 | 601 | // from drupal: if there is more than one mapping, don't throw exceptions |
602 | - $hold_exceptions = count( $salesforce_mappings ) > 1; |
|
602 | + $hold_exceptions = count($salesforce_mappings) > 1; |
|
603 | 603 | $exception = false; |
604 | 604 | |
605 | 605 | $frequencies = $this->queue->get_frequencies(); |
606 | - $seconds = reset( $frequencies )['frequency'] + 60; |
|
606 | + $seconds = reset($frequencies)['frequency'] + 60; |
|
607 | 607 | |
608 | 608 | $transients_to_delete = array(); |
609 | 609 | |
610 | - foreach ( $salesforce_mappings as $salesforce_mapping ) { |
|
610 | + foreach ($salesforce_mappings as $salesforce_mapping) { |
|
611 | 611 | |
612 | 612 | // this returns the row that maps the individual Salesforce row to the individual WordPress row |
613 | - if ( isset( $object['Id'] ) ) { |
|
614 | - $mapping_object = $this->mappings->load_by_salesforce( $object['Id'] ); |
|
613 | + if (isset($object['Id'])) { |
|
614 | + $mapping_object = $this->mappings->load_by_salesforce($object['Id']); |
|
615 | 615 | } else { |
616 | 616 | // if we don't have a Salesforce object id, we've got no business doing stuff in WordPress |
617 | 617 | $status = 'error'; |
618 | - if ( isset( $this->logging ) ) { |
|
618 | + if (isset($this->logging)) { |
|
619 | 619 | $logging = $this->logging; |
620 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
621 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
620 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
621 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
622 | 622 | } |
623 | 623 | |
624 | - $title = sprintf( esc_html__( 'Error: Salesforce Pull: unable to process queue item because it has no Salesforce Id.', 'object-sync-for-salesforce' ) ); |
|
624 | + $title = sprintf(esc_html__('Error: Salesforce Pull: unable to process queue item because it has no Salesforce Id.', 'object-sync-for-salesforce')); |
|
625 | 625 | |
626 | 626 | $logging->setup( |
627 | 627 | $title, |
628 | - print_r( $object, true ), // log whatever we have in the event of this error, so print the array |
|
628 | + print_r($object, true), // log whatever we have in the event of this error, so print the array |
|
629 | 629 | $sf_sync_trigger, |
630 | 630 | 0, // parent id goes here but we don't have one, so make it 0 |
631 | 631 | $status |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | // if it's not already connected (ie on create), the array will be empty |
638 | 638 | |
639 | 639 | // hook to allow other plugins to define or alter the mapping object |
640 | - $mapping_object = apply_filters( 'object_sync_for_salesforce_pull_mapping_object', $mapping_object, $object, $mapping ); |
|
640 | + $mapping_object = apply_filters('object_sync_for_salesforce_pull_mapping_object', $mapping_object, $object, $mapping); |
|
641 | 641 | |
642 | 642 | // we already have the data from Salesforce at this point; we just need to work with it in WordPress |
643 | 643 | $synced_object = array( |
@@ -646,58 +646,58 @@ discard block |
||
646 | 646 | 'mapping' => $mapping, |
647 | 647 | ); |
648 | 648 | |
649 | - $structure = $this->wordpress->get_wordpress_table_structure( $salesforce_mapping['wordpress_object'] ); |
|
649 | + $structure = $this->wordpress->get_wordpress_table_structure($salesforce_mapping['wordpress_object']); |
|
650 | 650 | $object_id = $structure['id_field']; |
651 | 651 | |
652 | 652 | $op = ''; |
653 | 653 | |
654 | 654 | // are these objects already connected in WordPress? |
655 | - if ( isset( $mapping_object['id'] ) ) { |
|
655 | + if (isset($mapping_object['id'])) { |
|
656 | 656 | $is_new = false; |
657 | 657 | $mapping_object_id_transient = $mapping_object['id']; |
658 | 658 | } else { |
659 | 659 | // there is not a mapping object for this WordPress object id yet |
660 | 660 | // check for that transient with the currently pushing id |
661 | 661 | $is_new = true; |
662 | - $mapping_object_id_transient = get_transient( 'salesforce_pushing_object_id' ); |
|
662 | + $mapping_object_id_transient = get_transient('salesforce_pushing_object_id'); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | // Drupal only does a salesforce_pull flag, but we might as well do push and pull because WordPress |
666 | - $salesforce_pushing = (int) get_transient( 'salesforce_pushing_' . $mapping_object_id_transient ); |
|
667 | - if ( 1 === $salesforce_pushing ) { |
|
666 | + $salesforce_pushing = (int) get_transient('salesforce_pushing_' . $mapping_object_id_transient); |
|
667 | + if (1 === $salesforce_pushing) { |
|
668 | 668 | $transients_to_delete[] = $mapping_object_id_transient; |
669 | 669 | continue; |
670 | 670 | } |
671 | 671 | |
672 | 672 | // deleting mapped objects |
673 | - if ( $sf_sync_trigger == $this->mappings->sync_sf_delete ) { // trigger is a bit operator |
|
674 | - if ( isset( $mapping_object['id'] ) ) { |
|
673 | + if ($sf_sync_trigger == $this->mappings->sync_sf_delete) { // trigger is a bit operator |
|
674 | + if (isset($mapping_object['id'])) { |
|
675 | 675 | |
676 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
677 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
676 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
677 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
678 | 678 | |
679 | 679 | $op = 'Delete'; |
680 | - $wordpress_check = $this->mappings->load_by_wordpress( $mapping_object['wordpress_object'], $mapping_object['wordpress_id'] ); |
|
681 | - if ( count( $wordpress_check ) === count( $wordpress_check, COUNT_RECURSIVE ) ) { |
|
680 | + $wordpress_check = $this->mappings->load_by_wordpress($mapping_object['wordpress_object'], $mapping_object['wordpress_id']); |
|
681 | + if (count($wordpress_check) === count($wordpress_check, COUNT_RECURSIVE)) { |
|
682 | 682 | try { |
683 | - $result = $this->wordpress->object_delete( $salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'] ); |
|
684 | - } catch ( WordpressException $e ) { |
|
683 | + $result = $this->wordpress->object_delete($salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id']); |
|
684 | + } catch (WordpressException $e) { |
|
685 | 685 | $status = 'error'; |
686 | 686 | // create log entry for failed delete |
687 | - if ( isset( $this->logging ) ) { |
|
687 | + if (isset($this->logging)) { |
|
688 | 688 | $logging = $this->logging; |
689 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
690 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
689 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
690 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | // 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 name of the Salesforce object, 6) the Salesforce Id value |
694 | - $title = sprintf( esc_html__( 'Error: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce' ), |
|
695 | - esc_attr( $op ), |
|
696 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
697 | - esc_attr( $object_id ), |
|
698 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
699 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
700 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
694 | + $title = sprintf(esc_html__('Error: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce'), |
|
695 | + esc_attr($op), |
|
696 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
697 | + esc_attr($object_id), |
|
698 | + esc_attr($mapping_object['wordpress_id']), |
|
699 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
700 | + esc_attr($mapping_object['salesforce_id']) |
|
701 | 701 | ); |
702 | 702 | |
703 | 703 | $logging->setup( |
@@ -708,38 +708,38 @@ discard block |
||
708 | 708 | $status |
709 | 709 | ); |
710 | 710 | |
711 | - if ( false === $hold_exceptions ) { |
|
711 | + if (false === $hold_exceptions) { |
|
712 | 712 | throw $e; |
713 | 713 | } |
714 | - if ( empty( $exception ) ) { |
|
714 | + if (empty($exception)) { |
|
715 | 715 | $exception = $e; |
716 | 716 | } else { |
717 | - $my_class = get_class( $e ); |
|
718 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
717 | + $my_class = get_class($e); |
|
718 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | // hook for pull fail |
722 | - do_action( 'object_sync_for_salesforce_pull_fail', $op, $result, $synced_object ); |
|
722 | + do_action('object_sync_for_salesforce_pull_fail', $op, $result, $synced_object); |
|
723 | 723 | |
724 | 724 | } // End try(). |
725 | 725 | |
726 | - if ( ! isset( $e ) ) { |
|
726 | + if ( ! isset($e)) { |
|
727 | 727 | // create log entry for successful delete if the result had no errors |
728 | 728 | $status = 'success'; |
729 | - if ( isset( $this->logging ) ) { |
|
729 | + if (isset($this->logging)) { |
|
730 | 730 | $logging = $this->logging; |
731 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
732 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
731 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
732 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | // 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 name of the Salesforce object, 6) the Salesforce Id value |
736 | - $title = sprintf( esc_html__( 'Success: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce' ), |
|
737 | - esc_attr( $op ), |
|
738 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
739 | - esc_attr( $object_id ), |
|
740 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
741 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
742 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
736 | + $title = sprintf(esc_html__('Success: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce'), |
|
737 | + esc_attr($op), |
|
738 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
739 | + esc_attr($object_id), |
|
740 | + esc_attr($mapping_object['wordpress_id']), |
|
741 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
742 | + esc_attr($mapping_object['salesforce_id']) |
|
743 | 743 | ); |
744 | 744 | |
745 | 745 | $logging->setup( |
@@ -751,38 +751,38 @@ discard block |
||
751 | 751 | ); |
752 | 752 | |
753 | 753 | // hook for pull success |
754 | - do_action( 'object_sync_for_salesforce_pull_success', $op, $result, $synced_object ); |
|
754 | + do_action('object_sync_for_salesforce_pull_success', $op, $result, $synced_object); |
|
755 | 755 | } |
756 | 756 | } else { |
757 | - $more_ids = sprintf( '<p>' . esc_html__( 'The WordPress record was not deleted because there are multiple Salesforce IDs that match this WordPress ID. They are:', 'object-sync-for-salesforce' ) ); |
|
757 | + $more_ids = sprintf('<p>' . esc_html__('The WordPress record was not deleted because there are multiple Salesforce IDs that match this WordPress ID. They are:', 'object-sync-for-salesforce')); |
|
758 | 758 | $i = 0; |
759 | - foreach ( $wordpress_check as $match ) { |
|
759 | + foreach ($wordpress_check as $match) { |
|
760 | 760 | $i++; |
761 | - $more_ids .= sprintf( $match['salesforce_id'] ); |
|
762 | - if ( count( $wordpress_check ) !== $i ) { |
|
763 | - $more_ids .= sprintf( ', ' ); |
|
761 | + $more_ids .= sprintf($match['salesforce_id']); |
|
762 | + if (count($wordpress_check) !== $i) { |
|
763 | + $more_ids .= sprintf(', '); |
|
764 | 764 | } else { |
765 | - $more_ids .= sprintf( '.</p>' ); |
|
765 | + $more_ids .= sprintf('.</p>'); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | |
769 | - $more_ids .= sprintf( '<p>' . esc_html__( 'The map row between this Salesforce object and the WordPress object, as stored in the WordPress database, will be deleted, and this Salesforce object has been deleted, but the WordPress object row will remain untouched.', 'object-sync-for-salesforce' ) . '</p>' ); |
|
769 | + $more_ids .= sprintf('<p>' . esc_html__('The map row between this Salesforce object and the WordPress object, as stored in the WordPress database, will be deleted, and this Salesforce object has been deleted, but the WordPress object row will remain untouched.', 'object-sync-for-salesforce') . '</p>'); |
|
770 | 770 | |
771 | 771 | $status = 'notice'; |
772 | - if ( isset( $this->logging ) ) { |
|
772 | + if (isset($this->logging)) { |
|
773 | 773 | $logging = $this->logging; |
774 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
775 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
774 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
775 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | // 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 name of the Salesforce object, 6) the Salesforce Id value |
779 | - $title = sprintf( esc_html__( 'Notice: %1$s %2$s with %3$s of %4$s (%5$s %6$s) did not delete the WordPress item.', 'object-sync-for-salesforce' ), |
|
780 | - esc_attr( $op ), |
|
781 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
782 | - esc_attr( $object_id ), |
|
783 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
784 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
785 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
779 | + $title = sprintf(esc_html__('Notice: %1$s %2$s with %3$s of %4$s (%5$s %6$s) did not delete the WordPress item.', 'object-sync-for-salesforce'), |
|
780 | + esc_attr($op), |
|
781 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
782 | + esc_attr($object_id), |
|
783 | + esc_attr($mapping_object['wordpress_id']), |
|
784 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
785 | + esc_attr($mapping_object['salesforce_id']) |
|
786 | 786 | ); |
787 | 787 | |
788 | 788 | $logging->setup( |
@@ -796,27 +796,27 @@ discard block |
||
796 | 796 | |
797 | 797 | // delete the map row from WordPress after the WordPress row has been deleted |
798 | 798 | // we delete the map row even if the WordPress delete failed, because the Salesforce object is gone |
799 | - $this->mappings->delete_object_map( $mapping_object['id'] ); |
|
799 | + $this->mappings->delete_object_map($mapping_object['id']); |
|
800 | 800 | // there is no map row if we end this if statement |
801 | 801 | } // End if(). |
802 | 802 | return; |
803 | 803 | } // End if(). |
804 | 804 | |
805 | 805 | // map the Salesforce values to WordPress fields |
806 | - $params = $this->mappings->map_params( $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
806 | + $params = $this->mappings->map_params($mapping, $object, $sf_sync_trigger, false, $is_new); |
|
807 | 807 | |
808 | 808 | // hook to allow other plugins to modify the $params array |
809 | 809 | // use hook to map fields between the WordPress and Salesforce objects |
810 | 810 | // returns $params. |
811 | - $params = apply_filters( 'object_sync_for_salesforce_pull_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
811 | + $params = apply_filters('object_sync_for_salesforce_pull_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new); |
|
812 | 812 | |
813 | 813 | // if we don't get any params, there are no fields that should be sent to WordPress |
814 | - if ( empty( $params ) ) { |
|
814 | + if (empty($params)) { |
|
815 | 815 | return; |
816 | 816 | } |
817 | 817 | |
818 | 818 | // if there is a prematch WordPress field - ie email - on the fieldmap object |
819 | - if ( isset( $params['prematch'] ) && is_array( $params['prematch'] ) ) { |
|
819 | + if (isset($params['prematch']) && is_array($params['prematch'])) { |
|
820 | 820 | $prematch_field_wordpress = $params['prematch']['wordpress_field']; |
821 | 821 | $prematch_field_salesforce = $params['prematch']['salesforce_field']; |
822 | 822 | $prematch_value = $params['prematch']['value']; |
@@ -826,22 +826,22 @@ discard block |
||
826 | 826 | 'method_update' => $params['prematch']['method_update'], |
827 | 827 | 'method_read' => $params['prematch']['method_read'], |
828 | 828 | ); |
829 | - unset( $params['prematch'] ); |
|
829 | + unset($params['prematch']); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | // if there is an external key field in Salesforce - ie a Mailchimp user id - on the fieldmap object, this should not affect how WordPress handles it so we have removed it from the pull parameters. |
833 | 833 | |
834 | 834 | // methods to run the wp create or update operations |
835 | 835 | |
836 | - if ( true === $is_new ) { |
|
836 | + if (true === $is_new) { |
|
837 | 837 | |
838 | 838 | // setup SF record type. CampaignMember objects get their Campaign's type |
839 | 839 | // i am still a bit confused about this |
840 | 840 | // we should store this as a meta field on each object, if it meets these criteria |
841 | 841 | // we need to store the read/modify attributes because the field doesn't exist in the mapping |
842 | - if ( $salesforce_mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty( $params['RecordTypeId'] ) && ( 'CampaignMember' !== $salesforce_mapping['salesforce_object'] ) ) { |
|
842 | + if ($salesforce_mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty($params['RecordTypeId']) && ('CampaignMember' !== $salesforce_mapping['salesforce_object'])) { |
|
843 | 843 | $type = $salesforce_mapping['wordpress_object']; |
844 | - if ( 'category' === $salesforce_mapping['wordpress_object'] || 'tag' === $salesforce_mapping['wordpress_object'] || 'post_tag' === $salesforce_mapping['wordpress_object'] ) { |
|
844 | + if ('category' === $salesforce_mapping['wordpress_object'] || 'tag' === $salesforce_mapping['wordpress_object'] || 'post_tag' === $salesforce_mapping['wordpress_object']) { |
|
845 | 845 | $type = 'term'; |
846 | 846 | } |
847 | 847 | $params['RecordTypeId'] = array( |
@@ -859,24 +859,24 @@ discard block |
||
859 | 859 | // returns a $salesforce_id. |
860 | 860 | // it should keep NULL if there is no match |
861 | 861 | // the function that calls this hook needs to check the mapping to make sure the WordPress object is the right type |
862 | - $wordpress_id = apply_filters( 'object_sync_for_salesforce_find_wp_object_match', null, $object, $mapping, 'pull' ); |
|
862 | + $wordpress_id = apply_filters('object_sync_for_salesforce_find_wp_object_match', null, $object, $mapping, 'pull'); |
|
863 | 863 | |
864 | 864 | // hook to allow other plugins to do something right before WordPress data is saved |
865 | 865 | // ex: run outside methods on an object if it exists, or do something in preparation for it if it doesn't |
866 | - do_action( 'object_sync_for_salesforce_pre_pull', $wordpress_id, $mapping, $object, $object_id, $params ); |
|
866 | + do_action('object_sync_for_salesforce_pre_pull', $wordpress_id, $mapping, $object, $object_id, $params); |
|
867 | 867 | |
868 | - if ( isset( $prematch_field_salesforce ) || null !== $wordpress_id ) { |
|
868 | + if (isset($prematch_field_salesforce) || null !== $wordpress_id) { |
|
869 | 869 | |
870 | 870 | $op = 'Upsert'; |
871 | 871 | |
872 | 872 | // if either prematch criteria exists, make the values queryable |
873 | - if ( isset( $prematch_field_salesforce ) ) { |
|
873 | + if (isset($prematch_field_salesforce)) { |
|
874 | 874 | $upsert_key = $prematch_field_wordpress; |
875 | 875 | $upsert_value = $prematch_value; |
876 | 876 | $upsert_methods = $prematch_methods; |
877 | 877 | } |
878 | 878 | |
879 | - if ( null !== $wordpress_id ) { |
|
879 | + if (null !== $wordpress_id) { |
|
880 | 880 | $upsert_key = $object_id; |
881 | 881 | $upsert_value = $wordpress_id; |
882 | 882 | $upsert_methods = array(); |
@@ -885,13 +885,13 @@ discard block |
||
885 | 885 | // with the flag at the end, upsert returns a $wordpress_id only |
886 | 886 | // we can then check to see if it has a mapping object |
887 | 887 | // we should only do this if the above hook didn't already set the $wordpress_id |
888 | - if ( null === $wordpress_id ) { |
|
889 | - $wordpress_id = $this->wordpress->object_upsert( $salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'], true ); |
|
888 | + if (null === $wordpress_id) { |
|
889 | + $wordpress_id = $this->wordpress->object_upsert($salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'], true); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | // find out if there is a mapping object for this WordPress object already |
893 | 893 | // don't do it if the WordPress id is 0. |
894 | - if ( 0 !== $wordpress_id ) { |
|
894 | + if (0 !== $wordpress_id) { |
|
895 | 895 | $mapping_object = $this->mappings->get_object_maps( |
896 | 896 | array( |
897 | 897 | 'wordpress_id' => $wordpress_id, |
@@ -906,35 +906,35 @@ discard block |
||
906 | 906 | ) |
907 | 907 | ); |
908 | 908 | |
909 | - if ( array() !== $mapping_object_debug ) { |
|
909 | + if (array() !== $mapping_object_debug) { |
|
910 | 910 | // create log entry to warn about at least one id of 0 |
911 | 911 | $status = 'error'; |
912 | - $title = sprintf( esc_html__( 'Error: There is at least one object map with a WordPress ID of 0.', 'object-sync-for-salesforce' ) ); |
|
912 | + $title = sprintf(esc_html__('Error: There is at least one object map with a WordPress ID of 0.', 'object-sync-for-salesforce')); |
|
913 | 913 | |
914 | - if ( 1 === count( $mapping_object_debug ) ) { |
|
914 | + if (1 === count($mapping_object_debug)) { |
|
915 | 915 | // translators: placeholders are: 1) the mapping object row ID, 2) the name of the WordPress object, 3) the ID of the Salesforce object it was trying to map |
916 | - $body = sprintf( esc_html__( 'There is an object map with ID of %1$s and it is mapped to the WordPress %2$s with ID of 0 and the Salesforce object with ID of %3$s', 'object-sync-for-salesforce' ), |
|
917 | - absint( $mapping_object_debug['id'] ), |
|
918 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
919 | - esc_attr( $mapping_object_debug['salesforce_id'] ) |
|
916 | + $body = sprintf(esc_html__('There is an object map with ID of %1$s and it is mapped to the WordPress %2$s with ID of 0 and the Salesforce object with ID of %3$s', 'object-sync-for-salesforce'), |
|
917 | + absint($mapping_object_debug['id']), |
|
918 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
919 | + esc_attr($mapping_object_debug['salesforce_id']) |
|
920 | 920 | ); |
921 | 921 | } else { |
922 | - $body = sprintf( esc_html__( 'There are multiple object maps with WordPress ID of 0. Their IDs are: ', 'object-sync-for-salesforce' ) . '<ul>' ); |
|
923 | - foreach ( $mapping_object_debug as $mapping_object ) { |
|
922 | + $body = sprintf(esc_html__('There are multiple object maps with WordPress ID of 0. Their IDs are: ', 'object-sync-for-salesforce') . '<ul>'); |
|
923 | + foreach ($mapping_object_debug as $mapping_object) { |
|
924 | 924 | // translators: placeholders are: 1) the mapping object row ID, 2) the ID of the Salesforce object, 3) the WordPress object type |
925 | - $body .= sprintf( '<li>' . esc_html__( 'Mapping object id: %1$s. Salesforce Id: %2$s. WordPress object type: %3$s', 'object-sync-for-salesforce' ) . '</li>', |
|
926 | - absint( $mapping_object['id'] ), |
|
927 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
928 | - esc_attr( $salesforce_mapping['wordpress_object'] ) |
|
925 | + $body .= sprintf('<li>' . esc_html__('Mapping object id: %1$s. Salesforce Id: %2$s. WordPress object type: %3$s', 'object-sync-for-salesforce') . '</li>', |
|
926 | + absint($mapping_object['id']), |
|
927 | + esc_attr($mapping_object['salesforce_id']), |
|
928 | + esc_attr($salesforce_mapping['wordpress_object']) |
|
929 | 929 | ); |
930 | 930 | } |
931 | - $body .= sprintf( '</ul>' ); |
|
931 | + $body .= sprintf('</ul>'); |
|
932 | 932 | } |
933 | 933 | |
934 | - if ( isset( $this->logging ) ) { |
|
934 | + if (isset($this->logging)) { |
|
935 | 935 | $logging = $this->logging; |
936 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
937 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
936 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
937 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
938 | 938 | } |
939 | 939 | $parent = 0; |
940 | 940 | $logging->setup( |
@@ -948,37 +948,37 @@ discard block |
||
948 | 948 | } // End if(). |
949 | 949 | |
950 | 950 | // there is already a mapping object. don't change the WordPress data to match this new Salesforce record, but log it |
951 | - if ( isset( $mapping_object['id'] ) ) { |
|
951 | + if (isset($mapping_object['id'])) { |
|
952 | 952 | // set the transient so that salesforce_push doesn't start doing stuff, then return out of here |
953 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
954 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
953 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
954 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
955 | 955 | // create log entry to indicate that nothing happened |
956 | 956 | $status = 'notice'; |
957 | 957 | // translators: placeholders are: 1) mapping object row id, 2) WordPress object tyoe, 3) individual WordPress item ID, 4) individual Salesforce item ID |
958 | - $title = sprintf( esc_html__( 'Notice: Because object map %1$s already exists, WordPress %2$s %3$s was not mapped to Salesforce Id %4$s', 'object-sync-for-salesforce' ), |
|
959 | - absint( $mapping_object['id'] ), |
|
960 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
961 | - absint( $wordpress_id ), |
|
962 | - esc_attr( $object['Id'] ) |
|
958 | + $title = sprintf(esc_html__('Notice: Because object map %1$s already exists, WordPress %2$s %3$s was not mapped to Salesforce Id %4$s', 'object-sync-for-salesforce'), |
|
959 | + absint($mapping_object['id']), |
|
960 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
961 | + absint($wordpress_id), |
|
962 | + esc_attr($object['Id']) |
|
963 | 963 | ); |
964 | 964 | |
965 | 965 | // translators: placeholders are 1) WordPress object type, 2) field name for the WordPress id, 3) the WordPress id value, 4) the Salesforce object type, 5) the Salesforce object Id that was modified, 6) the mapping object row id |
966 | - $body = sprintf( esc_html__( 'The WordPress %1$s with %2$s of %3$s is already mapped to the Salesforce %4$s with Id of %5$s in the mapping object with id of %6$s. The Salesforce %4$s with Id of %5$s was created or modified in Salesforce, and would otherwise have been mapped to this WordPress record. No WordPress data has been changed to prevent changing data unintentionally.', 'object-sync-for-salesforce' ), |
|
967 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
968 | - esc_attr( $structure['id_field'] ), |
|
969 | - absint( $wordpress_id ), |
|
970 | - esc_attr( $mapping_object['salesforce_object'] ), |
|
971 | - esc_attr( $object['Id'] ), |
|
972 | - absint( $mapping_object['id'] ) |
|
966 | + $body = sprintf(esc_html__('The WordPress %1$s with %2$s of %3$s is already mapped to the Salesforce %4$s with Id of %5$s in the mapping object with id of %6$s. The Salesforce %4$s with Id of %5$s was created or modified in Salesforce, and would otherwise have been mapped to this WordPress record. No WordPress data has been changed to prevent changing data unintentionally.', 'object-sync-for-salesforce'), |
|
967 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
968 | + esc_attr($structure['id_field']), |
|
969 | + absint($wordpress_id), |
|
970 | + esc_attr($mapping_object['salesforce_object']), |
|
971 | + esc_attr($object['Id']), |
|
972 | + absint($mapping_object['id']) |
|
973 | 973 | ); |
974 | 974 | |
975 | - if ( isset( $this->logging ) ) { |
|
975 | + if (isset($this->logging)) { |
|
976 | 976 | $logging = $this->logging; |
977 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
978 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
977 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
978 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
979 | 979 | } |
980 | 980 | // if we know the WordPress object id we can put it in there |
981 | - if ( null !== $wordpress_id ) { |
|
981 | + if (null !== $wordpress_id) { |
|
982 | 982 | $parent = $wordpress_id; |
983 | 983 | } else { |
984 | 984 | $parent = 0; |
@@ -997,9 +997,9 @@ discard block |
||
997 | 997 | // right here we should set the pulling transient |
998 | 998 | // this means we have to create the mapping object here as well, and update it with the correct IDs after successful response |
999 | 999 | // create the mapping object between the rows |
1000 | - $mapping_object_id = $this->create_object_map( $object, $this->mappings->generate_temporary_id( 'pull' ), $mapping ); |
|
1001 | - set_transient( 'salesforce_pulling_' . $mapping_object_id, 1, $seconds ); |
|
1002 | - set_transient( 'salesforce_pulling_object_id', $mapping_object_id ); |
|
1000 | + $mapping_object_id = $this->create_object_map($object, $this->mappings->generate_temporary_id('pull'), $mapping); |
|
1001 | + set_transient('salesforce_pulling_' . $mapping_object_id, 1, $seconds); |
|
1002 | + set_transient('salesforce_pulling_object_id', $mapping_object_id); |
|
1003 | 1003 | $mapping_object = $this->mappings->get_object_maps( |
1004 | 1004 | array( |
1005 | 1005 | 'id' => $mapping_object_id, |
@@ -1008,50 +1008,50 @@ discard block |
||
1008 | 1008 | |
1009 | 1009 | // now we can upsert the object in wp if we've gotten to this point |
1010 | 1010 | // this command will either create or update the object |
1011 | - $result = $this->wordpress->object_upsert( $salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'] ); |
|
1011 | + $result = $this->wordpress->object_upsert($salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts']); |
|
1012 | 1012 | |
1013 | 1013 | } else { |
1014 | 1014 | // No key or prematch field exists on this field map object, create a new object in WordPress. |
1015 | 1015 | $op = 'Create'; |
1016 | - $mapping_object_id = $this->create_object_map( $object, $this->mappings->generate_temporary_id( 'pull' ), $mapping ); |
|
1017 | - set_transient( 'salesforce_pulling_' . $mapping_object_id, 1, $seconds ); |
|
1018 | - set_transient( 'salesforce_pulling_object_id', $mapping_object_id ); |
|
1016 | + $mapping_object_id = $this->create_object_map($object, $this->mappings->generate_temporary_id('pull'), $mapping); |
|
1017 | + set_transient('salesforce_pulling_' . $mapping_object_id, 1, $seconds); |
|
1018 | + set_transient('salesforce_pulling_object_id', $mapping_object_id); |
|
1019 | 1019 | $mapping_object = $this->mappings->get_object_maps( |
1020 | 1020 | array( |
1021 | 1021 | 'id' => $mapping_object_id, |
1022 | 1022 | ) |
1023 | 1023 | ); |
1024 | 1024 | |
1025 | - $result = $this->wordpress->object_create( $salesforce_mapping['wordpress_object'], $params ); |
|
1025 | + $result = $this->wordpress->object_create($salesforce_mapping['wordpress_object'], $params); |
|
1026 | 1026 | } // End if(). |
1027 | - } catch ( WordpressException $e ) { |
|
1027 | + } catch (WordpressException $e) { |
|
1028 | 1028 | // create log entry for failed create or upsert |
1029 | 1029 | $status = 'error'; |
1030 | 1030 | |
1031 | 1031 | // translators: placeholders are: 1) what operation is happening, and 2) the name of the WordPress object |
1032 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s', 'object-sync-for-salesforce' ), |
|
1033 | - esc_attr( $op ), |
|
1034 | - esc_attr( $salesforce_mapping['wordpress_object'] ) |
|
1032 | + $title = sprintf(esc_html__('Error: %1$s %2$s', 'object-sync-for-salesforce'), |
|
1033 | + esc_attr($op), |
|
1034 | + esc_attr($salesforce_mapping['wordpress_object']) |
|
1035 | 1035 | ); |
1036 | 1036 | |
1037 | - if ( null !== $salesforce_id ) { |
|
1037 | + if (null !== $salesforce_id) { |
|
1038 | 1038 | $title .= ' ' . $salesforce_id; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | // translators: placeholders are: 1) the name of the Salesforce object, and 2) Id of the Salesforce object |
1042 | - $title .= sprintf( esc_html__( ' (Salesforce %1$s with Id of %2$s)', 'object-sync-for-salesforce' ), |
|
1042 | + $title .= sprintf(esc_html__(' (Salesforce %1$s with Id of %2$s)', 'object-sync-for-salesforce'), |
|
1043 | 1043 | $salesforce_mapping['salesforce_object'], |
1044 | 1044 | $object['Id'] |
1045 | 1045 | ); |
1046 | 1046 | |
1047 | - if ( isset( $this->logging ) ) { |
|
1047 | + if (isset($this->logging)) { |
|
1048 | 1048 | $logging = $this->logging; |
1049 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1050 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1049 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1050 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | 1053 | // if we know the WordPress object id we can put it in there |
1054 | - if ( null !== $wordpress_id ) { |
|
1054 | + if (null !== $wordpress_id) { |
|
1055 | 1055 | $parent = $wordpress_id; |
1056 | 1056 | } else { |
1057 | 1057 | $parent = 0; |
@@ -1065,26 +1065,26 @@ discard block |
||
1065 | 1065 | $status |
1066 | 1066 | ); |
1067 | 1067 | |
1068 | - if ( false === $hold_exceptions ) { |
|
1068 | + if (false === $hold_exceptions) { |
|
1069 | 1069 | throw $e; |
1070 | 1070 | } |
1071 | - if ( empty( $exception ) ) { |
|
1071 | + if (empty($exception)) { |
|
1072 | 1072 | $exception = $e; |
1073 | 1073 | } else { |
1074 | - $my_class = get_class( $e ); |
|
1075 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
1074 | + $my_class = get_class($e); |
|
1075 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | // hook for pull fail |
1079 | - do_action( 'object_sync_for_salesforce_pull_fail', $op, $result, $synced_object ); |
|
1079 | + do_action('object_sync_for_salesforce_pull_fail', $op, $result, $synced_object); |
|
1080 | 1080 | |
1081 | 1081 | return; |
1082 | 1082 | } // End try(). |
1083 | 1083 | |
1084 | 1084 | // set $wordpress_data to the query result |
1085 | 1085 | $wordpress_data = $result['data']; |
1086 | - if ( isset( $wordpress_data[ "$object_id" ] ) ) { |
|
1087 | - $wordpress_id = $wordpress_data[ "$object_id" ]; |
|
1086 | + if (isset($wordpress_data["$object_id"])) { |
|
1087 | + $wordpress_id = $wordpress_data["$object_id"]; |
|
1088 | 1088 | } else { |
1089 | 1089 | $wordpress_id = 0; |
1090 | 1090 | } |
@@ -1093,23 +1093,23 @@ discard block |
||
1093 | 1093 | // this means the object has already been created/updated in WordPress |
1094 | 1094 | // 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) |
1095 | 1095 | |
1096 | - if ( empty( $result['errors'] ) ) { |
|
1096 | + if (empty($result['errors'])) { |
|
1097 | 1097 | $status = 'success'; |
1098 | 1098 | |
1099 | - if ( isset( $this->logging ) ) { |
|
1099 | + if (isset($this->logging)) { |
|
1100 | 1100 | $logging = $this->logging; |
1101 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1102 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1101 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1102 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | // 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 name of the Salesforce object, 6) the Salesforce Id value |
1106 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s with %3$s of %4$s (Salesforce %5$s Id of %6$s)', 'object-sync-for-salesforce' ), |
|
1107 | - esc_attr( $op ), |
|
1108 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1109 | - esc_attr( $object_id ), |
|
1110 | - esc_attr( $wordpress_id ), |
|
1111 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1112 | - esc_attr( $object['Id'] ) |
|
1106 | + $title = sprintf(esc_html__('Success: %1$s %2$s with %3$s of %4$s (Salesforce %5$s Id of %6$s)', 'object-sync-for-salesforce'), |
|
1107 | + esc_attr($op), |
|
1108 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1109 | + esc_attr($object_id), |
|
1110 | + esc_attr($wordpress_id), |
|
1111 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1112 | + esc_attr($object['Id']) |
|
1113 | 1113 | ); |
1114 | 1114 | |
1115 | 1115 | $logging->setup( |
@@ -1122,40 +1122,40 @@ discard block |
||
1122 | 1122 | |
1123 | 1123 | // update that mapping object |
1124 | 1124 | $mapping_object['wordpress_id'] = $wordpress_id; |
1125 | - $mapping_object = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1125 | + $mapping_object = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1126 | 1126 | |
1127 | 1127 | // hook for pull success |
1128 | - do_action( 'object_sync_for_salesforce_pull_success', $op, $result, $synced_object ); |
|
1128 | + do_action('object_sync_for_salesforce_pull_success', $op, $result, $synced_object); |
|
1129 | 1129 | } else { |
1130 | 1130 | |
1131 | 1131 | // create log entry for failed create or upsert |
1132 | 1132 | // 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 |
1133 | 1133 | // if we see this in the log entries, we can understand what it does, but probably not until then |
1134 | 1134 | $status = 'error'; |
1135 | - if ( isset( $this->logging ) ) { |
|
1135 | + if (isset($this->logging)) { |
|
1136 | 1136 | $logging = $this->logging; |
1137 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1138 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1137 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1138 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | - if ( is_object( $wordpress_id ) ) { |
|
1141 | + if (is_object($wordpress_id)) { |
|
1142 | 1142 | // print this array because if this happens, something weird has happened and we want to log whatever we have |
1143 | - $wordpress_id = print_r( $wordpress_id, true ); |
|
1143 | + $wordpress_id = print_r($wordpress_id, true); |
|
1144 | 1144 | } |
1145 | 1145 | |
1146 | 1146 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object type, 3) the Salesforce object Id value |
1147 | - $title = sprintf( esc_html__( 'Error syncing: %1$s to WordPress (Salesforce %2$s Id %3$s)', 'object-sync-for-salesforce' ), |
|
1148 | - esc_attr( $op ), |
|
1149 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1150 | - esc_attr( $object['Id'] ) |
|
1147 | + $title = sprintf(esc_html__('Error syncing: %1$s to WordPress (Salesforce %2$s Id %3$s)', 'object-sync-for-salesforce'), |
|
1148 | + esc_attr($op), |
|
1149 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1150 | + esc_attr($object['Id']) |
|
1151 | 1151 | ); |
1152 | 1152 | |
1153 | 1153 | // translators: placeholders are: 1) the name of the WordPress object type, 2) the WordPress id field name, 3) the WordPress id field value, 4) the array of errors |
1154 | - $body = sprintf( '<p>' . esc_html__( 'Object: %1$s with %2$s of %3$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Message: ', 'object-sync-for-salesforce' ) . '%4$s', |
|
1155 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1156 | - esc_attr( $object_id ), |
|
1157 | - esc_attr( $wordpress_id ), |
|
1158 | - print_r( $result['errors'], true ) // if we get this error, we need to know whatever we have |
|
1154 | + $body = sprintf('<p>' . esc_html__('Object: %1$s with %2$s of %3$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Message: ', 'object-sync-for-salesforce') . '%4$s', |
|
1155 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1156 | + esc_attr($object_id), |
|
1157 | + esc_attr($wordpress_id), |
|
1158 | + print_r($result['errors'], true) // if we get this error, we need to know whatever we have |
|
1159 | 1159 | ); |
1160 | 1160 | |
1161 | 1161 | $logging->setup( |
@@ -1167,52 +1167,52 @@ discard block |
||
1167 | 1167 | ); |
1168 | 1168 | |
1169 | 1169 | // hook for pull fail |
1170 | - do_action( 'object_sync_for_salesforce_pull_fail', $op, $result, $synced_object ); |
|
1170 | + do_action('object_sync_for_salesforce_pull_fail', $op, $result, $synced_object); |
|
1171 | 1171 | |
1172 | 1172 | return; |
1173 | 1173 | } // End if(). |
1174 | - } elseif ( false === $is_new ) { |
|
1174 | + } elseif (false === $is_new) { |
|
1175 | 1175 | |
1176 | 1176 | // right here we should set the pulling transient |
1177 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
1178 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
1177 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
1178 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
1179 | 1179 | |
1180 | 1180 | // there is an existing object link |
1181 | 1181 | // if the last sync is greater than the last time this object was updated by Salesforce, skip it |
1182 | 1182 | // this keeps us from doing redundant syncs |
1183 | 1183 | // because SF stores all DateTimes in UTC. |
1184 | - $mapping_object['object_updated'] = current_time( 'mysql' ); |
|
1184 | + $mapping_object['object_updated'] = current_time('mysql'); |
|
1185 | 1185 | |
1186 | 1186 | $pull_trigger_field = $salesforce_mapping['pull_trigger_field']; |
1187 | - $pull_trigger_value = $object[ $pull_trigger_field ]; |
|
1187 | + $pull_trigger_value = $object[$pull_trigger_field]; |
|
1188 | 1188 | |
1189 | 1189 | try { |
1190 | 1190 | |
1191 | 1191 | // hook to allow other plugins to do something right before WordPress data is saved |
1192 | 1192 | // ex: run outside methods on an object if it exists, or do something in preparation for it if it doesn't |
1193 | - do_action( 'object_sync_for_salesforce_pre_pull', $mapping_object['wordpress_id'], $mapping, $object, $object_id, $params ); |
|
1193 | + do_action('object_sync_for_salesforce_pre_pull', $mapping_object['wordpress_id'], $mapping, $object, $object_id, $params); |
|
1194 | 1194 | |
1195 | 1195 | $op = 'Update'; |
1196 | - $result = $this->wordpress->object_update( $salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'], $params ); |
|
1196 | + $result = $this->wordpress->object_update($salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'], $params); |
|
1197 | 1197 | |
1198 | 1198 | $mapping_object['last_sync_status'] = $this->mappings->status_success; |
1199 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
1199 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
1200 | 1200 | |
1201 | 1201 | $status = 'success'; |
1202 | - if ( isset( $this->logging ) ) { |
|
1202 | + if (isset($this->logging)) { |
|
1203 | 1203 | $logging = $this->logging; |
1204 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1205 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1204 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1205 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | // 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 name of the Salesforce object, 6) the Salesforce Id value |
1209 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s with %3$s of %4$s (Salesforce %5$s Id of %6$s)', 'object-sync-for-salesforce' ), |
|
1210 | - esc_attr( $op ), |
|
1211 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1212 | - esc_attr( $object_id ), |
|
1213 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
1214 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1215 | - esc_attr( $object['Id'] ) |
|
1209 | + $title = sprintf(esc_html__('Success: %1$s %2$s with %3$s of %4$s (Salesforce %5$s Id of %6$s)', 'object-sync-for-salesforce'), |
|
1210 | + esc_attr($op), |
|
1211 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1212 | + esc_attr($object_id), |
|
1213 | + esc_attr($mapping_object['wordpress_id']), |
|
1214 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1215 | + esc_attr($object['Id']) |
|
1216 | 1216 | ); |
1217 | 1217 | |
1218 | 1218 | $logging->setup( |
@@ -1224,25 +1224,25 @@ discard block |
||
1224 | 1224 | ); |
1225 | 1225 | |
1226 | 1226 | // hook for pull success |
1227 | - do_action( 'object_sync_for_salesforce_pull_success', $op, $result, $synced_object ); |
|
1227 | + do_action('object_sync_for_salesforce_pull_success', $op, $result, $synced_object); |
|
1228 | 1228 | |
1229 | - } catch ( WordpressException $e ) { |
|
1229 | + } catch (WordpressException $e) { |
|
1230 | 1230 | // create log entry for failed update |
1231 | 1231 | $status = 'error'; |
1232 | - if ( isset( $this->logging ) ) { |
|
1232 | + if (isset($this->logging)) { |
|
1233 | 1233 | $logging = $this->logging; |
1234 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1235 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1234 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1235 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1236 | 1236 | } |
1237 | 1237 | |
1238 | 1238 | // translators: placeholders are: 1) what operation is happening, 2) the name of the WordPress object, 3) the WordPress id field name, 4) the WordPress object id value, 5) the name of the Salesforce object, 6) the Salesforce Id value |
1239 | - $title .= sprintf( esc_html__( 'Error: %1$s %2$s with %3$s of %4$s (Salesforce %5$s with Id of %6$s)', 'object-sync-for-salesforce' ), |
|
1240 | - esc_attr( $op ), |
|
1241 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1242 | - esc_attr( $object_id ), |
|
1243 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
1244 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1245 | - esc_attr( $object['Id'] ) |
|
1239 | + $title .= sprintf(esc_html__('Error: %1$s %2$s with %3$s of %4$s (Salesforce %5$s with Id of %6$s)', 'object-sync-for-salesforce'), |
|
1240 | + esc_attr($op), |
|
1241 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1242 | + esc_attr($object_id), |
|
1243 | + esc_attr($mapping_object['wordpress_id']), |
|
1244 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1245 | + esc_attr($object['Id']) |
|
1246 | 1246 | ); |
1247 | 1247 | |
1248 | 1248 | $logging->setup( |
@@ -1256,18 +1256,18 @@ discard block |
||
1256 | 1256 | $mapping_object['last_sync_status'] = $this->mappings->status_error; |
1257 | 1257 | $mapping_object['last_sync_message'] = $e->getMessage(); |
1258 | 1258 | |
1259 | - if ( false === $hold_exceptions ) { |
|
1259 | + if (false === $hold_exceptions) { |
|
1260 | 1260 | throw $e; |
1261 | 1261 | } |
1262 | - if ( empty( $exception ) ) { |
|
1262 | + if (empty($exception)) { |
|
1263 | 1263 | $exception = $e; |
1264 | 1264 | } else { |
1265 | - $my_class = get_class( $e ); |
|
1266 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
1265 | + $my_class = get_class($e); |
|
1266 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | // hook for pull fail |
1270 | - do_action( 'object_sync_for_salesforce_pull_fail', $op, $result, $synced_object ); |
|
1270 | + do_action('object_sync_for_salesforce_pull_fail', $op, $result, $synced_object); |
|
1271 | 1271 | |
1272 | 1272 | } // End try(). |
1273 | 1273 | |
@@ -1276,26 +1276,26 @@ discard block |
||
1276 | 1276 | // maybe can check to see if we actually updated anything in WordPress |
1277 | 1277 | // tell the mapping object - whether it is new or already existed - how we just used it |
1278 | 1278 | $mapping_object['last_sync_action'] = 'pull'; |
1279 | - $mapping_object['last_sync'] = current_time( 'mysql' ); |
|
1279 | + $mapping_object['last_sync'] = current_time('mysql'); |
|
1280 | 1280 | |
1281 | 1281 | // update that mapping object. the Salesforce data version will be set here as well because we set it earlier |
1282 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1282 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1283 | 1283 | // end of the if statement for is_new & update or create trigger |
1284 | 1284 | // this keeps stuff from running too many times, and also keeps it from using the wrong methods. we don't need a generic } else { here at this time. |
1285 | 1285 | } // End if(). |
1286 | 1286 | } // End foreach(). |
1287 | 1287 | |
1288 | 1288 | // delete transients that we've already processed |
1289 | - foreach ( $transients_to_delete as $mapping_object_id_transient ) { |
|
1290 | - delete_transient( 'salesforce_pushing_' . $mapping_object_id_transient ); |
|
1289 | + foreach ($transients_to_delete as $mapping_object_id_transient) { |
|
1290 | + delete_transient('salesforce_pushing_' . $mapping_object_id_transient); |
|
1291 | 1291 | } |
1292 | 1292 | |
1293 | - $pushing_id = get_transient( 'salesforce_pushing_object_id' ); |
|
1294 | - if ( in_array( $pushing_id, $transients_to_delete, true ) ) { |
|
1295 | - delete_transient( 'salesforce_pushing_object_id' ); |
|
1293 | + $pushing_id = get_transient('salesforce_pushing_object_id'); |
|
1294 | + if (in_array($pushing_id, $transients_to_delete, true)) { |
|
1295 | + delete_transient('salesforce_pushing_object_id'); |
|
1296 | 1296 | } |
1297 | 1297 | |
1298 | - if ( ! empty( $exception ) ) { |
|
1298 | + if ( ! empty($exception)) { |
|
1299 | 1299 | throw $exception; |
1300 | 1300 | } |
1301 | 1301 | |
@@ -1315,17 +1315,17 @@ discard block |
||
1315 | 1315 | * This is the database row for the map object |
1316 | 1316 | * |
1317 | 1317 | */ |
1318 | - private function create_object_map( $salesforce_object, $wordpress_id, $field_mapping ) { |
|
1318 | + private function create_object_map($salesforce_object, $wordpress_id, $field_mapping) { |
|
1319 | 1319 | // Create object map and save it |
1320 | 1320 | $mapping_object = $this->mappings->create_object_map( |
1321 | 1321 | array( |
1322 | 1322 | 'wordpress_id' => $wordpress_id, // wordpress unique id |
1323 | 1323 | 'salesforce_id' => $salesforce_object['Id'], // salesforce unique id. we don't care what kind of object it is at this point |
1324 | 1324 | 'wordpress_object' => $field_mapping['wordpress_object'], // keep track of what kind of wp object this is |
1325 | - 'last_sync' => current_time( 'mysql' ), |
|
1325 | + 'last_sync' => current_time('mysql'), |
|
1326 | 1326 | 'last_sync_action' => 'pull', |
1327 | 1327 | 'last_sync_status' => $this->mappings->status_success, |
1328 | - 'last_sync_message' => esc_html__( 'Mapping object created via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
1328 | + 'last_sync_message' => esc_html__('Mapping object created via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
1329 | 1329 | 'action' => 'created', |
1330 | 1330 | ) |
1331 | 1331 | ); |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | protected $schedulable_classes; |
21 | 21 | |
22 | 22 | /** |
23 | - * Constructor which sets up deactivate hooks |
|
24 | - * @param object $wpdb |
|
25 | - * @param string $version |
|
26 | - * @param string $slug |
|
27 | - * @param array $schedulable_classes |
|
28 | - * |
|
29 | - */ |
|
23 | + * Constructor which sets up deactivate hooks |
|
24 | + * @param object $wpdb |
|
25 | + * @param string $version |
|
26 | + * @param string $slug |
|
27 | + * @param array $schedulable_classes |
|
28 | + * |
|
29 | + */ |
|
30 | 30 | public function __construct( $wpdb, $version, $slug, $schedulable_classes ) { |
31 | 31 | $this->wpdb = $wpdb; |
32 | 32 | $this->version = $version; |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | - * Drop database tables for Salesforce |
|
49 | - * This removes the tables for fieldmaps (between types of objects) and object maps (between indidual instances of objects) |
|
50 | - * |
|
51 | - */ |
|
48 | + * Drop database tables for Salesforce |
|
49 | + * This removes the tables for fieldmaps (between types of objects) and object maps (between indidual instances of objects) |
|
50 | + * |
|
51 | + */ |
|
52 | 52 | public function wordpress_salesforce_drop_tables() { |
53 | 53 | $field_map_table = $this->wpdb->prefix . 'object_sync_sf_field_map'; |
54 | 54 | $object_map_table = $this->wpdb->prefix . 'object_sync_sf_object_map'; |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | - * Clear the scheduled tasks |
|
62 | - * This removes all the scheduled tasks that are included in the plugin's $schedulable_classes array |
|
61 | + * Clear the scheduled tasks |
|
62 | + * This removes all the scheduled tasks that are included in the plugin's $schedulable_classes array |
|
63 | 63 | // todo: fix this so it uses action scheduler's scheduled tasks instead |
64 | - * |
|
65 | - */ |
|
64 | + * |
|
65 | + */ |
|
66 | 66 | public function clear_schedule() { |
67 | 67 | foreach ( $this->schedulable_classes as $key => $value ) { |
68 | 68 | wp_clear_scheduled_hook( $key ); |
@@ -70,21 +70,21 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | - * Delete the log post type |
|
74 | - * This removes the log post type |
|
75 | - * |
|
76 | - */ |
|
73 | + * Delete the log post type |
|
74 | + * This removes the log post type |
|
75 | + * |
|
76 | + */ |
|
77 | 77 | public function delete_log_post_type() { |
78 | 78 | unregister_post_type( 'wp_log' ); |
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | - * Remove roles and capabilities |
|
83 | - * This removes the configure_salesforce capability from the admin role |
|
84 | - * |
|
85 | - * It also allows other plugins to remove the capability from other roles |
|
86 | - * |
|
87 | - */ |
|
82 | + * Remove roles and capabilities |
|
83 | + * This removes the configure_salesforce capability from the admin role |
|
84 | + * |
|
85 | + * It also allows other plugins to remove the capability from other roles |
|
86 | + * |
|
87 | + */ |
|
88 | 88 | public function remove_roles_capabilities() { |
89 | 89 | |
90 | 90 | // by default, only administrators can configure the plugin |
@@ -104,18 +104,18 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | - * Flush the plugin cache |
|
108 | - * |
|
109 | - */ |
|
107 | + * Flush the plugin cache |
|
108 | + * |
|
109 | + */ |
|
110 | 110 | public function flush_plugin_cache() { |
111 | 111 | $sfwp_transients = new Object_Sync_Sf_WordPress_Transient( 'sfwp_transients' ); |
112 | 112 | $sfwp_transients->flush(); |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | - * Clear the plugin options |
|
117 | - * |
|
118 | - */ |
|
116 | + * Clear the plugin options |
|
117 | + * |
|
118 | + */ |
|
119 | 119 | public function delete_plugin_options() { |
120 | 120 | $table = $this->wpdb->prefix . 'options'; |
121 | 121 | $plugin_options = $this->wpdb->get_results( 'SELECT option_name FROM ' . $table . ' WHERE option_name LIKE "object_sync_for_salesforce_%"', ARRAY_A ); |
@@ -5,7 +5,7 @@ discard block |
||
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 | |
@@ -27,20 +27,20 @@ discard block |
||
27 | 27 | * @param array $schedulable_classes |
28 | 28 | * |
29 | 29 | */ |
30 | - public function __construct( $wpdb, $version, $slug, $schedulable_classes ) { |
|
30 | + public function __construct($wpdb, $version, $slug, $schedulable_classes) { |
|
31 | 31 | $this->wpdb = $wpdb; |
32 | 32 | $this->version = $version; |
33 | 33 | $this->slug = $slug; |
34 | 34 | $this->schedulable_classes = $schedulable_classes; |
35 | - $delete_data = (int) get_option( 'object_sync_for_salesforce_delete_data_on_uninstall', 0 ); |
|
36 | - if ( 1 === $delete_data ) { |
|
37 | - register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'wordpress_salesforce_drop_tables' ) ); |
|
38 | - register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'clear_schedule' ) ); |
|
39 | - register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'delete_log_post_type' ) ); |
|
40 | - register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'remove_roles_capabilities' ) ); |
|
41 | - register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'flush_plugin_cache' ) |
|
35 | + $delete_data = (int) get_option('object_sync_for_salesforce_delete_data_on_uninstall', 0); |
|
36 | + if (1 === $delete_data) { |
|
37 | + register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'wordpress_salesforce_drop_tables')); |
|
38 | + register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'clear_schedule')); |
|
39 | + register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'delete_log_post_type')); |
|
40 | + register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'remove_roles_capabilities')); |
|
41 | + register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'flush_plugin_cache') |
|
42 | 42 | ); |
43 | - register_deactivation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'delete_plugin_options' ) ); |
|
43 | + register_deactivation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'delete_plugin_options')); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | public function wordpress_salesforce_drop_tables() { |
53 | 53 | $field_map_table = $this->wpdb->prefix . 'object_sync_sf_field_map'; |
54 | 54 | $object_map_table = $this->wpdb->prefix . 'object_sync_sf_object_map'; |
55 | - $this->wpdb->query( 'DROP TABLE IF EXISTS ' . $field_map_table ); |
|
56 | - $this->wpdb->query( 'DROP TABLE IF EXISTS ' . $object_map_table ); |
|
57 | - delete_option( 'object_sync_for_salesforce_db_version' ); |
|
55 | + $this->wpdb->query('DROP TABLE IF EXISTS ' . $field_map_table); |
|
56 | + $this->wpdb->query('DROP TABLE IF EXISTS ' . $object_map_table); |
|
57 | + delete_option('object_sync_for_salesforce_db_version'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | * |
65 | 65 | */ |
66 | 66 | public function clear_schedule() { |
67 | - foreach ( $this->schedulable_classes as $key => $value ) { |
|
68 | - wp_clear_scheduled_hook( $key ); |
|
67 | + foreach ($this->schedulable_classes as $key => $value) { |
|
68 | + wp_clear_scheduled_hook($key); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | */ |
77 | 77 | public function delete_log_post_type() { |
78 | - unregister_post_type( 'wp_log' ); |
|
78 | + unregister_post_type('wp_log'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | public function remove_roles_capabilities() { |
89 | 89 | |
90 | 90 | // by default, only administrators can configure the plugin |
91 | - $role = get_role( 'administrator' ); |
|
92 | - $role->remove_cap( 'configure_salesforce' ); |
|
91 | + $role = get_role('administrator'); |
|
92 | + $role->remove_cap('configure_salesforce'); |
|
93 | 93 | |
94 | 94 | // hook that allows other roles to configure the plugin as well |
95 | - $roles = apply_filters( 'object_sync_for_salesforce_roles_configure_salesforce', null ); |
|
95 | + $roles = apply_filters('object_sync_for_salesforce_roles_configure_salesforce', null); |
|
96 | 96 | |
97 | 97 | // for each role that we have, remove the configure salesforce capability |
98 | - if ( null !== $roles ) { |
|
99 | - foreach ( $roles as $role ) { |
|
100 | - $role->remove_cap( 'configure_salesforce' ); |
|
98 | + if (null !== $roles) { |
|
99 | + foreach ($roles as $role) { |
|
100 | + $role->remove_cap('configure_salesforce'); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * |
109 | 109 | */ |
110 | 110 | public function flush_plugin_cache() { |
111 | - $sfwp_transients = new Object_Sync_Sf_WordPress_Transient( 'sfwp_transients' ); |
|
111 | + $sfwp_transients = new Object_Sync_Sf_WordPress_Transient('sfwp_transients'); |
|
112 | 112 | $sfwp_transients->flush(); |
113 | 113 | } |
114 | 114 | |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function delete_plugin_options() { |
120 | 120 | $table = $this->wpdb->prefix . 'options'; |
121 | - $plugin_options = $this->wpdb->get_results( 'SELECT option_name FROM ' . $table . ' WHERE option_name LIKE "object_sync_for_salesforce_%"', ARRAY_A ); |
|
122 | - foreach ( $plugin_options as $option ) { |
|
123 | - delete_option( $option['option_name'] ); |
|
121 | + $plugin_options = $this->wpdb->get_results('SELECT option_name FROM ' . $table . ' WHERE option_name LIKE "object_sync_for_salesforce_%"', ARRAY_A); |
|
122 | + foreach ($plugin_options as $option) { |
|
123 | + delete_option($option['option_name']); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 |