@@ -1,12 +1,12 @@ |
||
1 | 1 | <input type="hidden" name="salesforce_update_mapped_user" value="1" /> |
2 | -<h2><?php echo esc_html__( 'Salesforce', 'object-sync-for-salesforce' ); ?></h2> |
|
3 | -<p><?php echo esc_html__( 'You can change the Salesforce object that this WordPress user maps to by changing the ID and updating this user.', 'object-sync-for-salesforce' ); ?></p> |
|
2 | +<h2><?php echo esc_html__('Salesforce', 'object-sync-for-salesforce'); ?></h2> |
|
3 | +<p><?php echo esc_html__('You can change the Salesforce object that this WordPress user maps to by changing the ID and updating this user.', 'object-sync-for-salesforce'); ?></p> |
|
4 | 4 | <table class="form-table"> |
5 | 5 | <tr> |
6 | - <th><label for="salesforce_id"><?php echo esc_html__( 'Salesforce ID', 'object-sync-for-salesforce' ); ?></label></th> |
|
6 | + <th><label for="salesforce_id"><?php echo esc_html__('Salesforce ID', 'object-sync-for-salesforce'); ?></label></th> |
|
7 | 7 | <td> |
8 | - <input type="text" name="salesforce_id" id="salesforce_id" value="<?php if ( isset( $mapping['id'] ) ) { echo esc_html( $mapping['salesforce_id'] ); } ?>" class="regular-text" /><br /> |
|
9 | - <span class="description"><?php echo esc_html__( 'Enter a Salesforce object ID.', 'object-sync-for-salesforce' ); ?></span> |
|
8 | + <input type="text" name="salesforce_id" id="salesforce_id" value="<?php if (isset($mapping['id'])) { echo esc_html($mapping['salesforce_id']); } ?>" class="regular-text" /><br /> |
|
9 | + <span class="description"><?php echo esc_html__('Enter a Salesforce object ID.', 'object-sync-for-salesforce'); ?></span> |
|
10 | 10 | </td> |
11 | 11 | </tr> |
12 | 12 | </table> |
@@ -1,2 +1,2 @@ |
||
1 | -<div class="success"><h2><?php echo esc_html__( 'Salesforce is successfully authenticated.' ); ?></h2></div> |
|
2 | -<p><a class="button button-primary" href="<?php echo esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=logout' ) ); ?>"><?php echo esc_html__( 'Disconnect from Salesforce', 'object-sync-for-salesforce' ); ?></a></p> |
|
1 | +<div class="success"><h2><?php echo esc_html__('Salesforce is successfully authenticated.'); ?></h2></div> |
|
2 | +<p><a class="button button-primary" href="<?php echo esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=logout')); ?>"><?php echo esc_html__('Disconnect from Salesforce', 'object-sync-for-salesforce'); ?></a></p> |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <input type="hidden" name="salesforce_create_mapped_user" value="1" /> |
2 | -<h2><?php echo esc_html__( 'Salesforce', 'object-sync-for-salesforce' ); ?></h2> |
|
3 | -<p><?php echo esc_html__( "This user is not mapped to an object in Salesforce. You can run a push to send this object to Salesforce, which will cause it to follow the plugin's normal mapping conventions, or you can create a manual link to a Salesforce object.", 'object-sync-for-salesforce' ); ?></p> |
|
2 | +<h2><?php echo esc_html__('Salesforce', 'object-sync-for-salesforce'); ?></h2> |
|
3 | +<p><?php echo esc_html__("This user is not mapped to an object in Salesforce. You can run a push to send this object to Salesforce, which will cause it to follow the plugin's normal mapping conventions, or you can create a manual link to a Salesforce object.", 'object-sync-for-salesforce'); ?></p> |
|
4 | 4 | <table class="form-table"> |
5 | 5 | <tr> |
6 | - <th><label for="salesforce_id"><?php echo esc_html__( 'Salesforce ID', 'object-sync-for-salesforce' ); ?></label></th> |
|
6 | + <th><label for="salesforce_id"><?php echo esc_html__('Salesforce ID', 'object-sync-for-salesforce'); ?></label></th> |
|
7 | 7 | <td> |
8 | 8 | <input type="text" name="salesforce_id" id="salesforce_id" value="" class="regular-text" /><br /> |
9 | - <span class="description"><?php echo esc_html__( 'Enter a Salesforce object ID.', 'object-sync-for-salesforce' ); ?></span> |
|
9 | + <span class="description"><?php echo esc_html__('Enter a Salesforce object ID.', 'object-sync-for-salesforce'); ?></span> |
|
10 | 10 | <p><strong>or</strong></p> |
11 | - <p><button type="submit" class="button button-secondary push_to_salesforce_button" name="push_new_user_to_salesforce"><?php echo esc_html__( 'Push to Salesforce as new record', 'object-sync-for-salesforce' ); ?></button></p> |
|
11 | + <p><button type="submit" class="button button-secondary push_to_salesforce_button" name="push_new_user_to_salesforce"><?php echo esc_html__('Push to Salesforce as new record', 'object-sync-for-salesforce'); ?></button></p> |
|
12 | 12 | </td> |
13 | 13 | </tr> |
14 | 14 | </table> |
@@ -22,27 +22,27 @@ discard block |
||
22 | 22 | public $conditions = array(); |
23 | 23 | |
24 | 24 | /** |
25 | - * Constructor which sets the query object type. |
|
26 | - * |
|
27 | - * @param string $object_type |
|
28 | - * Salesforce object type to query. |
|
29 | - */ |
|
25 | + * Constructor which sets the query object type. |
|
26 | + * |
|
27 | + * @param string $object_type |
|
28 | + * Salesforce object type to query. |
|
29 | + */ |
|
30 | 30 | public function __construct( $object_type = '' ) { |
31 | 31 | $this->object_type = $object_type; |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
35 | - * Add a condition to the query. |
|
36 | - * |
|
37 | - * @param string $field |
|
38 | - * Field name. |
|
39 | - * @param mixed $value |
|
40 | - * Condition value. If an array, it will be split into quote enclosed |
|
41 | - * strings separated by commas inside of parenthesis. Note that the caller |
|
42 | - * must enclose the value in quotes as needed by the SF API. |
|
43 | - * @param string $operator |
|
44 | - * Conditional operator. One of '=', '!=', '<', '>', 'LIKE, 'IN', 'NOT IN'. |
|
45 | - */ |
|
35 | + * Add a condition to the query. |
|
36 | + * |
|
37 | + * @param string $field |
|
38 | + * Field name. |
|
39 | + * @param mixed $value |
|
40 | + * Condition value. If an array, it will be split into quote enclosed |
|
41 | + * strings separated by commas inside of parenthesis. Note that the caller |
|
42 | + * must enclose the value in quotes as needed by the SF API. |
|
43 | + * @param string $operator |
|
44 | + * Conditional operator. One of '=', '!=', '<', '>', 'LIKE, 'IN', 'NOT IN'. |
|
45 | + */ |
|
46 | 46 | public function add_condition( $field, $value, $operator = '=' ) { |
47 | 47 | if ( is_array( $value ) ) { |
48 | 48 | $value = "('" . implode( "','", $value ) . "')"; |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Implements PHP's magic __toString(). |
|
64 | - * |
|
65 | - * Function to convert the query to a string to pass to the SF API. |
|
66 | - * |
|
67 | - * @return string |
|
68 | - * SOQL query ready to be executed the SF API. |
|
69 | - */ |
|
63 | + * Implements PHP's magic __toString(). |
|
64 | + * |
|
65 | + * Function to convert the query to a string to pass to the SF API. |
|
66 | + * |
|
67 | + * @return string |
|
68 | + * SOQL query ready to be executed the SF API. |
|
69 | + */ |
|
70 | 70 | public function __toString() { |
71 | 71 | |
72 | 72 | $query = 'SELECT '; |
@@ -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,7 +27,7 @@ discard block |
||
27 | 27 | * @param string $object_type |
28 | 28 | * Salesforce object type to query. |
29 | 29 | */ |
30 | - public function __construct( $object_type = '' ) { |
|
30 | + public function __construct($object_type = '') { |
|
31 | 31 | $this->object_type = $object_type; |
32 | 32 | } |
33 | 33 | |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | * @param string $operator |
44 | 44 | * Conditional operator. One of '=', '!=', '<', '>', 'LIKE, 'IN', 'NOT IN'. |
45 | 45 | */ |
46 | - public function add_condition( $field, $value, $operator = '=' ) { |
|
47 | - if ( is_array( $value ) ) { |
|
48 | - $value = "('" . implode( "','", $value ) . "')"; |
|
46 | + public function add_condition($field, $value, $operator = '=') { |
|
47 | + if (is_array($value)) { |
|
48 | + $value = "('" . implode("','", $value) . "')"; |
|
49 | 49 | |
50 | 50 | // Set operator to IN if wasn't already changed from the default. |
51 | - if ( '=' === $operator ) { |
|
51 | + if ('=' === $operator) { |
|
52 | 52 | $operator = 'IN'; |
53 | 53 | } |
54 | 54 | } |
@@ -70,31 +70,31 @@ discard block |
||
70 | 70 | public function __toString() { |
71 | 71 | |
72 | 72 | $query = 'SELECT '; |
73 | - $query .= implode( ', ', $this->fields ); |
|
73 | + $query .= implode(', ', $this->fields); |
|
74 | 74 | $query .= ' FROM ' . $this->object_type; |
75 | 75 | |
76 | - if ( count( $this->conditions ) > 0 ) { |
|
76 | + if (count($this->conditions) > 0) { |
|
77 | 77 | $where = array(); |
78 | - foreach ( $this->conditions as $condition ) { |
|
79 | - $where[] = implode( ' ', $condition ); |
|
78 | + foreach ($this->conditions as $condition) { |
|
79 | + $where[] = implode(' ', $condition); |
|
80 | 80 | } |
81 | - $query .= ' WHERE ' . implode( ' AND ', $where ); |
|
81 | + $query .= ' WHERE ' . implode(' AND ', $where); |
|
82 | 82 | } |
83 | 83 | |
84 | - if ( $this->order ) { |
|
84 | + if ($this->order) { |
|
85 | 85 | $query .= ' ORDER BY '; |
86 | 86 | $fields = array(); |
87 | - foreach ( $this->order as $field => $direction ) { |
|
87 | + foreach ($this->order as $field => $direction) { |
|
88 | 88 | $fields[] = $field . ' ' . $direction; |
89 | 89 | } |
90 | - $query .= implode( ', ', $fields ); |
|
90 | + $query .= implode(', ', $fields); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( $this->limit ) { |
|
93 | + if ($this->limit) { |
|
94 | 94 | $query .= ' LIMIT ' . (int) $this->limit; |
95 | 95 | } |
96 | 96 | |
97 | - if ( $this->offset ) { |
|
97 | + if ($this->offset) { |
|
98 | 98 | $query .= ' OFFSET ' . (int) $this->offset; |
99 | 99 | } |
100 | 100 |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | protected $template; |
22 | 22 | |
23 | 23 | /** |
24 | - * Constructor which sets up the admin_notices hook for rendering |
|
25 | - * |
|
26 | - * @param mixed $condition |
|
27 | - * @param string $message |
|
28 | - * @param bool $dismissible |
|
29 | - * @param string $type |
|
30 | - * @param string $template |
|
31 | - * |
|
32 | - */ |
|
24 | + * Constructor which sets up the admin_notices hook for rendering |
|
25 | + * |
|
26 | + * @param mixed $condition |
|
27 | + * @param string $message |
|
28 | + * @param bool $dismissible |
|
29 | + * @param string $type |
|
30 | + * @param string $template |
|
31 | + * |
|
32 | + */ |
|
33 | 33 | public function __construct( $condition, $message, $dismissible = false, $type = '', $template = '' ) { |
34 | 34 | $this->condition = $condition; |
35 | 35 | $this->message = $message; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Render an admin notice |
|
46 | - * |
|
47 | - */ |
|
45 | + * Render an admin notice |
|
46 | + * |
|
47 | + */ |
|
48 | 48 | public function render() { |
49 | 49 | |
50 | 50 | // class for the notice to use |
@@ -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,14 +30,14 @@ discard block |
||
30 | 30 | * @param string $template |
31 | 31 | * |
32 | 32 | */ |
33 | - public function __construct( $condition, $message, $dismissible = false, $type = '', $template = '' ) { |
|
33 | + public function __construct($condition, $message, $dismissible = false, $type = '', $template = '') { |
|
34 | 34 | $this->condition = $condition; |
35 | 35 | $this->message = $message; |
36 | 36 | $this->dismissible = $dismissible; |
37 | 37 | $this->type = $type; |
38 | 38 | $this->template = $template; |
39 | 39 | |
40 | - add_action( 'admin_notices', array( $this, 'render' ) ); |
|
40 | + add_action('admin_notices', array($this, 'render')); |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
@@ -49,18 +49,18 @@ discard block |
||
49 | 49 | |
50 | 50 | // class for the notice to use |
51 | 51 | $class = ''; |
52 | - if ( '' !== $this->type ) { |
|
52 | + if ('' !== $this->type) { |
|
53 | 53 | $class = ' notice-' . $this->type; |
54 | 54 | } |
55 | 55 | |
56 | 56 | $dismissible = ''; |
57 | - if ( true === $this->dismissible ) { |
|
57 | + if (true === $this->dismissible) { |
|
58 | 58 | $dismissible = ' is-dismissible'; |
59 | 59 | } |
60 | 60 | |
61 | 61 | // template for notice has a default |
62 | - if ( '' === $this->template ) { |
|
63 | - $template = plugin_dir_path( __FILE__ ) . '/../templates/admin/notice.php'; |
|
62 | + if ('' === $this->template) { |
|
63 | + $template = plugin_dir_path(__FILE__) . '/../templates/admin/notice.php'; |
|
64 | 64 | } else { |
65 | 65 | $template = $this->template; |
66 | 66 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $condition = $this->condition; |
69 | 69 | $message = $this->message; |
70 | 70 | |
71 | - require_once( $template ); |
|
71 | + require_once($template); |
|
72 | 72 | |
73 | 73 | } |
74 | 74 |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | protected $installed_version; |
20 | 20 | |
21 | 21 | /** |
22 | - * Constructor which sets up activate hooks |
|
23 | - * |
|
24 | - * @param object $wpdb |
|
25 | - * @param string $version |
|
26 | - * @param string $slug |
|
27 | - * |
|
28 | - */ |
|
22 | + * Constructor which sets up activate hooks |
|
23 | + * |
|
24 | + * @param object $wpdb |
|
25 | + * @param string $version |
|
26 | + * @param string $slug |
|
27 | + * |
|
28 | + */ |
|
29 | 29 | public function __construct( $wpdb, $version, $slug ) { |
30 | 30 | $this->wpdb = $wpdb; |
31 | 31 | $this->version = $version; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | - * Check for the minimum required version of php |
|
41 | - */ |
|
40 | + * Check for the minimum required version of php |
|
41 | + */ |
|
42 | 42 | public function php_requirements() { |
43 | 43 | if ( version_compare( PHP_VERSION, '5.5', '<' ) ) { |
44 | 44 | deactivate_plugins( plugin_basename( __FILE__ ) ); |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * Create database tables for Salesforce |
|
51 | - * This creates tables for fieldmaps (between types of objects) and object maps (between indidual instances of objects) |
|
52 | - * |
|
53 | - */ |
|
50 | + * Create database tables for Salesforce |
|
51 | + * This creates tables for fieldmaps (between types of objects) and object maps (between indidual instances of objects) |
|
52 | + * |
|
53 | + */ |
|
54 | 54 | public function wordpress_salesforce_tables() { |
55 | 55 | |
56 | 56 | $charset_collate = $this->wpdb->get_charset_collate(); |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | - * Check for database version on plugin upgrade |
|
115 | - * When the plugin is upgraded, if the database version does not match the current version, perform these methods |
|
116 | - * |
|
117 | - */ |
|
114 | + * Check for database version on plugin upgrade |
|
115 | + * When the plugin is upgraded, if the database version does not match the current version, perform these methods |
|
116 | + * |
|
117 | + */ |
|
118 | 118 | public function wordpress_salesforce_update_db_check() { |
119 | 119 | if ( get_site_option( 'object_sync_for_salesforce_db_version' ) !== $this->version ) { |
120 | 120 | $this->wordpress_salesforce_tables(); |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | - * Add roles and capabilities |
|
126 | - * This adds the configure_salesforce capability to the admin role |
|
127 | - * |
|
128 | - * It also allows other plugins to add the capability to other roles |
|
129 | - * |
|
130 | - */ |
|
125 | + * Add roles and capabilities |
|
126 | + * This adds the configure_salesforce capability to the admin role |
|
127 | + * |
|
128 | + * It also allows other plugins to add the capability to other roles |
|
129 | + * |
|
130 | + */ |
|
131 | 131 | public function add_roles_capabilities() { |
132 | 132 | |
133 | 133 | // by default, only administrators can configure the plugin |
@@ -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 | |
@@ -26,23 +26,23 @@ discard block |
||
26 | 26 | * @param string $slug |
27 | 27 | * |
28 | 28 | */ |
29 | - public function __construct( $wpdb, $version, $slug ) { |
|
29 | + public function __construct($wpdb, $version, $slug) { |
|
30 | 30 | $this->wpdb = $wpdb; |
31 | 31 | $this->version = $version; |
32 | - $this->installed_version = get_option( 'object_sync_for_salesforce_db_version', '' ); |
|
33 | - register_activation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'php_requirements' ) ); |
|
34 | - register_activation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'wordpress_salesforce_tables' ) ); |
|
35 | - register_activation_hook( dirname( __DIR__ ) . '/' . $slug . '.php', array( $this, 'add_roles_capabilities' ) ); |
|
36 | - add_action( 'plugins_loaded', array( $this, 'wordpress_salesforce_update_db_check' ) ); |
|
32 | + $this->installed_version = get_option('object_sync_for_salesforce_db_version', ''); |
|
33 | + register_activation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'php_requirements')); |
|
34 | + register_activation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'wordpress_salesforce_tables')); |
|
35 | + register_activation_hook(dirname(__DIR__) . '/' . $slug . '.php', array($this, 'add_roles_capabilities')); |
|
36 | + add_action('plugins_loaded', array($this, 'wordpress_salesforce_update_db_check')); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Check for the minimum required version of php |
41 | 41 | */ |
42 | 42 | public function php_requirements() { |
43 | - if ( version_compare( PHP_VERSION, '5.5', '<' ) ) { |
|
44 | - deactivate_plugins( plugin_basename( __FILE__ ) ); |
|
45 | - 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.' ); |
|
43 | + if (version_compare(PHP_VERSION, '5.5', '<')) { |
|
44 | + deactivate_plugins(plugin_basename(__FILE__)); |
|
45 | + 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.'); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | KEY salesforce_object (salesforce_id) |
96 | 96 | ) $charset_collate"; |
97 | 97 | |
98 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
98 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
99 | 99 | |
100 | 100 | // Note: see https://wordpress.stackexchange.com/questions/67345/how-to-implement-wordpress-plugin-update-that-modifies-the-database |
101 | 101 | // 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." |
102 | 102 | // 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. |
103 | - dbDelta( $field_map_sql ); |
|
104 | - dbDelta( $object_map_sql ); |
|
103 | + dbDelta($field_map_sql); |
|
104 | + dbDelta($object_map_sql); |
|
105 | 105 | |
106 | - update_option( 'object_sync_for_salesforce_db_version', $this->version ); |
|
106 | + update_option('object_sync_for_salesforce_db_version', $this->version); |
|
107 | 107 | |
108 | 108 | // store right now as the time for the plugin's activation |
109 | - update_option( 'object_sync_for_salesforce_activate_time', current_time( 'timestamp', true ) ); |
|
109 | + update_option('object_sync_for_salesforce_activate_time', current_time('timestamp', true)); |
|
110 | 110 | |
111 | 111 | } |
112 | 112 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * |
117 | 117 | */ |
118 | 118 | public function wordpress_salesforce_update_db_check() { |
119 | - if ( get_site_option( 'object_sync_for_salesforce_db_version' ) !== $this->version ) { |
|
119 | + if (get_site_option('object_sync_for_salesforce_db_version') !== $this->version) { |
|
120 | 120 | $this->wordpress_salesforce_tables(); |
121 | 121 | } |
122 | 122 | } |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | public function add_roles_capabilities() { |
132 | 132 | |
133 | 133 | // by default, only administrators can configure the plugin |
134 | - $role = get_role( 'administrator' ); |
|
135 | - $role->add_cap( 'configure_salesforce' ); |
|
134 | + $role = get_role('administrator'); |
|
135 | + $role->add_cap('configure_salesforce'); |
|
136 | 136 | |
137 | 137 | // hook that allows other roles to configure the plugin as well |
138 | - $roles = apply_filters( 'object_sync_for_salesforce_roles_configure_salesforce', null ); |
|
138 | + $roles = apply_filters('object_sync_for_salesforce_roles_configure_salesforce', null); |
|
139 | 139 | |
140 | 140 | // for each role that we have, give it the configure salesforce capability |
141 | - if ( null !== $roles ) { |
|
142 | - foreach ( $roles as $role ) { |
|
143 | - $role = get_role( $role ); |
|
144 | - $role->add_cap( 'configure_salesforce' ); |
|
141 | + if (null !== $roles) { |
|
142 | + foreach ($roles as $role) { |
|
143 | + $role = get_role($role); |
|
144 | + $role->add_cap('configure_salesforce'); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 |
@@ -24,24 +24,24 @@ discard block |
||
24 | 24 | protected $schedulable_classes; |
25 | 25 | |
26 | 26 | /** |
27 | - * @var string |
|
28 | - */ |
|
27 | + * @var string |
|
28 | + */ |
|
29 | 29 | public $schedule_name; // allow for naming the queue in case there are multiple queues |
30 | 30 | |
31 | 31 | /** |
32 | - * Constructor which sets up pull schedule |
|
33 | - * |
|
34 | - * @param object $wpdb |
|
35 | - * @param string $version |
|
36 | - * @param array $login_credentials |
|
37 | - * @param string $slug |
|
38 | - * @param object $wordpress |
|
39 | - * @param object $salesforce |
|
40 | - * @param object $mappings |
|
41 | - * @param object $logging |
|
42 | - * @param array $schedulable_classes |
|
43 | - * @throws \Exception |
|
44 | - */ |
|
32 | + * Constructor which sets up pull schedule |
|
33 | + * |
|
34 | + * @param object $wpdb |
|
35 | + * @param string $version |
|
36 | + * @param array $login_credentials |
|
37 | + * @param string $slug |
|
38 | + * @param object $wordpress |
|
39 | + * @param object $salesforce |
|
40 | + * @param object $mappings |
|
41 | + * @param object $logging |
|
42 | + * @param array $schedulable_classes |
|
43 | + * @throws \Exception |
|
44 | + */ |
|
45 | 45 | public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes ) { |
46 | 46 | $this->wpdb = $wpdb; |
47 | 47 | $this->version = $version; |
@@ -70,19 +70,19 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | - * Create the action hooks based on what object maps exist from the admin settings |
|
74 | - * |
|
75 | - */ |
|
73 | + * Create the action hooks based on what object maps exist from the admin settings |
|
74 | + * |
|
75 | + */ |
|
76 | 76 | private function add_actions() { |
77 | 77 | add_action( 'wp_ajax_salesforce_pull_webhook', array( $this, 'salesforce_pull_webhook' ) ); |
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | - * Ajax callback for salesforce pull. Returns status of 200 for successful |
|
82 | - * attempt or 403 for a failed pull attempt (SF not authorized, threshhold |
|
83 | - * reached, etc. |
|
84 | - * this is the ajax callback; not a cron run |
|
85 | - */ |
|
81 | + * Ajax callback for salesforce pull. Returns status of 200 for successful |
|
82 | + * attempt or 403 for a failed pull attempt (SF not authorized, threshhold |
|
83 | + * reached, etc. |
|
84 | + * this is the ajax callback; not a cron run |
|
85 | + */ |
|
86 | 86 | public function salesforce_pull_webhook() { |
87 | 87 | |
88 | 88 | if ( true === $this->salesforce_pull() ) { |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | - * Callback for the standard pull process used by webhooks and cron. |
|
106 | - */ |
|
105 | + * Callback for the standard pull process used by webhooks and cron. |
|
106 | + */ |
|
107 | 107 | public function salesforce_pull() { |
108 | 108 | $sfapi = $this->salesforce['sfapi']; |
109 | 109 | |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Load schedule |
|
127 | - * This loads the schedule class |
|
128 | - */ |
|
126 | + * Load schedule |
|
127 | + * This loads the schedule class |
|
128 | + */ |
|
129 | 129 | private function schedule() { |
130 | 130 | if ( ! class_exists( 'Object_Sync_Sf_Schedule' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) { |
131 | 131 | require_once plugin_dir_path( __FILE__ ) . '../vendor/autoload.php'; |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
140 | - * Determines if the Salesforce pull should be allowed, or throttled. |
|
141 | - * |
|
142 | - * Prevents too many pull processes from running at once. |
|
143 | - * |
|
144 | - * @return bool |
|
145 | - * Returns false if the time elapsed between recent pulls is too short. |
|
146 | - */ |
|
140 | + * Determines if the Salesforce pull should be allowed, or throttled. |
|
141 | + * |
|
142 | + * Prevents too many pull processes from running at once. |
|
143 | + * |
|
144 | + * @return bool |
|
145 | + * Returns false if the time elapsed between recent pulls is too short. |
|
146 | + */ |
|
147 | 147 | private function check_throttle() { |
148 | 148 | $pull_throttle = get_option( 'object_sync_for_salesforce_pull_throttle', 5 ); |
149 | 149 | $last_sync = get_option( 'object_sync_for_salesforce_pull_last_sync', 0 ); |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | - * Pull updated records from Salesforce and place them in the queue. |
|
160 | - * |
|
161 | - * Executes a SOQL query based on defined mappings, loops through the results, |
|
162 | - * and places each updated SF object into the queue for later processing. |
|
163 | - * |
|
164 | - * We copy the convention from the Drupal module here, and run a separate SOQL query for each type of object in SF |
|
165 | - * |
|
166 | - */ |
|
159 | + * Pull updated records from Salesforce and place them in the queue. |
|
160 | + * |
|
161 | + * Executes a SOQL query based on defined mappings, loops through the results, |
|
162 | + * and places each updated SF object into the queue for later processing. |
|
163 | + * |
|
164 | + * We copy the convention from the Drupal module here, and run a separate SOQL query for each type of object in SF |
|
165 | + * |
|
166 | + */ |
|
167 | 167 | private function get_updated_records() { |
168 | 168 | $sfapi = $this->salesforce['sfapi']; |
169 | 169 | foreach ( $this->mappings->get_fieldmaps() as $salesforce_mapping ) { |
@@ -329,18 +329,18 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
332 | - * Given a SObject type name, build an SOQL query to include all fields for all |
|
333 | - * SalesforceMappings mapped to that SObject. |
|
334 | - * |
|
335 | - * @param string $type |
|
336 | - * e.g. "Contact", "Account", etc. |
|
337 | - * |
|
338 | - * @return Object_Sync_Sf_Salesforce_Select_Query or null if no mappings or no mapped fields |
|
339 | - * were found. |
|
340 | - * |
|
341 | - * @see Object_Sync_Sf_Mapping::get_mapped_fields |
|
342 | - * @see Object_Sync_Sf_Mapping::get_mapped_record_types |
|
343 | - */ |
|
332 | + * Given a SObject type name, build an SOQL query to include all fields for all |
|
333 | + * SalesforceMappings mapped to that SObject. |
|
334 | + * |
|
335 | + * @param string $type |
|
336 | + * e.g. "Contact", "Account", etc. |
|
337 | + * |
|
338 | + * @return Object_Sync_Sf_Salesforce_Select_Query or null if no mappings or no mapped fields |
|
339 | + * were found. |
|
340 | + * |
|
341 | + * @see Object_Sync_Sf_Mapping::get_mapped_fields |
|
342 | + * @see Object_Sync_Sf_Mapping::get_mapped_record_types |
|
343 | + */ |
|
344 | 344 | private function get_pull_query( $type, $salesforce_mapping = array() ) { |
345 | 345 | $mapped_fields = array(); |
346 | 346 | $mapped_record_types = array(); |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | } |
423 | 423 | |
424 | 424 | /** |
425 | - * Get deleted records from salesforce. |
|
426 | - * Note that deletions can only be queried via REST with an API version >= 29.0. |
|
427 | - * |
|
428 | - */ |
|
425 | + * Get deleted records from salesforce. |
|
426 | + * Note that deletions can only be queried via REST with an API version >= 29.0. |
|
427 | + * |
|
428 | + */ |
|
429 | 429 | private function get_deleted_records() { |
430 | 430 | |
431 | 431 | $sfapi = $this->salesforce['sfapi']; |
@@ -517,13 +517,13 @@ discard block |
||
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
520 | - * Method for ajax hooks to call for pulling manually |
|
521 | - * |
|
522 | - * @param string $object_type |
|
523 | - * @param string $salesforce_id |
|
524 | - * @param string $wordpress_object |
|
525 | - * |
|
526 | - */ |
|
520 | + * Method for ajax hooks to call for pulling manually |
|
521 | + * |
|
522 | + * @param string $object_type |
|
523 | + * @param string $salesforce_id |
|
524 | + * @param string $wordpress_object |
|
525 | + * |
|
526 | + */ |
|
527 | 527 | public function manual_pull( $object_type, $salesforce_id, $wordpress_object ) { |
528 | 528 | $sfapi = $this->salesforce['sfapi']; |
529 | 529 | $object = $sfapi->api_call( 'sobjects/' . $object_type . '/' . $salesforce_id ); |
@@ -538,20 +538,20 @@ discard block |
||
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
541 | - * Sync WordPress objects and Salesforce objects from the queue using the REST API. |
|
542 | - * |
|
543 | - * @param string $object_type |
|
544 | - * Type of Salesforce object. |
|
545 | - * @param object $object |
|
546 | - * The Salesforce object. |
|
547 | - * @param object $mapping |
|
548 | - * Salesforce/WP mapping object. |
|
549 | - * @param int $sf_sync_trigger |
|
550 | - * Trigger for this sync. |
|
551 | - * |
|
552 | - * @return true or exit the method |
|
553 | - * |
|
554 | - */ |
|
541 | + * Sync WordPress objects and Salesforce objects from the queue using the REST API. |
|
542 | + * |
|
543 | + * @param string $object_type |
|
544 | + * Type of Salesforce object. |
|
545 | + * @param object $object |
|
546 | + * The Salesforce object. |
|
547 | + * @param object $mapping |
|
548 | + * Salesforce/WP mapping object. |
|
549 | + * @param int $sf_sync_trigger |
|
550 | + * Trigger for this sync. |
|
551 | + * |
|
552 | + * @return true or exit the method |
|
553 | + * |
|
554 | + */ |
|
555 | 555 | public function salesforce_pull_process_records( $object_type, $object, $mapping, $sf_sync_trigger ) { |
556 | 556 | $mapping_conditions = array( |
557 | 557 | 'salesforce_object' => $object_type, |
@@ -1282,19 +1282,19 @@ discard block |
||
1282 | 1282 | } |
1283 | 1283 | |
1284 | 1284 | /** |
1285 | - * Create an object map between a Salesforce object and a WordPress object |
|
1286 | - * |
|
1287 | - * @param array $salesforce_object |
|
1288 | - * Array of the salesforce object's data |
|
1289 | - * @param string $wordpress_id |
|
1290 | - * Unique identifier for the WordPress object |
|
1291 | - * @param array $field_mapping |
|
1292 | - * The row that maps the object types together, including which fields match which other fields |
|
1293 | - * |
|
1294 | - * @return int $wpdb->insert_id |
|
1295 | - * This is the database row for the map object |
|
1296 | - * |
|
1297 | - */ |
|
1285 | + * Create an object map between a Salesforce object and a WordPress object |
|
1286 | + * |
|
1287 | + * @param array $salesforce_object |
|
1288 | + * Array of the salesforce object's data |
|
1289 | + * @param string $wordpress_id |
|
1290 | + * Unique identifier for the WordPress object |
|
1291 | + * @param array $field_mapping |
|
1292 | + * The row that maps the object types together, including which fields match which other fields |
|
1293 | + * |
|
1294 | + * @return int $wpdb->insert_id |
|
1295 | + * This is the database row for the map object |
|
1296 | + * |
|
1297 | + */ |
|
1298 | 1298 | private function create_object_map( $salesforce_object, $wordpress_id, $field_mapping ) { |
1299 | 1299 | // Create object map and save it |
1300 | 1300 | $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 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param array $schedulable_classes |
43 | 43 | * @throws \Exception |
44 | 44 | */ |
45 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes ) { |
|
45 | + public function __construct($wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes) { |
|
46 | 46 | $this->wpdb = $wpdb; |
47 | 47 | $this->version = $version; |
48 | 48 | $this->login_credentials = $login_credentials; |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | $schedule = $this->schedule; |
62 | 62 | // create new schedule based on the options for this current class |
63 | 63 | // this will use the existing schedule if it already exists; otherwise it'll create one |
64 | - $schedule->use_schedule( $this->schedule_name ); |
|
64 | + $schedule->use_schedule($this->schedule_name); |
|
65 | 65 | |
66 | 66 | $this->add_actions(); |
67 | 67 | |
68 | - $this->debug = get_option( 'object_sync_for_salesforce_debug_mode', false ); |
|
68 | + $this->debug = get_option('object_sync_for_salesforce_debug_mode', false); |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | */ |
76 | 76 | private function add_actions() { |
77 | - add_action( 'wp_ajax_salesforce_pull_webhook', array( $this, 'salesforce_pull_webhook' ) ); |
|
77 | + add_action('wp_ajax_salesforce_pull_webhook', array($this, 'salesforce_pull_webhook')); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function salesforce_pull_webhook() { |
87 | 87 | |
88 | - if ( true === $this->salesforce_pull() ) { |
|
88 | + if (true === $this->salesforce_pull()) { |
|
89 | 89 | $code = '200'; |
90 | 90 | // check to see if anything is in the queue and handle it if it is |
91 | 91 | $this->schedule->maybe_handle(); |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | $code = '403'; |
94 | 94 | } |
95 | 95 | |
96 | - if ( ! empty( $_POST ) ) { // linter flags this, but we're not doing anything with the array just checking to see if it is empty |
|
97 | - wp_send_json_success( $code ); |
|
96 | + if ( ! empty($_POST)) { // linter flags this, but we're not doing anything with the array just checking to see if it is empty |
|
97 | + wp_send_json_success($code); |
|
98 | 98 | } else { |
99 | 99 | return $code; |
100 | 100 | } |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | public function salesforce_pull() { |
108 | 108 | $sfapi = $this->salesforce['sfapi']; |
109 | 109 | |
110 | - if ( true === $this->salesforce['is_authorized'] && true === $this->check_throttle() ) { |
|
110 | + if (true === $this->salesforce['is_authorized'] && true === $this->check_throttle()) { |
|
111 | 111 | |
112 | 112 | $this->get_updated_records(); |
113 | 113 | $this->get_deleted_records(); |
114 | 114 | |
115 | 115 | // Store this request time for the throttle check. |
116 | - update_option( 'object_sync_for_salesforce_pull_last_sync', current_time( 'timestamp', true ) ); |
|
116 | + update_option('object_sync_for_salesforce_pull_last_sync', current_time('timestamp', true)); |
|
117 | 117 | return true; |
118 | 118 | |
119 | 119 | } else { |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | * This loads the schedule class |
128 | 128 | */ |
129 | 129 | private function schedule() { |
130 | - if ( ! class_exists( 'Object_Sync_Sf_Schedule' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) { |
|
131 | - require_once plugin_dir_path( __FILE__ ) . '../vendor/autoload.php'; |
|
132 | - require_once plugin_dir_path( __FILE__ ) . '../classes/schedule.php'; |
|
130 | + if ( ! class_exists('Object_Sync_Sf_Schedule') && file_exists(plugin_dir_path(__FILE__) . '../vendor/autoload.php')) { |
|
131 | + require_once plugin_dir_path(__FILE__) . '../vendor/autoload.php'; |
|
132 | + require_once plugin_dir_path(__FILE__) . '../classes/schedule.php'; |
|
133 | 133 | } |
134 | - $schedule = new Object_Sync_Sf_Schedule( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->schedule_name, $this->logging, $this->schedulable_classes ); |
|
134 | + $schedule = new Object_Sync_Sf_Schedule($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->schedule_name, $this->logging, $this->schedulable_classes); |
|
135 | 135 | $this->schedule = $schedule; |
136 | 136 | return $schedule; |
137 | 137 | } |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | * Returns false if the time elapsed between recent pulls is too short. |
146 | 146 | */ |
147 | 147 | private function check_throttle() { |
148 | - $pull_throttle = get_option( 'object_sync_for_salesforce_pull_throttle', 5 ); |
|
149 | - $last_sync = get_option( 'object_sync_for_salesforce_pull_last_sync', 0 ); |
|
148 | + $pull_throttle = get_option('object_sync_for_salesforce_pull_throttle', 5); |
|
149 | + $last_sync = get_option('object_sync_for_salesforce_pull_last_sync', 0); |
|
150 | 150 | |
151 | - if ( current_time( 'timestamp', true ) > ( $last_sync + $pull_throttle ) ) { |
|
151 | + if (current_time('timestamp', true) > ($last_sync + $pull_throttle)) { |
|
152 | 152 | return true; |
153 | 153 | } else { |
154 | 154 | return false; |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | */ |
167 | 167 | private function get_updated_records() { |
168 | 168 | $sfapi = $this->salesforce['sfapi']; |
169 | - foreach ( $this->mappings->get_fieldmaps() as $salesforce_mapping ) { |
|
169 | + foreach ($this->mappings->get_fieldmaps() as $salesforce_mapping) { |
|
170 | 170 | $map_sync_triggers = $salesforce_mapping['sync_triggers']; // this sets which Salesforce triggers are allowed for the mapping |
171 | 171 | $type = $salesforce_mapping['salesforce_object']; // this sets the salesfore object type for the SOQL query |
172 | 172 | |
173 | - $soql = $this->get_pull_query( $type, $salesforce_mapping ); |
|
173 | + $soql = $this->get_pull_query($type, $salesforce_mapping); |
|
174 | 174 | |
175 | 175 | // get_pull_query returns null if it has no matching fields |
176 | - if ( null === $soql ) { |
|
176 | + if (null === $soql) { |
|
177 | 177 | continue; |
178 | 178 | } |
179 | 179 | |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | ); |
189 | 189 | |
190 | 190 | $response = $results['data']; |
191 | - $version_path = wp_parse_url( $sfapi->get_api_endpoint(), PHP_URL_PATH ); |
|
191 | + $version_path = wp_parse_url($sfapi->get_api_endpoint(), PHP_URL_PATH); |
|
192 | 192 | |
193 | - $sf_last_sync = get_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, null ); |
|
194 | - $last_sync = gmdate( 'Y-m-d\TH:i:s\Z', $sf_last_sync ); |
|
193 | + $sf_last_sync = get_option('object_sync_for_salesforce_pull_last_sync_' . $type, null); |
|
194 | + $last_sync = gmdate('Y-m-d\TH:i:s\Z', $sf_last_sync); |
|
195 | 195 | |
196 | - if ( ! isset( $response['errorCode'] ) ) { |
|
196 | + if ( ! isset($response['errorCode'])) { |
|
197 | 197 | // Write items to the queue. |
198 | - foreach ( $response['records'] as $result ) { |
|
198 | + foreach ($response['records'] as $result) { |
|
199 | 199 | |
200 | 200 | // if this record is new as of the last sync, use the create trigger |
201 | - if ( isset( $result['CreatedDate'] ) && $result['CreatedDate'] > $last_sync ) { |
|
201 | + if (isset($result['CreatedDate']) && $result['CreatedDate'] > $last_sync) { |
|
202 | 202 | $sf_sync_trigger = $this->mappings->sync_sf_create; |
203 | 203 | } else { |
204 | 204 | $sf_sync_trigger = $this->mappings->sync_sf_update; |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | |
207 | 207 | // Only queue when the record's trigger is configured for the mapping |
208 | 208 | // these are bit operators, so we leave out the strict |
209 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
209 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
210 | 210 | $data = array( |
211 | 211 | 'object_type' => $type, |
212 | 212 | 'object' => $result, |
@@ -218,16 +218,16 @@ discard block |
||
218 | 218 | $pull_allowed = true; |
219 | 219 | |
220 | 220 | // 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. |
221 | - if ( isset( $map_sync_triggers ) && ! in_array( $this->mappings->sync_sf_create, $map_sync_triggers ) ) { |
|
222 | - $object_map = $this->mappings->load_by_salesforce( $result['Id'] ); |
|
223 | - if ( empty( $object_map ) ) { |
|
221 | + if (isset($map_sync_triggers) && ! in_array($this->mappings->sync_sf_create, $map_sync_triggers)) { |
|
222 | + $object_map = $this->mappings->load_by_salesforce($result['Id']); |
|
223 | + if (empty($object_map)) { |
|
224 | 224 | $pull_allowed = false; |
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | 228 | // Hook to allow other plugins to prevent a pull per-mapping. |
229 | 229 | // Putting the pull_allowed hook here will keep the queue from storing data when it is not supposed to store it |
230 | - $pull_allowed = apply_filters( 'object_sync_for_salesforce_pull_object_allowed', $pull_allowed, $type, $result, $sf_sync_trigger, $salesforce_mapping ); |
|
230 | + $pull_allowed = apply_filters('object_sync_for_salesforce_pull_object_allowed', $pull_allowed, $type, $result, $sf_sync_trigger, $salesforce_mapping); |
|
231 | 231 | |
232 | 232 | // example to keep from pulling the Contact with id of abcdef |
233 | 233 | /* |
@@ -240,26 +240,26 @@ discard block |
||
240 | 240 | } |
241 | 241 | */ |
242 | 242 | |
243 | - if ( false === $pull_allowed ) { |
|
244 | - update_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, current_time( 'timestamp', true ) ); |
|
243 | + if (false === $pull_allowed) { |
|
244 | + update_option('object_sync_for_salesforce_pull_last_sync_' . $type, current_time('timestamp', true)); |
|
245 | 245 | continue; |
246 | 246 | } |
247 | 247 | |
248 | 248 | // Initialize the queue with the data for this record and save |
249 | - $this->schedule->data( array( $data ) ); |
|
249 | + $this->schedule->data(array($data)); |
|
250 | 250 | $this->schedule->save()->dispatch(); |
251 | 251 | // Update the last pull sync timestamp for this record type to avoid re-processing in case of error |
252 | - $last_sync_pull_trigger = DateTime::createFromFormat( 'Y-m-d\TH:i:s+', $result[ $salesforce_mapping['pull_trigger_field'] ], new DateTimeZone( 'UTC' ) ); |
|
253 | - update_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, $last_sync_pull_trigger->format( 'U' ) ); |
|
252 | + $last_sync_pull_trigger = DateTime::createFromFormat('Y-m-d\TH:i:s+', $result[$salesforce_mapping['pull_trigger_field']], new DateTimeZone('UTC')); |
|
253 | + update_option('object_sync_for_salesforce_pull_last_sync_' . $type, $last_sync_pull_trigger->format('U')); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Handle requests larger than the batch limit (usually 2000). |
258 | - $next_records_url = isset( $response['nextRecordsUrl'] ) ? str_replace( $version_path, '', $response['nextRecordsUrl'] ) : false; |
|
258 | + $next_records_url = isset($response['nextRecordsUrl']) ? str_replace($version_path, '', $response['nextRecordsUrl']) : false; |
|
259 | 259 | |
260 | - while ( $next_records_url ) { |
|
260 | + while ($next_records_url) { |
|
261 | 261 | // shouldn't cache this either. it's going into the queue if it exists anyway. |
262 | - $new_results = $sfapi->api_call( |
|
262 | + $new_results = $sfapi->api_call( |
|
263 | 263 | $next_records_url, |
264 | 264 | array(), |
265 | 265 | 'GET', |
@@ -268,11 +268,11 @@ discard block |
||
268 | 268 | ) |
269 | 269 | ); |
270 | 270 | $new_response = $new_results['data']; |
271 | - if ( ! isset( $new_response['errorCode'] ) ) { |
|
271 | + if ( ! isset($new_response['errorCode'])) { |
|
272 | 272 | // Write items to the queue. |
273 | - foreach ( $new_response['records'] as $result ) { |
|
273 | + foreach ($new_response['records'] as $result) { |
|
274 | 274 | // if this record is new as of the last sync, use the create trigger |
275 | - if ( isset( $result['CreatedDate'] ) && $result['CreatedDate'] > $last_sync ) { |
|
275 | + if (isset($result['CreatedDate']) && $result['CreatedDate'] > $last_sync) { |
|
276 | 276 | $sf_sync_trigger = $this->mappings->sync_sf_create; |
277 | 277 | } else { |
278 | 278 | $sf_sync_trigger = $this->mappings->sync_sf_update; |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | |
281 | 281 | // Only queue when the record's trigger is configured for the mapping |
282 | 282 | // these are bit operators, so we leave out the strict |
283 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
283 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
284 | 284 | $data = array( |
285 | 285 | 'object_type' => $type, |
286 | 286 | 'object' => $result, |
@@ -289,31 +289,31 @@ discard block |
||
289 | 289 | ); |
290 | 290 | |
291 | 291 | // Initialize the queue with the data for this record and save |
292 | - $this->schedule->data( array( $data ) ); |
|
292 | + $this->schedule->data(array($data)); |
|
293 | 293 | $this->schedule->save()->dispatch(); |
294 | 294 | // Update the last pull sync timestamp for this record type to avoid re-processing in case of error |
295 | - $last_sync_pull_trigger = DateTime::createFromFormat( 'Y-m-d\TH:i:s+', $result[ $salesforce_mapping['pull_trigger_field'] ], new DateTimeZone( 'UTC' ) ); |
|
296 | - update_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, $last_sync_pull_trigger->format( 'U' ) ); |
|
295 | + $last_sync_pull_trigger = DateTime::createFromFormat('Y-m-d\TH:i:s+', $result[$salesforce_mapping['pull_trigger_field']], new DateTimeZone('UTC')); |
|
296 | + update_option('object_sync_for_salesforce_pull_last_sync_' . $type, $last_sync_pull_trigger->format('U')); |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | } |
300 | 300 | |
301 | - $next_records_url = isset( $new_response['nextRecordsUrl'] ) ? str_replace( $version_path, '', $new_response['nextRecordsUrl'] ) : false; |
|
301 | + $next_records_url = isset($new_response['nextRecordsUrl']) ? str_replace($version_path, '', $new_response['nextRecordsUrl']) : false; |
|
302 | 302 | } |
303 | 303 | } else { |
304 | 304 | |
305 | 305 | // create log entry for failed pull |
306 | 306 | $status = 'error'; |
307 | 307 | // translators: placeholders are: 1) the server error code, and 2) the name of the Salesforce object |
308 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s', 'object-sync-for-salesforce' ), |
|
309 | - absint( $response['errorCode'] ), |
|
310 | - esc_attr( $salesforce_mapping['salesforce_object'] ) |
|
308 | + $title = sprintf(esc_html__('Error: %1$s %2$s', 'object-sync-for-salesforce'), |
|
309 | + absint($response['errorCode']), |
|
310 | + esc_attr($salesforce_mapping['salesforce_object']) |
|
311 | 311 | ); |
312 | 312 | |
313 | - if ( isset( $this->logging ) ) { |
|
313 | + if (isset($this->logging)) { |
|
314 | 314 | $logging = $this->logging; |
315 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
316 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
315 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
316 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | $logging->setup( |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | * @see Object_Sync_Sf_Mapping::get_mapped_fields |
342 | 342 | * @see Object_Sync_Sf_Mapping::get_mapped_record_types |
343 | 343 | */ |
344 | - private function get_pull_query( $type, $salesforce_mapping = array() ) { |
|
344 | + private function get_pull_query($type, $salesforce_mapping = array()) { |
|
345 | 345 | $mapped_fields = array(); |
346 | 346 | $mapped_record_types = array(); |
347 | 347 | |
@@ -353,35 +353,35 @@ discard block |
||
353 | 353 | ); |
354 | 354 | |
355 | 355 | // Iterate over each field mapping to determine our query parameters. |
356 | - foreach ( $mappings as $mapping ) { |
|
356 | + foreach ($mappings as $mapping) { |
|
357 | 357 | |
358 | 358 | // only use fields that come from Salesforce to WordPress, or that sync |
359 | 359 | $mapped_fields = array_merge( |
360 | 360 | $mapped_fields, |
361 | 361 | $this->mappings->get_mapped_fields( |
362 | 362 | $mapping, |
363 | - array( $this->mappings->direction_sync, $this->mappings->direction_sf_wordpress ) |
|
363 | + array($this->mappings->direction_sync, $this->mappings->direction_sf_wordpress) |
|
364 | 364 | ) |
365 | 365 | ); |
366 | 366 | |
367 | 367 | // If Record Type is specified, restrict query. |
368 | - $mapping_record_types = $this->mappings->get_mapped_record_types( $mapping ); |
|
368 | + $mapping_record_types = $this->mappings->get_mapped_record_types($mapping); |
|
369 | 369 | |
370 | 370 | // If Record Type is not specified for a given mapping, ensure query is unrestricted. |
371 | - if ( empty( $mapping_record_types ) ) { |
|
371 | + if (empty($mapping_record_types)) { |
|
372 | 372 | $mapped_record_types = false; |
373 | - } elseif ( is_array( $mapped_record_types ) ) { |
|
374 | - $mapped_record_types = array_merge( $mapped_record_types, $mapping_record_types ); |
|
373 | + } elseif (is_array($mapped_record_types)) { |
|
374 | + $mapped_record_types = array_merge($mapped_record_types, $mapping_record_types); |
|
375 | 375 | } |
376 | 376 | } // End foreach(). |
377 | 377 | |
378 | 378 | // There are no field mappings configured to pull data from Salesforce so |
379 | 379 | // move on to the next mapped object. Prevents querying unmapped data. |
380 | - if ( empty( $mapped_fields ) ) { |
|
380 | + if (empty($mapped_fields)) { |
|
381 | 381 | return null; |
382 | 382 | } |
383 | 383 | |
384 | - $soql = new Object_Sync_Sf_Salesforce_Select_Query( $type ); |
|
384 | + $soql = new Object_Sync_Sf_Salesforce_Select_Query($type); |
|
385 | 385 | |
386 | 386 | // Convert field mappings to SOQL. |
387 | 387 | $soql->fields = array_merge( |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | ); |
394 | 394 | |
395 | 395 | // these are bit operators, so we leave out the strict |
396 | - if ( in_array( $this->mappings->sync_sf_create, $salesforce_mapping['sync_triggers'] ) ) { |
|
396 | + if (in_array($this->mappings->sync_sf_create, $salesforce_mapping['sync_triggers'])) { |
|
397 | 397 | $soql->fields['CreatedDate'] = 'CreatedDate'; |
398 | 398 | } |
399 | 399 | |
@@ -401,14 +401,14 @@ discard block |
||
401 | 401 | // this should be what keeps it from getting all the records, whether or not they've ever been updated |
402 | 402 | // we also use the option for when the plugin was installed, and don't go back further than that by default |
403 | 403 | |
404 | - $sf_activate_time = get_option( 'object_sync_for_salesforce_activate_time', '' ); |
|
405 | - $sf_last_sync = get_option( 'object_sync_for_salesforce_pull_last_sync_' . $type, null ); |
|
406 | - if ( $sf_last_sync ) { |
|
407 | - $last_sync = gmdate( 'Y-m-d\TH:i:s\Z', $sf_last_sync ); |
|
408 | - $soql->add_condition( $salesforce_mapping['pull_trigger_field'], $last_sync, '>' ); |
|
404 | + $sf_activate_time = get_option('object_sync_for_salesforce_activate_time', ''); |
|
405 | + $sf_last_sync = get_option('object_sync_for_salesforce_pull_last_sync_' . $type, null); |
|
406 | + if ($sf_last_sync) { |
|
407 | + $last_sync = gmdate('Y-m-d\TH:i:s\Z', $sf_last_sync); |
|
408 | + $soql->add_condition($salesforce_mapping['pull_trigger_field'], $last_sync, '>'); |
|
409 | 409 | } else { |
410 | - $activated = gmdate( 'Y-m-d\TH:i:s\Z', $sf_activate_time ); |
|
411 | - $soql->add_condition( $salesforce_mapping['pull_trigger_field'], $activated, '>' ); |
|
410 | + $activated = gmdate('Y-m-d\TH:i:s\Z', $sf_activate_time); |
|
411 | + $soql->add_condition($salesforce_mapping['pull_trigger_field'], $activated, '>'); |
|
412 | 412 | // put a hook in here to let devs go retroactive if they want, and sync data from before plugin was activated |
413 | 413 | } |
414 | 414 | |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | // we are not incorporating that part of this branch at this time |
435 | 435 | |
436 | 436 | // Load all unique SF record types that we have mappings for. |
437 | - foreach ( $this->mappings->get_fieldmaps() as $salesforce_mapping ) { |
|
437 | + foreach ($this->mappings->get_fieldmaps() as $salesforce_mapping) { |
|
438 | 438 | |
439 | 439 | $type = $salesforce_mapping['salesforce_object']; |
440 | 440 | |
@@ -446,37 +446,37 @@ discard block |
||
446 | 446 | ); |
447 | 447 | |
448 | 448 | // Iterate over each field mapping to determine our query parameters. |
449 | - foreach ( $mappings as $mapping ) { |
|
449 | + foreach ($mappings as $mapping) { |
|
450 | 450 | |
451 | - $last_delete_sync = get_option( 'object_sync_for_salesforce_pull_delete_last_' . $type, current_time( 'timestamp', true ) ); |
|
452 | - $now = current_time( 'timestamp', true ); |
|
453 | - update_option( 'object_sync_for_salesforce_pull_delete_last_' . $type, $now ); |
|
451 | + $last_delete_sync = get_option('object_sync_for_salesforce_pull_delete_last_' . $type, current_time('timestamp', true)); |
|
452 | + $now = current_time('timestamp', true); |
|
453 | + update_option('object_sync_for_salesforce_pull_delete_last_' . $type, $now); |
|
454 | 454 | |
455 | 455 | // get_deleted() constraint: startDate cannot be more than 30 days ago |
456 | 456 | // (using an incompatible date may lead to exceptions). |
457 | - $last_delete_sync = $last_delete_sync > ( current_time( 'timestamp', true ) - 2505600 ) ? $last_delete_sync : ( current_time( 'timestamp', true ) - 2505600 ); |
|
457 | + $last_delete_sync = $last_delete_sync > (current_time('timestamp', true) - 2505600) ? $last_delete_sync : (current_time('timestamp', true) - 2505600); |
|
458 | 458 | |
459 | 459 | // get_deleted() constraint: startDate must be at least one minute greater |
460 | 460 | // than endDate. |
461 | - $now = $now > ( $last_delete_sync + 60 ) ? $now : $now + 60; |
|
461 | + $now = $now > ($last_delete_sync + 60) ? $now : $now + 60; |
|
462 | 462 | |
463 | 463 | // need to be using gmdate for salesforce call |
464 | - $last_delete_sync_sf = gmdate( 'Y-m-d\TH:i:s\Z', $last_delete_sync ); |
|
465 | - $now_sf = gmdate( 'Y-m-d\TH:i:s\Z', $now ); |
|
464 | + $last_delete_sync_sf = gmdate('Y-m-d\TH:i:s\Z', $last_delete_sync); |
|
465 | + $now_sf = gmdate('Y-m-d\TH:i:s\Z', $now); |
|
466 | 466 | |
467 | 467 | // salesforce call |
468 | - $deleted = $sfapi->get_deleted( $type, $last_delete_sync_sf, $now_sf ); |
|
468 | + $deleted = $sfapi->get_deleted($type, $last_delete_sync_sf, $now_sf); |
|
469 | 469 | |
470 | - if ( empty( $deleted['data']['deletedRecords'] ) ) { |
|
470 | + if (empty($deleted['data']['deletedRecords'])) { |
|
471 | 471 | continue; |
472 | 472 | } |
473 | 473 | |
474 | - foreach ( $deleted['data']['deletedRecords'] as $result ) { |
|
474 | + foreach ($deleted['data']['deletedRecords'] as $result) { |
|
475 | 475 | |
476 | 476 | $sf_sync_trigger = $this->mappings->sync_sf_delete; |
477 | 477 | |
478 | 478 | // 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? |
479 | - if ( ! isset( $result['Id'] ) && isset( $result['id'] ) ) { |
|
479 | + if ( ! isset($result['Id']) && isset($result['id'])) { |
|
480 | 480 | $result['Id'] = $result['id']; |
481 | 481 | } |
482 | 482 | $data = array( |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | |
489 | 489 | // Hook to allow other plugins to prevent a pull per-mapping. |
490 | 490 | // Putting the pull_allowed hook here will keep the queue from storing data when it is not supposed to store it |
491 | - $pull_allowed = apply_filters( 'object_sync_for_salesforce_pull_object_allowed', true, $type, $result, $sf_sync_trigger, $salesforce_mapping ); |
|
491 | + $pull_allowed = apply_filters('object_sync_for_salesforce_pull_object_allowed', true, $type, $result, $sf_sync_trigger, $salesforce_mapping); |
|
492 | 492 | |
493 | 493 | // example to keep from pulling the Contact with id of abcdef |
494 | 494 | /* |
@@ -501,16 +501,16 @@ discard block |
||
501 | 501 | } |
502 | 502 | */ |
503 | 503 | |
504 | - if ( false === $pull_allowed ) { |
|
504 | + if (false === $pull_allowed) { |
|
505 | 505 | continue; |
506 | 506 | } |
507 | 507 | |
508 | - $this->schedule->push_to_queue( $data ); |
|
508 | + $this->schedule->push_to_queue($data); |
|
509 | 509 | $this->schedule->save()->dispatch(); |
510 | 510 | |
511 | 511 | } |
512 | 512 | |
513 | - update_option( 'object_sync_for_salesforce_pull_delete_last_' . $type, current_time( 'timestamp', true ) ); |
|
513 | + update_option('object_sync_for_salesforce_pull_delete_last_' . $type, current_time('timestamp', true)); |
|
514 | 514 | |
515 | 515 | } // End foreach(). |
516 | 516 | } // End foreach(). |
@@ -524,9 +524,9 @@ discard block |
||
524 | 524 | * @param string $wordpress_object |
525 | 525 | * |
526 | 526 | */ |
527 | - public function manual_pull( $object_type, $salesforce_id, $wordpress_object ) { |
|
527 | + public function manual_pull($object_type, $salesforce_id, $wordpress_object) { |
|
528 | 528 | $sfapi = $this->salesforce['sfapi']; |
529 | - $object = $sfapi->api_call( 'sobjects/' . $object_type . '/' . $salesforce_id ); |
|
529 | + $object = $sfapi->api_call('sobjects/' . $object_type . '/' . $salesforce_id); |
|
530 | 530 | $mapping = $this->mappings->get_fieldmaps( |
531 | 531 | null, |
532 | 532 | array( |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | 'wordpress_object' => $wordpress_object, |
535 | 535 | ) |
536 | 536 | ); |
537 | - $this->salesforce_pull_process_records( $object_type, $object['data'], $mapping[0], $this->mappings->sync_sf_update ); |
|
537 | + $this->salesforce_pull_process_records($object_type, $object['data'], $mapping[0], $this->mappings->sync_sf_update); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
@@ -552,45 +552,45 @@ discard block |
||
552 | 552 | * @return true or exit the method |
553 | 553 | * |
554 | 554 | */ |
555 | - public function salesforce_pull_process_records( $object_type, $object, $mapping, $sf_sync_trigger ) { |
|
555 | + public function salesforce_pull_process_records($object_type, $object, $mapping, $sf_sync_trigger) { |
|
556 | 556 | $mapping_conditions = array( |
557 | 557 | 'salesforce_object' => $object_type, |
558 | 558 | ); |
559 | 559 | |
560 | - if ( isset( $object['RecordTypeId'] ) && $object['RecordTypeId'] !== $this->mappings->salesforce_default_record_type ) { |
|
560 | + if (isset($object['RecordTypeId']) && $object['RecordTypeId'] !== $this->mappings->salesforce_default_record_type) { |
|
561 | 561 | // use this condition to filter the mappings, at that time |
562 | 562 | $mapping_conditions['salesforce_record_type'] = $object['RecordTypeId']; |
563 | 563 | } |
564 | 564 | |
565 | - $salesforce_mappings = $this->mappings->get_fieldmaps( null, $mapping_conditions ); |
|
565 | + $salesforce_mappings = $this->mappings->get_fieldmaps(null, $mapping_conditions); |
|
566 | 566 | |
567 | 567 | // from drupal: if there is more than one mapping, don't throw exceptions |
568 | - $hold_exceptions = count( $salesforce_mappings ) > 1; |
|
568 | + $hold_exceptions = count($salesforce_mappings) > 1; |
|
569 | 569 | $exception = false; |
570 | 570 | |
571 | - $seconds = $this->schedule->get_schedule_frequency_seconds( $this->schedule_name ) + 60; |
|
571 | + $seconds = $this->schedule->get_schedule_frequency_seconds($this->schedule_name) + 60; |
|
572 | 572 | |
573 | 573 | $transients_to_delete = array(); |
574 | 574 | |
575 | - foreach ( $salesforce_mappings as $salesforce_mapping ) { |
|
575 | + foreach ($salesforce_mappings as $salesforce_mapping) { |
|
576 | 576 | |
577 | 577 | // this returns the row that maps the individual Salesforce row to the individual WordPress row |
578 | - if ( isset( $object['Id'] ) ) { |
|
579 | - $mapping_object = $this->mappings->load_by_salesforce( $object['Id'] ); |
|
578 | + if (isset($object['Id'])) { |
|
579 | + $mapping_object = $this->mappings->load_by_salesforce($object['Id']); |
|
580 | 580 | } else { |
581 | 581 | // if we don't have a Salesforce object id, we've got no business doing stuff in WordPress |
582 | 582 | $status = 'error'; |
583 | - if ( isset( $this->logging ) ) { |
|
583 | + if (isset($this->logging)) { |
|
584 | 584 | $logging = $this->logging; |
585 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
586 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
585 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
586 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
587 | 587 | } |
588 | 588 | |
589 | - $title = sprintf( esc_html__( 'Error: Salesforce Pull: unable to process queue item because it has no Salesforce Id.', 'object-sync-for-salesforce' ) ); |
|
589 | + $title = sprintf(esc_html__('Error: Salesforce Pull: unable to process queue item because it has no Salesforce Id.', 'object-sync-for-salesforce')); |
|
590 | 590 | |
591 | 591 | $logging->setup( |
592 | 592 | $title, |
593 | - print_r( $object, true ), // log whatever we have in the event of this error, so print the array |
|
593 | + print_r($object, true), // log whatever we have in the event of this error, so print the array |
|
594 | 594 | $sf_sync_trigger, |
595 | 595 | $status |
596 | 596 | ); |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | // if it's not already connected (ie on create), the array will be empty |
602 | 602 | |
603 | 603 | // hook to allow other plugins to define or alter the mapping object |
604 | - $mapping_object = apply_filters( 'object_sync_for_salesforce_pull_mapping_object', $mapping_object, $object, $mapping ); |
|
604 | + $mapping_object = apply_filters('object_sync_for_salesforce_pull_mapping_object', $mapping_object, $object, $mapping); |
|
605 | 605 | |
606 | 606 | // we already have the data from Salesforce at this point; we just need to work with it in WordPress |
607 | 607 | $synced_object = array( |
@@ -610,58 +610,58 @@ discard block |
||
610 | 610 | 'mapping' => $mapping, |
611 | 611 | ); |
612 | 612 | |
613 | - $structure = $this->wordpress->get_wordpress_table_structure( $salesforce_mapping['wordpress_object'] ); |
|
613 | + $structure = $this->wordpress->get_wordpress_table_structure($salesforce_mapping['wordpress_object']); |
|
614 | 614 | $object_id = $structure['id_field']; |
615 | 615 | |
616 | 616 | $op = ''; |
617 | 617 | |
618 | 618 | // are these objects already connected in WordPress? |
619 | - if ( isset( $mapping_object['id'] ) ) { |
|
619 | + if (isset($mapping_object['id'])) { |
|
620 | 620 | $is_new = false; |
621 | 621 | $mapping_object_id_transient = $mapping_object['id']; |
622 | 622 | } else { |
623 | 623 | // there is not a mapping object for this WordPress object id yet |
624 | 624 | // check for that transient with the currently pushing id |
625 | 625 | $is_new = true; |
626 | - $mapping_object_id_transient = get_transient( 'salesforce_pushing_object_id' ); |
|
626 | + $mapping_object_id_transient = get_transient('salesforce_pushing_object_id'); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | // Drupal only does a salesforce_pull flag, but we might as well do push and pull because WordPress |
630 | - $salesforce_pushing = (int) get_transient( 'salesforce_pushing_' . $mapping_object_id_transient ); |
|
631 | - if ( 1 === $salesforce_pushing ) { |
|
630 | + $salesforce_pushing = (int) get_transient('salesforce_pushing_' . $mapping_object_id_transient); |
|
631 | + if (1 === $salesforce_pushing) { |
|
632 | 632 | $transients_to_delete[] = $mapping_object_id_transient; |
633 | 633 | continue; |
634 | 634 | } |
635 | 635 | |
636 | 636 | // deleting mapped objects |
637 | - if ( $sf_sync_trigger == $this->mappings->sync_sf_delete ) { // trigger is a bit operator |
|
638 | - if ( isset( $mapping_object['id'] ) ) { |
|
637 | + if ($sf_sync_trigger == $this->mappings->sync_sf_delete) { // trigger is a bit operator |
|
638 | + if (isset($mapping_object['id'])) { |
|
639 | 639 | |
640 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
641 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
640 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
641 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
642 | 642 | |
643 | 643 | $op = 'Delete'; |
644 | - $wordpress_check = $this->mappings->load_by_wordpress( $mapping_object['wordpress_object'], $mapping_object['wordpress_id'] ); |
|
645 | - if ( count( $wordpress_check ) === count( $wordpress_check, COUNT_RECURSIVE ) ) { |
|
644 | + $wordpress_check = $this->mappings->load_by_wordpress($mapping_object['wordpress_object'], $mapping_object['wordpress_id']); |
|
645 | + if (count($wordpress_check) === count($wordpress_check, COUNT_RECURSIVE)) { |
|
646 | 646 | try { |
647 | - $result = $this->wordpress->object_delete( $salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'] ); |
|
648 | - } catch ( WordpressException $e ) { |
|
647 | + $result = $this->wordpress->object_delete($salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id']); |
|
648 | + } catch (WordpressException $e) { |
|
649 | 649 | $status = 'error'; |
650 | 650 | // create log entry for failed delete |
651 | - if ( isset( $this->logging ) ) { |
|
651 | + if (isset($this->logging)) { |
|
652 | 652 | $logging = $this->logging; |
653 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
654 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
653 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
654 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | // 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 |
658 | - $title = sprintf( esc_html__( 'Error: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce' ), |
|
659 | - esc_attr( $op ), |
|
660 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
661 | - esc_attr( $object_id ), |
|
662 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
663 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
664 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
658 | + $title = sprintf(esc_html__('Error: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce'), |
|
659 | + esc_attr($op), |
|
660 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
661 | + esc_attr($object_id), |
|
662 | + esc_attr($mapping_object['wordpress_id']), |
|
663 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
664 | + esc_attr($mapping_object['salesforce_id']) |
|
665 | 665 | ); |
666 | 666 | |
667 | 667 | $logging->setup( |
@@ -672,38 +672,38 @@ discard block |
||
672 | 672 | $status |
673 | 673 | ); |
674 | 674 | |
675 | - if ( false === $hold_exceptions ) { |
|
675 | + if (false === $hold_exceptions) { |
|
676 | 676 | throw $e; |
677 | 677 | } |
678 | - if ( empty( $exception ) ) { |
|
678 | + if (empty($exception)) { |
|
679 | 679 | $exception = $e; |
680 | 680 | } else { |
681 | - $my_class = get_class( $e ); |
|
682 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
681 | + $my_class = get_class($e); |
|
682 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | // hook for pull fail |
686 | - do_action( 'object_sync_for_salesforce_pull_fail', $op, $result, $synced_object ); |
|
686 | + do_action('object_sync_for_salesforce_pull_fail', $op, $result, $synced_object); |
|
687 | 687 | |
688 | 688 | } // End try(). |
689 | 689 | |
690 | - if ( ! isset( $e ) ) { |
|
690 | + if ( ! isset($e)) { |
|
691 | 691 | // create log entry for successful delete if the result had no errors |
692 | 692 | $status = 'success'; |
693 | - if ( isset( $this->logging ) ) { |
|
693 | + if (isset($this->logging)) { |
|
694 | 694 | $logging = $this->logging; |
695 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
696 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
695 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
696 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | // 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 |
700 | - $title = sprintf( esc_html__( 'Success: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce' ), |
|
701 | - esc_attr( $op ), |
|
702 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
703 | - esc_attr( $object_id ), |
|
704 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
705 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
706 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
700 | + $title = sprintf(esc_html__('Success: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce'), |
|
701 | + esc_attr($op), |
|
702 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
703 | + esc_attr($object_id), |
|
704 | + esc_attr($mapping_object['wordpress_id']), |
|
705 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
706 | + esc_attr($mapping_object['salesforce_id']) |
|
707 | 707 | ); |
708 | 708 | |
709 | 709 | $logging->setup( |
@@ -715,38 +715,38 @@ discard block |
||
715 | 715 | ); |
716 | 716 | |
717 | 717 | // hook for pull success |
718 | - do_action( 'object_sync_for_salesforce_pull_success', $op, $result, $synced_object ); |
|
718 | + do_action('object_sync_for_salesforce_pull_success', $op, $result, $synced_object); |
|
719 | 719 | } |
720 | 720 | } else { |
721 | - $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' ) ); |
|
721 | + $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')); |
|
722 | 722 | $i = 0; |
723 | - foreach ( $wordpress_check as $match ) { |
|
723 | + foreach ($wordpress_check as $match) { |
|
724 | 724 | $i++; |
725 | - $more_ids .= sprintf( $match['salesforce_id'] ); |
|
726 | - if ( count( $wordpress_check ) !== $i ) { |
|
727 | - $more_ids .= sprintf( ', ' ); |
|
725 | + $more_ids .= sprintf($match['salesforce_id']); |
|
726 | + if (count($wordpress_check) !== $i) { |
|
727 | + $more_ids .= sprintf(', '); |
|
728 | 728 | } else { |
729 | - $more_ids .= sprintf( '.</p>' ); |
|
729 | + $more_ids .= sprintf('.</p>'); |
|
730 | 730 | } |
731 | 731 | } |
732 | 732 | |
733 | - $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>' ); |
|
733 | + $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>'); |
|
734 | 734 | |
735 | 735 | $status = 'notice'; |
736 | - if ( isset( $this->logging ) ) { |
|
736 | + if (isset($this->logging)) { |
|
737 | 737 | $logging = $this->logging; |
738 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
739 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
738 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
739 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | // 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 |
743 | - $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' ), |
|
744 | - esc_attr( $op ), |
|
745 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
746 | - esc_attr( $object_id ), |
|
747 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
748 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
749 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
743 | + $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'), |
|
744 | + esc_attr($op), |
|
745 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
746 | + esc_attr($object_id), |
|
747 | + esc_attr($mapping_object['wordpress_id']), |
|
748 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
749 | + esc_attr($mapping_object['salesforce_id']) |
|
750 | 750 | ); |
751 | 751 | |
752 | 752 | $logging->setup( |
@@ -760,27 +760,27 @@ discard block |
||
760 | 760 | |
761 | 761 | // delete the map row from WordPress after the WordPress row has been deleted |
762 | 762 | // we delete the map row even if the WordPress delete failed, because the Salesforce object is gone |
763 | - $this->mappings->delete_object_map( $mapping_object['id'] ); |
|
763 | + $this->mappings->delete_object_map($mapping_object['id']); |
|
764 | 764 | // there is no map row if we end this if statement |
765 | 765 | } // End if(). |
766 | 766 | return; |
767 | 767 | } // End if(). |
768 | 768 | |
769 | 769 | // map the Salesforce values to WordPress fields |
770 | - $params = $this->mappings->map_params( $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
770 | + $params = $this->mappings->map_params($mapping, $object, $sf_sync_trigger, false, $is_new); |
|
771 | 771 | |
772 | 772 | // hook to allow other plugins to modify the $params array |
773 | 773 | // use hook to map fields between the WordPress and Salesforce objects |
774 | 774 | // returns $params. |
775 | - $params = apply_filters( 'object_sync_for_salesforce_pull_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
775 | + $params = apply_filters('object_sync_for_salesforce_pull_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new); |
|
776 | 776 | |
777 | 777 | // if we don't get any params, there are no fields that should be sent to WordPress |
778 | - if ( empty( $params ) ) { |
|
778 | + if (empty($params)) { |
|
779 | 779 | return; |
780 | 780 | } |
781 | 781 | |
782 | 782 | // if there is a prematch WordPress field - ie email - on the fieldmap object |
783 | - if ( isset( $params['prematch'] ) && is_array( $params['prematch'] ) ) { |
|
783 | + if (isset($params['prematch']) && is_array($params['prematch'])) { |
|
784 | 784 | $prematch_field_wordpress = $params['prematch']['wordpress_field']; |
785 | 785 | $prematch_field_salesforce = $params['prematch']['salesforce_field']; |
786 | 786 | $prematch_value = $params['prematch']['value']; |
@@ -790,11 +790,11 @@ discard block |
||
790 | 790 | 'method_update' => $params['prematch']['method_update'], |
791 | 791 | 'method_read' => $params['prematch']['method_read'], |
792 | 792 | ); |
793 | - unset( $params['prematch'] ); |
|
793 | + unset($params['prematch']); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | // if there is an external key field in salesforce - ie mailchimp user id - on the fieldmap object |
797 | - if ( isset( $params['key'] ) && is_array( $params['key'] ) ) { |
|
797 | + if (isset($params['key']) && is_array($params['key'])) { |
|
798 | 798 | $key_field_wordpress = $params['key']['wordpress_field']; |
799 | 799 | $key_field_salesforce = $params['key']['salesforce_field']; |
800 | 800 | $key_value = $params['key']['value']; |
@@ -804,20 +804,20 @@ discard block |
||
804 | 804 | 'method_update' => $params['prematch']['method_update'], |
805 | 805 | 'method_read' => $params['key']['method_read'], |
806 | 806 | ); |
807 | - unset( $params['key'] ); |
|
807 | + unset($params['key']); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | // methods to run the wp create or update operations |
811 | 811 | |
812 | - if ( true === $is_new ) { |
|
812 | + if (true === $is_new) { |
|
813 | 813 | |
814 | 814 | // setup SF record type. CampaignMember objects get their Campaign's type |
815 | 815 | // i am still a bit confused about this |
816 | 816 | // we should store this as a meta field on each object, if it meets these criteria |
817 | 817 | // we need to store the read/modify attributes because the field doesn't exist in the mapping |
818 | - if ( $salesforce_mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty( $params['RecordTypeId'] ) && ( 'CampaignMember' !== $salesforce_mapping['salesforce_object'] ) ) { |
|
818 | + if ($salesforce_mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty($params['RecordTypeId']) && ('CampaignMember' !== $salesforce_mapping['salesforce_object'])) { |
|
819 | 819 | $type = $salesforce_mapping['wordpress_object']; |
820 | - if ( 'category' === $salesforce_mapping['wordpress_object'] || 'tag' === $salesforce_mapping['wordpress_object'] || 'post_tag' === $salesforce_mapping['wordpress_object'] ) { |
|
820 | + if ('category' === $salesforce_mapping['wordpress_object'] || 'tag' === $salesforce_mapping['wordpress_object'] || 'post_tag' === $salesforce_mapping['wordpress_object']) { |
|
821 | 821 | $type = 'term'; |
822 | 822 | } |
823 | 823 | $params['RecordTypeId'] = array( |
@@ -835,28 +835,28 @@ discard block |
||
835 | 835 | // returns a $salesforce_id. |
836 | 836 | // it should keep NULL if there is no match |
837 | 837 | // the function that calls this hook needs to check the mapping to make sure the WordPress object is the right type |
838 | - $wordpress_id = apply_filters( 'object_sync_for_salesforce_find_wp_object_match', null, $object, $mapping, 'pull' ); |
|
838 | + $wordpress_id = apply_filters('object_sync_for_salesforce_find_wp_object_match', null, $object, $mapping, 'pull'); |
|
839 | 839 | |
840 | 840 | // hook to allow other plugins to do something right before WordPress data is saved |
841 | 841 | // ex: run outside methods on an object if it exists, or do something in preparation for it if it doesn't |
842 | - do_action( 'object_sync_for_salesforce_pre_pull', $wordpress_id, $mapping, $object, $object_id, $params ); |
|
842 | + do_action('object_sync_for_salesforce_pre_pull', $wordpress_id, $mapping, $object, $object_id, $params); |
|
843 | 843 | |
844 | - if ( isset( $prematch_field_salesforce ) || isset( $key_field_salesforce ) || null !== $wordpress_id ) { |
|
844 | + if (isset($prematch_field_salesforce) || isset($key_field_salesforce) || null !== $wordpress_id) { |
|
845 | 845 | |
846 | 846 | $op = 'Upsert'; |
847 | 847 | |
848 | 848 | // if either prematch criteria exists, make the values queryable |
849 | - if ( isset( $prematch_field_salesforce ) ) { |
|
849 | + if (isset($prematch_field_salesforce)) { |
|
850 | 850 | $upsert_key = $prematch_field_wordpress; |
851 | 851 | $upsert_value = $prematch_value; |
852 | 852 | $upsert_methods = $prematch_methods; |
853 | - } elseif ( isset( $key_field_salesforce ) ) { |
|
853 | + } elseif (isset($key_field_salesforce)) { |
|
854 | 854 | $upsert_key = $key_field_wordpress; |
855 | 855 | $upsert_value = $key_value; |
856 | 856 | $upsert_methods = $key_methods; |
857 | 857 | } |
858 | 858 | |
859 | - if ( null !== $wordpress_id ) { |
|
859 | + if (null !== $wordpress_id) { |
|
860 | 860 | $upsert_key = $object_id; |
861 | 861 | $upsert_value = $wordpress_id; |
862 | 862 | $upsert_methods = array(); |
@@ -865,13 +865,13 @@ discard block |
||
865 | 865 | // with the flag at the end, upsert returns a $wordpress_id only |
866 | 866 | // we can then check to see if it has a mapping object |
867 | 867 | // we should only do this if the above hook didn't already set the $wordpress_id |
868 | - if ( null === $wordpress_id ) { |
|
869 | - $wordpress_id = $this->wordpress->object_upsert( $salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'], true ); |
|
868 | + if (null === $wordpress_id) { |
|
869 | + $wordpress_id = $this->wordpress->object_upsert($salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'], true); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | // find out if there is a mapping object for this WordPress object already |
873 | 873 | // don't do it if the WordPress id is 0. |
874 | - if ( 0 !== $wordpress_id ) { |
|
874 | + if (0 !== $wordpress_id) { |
|
875 | 875 | $mapping_object = $this->mappings->get_object_maps( |
876 | 876 | array( |
877 | 877 | 'wordpress_id' => $wordpress_id, |
@@ -886,35 +886,35 @@ discard block |
||
886 | 886 | ) |
887 | 887 | ); |
888 | 888 | |
889 | - if ( array() !== $mapping_object_debug ) { |
|
889 | + if (array() !== $mapping_object_debug) { |
|
890 | 890 | // create log entry to warn about at least one id of 0 |
891 | 891 | $status = 'error'; |
892 | - $title = sprintf( esc_html__( 'Error: There is at least one object map with a WordPress ID of 0.', 'object-sync-for-salesforce' ) ); |
|
892 | + $title = sprintf(esc_html__('Error: There is at least one object map with a WordPress ID of 0.', 'object-sync-for-salesforce')); |
|
893 | 893 | |
894 | - if ( 1 === count( $mapping_object_debug ) ) { |
|
894 | + if (1 === count($mapping_object_debug)) { |
|
895 | 895 | // 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 |
896 | - $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' ), |
|
897 | - absint( $mapping_object_debug['id'] ), |
|
898 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
899 | - esc_attr( $mapping_object_debug['salesforce_id'] ) |
|
896 | + $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'), |
|
897 | + absint($mapping_object_debug['id']), |
|
898 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
899 | + esc_attr($mapping_object_debug['salesforce_id']) |
|
900 | 900 | ); |
901 | 901 | } else { |
902 | - $body = sprintf( esc_html__( 'There are multiple object maps with WordPress ID of 0. Their IDs are: ', 'object-sync-for-salesforce' ) . '<ul>' ); |
|
903 | - foreach ( $mapping_object_debug as $mapping_object ) { |
|
902 | + $body = sprintf(esc_html__('There are multiple object maps with WordPress ID of 0. Their IDs are: ', 'object-sync-for-salesforce') . '<ul>'); |
|
903 | + foreach ($mapping_object_debug as $mapping_object) { |
|
904 | 904 | // translators: placeholders are: 1) the mapping object row ID, 2) the ID of the Salesforce object, 3) the WordPress object type |
905 | - $body .= sprintf( '<li>' . esc_html__( 'Mapping object id: %1$s. Salesforce Id: %2$s. WordPress object type: %3$s', 'object-sync-for-salesforce' ) . '</li>', |
|
906 | - absint( $mapping_object['id'] ), |
|
907 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
908 | - esc_attr( $salesforce_mapping['wordpress_object'] ) |
|
905 | + $body .= sprintf('<li>' . esc_html__('Mapping object id: %1$s. Salesforce Id: %2$s. WordPress object type: %3$s', 'object-sync-for-salesforce') . '</li>', |
|
906 | + absint($mapping_object['id']), |
|
907 | + esc_attr($mapping_object['salesforce_id']), |
|
908 | + esc_attr($salesforce_mapping['wordpress_object']) |
|
909 | 909 | ); |
910 | 910 | } |
911 | - $body .= sprintf( '</ul>' ); |
|
911 | + $body .= sprintf('</ul>'); |
|
912 | 912 | } |
913 | 913 | |
914 | - if ( isset( $this->logging ) ) { |
|
914 | + if (isset($this->logging)) { |
|
915 | 915 | $logging = $this->logging; |
916 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
917 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
916 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
917 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
918 | 918 | } |
919 | 919 | $parent = 0; |
920 | 920 | $logging->setup( |
@@ -928,37 +928,37 @@ discard block |
||
928 | 928 | } // End if(). |
929 | 929 | |
930 | 930 | // there is already a mapping object. don't change the WordPress data to match this new Salesforce record, but log it |
931 | - if ( isset( $mapping_object['id'] ) ) { |
|
931 | + if (isset($mapping_object['id'])) { |
|
932 | 932 | // set the transient so that salesforce_push doesn't start doing stuff, then return out of here |
933 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
934 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
933 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
934 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
935 | 935 | // create log entry to indicate that nothing happened |
936 | 936 | $status = 'notice'; |
937 | 937 | // translators: placeholders are: 1) mapping object row id, 2) WordPress object tyoe, 3) individual WordPress item ID, 4) individual Salesforce item ID |
938 | - $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' ), |
|
939 | - absint( $mapping_object['id'] ), |
|
940 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
941 | - absint( $wordpress_id ), |
|
942 | - esc_attr( $object['Id'] ) |
|
938 | + $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'), |
|
939 | + absint($mapping_object['id']), |
|
940 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
941 | + absint($wordpress_id), |
|
942 | + esc_attr($object['Id']) |
|
943 | 943 | ); |
944 | 944 | |
945 | 945 | // 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 |
946 | - $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' ), |
|
947 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
948 | - esc_attr( $structure['id_field'] ), |
|
949 | - absint( $wordpress_id ), |
|
950 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
951 | - esc_attr( $object['Id'] ), |
|
952 | - absint( $mapping_object['id'] ) |
|
946 | + $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'), |
|
947 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
948 | + esc_attr($structure['id_field']), |
|
949 | + absint($wordpress_id), |
|
950 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
951 | + esc_attr($object['Id']), |
|
952 | + absint($mapping_object['id']) |
|
953 | 953 | ); |
954 | 954 | |
955 | - if ( isset( $this->logging ) ) { |
|
955 | + if (isset($this->logging)) { |
|
956 | 956 | $logging = $this->logging; |
957 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
958 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
957 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
958 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
959 | 959 | } |
960 | 960 | // if we know the WordPress object id we can put it in there |
961 | - if ( null !== $wordpress_id ) { |
|
961 | + if (null !== $wordpress_id) { |
|
962 | 962 | $parent = $wordpress_id; |
963 | 963 | } else { |
964 | 964 | $parent = 0; |
@@ -977,9 +977,9 @@ discard block |
||
977 | 977 | // right here we should set the pulling transient |
978 | 978 | // this means we have to create the mapping object here as well, and update it with the correct IDs after successful response |
979 | 979 | // create the mapping object between the rows |
980 | - $mapping_object_id = $this->create_object_map( $object, $this->mappings->generate_temporary_id( 'pull' ), $mapping ); |
|
981 | - set_transient( 'salesforce_pulling_' . $mapping_object_id, 1, $seconds ); |
|
982 | - set_transient( 'salesforce_pulling_object_id', $mapping_object_id ); |
|
980 | + $mapping_object_id = $this->create_object_map($object, $this->mappings->generate_temporary_id('pull'), $mapping); |
|
981 | + set_transient('salesforce_pulling_' . $mapping_object_id, 1, $seconds); |
|
982 | + set_transient('salesforce_pulling_object_id', $mapping_object_id); |
|
983 | 983 | $mapping_object = $this->mappings->get_object_maps( |
984 | 984 | array( |
985 | 985 | 'id' => $mapping_object_id, |
@@ -988,50 +988,50 @@ discard block |
||
988 | 988 | |
989 | 989 | // now we can upsert the object in wp if we've gotten to this point |
990 | 990 | // this command will either create or update the object |
991 | - $result = $this->wordpress->object_upsert( $salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'] ); |
|
991 | + $result = $this->wordpress->object_upsert($salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts']); |
|
992 | 992 | |
993 | 993 | } else { |
994 | 994 | // No key or prematch field exists on this field map object, create a new object in WordPress. |
995 | 995 | $op = 'Create'; |
996 | - $mapping_object_id = $this->create_object_map( $object, $this->mappings->generate_temporary_id( 'pull' ), $mapping ); |
|
997 | - set_transient( 'salesforce_pulling_' . $mapping_object_id, 1, $seconds ); |
|
998 | - set_transient( 'salesforce_pulling_object_id', $mapping_object_id ); |
|
996 | + $mapping_object_id = $this->create_object_map($object, $this->mappings->generate_temporary_id('pull'), $mapping); |
|
997 | + set_transient('salesforce_pulling_' . $mapping_object_id, 1, $seconds); |
|
998 | + set_transient('salesforce_pulling_object_id', $mapping_object_id); |
|
999 | 999 | $mapping_object = $this->mappings->get_object_maps( |
1000 | 1000 | array( |
1001 | 1001 | 'id' => $mapping_object_id, |
1002 | 1002 | ) |
1003 | 1003 | ); |
1004 | 1004 | |
1005 | - $result = $this->wordpress->object_create( $salesforce_mapping['wordpress_object'], $params ); |
|
1005 | + $result = $this->wordpress->object_create($salesforce_mapping['wordpress_object'], $params); |
|
1006 | 1006 | } // End if(). |
1007 | - } catch ( WordpressException $e ) { |
|
1007 | + } catch (WordpressException $e) { |
|
1008 | 1008 | // create log entry for failed create or upsert |
1009 | 1009 | $status = 'error'; |
1010 | 1010 | |
1011 | 1011 | // translators: placeholders are: 1) what operation is happening, and 2) the name of the WordPress object |
1012 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s', 'object-sync-for-salesforce' ), |
|
1013 | - esc_attr( $op ), |
|
1014 | - esc_attr( $salesforce_mapping['wordpress_object'] ) |
|
1012 | + $title = sprintf(esc_html__('Error: %1$s %2$s', 'object-sync-for-salesforce'), |
|
1013 | + esc_attr($op), |
|
1014 | + esc_attr($salesforce_mapping['wordpress_object']) |
|
1015 | 1015 | ); |
1016 | 1016 | |
1017 | - if ( null !== $salesforce_id ) { |
|
1017 | + if (null !== $salesforce_id) { |
|
1018 | 1018 | $title .= ' ' . $salesforce_id; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | // translators: placeholders are: 1) the name of the Salesforce object, and 2) Id of the Salesforce object |
1022 | - $title .= sprintf( esc_html__( ' (Salesforce %1$s with Id of %2$s)', 'object-sync-for-salesforce' ), |
|
1022 | + $title .= sprintf(esc_html__(' (Salesforce %1$s with Id of %2$s)', 'object-sync-for-salesforce'), |
|
1023 | 1023 | $salesforce_mapping['salesforce_object'], |
1024 | 1024 | $object['Id'] |
1025 | 1025 | ); |
1026 | 1026 | |
1027 | - if ( isset( $this->logging ) ) { |
|
1027 | + if (isset($this->logging)) { |
|
1028 | 1028 | $logging = $this->logging; |
1029 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1030 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1029 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1030 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | // if we know the WordPress object id we can put it in there |
1034 | - if ( null !== $wordpress_id ) { |
|
1034 | + if (null !== $wordpress_id) { |
|
1035 | 1035 | $parent = $wordpress_id; |
1036 | 1036 | } else { |
1037 | 1037 | $parent = 0; |
@@ -1045,26 +1045,26 @@ discard block |
||
1045 | 1045 | $status |
1046 | 1046 | ); |
1047 | 1047 | |
1048 | - if ( false === $hold_exceptions ) { |
|
1048 | + if (false === $hold_exceptions) { |
|
1049 | 1049 | throw $e; |
1050 | 1050 | } |
1051 | - if ( empty( $exception ) ) { |
|
1051 | + if (empty($exception)) { |
|
1052 | 1052 | $exception = $e; |
1053 | 1053 | } else { |
1054 | - $my_class = get_class( $e ); |
|
1055 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
1054 | + $my_class = get_class($e); |
|
1055 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | // hook for pull fail |
1059 | - do_action( 'object_sync_for_salesforce_pull_fail', $op, $result, $synced_object ); |
|
1059 | + do_action('object_sync_for_salesforce_pull_fail', $op, $result, $synced_object); |
|
1060 | 1060 | |
1061 | 1061 | return; |
1062 | 1062 | } // End try(). |
1063 | 1063 | |
1064 | 1064 | // set $wordpress_data to the query result |
1065 | 1065 | $wordpress_data = $result['data']; |
1066 | - if ( isset( $wordpress_data[ "$object_id" ] ) ) { |
|
1067 | - $wordpress_id = $wordpress_data[ "$object_id" ]; |
|
1066 | + if (isset($wordpress_data["$object_id"])) { |
|
1067 | + $wordpress_id = $wordpress_data["$object_id"]; |
|
1068 | 1068 | } else { |
1069 | 1069 | $wordpress_id = 0; |
1070 | 1070 | } |
@@ -1073,23 +1073,23 @@ discard block |
||
1073 | 1073 | // this means the object has already been created/updated in WordPress |
1074 | 1074 | // 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) |
1075 | 1075 | |
1076 | - if ( empty( $result['errors'] ) ) { |
|
1076 | + if (empty($result['errors'])) { |
|
1077 | 1077 | $status = 'success'; |
1078 | 1078 | |
1079 | - if ( isset( $this->logging ) ) { |
|
1079 | + if (isset($this->logging)) { |
|
1080 | 1080 | $logging = $this->logging; |
1081 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1082 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1081 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1082 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1083 | 1083 | } |
1084 | 1084 | |
1085 | 1085 | // 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 |
1086 | - $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' ), |
|
1087 | - esc_attr( $op ), |
|
1088 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1089 | - esc_attr( $object_id ), |
|
1090 | - esc_attr( $wordpress_id ), |
|
1091 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1092 | - esc_attr( $object['Id'] ) |
|
1086 | + $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'), |
|
1087 | + esc_attr($op), |
|
1088 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1089 | + esc_attr($object_id), |
|
1090 | + esc_attr($wordpress_id), |
|
1091 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1092 | + esc_attr($object['Id']) |
|
1093 | 1093 | ); |
1094 | 1094 | |
1095 | 1095 | $logging->setup( |
@@ -1102,40 +1102,40 @@ discard block |
||
1102 | 1102 | |
1103 | 1103 | // update that mapping object |
1104 | 1104 | $mapping_object['wordpress_id'] = $wordpress_id; |
1105 | - $mapping_object = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1105 | + $mapping_object = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1106 | 1106 | |
1107 | 1107 | // hook for pull success |
1108 | - do_action( 'object_sync_for_salesforce_pull_success', $op, $result, $synced_object ); |
|
1108 | + do_action('object_sync_for_salesforce_pull_success', $op, $result, $synced_object); |
|
1109 | 1109 | } else { |
1110 | 1110 | |
1111 | 1111 | // create log entry for failed create or upsert |
1112 | 1112 | // 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 |
1113 | 1113 | // if we see this in the log entries, we can understand what it does, but probably not until then |
1114 | 1114 | $status = 'error'; |
1115 | - if ( isset( $this->logging ) ) { |
|
1115 | + if (isset($this->logging)) { |
|
1116 | 1116 | $logging = $this->logging; |
1117 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1118 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1117 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1118 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | - if ( is_object( $wordpress_id ) ) { |
|
1121 | + if (is_object($wordpress_id)) { |
|
1122 | 1122 | // print this array because if this happens, something weird has happened and we want to log whatever we have |
1123 | - $wordpress_id = print_r( $wordpress_id, true ); |
|
1123 | + $wordpress_id = print_r($wordpress_id, true); |
|
1124 | 1124 | } |
1125 | 1125 | |
1126 | 1126 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object type, 3) the Salesforce object Id value |
1127 | - $title = sprintf( esc_html__( 'Error syncing: %1$s to WordPress (Salesforce %2$s Id %3$s)', 'object-sync-for-salesforce' ), |
|
1128 | - esc_attr( $op ), |
|
1129 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1130 | - esc_attr( $object['Id'] ) |
|
1127 | + $title = sprintf(esc_html__('Error syncing: %1$s to WordPress (Salesforce %2$s Id %3$s)', 'object-sync-for-salesforce'), |
|
1128 | + esc_attr($op), |
|
1129 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1130 | + esc_attr($object['Id']) |
|
1131 | 1131 | ); |
1132 | 1132 | |
1133 | 1133 | // 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 |
1134 | - $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', |
|
1135 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1136 | - esc_attr( $object_id ), |
|
1137 | - esc_attr( $wordpress_id ), |
|
1138 | - print_r( $result['errors'], true ) // if we get this error, we need to know whatever we have |
|
1134 | + $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', |
|
1135 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1136 | + esc_attr($object_id), |
|
1137 | + esc_attr($wordpress_id), |
|
1138 | + print_r($result['errors'], true) // if we get this error, we need to know whatever we have |
|
1139 | 1139 | ); |
1140 | 1140 | |
1141 | 1141 | $logging->setup( |
@@ -1147,52 +1147,52 @@ discard block |
||
1147 | 1147 | ); |
1148 | 1148 | |
1149 | 1149 | // hook for pull fail |
1150 | - do_action( 'object_sync_for_salesforce_pull_fail', $op, $result, $synced_object ); |
|
1150 | + do_action('object_sync_for_salesforce_pull_fail', $op, $result, $synced_object); |
|
1151 | 1151 | |
1152 | 1152 | return; |
1153 | 1153 | } // End if(). |
1154 | - } elseif ( false === $is_new ) { |
|
1154 | + } elseif (false === $is_new) { |
|
1155 | 1155 | |
1156 | 1156 | // right here we should set the pulling transient |
1157 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
1158 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
1157 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
1158 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
1159 | 1159 | |
1160 | 1160 | // there is an existing object link |
1161 | 1161 | // if the last sync is greater than the last time this object was updated by Salesforce, skip it |
1162 | 1162 | // this keeps us from doing redundant syncs |
1163 | 1163 | // because SF stores all DateTimes in UTC. |
1164 | - $mapping_object['object_updated'] = current_time( 'mysql' ); |
|
1164 | + $mapping_object['object_updated'] = current_time('mysql'); |
|
1165 | 1165 | |
1166 | 1166 | $pull_trigger_field = $salesforce_mapping['pull_trigger_field']; |
1167 | - $pull_trigger_value = $object[ $pull_trigger_field ]; |
|
1167 | + $pull_trigger_value = $object[$pull_trigger_field]; |
|
1168 | 1168 | |
1169 | 1169 | try { |
1170 | 1170 | |
1171 | 1171 | // hook to allow other plugins to do something right before WordPress data is saved |
1172 | 1172 | // ex: run outside methods on an object if it exists, or do something in preparation for it if it doesn't |
1173 | - do_action( 'object_sync_for_salesforce_pre_pull', $mapping_object['wordpress_id'], $mapping, $object, $object_id, $params ); |
|
1173 | + do_action('object_sync_for_salesforce_pre_pull', $mapping_object['wordpress_id'], $mapping, $object, $object_id, $params); |
|
1174 | 1174 | |
1175 | 1175 | $op = 'Update'; |
1176 | - $result = $this->wordpress->object_update( $salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'], $params ); |
|
1176 | + $result = $this->wordpress->object_update($salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'], $params); |
|
1177 | 1177 | |
1178 | 1178 | $mapping_object['last_sync_status'] = $this->mappings->status_success; |
1179 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
1179 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
1180 | 1180 | |
1181 | 1181 | $status = 'success'; |
1182 | - if ( isset( $this->logging ) ) { |
|
1182 | + if (isset($this->logging)) { |
|
1183 | 1183 | $logging = $this->logging; |
1184 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1185 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1184 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1185 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1186 | 1186 | } |
1187 | 1187 | |
1188 | 1188 | // 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 |
1189 | - $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' ), |
|
1190 | - esc_attr( $op ), |
|
1191 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1192 | - esc_attr( $object_id ), |
|
1193 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
1194 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1195 | - esc_attr( $object['Id'] ) |
|
1189 | + $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'), |
|
1190 | + esc_attr($op), |
|
1191 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1192 | + esc_attr($object_id), |
|
1193 | + esc_attr($mapping_object['wordpress_id']), |
|
1194 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1195 | + esc_attr($object['Id']) |
|
1196 | 1196 | ); |
1197 | 1197 | |
1198 | 1198 | $logging->setup( |
@@ -1204,25 +1204,25 @@ discard block |
||
1204 | 1204 | ); |
1205 | 1205 | |
1206 | 1206 | // hook for pull success |
1207 | - do_action( 'object_sync_for_salesforce_pull_success', $op, $result, $synced_object ); |
|
1207 | + do_action('object_sync_for_salesforce_pull_success', $op, $result, $synced_object); |
|
1208 | 1208 | |
1209 | - } catch ( WordpressException $e ) { |
|
1209 | + } catch (WordpressException $e) { |
|
1210 | 1210 | // create log entry for failed update |
1211 | 1211 | $status = 'error'; |
1212 | - if ( isset( $this->logging ) ) { |
|
1212 | + if (isset($this->logging)) { |
|
1213 | 1213 | $logging = $this->logging; |
1214 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1215 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1214 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1215 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | 1218 | // 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 |
1219 | - $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' ), |
|
1220 | - esc_attr( $op ), |
|
1221 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1222 | - esc_attr( $object_id ), |
|
1223 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
1224 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1225 | - esc_attr( $object['Id'] ) |
|
1219 | + $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'), |
|
1220 | + esc_attr($op), |
|
1221 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1222 | + esc_attr($object_id), |
|
1223 | + esc_attr($mapping_object['wordpress_id']), |
|
1224 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1225 | + esc_attr($object['Id']) |
|
1226 | 1226 | ); |
1227 | 1227 | |
1228 | 1228 | $logging->setup( |
@@ -1236,18 +1236,18 @@ discard block |
||
1236 | 1236 | $mapping_object['last_sync_status'] = $this->mappings->status_error; |
1237 | 1237 | $mapping_object['last_sync_message'] = $e->getMessage(); |
1238 | 1238 | |
1239 | - if ( false === $hold_exceptions ) { |
|
1239 | + if (false === $hold_exceptions) { |
|
1240 | 1240 | throw $e; |
1241 | 1241 | } |
1242 | - if ( empty( $exception ) ) { |
|
1242 | + if (empty($exception)) { |
|
1243 | 1243 | $exception = $e; |
1244 | 1244 | } else { |
1245 | - $my_class = get_class( $e ); |
|
1246 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
1245 | + $my_class = get_class($e); |
|
1246 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
1247 | 1247 | } |
1248 | 1248 | |
1249 | 1249 | // hook for pull fail |
1250 | - do_action( 'object_sync_for_salesforce_pull_fail', $op, $result, $synced_object ); |
|
1250 | + do_action('object_sync_for_salesforce_pull_fail', $op, $result, $synced_object); |
|
1251 | 1251 | |
1252 | 1252 | } // End try(). |
1253 | 1253 | |
@@ -1256,26 +1256,26 @@ discard block |
||
1256 | 1256 | // maybe can check to see if we actually updated anything in WordPress |
1257 | 1257 | // tell the mapping object - whether it is new or already existed - how we just used it |
1258 | 1258 | $mapping_object['last_sync_action'] = 'pull'; |
1259 | - $mapping_object['last_sync'] = current_time( 'mysql' ); |
|
1259 | + $mapping_object['last_sync'] = current_time('mysql'); |
|
1260 | 1260 | |
1261 | 1261 | // update that mapping object. the Salesforce data version will be set here as well because we set it earlier |
1262 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1262 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1263 | 1263 | // end of the if statement for is_new & update or create trigger |
1264 | 1264 | // 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. |
1265 | 1265 | } // End if(). |
1266 | 1266 | } // End foreach(). |
1267 | 1267 | |
1268 | 1268 | // delete transients that we've already processed |
1269 | - foreach ( $transients_to_delete as $mapping_object_id_transient ) { |
|
1270 | - delete_transient( 'salesforce_pushing_' . $mapping_object_id_transient ); |
|
1269 | + foreach ($transients_to_delete as $mapping_object_id_transient) { |
|
1270 | + delete_transient('salesforce_pushing_' . $mapping_object_id_transient); |
|
1271 | 1271 | } |
1272 | 1272 | |
1273 | - $pushing_id = get_transient( 'salesforce_pushing_object_id' ); |
|
1274 | - if ( in_array( $pushing_id, $transients_to_delete, true ) ) { |
|
1275 | - delete_transient( 'salesforce_pushing_object_id' ); |
|
1273 | + $pushing_id = get_transient('salesforce_pushing_object_id'); |
|
1274 | + if (in_array($pushing_id, $transients_to_delete, true)) { |
|
1275 | + delete_transient('salesforce_pushing_object_id'); |
|
1276 | 1276 | } |
1277 | 1277 | |
1278 | - if ( ! empty( $exception ) ) { |
|
1278 | + if ( ! empty($exception)) { |
|
1279 | 1279 | throw $exception; |
1280 | 1280 | } |
1281 | 1281 | |
@@ -1295,17 +1295,17 @@ discard block |
||
1295 | 1295 | * This is the database row for the map object |
1296 | 1296 | * |
1297 | 1297 | */ |
1298 | - private function create_object_map( $salesforce_object, $wordpress_id, $field_mapping ) { |
|
1298 | + private function create_object_map($salesforce_object, $wordpress_id, $field_mapping) { |
|
1299 | 1299 | // Create object map and save it |
1300 | 1300 | $mapping_object = $this->mappings->create_object_map( |
1301 | 1301 | array( |
1302 | 1302 | 'wordpress_id' => $wordpress_id, // wordpress unique id |
1303 | 1303 | 'salesforce_id' => $salesforce_object['Id'], // salesforce unique id. we don't care what kind of object it is at this point |
1304 | 1304 | 'wordpress_object' => $field_mapping['wordpress_object'], // keep track of what kind of wp object this is |
1305 | - 'last_sync' => current_time( 'mysql' ), |
|
1305 | + 'last_sync' => current_time('mysql'), |
|
1306 | 1306 | 'last_sync_action' => 'pull', |
1307 | 1307 | 'last_sync_status' => $this->mappings->status_success, |
1308 | - 'last_sync_message' => esc_html__( 'Mapping object created via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
1308 | + 'last_sync_message' => esc_html__('Mapping object created via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
1309 | 1309 | 'action' => 'created', |
1310 | 1310 | ) |
1311 | 1311 | ); |
@@ -26,62 +26,62 @@ discard block |
||
26 | 26 | protected $schedulable_classes; |
27 | 27 | |
28 | 28 | /** |
29 | - * @var string |
|
30 | - * Default path for the Salesforce authorize URL |
|
31 | - */ |
|
29 | + * @var string |
|
30 | + * Default path for the Salesforce authorize URL |
|
31 | + */ |
|
32 | 32 | public $default_authorize_url_path; |
33 | 33 | |
34 | 34 | /** |
35 | - * @var string |
|
36 | - * Default path for the Salesforce token URL |
|
37 | - */ |
|
35 | + * @var string |
|
36 | + * Default path for the Salesforce token URL |
|
37 | + */ |
|
38 | 38 | public $default_token_url_path; |
39 | 39 | |
40 | 40 | /** |
41 | - * @var string |
|
42 | - * What version of the Salesforce API should be the default on the settings screen. |
|
43 | - * Users can edit this, but they won't see a correct list of all their available versions until WordPress has |
|
44 | - * been authenticated with Salesforce. |
|
45 | - */ |
|
41 | + * @var string |
|
42 | + * What version of the Salesforce API should be the default on the settings screen. |
|
43 | + * Users can edit this, but they won't see a correct list of all their available versions until WordPress has |
|
44 | + * been authenticated with Salesforce. |
|
45 | + */ |
|
46 | 46 | public $default_api_version; |
47 | 47 | |
48 | 48 | /** |
49 | - * @var bool |
|
50 | - * Default for whether to limit to triggerable items |
|
51 | - * Users can edit this |
|
52 | - */ |
|
49 | + * @var bool |
|
50 | + * Default for whether to limit to triggerable items |
|
51 | + * Users can edit this |
|
52 | + */ |
|
53 | 53 | public $default_triggerable; |
54 | 54 | |
55 | 55 | /** |
56 | - * @var bool |
|
57 | - * Default for whether to limit to updateable items |
|
58 | - * Users can edit this |
|
59 | - */ |
|
56 | + * @var bool |
|
57 | + * Default for whether to limit to updateable items |
|
58 | + * Users can edit this |
|
59 | + */ |
|
60 | 60 | public $default_updateable; |
61 | 61 | |
62 | 62 | /** |
63 | - * @var int |
|
64 | - * Default pull throttle for how often Salesforce can pull |
|
65 | - * Users can edit this |
|
66 | - */ |
|
63 | + * @var int |
|
64 | + * Default pull throttle for how often Salesforce can pull |
|
65 | + * Users can edit this |
|
66 | + */ |
|
67 | 67 | public $default_pull_throttle; |
68 | 68 | |
69 | 69 | /** |
70 | - * Constructor which sets up admin pages |
|
71 | - * |
|
72 | - * @param object $wpdb |
|
73 | - * @param string $version |
|
74 | - * @param array $login_credentials |
|
75 | - * @param string $slug |
|
76 | - * @param object $wordpress |
|
77 | - * @param object $salesforce |
|
78 | - * @param object $mappings |
|
79 | - * @param object $push |
|
80 | - * @param object $pull |
|
81 | - * @param object $logging |
|
82 | - * @param array $schedulable_classes |
|
83 | - * @throws \Exception |
|
84 | - */ |
|
70 | + * Constructor which sets up admin pages |
|
71 | + * |
|
72 | + * @param object $wpdb |
|
73 | + * @param string $version |
|
74 | + * @param array $login_credentials |
|
75 | + * @param string $slug |
|
76 | + * @param object $wordpress |
|
77 | + * @param object $salesforce |
|
78 | + * @param object $mappings |
|
79 | + * @param object $push |
|
80 | + * @param object $pull |
|
81 | + * @param object $logging |
|
82 | + * @param array $schedulable_classes |
|
83 | + * @throws \Exception |
|
84 | + */ |
|
85 | 85 | public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes ) { |
86 | 86 | $this->wpdb = $wpdb; |
87 | 87 | $this->version = $version; |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | - * Create the action hooks to create the admin page(s) |
|
121 | - * |
|
122 | - */ |
|
120 | + * Create the action hooks to create the admin page(s) |
|
121 | + * |
|
122 | + */ |
|
123 | 123 | public function add_actions() { |
124 | 124 | add_action( 'admin_init', array( $this, 'salesforce_settings_forms' ) ); |
125 | 125 | add_action( 'admin_init', array( $this, 'notices' ) ); |
@@ -148,21 +148,21 @@ discard block |
||
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Create WordPress admin options page |
|
152 | - * |
|
153 | - */ |
|
151 | + * Create WordPress admin options page |
|
152 | + * |
|
153 | + */ |
|
154 | 154 | public function create_admin_menu() { |
155 | 155 | $title = __( 'Salesforce', 'object-sync-for-salesforce' ); |
156 | 156 | add_options_page( $title, $title, 'configure_salesforce', 'object-sync-salesforce-admin', array( $this, 'show_admin_page' ) ); |
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | - * Render full admin pages in WordPress |
|
161 | - * This allows other plugins to add tabs to the Salesforce settings screen |
|
162 | - * |
|
163 | - * todo: better front end: html, organization of html into templates, css, js |
|
164 | - * |
|
165 | - */ |
|
160 | + * Render full admin pages in WordPress |
|
161 | + * This allows other plugins to add tabs to the Salesforce settings screen |
|
162 | + * |
|
163 | + * todo: better front end: html, organization of html into templates, css, js |
|
164 | + * |
|
165 | + */ |
|
166 | 166 | public function show_admin_page() { |
167 | 167 | $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
168 | 168 | echo '<div class="wrap">'; |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
375 | - * Create default WordPress admin settings form for salesforce |
|
376 | - * This is for the Settings page/tab |
|
377 | - * |
|
378 | - */ |
|
375 | + * Create default WordPress admin settings form for salesforce |
|
376 | + * This is for the Settings page/tab |
|
377 | + * |
|
378 | + */ |
|
379 | 379 | public function salesforce_settings_forms() { |
380 | 380 | $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
381 | 381 | $page = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
@@ -400,13 +400,13 @@ discard block |
||
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
403 | - * Fields for the Settings tab |
|
404 | - * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
405 | - * |
|
406 | - * @param string $page |
|
407 | - * @param string $section |
|
408 | - * @param string $input_callback |
|
409 | - */ |
|
403 | + * Fields for the Settings tab |
|
404 | + * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
405 | + * |
|
406 | + * @param string $page |
|
407 | + * @param string $section |
|
408 | + * @param string $input_callback |
|
409 | + */ |
|
410 | 410 | private function fields_settings( $page, $section, $callbacks ) { |
411 | 411 | add_settings_section( $page, ucwords( $page ), null, $page ); |
412 | 412 | $salesforce_settings = array( |
@@ -611,25 +611,25 @@ discard block |
||
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
614 | - * Fields for the Fieldmaps tab |
|
615 | - * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
616 | - * |
|
617 | - * @param string $page |
|
618 | - * @param string $section |
|
619 | - * @param string $input_callback |
|
620 | - */ |
|
614 | + * Fields for the Fieldmaps tab |
|
615 | + * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
616 | + * |
|
617 | + * @param string $page |
|
618 | + * @param string $section |
|
619 | + * @param string $input_callback |
|
620 | + */ |
|
621 | 621 | private function fields_fieldmaps( $page, $section, $input_callback = '' ) { |
622 | 622 | add_settings_section( $page, ucwords( $page ), null, $page ); |
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
626 | - * Fields for the Scheduling tab |
|
627 | - * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
628 | - * |
|
629 | - * @param string $page |
|
630 | - * @param string $section |
|
631 | - * @param string $input_callback |
|
632 | - */ |
|
626 | + * Fields for the Scheduling tab |
|
627 | + * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
628 | + * |
|
629 | + * @param string $page |
|
630 | + * @param string $section |
|
631 | + * @param string $input_callback |
|
632 | + */ |
|
633 | 633 | private function fields_scheduling( $page, $section, $callbacks ) { |
634 | 634 | foreach ( $this->schedulable_classes as $key => $value ) { |
635 | 635 | add_settings_section( $key, $value['label'], null, $page ); |
@@ -708,13 +708,13 @@ discard block |
||
708 | 708 | } |
709 | 709 | |
710 | 710 | /** |
711 | - * Fields for the Log Settings tab |
|
712 | - * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
713 | - * |
|
714 | - * @param string $page |
|
715 | - * @param string $section |
|
716 | - * @param array $callbacks |
|
717 | - */ |
|
711 | + * Fields for the Log Settings tab |
|
712 | + * This runs add_settings_section once, as well as add_settings_field and register_setting methods for each option |
|
713 | + * |
|
714 | + * @param string $page |
|
715 | + * @param string $section |
|
716 | + * @param array $callbacks |
|
717 | + */ |
|
718 | 718 | private function fields_log_settings( $page, $section, $callbacks ) { |
719 | 719 | add_settings_section( $page, ucwords( str_replace( '_', ' ', $page ) ), null, $page ); |
720 | 720 | $log_settings = array( |
@@ -892,9 +892,9 @@ discard block |
||
892 | 892 | } |
893 | 893 | |
894 | 894 | /** |
895 | - * Create the notices, settings, and conditions by which admin notices should appear |
|
896 | - * |
|
897 | - */ |
|
895 | + * Create the notices, settings, and conditions by which admin notices should appear |
|
896 | + * |
|
897 | + */ |
|
898 | 898 | public function notices() { |
899 | 899 | |
900 | 900 | // before a notice is displayed, we should make sure we are on a page related to this plugin |
@@ -967,14 +967,14 @@ discard block |
||
967 | 967 | } |
968 | 968 | |
969 | 969 | /** |
970 | - * Get all the Salesforce object settings for fieldmapping |
|
971 | - * This takes either the $_POST array via ajax, or can be directly called with a $data array |
|
972 | - * |
|
973 | - * @param array $data |
|
974 | - * data must contain a salesforce_object |
|
975 | - * can optionally contain a type |
|
976 | - * @return array $object_settings |
|
977 | - */ |
|
970 | + * Get all the Salesforce object settings for fieldmapping |
|
971 | + * This takes either the $_POST array via ajax, or can be directly called with a $data array |
|
972 | + * |
|
973 | + * @param array $data |
|
974 | + * data must contain a salesforce_object |
|
975 | + * can optionally contain a type |
|
976 | + * @return array $object_settings |
|
977 | + */ |
|
978 | 978 | public function get_salesforce_object_description( $data = array() ) { |
979 | 979 | $ajax = false; |
980 | 980 | if ( empty( $data ) ) { |
@@ -1022,13 +1022,13 @@ discard block |
||
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | /** |
1025 | - * Get Salesforce object fields for fieldmapping |
|
1026 | - * |
|
1027 | - * @param array $data |
|
1028 | - * data must contain a salesforce_object |
|
1029 | - * can optionally contain a type for the field |
|
1030 | - * @return array $object_fields |
|
1031 | - */ |
|
1025 | + * Get Salesforce object fields for fieldmapping |
|
1026 | + * |
|
1027 | + * @param array $data |
|
1028 | + * data must contain a salesforce_object |
|
1029 | + * can optionally contain a type for the field |
|
1030 | + * @return array $object_fields |
|
1031 | + */ |
|
1032 | 1032 | public function get_salesforce_object_fields( $data = array() ) { |
1033 | 1033 | |
1034 | 1034 | if ( ! empty( $data['salesforce_object'] ) ) { |
@@ -1056,12 +1056,12 @@ discard block |
||
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | /** |
1059 | - * Get WordPress object fields for fieldmapping |
|
1060 | - * This takes either the $_POST array via ajax, or can be directly called with a $wordpress_object field |
|
1061 | - * |
|
1062 | - * @param string $wordpress_object |
|
1063 | - * @return array $object_fields |
|
1064 | - */ |
|
1059 | + * Get WordPress object fields for fieldmapping |
|
1060 | + * This takes either the $_POST array via ajax, or can be directly called with a $wordpress_object field |
|
1061 | + * |
|
1062 | + * @param string $wordpress_object |
|
1063 | + * @return array $object_fields |
|
1064 | + */ |
|
1065 | 1065 | public function get_wordpress_object_fields( $wordpress_object = '' ) { |
1066 | 1066 | $ajax = false; |
1067 | 1067 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
@@ -1080,13 +1080,13 @@ discard block |
||
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | /** |
1083 | - * Get WordPress and Salesforce object fields together for fieldmapping |
|
1084 | - * This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $salesforce_object fields |
|
1085 | - * |
|
1086 | - * @param string $wordpress_object |
|
1087 | - * @param string $salesforce_object |
|
1088 | - * @return array $object_fields |
|
1089 | - */ |
|
1083 | + * Get WordPress and Salesforce object fields together for fieldmapping |
|
1084 | + * This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $salesforce_object fields |
|
1085 | + * |
|
1086 | + * @param string $wordpress_object |
|
1087 | + * @param string $salesforce_object |
|
1088 | + * @return array $object_fields |
|
1089 | + */ |
|
1090 | 1090 | public function get_wp_sf_object_fields( $wordpress_object = '', $salesforce = '' ) { |
1091 | 1091 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1092 | 1092 | if ( empty( $wordpress_object ) ) { |
@@ -1111,12 +1111,12 @@ discard block |
||
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | /** |
1114 | - * Manually push the WordPress object to Salesforce |
|
1115 | - * This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $wordpress_id fields |
|
1116 | - * |
|
1117 | - * @param string $wordpress_object |
|
1118 | - * @param int $wordpress_id |
|
1119 | - */ |
|
1114 | + * Manually push the WordPress object to Salesforce |
|
1115 | + * This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $wordpress_id fields |
|
1116 | + * |
|
1117 | + * @param string $wordpress_object |
|
1118 | + * @param int $wordpress_id |
|
1119 | + */ |
|
1120 | 1120 | public function push_to_salesforce( $wordpress_object = '', $wordpress_id = '' ) { |
1121 | 1121 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1122 | 1122 | if ( empty( $wordpress_object ) && empty( $wordpress_id ) ) { |
@@ -1135,12 +1135,12 @@ discard block |
||
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | /** |
1138 | - * Manually pull the Salesforce object into WordPress |
|
1139 | - * This takes either the $_POST array via ajax, or can be directly called with $salesforce_id fields |
|
1140 | - * |
|
1141 | - * @param string $salesforce_id |
|
1142 | - * @param string $wordpress_object |
|
1143 | - */ |
|
1138 | + * Manually pull the Salesforce object into WordPress |
|
1139 | + * This takes either the $_POST array via ajax, or can be directly called with $salesforce_id fields |
|
1140 | + * |
|
1141 | + * @param string $salesforce_id |
|
1142 | + * @param string $wordpress_object |
|
1143 | + */ |
|
1144 | 1144 | public function pull_from_salesforce( $salesforce_id = '', $wordpress_object = '' ) { |
1145 | 1145 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1146 | 1146 | if ( empty( $wordpress_object ) && empty( $salesforce_id ) ) { |
@@ -1157,11 +1157,11 @@ discard block |
||
1157 | 1157 | } |
1158 | 1158 | |
1159 | 1159 | /** |
1160 | - * Manually pull the Salesforce object into WordPress |
|
1161 | - * This takes an id for a mapping object row |
|
1162 | - * |
|
1163 | - * @param int $mapping_id |
|
1164 | - */ |
|
1160 | + * Manually pull the Salesforce object into WordPress |
|
1161 | + * This takes an id for a mapping object row |
|
1162 | + * |
|
1163 | + * @param int $mapping_id |
|
1164 | + */ |
|
1165 | 1165 | public function refresh_mapped_data( $mapping_id = '' ) { |
1166 | 1166 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1167 | 1167 | if ( empty( $mapping_id ) ) { |
@@ -1180,13 +1180,13 @@ discard block |
||
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | /** |
1183 | - * Prepare fieldmap data and redirect after processing |
|
1184 | - * This runs when the create or update forms are submitted |
|
1185 | - * It is public because it depends on an admin hook |
|
1186 | - * It then calls the Object_Sync_Sf_Mapping class and sends prepared data over to it, then redirects to the correct page |
|
1187 | - * This method does include error handling, by loading the submission in a transient if there is an error, and then deleting it upon success |
|
1188 | - * |
|
1189 | - */ |
|
1183 | + * Prepare fieldmap data and redirect after processing |
|
1184 | + * This runs when the create or update forms are submitted |
|
1185 | + * It is public because it depends on an admin hook |
|
1186 | + * It then calls the Object_Sync_Sf_Mapping class and sends prepared data over to it, then redirects to the correct page |
|
1187 | + * This method does include error handling, by loading the submission in a transient if there is an error, and then deleting it upon success |
|
1188 | + * |
|
1189 | + */ |
|
1190 | 1190 | public function prepare_fieldmap_data() { |
1191 | 1191 | $error = false; |
1192 | 1192 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
@@ -1234,12 +1234,12 @@ discard block |
||
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | /** |
1237 | - * Delete fieldmap data and redirect after processing |
|
1238 | - * This runs when the delete link is clicked, after the user confirms |
|
1239 | - * It is public because it depends on an admin hook |
|
1240 | - * It then calls the Object_Sync_Sf_Mapping class and the delete method |
|
1241 | - * |
|
1242 | - */ |
|
1237 | + * Delete fieldmap data and redirect after processing |
|
1238 | + * This runs when the delete link is clicked, after the user confirms |
|
1239 | + * It is public because it depends on an admin hook |
|
1240 | + * It then calls the Object_Sync_Sf_Mapping class and the delete method |
|
1241 | + * |
|
1242 | + */ |
|
1243 | 1243 | public function delete_fieldmap() { |
1244 | 1244 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1245 | 1245 | if ( $post_data['id'] ) { |
@@ -1255,13 +1255,13 @@ discard block |
||
1255 | 1255 | } |
1256 | 1256 | |
1257 | 1257 | /** |
1258 | - * Prepare object data and redirect after processing |
|
1259 | - * This runs when the update form is submitted |
|
1260 | - * It is public because it depends on an admin hook |
|
1261 | - * It then calls the Object_Sync_Sf_Mapping class and sends prepared data over to it, then redirects to the correct page |
|
1262 | - * This method does include error handling, by loading the submission in a transient if there is an error, and then deleting it upon success |
|
1263 | - * |
|
1264 | - */ |
|
1258 | + * Prepare object data and redirect after processing |
|
1259 | + * This runs when the update form is submitted |
|
1260 | + * It is public because it depends on an admin hook |
|
1261 | + * It then calls the Object_Sync_Sf_Mapping class and sends prepared data over to it, then redirects to the correct page |
|
1262 | + * This method does include error handling, by loading the submission in a transient if there is an error, and then deleting it upon success |
|
1263 | + * |
|
1264 | + */ |
|
1265 | 1265 | public function prepare_object_map_data() { |
1266 | 1266 | $error = false; |
1267 | 1267 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
@@ -1300,12 +1300,12 @@ discard block |
||
1300 | 1300 | } |
1301 | 1301 | |
1302 | 1302 | /** |
1303 | - * Delete object map data and redirect after processing |
|
1304 | - * This runs when the delete link is clicked on an error row, after the user confirms |
|
1305 | - * It is public because it depends on an admin hook |
|
1306 | - * It then calls the Object_Sync_Sf_Mapping class and the delete method |
|
1307 | - * |
|
1308 | - */ |
|
1303 | + * Delete object map data and redirect after processing |
|
1304 | + * This runs when the delete link is clicked on an error row, after the user confirms |
|
1305 | + * It is public because it depends on an admin hook |
|
1306 | + * It then calls the Object_Sync_Sf_Mapping class and the delete method |
|
1307 | + * |
|
1308 | + */ |
|
1309 | 1309 | public function delete_object_map() { |
1310 | 1310 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1311 | 1311 | if ( $post_data['id'] ) { |
@@ -1321,9 +1321,9 @@ discard block |
||
1321 | 1321 | } |
1322 | 1322 | |
1323 | 1323 | /** |
1324 | - * Import a json file and use it for plugin data |
|
1325 | - * |
|
1326 | - */ |
|
1324 | + * Import a json file and use it for plugin data |
|
1325 | + * |
|
1326 | + */ |
|
1327 | 1327 | public function import_json_file() { |
1328 | 1328 | |
1329 | 1329 | if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_import'], 'object_sync_for_salesforce_nonce_import' ) ) { |
@@ -1421,9 +1421,9 @@ discard block |
||
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | /** |
1424 | - * Create a json file for exporting |
|
1425 | - * |
|
1426 | - */ |
|
1424 | + * Create a json file for exporting |
|
1425 | + * |
|
1426 | + */ |
|
1427 | 1427 | public function export_json_file() { |
1428 | 1428 | |
1429 | 1429 | if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_export'], 'object_sync_for_salesforce_nonce_export' ) ) { |
@@ -1452,10 +1452,10 @@ discard block |
||
1452 | 1452 | } |
1453 | 1453 | |
1454 | 1454 | /** |
1455 | - * Default display for <input> fields |
|
1456 | - * |
|
1457 | - * @param array $args |
|
1458 | - */ |
|
1455 | + * Default display for <input> fields |
|
1456 | + * |
|
1457 | + * @param array $args |
|
1458 | + */ |
|
1459 | 1459 | public function display_input_field( $args ) { |
1460 | 1460 | $type = $args['type']; |
1461 | 1461 | $id = $args['label_for']; |
@@ -1502,11 +1502,11 @@ discard block |
||
1502 | 1502 | } |
1503 | 1503 | |
1504 | 1504 | /** |
1505 | - * Display for multiple checkboxes |
|
1506 | - * Above method can handle a single checkbox as it is |
|
1507 | - * |
|
1508 | - * @param array $args |
|
1509 | - */ |
|
1505 | + * Display for multiple checkboxes |
|
1506 | + * Above method can handle a single checkbox as it is |
|
1507 | + * |
|
1508 | + * @param array $args |
|
1509 | + */ |
|
1510 | 1510 | public function display_checkboxes( $args ) { |
1511 | 1511 | $type = 'checkbox'; |
1512 | 1512 | $name = $args['name']; |
@@ -1540,10 +1540,10 @@ discard block |
||
1540 | 1540 | } |
1541 | 1541 | |
1542 | 1542 | /** |
1543 | - * Display for a dropdown |
|
1544 | - * |
|
1545 | - * @param array $args |
|
1546 | - */ |
|
1543 | + * Display for a dropdown |
|
1544 | + * |
|
1545 | + * @param array $args |
|
1546 | + */ |
|
1547 | 1547 | public function display_select( $args ) { |
1548 | 1548 | $type = $args['type']; |
1549 | 1549 | $id = $args['label_for']; |
@@ -1587,10 +1587,10 @@ discard block |
||
1587 | 1587 | } |
1588 | 1588 | |
1589 | 1589 | /** |
1590 | - * Dropdown formatted list of Salesforce API versions |
|
1591 | - * |
|
1592 | - * @return array $args |
|
1593 | - */ |
|
1590 | + * Dropdown formatted list of Salesforce API versions |
|
1591 | + * |
|
1592 | + * @return array $args |
|
1593 | + */ |
|
1594 | 1594 | private function version_options() { |
1595 | 1595 | $versions = $this->salesforce['sfapi']->get_api_versions(); |
1596 | 1596 | $args = array(); |
@@ -1604,10 +1604,10 @@ discard block |
||
1604 | 1604 | } |
1605 | 1605 | |
1606 | 1606 | /** |
1607 | - * Default display for <a href> links |
|
1608 | - * |
|
1609 | - * @param array $args |
|
1610 | - */ |
|
1607 | + * Default display for <a href> links |
|
1608 | + * |
|
1609 | + * @param array $args |
|
1610 | + */ |
|
1611 | 1611 | public function display_link( $args ) { |
1612 | 1612 | $label = $args['label']; |
1613 | 1613 | $desc = $args['desc']; |
@@ -1634,10 +1634,10 @@ discard block |
||
1634 | 1634 | } |
1635 | 1635 | |
1636 | 1636 | /** |
1637 | - * Run a demo of Salesforce API call on the authenticate tab after WordPress has authenticated with it |
|
1638 | - * |
|
1639 | - * @param object $sfapi |
|
1640 | - */ |
|
1637 | + * Run a demo of Salesforce API call on the authenticate tab after WordPress has authenticated with it |
|
1638 | + * |
|
1639 | + * @param object $sfapi |
|
1640 | + */ |
|
1641 | 1641 | private function status( $sfapi ) { |
1642 | 1642 | |
1643 | 1643 | $versions = $sfapi->get_api_versions(); |
@@ -1696,10 +1696,10 @@ discard block |
||
1696 | 1696 | } |
1697 | 1697 | |
1698 | 1698 | /** |
1699 | - * Deauthorize WordPress from Salesforce. |
|
1700 | - * This deletes the tokens from the database; it does not currently do anything in Salesforce |
|
1701 | - * For this plugin at this time, that is the decision we are making: don't do any kind of authorization stuff inside Salesforce |
|
1702 | - */ |
|
1699 | + * Deauthorize WordPress from Salesforce. |
|
1700 | + * This deletes the tokens from the database; it does not currently do anything in Salesforce |
|
1701 | + * For this plugin at this time, that is the decision we are making: don't do any kind of authorization stuff inside Salesforce |
|
1702 | + */ |
|
1703 | 1703 | private function logout() { |
1704 | 1704 | $this->access_token = delete_option( $this->option_prefix . 'access_token' ); |
1705 | 1705 | $this->instance_url = delete_option( $this->option_prefix . 'instance_url' ); |
@@ -1711,8 +1711,8 @@ discard block |
||
1711 | 1711 | } |
1712 | 1712 | |
1713 | 1713 | /** |
1714 | - * Ajax call to clear the plugin cache. |
|
1715 | - */ |
|
1714 | + * Ajax call to clear the plugin cache. |
|
1715 | + */ |
|
1716 | 1716 | public function clear_sfwp_cache() { |
1717 | 1717 | $result = $this->clear_cache( true ); |
1718 | 1718 | $response = array( |
@@ -1723,9 +1723,9 @@ discard block |
||
1723 | 1723 | } |
1724 | 1724 | |
1725 | 1725 | /** |
1726 | - * Clear the plugin's cache. |
|
1727 | - * This uses the flush method contained in the WordPress cache to clear all of this plugin's cached data. |
|
1728 | - */ |
|
1726 | + * Clear the plugin's cache. |
|
1727 | + * This uses the flush method contained in the WordPress cache to clear all of this plugin's cached data. |
|
1728 | + */ |
|
1729 | 1729 | private function clear_cache( $ajax = false ) { |
1730 | 1730 | $result = (bool) $this->wordpress->sfwp_transients->flush(); |
1731 | 1731 | if ( true === $result ) { |
@@ -1745,9 +1745,9 @@ discard block |
||
1745 | 1745 | } |
1746 | 1746 | |
1747 | 1747 | /** |
1748 | - * Check WordPress Admin permissions |
|
1749 | - * Check if the current user is allowed to access the Salesforce plugin options |
|
1750 | - */ |
|
1748 | + * Check WordPress Admin permissions |
|
1749 | + * Check if the current user is allowed to access the Salesforce plugin options |
|
1750 | + */ |
|
1751 | 1751 | private function check_wordpress_admin_permissions() { |
1752 | 1752 | |
1753 | 1753 | // one programmatic way to give this capability to additional user roles is the |
@@ -1767,10 +1767,10 @@ discard block |
||
1767 | 1767 | } |
1768 | 1768 | |
1769 | 1769 | /** |
1770 | - * Show what we know about this user's relationship to a Salesforce object, if any |
|
1771 | - * @param object $user |
|
1772 | - * |
|
1773 | - */ |
|
1770 | + * Show what we know about this user's relationship to a Salesforce object, if any |
|
1771 | + * @param object $user |
|
1772 | + * |
|
1773 | + */ |
|
1774 | 1774 | public function show_salesforce_user_fields( $user ) { |
1775 | 1775 | $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
1776 | 1776 | if ( true === $this->check_wordpress_admin_permissions() ) { |
@@ -1794,10 +1794,10 @@ discard block |
||
1794 | 1794 | } |
1795 | 1795 | |
1796 | 1796 | /** |
1797 | - * If the user profile has been mapped to Salesforce, do it |
|
1798 | - * @param int $user_id |
|
1799 | - * |
|
1800 | - */ |
|
1797 | + * If the user profile has been mapped to Salesforce, do it |
|
1798 | + * @param int $user_id |
|
1799 | + * |
|
1800 | + */ |
|
1801 | 1801 | public function save_salesforce_user_fields( $user_id ) { |
1802 | 1802 | $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
1803 | 1803 | if ( isset( $post_data['salesforce_update_mapped_user'] ) && '1' === rawurlencode( $post_data['salesforce_update_mapped_user'] ) ) { |
@@ -1822,10 +1822,10 @@ discard block |
||
1822 | 1822 | } |
1823 | 1823 | |
1824 | 1824 | /** |
1825 | - * Render tabs for settings pages in admin |
|
1826 | - * @param array $tabs |
|
1827 | - * @param string $tab |
|
1828 | - */ |
|
1825 | + * Render tabs for settings pages in admin |
|
1826 | + * @param array $tabs |
|
1827 | + * @param string $tab |
|
1828 | + */ |
|
1829 | 1829 | private function tabs( $tabs, $tab = '' ) { |
1830 | 1830 | |
1831 | 1831 | $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
@@ -1855,9 +1855,9 @@ discard block |
||
1855 | 1855 | } |
1856 | 1856 | |
1857 | 1857 | /** |
1858 | - * Clear schedule |
|
1859 | - * This clears the schedule if the user clicks the button |
|
1860 | - */ |
|
1858 | + * Clear schedule |
|
1859 | + * This clears the schedule if the user clicks the button |
|
1860 | + */ |
|
1861 | 1861 | private function clear_schedule( $schedule_name = '' ) { |
1862 | 1862 | if ( '' !== $schedule_name ) { |
1863 | 1863 | $schedule = $this->schedule( $schedule_name ); |
@@ -1879,8 +1879,8 @@ discard block |
||
1879 | 1879 | } |
1880 | 1880 | |
1881 | 1881 | /** |
1882 | - * Load the schedule class |
|
1883 | - */ |
|
1882 | + * Load the schedule class |
|
1883 | + */ |
|
1884 | 1884 | private function schedule( $schedule_name ) { |
1885 | 1885 | if ( ! class_exists( 'Object_Sync_Sf_Schedule' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) { |
1886 | 1886 | require_once plugin_dir_path( __FILE__ ) . '../vendor/autoload.php'; |
@@ -1892,21 +1892,21 @@ discard block |
||
1892 | 1892 | } |
1893 | 1893 | |
1894 | 1894 | /** |
1895 | - * Create an object map between a WordPress object and a Salesforce object |
|
1896 | - * |
|
1897 | - * @param int $wordpress_id |
|
1898 | - * Unique identifier for the WordPress object |
|
1899 | - * @param string $wordpress_object |
|
1900 | - * What kind of object is it? |
|
1901 | - * @param string $salesforce_id |
|
1902 | - * Unique identifier for the Salesforce object |
|
1903 | - * @param string $action |
|
1904 | - * Did we push or pull? |
|
1905 | - * |
|
1906 | - * @return int $wpdb->insert_id |
|
1907 | - * This is the database row for the map object |
|
1908 | - * |
|
1909 | - */ |
|
1895 | + * Create an object map between a WordPress object and a Salesforce object |
|
1896 | + * |
|
1897 | + * @param int $wordpress_id |
|
1898 | + * Unique identifier for the WordPress object |
|
1899 | + * @param string $wordpress_object |
|
1900 | + * What kind of object is it? |
|
1901 | + * @param string $salesforce_id |
|
1902 | + * Unique identifier for the Salesforce object |
|
1903 | + * @param string $action |
|
1904 | + * Did we push or pull? |
|
1905 | + * |
|
1906 | + * @return int $wpdb->insert_id |
|
1907 | + * This is the database row for the map object |
|
1908 | + * |
|
1909 | + */ |
|
1910 | 1910 | private function create_object_map( $wordpress_id, $wordpress_object, $salesforce_id, $action = '' ) { |
1911 | 1911 | // Create object map and save it |
1912 | 1912 | $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 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param array $schedulable_classes |
83 | 83 | * @throws \Exception |
84 | 84 | */ |
85 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes ) { |
|
85 | + public function __construct($wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes) { |
|
86 | 86 | $this->wpdb = $wpdb; |
87 | 87 | $this->version = $version; |
88 | 88 | $this->login_credentials = $login_credentials; |
@@ -121,29 +121,29 @@ discard block |
||
121 | 121 | * |
122 | 122 | */ |
123 | 123 | public function add_actions() { |
124 | - add_action( 'admin_init', array( $this, 'salesforce_settings_forms' ) ); |
|
125 | - add_action( 'admin_init', array( $this, 'notices' ) ); |
|
126 | - add_action( 'admin_post_post_fieldmap', array( $this, 'prepare_fieldmap_data' ) ); |
|
127 | - |
|
128 | - add_action( 'admin_post_delete_fieldmap', array( $this, 'delete_fieldmap' ) ); |
|
129 | - add_action( 'wp_ajax_get_salesforce_object_description', array( $this, 'get_salesforce_object_description' ) ); |
|
130 | - add_action( 'wp_ajax_get_wordpress_object_description', array( $this, 'get_wordpress_object_fields' ) ); |
|
131 | - add_action( 'wp_ajax_get_wp_sf_object_fields', array( $this, 'get_wp_sf_object_fields' ) ); |
|
132 | - add_action( 'wp_ajax_push_to_salesforce', array( $this, 'push_to_salesforce' ) ); |
|
133 | - add_action( 'wp_ajax_pull_from_salesforce', array( $this, 'pull_from_salesforce' ) ); |
|
134 | - add_action( 'wp_ajax_refresh_mapped_data', array( $this, 'refresh_mapped_data' ) ); |
|
135 | - add_action( 'wp_ajax_clear_sfwp_cache', array( $this, 'clear_sfwp_cache' ) ); |
|
136 | - |
|
137 | - add_action( 'edit_user_profile', array( $this, 'show_salesforce_user_fields' ) ); |
|
138 | - add_action( 'personal_options_update', array( $this, 'save_salesforce_user_fields' ) ); |
|
139 | - add_action( 'edit_user_profile_update', array( $this, 'save_salesforce_user_fields' ) ); |
|
140 | - |
|
141 | - add_action( 'admin_post_delete_object_map', array( $this, 'delete_object_map' ) ); |
|
142 | - add_action( 'admin_post_post_object_map', array( $this, 'prepare_object_map_data' ) ); |
|
124 | + add_action('admin_init', array($this, 'salesforce_settings_forms')); |
|
125 | + add_action('admin_init', array($this, 'notices')); |
|
126 | + add_action('admin_post_post_fieldmap', array($this, 'prepare_fieldmap_data')); |
|
127 | + |
|
128 | + add_action('admin_post_delete_fieldmap', array($this, 'delete_fieldmap')); |
|
129 | + add_action('wp_ajax_get_salesforce_object_description', array($this, 'get_salesforce_object_description')); |
|
130 | + add_action('wp_ajax_get_wordpress_object_description', array($this, 'get_wordpress_object_fields')); |
|
131 | + add_action('wp_ajax_get_wp_sf_object_fields', array($this, 'get_wp_sf_object_fields')); |
|
132 | + add_action('wp_ajax_push_to_salesforce', array($this, 'push_to_salesforce')); |
|
133 | + add_action('wp_ajax_pull_from_salesforce', array($this, 'pull_from_salesforce')); |
|
134 | + add_action('wp_ajax_refresh_mapped_data', array($this, 'refresh_mapped_data')); |
|
135 | + add_action('wp_ajax_clear_sfwp_cache', array($this, 'clear_sfwp_cache')); |
|
136 | + |
|
137 | + add_action('edit_user_profile', array($this, 'show_salesforce_user_fields')); |
|
138 | + add_action('personal_options_update', array($this, 'save_salesforce_user_fields')); |
|
139 | + add_action('edit_user_profile_update', array($this, 'save_salesforce_user_fields')); |
|
140 | + |
|
141 | + add_action('admin_post_delete_object_map', array($this, 'delete_object_map')); |
|
142 | + add_action('admin_post_post_object_map', array($this, 'prepare_object_map_data')); |
|
143 | 143 | |
144 | 144 | // import and export plugin data |
145 | - add_action( 'admin_post_object_sync_for_salesforce_import', array( $this, 'import_json_file' ) ); |
|
146 | - add_action( 'admin_post_object_sync_for_salesforce_export', array( $this, 'export_json_file' ) ); |
|
145 | + add_action('admin_post_object_sync_for_salesforce_import', array($this, 'import_json_file')); |
|
146 | + add_action('admin_post_object_sync_for_salesforce_export', array($this, 'export_json_file')); |
|
147 | 147 | |
148 | 148 | } |
149 | 149 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | * |
153 | 153 | */ |
154 | 154 | public function create_admin_menu() { |
155 | - $title = __( 'Salesforce', 'object-sync-for-salesforce' ); |
|
156 | - add_options_page( $title, $title, 'configure_salesforce', 'object-sync-salesforce-admin', array( $this, 'show_admin_page' ) ); |
|
155 | + $title = __('Salesforce', 'object-sync-for-salesforce'); |
|
156 | + add_options_page($title, $title, 'configure_salesforce', 'object-sync-salesforce-admin', array($this, 'show_admin_page')); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,114 +164,114 @@ discard block |
||
164 | 164 | * |
165 | 165 | */ |
166 | 166 | public function show_admin_page() { |
167 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
167 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
168 | 168 | echo '<div class="wrap">'; |
169 | - echo '<h1>' . esc_html( get_admin_page_title() ) . '</h1>'; |
|
169 | + echo '<h1>' . esc_html(get_admin_page_title()) . '</h1>'; |
|
170 | 170 | $allowed = $this->check_wordpress_admin_permissions(); |
171 | - if ( false === $allowed ) { |
|
171 | + if (false === $allowed) { |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | $tabs = array( |
175 | - 'settings' => __( 'Settings', 'object-sync-for-salesforce' ), |
|
176 | - 'authorize' => __( 'Authorize', 'object-sync-for-salesforce' ), |
|
177 | - 'fieldmaps' => __( 'Fieldmaps', 'object-sync-for-salesforce' ), |
|
178 | - 'schedule' => __( 'Scheduling', 'object-sync-for-salesforce' ), |
|
179 | - 'import-export' => __( 'Import & Export', 'object-sync-for-salesforce' ), |
|
175 | + 'settings' => __('Settings', 'object-sync-for-salesforce'), |
|
176 | + 'authorize' => __('Authorize', 'object-sync-for-salesforce'), |
|
177 | + 'fieldmaps' => __('Fieldmaps', 'object-sync-for-salesforce'), |
|
178 | + 'schedule' => __('Scheduling', 'object-sync-for-salesforce'), |
|
179 | + 'import-export' => __('Import & Export', 'object-sync-for-salesforce'), |
|
180 | 180 | ); // this creates the tabs for the admin |
181 | 181 | |
182 | 182 | // optionally make tab(s) for logging and log settings |
183 | - $logging_enabled = get_option( $this->option_prefix . 'enable_logging', false ); |
|
184 | - $tabs['log_settings'] = __( 'Log Settings', 'object-sync-for-salesforce' ); |
|
183 | + $logging_enabled = get_option($this->option_prefix . 'enable_logging', false); |
|
184 | + $tabs['log_settings'] = __('Log Settings', 'object-sync-for-salesforce'); |
|
185 | 185 | |
186 | 186 | $mapping_errors = $this->mappings->get_failed_object_maps(); |
187 | - if ( ! empty( $mapping_errors ) ) { |
|
188 | - $tabs['mapping_errors'] = __( 'Mapping Errors', 'object-sync-for-salesforce' ); |
|
187 | + if ( ! empty($mapping_errors)) { |
|
188 | + $tabs['mapping_errors'] = __('Mapping Errors', 'object-sync-for-salesforce'); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | // filter for extending the tabs available on the page |
192 | 192 | // currently it will go into the default switch case for $tab |
193 | - $tabs = apply_filters( 'object_sync_for_salesforce_settings_tabs', $tabs ); |
|
193 | + $tabs = apply_filters('object_sync_for_salesforce_settings_tabs', $tabs); |
|
194 | 194 | |
195 | - $tab = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
196 | - $this->tabs( $tabs, $tab ); |
|
195 | + $tab = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
196 | + $this->tabs($tabs, $tab); |
|
197 | 197 | |
198 | 198 | $consumer_key = $this->login_credentials['consumer_key']; |
199 | 199 | $consumer_secret = $this->login_credentials['consumer_secret']; |
200 | 200 | $callback_url = $this->login_credentials['callback_url']; |
201 | 201 | |
202 | - if ( true !== $this->salesforce['is_authorized'] ) { |
|
203 | - $url = esc_url( $callback_url ); |
|
204 | - $anchor = esc_html__( 'Authorize tab', 'object-sync-for-salesforce' ); |
|
205 | - $message = sprintf( 'Salesforce needs to be authorized to connect to this website. Use the <a href="%s">%s</a> to connect.', $url, $anchor ); |
|
206 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
202 | + if (true !== $this->salesforce['is_authorized']) { |
|
203 | + $url = esc_url($callback_url); |
|
204 | + $anchor = esc_html__('Authorize tab', 'object-sync-for-salesforce'); |
|
205 | + $message = sprintf('Salesforce needs to be authorized to connect to this website. Use the <a href="%s">%s</a> to connect.', $url, $anchor); |
|
206 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( 0 === count( $this->mappings->get_fieldmaps() ) ) { |
|
210 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps' ) ); |
|
211 | - $anchor = esc_html__( 'Fieldmaps tab', 'object-sync-for-salesforce' ); |
|
212 | - $message = sprintf( 'No fieldmaps exist yet. Use the <a href="%s">%s</a> to map WordPress and Salesforce objects to each other.', $url, $anchor ); |
|
213 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
209 | + if (0 === count($this->mappings->get_fieldmaps())) { |
|
210 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps')); |
|
211 | + $anchor = esc_html__('Fieldmaps tab', 'object-sync-for-salesforce'); |
|
212 | + $message = sprintf('No fieldmaps exist yet. Use the <a href="%s">%s</a> to map WordPress and Salesforce objects to each other.', $url, $anchor); |
|
213 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
214 | 214 | } |
215 | 215 | |
216 | - $push_schedule_number = get_option( $this->option_prefix . 'salesforce_push_schedule_number', '' ); |
|
217 | - $push_schedule_unit = get_option( $this->option_prefix . 'salesforce_push_schedule_unit', '' ); |
|
218 | - $pull_schedule_number = get_option( $this->option_prefix . 'salesforce_pull_schedule_number', '' ); |
|
219 | - $pull_schedule_unit = get_option( $this->option_prefix . 'salesforce_pull_schedule_unit', '' ); |
|
216 | + $push_schedule_number = get_option($this->option_prefix . 'salesforce_push_schedule_number', ''); |
|
217 | + $push_schedule_unit = get_option($this->option_prefix . 'salesforce_push_schedule_unit', ''); |
|
218 | + $pull_schedule_number = get_option($this->option_prefix . 'salesforce_pull_schedule_number', ''); |
|
219 | + $pull_schedule_unit = get_option($this->option_prefix . 'salesforce_pull_schedule_unit', ''); |
|
220 | 220 | |
221 | - if ( '' === $push_schedule_number && '' === $push_schedule_unit && '' === $pull_schedule_number && '' === $pull_schedule_unit ) { |
|
222 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=schedule' ) ); |
|
223 | - $anchor = esc_html__( 'Scheduling tab', 'object-sync-for-salesforce' ); |
|
224 | - $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 ); |
|
225 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
221 | + if ('' === $push_schedule_number && '' === $push_schedule_unit && '' === $pull_schedule_number && '' === $pull_schedule_unit) { |
|
222 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=schedule')); |
|
223 | + $anchor = esc_html__('Scheduling tab', 'object-sync-for-salesforce'); |
|
224 | + $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); |
|
225 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | try { |
229 | - switch ( $tab ) { |
|
229 | + switch ($tab) { |
|
230 | 230 | case 'authorize': |
231 | - if ( isset( $get_data['code'] ) ) { |
|
231 | + if (isset($get_data['code'])) { |
|
232 | 232 | // this string is an oauth token |
233 | - $data = esc_html( wp_unslash( $get_data['code'] ) ); |
|
234 | - $is_authorized = $this->salesforce['sfapi']->request_token( $data ); |
|
233 | + $data = esc_html(wp_unslash($get_data['code'])); |
|
234 | + $is_authorized = $this->salesforce['sfapi']->request_token($data); |
|
235 | 235 | ?> |
236 | - <script>window.location = '<?php echo esc_url_raw( $callback_url ); ?>'</script> |
|
236 | + <script>window.location = '<?php echo esc_url_raw($callback_url); ?>'</script> |
|
237 | 237 | <?php |
238 | - } elseif ( true === $this->salesforce['is_authorized'] ) { |
|
239 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/authorized.php' ); |
|
240 | - $this->status( $this->salesforce['sfapi'] ); |
|
241 | - } elseif ( true === is_object( $this->salesforce['sfapi'] ) && isset( $consumer_key ) && isset( $consumer_secret ) ) { |
|
238 | + } elseif (true === $this->salesforce['is_authorized']) { |
|
239 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/authorized.php'); |
|
240 | + $this->status($this->salesforce['sfapi']); |
|
241 | + } elseif (true === is_object($this->salesforce['sfapi']) && isset($consumer_key) && isset($consumer_secret)) { |
|
242 | 242 | ?> |
243 | - <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> |
|
243 | + <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> |
|
244 | 244 | <?php |
245 | 245 | } else { |
246 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=settings' ) ); |
|
247 | - $anchor = esc_html__( 'Settings', 'object-sync-for-salesforce' ); |
|
246 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=settings')); |
|
247 | + $anchor = esc_html__('Settings', 'object-sync-for-salesforce'); |
|
248 | 248 | // translators: placeholders are for the settings tab link: 1) the url, and 2) the anchor text |
249 | - $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 ); |
|
250 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
249 | + $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); |
|
250 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
251 | 251 | } |
252 | 252 | break; |
253 | 253 | case 'fieldmaps': |
254 | - if ( isset( $get_data['method'] ) ) { |
|
254 | + if (isset($get_data['method'])) { |
|
255 | 255 | |
256 | - $method = sanitize_key( $get_data['method'] ); |
|
257 | - $error_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps&method=' . $method ); |
|
258 | - $success_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps' ); |
|
256 | + $method = sanitize_key($get_data['method']); |
|
257 | + $error_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps&method=' . $method); |
|
258 | + $success_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps'); |
|
259 | 259 | |
260 | - if ( isset( $get_data['transient'] ) ) { |
|
261 | - $transient = sanitize_key( $get_data['transient'] ); |
|
262 | - $posted = $this->sfwp_transients->get( $transient ); |
|
260 | + if (isset($get_data['transient'])) { |
|
261 | + $transient = sanitize_key($get_data['transient']); |
|
262 | + $posted = $this->sfwp_transients->get($transient); |
|
263 | 263 | } |
264 | 264 | |
265 | - if ( isset( $posted ) && is_array( $posted ) ) { |
|
265 | + if (isset($posted) && is_array($posted)) { |
|
266 | 266 | $map = $posted; |
267 | - } elseif ( 'edit' === $method || 'clone' === $method || 'delete' === $method ) { |
|
268 | - $map = $this->mappings->get_fieldmaps( isset( $get_data['id'] ) ? sanitize_key( $get_data['id'] ) : '' ); |
|
267 | + } elseif ('edit' === $method || 'clone' === $method || 'delete' === $method) { |
|
268 | + $map = $this->mappings->get_fieldmaps(isset($get_data['id']) ? sanitize_key($get_data['id']) : ''); |
|
269 | 269 | } |
270 | 270 | |
271 | - if ( isset( $map ) && is_array( $map ) ) { |
|
271 | + if (isset($map) && is_array($map)) { |
|
272 | 272 | $label = $map['label']; |
273 | 273 | $salesforce_object = $map['salesforce_object']; |
274 | - $salesforce_record_types_allowed = maybe_unserialize( $map['salesforce_record_types_allowed'] ); |
|
274 | + $salesforce_record_types_allowed = maybe_unserialize($map['salesforce_record_types_allowed']); |
|
275 | 275 | $salesforce_record_type_default = $map['salesforce_record_type_default']; |
276 | 276 | $wordpress_object = $map['wordpress_object']; |
277 | 277 | $pull_trigger_field = $map['pull_trigger_field']; |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | $weight = $map['weight']; |
283 | 283 | } |
284 | 284 | |
285 | - if ( 'add' === $method || 'edit' === $method || 'clone' === $method ) { |
|
286 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-add-edit-clone.php' ); |
|
287 | - } elseif ( 'delete' === $method ) { |
|
288 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-delete.php' ); |
|
285 | + if ('add' === $method || 'edit' === $method || 'clone' === $method) { |
|
286 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-add-edit-clone.php'); |
|
287 | + } elseif ('delete' === $method) { |
|
288 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-delete.php'); |
|
289 | 289 | } |
290 | 290 | } else { |
291 | 291 | $fieldmaps = $this->mappings->get_fieldmaps(); |
292 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-list.php' ); |
|
292 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-list.php'); |
|
293 | 293 | } // End if(). |
294 | 294 | break; |
295 | 295 | case 'logout': |
@@ -299,73 +299,73 @@ discard block |
||
299 | 299 | $this->clear_cache(); |
300 | 300 | break; |
301 | 301 | case 'clear_schedule': |
302 | - if ( isset( $get_data['schedule_name'] ) ) { |
|
303 | - $schedule_name = sanitize_key( $get_data['schedule_name'] ); |
|
302 | + if (isset($get_data['schedule_name'])) { |
|
303 | + $schedule_name = sanitize_key($get_data['schedule_name']); |
|
304 | 304 | } |
305 | - $this->clear_schedule( $schedule_name ); |
|
305 | + $this->clear_schedule($schedule_name); |
|
306 | 306 | break; |
307 | 307 | case 'settings': |
308 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/settings.php' ); |
|
308 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/settings.php'); |
|
309 | 309 | break; |
310 | 310 | case 'mapping_errors': |
311 | - if ( isset( $get_data['method'] ) ) { |
|
311 | + if (isset($get_data['method'])) { |
|
312 | 312 | |
313 | - $method = sanitize_key( $get_data['method'] ); |
|
314 | - $error_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors&method=' . $method ); |
|
315 | - $success_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors' ); |
|
313 | + $method = sanitize_key($get_data['method']); |
|
314 | + $error_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors&method=' . $method); |
|
315 | + $success_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors'); |
|
316 | 316 | |
317 | - if ( isset( $get_data['map_transient'] ) ) { |
|
318 | - $transient = sanitize_key( $get_data['map_transient'] ); |
|
319 | - $posted = $this->sfwp_transients->get( $transient ); |
|
317 | + if (isset($get_data['map_transient'])) { |
|
318 | + $transient = sanitize_key($get_data['map_transient']); |
|
319 | + $posted = $this->sfwp_transients->get($transient); |
|
320 | 320 | } |
321 | 321 | |
322 | - if ( isset( $posted ) && is_array( $posted ) ) { |
|
322 | + if (isset($posted) && is_array($posted)) { |
|
323 | 323 | $map_row = $posted; |
324 | - } elseif ( 'edit' === $method || 'delete' === $method ) { |
|
325 | - $map_row = $this->mappings->get_failed_object_map( isset( $get_data['id'] ) ? sanitize_key( $get_data['id'] ) : '' ); |
|
324 | + } elseif ('edit' === $method || 'delete' === $method) { |
|
325 | + $map_row = $this->mappings->get_failed_object_map(isset($get_data['id']) ? sanitize_key($get_data['id']) : ''); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $map_row ) && is_array( $map_row ) ) { |
|
328 | + if (isset($map_row) && is_array($map_row)) { |
|
329 | 329 | $salesforce_id = $map_row['salesforce_id']; |
330 | 330 | $wordpress_id = $map_row['wordpress_id']; |
331 | 331 | } |
332 | 332 | |
333 | - if ( 'edit' === $method ) { |
|
334 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors-edit.php' ); |
|
335 | - } elseif ( 'delete' === $method ) { |
|
336 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors-delete.php' ); |
|
333 | + if ('edit' === $method) { |
|
334 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors-edit.php'); |
|
335 | + } elseif ('delete' === $method) { |
|
336 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors-delete.php'); |
|
337 | 337 | } |
338 | 338 | } else { |
339 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors.php' ); |
|
339 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors.php'); |
|
340 | 340 | } |
341 | 341 | break; |
342 | 342 | case 'import-export': |
343 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/import-export.php' ); |
|
343 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/import-export.php'); |
|
344 | 344 | break; |
345 | 345 | default: |
346 | - $include_settings = apply_filters( 'object_sync_for_salesforce_settings_tab_include_settings', true, $tab ); |
|
347 | - $content_before = apply_filters( 'object_sync_for_salesforce_settings_tab_content_before', null, $tab ); |
|
348 | - $content_after = apply_filters( 'object_sync_for_salesforce_settings_tab_content_after', null, $tab ); |
|
349 | - if ( null !== $content_before ) { |
|
350 | - echo esc_html( $content_before ); |
|
346 | + $include_settings = apply_filters('object_sync_for_salesforce_settings_tab_include_settings', true, $tab); |
|
347 | + $content_before = apply_filters('object_sync_for_salesforce_settings_tab_content_before', null, $tab); |
|
348 | + $content_after = apply_filters('object_sync_for_salesforce_settings_tab_content_after', null, $tab); |
|
349 | + if (null !== $content_before) { |
|
350 | + echo esc_html($content_before); |
|
351 | 351 | } |
352 | - if ( true === $include_settings ) { |
|
353 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/settings.php' ); |
|
352 | + if (true === $include_settings) { |
|
353 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/settings.php'); |
|
354 | 354 | } |
355 | - if ( null !== $content_after ) { |
|
356 | - echo esc_html( $content_after ); |
|
355 | + if (null !== $content_after) { |
|
356 | + echo esc_html($content_after); |
|
357 | 357 | } |
358 | 358 | break; |
359 | 359 | } // End switch(). |
360 | - } catch ( SalesforceApiException $ex ) { |
|
361 | - echo sprintf( '<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
362 | - absint( $ex->getCode() ), |
|
363 | - esc_html( $ex->getMessage() ) |
|
360 | + } catch (SalesforceApiException $ex) { |
|
361 | + echo sprintf('<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
362 | + absint($ex->getCode()), |
|
363 | + esc_html($ex->getMessage()) |
|
364 | 364 | ); |
365 | - } catch ( Exception $ex ) { |
|
366 | - echo sprintf( '<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
367 | - absint( $ex->getCode() ), |
|
368 | - esc_html( $ex->getMessage() ) |
|
365 | + } catch (Exception $ex) { |
|
366 | + echo sprintf('<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
367 | + absint($ex->getCode()), |
|
368 | + esc_html($ex->getMessage()) |
|
369 | 369 | ); |
370 | 370 | } // End try(). |
371 | 371 | echo '</div>'; |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | * |
378 | 378 | */ |
379 | 379 | public function salesforce_settings_forms() { |
380 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
381 | - $page = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
382 | - $section = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
380 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
381 | + $page = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
382 | + $section = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
383 | 383 | |
384 | - $input_callback_default = array( $this, 'display_input_field' ); |
|
385 | - $input_checkboxes_default = array( $this, 'display_checkboxes' ); |
|
386 | - $input_select_default = array( $this, 'display_select' ); |
|
387 | - $link_default = array( $this, 'display_link' ); |
|
384 | + $input_callback_default = array($this, 'display_input_field'); |
|
385 | + $input_checkboxes_default = array($this, 'display_checkboxes'); |
|
386 | + $input_select_default = array($this, 'display_select'); |
|
387 | + $link_default = array($this, 'display_link'); |
|
388 | 388 | |
389 | 389 | $all_field_callbacks = array( |
390 | 390 | 'text' => $input_callback_default, |
@@ -393,10 +393,10 @@ discard block |
||
393 | 393 | 'link' => $link_default, |
394 | 394 | ); |
395 | 395 | |
396 | - $this->fields_settings( 'settings', 'settings', $all_field_callbacks ); |
|
397 | - $this->fields_fieldmaps( 'fieldmaps', 'objects' ); |
|
398 | - $this->fields_scheduling( 'schedule', 'schedule', $all_field_callbacks ); |
|
399 | - $this->fields_log_settings( 'log_settings', 'log_settings', $all_field_callbacks ); |
|
396 | + $this->fields_settings('settings', 'settings', $all_field_callbacks); |
|
397 | + $this->fields_fieldmaps('fieldmaps', 'objects'); |
|
398 | + $this->fields_scheduling('schedule', 'schedule', $all_field_callbacks); |
|
399 | + $this->fields_log_settings('log_settings', 'log_settings', $all_field_callbacks); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -407,11 +407,11 @@ discard block |
||
407 | 407 | * @param string $section |
408 | 408 | * @param string $input_callback |
409 | 409 | */ |
410 | - private function fields_settings( $page, $section, $callbacks ) { |
|
411 | - add_settings_section( $page, ucwords( $page ), null, $page ); |
|
410 | + private function fields_settings($page, $section, $callbacks) { |
|
411 | + add_settings_section($page, ucwords($page), null, $page); |
|
412 | 412 | $salesforce_settings = array( |
413 | 413 | 'consumer_key' => array( |
414 | - 'title' => __( 'Consumer Key', 'object-sync-for-salesforce' ), |
|
414 | + 'title' => __('Consumer Key', 'object-sync-for-salesforce'), |
|
415 | 415 | 'callback' => $callbacks['text'], |
416 | 416 | 'page' => $page, |
417 | 417 | 'section' => $section, |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | |
425 | 425 | ), |
426 | 426 | 'consumer_secret' => array( |
427 | - 'title' => __( 'Consumer Secret', 'object-sync-for-salesforce' ), |
|
427 | + 'title' => __('Consumer Secret', 'object-sync-for-salesforce'), |
|
428 | 428 | 'callback' => $callbacks['text'], |
429 | 429 | 'page' => $page, |
430 | 430 | 'section' => $section, |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | ), |
437 | 437 | ), |
438 | 438 | 'callback_url' => array( |
439 | - 'title' => __( 'Callback URL', 'object-sync-for-salesforce' ), |
|
439 | + 'title' => __('Callback URL', 'object-sync-for-salesforce'), |
|
440 | 440 | 'callback' => $callbacks['text'], |
441 | 441 | 'page' => $page, |
442 | 442 | 'section' => $section, |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | ), |
449 | 449 | ), |
450 | 450 | 'login_base_url' => array( |
451 | - 'title' => __( 'Login Base URL', 'object-sync-for-salesforce' ), |
|
451 | + 'title' => __('Login Base URL', 'object-sync-for-salesforce'), |
|
452 | 452 | 'callback' => $callbacks['text'], |
453 | 453 | 'page' => $page, |
454 | 454 | 'section' => $section, |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | 'type' => 'url', |
457 | 457 | 'validate' => 'sanitize_text_field', |
458 | 458 | // translators: 1) production salesforce login, 2) sandbox salesforce login |
459 | - 'desc' => sprintf( __( 'For most Salesforce setups, you should use %1$s for production and %2$s for sandbox.', 'object-sync-for-salesforce' ), |
|
460 | - esc_url( 'https://login.salesforce.com' ), |
|
461 | - esc_url( 'https://test.salesforce.com' ) |
|
459 | + 'desc' => sprintf(__('For most Salesforce setups, you should use %1$s for production and %2$s for sandbox.', 'object-sync-for-salesforce'), |
|
460 | + esc_url('https://login.salesforce.com'), |
|
461 | + esc_url('https://test.salesforce.com') |
|
462 | 462 | ), |
463 | 463 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL', |
464 | 464 | ), |
465 | 465 | ), |
466 | 466 | 'authorize_url_path' => array( |
467 | - 'title' => __( 'Authorize URL Path', 'object-sync-for-salesforce' ), |
|
467 | + 'title' => __('Authorize URL Path', 'object-sync-for-salesforce'), |
|
468 | 468 | 'callback' => $callbacks['text'], |
469 | 469 | 'page' => $page, |
470 | 470 | 'section' => $section, |
471 | 471 | 'args' => array( |
472 | 472 | 'type' => 'text', |
473 | 473 | 'validate' => 'sanitize_text_field', |
474 | - 'desc' => __( 'For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce' ), |
|
474 | + 'desc' => __('For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce'), |
|
475 | 475 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH', |
476 | 476 | 'default' => $this->default_authorize_url_path, |
477 | 477 | ), |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | 'args' => array( |
485 | 485 | 'type' => 'text', |
486 | 486 | 'validate' => 'sanitize_text_field', |
487 | - 'desc' => __( 'For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce' ), |
|
487 | + 'desc' => __('For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce'), |
|
488 | 488 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH', |
489 | 489 | 'default' => $this->default_token_url_path, |
490 | 490 | ), |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | 'args' => array( |
511 | 511 | 'type' => 'checkboxes', |
512 | 512 | 'validate' => 'sanitize_text_field', |
513 | - 'desc' => __( 'Allows you to limit which Salesforce objects can be mapped', 'object-sync-for-salesforce' ), |
|
513 | + 'desc' => __('Allows you to limit which Salesforce objects can be mapped', 'object-sync-for-salesforce'), |
|
514 | 514 | 'items' => array( |
515 | 515 | 'triggerable' => array( |
516 | 516 | 'text' => 'Only Triggerable objects', |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | 'args' => array( |
536 | 536 | 'type' => 'number', |
537 | 537 | 'validate' => 'sanitize_text_field', |
538 | - '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' ), |
|
538 | + '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'), |
|
539 | 539 | 'constant' => '', |
540 | 540 | 'default' => $this->default_pull_throttle, |
541 | 541 | ), |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | 'args' => array( |
549 | 549 | 'type' => 'checkbox', |
550 | 550 | 'validate' => 'sanitize_text_field', |
551 | - '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' ), |
|
551 | + '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'), |
|
552 | 552 | 'constant' => '', |
553 | 553 | ), |
554 | 554 | ), |
@@ -560,13 +560,13 @@ discard block |
||
560 | 560 | 'args' => array( |
561 | 561 | 'type' => 'checkbox', |
562 | 562 | 'validate' => 'sanitize_text_field', |
563 | - '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' ), |
|
563 | + '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'), |
|
564 | 564 | 'constant' => '', |
565 | 565 | ), |
566 | 566 | ), |
567 | 567 | ); |
568 | 568 | |
569 | - if ( true === is_object( $this->salesforce['sfapi'] ) && true === $this->salesforce['sfapi']->is_authorized() ) { |
|
569 | + if (true === is_object($this->salesforce['sfapi']) && true === $this->salesforce['sfapi']->is_authorized()) { |
|
570 | 570 | $salesforce_settings['api_version'] = array( |
571 | 571 | 'title' => 'Salesforce API Version', |
572 | 572 | 'callback' => $callbacks['select'], |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | ); |
583 | 583 | } |
584 | 584 | |
585 | - foreach ( $salesforce_settings as $key => $attributes ) { |
|
585 | + foreach ($salesforce_settings as $key => $attributes) { |
|
586 | 586 | $id = $this->option_prefix . $key; |
587 | 587 | $name = $this->option_prefix . $key; |
588 | 588 | $title = $attributes['title']; |
@@ -601,12 +601,12 @@ discard block |
||
601 | 601 | ); |
602 | 602 | |
603 | 603 | // if there is a constant and it is defined, don't run a validate function |
604 | - if ( isset( $attributes['args']['constant'] ) && defined( $attributes['args']['constant'] ) ) { |
|
604 | + if (isset($attributes['args']['constant']) && defined($attributes['args']['constant'])) { |
|
605 | 605 | $validate = ''; |
606 | 606 | } |
607 | 607 | |
608 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
609 | - register_setting( $page, $id, array( $this, $validate ) ); |
|
608 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
609 | + register_setting($page, $id, array($this, $validate)); |
|
610 | 610 | } |
611 | 611 | } |
612 | 612 | |
@@ -618,8 +618,8 @@ discard block |
||
618 | 618 | * @param string $section |
619 | 619 | * @param string $input_callback |
620 | 620 | */ |
621 | - private function fields_fieldmaps( $page, $section, $input_callback = '' ) { |
|
622 | - add_settings_section( $page, ucwords( $page ), null, $page ); |
|
621 | + private function fields_fieldmaps($page, $section, $input_callback = '') { |
|
622 | + add_settings_section($page, ucwords($page), null, $page); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
@@ -630,12 +630,12 @@ discard block |
||
630 | 630 | * @param string $section |
631 | 631 | * @param string $input_callback |
632 | 632 | */ |
633 | - private function fields_scheduling( $page, $section, $callbacks ) { |
|
634 | - foreach ( $this->schedulable_classes as $key => $value ) { |
|
635 | - add_settings_section( $key, $value['label'], null, $page ); |
|
633 | + private function fields_scheduling($page, $section, $callbacks) { |
|
634 | + foreach ($this->schedulable_classes as $key => $value) { |
|
635 | + add_settings_section($key, $value['label'], null, $page); |
|
636 | 636 | $schedule_settings = array( |
637 | 637 | $key . '_schedule_number' => array( |
638 | - 'title' => __( 'Run schedule every', 'object-sync-for-salesforce' ), |
|
638 | + 'title' => __('Run schedule every', 'object-sync-for-salesforce'), |
|
639 | 639 | 'callback' => $callbacks['text'], |
640 | 640 | 'page' => $page, |
641 | 641 | 'section' => $key, |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | ), |
648 | 648 | ), |
649 | 649 | $key . '_schedule_unit' => array( |
650 | - 'title' => __( 'Time unit', 'object-sync-for-salesforce' ), |
|
650 | + 'title' => __('Time unit', 'object-sync-for-salesforce'), |
|
651 | 651 | 'callback' => $callbacks['select'], |
652 | 652 | 'page' => $page, |
653 | 653 | 'section' => $key, |
@@ -673,19 +673,19 @@ discard block |
||
673 | 673 | ), |
674 | 674 | $key . '_clear_button' => array( |
675 | 675 | // translators: $this->get_schedule_count is an integer showing how many items are in the current queue |
676 | - 'title' => sprintf( 'This queue has ' . _n( '%s item', '%s items', $this->get_schedule_count( $key ), 'object-sync-for-salesforce' ), $this->get_schedule_count( $key ) ), |
|
676 | + 'title' => sprintf('This queue has ' . _n('%s item', '%s items', $this->get_schedule_count($key), 'object-sync-for-salesforce'), $this->get_schedule_count($key)), |
|
677 | 677 | 'callback' => $callbacks['link'], |
678 | 678 | 'page' => $page, |
679 | 679 | 'section' => $key, |
680 | 680 | 'args' => array( |
681 | 681 | 'label' => 'Clear this queue', |
682 | 682 | 'desc' => '', |
683 | - 'url' => esc_url( '?page=object-sync-salesforce-admin&tab=clear_schedule&schedule_name=' . $key ), |
|
683 | + 'url' => esc_url('?page=object-sync-salesforce-admin&tab=clear_schedule&schedule_name=' . $key), |
|
684 | 684 | 'link_class' => 'button button-secondary', |
685 | 685 | ), |
686 | 686 | ), |
687 | 687 | ); |
688 | - foreach ( $schedule_settings as $key => $attributes ) { |
|
688 | + foreach ($schedule_settings as $key => $attributes) { |
|
689 | 689 | $id = $this->option_prefix . $key; |
690 | 690 | $name = $this->option_prefix . $key; |
691 | 691 | $title = $attributes['title']; |
@@ -701,8 +701,8 @@ discard block |
||
701 | 701 | 'name' => $name, |
702 | 702 | ) |
703 | 703 | ); |
704 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
705 | - register_setting( $page, $id ); |
|
704 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
705 | + register_setting($page, $id); |
|
706 | 706 | } |
707 | 707 | } // End foreach(). |
708 | 708 | } |
@@ -715,11 +715,11 @@ discard block |
||
715 | 715 | * @param string $section |
716 | 716 | * @param array $callbacks |
717 | 717 | */ |
718 | - private function fields_log_settings( $page, $section, $callbacks ) { |
|
719 | - add_settings_section( $page, ucwords( str_replace( '_', ' ', $page ) ), null, $page ); |
|
718 | + private function fields_log_settings($page, $section, $callbacks) { |
|
719 | + add_settings_section($page, ucwords(str_replace('_', ' ', $page)), null, $page); |
|
720 | 720 | $log_settings = array( |
721 | 721 | 'enable_logging' => array( |
722 | - 'title' => __( 'Enable Logging?', 'object-sync-for-salesforce' ), |
|
722 | + 'title' => __('Enable Logging?', 'object-sync-for-salesforce'), |
|
723 | 723 | 'callback' => $callbacks['text'], |
724 | 724 | 'page' => $page, |
725 | 725 | 'section' => $section, |
@@ -731,32 +731,32 @@ discard block |
||
731 | 731 | ), |
732 | 732 | ), |
733 | 733 | 'statuses_to_log' => array( |
734 | - 'title' => __( 'Statuses to log', 'object-sync-for-salesforce' ), |
|
734 | + 'title' => __('Statuses to log', 'object-sync-for-salesforce'), |
|
735 | 735 | 'callback' => $callbacks['checkboxes'], |
736 | 736 | 'page' => $page, |
737 | 737 | 'section' => $section, |
738 | 738 | 'args' => array( |
739 | 739 | 'type' => 'checkboxes', |
740 | 740 | 'validate' => 'sanitize_text_field', |
741 | - 'desc' => __( 'these are the statuses to log', 'object-sync-for-salesforce' ), |
|
741 | + 'desc' => __('these are the statuses to log', 'object-sync-for-salesforce'), |
|
742 | 742 | 'items' => array( |
743 | 743 | 'error' => array( |
744 | - 'text' => __( 'Error', 'object-sync-for-salesforce' ), |
|
744 | + 'text' => __('Error', 'object-sync-for-salesforce'), |
|
745 | 745 | 'id' => 'error', |
746 | 746 | 'desc' => '', |
747 | 747 | ), |
748 | 748 | 'success' => array( |
749 | - 'text' => __( 'Success', 'object-sync-for-salesforce' ), |
|
749 | + 'text' => __('Success', 'object-sync-for-salesforce'), |
|
750 | 750 | 'id' => 'success', |
751 | 751 | 'desc' => '', |
752 | 752 | ), |
753 | 753 | 'notice' => array( |
754 | - 'text' => __( 'Notice', 'object-sync-for-salesforce' ), |
|
754 | + 'text' => __('Notice', 'object-sync-for-salesforce'), |
|
755 | 755 | 'id' => 'notice', |
756 | 756 | 'desc' => '', |
757 | 757 | ), |
758 | 758 | 'debug' => array( |
759 | - 'text' => __( 'Debug', 'object-sync-for-salesforce' ), |
|
759 | + 'text' => __('Debug', 'object-sync-for-salesforce'), |
|
760 | 760 | 'id' => 'debug', |
761 | 761 | 'desc' => '', |
762 | 762 | ), |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | ), |
765 | 765 | ), |
766 | 766 | 'prune_logs' => array( |
767 | - 'title' => __( 'Automatically delete old log entries?', 'object-sync-for-salesforce' ), |
|
767 | + 'title' => __('Automatically delete old log entries?', 'object-sync-for-salesforce'), |
|
768 | 768 | 'callback' => $callbacks['text'], |
769 | 769 | 'page' => $page, |
770 | 770 | 'section' => $section, |
@@ -776,20 +776,20 @@ discard block |
||
776 | 776 | ), |
777 | 777 | ), |
778 | 778 | 'logs_how_old' => array( |
779 | - 'title' => __( 'Age to delete log entries', 'object-sync-for-salesforce' ), |
|
779 | + 'title' => __('Age to delete log entries', 'object-sync-for-salesforce'), |
|
780 | 780 | 'callback' => $callbacks['text'], |
781 | 781 | 'page' => $page, |
782 | 782 | 'section' => $section, |
783 | 783 | 'args' => array( |
784 | 784 | 'type' => 'text', |
785 | 785 | 'validate' => 'sanitize_text_field', |
786 | - 'desc' => __( 'If automatic deleting is enabled, it will affect logs this old.', 'object-sync-for-salesforce' ), |
|
786 | + 'desc' => __('If automatic deleting is enabled, it will affect logs this old.', 'object-sync-for-salesforce'), |
|
787 | 787 | 'default' => '2 weeks', |
788 | 788 | 'constant' => '', |
789 | 789 | ), |
790 | 790 | ), |
791 | 791 | 'logs_how_often_number' => array( |
792 | - 'title' => __( 'Check for old logs every', 'object-sync-for-salesforce' ), |
|
792 | + 'title' => __('Check for old logs every', 'object-sync-for-salesforce'), |
|
793 | 793 | 'callback' => $callbacks['text'], |
794 | 794 | 'page' => $page, |
795 | 795 | 'section' => $section, |
@@ -802,67 +802,67 @@ discard block |
||
802 | 802 | ), |
803 | 803 | ), |
804 | 804 | 'logs_how_often_unit' => array( |
805 | - 'title' => __( 'Time unit', 'object-sync-for-salesforce' ), |
|
805 | + 'title' => __('Time unit', 'object-sync-for-salesforce'), |
|
806 | 806 | 'callback' => $callbacks['select'], |
807 | 807 | 'page' => $page, |
808 | 808 | 'section' => $section, |
809 | 809 | 'args' => array( |
810 | 810 | 'type' => 'select', |
811 | 811 | 'validate' => 'sanitize_text_field', |
812 | - 'desc' => __( 'These two fields are how often the site will check for logs to delete.', 'object-sync-for-salesforce' ), |
|
812 | + 'desc' => __('These two fields are how often the site will check for logs to delete.', 'object-sync-for-salesforce'), |
|
813 | 813 | 'items' => array( |
814 | 814 | 'minutes' => array( |
815 | - 'text' => __( 'Minutes', 'object-sync-for-salesforce' ), |
|
815 | + 'text' => __('Minutes', 'object-sync-for-salesforce'), |
|
816 | 816 | 'value' => 'minutes', |
817 | 817 | ), |
818 | 818 | 'hours' => array( |
819 | - 'text' => __( 'Hours', 'object-sync-for-salesforce' ), |
|
819 | + 'text' => __('Hours', 'object-sync-for-salesforce'), |
|
820 | 820 | 'value' => 'hours', |
821 | 821 | ), |
822 | 822 | 'days' => array( |
823 | - 'text' => __( 'Days', 'object-sync-for-salesforce' ), |
|
823 | + 'text' => __('Days', 'object-sync-for-salesforce'), |
|
824 | 824 | 'value' => 'days', |
825 | 825 | ), |
826 | 826 | ), |
827 | 827 | ), |
828 | 828 | ), |
829 | 829 | 'triggers_to_log' => array( |
830 | - 'title' => __( 'Triggers to log', 'object-sync-for-salesforce' ), |
|
830 | + 'title' => __('Triggers to log', 'object-sync-for-salesforce'), |
|
831 | 831 | 'callback' => $callbacks['checkboxes'], |
832 | 832 | 'page' => $page, |
833 | 833 | 'section' => $section, |
834 | 834 | 'args' => array( |
835 | 835 | 'type' => 'checkboxes', |
836 | 836 | 'validate' => 'sanitize_text_field', |
837 | - 'desc' => __( 'these are the triggers to log', 'object-sync-for-salesforce' ), |
|
837 | + 'desc' => __('these are the triggers to log', 'object-sync-for-salesforce'), |
|
838 | 838 | 'items' => array( |
839 | 839 | $this->mappings->sync_wordpress_create => array( |
840 | - 'text' => __( 'WordPress create', 'object-sync-for-salesforce' ), |
|
840 | + 'text' => __('WordPress create', 'object-sync-for-salesforce'), |
|
841 | 841 | 'id' => 'wordpress_create', |
842 | 842 | 'desc' => '', |
843 | 843 | ), |
844 | 844 | $this->mappings->sync_wordpress_update => array( |
845 | - 'text' => __( 'WordPress update', 'object-sync-for-salesforce' ), |
|
845 | + 'text' => __('WordPress update', 'object-sync-for-salesforce'), |
|
846 | 846 | 'id' => 'wordpress_update', |
847 | 847 | 'desc' => '', |
848 | 848 | ), |
849 | 849 | $this->mappings->sync_wordpress_delete => array( |
850 | - 'text' => __( 'WordPress delete', 'object-sync-for-salesforce' ), |
|
850 | + 'text' => __('WordPress delete', 'object-sync-for-salesforce'), |
|
851 | 851 | 'id' => 'wordpress_delete', |
852 | 852 | 'desc' => '', |
853 | 853 | ), |
854 | 854 | $this->mappings->sync_sf_create => array( |
855 | - 'text' => __( 'Salesforce create', 'object-sync-for-salesforce' ), |
|
855 | + 'text' => __('Salesforce create', 'object-sync-for-salesforce'), |
|
856 | 856 | 'id' => 'sf_create', |
857 | 857 | 'desc' => '', |
858 | 858 | ), |
859 | 859 | $this->mappings->sync_sf_update => array( |
860 | - 'text' => __( 'Salesforce update', 'object-sync-for-salesforce' ), |
|
860 | + 'text' => __('Salesforce update', 'object-sync-for-salesforce'), |
|
861 | 861 | 'id' => 'sf_update', |
862 | 862 | 'desc' => '', |
863 | 863 | ), |
864 | 864 | $this->mappings->sync_sf_delete => array( |
865 | - 'text' => __( 'Salesforce delete', 'object-sync-for-salesforce' ), |
|
865 | + 'text' => __('Salesforce delete', 'object-sync-for-salesforce'), |
|
866 | 866 | 'id' => 'sf_delete', |
867 | 867 | 'desc' => '', |
868 | 868 | ), |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | ), |
871 | 871 | ), |
872 | 872 | ); |
873 | - foreach ( $log_settings as $key => $attributes ) { |
|
873 | + foreach ($log_settings as $key => $attributes) { |
|
874 | 874 | $id = $this->option_prefix . $key; |
875 | 875 | $name = $this->option_prefix . $key; |
876 | 876 | $title = $attributes['title']; |
@@ -886,8 +886,8 @@ discard block |
||
886 | 886 | 'name' => $name, |
887 | 887 | ) |
888 | 888 | ); |
889 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
890 | - register_setting( $page, $id ); |
|
889 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
890 | + register_setting($page, $id); |
|
891 | 891 | } |
892 | 892 | } |
893 | 893 | |
@@ -898,69 +898,69 @@ discard block |
||
898 | 898 | public function notices() { |
899 | 899 | |
900 | 900 | // before a notice is displayed, we should make sure we are on a page related to this plugin |
901 | - if ( ! isset( $_GET['page'] ) || 'object-sync-salesforce-admin' !== $_GET['page'] ) { |
|
901 | + if ( ! isset($_GET['page']) || 'object-sync-salesforce-admin' !== $_GET['page']) { |
|
902 | 902 | return; |
903 | 903 | } |
904 | 904 | |
905 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
906 | - require_once plugin_dir_path( __FILE__ ) . '../classes/admin-notice.php'; |
|
905 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
906 | + require_once plugin_dir_path(__FILE__) . '../classes/admin-notice.php'; |
|
907 | 907 | |
908 | 908 | $notices = array( |
909 | 909 | 'permission' => array( |
910 | 910 | 'condition' => false === $this->check_wordpress_admin_permissions(), |
911 | - 'message' => __( "Your account does not have permission to edit the Salesforce REST API plugin's settings.", 'object-sync-for-salesforce' ), |
|
911 | + 'message' => __("Your account does not have permission to edit the Salesforce REST API plugin's settings.", 'object-sync-for-salesforce'), |
|
912 | 912 | 'type' => 'error', |
913 | 913 | 'dismissible' => false, |
914 | 914 | ), |
915 | 915 | 'fieldmap' => array( |
916 | - 'condition' => isset( $get_data['transient'] ), |
|
917 | - 'message' => __( 'Errors kept this fieldmap from being saved.', 'object-sync-for-salesforce' ), |
|
916 | + 'condition' => isset($get_data['transient']), |
|
917 | + 'message' => __('Errors kept this fieldmap from being saved.', 'object-sync-for-salesforce'), |
|
918 | 918 | 'type' => 'error', |
919 | 919 | 'dismissible' => true, |
920 | 920 | ), |
921 | 921 | 'object_map' => array( |
922 | - 'condition' => isset( $get_data['map_transient'] ), |
|
923 | - 'message' => __( 'Errors kept this object map from being saved.', 'object-sync-for-salesforce' ), |
|
922 | + 'condition' => isset($get_data['map_transient']), |
|
923 | + 'message' => __('Errors kept this object map from being saved.', 'object-sync-for-salesforce'), |
|
924 | 924 | 'type' => 'error', |
925 | 925 | 'dismissible' => true, |
926 | 926 | ), |
927 | 927 | 'data_saved' => array( |
928 | - 'condition' => isset( $get_data['data_saved'] ) && 'true' === $get_data['data_saved'], |
|
929 | - 'message' => __( 'This data was successfully saved.', 'object-sync-for-salesforce' ), |
|
928 | + 'condition' => isset($get_data['data_saved']) && 'true' === $get_data['data_saved'], |
|
929 | + 'message' => __('This data was successfully saved.', 'object-sync-for-salesforce'), |
|
930 | 930 | 'type' => 'success', |
931 | 931 | 'dismissible' => true, |
932 | 932 | ), |
933 | 933 | 'data_save_error' => array( |
934 | - 'condition' => isset( $get_data['data_saved'] ) && 'false' === $get_data['data_saved'], |
|
935 | - 'message' => __( 'This data was not successfully saved. Try again.', 'object-sync-for-salesforce' ), |
|
934 | + 'condition' => isset($get_data['data_saved']) && 'false' === $get_data['data_saved'], |
|
935 | + 'message' => __('This data was not successfully saved. Try again.', 'object-sync-for-salesforce'), |
|
936 | 936 | 'type' => 'error', |
937 | 937 | 'dismissible' => true, |
938 | 938 | ), |
939 | 939 | ); |
940 | 940 | |
941 | - foreach ( $notices as $key => $value ) { |
|
941 | + foreach ($notices as $key => $value) { |
|
942 | 942 | |
943 | 943 | $condition = $value['condition']; |
944 | 944 | $message = $value['message']; |
945 | 945 | |
946 | - if ( isset( $value['dismissible'] ) ) { |
|
946 | + if (isset($value['dismissible'])) { |
|
947 | 947 | $dismissible = $value['dismissible']; |
948 | 948 | } else { |
949 | 949 | $dismissible = false; |
950 | 950 | } |
951 | 951 | |
952 | - if ( isset( $value['type'] ) ) { |
|
952 | + if (isset($value['type'])) { |
|
953 | 953 | $type = $value['type']; |
954 | 954 | } else { |
955 | 955 | $type = ''; |
956 | 956 | } |
957 | 957 | |
958 | - if ( ! isset( $value['template'] ) ) { |
|
958 | + if ( ! isset($value['template'])) { |
|
959 | 959 | $template = ''; |
960 | 960 | } |
961 | 961 | |
962 | - if ( $condition ) { |
|
963 | - new Object_Sync_Sf_Admin_Notice( $condition, $message, $dismissible, $type, $template ); |
|
962 | + if ($condition) { |
|
963 | + new Object_Sync_Sf_Admin_Notice($condition, $message, $dismissible, $type, $template); |
|
964 | 964 | } |
965 | 965 | } |
966 | 966 | |
@@ -975,47 +975,47 @@ discard block |
||
975 | 975 | * can optionally contain a type |
976 | 976 | * @return array $object_settings |
977 | 977 | */ |
978 | - public function get_salesforce_object_description( $data = array() ) { |
|
978 | + public function get_salesforce_object_description($data = array()) { |
|
979 | 979 | $ajax = false; |
980 | - if ( empty( $data ) ) { |
|
981 | - $data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
980 | + if (empty($data)) { |
|
981 | + $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
982 | 982 | $ajax = true; |
983 | 983 | } |
984 | 984 | |
985 | 985 | $object_description = array(); |
986 | 986 | |
987 | - if ( ! empty( $data['salesforce_object'] ) ) { |
|
988 | - $object = $this->salesforce['sfapi']->object_describe( esc_attr( $data['salesforce_object'] ) ); |
|
987 | + if ( ! empty($data['salesforce_object'])) { |
|
988 | + $object = $this->salesforce['sfapi']->object_describe(esc_attr($data['salesforce_object'])); |
|
989 | 989 | |
990 | 990 | $object_fields = array(); |
991 | 991 | $include_record_types = array(); |
992 | 992 | |
993 | 993 | // these can come from ajax |
994 | - $include = isset( $data['include'] ) ? (array) $data['include'] : array(); |
|
995 | - $include = array_map( 'esc_attr', $include ); |
|
996 | - |
|
997 | - if ( in_array( 'fields', $include, true ) || empty( $include ) ) { |
|
998 | - $type = isset( $data['field_type'] ) ? esc_attr( $data['field_type'] ) : ''; // can come from ajax |
|
999 | - foreach ( $object['data']['fields'] as $key => $value ) { |
|
1000 | - if ( '' === $type || $type === $value['type'] ) { |
|
1001 | - $object_fields[ $key ] = $value; |
|
994 | + $include = isset($data['include']) ? (array) $data['include'] : array(); |
|
995 | + $include = array_map('esc_attr', $include); |
|
996 | + |
|
997 | + if (in_array('fields', $include, true) || empty($include)) { |
|
998 | + $type = isset($data['field_type']) ? esc_attr($data['field_type']) : ''; // can come from ajax |
|
999 | + foreach ($object['data']['fields'] as $key => $value) { |
|
1000 | + if ('' === $type || $type === $value['type']) { |
|
1001 | + $object_fields[$key] = $value; |
|
1002 | 1002 | } |
1003 | 1003 | } |
1004 | 1004 | $object_description['fields'] = $object_fields; |
1005 | 1005 | } |
1006 | 1006 | |
1007 | - if ( in_array( 'recordTypeInfos', $include, true ) ) { |
|
1008 | - if ( isset( $object['data']['recordTypeInfos'] ) && count( $object['data']['recordTypeInfos'] ) > 1 ) { |
|
1009 | - foreach ( $object['data']['recordTypeInfos'] as $type ) { |
|
1010 | - $object_record_types[ $type['recordTypeId'] ] = $type['name']; |
|
1007 | + if (in_array('recordTypeInfos', $include, true)) { |
|
1008 | + if (isset($object['data']['recordTypeInfos']) && count($object['data']['recordTypeInfos']) > 1) { |
|
1009 | + foreach ($object['data']['recordTypeInfos'] as $type) { |
|
1010 | + $object_record_types[$type['recordTypeId']] = $type['name']; |
|
1011 | 1011 | } |
1012 | 1012 | $object_description['recordTypeInfos'] = $object_record_types; |
1013 | 1013 | } |
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | |
1017 | - if ( true === $ajax ) { |
|
1018 | - wp_send_json_success( $object_description ); |
|
1017 | + if (true === $ajax) { |
|
1018 | + wp_send_json_success($object_description); |
|
1019 | 1019 | } else { |
1020 | 1020 | return $object_description; |
1021 | 1021 | } |
@@ -1029,23 +1029,23 @@ discard block |
||
1029 | 1029 | * can optionally contain a type for the field |
1030 | 1030 | * @return array $object_fields |
1031 | 1031 | */ |
1032 | - public function get_salesforce_object_fields( $data = array() ) { |
|
1032 | + public function get_salesforce_object_fields($data = array()) { |
|
1033 | 1033 | |
1034 | - if ( ! empty( $data['salesforce_object'] ) ) { |
|
1035 | - $object = $this->salesforce['sfapi']->object_describe( esc_attr( $data['salesforce_object'] ) ); |
|
1034 | + if ( ! empty($data['salesforce_object'])) { |
|
1035 | + $object = $this->salesforce['sfapi']->object_describe(esc_attr($data['salesforce_object'])); |
|
1036 | 1036 | $object_fields = array(); |
1037 | - $type = isset( $data['type'] ) ? esc_attr( $data['type'] ) : ''; |
|
1038 | - $include_record_types = isset( $data['include_record_types'] ) ? esc_attr( $data['include_record_types'] ) : false; |
|
1039 | - foreach ( $object['data']['fields'] as $key => $value ) { |
|
1040 | - if ( '' === $type || $type === $value['type'] ) { |
|
1041 | - $object_fields[ $key ] = $value; |
|
1037 | + $type = isset($data['type']) ? esc_attr($data['type']) : ''; |
|
1038 | + $include_record_types = isset($data['include_record_types']) ? esc_attr($data['include_record_types']) : false; |
|
1039 | + foreach ($object['data']['fields'] as $key => $value) { |
|
1040 | + if ('' === $type || $type === $value['type']) { |
|
1041 | + $object_fields[$key] = $value; |
|
1042 | 1042 | } |
1043 | 1043 | } |
1044 | - if ( true === $include_record_types ) { |
|
1044 | + if (true === $include_record_types) { |
|
1045 | 1045 | $object_record_types = array(); |
1046 | - if ( isset( $object['data']['recordTypeInfos'] ) && count( $object['data']['recordTypeInfos'] ) > 1 ) { |
|
1047 | - foreach ( $object['data']['recordTypeInfos'] as $type ) { |
|
1048 | - $object_record_types[ $type['recordTypeId'] ] = $type['name']; |
|
1046 | + if (isset($object['data']['recordTypeInfos']) && count($object['data']['recordTypeInfos']) > 1) { |
|
1047 | + foreach ($object['data']['recordTypeInfos'] as $type) { |
|
1048 | + $object_record_types[$type['recordTypeId']] = $type['name']; |
|
1049 | 1049 | } |
1050 | 1050 | } |
1051 | 1051 | } |
@@ -1062,18 +1062,18 @@ discard block |
||
1062 | 1062 | * @param string $wordpress_object |
1063 | 1063 | * @return array $object_fields |
1064 | 1064 | */ |
1065 | - public function get_wordpress_object_fields( $wordpress_object = '' ) { |
|
1065 | + public function get_wordpress_object_fields($wordpress_object = '') { |
|
1066 | 1066 | $ajax = false; |
1067 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1068 | - if ( empty( $wordpress_object ) ) { |
|
1069 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1067 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1068 | + if (empty($wordpress_object)) { |
|
1069 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1070 | 1070 | $ajax = true; |
1071 | 1071 | } |
1072 | 1072 | |
1073 | - $object_fields = $this->wordpress->get_wordpress_object_fields( $wordpress_object ); |
|
1073 | + $object_fields = $this->wordpress->get_wordpress_object_fields($wordpress_object); |
|
1074 | 1074 | |
1075 | - if ( true === $ajax ) { |
|
1076 | - wp_send_json_success( $object_fields ); |
|
1075 | + if (true === $ajax) { |
|
1076 | + wp_send_json_success($object_fields); |
|
1077 | 1077 | } else { |
1078 | 1078 | return $object_fields; |
1079 | 1079 | } |
@@ -1087,24 +1087,24 @@ discard block |
||
1087 | 1087 | * @param string $salesforce_object |
1088 | 1088 | * @return array $object_fields |
1089 | 1089 | */ |
1090 | - public function get_wp_sf_object_fields( $wordpress_object = '', $salesforce = '' ) { |
|
1091 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1092 | - if ( empty( $wordpress_object ) ) { |
|
1093 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1090 | + public function get_wp_sf_object_fields($wordpress_object = '', $salesforce = '') { |
|
1091 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1092 | + if (empty($wordpress_object)) { |
|
1093 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1094 | 1094 | } |
1095 | - if ( empty( $salesforce_object ) ) { |
|
1096 | - $salesforce_object = isset( $post_data['salesforce_object'] ) ? sanitize_text_field( wp_unslash( $post_data['salesforce_object'] ) ) : ''; |
|
1095 | + if (empty($salesforce_object)) { |
|
1096 | + $salesforce_object = isset($post_data['salesforce_object']) ? sanitize_text_field(wp_unslash($post_data['salesforce_object'])) : ''; |
|
1097 | 1097 | } |
1098 | 1098 | |
1099 | - $object_fields['wordpress'] = $this->get_wordpress_object_fields( $wordpress_object ); |
|
1099 | + $object_fields['wordpress'] = $this->get_wordpress_object_fields($wordpress_object); |
|
1100 | 1100 | $object_fields['salesforce'] = $this->get_salesforce_object_fields( |
1101 | 1101 | array( |
1102 | 1102 | 'salesforce_object' => $salesforce_object, |
1103 | 1103 | ) |
1104 | 1104 | ); |
1105 | 1105 | |
1106 | - if ( ! empty( $post_data ) ) { |
|
1107 | - wp_send_json_success( $object_fields ); |
|
1106 | + if ( ! empty($post_data)) { |
|
1107 | + wp_send_json_success($object_fields); |
|
1108 | 1108 | } else { |
1109 | 1109 | return $object_fields; |
1110 | 1110 | } |
@@ -1117,17 +1117,17 @@ discard block |
||
1117 | 1117 | * @param string $wordpress_object |
1118 | 1118 | * @param int $wordpress_id |
1119 | 1119 | */ |
1120 | - public function push_to_salesforce( $wordpress_object = '', $wordpress_id = '' ) { |
|
1121 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1122 | - if ( empty( $wordpress_object ) && empty( $wordpress_id ) ) { |
|
1123 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1124 | - $wordpress_id = isset( $post_data['wordpress_id'] ) ? absint( $post_data['wordpress_id'] ) : ''; |
|
1120 | + public function push_to_salesforce($wordpress_object = '', $wordpress_id = '') { |
|
1121 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1122 | + if (empty($wordpress_object) && empty($wordpress_id)) { |
|
1123 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1124 | + $wordpress_id = isset($post_data['wordpress_id']) ? absint($post_data['wordpress_id']) : ''; |
|
1125 | 1125 | } |
1126 | - $data = $this->wordpress->get_wordpress_object_data( $wordpress_object, $wordpress_id ); |
|
1127 | - $result = $this->push->manual_object_update( $data, $wordpress_object ); |
|
1126 | + $data = $this->wordpress->get_wordpress_object_data($wordpress_object, $wordpress_id); |
|
1127 | + $result = $this->push->manual_object_update($data, $wordpress_object); |
|
1128 | 1128 | |
1129 | - if ( ! empty( $post_data['wordpress_object'] ) && ! empty( $post_data['wordpress_id'] ) ) { |
|
1130 | - wp_send_json_success( $result ); |
|
1129 | + if ( ! empty($post_data['wordpress_object']) && ! empty($post_data['wordpress_id'])) { |
|
1130 | + wp_send_json_success($result); |
|
1131 | 1131 | } else { |
1132 | 1132 | return $result; |
1133 | 1133 | } |
@@ -1141,16 +1141,16 @@ discard block |
||
1141 | 1141 | * @param string $salesforce_id |
1142 | 1142 | * @param string $wordpress_object |
1143 | 1143 | */ |
1144 | - public function pull_from_salesforce( $salesforce_id = '', $wordpress_object = '' ) { |
|
1145 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1146 | - if ( empty( $wordpress_object ) && empty( $salesforce_id ) ) { |
|
1147 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1148 | - $salesforce_id = isset( $post_data['salesforce_id'] ) ? sanitize_text_field( wp_unslash( $post_data['salesforce_id'] ) ) : ''; |
|
1149 | - } |
|
1150 | - $type = $this->salesforce['sfapi']->get_sobject_type( $salesforce_id ); |
|
1151 | - $result = $this->pull->manual_pull( $type, $salesforce_id, $wordpress_object ); // we want the wp object to make sure we get the right fieldmap |
|
1152 | - if ( ! empty( $post_data ) ) { |
|
1153 | - wp_send_json_success( $result ); |
|
1144 | + public function pull_from_salesforce($salesforce_id = '', $wordpress_object = '') { |
|
1145 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1146 | + if (empty($wordpress_object) && empty($salesforce_id)) { |
|
1147 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1148 | + $salesforce_id = isset($post_data['salesforce_id']) ? sanitize_text_field(wp_unslash($post_data['salesforce_id'])) : ''; |
|
1149 | + } |
|
1150 | + $type = $this->salesforce['sfapi']->get_sobject_type($salesforce_id); |
|
1151 | + $result = $this->pull->manual_pull($type, $salesforce_id, $wordpress_object); // we want the wp object to make sure we get the right fieldmap |
|
1152 | + if ( ! empty($post_data)) { |
|
1153 | + wp_send_json_success($result); |
|
1154 | 1154 | } else { |
1155 | 1155 | return $result; |
1156 | 1156 | } |
@@ -1162,18 +1162,18 @@ discard block |
||
1162 | 1162 | * |
1163 | 1163 | * @param int $mapping_id |
1164 | 1164 | */ |
1165 | - public function refresh_mapped_data( $mapping_id = '' ) { |
|
1166 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1167 | - if ( empty( $mapping_id ) ) { |
|
1168 | - $mapping_id = isset( $post_data['mapping_id'] ) ? absint( $post_data['mapping_id'] ) : ''; |
|
1165 | + public function refresh_mapped_data($mapping_id = '') { |
|
1166 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1167 | + if (empty($mapping_id)) { |
|
1168 | + $mapping_id = isset($post_data['mapping_id']) ? absint($post_data['mapping_id']) : ''; |
|
1169 | 1169 | } |
1170 | 1170 | $result = $this->mappings->get_object_maps( |
1171 | 1171 | array( |
1172 | 1172 | 'id' => $mapping_id, |
1173 | 1173 | ) |
1174 | 1174 | ); |
1175 | - if ( ! empty( $post_data ) ) { |
|
1176 | - wp_send_json_success( $result ); |
|
1175 | + if ( ! empty($post_data)) { |
|
1176 | + wp_send_json_success($result); |
|
1177 | 1177 | } else { |
1178 | 1178 | return $result; |
1179 | 1179 | } |
@@ -1189,47 +1189,47 @@ discard block |
||
1189 | 1189 | */ |
1190 | 1190 | public function prepare_fieldmap_data() { |
1191 | 1191 | $error = false; |
1192 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1193 | - $cachekey = md5( wp_json_encode( $post_data ) ); |
|
1192 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1193 | + $cachekey = md5(wp_json_encode($post_data)); |
|
1194 | 1194 | |
1195 | - if ( ! isset( $post_data['label'] ) || ! isset( $post_data['salesforce_object'] ) || ! isset( $post_data['wordpress_object'] ) ) { |
|
1195 | + if ( ! isset($post_data['label']) || ! isset($post_data['salesforce_object']) || ! isset($post_data['wordpress_object'])) { |
|
1196 | 1196 | $error = true; |
1197 | 1197 | } |
1198 | - if ( true === $error ) { |
|
1199 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1200 | - if ( '' !== $cachekey ) { |
|
1201 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&transient=' . $cachekey; |
|
1198 | + if (true === $error) { |
|
1199 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1200 | + if ('' !== $cachekey) { |
|
1201 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&transient=' . $cachekey; |
|
1202 | 1202 | } |
1203 | 1203 | } else { // there are no errors |
1204 | 1204 | // send the row to the fieldmap class |
1205 | 1205 | // if it is add or clone, use the create method |
1206 | - $method = esc_attr( $post_data['method'] ); |
|
1206 | + $method = esc_attr($post_data['method']); |
|
1207 | 1207 | $salesforce_fields = $this->get_salesforce_object_fields( |
1208 | 1208 | array( |
1209 | 1209 | 'salesforce_object' => $post_data['salesforce_object'], |
1210 | 1210 | ) |
1211 | 1211 | ); |
1212 | - $wordpress_fields = $this->get_wordpress_object_fields( $post_data['wordpress_object'] ); |
|
1213 | - if ( 'add' === $method || 'clone' === $method ) { |
|
1214 | - $result = $this->mappings->create_fieldmap( $post_data, $wordpress_fields, $salesforce_fields ); |
|
1215 | - } elseif ( 'edit' === $method ) { // if it is edit, use the update method |
|
1216 | - $id = esc_attr( $post_data['id'] ); |
|
1217 | - $result = $this->mappings->update_fieldmap( $post_data, $wordpress_fields, $salesforce_fields, $id ); |
|
1212 | + $wordpress_fields = $this->get_wordpress_object_fields($post_data['wordpress_object']); |
|
1213 | + if ('add' === $method || 'clone' === $method) { |
|
1214 | + $result = $this->mappings->create_fieldmap($post_data, $wordpress_fields, $salesforce_fields); |
|
1215 | + } elseif ('edit' === $method) { // if it is edit, use the update method |
|
1216 | + $id = esc_attr($post_data['id']); |
|
1217 | + $result = $this->mappings->update_fieldmap($post_data, $wordpress_fields, $salesforce_fields, $id); |
|
1218 | 1218 | } |
1219 | - if ( false === $result ) { // if the database didn't save, it's still an error |
|
1220 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1221 | - if ( '' !== $cachekey ) { |
|
1222 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&transient=' . $cachekey; |
|
1219 | + if (false === $result) { // if the database didn't save, it's still an error |
|
1220 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1221 | + if ('' !== $cachekey) { |
|
1222 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&transient=' . $cachekey; |
|
1223 | 1223 | } |
1224 | 1224 | } else { |
1225 | - if ( isset( $post_data['transient'] ) ) { // there was previously an error saved. can delete it now. |
|
1226 | - $this->sfwp_transients->delete( esc_attr( $post_data['map_transient'] ) ); |
|
1225 | + if (isset($post_data['transient'])) { // there was previously an error saved. can delete it now. |
|
1226 | + $this->sfwp_transients->delete(esc_attr($post_data['map_transient'])); |
|
1227 | 1227 | } |
1228 | 1228 | // then send the user to the list of fieldmaps |
1229 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1229 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1230 | 1230 | } |
1231 | 1231 | } |
1232 | - wp_safe_redirect( $url ); |
|
1232 | + wp_safe_redirect($url); |
|
1233 | 1233 | exit(); |
1234 | 1234 | } |
1235 | 1235 | |
@@ -1241,15 +1241,15 @@ discard block |
||
1241 | 1241 | * |
1242 | 1242 | */ |
1243 | 1243 | public function delete_fieldmap() { |
1244 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1245 | - if ( $post_data['id'] ) { |
|
1246 | - $result = $this->mappings->delete_fieldmap( $post_data['id'] ); |
|
1247 | - if ( true === $result ) { |
|
1248 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1244 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1245 | + if ($post_data['id']) { |
|
1246 | + $result = $this->mappings->delete_fieldmap($post_data['id']); |
|
1247 | + if (true === $result) { |
|
1248 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1249 | 1249 | } else { |
1250 | - $url = esc_url_raw( $post_data['redirect_url_error'] . '&id=' . $post_data['id'] ); |
|
1250 | + $url = esc_url_raw($post_data['redirect_url_error'] . '&id=' . $post_data['id']); |
|
1251 | 1251 | } |
1252 | - wp_safe_redirect( $url ); |
|
1252 | + wp_safe_redirect($url); |
|
1253 | 1253 | exit(); |
1254 | 1254 | } |
1255 | 1255 | } |
@@ -1264,38 +1264,38 @@ discard block |
||
1264 | 1264 | */ |
1265 | 1265 | public function prepare_object_map_data() { |
1266 | 1266 | $error = false; |
1267 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1268 | - $cachekey = md5( wp_json_encode( $post_data ) ); |
|
1267 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1268 | + $cachekey = md5(wp_json_encode($post_data)); |
|
1269 | 1269 | |
1270 | - if ( ! isset( $post_data['wordpress_id'] ) || ! isset( $post_data['salesforce_id'] ) ) { |
|
1270 | + if ( ! isset($post_data['wordpress_id']) || ! isset($post_data['salesforce_id'])) { |
|
1271 | 1271 | $error = true; |
1272 | 1272 | } |
1273 | - if ( true === $error ) { |
|
1274 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1275 | - if ( '' !== $cachekey ) { |
|
1276 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&map_transient=' . $cachekey; |
|
1273 | + if (true === $error) { |
|
1274 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1275 | + if ('' !== $cachekey) { |
|
1276 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&map_transient=' . $cachekey; |
|
1277 | 1277 | } |
1278 | 1278 | } else { // there are no errors |
1279 | 1279 | // send the row to the object map class |
1280 | - $method = esc_attr( $post_data['method'] ); |
|
1281 | - if ( 'edit' === $method ) { // if it is edit, use the update method |
|
1282 | - $id = esc_attr( $post_data['id'] ); |
|
1283 | - $result = $this->mappings->update_object_map( $post_data, $id ); |
|
1280 | + $method = esc_attr($post_data['method']); |
|
1281 | + if ('edit' === $method) { // if it is edit, use the update method |
|
1282 | + $id = esc_attr($post_data['id']); |
|
1283 | + $result = $this->mappings->update_object_map($post_data, $id); |
|
1284 | 1284 | } |
1285 | - if ( false === $result ) { // if the database didn't save, it's still an error |
|
1286 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1287 | - if ( '' !== $cachekey ) { |
|
1288 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&map_transient=' . $cachekey; |
|
1285 | + if (false === $result) { // if the database didn't save, it's still an error |
|
1286 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1287 | + if ('' !== $cachekey) { |
|
1288 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&map_transient=' . $cachekey; |
|
1289 | 1289 | } |
1290 | 1290 | } else { |
1291 | - if ( isset( $post_data['map_transient'] ) ) { // there was previously an error saved. can delete it now. |
|
1292 | - $this->sfwp_transients->delete( esc_attr( $post_data['map_transient'] ) ); |
|
1291 | + if (isset($post_data['map_transient'])) { // there was previously an error saved. can delete it now. |
|
1292 | + $this->sfwp_transients->delete(esc_attr($post_data['map_transient'])); |
|
1293 | 1293 | } |
1294 | 1294 | // then send the user to the success redirect url |
1295 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1295 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1296 | 1296 | } |
1297 | 1297 | } |
1298 | - wp_safe_redirect( $url ); |
|
1298 | + wp_safe_redirect($url); |
|
1299 | 1299 | exit(); |
1300 | 1300 | } |
1301 | 1301 | |
@@ -1307,15 +1307,15 @@ discard block |
||
1307 | 1307 | * |
1308 | 1308 | */ |
1309 | 1309 | public function delete_object_map() { |
1310 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1311 | - if ( $post_data['id'] ) { |
|
1312 | - $result = $this->mappings->delete_object_map( $post_data['id'] ); |
|
1313 | - if ( true === $result ) { |
|
1314 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1310 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1311 | + if ($post_data['id']) { |
|
1312 | + $result = $this->mappings->delete_object_map($post_data['id']); |
|
1313 | + if (true === $result) { |
|
1314 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1315 | 1315 | } else { |
1316 | - $url = esc_url_raw( $post_data['redirect_url_error'] . '&id=' . $post_data['id'] ); |
|
1316 | + $url = esc_url_raw($post_data['redirect_url_error'] . '&id=' . $post_data['id']); |
|
1317 | 1317 | } |
1318 | - wp_safe_redirect( $url ); |
|
1318 | + wp_safe_redirect($url); |
|
1319 | 1319 | exit(); |
1320 | 1320 | } |
1321 | 1321 | } |
@@ -1326,95 +1326,95 @@ discard block |
||
1326 | 1326 | */ |
1327 | 1327 | public function import_json_file() { |
1328 | 1328 | |
1329 | - if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_import'], 'object_sync_for_salesforce_nonce_import' ) ) { |
|
1329 | + if ( ! wp_verify_nonce($_POST['object_sync_for_salesforce_nonce_import'], 'object_sync_for_salesforce_nonce_import')) { |
|
1330 | 1330 | return; |
1331 | 1331 | } |
1332 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1332 | + if ( ! current_user_can('manage_options')) { |
|
1333 | 1333 | return; |
1334 | 1334 | } |
1335 | 1335 | $path = $_FILES['import_file']['name']; |
1336 | - $extension = pathinfo( $path, PATHINFO_EXTENSION ); |
|
1337 | - if ( 'json' !== $extension ) { |
|
1338 | - wp_die( __( 'Please upload a valid .json file' ) ); |
|
1336 | + $extension = pathinfo($path, PATHINFO_EXTENSION); |
|
1337 | + if ('json' !== $extension) { |
|
1338 | + wp_die(__('Please upload a valid .json file')); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | 1341 | $import_file = $_FILES['import_file']['tmp_name']; |
1342 | - if ( empty( $import_file ) ) { |
|
1343 | - wp_die( __( 'Please upload a file to import' ) ); |
|
1342 | + if (empty($import_file)) { |
|
1343 | + wp_die(__('Please upload a file to import')); |
|
1344 | 1344 | } |
1345 | 1345 | |
1346 | 1346 | // Retrieve the data from the file and convert the json object to an array. |
1347 | - $data = (array) json_decode( file_get_contents( $import_file ), true ); |
|
1347 | + $data = (array) json_decode(file_get_contents($import_file), true); |
|
1348 | 1348 | |
1349 | 1349 | // if there is only one object map, fix the array |
1350 | - if ( isset( $data['object_maps'] ) ) { |
|
1351 | - if ( count( $data['object_maps'] ) === count( $data['object_maps'], COUNT_RECURSIVE ) ) { |
|
1352 | - $data['object_maps'] = array( 0 => $data['object_maps'] ); |
|
1350 | + if (isset($data['object_maps'])) { |
|
1351 | + if (count($data['object_maps']) === count($data['object_maps'], COUNT_RECURSIVE)) { |
|
1352 | + $data['object_maps'] = array(0 => $data['object_maps']); |
|
1353 | 1353 | } |
1354 | 1354 | } |
1355 | 1355 | |
1356 | - $overwrite = isset( $_POST['overwrite'] ) ? esc_attr( $_POST['overwrite'] ) : ''; |
|
1357 | - if ( '1' === $overwrite ) { |
|
1358 | - if ( isset( $data['fieldmaps'] ) ) { |
|
1356 | + $overwrite = isset($_POST['overwrite']) ? esc_attr($_POST['overwrite']) : ''; |
|
1357 | + if ('1' === $overwrite) { |
|
1358 | + if (isset($data['fieldmaps'])) { |
|
1359 | 1359 | $fieldmaps = $this->mappings->get_fieldmaps(); |
1360 | - foreach ( $fieldmaps as $fieldmap ) { |
|
1360 | + foreach ($fieldmaps as $fieldmap) { |
|
1361 | 1361 | $id = $fieldmap['id']; |
1362 | - $delete = $this->mappings->delete_fieldmap( $id ); |
|
1362 | + $delete = $this->mappings->delete_fieldmap($id); |
|
1363 | 1363 | } |
1364 | 1364 | } |
1365 | - if ( isset( $data['object_maps'] ) ) { |
|
1365 | + if (isset($data['object_maps'])) { |
|
1366 | 1366 | $object_maps = $this->mappings->get_object_maps(); |
1367 | 1367 | |
1368 | 1368 | // if there is only one existing object map, fix the array |
1369 | - if ( count( $object_maps ) === count( $object_maps, COUNT_RECURSIVE ) ) { |
|
1370 | - $object_maps = array( 0 => $object_maps ); |
|
1369 | + if (count($object_maps) === count($object_maps, COUNT_RECURSIVE)) { |
|
1370 | + $object_maps = array(0 => $object_maps); |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | - foreach ( $object_maps as $object_map ) { |
|
1373 | + foreach ($object_maps as $object_map) { |
|
1374 | 1374 | $id = $object_map['id']; |
1375 | - $delete = $this->mappings->delete_object_map( $id ); |
|
1375 | + $delete = $this->mappings->delete_object_map($id); |
|
1376 | 1376 | } |
1377 | 1377 | } |
1378 | - if ( isset( $data['plugin_settings'] ) ) { |
|
1379 | - foreach ( $data['plugin_settings'] as $key => $value ) { |
|
1380 | - delete_option( $value['option_name'] ); |
|
1378 | + if (isset($data['plugin_settings'])) { |
|
1379 | + foreach ($data['plugin_settings'] as $key => $value) { |
|
1380 | + delete_option($value['option_name']); |
|
1381 | 1381 | } |
1382 | 1382 | } |
1383 | 1383 | } |
1384 | 1384 | |
1385 | 1385 | $success = true; |
1386 | 1386 | |
1387 | - if ( isset( $data['fieldmaps'] ) ) { |
|
1388 | - foreach ( $data['fieldmaps'] as $fieldmap ) { |
|
1389 | - unset( $fieldmap['id'] ); |
|
1390 | - $create = $this->mappings->create_fieldmap( $fieldmap ); |
|
1391 | - if ( false === $create ) { |
|
1387 | + if (isset($data['fieldmaps'])) { |
|
1388 | + foreach ($data['fieldmaps'] as $fieldmap) { |
|
1389 | + unset($fieldmap['id']); |
|
1390 | + $create = $this->mappings->create_fieldmap($fieldmap); |
|
1391 | + if (false === $create) { |
|
1392 | 1392 | $success = false; |
1393 | 1393 | } |
1394 | 1394 | } |
1395 | 1395 | } |
1396 | 1396 | |
1397 | - if ( isset( $data['object_maps'] ) ) { |
|
1398 | - foreach ( $data['object_maps'] as $object_map ) { |
|
1399 | - unset( $object_map['id'] ); |
|
1400 | - $create = $this->mappings->create_object_map( $object_map ); |
|
1401 | - if ( false === $create ) { |
|
1397 | + if (isset($data['object_maps'])) { |
|
1398 | + foreach ($data['object_maps'] as $object_map) { |
|
1399 | + unset($object_map['id']); |
|
1400 | + $create = $this->mappings->create_object_map($object_map); |
|
1401 | + if (false === $create) { |
|
1402 | 1402 | $success = false; |
1403 | 1403 | } |
1404 | 1404 | } |
1405 | 1405 | } |
1406 | 1406 | |
1407 | - if ( isset( $data['plugin_settings'] ) ) { |
|
1408 | - foreach ( $data['plugin_settings'] as $key => $value ) { |
|
1409 | - update_option( $value['option_name'], maybe_unserialize( $value['option_value'] ), $value['autoload'] ); |
|
1407 | + if (isset($data['plugin_settings'])) { |
|
1408 | + foreach ($data['plugin_settings'] as $key => $value) { |
|
1409 | + update_option($value['option_name'], maybe_unserialize($value['option_value']), $value['autoload']); |
|
1410 | 1410 | } |
1411 | 1411 | } |
1412 | 1412 | |
1413 | - if ( true === $success ) { |
|
1414 | - wp_safe_redirect( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=true' ) ); |
|
1413 | + if (true === $success) { |
|
1414 | + wp_safe_redirect(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=true')); |
|
1415 | 1415 | exit; |
1416 | 1416 | } else { |
1417 | - wp_safe_redirect( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=false' ) ); |
|
1417 | + wp_safe_redirect(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=false')); |
|
1418 | 1418 | exit; |
1419 | 1419 | } |
1420 | 1420 | |
@@ -1426,28 +1426,28 @@ discard block |
||
1426 | 1426 | */ |
1427 | 1427 | public function export_json_file() { |
1428 | 1428 | |
1429 | - if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_export'], 'object_sync_for_salesforce_nonce_export' ) ) { |
|
1429 | + if ( ! wp_verify_nonce($_POST['object_sync_for_salesforce_nonce_export'], 'object_sync_for_salesforce_nonce_export')) { |
|
1430 | 1430 | return; |
1431 | 1431 | } |
1432 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1432 | + if ( ! current_user_can('manage_options')) { |
|
1433 | 1433 | return; |
1434 | 1434 | } |
1435 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1435 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1436 | 1436 | $export = array(); |
1437 | - if ( in_array( 'fieldmaps', $post_data['export'] ) ) { |
|
1437 | + if (in_array('fieldmaps', $post_data['export'])) { |
|
1438 | 1438 | $export['fieldmaps'] = $this->mappings->get_fieldmaps(); |
1439 | 1439 | } |
1440 | - if ( in_array( 'object_maps', $post_data['export'] ) ) { |
|
1440 | + if (in_array('object_maps', $post_data['export'])) { |
|
1441 | 1441 | $export['object_maps'] = $this->mappings->get_object_maps(); |
1442 | 1442 | } |
1443 | - if ( in_array( 'plugin_settings', $post_data['export'] ) ) { |
|
1444 | - $export['plugin_settings'] = $this->wpdb->get_results( 'SELECT * FROM ' . $this->wpdb->prefix . 'options' . ' WHERE option_name like "' . $this->option_prefix . '%"', ARRAY_A ); |
|
1443 | + if (in_array('plugin_settings', $post_data['export'])) { |
|
1444 | + $export['plugin_settings'] = $this->wpdb->get_results('SELECT * FROM ' . $this->wpdb->prefix . 'options' . ' WHERE option_name like "' . $this->option_prefix . '%"', ARRAY_A); |
|
1445 | 1445 | } |
1446 | 1446 | nocache_headers(); |
1447 | - header( 'Content-Type: application/json; charset=utf-8' ); |
|
1448 | - header( 'Content-Disposition: attachment; filename=object-sync-for-salesforce-data-export-' . date( 'm-d-Y' ) . '.json' ); |
|
1449 | - header( 'Expires: 0' ); |
|
1450 | - echo wp_json_encode( $export ); |
|
1447 | + header('Content-Type: application/json; charset=utf-8'); |
|
1448 | + header('Content-Disposition: attachment; filename=object-sync-for-salesforce-data-export-' . date('m-d-Y') . '.json'); |
|
1449 | + header('Expires: 0'); |
|
1450 | + echo wp_json_encode($export); |
|
1451 | 1451 | exit; |
1452 | 1452 | } |
1453 | 1453 | |
@@ -1456,7 +1456,7 @@ discard block |
||
1456 | 1456 | * |
1457 | 1457 | * @param array $args |
1458 | 1458 | */ |
1459 | - public function display_input_field( $args ) { |
|
1459 | + public function display_input_field($args) { |
|
1460 | 1460 | $type = $args['type']; |
1461 | 1461 | $id = $args['label_for']; |
1462 | 1462 | $name = $args['name']; |
@@ -1465,38 +1465,38 @@ discard block |
||
1465 | 1465 | |
1466 | 1466 | $class = 'regular-text'; |
1467 | 1467 | |
1468 | - if ( 'checkbox' === $type ) { |
|
1468 | + if ('checkbox' === $type) { |
|
1469 | 1469 | $class = 'checkbox'; |
1470 | 1470 | } |
1471 | 1471 | |
1472 | - if ( ! isset( $args['constant'] ) || ! defined( $args['constant'] ) ) { |
|
1473 | - $value = esc_attr( get_option( $id, '' ) ); |
|
1474 | - if ( 'checkbox' === $type ) { |
|
1475 | - if ( '1' === $value ) { |
|
1472 | + if ( ! isset($args['constant']) || ! defined($args['constant'])) { |
|
1473 | + $value = esc_attr(get_option($id, '')); |
|
1474 | + if ('checkbox' === $type) { |
|
1475 | + if ('1' === $value) { |
|
1476 | 1476 | $checked = 'checked '; |
1477 | 1477 | } |
1478 | 1478 | $value = 1; |
1479 | 1479 | } |
1480 | - if ( '' === $value && isset( $args['default'] ) && '' !== $args['default'] ) { |
|
1480 | + if ('' === $value && isset($args['default']) && '' !== $args['default']) { |
|
1481 | 1481 | $value = $args['default']; |
1482 | 1482 | } |
1483 | 1483 | |
1484 | - echo sprintf( '<input type="%1$s" value="%2$s" name="%3$s" id="%4$s" class="%5$s"%6$s>', |
|
1485 | - esc_attr( $type ), |
|
1486 | - esc_attr( $value ), |
|
1487 | - esc_attr( $name ), |
|
1488 | - esc_attr( $id ), |
|
1489 | - sanitize_html_class( $class . esc_html( ' code' ) ), |
|
1490 | - esc_html( $checked ) |
|
1484 | + echo sprintf('<input type="%1$s" value="%2$s" name="%3$s" id="%4$s" class="%5$s"%6$s>', |
|
1485 | + esc_attr($type), |
|
1486 | + esc_attr($value), |
|
1487 | + esc_attr($name), |
|
1488 | + esc_attr($id), |
|
1489 | + sanitize_html_class($class . esc_html(' code')), |
|
1490 | + esc_html($checked) |
|
1491 | 1491 | ); |
1492 | - if ( '' !== $desc ) { |
|
1493 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1494 | - esc_html( $desc ) |
|
1492 | + if ('' !== $desc) { |
|
1493 | + echo sprintf('<p class="description">%1$s</p>', |
|
1494 | + esc_html($desc) |
|
1495 | 1495 | ); |
1496 | 1496 | } |
1497 | 1497 | } else { |
1498 | - echo sprintf( '<p><code>%1$s</code></p>', |
|
1499 | - esc_html__( 'Defined in wp-config.php', 'object-sync-for-salesforce' ) |
|
1498 | + echo sprintf('<p><code>%1$s</code></p>', |
|
1499 | + esc_html__('Defined in wp-config.php', 'object-sync-for-salesforce') |
|
1500 | 1500 | ); |
1501 | 1501 | } |
1502 | 1502 | } |
@@ -1507,33 +1507,33 @@ discard block |
||
1507 | 1507 | * |
1508 | 1508 | * @param array $args |
1509 | 1509 | */ |
1510 | - public function display_checkboxes( $args ) { |
|
1510 | + public function display_checkboxes($args) { |
|
1511 | 1511 | $type = 'checkbox'; |
1512 | 1512 | $name = $args['name']; |
1513 | - $options = get_option( $name, array() ); |
|
1514 | - foreach ( $args['items'] as $key => $value ) { |
|
1513 | + $options = get_option($name, array()); |
|
1514 | + foreach ($args['items'] as $key => $value) { |
|
1515 | 1515 | $text = $value['text']; |
1516 | 1516 | $id = $value['id']; |
1517 | 1517 | $desc = $value['desc']; |
1518 | 1518 | $checked = ''; |
1519 | - if ( is_array( $options ) && in_array( (string) $key, $options, true ) ) { |
|
1519 | + if (is_array($options) && in_array((string) $key, $options, true)) { |
|
1520 | 1520 | $checked = 'checked'; |
1521 | - } elseif ( is_array( $options ) && empty( $options ) ) { |
|
1522 | - if ( isset( $value['default'] ) && true === $value['default'] ) { |
|
1521 | + } elseif (is_array($options) && empty($options)) { |
|
1522 | + if (isset($value['default']) && true === $value['default']) { |
|
1523 | 1523 | $checked = 'checked'; |
1524 | 1524 | } |
1525 | 1525 | } |
1526 | - 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>', |
|
1527 | - esc_attr( $type ), |
|
1528 | - esc_attr( $key ), |
|
1529 | - esc_attr( $name ), |
|
1530 | - esc_attr( $id ), |
|
1531 | - esc_html( $checked ), |
|
1532 | - esc_html( $text ) |
|
1526 | + 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>', |
|
1527 | + esc_attr($type), |
|
1528 | + esc_attr($key), |
|
1529 | + esc_attr($name), |
|
1530 | + esc_attr($id), |
|
1531 | + esc_html($checked), |
|
1532 | + esc_html($text) |
|
1533 | 1533 | ); |
1534 | - if ( '' !== $desc ) { |
|
1535 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1536 | - esc_html( $desc ) |
|
1534 | + if ('' !== $desc) { |
|
1535 | + echo sprintf('<p class="description">%1$s</p>', |
|
1536 | + esc_html($desc) |
|
1537 | 1537 | ); |
1538 | 1538 | } |
1539 | 1539 | } |
@@ -1544,44 +1544,44 @@ discard block |
||
1544 | 1544 | * |
1545 | 1545 | * @param array $args |
1546 | 1546 | */ |
1547 | - public function display_select( $args ) { |
|
1547 | + public function display_select($args) { |
|
1548 | 1548 | $type = $args['type']; |
1549 | 1549 | $id = $args['label_for']; |
1550 | 1550 | $name = $args['name']; |
1551 | 1551 | $desc = $args['desc']; |
1552 | - if ( ! isset( $args['constant'] ) || ! defined( $args['constant'] ) ) { |
|
1553 | - $current_value = get_option( $name ); |
|
1552 | + if ( ! isset($args['constant']) || ! defined($args['constant'])) { |
|
1553 | + $current_value = get_option($name); |
|
1554 | 1554 | |
1555 | - echo sprintf( '<div class="select"><select id="%1$s" name="%2$s"><option value="">- ' . __( 'Select one', 'object-sync-for-salesforce' ) . ' -</option>', |
|
1556 | - esc_attr( $id ), |
|
1557 | - esc_attr( $name ) |
|
1555 | + echo sprintf('<div class="select"><select id="%1$s" name="%2$s"><option value="">- ' . __('Select one', 'object-sync-for-salesforce') . ' -</option>', |
|
1556 | + esc_attr($id), |
|
1557 | + esc_attr($name) |
|
1558 | 1558 | ); |
1559 | 1559 | |
1560 | - foreach ( $args['items'] as $key => $value ) { |
|
1560 | + foreach ($args['items'] as $key => $value) { |
|
1561 | 1561 | $text = $value['text']; |
1562 | 1562 | $value = $value['value']; |
1563 | 1563 | $selected = ''; |
1564 | - if ( $key === $current_value || $value === $current_value ) { |
|
1564 | + if ($key === $current_value || $value === $current_value) { |
|
1565 | 1565 | $selected = ' selected'; |
1566 | 1566 | } |
1567 | 1567 | |
1568 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
1569 | - esc_attr( $value ), |
|
1570 | - esc_attr( $selected ), |
|
1571 | - esc_html( $text ) |
|
1568 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
1569 | + esc_attr($value), |
|
1570 | + esc_attr($selected), |
|
1571 | + esc_html($text) |
|
1572 | 1572 | ); |
1573 | 1573 | |
1574 | 1574 | } |
1575 | 1575 | echo '</select>'; |
1576 | - if ( '' !== $desc ) { |
|
1577 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1578 | - esc_html( $desc ) |
|
1576 | + if ('' !== $desc) { |
|
1577 | + echo sprintf('<p class="description">%1$s</p>', |
|
1578 | + esc_html($desc) |
|
1579 | 1579 | ); |
1580 | 1580 | } |
1581 | 1581 | echo '</div>'; |
1582 | 1582 | } else { |
1583 | - echo sprintf( '<p><code>%1$s</code></p>', |
|
1584 | - esc_html__( 'Defined in wp-config.php', 'object-sync-for-salesforce' ) |
|
1583 | + echo sprintf('<p><code>%1$s</code></p>', |
|
1584 | + esc_html__('Defined in wp-config.php', 'object-sync-for-salesforce') |
|
1585 | 1585 | ); |
1586 | 1586 | } |
1587 | 1587 | } |
@@ -1594,7 +1594,7 @@ discard block |
||
1594 | 1594 | private function version_options() { |
1595 | 1595 | $versions = $this->salesforce['sfapi']->get_api_versions(); |
1596 | 1596 | $args = array(); |
1597 | - foreach ( $versions['data'] as $key => $value ) { |
|
1597 | + foreach ($versions['data'] as $key => $value) { |
|
1598 | 1598 | $args[] = array( |
1599 | 1599 | 'value' => $value['version'], |
1600 | 1600 | 'text' => $value['label'] . ' (' . $value['version'] . ')', |
@@ -1608,26 +1608,26 @@ discard block |
||
1608 | 1608 | * |
1609 | 1609 | * @param array $args |
1610 | 1610 | */ |
1611 | - public function display_link( $args ) { |
|
1611 | + public function display_link($args) { |
|
1612 | 1612 | $label = $args['label']; |
1613 | 1613 | $desc = $args['desc']; |
1614 | 1614 | $url = $args['url']; |
1615 | - if ( isset( $args['link_class'] ) ) { |
|
1616 | - echo sprintf( '<p><a class="%1$s" href="%2$s">%3$s</a></p>', |
|
1617 | - esc_attr( $args['link_class'] ), |
|
1618 | - esc_url( $url ), |
|
1619 | - esc_html( $label ) |
|
1615 | + if (isset($args['link_class'])) { |
|
1616 | + echo sprintf('<p><a class="%1$s" href="%2$s">%3$s</a></p>', |
|
1617 | + esc_attr($args['link_class']), |
|
1618 | + esc_url($url), |
|
1619 | + esc_html($label) |
|
1620 | 1620 | ); |
1621 | 1621 | } else { |
1622 | - echo sprintf( '<p><a href="%1$s">%2$s</a></p>', |
|
1623 | - esc_url( $url ), |
|
1624 | - esc_html( $label ) |
|
1622 | + echo sprintf('<p><a href="%1$s">%2$s</a></p>', |
|
1623 | + esc_url($url), |
|
1624 | + esc_html($label) |
|
1625 | 1625 | ); |
1626 | 1626 | } |
1627 | 1627 | |
1628 | - if ( '' !== $desc ) { |
|
1629 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1630 | - esc_html( $desc ) |
|
1628 | + if ('' !== $desc) { |
|
1629 | + echo sprintf('<p class="description">%1$s</p>', |
|
1630 | + esc_html($desc) |
|
1631 | 1631 | ); |
1632 | 1632 | } |
1633 | 1633 | |
@@ -1638,60 +1638,60 @@ discard block |
||
1638 | 1638 | * |
1639 | 1639 | * @param object $sfapi |
1640 | 1640 | */ |
1641 | - private function status( $sfapi ) { |
|
1641 | + private function status($sfapi) { |
|
1642 | 1642 | |
1643 | 1643 | $versions = $sfapi->get_api_versions(); |
1644 | 1644 | |
1645 | 1645 | // format this array into text so users can see the versions |
1646 | - if ( true === $versions['cached'] ) { |
|
1647 | - $versions_is_cached = esc_html__( 'This list is cached, and', 'object-sync-salesforce' ); |
|
1646 | + if (true === $versions['cached']) { |
|
1647 | + $versions_is_cached = esc_html__('This list is cached, and', 'object-sync-salesforce'); |
|
1648 | 1648 | } else { |
1649 | - $versions_is_cached = esc_html__( 'This list is not cached, but', 'object-sync-salesforce' ); |
|
1649 | + $versions_is_cached = esc_html__('This list is not cached, but', 'object-sync-salesforce'); |
|
1650 | 1650 | } |
1651 | 1651 | |
1652 | - if ( true === $versions['from_cache'] ) { |
|
1653 | - $versions_from_cache = esc_html__( 'items were loaded from the cache', 'object-sync-salesforce' ); |
|
1652 | + if (true === $versions['from_cache']) { |
|
1653 | + $versions_from_cache = esc_html__('items were loaded from the cache', 'object-sync-salesforce'); |
|
1654 | 1654 | } else { |
1655 | - $versions_from_cache = esc_html__( 'items were not loaded from the cache', 'object-sync-salesforce' ); |
|
1655 | + $versions_from_cache = esc_html__('items were not loaded from the cache', 'object-sync-salesforce'); |
|
1656 | 1656 | } |
1657 | 1657 | |
1658 | 1658 | // 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 |
1659 | - $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' ), |
|
1659 | + $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'), |
|
1660 | 1660 | $versions_is_cached, |
1661 | 1661 | $versions_from_cache |
1662 | 1662 | ); |
1663 | 1663 | |
1664 | - $contacts = $sfapi->query( 'SELECT Name, Id from Contact LIMIT 100' ); |
|
1664 | + $contacts = $sfapi->query('SELECT Name, Id from Contact LIMIT 100'); |
|
1665 | 1665 | |
1666 | 1666 | // format this array into html so users can see the contacts |
1667 | - if ( true === $contacts['cached'] ) { |
|
1668 | - $contacts_is_cached = esc_html__( 'They are cached, and', 'object-sync-salesforce' ); |
|
1667 | + if (true === $contacts['cached']) { |
|
1668 | + $contacts_is_cached = esc_html__('They are cached, and', 'object-sync-salesforce'); |
|
1669 | 1669 | } else { |
1670 | - $contacts_is_cached = esc_html__( 'They are not cached, but', 'object-sync-salesforce' ); |
|
1670 | + $contacts_is_cached = esc_html__('They are not cached, but', 'object-sync-salesforce'); |
|
1671 | 1671 | } |
1672 | 1672 | |
1673 | - if ( true === $contacts['from_cache'] ) { |
|
1674 | - $contacts_from_cache = esc_html__( 'they were loaded from the cache', 'object-sync-salesforce' ); |
|
1673 | + if (true === $contacts['from_cache']) { |
|
1674 | + $contacts_from_cache = esc_html__('they were loaded from the cache', 'object-sync-salesforce'); |
|
1675 | 1675 | } else { |
1676 | - $contacts_from_cache = esc_html__( 'they were not loaded from the cache', 'object-sync-salesforce' ); |
|
1676 | + $contacts_from_cache = esc_html__('they were not loaded from the cache', 'object-sync-salesforce'); |
|
1677 | 1677 | } |
1678 | 1678 | |
1679 | - if ( true === $contacts['is_redo'] ) { |
|
1680 | - $contacts_refreshed_token = esc_html__( 'This request did require refreshing the Salesforce token', 'object-sync-salesforce' ); |
|
1679 | + if (true === $contacts['is_redo']) { |
|
1680 | + $contacts_refreshed_token = esc_html__('This request did require refreshing the Salesforce token', 'object-sync-salesforce'); |
|
1681 | 1681 | } else { |
1682 | - $contacts_refreshed_token = esc_html__( 'This request did not require refreshing the Salesforce token', 'object-sync-salesforce' ); |
|
1682 | + $contacts_refreshed_token = esc_html__('This request did not require refreshing the Salesforce token', 'object-sync-salesforce'); |
|
1683 | 1683 | } |
1684 | 1684 | |
1685 | 1685 | // 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 |
1686 | - $contacts_apicall_summary = sprintf( esc_html__( 'Salesforce successfully returned %1$s %2$s records. %3$s %4$s. %5$s.', 'object-sync-for-salesforce' ), |
|
1687 | - absint( $contacts['data']['totalSize'] ), |
|
1688 | - esc_html( $contacts['data']['records'][0]['attributes']['type'] ), |
|
1686 | + $contacts_apicall_summary = sprintf(esc_html__('Salesforce successfully returned %1$s %2$s records. %3$s %4$s. %5$s.', 'object-sync-for-salesforce'), |
|
1687 | + absint($contacts['data']['totalSize']), |
|
1688 | + esc_html($contacts['data']['records'][0]['attributes']['type']), |
|
1689 | 1689 | $contacts_is_cached, |
1690 | 1690 | $contacts_from_cache, |
1691 | 1691 | $contacts_refreshed_token |
1692 | 1692 | ); |
1693 | 1693 | |
1694 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/status.php' ); |
|
1694 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/status.php'); |
|
1695 | 1695 | |
1696 | 1696 | } |
1697 | 1697 | |
@@ -1701,12 +1701,12 @@ discard block |
||
1701 | 1701 | * For this plugin at this time, that is the decision we are making: don't do any kind of authorization stuff inside Salesforce |
1702 | 1702 | */ |
1703 | 1703 | private function logout() { |
1704 | - $this->access_token = delete_option( $this->option_prefix . 'access_token' ); |
|
1705 | - $this->instance_url = delete_option( $this->option_prefix . 'instance_url' ); |
|
1706 | - $this->refresh_token = delete_option( $this->option_prefix . 'refresh_token' ); |
|
1707 | - 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>', |
|
1708 | - esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize' ) ), |
|
1709 | - esc_html__( 'Authorize', 'object-sync-for-salesforce' ) |
|
1704 | + $this->access_token = delete_option($this->option_prefix . 'access_token'); |
|
1705 | + $this->instance_url = delete_option($this->option_prefix . 'instance_url'); |
|
1706 | + $this->refresh_token = delete_option($this->option_prefix . 'refresh_token'); |
|
1707 | + 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>', |
|
1708 | + esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize')), |
|
1709 | + esc_html__('Authorize', 'object-sync-for-salesforce') |
|
1710 | 1710 | ); |
1711 | 1711 | } |
1712 | 1712 | |
@@ -1714,28 +1714,28 @@ discard block |
||
1714 | 1714 | * Ajax call to clear the plugin cache. |
1715 | 1715 | */ |
1716 | 1716 | public function clear_sfwp_cache() { |
1717 | - $result = $this->clear_cache( true ); |
|
1717 | + $result = $this->clear_cache(true); |
|
1718 | 1718 | $response = array( |
1719 | 1719 | 'message' => $result['message'], |
1720 | 1720 | 'success' => $result['success'], |
1721 | 1721 | ); |
1722 | - wp_send_json_success( $response ); |
|
1722 | + wp_send_json_success($response); |
|
1723 | 1723 | } |
1724 | 1724 | |
1725 | 1725 | /** |
1726 | 1726 | * Clear the plugin's cache. |
1727 | 1727 | * This uses the flush method contained in the WordPress cache to clear all of this plugin's cached data. |
1728 | 1728 | */ |
1729 | - private function clear_cache( $ajax = false ) { |
|
1729 | + private function clear_cache($ajax = false) { |
|
1730 | 1730 | $result = (bool) $this->wordpress->sfwp_transients->flush(); |
1731 | - if ( true === $result ) { |
|
1732 | - $message = __( 'The plugin cache has been cleared.', 'object-sync-for-salesforce' ); |
|
1731 | + if (true === $result) { |
|
1732 | + $message = __('The plugin cache has been cleared.', 'object-sync-for-salesforce'); |
|
1733 | 1733 | } else { |
1734 | - $message = __( 'There was an error clearing the plugin cache. Try refreshing this page.', 'object-sync-for-salesforce' ); |
|
1734 | + $message = __('There was an error clearing the plugin cache. Try refreshing this page.', 'object-sync-for-salesforce'); |
|
1735 | 1735 | } |
1736 | - if ( false === $ajax ) { |
|
1736 | + if (false === $ajax) { |
|
1737 | 1737 | // translators: parameter 1 is the result message |
1738 | - echo sprintf( '<p>%1$s</p>', $message ); |
|
1738 | + echo sprintf('<p>%1$s</p>', $message); |
|
1739 | 1739 | } else { |
1740 | 1740 | return array( |
1741 | 1741 | 'message' => $message, |
@@ -1758,7 +1758,7 @@ discard block |
||
1758 | 1758 | // alternatively, other roles can get this capability in whatever other way you like |
1759 | 1759 | // point is: to administer this plugin, you need this capability |
1760 | 1760 | |
1761 | - if ( ! current_user_can( 'configure_salesforce' ) ) { |
|
1761 | + if ( ! current_user_can('configure_salesforce')) { |
|
1762 | 1762 | return false; |
1763 | 1763 | } else { |
1764 | 1764 | return true; |
@@ -1771,23 +1771,23 @@ discard block |
||
1771 | 1771 | * @param object $user |
1772 | 1772 | * |
1773 | 1773 | */ |
1774 | - public function show_salesforce_user_fields( $user ) { |
|
1775 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
1776 | - if ( true === $this->check_wordpress_admin_permissions() ) { |
|
1777 | - $mapping = $this->mappings->load_by_wordpress( 'user', $user->ID ); |
|
1774 | + public function show_salesforce_user_fields($user) { |
|
1775 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
1776 | + if (true === $this->check_wordpress_admin_permissions()) { |
|
1777 | + $mapping = $this->mappings->load_by_wordpress('user', $user->ID); |
|
1778 | 1778 | $fieldmap = $this->mappings->get_fieldmaps( |
1779 | 1779 | null, // id field must be null for multiples |
1780 | 1780 | array( |
1781 | 1781 | 'wordpress_object' => 'user', |
1782 | 1782 | ) |
1783 | 1783 | ); |
1784 | - if ( isset( $mapping['id'] ) && ! isset( $get_data['edit_salesforce_mapping'] ) ) { |
|
1785 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce.php' ); |
|
1786 | - } elseif ( ! empty( $fieldmap ) ) { // is the user mapped to something already? |
|
1787 | - if ( isset( $get_data['edit_salesforce_mapping'] ) && 'true' === sanitize_key( $get_data['edit_salesforce_mapping'] ) ) { |
|
1788 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce-change.php' ); |
|
1784 | + if (isset($mapping['id']) && ! isset($get_data['edit_salesforce_mapping'])) { |
|
1785 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce.php'); |
|
1786 | + } elseif ( ! empty($fieldmap)) { // is the user mapped to something already? |
|
1787 | + if (isset($get_data['edit_salesforce_mapping']) && 'true' === sanitize_key($get_data['edit_salesforce_mapping'])) { |
|
1788 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce-change.php'); |
|
1789 | 1789 | } else { |
1790 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce-map.php' ); |
|
1790 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce-map.php'); |
|
1791 | 1791 | } |
1792 | 1792 | } |
1793 | 1793 | } |
@@ -1798,10 +1798,10 @@ discard block |
||
1798 | 1798 | * @param int $user_id |
1799 | 1799 | * |
1800 | 1800 | */ |
1801 | - public function save_salesforce_user_fields( $user_id ) { |
|
1802 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1803 | - if ( isset( $post_data['salesforce_update_mapped_user'] ) && '1' === rawurlencode( $post_data['salesforce_update_mapped_user'] ) ) { |
|
1804 | - $mapping_object = $this->mappings->get_object_maps( |
|
1801 | + public function save_salesforce_user_fields($user_id) { |
|
1802 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1803 | + if (isset($post_data['salesforce_update_mapped_user']) && '1' === rawurlencode($post_data['salesforce_update_mapped_user'])) { |
|
1804 | + $mapping_object = $this->mappings->get_object_maps( |
|
1805 | 1805 | array( |
1806 | 1806 | 'wordpress_id' => $user_id, |
1807 | 1807 | 'wordpress_object' => 'user', |
@@ -1809,14 +1809,14 @@ discard block |
||
1809 | 1809 | ); |
1810 | 1810 | $mapping_object['salesforce_id'] = $post_data['salesforce_id']; |
1811 | 1811 | |
1812 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1813 | - } elseif ( isset( $post_data['salesforce_create_mapped_user'] ) && '1' === rawurlencode( $post_data['salesforce_create_mapped_user'] ) ) { |
|
1812 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1813 | + } elseif (isset($post_data['salesforce_create_mapped_user']) && '1' === rawurlencode($post_data['salesforce_create_mapped_user'])) { |
|
1814 | 1814 | // if a Salesforce ID was entered |
1815 | - if ( isset( $post_data['salesforce_id'] ) && ! empty( $post_data['salesforce_id'] ) ) { |
|
1816 | - $mapping_object = $this->create_object_map( $user_id, 'user', $post_data['salesforce_id'] ); |
|
1817 | - } elseif ( isset( $post_data['push_new_user_to_salesforce'] ) ) { |
|
1815 | + if (isset($post_data['salesforce_id']) && ! empty($post_data['salesforce_id'])) { |
|
1816 | + $mapping_object = $this->create_object_map($user_id, 'user', $post_data['salesforce_id']); |
|
1817 | + } elseif (isset($post_data['push_new_user_to_salesforce'])) { |
|
1818 | 1818 | // otherwise, create a new record in Salesforce |
1819 | - $result = $this->push_to_salesforce( 'user', $user_id ); |
|
1819 | + $result = $this->push_to_salesforce('user', $user_id); |
|
1820 | 1820 | } |
1821 | 1821 | } |
1822 | 1822 | } |
@@ -1826,29 +1826,29 @@ discard block |
||
1826 | 1826 | * @param array $tabs |
1827 | 1827 | * @param string $tab |
1828 | 1828 | */ |
1829 | - private function tabs( $tabs, $tab = '' ) { |
|
1829 | + private function tabs($tabs, $tab = '') { |
|
1830 | 1830 | |
1831 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
1831 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
1832 | 1832 | $consumer_key = $this->login_credentials['consumer_key']; |
1833 | 1833 | $consumer_secret = $this->login_credentials['consumer_secret']; |
1834 | 1834 | $callback_url = $this->login_credentials['callback_url']; |
1835 | 1835 | |
1836 | 1836 | $current_tab = $tab; |
1837 | 1837 | echo '<h2 class="nav-tab-wrapper">'; |
1838 | - foreach ( $tabs as $tab_key => $tab_caption ) { |
|
1838 | + foreach ($tabs as $tab_key => $tab_caption) { |
|
1839 | 1839 | $active = $current_tab === $tab_key ? ' nav-tab-active' : ''; |
1840 | - if ( 'settings' === $tab_key || ( isset( $consumer_key ) && isset( $consumer_secret ) && ! empty( $consumer_key ) && ! empty( $consumer_secret ) ) ) { |
|
1841 | - echo sprintf( '<a class="nav-tab%1$s" href="%2$s">%3$s</a>', |
|
1842 | - esc_attr( $active ), |
|
1843 | - esc_url( '?page=object-sync-salesforce-admin&tab=' . $tab_key ), |
|
1844 | - esc_html( $tab_caption ) |
|
1840 | + if ('settings' === $tab_key || (isset($consumer_key) && isset($consumer_secret) && ! empty($consumer_key) && ! empty($consumer_secret))) { |
|
1841 | + echo sprintf('<a class="nav-tab%1$s" href="%2$s">%3$s</a>', |
|
1842 | + esc_attr($active), |
|
1843 | + esc_url('?page=object-sync-salesforce-admin&tab=' . $tab_key), |
|
1844 | + esc_html($tab_caption) |
|
1845 | 1845 | ); |
1846 | 1846 | } |
1847 | 1847 | } |
1848 | 1848 | echo '</h2>'; |
1849 | 1849 | |
1850 | - if ( isset( $get_data['tab'] ) ) { |
|
1851 | - $tab = sanitize_key( $get_data['tab'] ); |
|
1850 | + if (isset($get_data['tab'])) { |
|
1851 | + $tab = sanitize_key($get_data['tab']); |
|
1852 | 1852 | } else { |
1853 | 1853 | $tab = ''; |
1854 | 1854 | } |
@@ -1858,21 +1858,21 @@ discard block |
||
1858 | 1858 | * Clear schedule |
1859 | 1859 | * This clears the schedule if the user clicks the button |
1860 | 1860 | */ |
1861 | - private function clear_schedule( $schedule_name = '' ) { |
|
1862 | - if ( '' !== $schedule_name ) { |
|
1863 | - $schedule = $this->schedule( $schedule_name ); |
|
1864 | - $schedule->cancel_by_name( $schedule_name ); |
|
1861 | + private function clear_schedule($schedule_name = '') { |
|
1862 | + if ('' !== $schedule_name) { |
|
1863 | + $schedule = $this->schedule($schedule_name); |
|
1864 | + $schedule->cancel_by_name($schedule_name); |
|
1865 | 1865 | // translators: $schedule_name is the name of the current queue. Defaults: salesforce_pull, salesforce_push, salesforce |
1866 | - echo sprintf( esc_html__( 'You have cleared the %s schedule.', 'object-sync-for-salesforce' ), esc_html( $schedule_name ) ); |
|
1866 | + echo sprintf(esc_html__('You have cleared the %s schedule.', 'object-sync-for-salesforce'), esc_html($schedule_name)); |
|
1867 | 1867 | } else { |
1868 | - echo esc_html__( 'You need to specify the name of the schedule you want to clear.', 'object-sync-for-salesforce' ); |
|
1868 | + echo esc_html__('You need to specify the name of the schedule you want to clear.', 'object-sync-for-salesforce'); |
|
1869 | 1869 | } |
1870 | 1870 | } |
1871 | 1871 | |
1872 | - private function get_schedule_count( $schedule_name = '' ) { |
|
1873 | - if ( '' !== $schedule_name ) { |
|
1874 | - $schedule = $this->schedule( $schedule_name ); |
|
1875 | - return $this->schedule->count_queue_items( $schedule_name ); |
|
1872 | + private function get_schedule_count($schedule_name = '') { |
|
1873 | + if ('' !== $schedule_name) { |
|
1874 | + $schedule = $this->schedule($schedule_name); |
|
1875 | + return $this->schedule->count_queue_items($schedule_name); |
|
1876 | 1876 | } else { |
1877 | 1877 | return 'unknown'; |
1878 | 1878 | } |
@@ -1881,12 +1881,12 @@ discard block |
||
1881 | 1881 | /** |
1882 | 1882 | * Load the schedule class |
1883 | 1883 | */ |
1884 | - private function schedule( $schedule_name ) { |
|
1885 | - if ( ! class_exists( 'Object_Sync_Sf_Schedule' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) { |
|
1886 | - require_once plugin_dir_path( __FILE__ ) . '../vendor/autoload.php'; |
|
1887 | - require_once plugin_dir_path( __FILE__ ) . '../classes/schedule.php'; |
|
1884 | + private function schedule($schedule_name) { |
|
1885 | + if ( ! class_exists('Object_Sync_Sf_Schedule') && file_exists(plugin_dir_path(__FILE__) . '../vendor/autoload.php')) { |
|
1886 | + require_once plugin_dir_path(__FILE__) . '../vendor/autoload.php'; |
|
1887 | + require_once plugin_dir_path(__FILE__) . '../classes/schedule.php'; |
|
1888 | 1888 | } |
1889 | - $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 ); |
|
1889 | + $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); |
|
1890 | 1890 | $this->schedule = $schedule; |
1891 | 1891 | return $schedule; |
1892 | 1892 | } |
@@ -1907,17 +1907,17 @@ discard block |
||
1907 | 1907 | * This is the database row for the map object |
1908 | 1908 | * |
1909 | 1909 | */ |
1910 | - private function create_object_map( $wordpress_id, $wordpress_object, $salesforce_id, $action = '' ) { |
|
1910 | + private function create_object_map($wordpress_id, $wordpress_object, $salesforce_id, $action = '') { |
|
1911 | 1911 | // Create object map and save it |
1912 | 1912 | $mapping_object = $this->mappings->create_object_map( |
1913 | 1913 | array( |
1914 | 1914 | 'wordpress_id' => $wordpress_id, // wordpress unique id |
1915 | 1915 | 'salesforce_id' => $salesforce_id, // salesforce unique id. we don't care what kind of object it is at this point |
1916 | 1916 | 'wordpress_object' => $wordpress_object, // keep track of what kind of wp object this is |
1917 | - 'last_sync' => current_time( 'mysql' ), |
|
1917 | + 'last_sync' => current_time('mysql'), |
|
1918 | 1918 | 'last_sync_action' => $action, |
1919 | 1919 | 'last_sync_status' => $this->mappings->status_success, |
1920 | - 'last_sync_message' => __( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
1920 | + 'last_sync_message' => __('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
1921 | 1921 | ) |
1922 | 1922 | ); |
1923 | 1923 |
@@ -24,24 +24,24 @@ discard block |
||
24 | 24 | protected $schedulable_classes; |
25 | 25 | |
26 | 26 | /** |
27 | - * @var string |
|
28 | - */ |
|
27 | + * @var string |
|
28 | + */ |
|
29 | 29 | public $schedule_name; // allow for naming the queue in case there are multiple queues |
30 | 30 | |
31 | 31 | /** |
32 | - * Constructor which sets up push schedule |
|
33 | - * |
|
34 | - * @param object $wpdb |
|
35 | - * @param string $version |
|
36 | - * @param array $login_credentials |
|
37 | - * @param string $slug |
|
38 | - * @param object $wordpress |
|
39 | - * @param object $salesforce |
|
40 | - * @param object $mappings |
|
41 | - * @param object $logging |
|
42 | - * @param array $schedulable_classes |
|
43 | - * @throws \Object_Sync_Sf_Exception |
|
44 | - */ |
|
32 | + * Constructor which sets up push schedule |
|
33 | + * |
|
34 | + * @param object $wpdb |
|
35 | + * @param string $version |
|
36 | + * @param array $login_credentials |
|
37 | + * @param string $slug |
|
38 | + * @param object $wordpress |
|
39 | + * @param object $salesforce |
|
40 | + * @param object $mappings |
|
41 | + * @param object $logging |
|
42 | + * @param array $schedulable_classes |
|
43 | + * @throws \Object_Sync_Sf_Exception |
|
44 | + */ |
|
45 | 45 | public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes ) { |
46 | 46 | $this->wpdb = $wpdb; |
47 | 47 | $this->version = $version; |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | - * Create the action hooks based on what object maps exist from the admin settings. |
|
66 | - * We do not have any actions for blogroll at this time. |
|
67 | - * |
|
68 | - */ |
|
65 | + * Create the action hooks based on what object maps exist from the admin settings. |
|
66 | + * We do not have any actions for blogroll at this time. |
|
67 | + * |
|
68 | + */ |
|
69 | 69 | private function add_actions() { |
70 | 70 | $db_version = get_option( 'object_sync_for_salesforce_db_version', false ); |
71 | 71 | if ( $db_version === $this->version ) { |
@@ -97,54 +97,54 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | - * Method for ajax hooks to call for pushing manually |
|
101 | - * |
|
102 | - * @param array $object |
|
103 | - * @param string $type |
|
104 | - * |
|
105 | - */ |
|
100 | + * Method for ajax hooks to call for pushing manually |
|
101 | + * |
|
102 | + * @param array $object |
|
103 | + * @param string $type |
|
104 | + * |
|
105 | + */ |
|
106 | 106 | public function manual_object_update( $object, $type ) { |
107 | 107 | $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update, true ); |
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | - * Callback method for adding a user |
|
112 | - * |
|
113 | - * @param string $user_id |
|
114 | - */ |
|
111 | + * Callback method for adding a user |
|
112 | + * |
|
113 | + * @param string $user_id |
|
114 | + */ |
|
115 | 115 | public function add_user( $user_id ) { |
116 | 116 | $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
117 | 117 | $this->object_insert( $user, 'user' ); |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Callback method for editing a user |
|
122 | - * |
|
123 | - * @param string $user_id |
|
124 | - * @param object $old_user_data |
|
125 | - */ |
|
121 | + * Callback method for editing a user |
|
122 | + * |
|
123 | + * @param string $user_id |
|
124 | + * @param object $old_user_data |
|
125 | + */ |
|
126 | 126 | public function edit_user( $user_id, $old_user_data ) { |
127 | 127 | $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
128 | 128 | $this->object_update( $user, 'user' ); |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * Callback method for deleting a user |
|
133 | - * |
|
134 | - * @param string $user_id |
|
135 | - */ |
|
132 | + * Callback method for deleting a user |
|
133 | + * |
|
134 | + * @param string $user_id |
|
135 | + */ |
|
136 | 136 | public function delete_user( $user_id ) { |
137 | 137 | $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
138 | 138 | $this->object_delete( $user, 'user' ); |
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | - * Callback method for posts of any type |
|
143 | - * This can handle create, update, and delete actions |
|
144 | - * |
|
145 | - * @param string $post_id |
|
146 | - * @param object $post |
|
147 | - */ |
|
142 | + * Callback method for posts of any type |
|
143 | + * This can handle create, update, and delete actions |
|
144 | + * |
|
145 | + * @param string $post_id |
|
146 | + * @param object $post |
|
147 | + */ |
|
148 | 148 | public function post_actions( $post_id, $post ) { |
149 | 149 | |
150 | 150 | $post_type = $post->post_type; |
@@ -191,66 +191,66 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * Callback method for adding an attachment |
|
195 | - * |
|
196 | - * @param string $post_id |
|
197 | - */ |
|
194 | + * Callback method for adding an attachment |
|
195 | + * |
|
196 | + * @param string $post_id |
|
197 | + */ |
|
198 | 198 | public function add_attachment( $post_id ) { |
199 | 199 | $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
200 | 200 | $this->object_insert( $attachment, 'attachment' ); |
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
204 | - * Callback method for editing an attachment |
|
205 | - * |
|
206 | - * @param string $post_id |
|
207 | - */ |
|
204 | + * Callback method for editing an attachment |
|
205 | + * |
|
206 | + * @param string $post_id |
|
207 | + */ |
|
208 | 208 | public function edit_attachment( $post_id ) { |
209 | 209 | $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
210 | 210 | $this->object_update( $attachment, 'attachment' ); |
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | - * Callback method for editing an attachment |
|
215 | - * |
|
216 | - * @param string $post_id |
|
217 | - */ |
|
214 | + * Callback method for editing an attachment |
|
215 | + * |
|
216 | + * @param string $post_id |
|
217 | + */ |
|
218 | 218 | public function delete_attachment( $post_id ) { |
219 | 219 | $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
220 | 220 | $this->object_delete( $attachment, 'attachment' ); |
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * Callback method for adding a term |
|
225 | - * |
|
226 | - * @param string $term_id |
|
227 | - * @param string $tt_id |
|
228 | - * @param string $taxonomy |
|
229 | - */ |
|
224 | + * Callback method for adding a term |
|
225 | + * |
|
226 | + * @param string $term_id |
|
227 | + * @param string $tt_id |
|
228 | + * @param string $taxonomy |
|
229 | + */ |
|
230 | 230 | public function add_term( $term_id, $tt_id, $taxonomy ) { |
231 | 231 | $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
232 | 232 | $this->object_insert( $term, $taxonomy ); |
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
236 | - * Callback method for editing a term |
|
237 | - * |
|
238 | - * @param string $term_id |
|
239 | - * @param string $taxonomy |
|
240 | - */ |
|
236 | + * Callback method for editing a term |
|
237 | + * |
|
238 | + * @param string $term_id |
|
239 | + * @param string $taxonomy |
|
240 | + */ |
|
241 | 241 | public function edit_term( $term_id, $taxonomy ) { |
242 | 242 | $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
243 | 243 | $this->object_update( $term, $taxonomy ); |
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
247 | - * Callback method for deleting a term |
|
248 | - * |
|
249 | - * @param int $term (id) |
|
250 | - * @param int $term_taxonomy_id |
|
251 | - * @param string $taxonomy (slug) |
|
252 | - * @param object $deleted_term |
|
253 | - */ |
|
247 | + * Callback method for deleting a term |
|
248 | + * |
|
249 | + * @param int $term (id) |
|
250 | + * @param int $term_taxonomy_id |
|
251 | + * @param string $taxonomy (slug) |
|
252 | + * @param object $deleted_term |
|
253 | + */ |
|
254 | 254 | public function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) { |
255 | 255 | $deleted_term = (array) $deleted_term; |
256 | 256 | $type = $deleted_term['taxonomy']; |
@@ -258,75 +258,75 @@ discard block |
||
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Callback method for adding a comment |
|
262 | - * |
|
263 | - * @param string $comment_id |
|
264 | - * @param int|string comment_approved |
|
265 | - * @param array $commentdata |
|
266 | - */ |
|
261 | + * Callback method for adding a comment |
|
262 | + * |
|
263 | + * @param string $comment_id |
|
264 | + * @param int|string comment_approved |
|
265 | + * @param array $commentdata |
|
266 | + */ |
|
267 | 267 | public function add_comment( $comment_id, $comment_approved, $commentdata = array() ) { |
268 | 268 | $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
269 | 269 | $this->object_insert( $comment, 'comment' ); |
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | - * Callback method for editing a comment |
|
274 | - * |
|
275 | - * @param string $comment_id |
|
276 | - */ |
|
273 | + * Callback method for editing a comment |
|
274 | + * |
|
275 | + * @param string $comment_id |
|
276 | + */ |
|
277 | 277 | public function edit_comment( $comment_id ) { |
278 | 278 | $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
279 | 279 | $this->object_update( $comment, 'comment' ); |
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
283 | - * Callback method for deleting a comment |
|
284 | - * |
|
285 | - * @param string $comment_id |
|
286 | - */ |
|
283 | + * Callback method for deleting a comment |
|
284 | + * |
|
285 | + * @param string $comment_id |
|
286 | + */ |
|
287 | 287 | public function delete_comment( $comment_id ) { |
288 | 288 | $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
289 | 289 | $this->object_delete( $comment, 'comment' ); |
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
293 | - * Insert a new object |
|
294 | - * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
295 | - */ |
|
293 | + * Insert a new object |
|
294 | + * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
295 | + */ |
|
296 | 296 | private function object_insert( $object, $type ) { |
297 | 297 | $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_create ); |
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
301 | - * Update an existing object |
|
302 | - * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
303 | - */ |
|
301 | + * Update an existing object |
|
302 | + * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
303 | + */ |
|
304 | 304 | private function object_update( $object, $type ) { |
305 | 305 | $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update ); |
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | - * Delete an existing object |
|
310 | - * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
311 | - */ |
|
309 | + * Delete an existing object |
|
310 | + * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
|
311 | + */ |
|
312 | 312 | private function object_delete( $object, $type ) { |
313 | 313 | $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_delete ); |
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
317 | - * Push objects to Salesforce. |
|
318 | - * This method decides whether to do the processing immediately or queue it to the schedule class (or skip it based on another plugin's activity) |
|
319 | - * |
|
320 | - * @param string $object_type |
|
321 | - * Type of WordPress object. |
|
322 | - * @param array $object |
|
323 | - * The WordPress data that needs to be sent to Salesforce. |
|
324 | - * @param int $sf_sync_trigger |
|
325 | - * The trigger being responded to. |
|
326 | - * @param bool $manual |
|
327 | - * Are we calling this manually? |
|
328 | - * |
|
329 | - */ |
|
317 | + * Push objects to Salesforce. |
|
318 | + * This method decides whether to do the processing immediately or queue it to the schedule class (or skip it based on another plugin's activity) |
|
319 | + * |
|
320 | + * @param string $object_type |
|
321 | + * Type of WordPress object. |
|
322 | + * @param array $object |
|
323 | + * The WordPress data that needs to be sent to Salesforce. |
|
324 | + * @param int $sf_sync_trigger |
|
325 | + * The trigger being responded to. |
|
326 | + * @param bool $manual |
|
327 | + * Are we calling this manually? |
|
328 | + * |
|
329 | + */ |
|
330 | 330 | private function salesforce_push_object_crud( $object_type, $object, $sf_sync_trigger, $manual = false ) { |
331 | 331 | |
332 | 332 | $structure = $this->wordpress->get_wordpress_table_structure( $object_type ); |
@@ -451,20 +451,20 @@ discard block |
||
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
454 | - * Sync WordPress objects and Salesforce objects using the REST API. |
|
455 | - * |
|
456 | - * @param string $object_type |
|
457 | - * Type of WordPress object. |
|
458 | - * @param object $object |
|
459 | - * The object object. |
|
460 | - * @param object $mapping |
|
461 | - * Salesforce mapping object. |
|
462 | - * @param int $sf_sync_trigger |
|
463 | - * Trigger for this sync. |
|
464 | - * |
|
465 | - * @return true or exit the method |
|
466 | - * |
|
467 | - */ |
|
454 | + * Sync WordPress objects and Salesforce objects using the REST API. |
|
455 | + * |
|
456 | + * @param string $object_type |
|
457 | + * Type of WordPress object. |
|
458 | + * @param object $object |
|
459 | + * The object object. |
|
460 | + * @param object $mapping |
|
461 | + * Salesforce mapping object. |
|
462 | + * @param int $sf_sync_trigger |
|
463 | + * Trigger for this sync. |
|
464 | + * |
|
465 | + * @return true or exit the method |
|
466 | + * |
|
467 | + */ |
|
468 | 468 | public function salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ) { |
469 | 469 | |
470 | 470 | // If Salesforce is not authorized, don't do anything. |
@@ -1006,21 +1006,21 @@ discard block |
||
1006 | 1006 | } |
1007 | 1007 | |
1008 | 1008 | /** |
1009 | - * Create an object map between a WordPress object and a Salesforce object |
|
1010 | - * |
|
1011 | - * @param array $wordpress_object |
|
1012 | - * Array of the WordPress object's data |
|
1013 | - * @param string $id_field_name |
|
1014 | - * How this object names its primary field. ie Id or comment_id or whatever |
|
1015 | - * @param string $salesforce_id |
|
1016 | - * Unique identifier for the Salesforce object |
|
1017 | - * @param array $field_mapping |
|
1018 | - * The row that maps the object types together, including which fields match which other fields |
|
1019 | - * |
|
1020 | - * @return int $wpdb->insert_id |
|
1021 | - * This is the database row for the map object |
|
1022 | - * |
|
1023 | - */ |
|
1009 | + * Create an object map between a WordPress object and a Salesforce object |
|
1010 | + * |
|
1011 | + * @param array $wordpress_object |
|
1012 | + * Array of the WordPress object's data |
|
1013 | + * @param string $id_field_name |
|
1014 | + * How this object names its primary field. ie Id or comment_id or whatever |
|
1015 | + * @param string $salesforce_id |
|
1016 | + * Unique identifier for the Salesforce object |
|
1017 | + * @param array $field_mapping |
|
1018 | + * The row that maps the object types together, including which fields match which other fields |
|
1019 | + * |
|
1020 | + * @return int $wpdb->insert_id |
|
1021 | + * This is the database row for the map object |
|
1022 | + * |
|
1023 | + */ |
|
1024 | 1024 | private function create_object_map( $wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false ) { |
1025 | 1025 | |
1026 | 1026 | if ( true === $pending ) { |
@@ -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 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param array $schedulable_classes |
43 | 43 | * @throws \Object_Sync_Sf_Exception |
44 | 44 | */ |
45 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes ) { |
|
45 | + public function __construct($wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes) { |
|
46 | 46 | $this->wpdb = $wpdb; |
47 | 47 | $this->version = $version; |
48 | 48 | $this->login_credentials = $login_credentials; |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $this->schedule = $this->schedule(); |
58 | 58 | $this->add_actions(); |
59 | 59 | |
60 | - $this->debug = get_option( 'object_sync_for_salesforce_debug_mode', false ); |
|
60 | + $this->debug = get_option('object_sync_for_salesforce_debug_mode', false); |
|
61 | 61 | |
62 | 62 | } |
63 | 63 | |
@@ -67,31 +67,31 @@ discard block |
||
67 | 67 | * |
68 | 68 | */ |
69 | 69 | private function add_actions() { |
70 | - $db_version = get_option( 'object_sync_for_salesforce_db_version', false ); |
|
71 | - if ( $db_version === $this->version ) { |
|
72 | - foreach ( $this->mappings->get_fieldmaps() as $mapping ) { |
|
70 | + $db_version = get_option('object_sync_for_salesforce_db_version', false); |
|
71 | + if ($db_version === $this->version) { |
|
72 | + foreach ($this->mappings->get_fieldmaps() as $mapping) { |
|
73 | 73 | $object_type = $mapping['wordpress_object']; |
74 | - if ( 'user' === $object_type ) { |
|
75 | - add_action( 'user_register', array( $this, 'add_user' ), 11, 1 ); |
|
76 | - add_action( 'profile_update', array( $this, 'edit_user' ), 11, 2 ); |
|
77 | - add_action( 'delete_user', array( $this, 'delete_user' ) ); |
|
78 | - } elseif ( 'post' === $object_type ) { |
|
79 | - add_action( 'save_post', array( $this, 'post_actions' ), 11, 2 ); |
|
80 | - } elseif ( 'attachment' === $object_type ) { |
|
81 | - add_action( 'add_attachment', array( $this, 'add_attachment' ) ); |
|
82 | - add_action( 'edit_attachment', array( $this, 'edit_attachment' ) ); |
|
83 | - add_action( 'delete_attachment', array( $this, 'delete_attachment' ) ); |
|
84 | - } elseif ( 'category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type ) { |
|
85 | - add_action( 'create_term', array( $this, 'add_term' ), 11, 3 ); |
|
86 | - add_action( 'edit_terms', array( $this, 'edit_term' ), 11, 2 ); |
|
87 | - add_action( 'delete_term', array( $this, 'delete_term' ), 10, 4 ); |
|
88 | - } elseif ( 'comment' === $object_type ) { |
|
89 | - add_action( 'comment_post', array( $this, 'add_comment' ), 11, 3 ); |
|
90 | - add_action( 'edit_comment', array( $this, 'edit_comment' ) ); |
|
91 | - add_action( 'delete_comment', array( $this, 'delete_comment' ) ); // to be clear: this only runs when the comment gets deleted from the trash, either manually or automatically |
|
74 | + if ('user' === $object_type) { |
|
75 | + add_action('user_register', array($this, 'add_user'), 11, 1); |
|
76 | + add_action('profile_update', array($this, 'edit_user'), 11, 2); |
|
77 | + add_action('delete_user', array($this, 'delete_user')); |
|
78 | + } elseif ('post' === $object_type) { |
|
79 | + add_action('save_post', array($this, 'post_actions'), 11, 2); |
|
80 | + } elseif ('attachment' === $object_type) { |
|
81 | + add_action('add_attachment', array($this, 'add_attachment')); |
|
82 | + add_action('edit_attachment', array($this, 'edit_attachment')); |
|
83 | + add_action('delete_attachment', array($this, 'delete_attachment')); |
|
84 | + } elseif ('category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type) { |
|
85 | + add_action('create_term', array($this, 'add_term'), 11, 3); |
|
86 | + add_action('edit_terms', array($this, 'edit_term'), 11, 2); |
|
87 | + add_action('delete_term', array($this, 'delete_term'), 10, 4); |
|
88 | + } elseif ('comment' === $object_type) { |
|
89 | + add_action('comment_post', array($this, 'add_comment'), 11, 3); |
|
90 | + add_action('edit_comment', array($this, 'edit_comment')); |
|
91 | + add_action('delete_comment', array($this, 'delete_comment')); // to be clear: this only runs when the comment gets deleted from the trash, either manually or automatically |
|
92 | 92 | } else { // this is for custom post types |
93 | 93 | // we still have to use save_post because save_post_type fails to pull in the metadata |
94 | - add_action( 'save_post', array( $this, 'post_actions' ), 11, 2 ); |
|
94 | + add_action('save_post', array($this, 'post_actions'), 11, 2); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | } |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @param string $type |
105 | 105 | * |
106 | 106 | */ |
107 | - public function manual_object_update( $object, $type ) { |
|
108 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update, true ); |
|
107 | + public function manual_object_update($object, $type) { |
|
108 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_update, true); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @param string $user_id |
115 | 115 | */ |
116 | - public function add_user( $user_id ) { |
|
117 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
118 | - $this->object_insert( $user, 'user' ); |
|
116 | + public function add_user($user_id) { |
|
117 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
118 | + $this->object_insert($user, 'user'); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * @param string $user_id |
125 | 125 | * @param object $old_user_data |
126 | 126 | */ |
127 | - public function edit_user( $user_id, $old_user_data ) { |
|
128 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
129 | - $this->object_update( $user, 'user' ); |
|
127 | + public function edit_user($user_id, $old_user_data) { |
|
128 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
129 | + $this->object_update($user, 'user'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param string $user_id |
136 | 136 | */ |
137 | - public function delete_user( $user_id ) { |
|
138 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
139 | - $this->object_delete( $user, 'user' ); |
|
137 | + public function delete_user($user_id) { |
|
138 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
139 | + $this->object_delete($user, 'user'); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,48 +146,48 @@ discard block |
||
146 | 146 | * @param string $post_id |
147 | 147 | * @param object $post |
148 | 148 | */ |
149 | - public function post_actions( $post_id, $post ) { |
|
149 | + public function post_actions($post_id, $post) { |
|
150 | 150 | |
151 | 151 | $post_type = $post->post_type; |
152 | 152 | |
153 | - if ( isset( $post->post_status ) && 'auto-draft' === $post->post_status ) { |
|
153 | + if (isset($post->post_status) && 'auto-draft' === $post->post_status) { |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 | // this plugin does not sync log or revision posts with salesforce |
157 | - if ( isset( $post->post_type ) && in_array( $post->post_type, array( 'wp_log', 'revision' ), true ) ) { |
|
157 | + if (isset($post->post_type) && in_array($post->post_type, array('wp_log', 'revision'), true)) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | - if ( $post->post_modified_gmt === $post->post_date_gmt && 'trash' !== $post->post_status ) { |
|
160 | + if ($post->post_modified_gmt === $post->post_date_gmt && 'trash' !== $post->post_status) { |
|
161 | 161 | $update = 0; |
162 | 162 | $delete = 0; |
163 | - } elseif ( 'trash' !== $post->post_status ) { |
|
163 | + } elseif ('trash' !== $post->post_status) { |
|
164 | 164 | $update = 1; |
165 | 165 | $delete = 0; |
166 | - } elseif ( 'trash' === $post->post_status ) { |
|
166 | + } elseif ('trash' === $post->post_status) { |
|
167 | 167 | $update = 0; |
168 | 168 | $delete = 1; |
169 | 169 | } |
170 | 170 | |
171 | 171 | // add support for woocommerce if it is installed |
172 | - if ( defined( 'WC_VERSION' ) ) { |
|
172 | + if (defined('WC_VERSION')) { |
|
173 | 173 | // statuses to ignore |
174 | - if ( isset( $post->post_status ) && in_array( $post->post_status, array( 'wc-pending' ), true ) ) { |
|
174 | + if (isset($post->post_status) && in_array($post->post_status, array('wc-pending'), true)) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | // statuses to count as new. note that the api will also check to see if it already has been mapped before saving. |
178 | - if ( isset( $post->post_status ) && in_array( $post->post_status, array( 'wc-on-hold', 'wc-processing' ), true ) ) { |
|
178 | + if (isset($post->post_status) && in_array($post->post_status, array('wc-on-hold', 'wc-processing'), true)) { |
|
179 | 179 | $update = 0; |
180 | 180 | $delete = 0; |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | - $post = $this->wordpress->get_wordpress_object_data( $post->post_type, $post_id ); |
|
185 | - if ( 1 === $update ) { |
|
186 | - $this->object_update( $post, $post_type ); |
|
187 | - } elseif ( 1 === $delete ) { |
|
188 | - $this->object_delete( $post, $post_type ); |
|
184 | + $post = $this->wordpress->get_wordpress_object_data($post->post_type, $post_id); |
|
185 | + if (1 === $update) { |
|
186 | + $this->object_update($post, $post_type); |
|
187 | + } elseif (1 === $delete) { |
|
188 | + $this->object_delete($post, $post_type); |
|
189 | 189 | } else { |
190 | - $this->object_insert( $post, $post_type ); |
|
190 | + $this->object_insert($post, $post_type); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @param string $post_id |
198 | 198 | */ |
199 | - public function add_attachment( $post_id ) { |
|
200 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
201 | - $this->object_insert( $attachment, 'attachment' ); |
|
199 | + public function add_attachment($post_id) { |
|
200 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
201 | + $this->object_insert($attachment, 'attachment'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @param string $post_id |
208 | 208 | */ |
209 | - public function edit_attachment( $post_id ) { |
|
210 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
211 | - $this->object_update( $attachment, 'attachment' ); |
|
209 | + public function edit_attachment($post_id) { |
|
210 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
211 | + $this->object_update($attachment, 'attachment'); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @param string $post_id |
218 | 218 | */ |
219 | - public function delete_attachment( $post_id ) { |
|
220 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
221 | - $this->object_delete( $attachment, 'attachment' ); |
|
219 | + public function delete_attachment($post_id) { |
|
220 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
221 | + $this->object_delete($attachment, 'attachment'); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | * @param string $tt_id |
229 | 229 | * @param string $taxonomy |
230 | 230 | */ |
231 | - public function add_term( $term_id, $tt_id, $taxonomy ) { |
|
232 | - $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
|
233 | - $this->object_insert( $term, $taxonomy ); |
|
231 | + public function add_term($term_id, $tt_id, $taxonomy) { |
|
232 | + $term = $this->wordpress->get_wordpress_object_data($taxonomy, $term_id); |
|
233 | + $this->object_insert($term, $taxonomy); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | * @param string $term_id |
240 | 240 | * @param string $taxonomy |
241 | 241 | */ |
242 | - public function edit_term( $term_id, $taxonomy ) { |
|
243 | - $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
|
244 | - $this->object_update( $term, $taxonomy ); |
|
242 | + public function edit_term($term_id, $taxonomy) { |
|
243 | + $term = $this->wordpress->get_wordpress_object_data($taxonomy, $term_id); |
|
244 | + $this->object_update($term, $taxonomy); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | * @param string $taxonomy (slug) |
253 | 253 | * @param object $deleted_term |
254 | 254 | */ |
255 | - public function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) { |
|
255 | + public function delete_term($term, $tt_id, $taxonomy, $deleted_term) { |
|
256 | 256 | $deleted_term = (array) $deleted_term; |
257 | 257 | $type = $deleted_term['taxonomy']; |
258 | - $this->object_delete( $deleted_term, $type ); |
|
258 | + $this->object_delete($deleted_term, $type); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -265,9 +265,9 @@ discard block |
||
265 | 265 | * @param int|string comment_approved |
266 | 266 | * @param array $commentdata |
267 | 267 | */ |
268 | - public function add_comment( $comment_id, $comment_approved, $commentdata = array() ) { |
|
269 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
270 | - $this->object_insert( $comment, 'comment' ); |
|
268 | + public function add_comment($comment_id, $comment_approved, $commentdata = array()) { |
|
269 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
270 | + $this->object_insert($comment, 'comment'); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @param string $comment_id |
277 | 277 | */ |
278 | - public function edit_comment( $comment_id ) { |
|
279 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
280 | - $this->object_update( $comment, 'comment' ); |
|
278 | + public function edit_comment($comment_id) { |
|
279 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
280 | + $this->object_update($comment, 'comment'); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -285,33 +285,33 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @param string $comment_id |
287 | 287 | */ |
288 | - public function delete_comment( $comment_id ) { |
|
289 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
290 | - $this->object_delete( $comment, 'comment' ); |
|
288 | + public function delete_comment($comment_id) { |
|
289 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
290 | + $this->object_delete($comment, 'comment'); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | 294 | * Insert a new object |
295 | 295 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
296 | 296 | */ |
297 | - private function object_insert( $object, $type ) { |
|
298 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_create ); |
|
297 | + private function object_insert($object, $type) { |
|
298 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_create); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
302 | 302 | * Update an existing object |
303 | 303 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
304 | 304 | */ |
305 | - private function object_update( $object, $type ) { |
|
306 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update ); |
|
305 | + private function object_update($object, $type) { |
|
306 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_update); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | 310 | * Delete an existing object |
311 | 311 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
312 | 312 | */ |
313 | - private function object_delete( $object, $type ) { |
|
314 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_delete ); |
|
313 | + private function object_delete($object, $type) { |
|
314 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_delete); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -328,50 +328,50 @@ discard block |
||
328 | 328 | * Are we calling this manually? |
329 | 329 | * |
330 | 330 | */ |
331 | - private function salesforce_push_object_crud( $object_type, $object, $sf_sync_trigger, $manual = false ) { |
|
331 | + private function salesforce_push_object_crud($object_type, $object, $sf_sync_trigger, $manual = false) { |
|
332 | 332 | |
333 | - $structure = $this->wordpress->get_wordpress_table_structure( $object_type ); |
|
333 | + $structure = $this->wordpress->get_wordpress_table_structure($object_type); |
|
334 | 334 | $object_id_field = $structure['id_field']; |
335 | 335 | |
336 | 336 | // there is a WordPress object to push |
337 | - if ( isset( $object[ $object_id_field ] ) ) { |
|
338 | - $mapping_object = $this->mappings->load_by_wordpress( $object_type, $object[ $object_id_field ] ); |
|
337 | + if (isset($object[$object_id_field])) { |
|
338 | + $mapping_object = $this->mappings->load_by_wordpress($object_type, $object[$object_id_field]); |
|
339 | 339 | |
340 | 340 | // there is already a mapping object for this WordPress object |
341 | - if ( isset( $mapping_object['id'] ) ) { |
|
341 | + if (isset($mapping_object['id'])) { |
|
342 | 342 | $mapping_object_id_transient = $mapping_object['id']; |
343 | 343 | } else { |
344 | 344 | // there is not a mapping object for this WordPress object id yet |
345 | 345 | // check for that transient with the currently pulling id |
346 | - $mapping_object_id_transient = (int) get_transient( 'salesforce_pulling_object_id' ); |
|
346 | + $mapping_object_id_transient = (int) get_transient('salesforce_pulling_object_id'); |
|
347 | 347 | } |
348 | 348 | |
349 | - $salesforce_pulling = (int) get_transient( 'salesforce_pulling_' . $mapping_object_id_transient ); |
|
350 | - if ( 1 === $salesforce_pulling ) { |
|
351 | - delete_transient( 'salesforce_pulling_' . $mapping_object_id_transient ); |
|
352 | - $pulling_id = get_transient( 'salesforce_pulling_object_id' ); |
|
353 | - if ( $pulling_id === $mapping_object_id_transient ) { |
|
354 | - delete_transient( 'salesforce_pulling_object_id' ); |
|
349 | + $salesforce_pulling = (int) get_transient('salesforce_pulling_' . $mapping_object_id_transient); |
|
350 | + if (1 === $salesforce_pulling) { |
|
351 | + delete_transient('salesforce_pulling_' . $mapping_object_id_transient); |
|
352 | + $pulling_id = get_transient('salesforce_pulling_object_id'); |
|
353 | + if ($pulling_id === $mapping_object_id_transient) { |
|
354 | + delete_transient('salesforce_pulling_object_id'); |
|
355 | 355 | } |
356 | 356 | return false; |
357 | 357 | } |
358 | 358 | } else { |
359 | 359 | // if we don't have a WordPress object id, we've got no business doing stuff in Salesforce |
360 | 360 | $status = 'error'; |
361 | - if ( isset( $this->logging ) ) { |
|
361 | + if (isset($this->logging)) { |
|
362 | 362 | $logging = $this->logging; |
363 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
364 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
363 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
364 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | // translators: placeholder is the name of the WordPress id field |
368 | - $title = sprintf( esc_html__( 'Error: Salesforce Push: unable to process queue item because it has no WordPress %1$s.', 'object-sync-for-salesforce' ), |
|
369 | - esc_attr( $object_id_field ) |
|
368 | + $title = sprintf(esc_html__('Error: Salesforce Push: unable to process queue item because it has no WordPress %1$s.', 'object-sync-for-salesforce'), |
|
369 | + esc_attr($object_id_field) |
|
370 | 370 | ); |
371 | 371 | |
372 | 372 | $logging->setup( |
373 | 373 | $title, |
374 | - print_r( $object, true ), // print this array because if this happens, something weird has happened and we want to log whatever we have |
|
374 | + print_r($object, true), // print this array because if this happens, something weird has happened and we want to log whatever we have |
|
375 | 375 | $sf_sync_trigger, |
376 | 376 | 0, // parent id goes here but we don't have one, so make it 0 |
377 | 377 | $status |
@@ -388,14 +388,14 @@ discard block |
||
388 | 388 | ) |
389 | 389 | ); |
390 | 390 | |
391 | - foreach ( $sf_mappings as $mapping ) { // for each mapping of this object |
|
391 | + foreach ($sf_mappings as $mapping) { // for each mapping of this object |
|
392 | 392 | $map_sync_triggers = $mapping['sync_triggers']; |
393 | 393 | |
394 | 394 | // these are bit operators, so we leave out the strict |
395 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
395 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
396 | 396 | |
397 | 397 | // hook to allow other plugins to prevent a push per-mapping. |
398 | - $push_allowed = apply_filters( 'object_sync_for_salesforce_push_object_allowed', true, $object_type, $object, $sf_sync_trigger, $mapping ); |
|
398 | + $push_allowed = apply_filters('object_sync_for_salesforce_push_object_allowed', true, $object_type, $object, $sf_sync_trigger, $mapping); |
|
399 | 399 | |
400 | 400 | // example to keep from pushing the user with id of 1 |
401 | 401 | /* |
@@ -408,17 +408,17 @@ discard block |
||
408 | 408 | } |
409 | 409 | */ |
410 | 410 | |
411 | - if ( false === $push_allowed ) { |
|
411 | + if (false === $push_allowed) { |
|
412 | 412 | continue; |
413 | 413 | } |
414 | 414 | |
415 | 415 | // push drafts if the setting says so |
416 | 416 | // post status is draft, or post status is inherit and post type is not attachment |
417 | - if ( ( ! isset( $mapping['push_drafts'] ) || '1' !== $mapping['push_drafts'] ) && isset( $object['post_status'] ) && ( 'draft' === $object['post_status'] || ( 'inherit' === $object['post_status'] && 'attachment' !== $object['post_type'] ) ) ) { |
|
417 | + if (( ! isset($mapping['push_drafts']) || '1' !== $mapping['push_drafts']) && isset($object['post_status']) && ('draft' === $object['post_status'] || ('inherit' === $object['post_status'] && 'attachment' !== $object['post_type']))) { |
|
418 | 418 | // skip this object if it is a draft and the fieldmap settings told us to ignore it |
419 | 419 | continue; |
420 | 420 | } |
421 | - if ( isset( $mapping['push_async'] ) && ( '1' === $mapping['push_async'] ) && false === $manual ) { |
|
421 | + if (isset($mapping['push_async']) && ('1' === $mapping['push_async']) && false === $manual) { |
|
422 | 422 | // this item is async and we want to save it to the queue |
423 | 423 | $data = array( |
424 | 424 | 'object_type' => $object_type, |
@@ -429,24 +429,24 @@ discard block |
||
429 | 429 | |
430 | 430 | // create new schedule based on the options for this current class |
431 | 431 | // this will use the existing schedule if it already exists; otherwise it'll create one |
432 | - $this->schedule->use_schedule( $this->schedule_name ); |
|
433 | - $this->schedule->push_to_queue( $data ); |
|
432 | + $this->schedule->use_schedule($this->schedule_name); |
|
433 | + $this->schedule->push_to_queue($data); |
|
434 | 434 | $this->schedule->save()->dispatch(); |
435 | 435 | |
436 | 436 | } else { |
437 | 437 | // this one is not async. do it immediately. |
438 | - $push = $this->salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ); |
|
438 | + $push = $this->salesforce_push_sync_rest($object_type, $object, $mapping, $sf_sync_trigger); |
|
439 | 439 | } // End if(). |
440 | 440 | } // End if(). if the trigger does not match our requirements, skip it |
441 | 441 | } // End foreach(). |
442 | 442 | } |
443 | 443 | |
444 | 444 | private function schedule() { |
445 | - if ( ! class_exists( 'Object_Sync_Sf_Schedule' ) && file_exists( plugin_dir_path( __FILE__ ) . '../vendor/autoload.php' ) ) { |
|
446 | - require_once plugin_dir_path( __FILE__ ) . '../vendor/autoload.php'; |
|
447 | - require_once plugin_dir_path( __FILE__ ) . '../classes/schedule.php'; |
|
445 | + if ( ! class_exists('Object_Sync_Sf_Schedule') && file_exists(plugin_dir_path(__FILE__) . '../vendor/autoload.php')) { |
|
446 | + require_once plugin_dir_path(__FILE__) . '../vendor/autoload.php'; |
|
447 | + require_once plugin_dir_path(__FILE__) . '../classes/schedule.php'; |
|
448 | 448 | } |
449 | - $schedule = new Object_Sync_Sf_Schedule( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->schedule_name, $this->logging, $this->schedulable_classes ); |
|
449 | + $schedule = new Object_Sync_Sf_Schedule($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->schedule_name, $this->logging, $this->schedulable_classes); |
|
450 | 450 | $this->schedule = $schedule; |
451 | 451 | return $schedule; |
452 | 452 | } |
@@ -466,25 +466,25 @@ discard block |
||
466 | 466 | * @return true or exit the method |
467 | 467 | * |
468 | 468 | */ |
469 | - public function salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ) { |
|
469 | + public function salesforce_push_sync_rest($object_type, $object, $mapping, $sf_sync_trigger) { |
|
470 | 470 | |
471 | 471 | // If Salesforce is not authorized, don't do anything. |
472 | 472 | // it's unclear to me if we need to do something else here or if this is sufficient. This is all Drupal does. |
473 | - if ( true !== $this->salesforce['is_authorized'] ) { |
|
473 | + if (true !== $this->salesforce['is_authorized']) { |
|
474 | 474 | return; |
475 | 475 | } |
476 | 476 | |
477 | 477 | $sfapi = $this->salesforce['sfapi']; |
478 | 478 | |
479 | 479 | // we need to get the WordPress id here so we can check to see if the object already has a map |
480 | - $structure = $this->wordpress->get_wordpress_table_structure( $object_type ); |
|
480 | + $structure = $this->wordpress->get_wordpress_table_structure($object_type); |
|
481 | 481 | $object_id = $structure['id_field']; |
482 | 482 | |
483 | 483 | // this returns the row that maps the individual WordPress row to the individual Salesfoce row |
484 | - $mapping_object = $this->mappings->load_by_wordpress( $object_type, $object[ "$object_id" ] ); |
|
484 | + $mapping_object = $this->mappings->load_by_wordpress($object_type, $object["$object_id"]); |
|
485 | 485 | |
486 | 486 | // hook to allow other plugins to define or alter the mapping object |
487 | - $mapping_object = apply_filters( 'object_sync_for_salesforce_push_mapping_object', $mapping_object, $object, $mapping ); |
|
487 | + $mapping_object = apply_filters('object_sync_for_salesforce_push_mapping_object', $mapping_object, $object, $mapping); |
|
488 | 488 | |
489 | 489 | // we already have the data from WordPress at this point; we just need to work with it in Salesforce |
490 | 490 | $synced_object = array( |
@@ -498,84 +498,84 @@ discard block |
||
498 | 498 | |
499 | 499 | // deleting mapped objects |
500 | 500 | // these are bit operators, so we leave out the strict |
501 | - if ( $sf_sync_trigger == $this->mappings->sync_wordpress_delete ) { |
|
502 | - if ( isset( $mapping_object['id'] ) ) { |
|
501 | + if ($sf_sync_trigger == $this->mappings->sync_wordpress_delete) { |
|
502 | + if (isset($mapping_object['id'])) { |
|
503 | 503 | $op = 'Delete'; |
504 | 504 | |
505 | - $salesforce_check = $this->mappings->load_by_salesforce( $mapping_object['salesforce_id'] ); |
|
505 | + $salesforce_check = $this->mappings->load_by_salesforce($mapping_object['salesforce_id']); |
|
506 | 506 | |
507 | - if ( count( $salesforce_check ) === count( $salesforce_check, COUNT_RECURSIVE ) ) { |
|
507 | + if (count($salesforce_check) === count($salesforce_check, COUNT_RECURSIVE)) { |
|
508 | 508 | try { |
509 | - $result = $sfapi->object_delete( $mapping['salesforce_object'], $mapping_object['salesforce_id'] ); |
|
510 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
509 | + $result = $sfapi->object_delete($mapping['salesforce_object'], $mapping_object['salesforce_id']); |
|
510 | + } catch (Object_Sync_Sf_Exception $e) { |
|
511 | 511 | $status = 'error'; |
512 | 512 | // create log entry for failed delete |
513 | - if ( isset( $this->logging ) ) { |
|
513 | + if (isset($this->logging)) { |
|
514 | 514 | $logging = $this->logging; |
515 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
516 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
515 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
516 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value |
520 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
521 | - esc_attr( $op ), |
|
522 | - esc_attr( $mapping['salesforce_object'] ), |
|
523 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
524 | - esc_attr( $mapping['wordpress_object'] ), |
|
525 | - esc_attr( $object_id ), |
|
526 | - esc_attr( $object[ "$object_id" ] ) |
|
520 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
521 | + esc_attr($op), |
|
522 | + esc_attr($mapping['salesforce_object']), |
|
523 | + esc_attr($mapping_object['salesforce_id']), |
|
524 | + esc_attr($mapping['wordpress_object']), |
|
525 | + esc_attr($object_id), |
|
526 | + esc_attr($object["$object_id"]) |
|
527 | 527 | ); |
528 | 528 | |
529 | 529 | $logging->setup( |
530 | 530 | $title, |
531 | 531 | $e->getMessage(), |
532 | 532 | $sf_sync_trigger, |
533 | - $object[ "$object_id" ], |
|
533 | + $object["$object_id"], |
|
534 | 534 | $status |
535 | 535 | ); |
536 | 536 | |
537 | 537 | // hook for push fail |
538 | - do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object, $object_id ); |
|
538 | + do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object, $object_id); |
|
539 | 539 | |
540 | 540 | } |
541 | 541 | |
542 | - if ( ! isset( $e ) ) { |
|
542 | + if ( ! isset($e)) { |
|
543 | 543 | // create log entry for successful delete if the result had no errors |
544 | 544 | $status = 'success'; |
545 | - if ( isset( $this->logging ) ) { |
|
545 | + if (isset($this->logging)) { |
|
546 | 546 | $logging = $this->logging; |
547 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
548 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
547 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
548 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value |
552 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
553 | - esc_attr( $op ), |
|
554 | - esc_attr( $mapping['salesforce_object'] ), |
|
555 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
556 | - esc_attr( $mapping['wordpress_object'] ), |
|
557 | - esc_attr( $object_id ), |
|
558 | - esc_attr( $object[ "$object_id" ] ) |
|
552 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
553 | + esc_attr($op), |
|
554 | + esc_attr($mapping['salesforce_object']), |
|
555 | + esc_attr($mapping_object['salesforce_id']), |
|
556 | + esc_attr($mapping['wordpress_object']), |
|
557 | + esc_attr($object_id), |
|
558 | + esc_attr($object["$object_id"]) |
|
559 | 559 | ); |
560 | 560 | |
561 | 561 | $logging->setup( |
562 | 562 | $title, |
563 | 563 | '', |
564 | 564 | $sf_sync_trigger, |
565 | - $object[ "$object_id" ], |
|
565 | + $object["$object_id"], |
|
566 | 566 | $status |
567 | 567 | ); |
568 | 568 | |
569 | 569 | // hook for push success |
570 | - do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
570 | + do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
571 | 571 | } |
572 | 572 | } else { |
573 | 573 | $more_ids = '<p>The Salesforce record was not deleted because there are multiple WordPress IDs that match this Salesforce ID. They are: '; |
574 | 574 | $i = 0; |
575 | - foreach ( $salesforce_check as $match ) { |
|
575 | + foreach ($salesforce_check as $match) { |
|
576 | 576 | $i++; |
577 | 577 | $more_ids .= $match['wordpress_id']; |
578 | - if ( count( $salesforce_check ) !== $i ) { |
|
578 | + if (count($salesforce_check) !== $i) { |
|
579 | 579 | $more_ids .= ', '; |
580 | 580 | } else { |
581 | 581 | $more_ids .= '.</p>'; |
@@ -585,34 +585,34 @@ discard block |
||
585 | 585 | $more_ids .= '<p>The map row between this WordPress object and the Salesforce object, as stored in the WordPress database, will be deleted, and this WordPress object has been deleted, but Salesforce will remain untouched.</p>'; |
586 | 586 | |
587 | 587 | $status = 'notice'; |
588 | - if ( isset( $this->logging ) ) { |
|
588 | + if (isset($this->logging)) { |
|
589 | 589 | $logging = $this->logging; |
590 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
591 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
590 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
591 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value |
595 | - $title = sprintf( esc_html__( 'Notice: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s did not delete the Salesforce item.)', 'object-sync-for-salesforce' ), |
|
596 | - esc_attr( $op ), |
|
597 | - esc_attr( $mapping['salesforce_object'] ), |
|
598 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
599 | - esc_attr( $mapping['wordpress_object'] ), |
|
600 | - esc_attr( $object_id ), |
|
601 | - esc_attr( $object[ "$object_id" ] ) |
|
595 | + $title = sprintf(esc_html__('Notice: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s did not delete the Salesforce item.)', 'object-sync-for-salesforce'), |
|
596 | + esc_attr($op), |
|
597 | + esc_attr($mapping['salesforce_object']), |
|
598 | + esc_attr($mapping_object['salesforce_id']), |
|
599 | + esc_attr($mapping['wordpress_object']), |
|
600 | + esc_attr($object_id), |
|
601 | + esc_attr($object["$object_id"]) |
|
602 | 602 | ); |
603 | 603 | |
604 | 604 | $logging->setup( |
605 | 605 | $title, |
606 | 606 | $more_ids, |
607 | 607 | $sf_sync_trigger, |
608 | - $object[ "$object_id" ], |
|
608 | + $object["$object_id"], |
|
609 | 609 | $status |
610 | 610 | ); |
611 | 611 | } // End if(). |
612 | 612 | |
613 | 613 | // delete the map row from WordPress after the Salesforce row has been deleted |
614 | 614 | // we delete the map row even if the Salesforce delete failed, because the WordPress object is gone |
615 | - $this->mappings->delete_object_map( $mapping_object['id'] ); |
|
615 | + $this->mappings->delete_object_map($mapping_object['id']); |
|
616 | 616 | |
617 | 617 | } // End if(). there is no map row |
618 | 618 | |
@@ -620,51 +620,51 @@ discard block |
||
620 | 620 | } // End if(). |
621 | 621 | |
622 | 622 | // are these objects already connected in WordPress? |
623 | - if ( isset( $mapping_object['id'] ) ) { |
|
623 | + if (isset($mapping_object['id'])) { |
|
624 | 624 | $is_new = false; |
625 | 625 | } else { |
626 | 626 | $is_new = true; |
627 | 627 | } |
628 | 628 | |
629 | 629 | // map the WordPress values to salesforce fields |
630 | - $params = $this->mappings->map_params( $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
630 | + $params = $this->mappings->map_params($mapping, $object, $sf_sync_trigger, false, $is_new); |
|
631 | 631 | |
632 | 632 | // hook to allow other plugins to modify the $params array |
633 | 633 | // use hook to map fields between the WordPress and Salesforce objects |
634 | 634 | // returns $params. |
635 | - $params = apply_filters( 'object_sync_for_salesforce_push_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
635 | + $params = apply_filters('object_sync_for_salesforce_push_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new); |
|
636 | 636 | |
637 | 637 | // if we don't get any params, there are no fields that should be sent to Salesforce |
638 | - if ( empty( $params ) ) { |
|
638 | + if (empty($params)) { |
|
639 | 639 | return; |
640 | 640 | } |
641 | 641 | |
642 | 642 | // if there is a prematch WordPress field - ie email - on the fieldmap object |
643 | - if ( isset( $params['prematch'] ) && is_array( $params['prematch'] ) ) { |
|
643 | + if (isset($params['prematch']) && is_array($params['prematch'])) { |
|
644 | 644 | $prematch_field_wordpress = $params['prematch']['wordpress_field']; |
645 | 645 | $prematch_field_salesforce = $params['prematch']['salesforce_field']; |
646 | 646 | $prematch_value = $params['prematch']['value']; |
647 | - unset( $params['prematch'] ); |
|
647 | + unset($params['prematch']); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // if there is an external key field in Salesforce - ie mailchimp user id - on the fieldmap object |
651 | - if ( isset( $params['key'] ) && is_array( $params['key'] ) ) { |
|
651 | + if (isset($params['key']) && is_array($params['key'])) { |
|
652 | 652 | $key_field_wordpress = $params['key']['wordpress_field']; |
653 | 653 | $key_field_salesforce = $params['key']['salesforce_field']; |
654 | 654 | $key_value = $params['key']['value']; |
655 | - unset( $params['key'] ); |
|
655 | + unset($params['key']); |
|
656 | 656 | } |
657 | 657 | |
658 | - $seconds = $this->schedule->get_schedule_frequency_seconds( $this->schedule_name ) + 60; |
|
658 | + $seconds = $this->schedule->get_schedule_frequency_seconds($this->schedule_name) + 60; |
|
659 | 659 | |
660 | - if ( true === $is_new ) { |
|
660 | + if (true === $is_new) { |
|
661 | 661 | |
662 | 662 | // right here we should set the pushing transient |
663 | 663 | // this means we have to create the mapping object here as well, and update it with the correct IDs after successful response |
664 | 664 | // create the mapping object between the rows |
665 | - $mapping_object_id = $this->create_object_map( $object, $object_id, $this->mappings->generate_temporary_id( 'push' ), $mapping, true ); |
|
666 | - set_transient( 'salesforce_pushing_' . $mapping_object_id, 1, $seconds ); |
|
667 | - set_transient( 'salesforce_pushing_object_id', $mapping_object_id ); |
|
665 | + $mapping_object_id = $this->create_object_map($object, $object_id, $this->mappings->generate_temporary_id('push'), $mapping, true); |
|
666 | + set_transient('salesforce_pushing_' . $mapping_object_id, 1, $seconds); |
|
667 | + set_transient('salesforce_pushing_object_id', $mapping_object_id); |
|
668 | 668 | $mapping_object = $this->mappings->get_object_maps( |
669 | 669 | array( |
670 | 670 | 'id' => $mapping_object_id, |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | |
674 | 674 | // setup SF record type. CampaignMember objects get their Campaign's type |
675 | 675 | // i am still a bit confused about this |
676 | - if ( $mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty( $params['RecordTypeId'] ) && ( 'CampaignMember' !== $mapping['salesforce_object'] ) ) { |
|
676 | + if ($mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty($params['RecordTypeId']) && ('CampaignMember' !== $mapping['salesforce_object'])) { |
|
677 | 677 | $params['RecordTypeId'] = $mapping['salesforce_record_type_default']; |
678 | 678 | } |
679 | 679 | |
@@ -685,61 +685,61 @@ discard block |
||
685 | 685 | // returns a $salesforce_id. |
686 | 686 | // it should keep NULL if there is no match |
687 | 687 | // the function that calls this hook needs to check the mapping to make sure the WordPress object is the right type |
688 | - $salesforce_id = apply_filters( 'object_sync_for_salesforce_find_sf_object_match', null, $object, $mapping, 'push' ); |
|
688 | + $salesforce_id = apply_filters('object_sync_for_salesforce_find_sf_object_match', null, $object, $mapping, 'push'); |
|
689 | 689 | |
690 | 690 | // hook to allow other plugins to do something right before Salesforce data is saved |
691 | 691 | // ex: run WordPress methods on an object if it exists, or do something in preparation for it if it doesn't |
692 | - do_action( 'object_sync_for_salesforce_pre_push', $salesforce_id, $mapping, $object, $object_id, $params ); |
|
692 | + do_action('object_sync_for_salesforce_pre_push', $salesforce_id, $mapping, $object, $object_id, $params); |
|
693 | 693 | |
694 | 694 | // hook to allow other plugins to change params on update actions only |
695 | 695 | // use hook to map fields between the WordPress and Salesforce objects |
696 | 696 | // returns $params. |
697 | - $params = apply_filters( 'object_sync_for_salesforce_push_update_params_modify', $params, $salesforce_id, $mapping, $object ); |
|
697 | + $params = apply_filters('object_sync_for_salesforce_push_update_params_modify', $params, $salesforce_id, $mapping, $object); |
|
698 | 698 | |
699 | - if ( isset( $prematch_field_wordpress ) || isset( $key_field_wordpress ) || null !== $salesforce_id ) { |
|
699 | + if (isset($prematch_field_wordpress) || isset($key_field_wordpress) || null !== $salesforce_id) { |
|
700 | 700 | |
701 | 701 | // if either prematch criteria exists, make the values queryable |
702 | 702 | |
703 | - if ( isset( $prematch_field_wordpress ) ) { |
|
703 | + if (isset($prematch_field_wordpress)) { |
|
704 | 704 | // a prematch has been specified, attempt an upsert(). |
705 | 705 | // prematch values with punctuation need to be escaped |
706 | - $encoded_prematch_value = rawurlencode( $prematch_value ); |
|
706 | + $encoded_prematch_value = rawurlencode($prematch_value); |
|
707 | 707 | // for at least 'email' fields, periods also need to be escaped: |
708 | 708 | // https://developer.salesforce.com/forums?id=906F000000099xPIAQ |
709 | - $encoded_prematch_value = str_replace( '.', '%2E', $encoded_prematch_value ); |
|
709 | + $encoded_prematch_value = str_replace('.', '%2E', $encoded_prematch_value); |
|
710 | 710 | } |
711 | 711 | |
712 | - if ( isset( $key_field_wordpress ) ) { |
|
712 | + if (isset($key_field_wordpress)) { |
|
713 | 713 | // an external key has been specified, attempt an upsert(). |
714 | 714 | // external key values with punctuation need to be escaped |
715 | - $encoded_key_value = rawurlencode( $key_value ); |
|
715 | + $encoded_key_value = rawurlencode($key_value); |
|
716 | 716 | // for at least 'email' fields, periods also need to be escaped: |
717 | 717 | // https://developer.salesforce.com/forums?id=906F000000099xPIAQ |
718 | - $encoded_key_value = str_replace( '.', '%2E', $encoded_key_value ); |
|
718 | + $encoded_key_value = str_replace('.', '%2E', $encoded_key_value); |
|
719 | 719 | } |
720 | 720 | |
721 | - if ( isset( $prematch_field_wordpress ) ) { |
|
721 | + if (isset($prematch_field_wordpress)) { |
|
722 | 722 | $upsert_key = $prematch_field_salesforce; |
723 | 723 | $upsert_value = $encoded_prematch_value; |
724 | - } elseif ( isset( $key_field_wordpress ) ) { |
|
724 | + } elseif (isset($key_field_wordpress)) { |
|
725 | 725 | $upsert_key = $key_field_salesforce; |
726 | 726 | $upsert_value = $encoded_key_value; |
727 | 727 | } |
728 | 728 | |
729 | - if ( null !== $salesforce_id ) { |
|
729 | + if (null !== $salesforce_id) { |
|
730 | 730 | $upsert_key = 'Id'; |
731 | 731 | $upsert_value = $salesforce_id; |
732 | 732 | } |
733 | 733 | |
734 | 734 | $op = 'Upsert'; |
735 | 735 | |
736 | - $result = $sfapi->object_upsert( $mapping['salesforce_object'], $upsert_key, $upsert_value, $params ); |
|
736 | + $result = $sfapi->object_upsert($mapping['salesforce_object'], $upsert_key, $upsert_value, $params); |
|
737 | 737 | |
738 | 738 | // Handle upsert responses. |
739 | - switch ( $sfapi->response['code'] ) { |
|
739 | + switch ($sfapi->response['code']) { |
|
740 | 740 | // On Upsert:update retrieved object. |
741 | 741 | case '204': |
742 | - $sf_object = $sfapi->object_readby_external_id( $mapping['salesforce_object'], $upsert_key, $upsert_value ); |
|
742 | + $sf_object = $sfapi->object_readby_external_id($mapping['salesforce_object'], $upsert_key, $upsert_value); |
|
743 | 743 | $salesforce_data['id'] = $sf_object['data']['Id']; |
744 | 744 | break; |
745 | 745 | // Handle duplicate records. |
@@ -750,43 +750,43 @@ discard block |
||
750 | 750 | } else { |
751 | 751 | // No key or prematch field exists on this field map object, create a new object in Salesforce. |
752 | 752 | $op = 'Create'; |
753 | - $result = $sfapi->object_create( $mapping['salesforce_object'], $params ); |
|
753 | + $result = $sfapi->object_create($mapping['salesforce_object'], $params); |
|
754 | 754 | } // End if(). |
755 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
755 | + } catch (Object_Sync_Sf_Exception $e) { |
|
756 | 756 | // create log entry for failed create or upsert |
757 | 757 | $status = 'error'; |
758 | 758 | |
759 | - if ( isset( $this->logging ) ) { |
|
759 | + if (isset($this->logging)) { |
|
760 | 760 | $logging = $this->logging; |
761 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
762 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
761 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
762 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value if there is one, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value |
766 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
767 | - esc_attr( $op ), |
|
768 | - esc_attr( $mapping['salesforce_object'] ), |
|
769 | - isset( $salesforce_id ) ? ' ' . esc_attr( $salesforce_id ) : '', |
|
770 | - esc_attr( $mapping['wordpress_object'] ), |
|
771 | - esc_attr( $object_id ), |
|
772 | - esc_attr( $object[ "$object_id" ] ) |
|
766 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
767 | + esc_attr($op), |
|
768 | + esc_attr($mapping['salesforce_object']), |
|
769 | + isset($salesforce_id) ? ' ' . esc_attr($salesforce_id) : '', |
|
770 | + esc_attr($mapping['wordpress_object']), |
|
771 | + esc_attr($object_id), |
|
772 | + esc_attr($object["$object_id"]) |
|
773 | 773 | ); |
774 | 774 | |
775 | 775 | $logging->setup( |
776 | 776 | $title, |
777 | 777 | $e->getMessage(), |
778 | 778 | $sf_sync_trigger, |
779 | - $object[ "$object_id" ], |
|
779 | + $object["$object_id"], |
|
780 | 780 | $status |
781 | 781 | ); |
782 | 782 | |
783 | 783 | // hook for push fail |
784 | - do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object ); |
|
784 | + do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object); |
|
785 | 785 | |
786 | 786 | return; |
787 | 787 | } // End try(). |
788 | 788 | |
789 | - if ( ! isset( $salesforce_data ) ) { |
|
789 | + if ( ! isset($salesforce_data)) { |
|
790 | 790 | // if we didn't set $salesforce_data already, set it now to api call result |
791 | 791 | $salesforce_data = $result['data']; |
792 | 792 | } |
@@ -795,78 +795,78 @@ discard block |
||
795 | 795 | // this means the object has already been created/updated in Salesforce |
796 | 796 | // this is not redundant because this is where it creates the object mapping rows in WordPress if the object does not already have one (we are still inside $is_new === TRUE here) |
797 | 797 | |
798 | - if ( empty( $result['errorCode'] ) ) { |
|
798 | + if (empty($result['errorCode'])) { |
|
799 | 799 | $salesforce_id = $salesforce_data['id']; |
800 | 800 | $status = 'success'; |
801 | 801 | |
802 | - if ( isset( $this->logging ) ) { |
|
802 | + if (isset($this->logging)) { |
|
803 | 803 | $logging = $this->logging; |
804 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
805 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
804 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
805 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value |
809 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
810 | - esc_attr( $op ), |
|
811 | - esc_attr( $mapping['salesforce_object'] ), |
|
812 | - esc_attr( $salesforce_id ), |
|
813 | - esc_attr( $mapping['wordpress_object'] ), |
|
814 | - esc_attr( $object_id ), |
|
815 | - esc_attr( $object[ "$object_id" ] ) |
|
809 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
810 | + esc_attr($op), |
|
811 | + esc_attr($mapping['salesforce_object']), |
|
812 | + esc_attr($salesforce_id), |
|
813 | + esc_attr($mapping['wordpress_object']), |
|
814 | + esc_attr($object_id), |
|
815 | + esc_attr($object["$object_id"]) |
|
816 | 816 | ); |
817 | 817 | |
818 | 818 | $logging->setup( |
819 | 819 | $title, |
820 | 820 | '', |
821 | 821 | $sf_sync_trigger, |
822 | - $object[ "$object_id" ], |
|
822 | + $object["$object_id"], |
|
823 | 823 | $status |
824 | 824 | ); |
825 | 825 | |
826 | 826 | // update that mapping object |
827 | 827 | $mapping_object['salesforce_id'] = $salesforce_id; |
828 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
829 | - $mapping_object = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
828 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
829 | + $mapping_object = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
830 | 830 | |
831 | 831 | // hook for push success |
832 | - do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
832 | + do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
833 | 833 | } else { |
834 | 834 | |
835 | 835 | // create log entry for failed create or upsert |
836 | 836 | // this is part of the drupal module but i am failing to understand when it would ever fire, since the catch should catch the errors |
837 | 837 | // if we see this in the log entries, we can understand what it does, but probably not until then |
838 | 838 | $status = 'error'; |
839 | - if ( isset( $this->logging ) ) { |
|
839 | + if (isset($this->logging)) { |
|
840 | 840 | $logging = $this->logging; |
841 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
842 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
841 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
842 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | // translators: placeholders are: 1) error code the Salesforce API returned, 2) what operation is happening, 3) the name of the WordPress object type, 4) the WordPress id field name, 5) the WordPress object id value |
846 | - $title = sprintf( esc_html__( '%1$s error syncing: %2$s to Salesforce (WordPress %3$s with %4$s of %5$s)', 'object-sync-for-salesforce' ), |
|
847 | - absint( $salesforce_data['errorCode'] ), |
|
848 | - esc_attr( $op ), |
|
849 | - esc_attr( $mapping['wordpress_object'] ), |
|
850 | - esc_attr( $object_id ), |
|
851 | - esc_attr( $object[ "$object_id" ] ) |
|
846 | + $title = sprintf(esc_html__('%1$s error syncing: %2$s to Salesforce (WordPress %3$s with %4$s of %5$s)', 'object-sync-for-salesforce'), |
|
847 | + absint($salesforce_data['errorCode']), |
|
848 | + esc_attr($op), |
|
849 | + esc_attr($mapping['wordpress_object']), |
|
850 | + esc_attr($object_id), |
|
851 | + esc_attr($object["$object_id"]) |
|
852 | 852 | ); |
853 | 853 | |
854 | 854 | // translators: placeholders are 1) the name of the Salesforce object type, 2) the error message returned from the Salesforce APIs |
855 | - $body = sprintf( '<p>' . esc_html__( 'Object: %1$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Message: %2$s', 'object-sync-for-salesforce' ) . '</p>', |
|
856 | - esc_attr( $mapping['salesforce_object'] ), |
|
857 | - esc_html( $salesforce_data['message'] ) |
|
855 | + $body = sprintf('<p>' . esc_html__('Object: %1$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Message: %2$s', 'object-sync-for-salesforce') . '</p>', |
|
856 | + esc_attr($mapping['salesforce_object']), |
|
857 | + esc_html($salesforce_data['message']) |
|
858 | 858 | ); |
859 | 859 | |
860 | 860 | $logging->setup( |
861 | 861 | $title, |
862 | 862 | $body, |
863 | 863 | $sf_sync_trigger, |
864 | - $object[ "$object_id" ], |
|
864 | + $object["$object_id"], |
|
865 | 865 | $status |
866 | 866 | ); |
867 | 867 | |
868 | 868 | // hook for push fail |
869 | - do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object ); |
|
869 | + do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object); |
|
870 | 870 | |
871 | 871 | return; |
872 | 872 | } // End if(). |
@@ -874,41 +874,41 @@ discard block |
||
874 | 874 | // $is_new is false here; we are updating an already mapped object |
875 | 875 | |
876 | 876 | // right here we should set the pushing transient |
877 | - set_transient( 'salesforce_pushing_' . $mapping_object['id'], 1, $seconds ); |
|
878 | - set_transient( 'salesforce_pushing_object_id', $mapping_object['id'] ); |
|
877 | + set_transient('salesforce_pushing_' . $mapping_object['id'], 1, $seconds); |
|
878 | + set_transient('salesforce_pushing_object_id', $mapping_object['id']); |
|
879 | 879 | |
880 | 880 | // there is an existing object link |
881 | 881 | // if the last sync is greater than the last time this object was updated, skip it |
882 | 882 | // this keeps us from doing redundant syncs |
883 | - $mapping_object['object_updated'] = current_time( 'mysql' ); |
|
884 | - if ( $mapping_object['last_sync'] > $mapping_object['object_updated'] ) { |
|
883 | + $mapping_object['object_updated'] = current_time('mysql'); |
|
884 | + if ($mapping_object['last_sync'] > $mapping_object['object_updated']) { |
|
885 | 885 | $status = 'notice'; |
886 | - if ( isset( $this->logging ) ) { |
|
886 | + if (isset($this->logging)) { |
|
887 | 887 | $logging = $this->logging; |
888 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
889 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
888 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
889 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | // translators: placeholders are: 1) what operation is happening, 2) the name of the WordPress object type, 3) the WordPress id field name, 4) the WordPress object id value, 5) the Salesforce Id value |
893 | - $title = sprintf( esc_html__( 'Notice: %1$s: Did not sync WordPress %2$s with %3$s of %4$s with Salesforce Id %5$s because the last sync timestamp was greater than the object updated timestamp.', 'object-sync-for-salesforce' ), |
|
894 | - esc_attr( $op ), |
|
895 | - esc_attr( $mapping['wordpress_object'] ), |
|
896 | - esc_attr( $object_id ), |
|
897 | - esc_attr( $object[ "$object_id" ] ), |
|
898 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
893 | + $title = sprintf(esc_html__('Notice: %1$s: Did not sync WordPress %2$s with %3$s of %4$s with Salesforce Id %5$s because the last sync timestamp was greater than the object updated timestamp.', 'object-sync-for-salesforce'), |
|
894 | + esc_attr($op), |
|
895 | + esc_attr($mapping['wordpress_object']), |
|
896 | + esc_attr($object_id), |
|
897 | + esc_attr($object["$object_id"]), |
|
898 | + esc_attr($mapping_object['salesforce_id']) |
|
899 | 899 | ); |
900 | 900 | |
901 | 901 | // translators: placeholders are 1) when a sync on this mapping last occured, 2) when the object was last updated |
902 | - $body = sprintf( '<p>' . esc_html__( 'Last sync time: %1$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Object updated time: %2$s', 'object-sync-for-salesforce' ) . '</p>', |
|
903 | - esc_attr( $mapping_object['last_sync'] ), |
|
904 | - esc_html( $mapping_object['object_updated'] ) |
|
902 | + $body = sprintf('<p>' . esc_html__('Last sync time: %1$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Object updated time: %2$s', 'object-sync-for-salesforce') . '</p>', |
|
903 | + esc_attr($mapping_object['last_sync']), |
|
904 | + esc_html($mapping_object['object_updated']) |
|
905 | 905 | ); |
906 | 906 | |
907 | 907 | $logging->setup( |
908 | 908 | $title, |
909 | 909 | $body, |
910 | 910 | $sf_sync_trigger, |
911 | - $object[ "$object_id" ], |
|
911 | + $object["$object_id"], |
|
912 | 912 | $status |
913 | 913 | ); |
914 | 914 | return; |
@@ -919,71 +919,71 @@ discard block |
||
919 | 919 | |
920 | 920 | // hook to allow other plugins to do something right before Salesforce data is saved |
921 | 921 | // ex: run WordPress methods on an object if it exists, or do something in preparation for it if it doesn't |
922 | - do_action( 'object_sync_for_salesforce_pre_push', $mapping_object['salesforce_id'], $mapping, $object, $object_id, $params ); |
|
922 | + do_action('object_sync_for_salesforce_pre_push', $mapping_object['salesforce_id'], $mapping, $object, $object_id, $params); |
|
923 | 923 | |
924 | 924 | // hook to allow other plugins to change params on update actions only |
925 | 925 | // use hook to map fields between the WordPress and Salesforce objects |
926 | 926 | // returns $params. |
927 | - $params = apply_filters( 'object_sync_for_salesforce_push_update_params_modify', $params, $mapping_object['salesforce_id'], $mapping, $object ); |
|
927 | + $params = apply_filters('object_sync_for_salesforce_push_update_params_modify', $params, $mapping_object['salesforce_id'], $mapping, $object); |
|
928 | 928 | |
929 | 929 | $op = 'Update'; |
930 | - $result = $sfapi->object_update( $mapping['salesforce_object'], $mapping_object['salesforce_id'], $params ); |
|
930 | + $result = $sfapi->object_update($mapping['salesforce_object'], $mapping_object['salesforce_id'], $params); |
|
931 | 931 | |
932 | 932 | $mapping_object['last_sync_status'] = $this->mappings->status_success; |
933 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
933 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
934 | 934 | |
935 | 935 | $status = 'success'; |
936 | - if ( isset( $this->logging ) ) { |
|
936 | + if (isset($this->logging)) { |
|
937 | 937 | $logging = $this->logging; |
938 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
939 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
938 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
939 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value |
943 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
944 | - esc_attr( $op ), |
|
945 | - esc_attr( $mapping['salesforce_object'] ), |
|
946 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
947 | - esc_attr( $mapping['wordpress_object'] ), |
|
948 | - esc_attr( $object_id ), |
|
949 | - esc_attr( $object[ "$object_id" ] ) |
|
943 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
944 | + esc_attr($op), |
|
945 | + esc_attr($mapping['salesforce_object']), |
|
946 | + esc_attr($mapping_object['salesforce_id']), |
|
947 | + esc_attr($mapping['wordpress_object']), |
|
948 | + esc_attr($object_id), |
|
949 | + esc_attr($object["$object_id"]) |
|
950 | 950 | ); |
951 | 951 | |
952 | 952 | $logging->setup( |
953 | 953 | $title, |
954 | 954 | '', |
955 | 955 | $sf_sync_trigger, |
956 | - $object[ "$object_id" ], |
|
956 | + $object["$object_id"], |
|
957 | 957 | $status |
958 | 958 | ); |
959 | 959 | |
960 | 960 | // hook for push success |
961 | - do_action( 'object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
961 | + do_action('object_sync_for_salesforce_push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
962 | 962 | |
963 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
963 | + } catch (Object_Sync_Sf_Exception $e) { |
|
964 | 964 | // create log entry for failed update |
965 | 965 | $status = 'error'; |
966 | - if ( isset( $this->logging ) ) { |
|
966 | + if (isset($this->logging)) { |
|
967 | 967 | $logging = $this->logging; |
968 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
969 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
968 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
969 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object, 3) the Salesforce Id value, 4) the name of the WordPress object type, 5) the WordPress id field name, 6) the WordPress object id value |
973 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
974 | - esc_attr( $op ), |
|
975 | - esc_attr( $mapping['salesforce_object'] ), |
|
976 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
977 | - esc_attr( $mapping['wordpress_object'] ), |
|
978 | - esc_attr( $object_id ), |
|
979 | - esc_attr( $object[ "$object_id" ] ) |
|
973 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
974 | + esc_attr($op), |
|
975 | + esc_attr($mapping['salesforce_object']), |
|
976 | + esc_attr($mapping_object['salesforce_id']), |
|
977 | + esc_attr($mapping['wordpress_object']), |
|
978 | + esc_attr($object_id), |
|
979 | + esc_attr($object["$object_id"]) |
|
980 | 980 | ); |
981 | 981 | |
982 | 982 | $logging->setup( |
983 | 983 | $title, |
984 | 984 | $e->getMessage(), |
985 | 985 | $sf_sync_trigger, |
986 | - $object[ "$object_id" ], |
|
986 | + $object["$object_id"], |
|
987 | 987 | $status |
988 | 988 | ); |
989 | 989 | |
@@ -991,16 +991,16 @@ discard block |
||
991 | 991 | $mapping_object['last_sync_message'] = $e->getMessage(); |
992 | 992 | |
993 | 993 | // hook for push fail |
994 | - do_action( 'object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object ); |
|
994 | + do_action('object_sync_for_salesforce_push_fail', $op, $sfapi->response, $synced_object); |
|
995 | 995 | |
996 | 996 | } // End try(). |
997 | 997 | |
998 | 998 | // tell the mapping object - whether it is new or already existed - how we just used it |
999 | 999 | $mapping_object['last_sync_action'] = 'push'; |
1000 | - $mapping_object['last_sync'] = current_time( 'mysql' ); |
|
1000 | + $mapping_object['last_sync'] = current_time('mysql'); |
|
1001 | 1001 | |
1002 | 1002 | // update that mapping object |
1003 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1003 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1004 | 1004 | |
1005 | 1005 | } // End if(). this is the end of the if is_new stuff |
1006 | 1006 | |
@@ -1022,9 +1022,9 @@ discard block |
||
1022 | 1022 | * This is the database row for the map object |
1023 | 1023 | * |
1024 | 1024 | */ |
1025 | - private function create_object_map( $wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false ) { |
|
1025 | + private function create_object_map($wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false) { |
|
1026 | 1026 | |
1027 | - if ( true === $pending ) { |
|
1027 | + if (true === $pending) { |
|
1028 | 1028 | $action = 'pending'; |
1029 | 1029 | } else { |
1030 | 1030 | $action = 'created'; |
@@ -1033,15 +1033,15 @@ discard block |
||
1033 | 1033 | // Create object map and save it |
1034 | 1034 | $mapping_object = $this->mappings->create_object_map( |
1035 | 1035 | array( |
1036 | - 'wordpress_id' => $wordpress_object[ $id_field_name ], // wordpress unique id |
|
1036 | + 'wordpress_id' => $wordpress_object[$id_field_name], // wordpress unique id |
|
1037 | 1037 | 'salesforce_id' => $salesforce_id, // salesforce unique id. we don't care what kind of object it is at this point |
1038 | 1038 | 'wordpress_object' => $field_mapping['wordpress_object'], // keep track of what kind of wp object this is |
1039 | - 'last_sync' => current_time( 'mysql' ), |
|
1039 | + 'last_sync' => current_time('mysql'), |
|
1040 | 1040 | 'last_sync_action' => 'push', |
1041 | 1041 | 'last_sync_status' => $this->mappings->status_success, |
1042 | 1042 | // translators: placeholder is for the action that occurred on the mapping object (pending or created) |
1043 | - 'last_sync_message' => sprintf( esc_html__( 'Mapping object %1$s via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
1044 | - esc_attr( $action ) |
|
1043 | + 'last_sync_message' => sprintf(esc_html__('Mapping object %1$s via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
1044 | + esc_attr($action) |
|
1045 | 1045 | ), |
1046 | 1046 | 'action' => $action, |
1047 | 1047 | ) |