@@ -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 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param object $queue |
47 | 47 | * @throws \Object_Sync_Sf_Exception |
48 | 48 | */ |
49 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
|
49 | + public function __construct($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue) { |
|
50 | 50 | $this->wpdb = $wpdb; |
51 | 51 | $this->version = $version; |
52 | 52 | $this->login_credentials = $login_credentials; |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | $this->schedule_name = 'salesforce_push'; |
63 | 63 | |
64 | 64 | // Create action hooks for WordPress objects. We run this after plugins are loaded in case something depends on another plugin. |
65 | - add_action( 'plugins_loaded', array( $this, 'add_actions' ) ); |
|
65 | + add_action('plugins_loaded', array($this, 'add_actions')); |
|
66 | 66 | |
67 | - $this->debug = get_option( $this->option_prefix . 'debug_mode', false ); |
|
67 | + $this->debug = get_option($this->option_prefix . 'debug_mode', false); |
|
68 | 68 | |
69 | 69 | } |
70 | 70 | |
@@ -74,41 +74,41 @@ discard block |
||
74 | 74 | * |
75 | 75 | */ |
76 | 76 | public function add_actions() { |
77 | - $db_version = get_option( $this->option_prefix . 'db_version', false ); |
|
78 | - if ( $db_version === $this->version ) { |
|
79 | - foreach ( $this->mappings->get_fieldmaps() as $mapping ) { |
|
77 | + $db_version = get_option($this->option_prefix . 'db_version', false); |
|
78 | + if ($db_version === $this->version) { |
|
79 | + foreach ($this->mappings->get_fieldmaps() as $mapping) { |
|
80 | 80 | $object_type = $mapping['wordpress_object']; |
81 | - if ( 'user' === $object_type ) { |
|
82 | - if ( defined( 'ultimatemember_plugin_name' ) ) { |
|
83 | - add_action( 'um_user_register', array( $this, 'um_add_user' ), 11, 2 ); |
|
81 | + if ('user' === $object_type) { |
|
82 | + if (defined('ultimatemember_plugin_name')) { |
|
83 | + add_action('um_user_register', array($this, 'um_add_user'), 11, 2); |
|
84 | 84 | } else { |
85 | - add_action( 'user_register', array( $this, 'add_user' ), 11, 1 ); |
|
85 | + add_action('user_register', array($this, 'add_user'), 11, 1); |
|
86 | 86 | } |
87 | - add_action( 'profile_update', array( $this, 'edit_user' ), 11, 2 ); |
|
88 | - add_action( 'delete_user', array( $this, 'delete_user' ) ); |
|
89 | - } elseif ( 'post' === $object_type ) { |
|
90 | - add_action( 'save_post', array( $this, 'post_actions' ), 11, 2 ); |
|
91 | - } elseif ( 'attachment' === $object_type ) { |
|
92 | - add_action( 'add_attachment', array( $this, 'add_attachment' ) ); |
|
93 | - add_action( 'edit_attachment', array( $this, 'edit_attachment' ) ); |
|
94 | - add_action( 'delete_attachment', array( $this, 'delete_attachment' ) ); |
|
95 | - } elseif ( 'category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type ) { |
|
96 | - add_action( 'create_term', array( $this, 'add_term' ), 11, 3 ); |
|
97 | - add_action( 'edit_terms', array( $this, 'edit_term' ), 11, 2 ); |
|
98 | - add_action( 'delete_term', array( $this, 'delete_term' ), 10, 4 ); |
|
99 | - } elseif ( 'comment' === $object_type ) { |
|
100 | - add_action( 'comment_post', array( $this, 'add_comment' ), 11, 3 ); |
|
101 | - add_action( 'edit_comment', array( $this, 'edit_comment' ) ); |
|
102 | - 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 |
|
87 | + add_action('profile_update', array($this, 'edit_user'), 11, 2); |
|
88 | + add_action('delete_user', array($this, 'delete_user')); |
|
89 | + } elseif ('post' === $object_type) { |
|
90 | + add_action('save_post', array($this, 'post_actions'), 11, 2); |
|
91 | + } elseif ('attachment' === $object_type) { |
|
92 | + add_action('add_attachment', array($this, 'add_attachment')); |
|
93 | + add_action('edit_attachment', array($this, 'edit_attachment')); |
|
94 | + add_action('delete_attachment', array($this, 'delete_attachment')); |
|
95 | + } elseif ('category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type) { |
|
96 | + add_action('create_term', array($this, 'add_term'), 11, 3); |
|
97 | + add_action('edit_terms', array($this, 'edit_term'), 11, 2); |
|
98 | + add_action('delete_term', array($this, 'delete_term'), 10, 4); |
|
99 | + } elseif ('comment' === $object_type) { |
|
100 | + add_action('comment_post', array($this, 'add_comment'), 11, 3); |
|
101 | + add_action('edit_comment', array($this, 'edit_comment')); |
|
102 | + 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 |
|
103 | 103 | } else { // this is for custom post types |
104 | 104 | // we still have to use save_post because save_post_type fails to pull in the metadata |
105 | - add_action( 'save_post', array( $this, 'post_actions' ), 11, 2 ); |
|
105 | + add_action('save_post', array($this, 'post_actions'), 11, 2); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | 110 | // hook that action-scheduler can call |
111 | - add_action( $this->option_prefix . 'push_record', array( $this, 'salesforce_push_sync_rest' ), 10, 4 ); |
|
111 | + add_action($this->option_prefix . 'push_record', array($this, 'salesforce_push_sync_rest'), 10, 4); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @param string $type |
120 | 120 | * |
121 | 121 | */ |
122 | - public function manual_object_update( $object, $type ) { |
|
123 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update, true ); |
|
122 | + public function manual_object_update($object, $type) { |
|
123 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_update, true); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @param string $user_id |
130 | 130 | */ |
131 | - public function add_user( $user_id ) { |
|
132 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
133 | - $this->object_insert( $user, 'user' ); |
|
131 | + public function add_user($user_id) { |
|
132 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
133 | + $this->object_insert($user, 'user'); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @param string $user_id |
140 | 140 | */ |
141 | - public function um_add_user( $user_id, $form_data = array() ) { |
|
142 | - $this->object_insert( $form_data, 'user' ); |
|
141 | + public function um_add_user($user_id, $form_data = array()) { |
|
142 | + $this->object_insert($form_data, 'user'); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param string $user_id |
149 | 149 | * @param object $old_user_data |
150 | 150 | */ |
151 | - public function edit_user( $user_id, $old_user_data ) { |
|
152 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
153 | - $this->object_update( $user, 'user' ); |
|
151 | + public function edit_user($user_id, $old_user_data) { |
|
152 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
153 | + $this->object_update($user, 'user'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @param string $user_id |
160 | 160 | */ |
161 | - public function delete_user( $user_id ) { |
|
162 | - $user = $this->wordpress->get_wordpress_object_data( 'user', $user_id ); |
|
163 | - $this->object_delete( $user, 'user' ); |
|
161 | + public function delete_user($user_id) { |
|
162 | + $user = $this->wordpress->get_wordpress_object_data('user', $user_id); |
|
163 | + $this->object_delete($user, 'user'); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -170,48 +170,48 @@ discard block |
||
170 | 170 | * @param string $post_id |
171 | 171 | * @param object $post |
172 | 172 | */ |
173 | - public function post_actions( $post_id, $post ) { |
|
173 | + public function post_actions($post_id, $post) { |
|
174 | 174 | |
175 | 175 | $post_type = $post->post_type; |
176 | 176 | |
177 | - if ( isset( $post->post_status ) && 'auto-draft' === $post->post_status ) { |
|
177 | + if (isset($post->post_status) && 'auto-draft' === $post->post_status) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | 180 | // this plugin does not sync log or revision posts with salesforce |
181 | - if ( isset( $post->post_type ) && in_array( $post->post_type, array( 'wp_log', 'revision' ), true ) ) { |
|
181 | + if (isset($post->post_type) && in_array($post->post_type, array('wp_log', 'revision'), true)) { |
|
182 | 182 | return; |
183 | 183 | } |
184 | - if ( $post->post_modified_gmt === $post->post_date_gmt && 'trash' !== $post->post_status ) { |
|
184 | + if ($post->post_modified_gmt === $post->post_date_gmt && 'trash' !== $post->post_status) { |
|
185 | 185 | $update = 0; |
186 | 186 | $delete = 0; |
187 | - } elseif ( 'trash' !== $post->post_status ) { |
|
187 | + } elseif ('trash' !== $post->post_status) { |
|
188 | 188 | $update = 1; |
189 | 189 | $delete = 0; |
190 | - } elseif ( 'trash' === $post->post_status ) { |
|
190 | + } elseif ('trash' === $post->post_status) { |
|
191 | 191 | $update = 0; |
192 | 192 | $delete = 1; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // add support for woocommerce if it is installed |
196 | - if ( defined( 'WC_VERSION' ) ) { |
|
196 | + if (defined('WC_VERSION')) { |
|
197 | 197 | // statuses to ignore |
198 | - if ( isset( $post->post_status ) && in_array( $post->post_status, array( 'wc-pending' ), true ) ) { |
|
198 | + if (isset($post->post_status) && in_array($post->post_status, array('wc-pending'), true)) { |
|
199 | 199 | return; |
200 | 200 | } |
201 | 201 | // statuses to count as new. note that the api will also check to see if it already has been mapped before saving. |
202 | - if ( isset( $post->post_status ) && in_array( $post->post_status, array( 'wc-on-hold', 'wc-processing' ), true ) ) { |
|
202 | + if (isset($post->post_status) && in_array($post->post_status, array('wc-on-hold', 'wc-processing'), true)) { |
|
203 | 203 | $update = 0; |
204 | 204 | $delete = 0; |
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | - $post = $this->wordpress->get_wordpress_object_data( $post->post_type, $post_id ); |
|
209 | - if ( 1 === $update ) { |
|
210 | - $this->object_update( $post, $post_type ); |
|
211 | - } elseif ( 1 === $delete ) { |
|
212 | - $this->object_delete( $post, $post_type ); |
|
208 | + $post = $this->wordpress->get_wordpress_object_data($post->post_type, $post_id); |
|
209 | + if (1 === $update) { |
|
210 | + $this->object_update($post, $post_type); |
|
211 | + } elseif (1 === $delete) { |
|
212 | + $this->object_delete($post, $post_type); |
|
213 | 213 | } else { |
214 | - $this->object_insert( $post, $post_type ); |
|
214 | + $this->object_insert($post, $post_type); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @param string $post_id |
222 | 222 | */ |
223 | - public function add_attachment( $post_id ) { |
|
224 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
225 | - $this->object_insert( $attachment, 'attachment' ); |
|
223 | + public function add_attachment($post_id) { |
|
224 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
225 | + $this->object_insert($attachment, 'attachment'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @param string $post_id |
232 | 232 | */ |
233 | - public function edit_attachment( $post_id ) { |
|
234 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
235 | - $this->object_update( $attachment, 'attachment' ); |
|
233 | + public function edit_attachment($post_id) { |
|
234 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
235 | + $this->object_update($attachment, 'attachment'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @param string $post_id |
242 | 242 | */ |
243 | - public function delete_attachment( $post_id ) { |
|
244 | - $attachment = $this->wordpress->get_wordpress_object_data( 'attachment', $post_id ); |
|
245 | - $this->object_delete( $attachment, 'attachment' ); |
|
243 | + public function delete_attachment($post_id) { |
|
244 | + $attachment = $this->wordpress->get_wordpress_object_data('attachment', $post_id); |
|
245 | + $this->object_delete($attachment, 'attachment'); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -252,9 +252,9 @@ discard block |
||
252 | 252 | * @param string $tt_id |
253 | 253 | * @param string $taxonomy |
254 | 254 | */ |
255 | - public function add_term( $term_id, $tt_id, $taxonomy ) { |
|
256 | - $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
|
257 | - $this->object_insert( $term, $taxonomy ); |
|
255 | + public function add_term($term_id, $tt_id, $taxonomy) { |
|
256 | + $term = $this->wordpress->get_wordpress_object_data($taxonomy, $term_id); |
|
257 | + $this->object_insert($term, $taxonomy); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -263,9 +263,9 @@ discard block |
||
263 | 263 | * @param string $term_id |
264 | 264 | * @param string $taxonomy |
265 | 265 | */ |
266 | - public function edit_term( $term_id, $taxonomy ) { |
|
267 | - $term = $this->wordpress->get_wordpress_object_data( $taxonomy, $term_id ); |
|
268 | - $this->object_update( $term, $taxonomy ); |
|
266 | + public function edit_term($term_id, $taxonomy) { |
|
267 | + $term = $this->wordpress->get_wordpress_object_data($taxonomy, $term_id); |
|
268 | + $this->object_update($term, $taxonomy); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | * @param string $taxonomy (slug) |
277 | 277 | * @param object $deleted_term |
278 | 278 | */ |
279 | - public function delete_term( $term, $tt_id, $taxonomy, $deleted_term ) { |
|
279 | + public function delete_term($term, $tt_id, $taxonomy, $deleted_term) { |
|
280 | 280 | $deleted_term = (array) $deleted_term; |
281 | 281 | $type = $deleted_term['taxonomy']; |
282 | - $this->object_delete( $deleted_term, $type ); |
|
282 | + $this->object_delete($deleted_term, $type); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -289,9 +289,9 @@ discard block |
||
289 | 289 | * @param int|string comment_approved |
290 | 290 | * @param array $commentdata |
291 | 291 | */ |
292 | - public function add_comment( $comment_id, $comment_approved, $commentdata = array() ) { |
|
293 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
294 | - $this->object_insert( $comment, 'comment' ); |
|
292 | + public function add_comment($comment_id, $comment_approved, $commentdata = array()) { |
|
293 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
294 | + $this->object_insert($comment, 'comment'); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -299,9 +299,9 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param string $comment_id |
301 | 301 | */ |
302 | - public function edit_comment( $comment_id ) { |
|
303 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
304 | - $this->object_update( $comment, 'comment' ); |
|
302 | + public function edit_comment($comment_id) { |
|
303 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
304 | + $this->object_update($comment, 'comment'); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -309,33 +309,33 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @param string $comment_id |
311 | 311 | */ |
312 | - public function delete_comment( $comment_id ) { |
|
313 | - $comment = $this->wordpress->get_wordpress_object_data( 'comment', $comment_id ); |
|
314 | - $this->object_delete( $comment, 'comment' ); |
|
312 | + public function delete_comment($comment_id) { |
|
313 | + $comment = $this->wordpress->get_wordpress_object_data('comment', $comment_id); |
|
314 | + $this->object_delete($comment, 'comment'); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
318 | 318 | * Insert a new object |
319 | 319 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
320 | 320 | */ |
321 | - private function object_insert( $object, $type ) { |
|
322 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_create ); |
|
321 | + private function object_insert($object, $type) { |
|
322 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_create); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
326 | 326 | * Update an existing object |
327 | 327 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
328 | 328 | */ |
329 | - private function object_update( $object, $type ) { |
|
330 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_update ); |
|
329 | + private function object_update($object, $type) { |
|
330 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_update); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
334 | 334 | * Delete an existing object |
335 | 335 | * This calls the overall push crud method, which controls queuing and sending data to the Salesforce class |
336 | 336 | */ |
337 | - private function object_delete( $object, $type ) { |
|
338 | - $this->salesforce_push_object_crud( $type, $object, $this->mappings->sync_wordpress_delete ); |
|
337 | + private function object_delete($object, $type) { |
|
338 | + $this->salesforce_push_object_crud($type, $object, $this->mappings->sync_wordpress_delete); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -352,50 +352,50 @@ discard block |
||
352 | 352 | * Are we calling this manually? |
353 | 353 | * |
354 | 354 | */ |
355 | - private function salesforce_push_object_crud( $object_type, $object, $sf_sync_trigger, $manual = false ) { |
|
355 | + private function salesforce_push_object_crud($object_type, $object, $sf_sync_trigger, $manual = false) { |
|
356 | 356 | |
357 | - $structure = $this->wordpress->get_wordpress_table_structure( $object_type ); |
|
357 | + $structure = $this->wordpress->get_wordpress_table_structure($object_type); |
|
358 | 358 | $object_id_field = $structure['id_field']; |
359 | 359 | |
360 | 360 | // there is a WordPress object to push |
361 | - if ( isset( $object[ $object_id_field ] ) ) { |
|
362 | - $mapping_object = $this->mappings->load_by_wordpress( $object_type, $object[ $object_id_field ] ); |
|
361 | + if (isset($object[$object_id_field])) { |
|
362 | + $mapping_object = $this->mappings->load_by_wordpress($object_type, $object[$object_id_field]); |
|
363 | 363 | |
364 | 364 | // there is already a mapping object for this WordPress object |
365 | - if ( isset( $mapping_object['id'] ) ) { |
|
365 | + if (isset($mapping_object['id'])) { |
|
366 | 366 | $mapping_object_id_transient = $mapping_object['id']; |
367 | 367 | } else { |
368 | 368 | // there is not a mapping object for this WordPress object id yet |
369 | 369 | // check for that transient with the currently pulling id |
370 | - $mapping_object_id_transient = (int) get_transient( 'salesforce_pulling_object_id' ); |
|
370 | + $mapping_object_id_transient = (int) get_transient('salesforce_pulling_object_id'); |
|
371 | 371 | } |
372 | 372 | |
373 | - $salesforce_pulling = (int) get_transient( 'salesforce_pulling_' . $mapping_object_id_transient ); |
|
374 | - if ( 1 === $salesforce_pulling ) { |
|
375 | - delete_transient( 'salesforce_pulling_' . $mapping_object_id_transient ); |
|
376 | - $pulling_id = get_transient( 'salesforce_pulling_object_id' ); |
|
377 | - if ( $pulling_id === $mapping_object_id_transient ) { |
|
378 | - delete_transient( 'salesforce_pulling_object_id' ); |
|
373 | + $salesforce_pulling = (int) get_transient('salesforce_pulling_' . $mapping_object_id_transient); |
|
374 | + if (1 === $salesforce_pulling) { |
|
375 | + delete_transient('salesforce_pulling_' . $mapping_object_id_transient); |
|
376 | + $pulling_id = get_transient('salesforce_pulling_object_id'); |
|
377 | + if ($pulling_id === $mapping_object_id_transient) { |
|
378 | + delete_transient('salesforce_pulling_object_id'); |
|
379 | 379 | } |
380 | 380 | return false; |
381 | 381 | } |
382 | 382 | } else { |
383 | 383 | // if we don't have a WordPress object id, we've got no business doing stuff in Salesforce |
384 | 384 | $status = 'error'; |
385 | - if ( isset( $this->logging ) ) { |
|
385 | + if (isset($this->logging)) { |
|
386 | 386 | $logging = $this->logging; |
387 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
388 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
387 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
388 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | // translators: placeholder is the name of the WordPress id field |
392 | - $title = sprintf( esc_html__( 'Error: Salesforce Push: unable to process queue item because it has no WordPress %1$s.', 'object-sync-for-salesforce' ), |
|
393 | - esc_attr( $object_id_field ) |
|
392 | + $title = sprintf(esc_html__('Error: Salesforce Push: unable to process queue item because it has no WordPress %1$s.', 'object-sync-for-salesforce'), |
|
393 | + esc_attr($object_id_field) |
|
394 | 394 | ); |
395 | 395 | |
396 | 396 | $logging->setup( |
397 | 397 | $title, |
398 | - print_r( $object, true ), // print this array because if this happens, something weird has happened and we want to log whatever we have |
|
398 | + print_r($object, true), // print this array because if this happens, something weird has happened and we want to log whatever we have |
|
399 | 399 | $sf_sync_trigger, |
400 | 400 | 0, // parent id goes here but we don't have one, so make it 0 |
401 | 401 | $status |
@@ -412,14 +412,14 @@ discard block |
||
412 | 412 | ) |
413 | 413 | ); |
414 | 414 | |
415 | - foreach ( $sf_mappings as $mapping ) { // for each mapping of this object |
|
415 | + foreach ($sf_mappings as $mapping) { // for each mapping of this object |
|
416 | 416 | $map_sync_triggers = $mapping['sync_triggers']; |
417 | 417 | |
418 | 418 | // these are bit operators, so we leave out the strict |
419 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
419 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
420 | 420 | |
421 | 421 | // hook to allow other plugins to prevent a push per-mapping. |
422 | - $push_allowed = apply_filters( $this->option_prefix . 'push_object_allowed', true, $object_type, $object, $sf_sync_trigger, $mapping ); |
|
422 | + $push_allowed = apply_filters($this->option_prefix . 'push_object_allowed', true, $object_type, $object, $sf_sync_trigger, $mapping); |
|
423 | 423 | |
424 | 424 | // example to keep from pushing the user with id of 1 |
425 | 425 | /* |
@@ -432,18 +432,18 @@ discard block |
||
432 | 432 | } |
433 | 433 | */ |
434 | 434 | |
435 | - if ( false === $push_allowed ) { |
|
435 | + if (false === $push_allowed) { |
|
436 | 436 | continue; |
437 | 437 | } |
438 | 438 | |
439 | 439 | // push drafts if the setting says so |
440 | 440 | // post status is draft, or post status is inherit and post type is not attachment |
441 | - 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'] ) ) ) { |
|
441 | + 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']))) { |
|
442 | 442 | // skip this object if it is a draft and the fieldmap settings told us to ignore it |
443 | 443 | continue; |
444 | 444 | } |
445 | 445 | |
446 | - if ( isset( $mapping['push_async'] ) && ( '1' === $mapping['push_async'] ) && false === $manual ) { |
|
446 | + if (isset($mapping['push_async']) && ('1' === $mapping['push_async']) && false === $manual) { |
|
447 | 447 | // this item is async and we want to save it to the queue |
448 | 448 | |
449 | 449 | // if we determine that the below code does not perform well, worst case scenario is we could save $data to a custom table, and pass the id to the callback method. |
@@ -457,18 +457,18 @@ discard block |
||
457 | 457 | // add a queue action to push data to salesforce |
458 | 458 | // this means we don't need the frequency for this method anymore, i think |
459 | 459 | $this->queue->add( |
460 | - $this->schedulable_classes[ $this->schedule_name ]['callback'], |
|
460 | + $this->schedulable_classes[$this->schedule_name]['callback'], |
|
461 | 461 | array( |
462 | 462 | 'object_type' => $object_type, |
463 | - 'object' => filter_var( $object[ $object_id_field ], FILTER_VALIDATE_INT ), |
|
464 | - 'mapping' => filter_var( $mapping['id'], FILTER_VALIDATE_INT ), |
|
463 | + 'object' => filter_var($object[$object_id_field], FILTER_VALIDATE_INT), |
|
464 | + 'mapping' => filter_var($mapping['id'], FILTER_VALIDATE_INT), |
|
465 | 465 | 'sf_sync_trigger' => $sf_sync_trigger, |
466 | 466 | ), |
467 | 467 | $this->schedule_name |
468 | 468 | ); |
469 | 469 | } else { |
470 | 470 | // this one is not async. do it immediately. |
471 | - $push = $this->salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ); |
|
471 | + $push = $this->salesforce_push_sync_rest($object_type, $object, $mapping, $sf_sync_trigger); |
|
472 | 472 | } // End if(). |
473 | 473 | } // End if(). if the trigger does not match our requirements, skip it |
474 | 474 | } // End foreach(). |
@@ -489,35 +489,35 @@ discard block |
||
489 | 489 | * @return true or exit the method |
490 | 490 | * |
491 | 491 | */ |
492 | - public function salesforce_push_sync_rest( $object_type, $object, $mapping, $sf_sync_trigger ) { |
|
492 | + public function salesforce_push_sync_rest($object_type, $object, $mapping, $sf_sync_trigger) { |
|
493 | 493 | |
494 | - if ( is_int( $object ) ) { |
|
494 | + if (is_int($object)) { |
|
495 | 495 | $object_id = $object; |
496 | - $object = $this->wordpress->get_wordpress_object_data( $object_type, $object_id ); |
|
496 | + $object = $this->wordpress->get_wordpress_object_data($object_type, $object_id); |
|
497 | 497 | } |
498 | 498 | |
499 | - if ( is_int( $mapping ) ) { |
|
499 | + if (is_int($mapping)) { |
|
500 | 500 | $mapping_id = $mapping; |
501 | - $mapping = $this->mappings->get_fieldmaps( $mapping_id ); |
|
501 | + $mapping = $this->mappings->get_fieldmaps($mapping_id); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | // If Salesforce is not authorized, don't do anything. |
505 | 505 | // it's unclear to me if we need to do something else here or if this is sufficient. This is all Drupal does. |
506 | - if ( true !== $this->salesforce['is_authorized'] ) { |
|
506 | + if (true !== $this->salesforce['is_authorized']) { |
|
507 | 507 | return; |
508 | 508 | } |
509 | 509 | |
510 | 510 | $sfapi = $this->salesforce['sfapi']; |
511 | 511 | |
512 | 512 | // we need to get the WordPress id here so we can check to see if the object already has a map |
513 | - $structure = $this->wordpress->get_wordpress_table_structure( $object_type ); |
|
513 | + $structure = $this->wordpress->get_wordpress_table_structure($object_type); |
|
514 | 514 | $object_id = $structure['id_field']; |
515 | 515 | |
516 | 516 | // this returns the row that maps the individual WordPress row to the individual Salesfoce row |
517 | - $mapping_object = $this->mappings->load_by_wordpress( $object_type, $object[ "$object_id" ] ); |
|
517 | + $mapping_object = $this->mappings->load_by_wordpress($object_type, $object["$object_id"]); |
|
518 | 518 | |
519 | 519 | // hook to allow other plugins to define or alter the mapping object |
520 | - $mapping_object = apply_filters( $this->option_prefix . 'push_mapping_object', $mapping_object, $object, $mapping ); |
|
520 | + $mapping_object = apply_filters($this->option_prefix . 'push_mapping_object', $mapping_object, $object, $mapping); |
|
521 | 521 | |
522 | 522 | // we already have the data from WordPress at this point; we just need to work with it in Salesforce |
523 | 523 | $synced_object = array( |
@@ -531,84 +531,84 @@ discard block |
||
531 | 531 | |
532 | 532 | // deleting mapped objects |
533 | 533 | // these are bit operators, so we leave out the strict |
534 | - if ( $sf_sync_trigger == $this->mappings->sync_wordpress_delete ) { |
|
535 | - if ( isset( $mapping_object['id'] ) ) { |
|
534 | + if ($sf_sync_trigger == $this->mappings->sync_wordpress_delete) { |
|
535 | + if (isset($mapping_object['id'])) { |
|
536 | 536 | $op = 'Delete'; |
537 | 537 | |
538 | - $salesforce_check = $this->mappings->load_by_salesforce( $mapping_object['salesforce_id'] ); |
|
538 | + $salesforce_check = $this->mappings->load_by_salesforce($mapping_object['salesforce_id']); |
|
539 | 539 | |
540 | - if ( count( $salesforce_check ) === count( $salesforce_check, COUNT_RECURSIVE ) ) { |
|
540 | + if (count($salesforce_check) === count($salesforce_check, COUNT_RECURSIVE)) { |
|
541 | 541 | try { |
542 | - $result = $sfapi->object_delete( $mapping['salesforce_object'], $mapping_object['salesforce_id'] ); |
|
543 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
542 | + $result = $sfapi->object_delete($mapping['salesforce_object'], $mapping_object['salesforce_id']); |
|
543 | + } catch (Object_Sync_Sf_Exception $e) { |
|
544 | 544 | $status = 'error'; |
545 | 545 | // create log entry for failed delete |
546 | - if ( isset( $this->logging ) ) { |
|
546 | + if (isset($this->logging)) { |
|
547 | 547 | $logging = $this->logging; |
548 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
549 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
548 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
549 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | // 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 |
553 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
554 | - esc_attr( $op ), |
|
555 | - esc_attr( $mapping['salesforce_object'] ), |
|
556 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
557 | - esc_attr( $mapping['wordpress_object'] ), |
|
558 | - esc_attr( $object_id ), |
|
559 | - esc_attr( $object[ "$object_id" ] ) |
|
553 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
554 | + esc_attr($op), |
|
555 | + esc_attr($mapping['salesforce_object']), |
|
556 | + esc_attr($mapping_object['salesforce_id']), |
|
557 | + esc_attr($mapping['wordpress_object']), |
|
558 | + esc_attr($object_id), |
|
559 | + esc_attr($object["$object_id"]) |
|
560 | 560 | ); |
561 | 561 | |
562 | 562 | $logging->setup( |
563 | 563 | $title, |
564 | 564 | $e->getMessage(), |
565 | 565 | $sf_sync_trigger, |
566 | - $object[ "$object_id" ], |
|
566 | + $object["$object_id"], |
|
567 | 567 | $status |
568 | 568 | ); |
569 | 569 | |
570 | 570 | // hook for push fail |
571 | - do_action( $this->option_prefix . 'push_fail', $op, $sfapi->response, $synced_object, $object_id ); |
|
571 | + do_action($this->option_prefix . 'push_fail', $op, $sfapi->response, $synced_object, $object_id); |
|
572 | 572 | |
573 | 573 | } |
574 | 574 | |
575 | - if ( ! isset( $e ) ) { |
|
575 | + if ( ! isset($e)) { |
|
576 | 576 | // create log entry for successful delete if the result had no errors |
577 | 577 | $status = 'success'; |
578 | - if ( isset( $this->logging ) ) { |
|
578 | + if (isset($this->logging)) { |
|
579 | 579 | $logging = $this->logging; |
580 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
581 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
580 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
581 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | // 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 |
585 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
586 | - esc_attr( $op ), |
|
587 | - esc_attr( $mapping['salesforce_object'] ), |
|
588 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
589 | - esc_attr( $mapping['wordpress_object'] ), |
|
590 | - esc_attr( $object_id ), |
|
591 | - esc_attr( $object[ "$object_id" ] ) |
|
585 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
586 | + esc_attr($op), |
|
587 | + esc_attr($mapping['salesforce_object']), |
|
588 | + esc_attr($mapping_object['salesforce_id']), |
|
589 | + esc_attr($mapping['wordpress_object']), |
|
590 | + esc_attr($object_id), |
|
591 | + esc_attr($object["$object_id"]) |
|
592 | 592 | ); |
593 | 593 | |
594 | 594 | $logging->setup( |
595 | 595 | $title, |
596 | 596 | '', |
597 | 597 | $sf_sync_trigger, |
598 | - $object[ "$object_id" ], |
|
598 | + $object["$object_id"], |
|
599 | 599 | $status |
600 | 600 | ); |
601 | 601 | |
602 | 602 | // hook for push success |
603 | - do_action( $this->option_prefix . 'push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
603 | + do_action($this->option_prefix . 'push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
604 | 604 | } |
605 | 605 | } else { |
606 | 606 | $more_ids = '<p>The Salesforce record was not deleted because there are multiple WordPress IDs that match this Salesforce ID. They are: '; |
607 | 607 | $i = 0; |
608 | - foreach ( $salesforce_check as $match ) { |
|
608 | + foreach ($salesforce_check as $match) { |
|
609 | 609 | $i++; |
610 | 610 | $more_ids .= $match['wordpress_id']; |
611 | - if ( count( $salesforce_check ) !== $i ) { |
|
611 | + if (count($salesforce_check) !== $i) { |
|
612 | 612 | $more_ids .= ', '; |
613 | 613 | } else { |
614 | 614 | $more_ids .= '.</p>'; |
@@ -618,34 +618,34 @@ discard block |
||
618 | 618 | $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>'; |
619 | 619 | |
620 | 620 | $status = 'notice'; |
621 | - if ( isset( $this->logging ) ) { |
|
621 | + if (isset($this->logging)) { |
|
622 | 622 | $logging = $this->logging; |
623 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
624 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
623 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
624 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | // 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 |
628 | - $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' ), |
|
629 | - esc_attr( $op ), |
|
630 | - esc_attr( $mapping['salesforce_object'] ), |
|
631 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
632 | - esc_attr( $mapping['wordpress_object'] ), |
|
633 | - esc_attr( $object_id ), |
|
634 | - esc_attr( $object[ "$object_id" ] ) |
|
628 | + $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'), |
|
629 | + esc_attr($op), |
|
630 | + esc_attr($mapping['salesforce_object']), |
|
631 | + esc_attr($mapping_object['salesforce_id']), |
|
632 | + esc_attr($mapping['wordpress_object']), |
|
633 | + esc_attr($object_id), |
|
634 | + esc_attr($object["$object_id"]) |
|
635 | 635 | ); |
636 | 636 | |
637 | 637 | $logging->setup( |
638 | 638 | $title, |
639 | 639 | $more_ids, |
640 | 640 | $sf_sync_trigger, |
641 | - $object[ "$object_id" ], |
|
641 | + $object["$object_id"], |
|
642 | 642 | $status |
643 | 643 | ); |
644 | 644 | } // End if(). |
645 | 645 | |
646 | 646 | // delete the map row from WordPress after the Salesforce row has been deleted |
647 | 647 | // we delete the map row even if the Salesforce delete failed, because the WordPress object is gone |
648 | - $this->mappings->delete_object_map( $mapping_object['id'] ); |
|
648 | + $this->mappings->delete_object_map($mapping_object['id']); |
|
649 | 649 | |
650 | 650 | } // End if(). there is no map row |
651 | 651 | |
@@ -653,52 +653,52 @@ discard block |
||
653 | 653 | } // End if(). |
654 | 654 | |
655 | 655 | // are these objects already connected in WordPress? |
656 | - if ( isset( $mapping_object['id'] ) ) { |
|
656 | + if (isset($mapping_object['id'])) { |
|
657 | 657 | $is_new = false; |
658 | 658 | } else { |
659 | 659 | $is_new = true; |
660 | 660 | } |
661 | 661 | |
662 | 662 | // map the WordPress values to salesforce fields |
663 | - $params = $this->mappings->map_params( $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
663 | + $params = $this->mappings->map_params($mapping, $object, $sf_sync_trigger, false, $is_new); |
|
664 | 664 | |
665 | 665 | // hook to allow other plugins to modify the $params array |
666 | 666 | // use hook to map fields between the WordPress and Salesforce objects |
667 | 667 | // returns $params. |
668 | - $params = apply_filters( $this->option_prefix . 'push_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
668 | + $params = apply_filters($this->option_prefix . 'push_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new); |
|
669 | 669 | |
670 | 670 | // if we don't get any params, there are no fields that should be sent to Salesforce |
671 | - if ( empty( $params ) ) { |
|
671 | + if (empty($params)) { |
|
672 | 672 | return; |
673 | 673 | } |
674 | 674 | |
675 | 675 | // if there is a prematch WordPress field - ie email - on the fieldmap object |
676 | - if ( isset( $params['prematch'] ) && is_array( $params['prematch'] ) ) { |
|
676 | + if (isset($params['prematch']) && is_array($params['prematch'])) { |
|
677 | 677 | $prematch_field_wordpress = $params['prematch']['wordpress_field']; |
678 | 678 | $prematch_field_salesforce = $params['prematch']['salesforce_field']; |
679 | 679 | $prematch_value = $params['prematch']['value']; |
680 | - unset( $params['prematch'] ); |
|
680 | + unset($params['prematch']); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | // if there is an external key field in Salesforce - ie mailchimp user id - on the fieldmap object |
684 | - if ( isset( $params['key'] ) && is_array( $params['key'] ) ) { |
|
684 | + if (isset($params['key']) && is_array($params['key'])) { |
|
685 | 685 | $key_field_wordpress = $params['key']['wordpress_field']; |
686 | 686 | $key_field_salesforce = $params['key']['salesforce_field']; |
687 | 687 | $key_value = $params['key']['value']; |
688 | - unset( $params['key'] ); |
|
688 | + unset($params['key']); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | $frequencies = $this->queue->get_frequencies(); |
692 | - $seconds = reset( $frequencies )['frequency'] + 60; |
|
692 | + $seconds = reset($frequencies)['frequency'] + 60; |
|
693 | 693 | |
694 | - if ( true === $is_new ) { |
|
694 | + if (true === $is_new) { |
|
695 | 695 | |
696 | 696 | // right here we should set the pushing transient |
697 | 697 | // this means we have to create the mapping object here as well, and update it with the correct IDs after successful response |
698 | 698 | // create the mapping object between the rows |
699 | - $mapping_object_id = $this->create_object_map( $object, $object_id, $this->mappings->generate_temporary_id( 'push' ), $mapping, true ); |
|
700 | - set_transient( 'salesforce_pushing_' . $mapping_object_id, 1, $seconds ); |
|
701 | - set_transient( 'salesforce_pushing_object_id', $mapping_object_id ); |
|
699 | + $mapping_object_id = $this->create_object_map($object, $object_id, $this->mappings->generate_temporary_id('push'), $mapping, true); |
|
700 | + set_transient('salesforce_pushing_' . $mapping_object_id, 1, $seconds); |
|
701 | + set_transient('salesforce_pushing_object_id', $mapping_object_id); |
|
702 | 702 | $mapping_object = $this->mappings->get_object_maps( |
703 | 703 | array( |
704 | 704 | 'id' => $mapping_object_id, |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | |
708 | 708 | // setup SF record type. CampaignMember objects get their Campaign's type |
709 | 709 | // i am still a bit confused about this |
710 | - if ( $mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty( $params['RecordTypeId'] ) && ( 'CampaignMember' !== $mapping['salesforce_object'] ) ) { |
|
710 | + if ($mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty($params['RecordTypeId']) && ('CampaignMember' !== $mapping['salesforce_object'])) { |
|
711 | 711 | $params['RecordTypeId'] = $mapping['salesforce_record_type_default']; |
712 | 712 | } |
713 | 713 | |
@@ -719,61 +719,61 @@ discard block |
||
719 | 719 | // returns a $salesforce_id. |
720 | 720 | // it should keep NULL if there is no match |
721 | 721 | // the function that calls this hook needs to check the mapping to make sure the WordPress object is the right type |
722 | - $salesforce_id = apply_filters( $this->option_prefix . 'find_sf_object_match', null, $object, $mapping, 'push' ); |
|
722 | + $salesforce_id = apply_filters($this->option_prefix . 'find_sf_object_match', null, $object, $mapping, 'push'); |
|
723 | 723 | |
724 | 724 | // hook to allow other plugins to do something right before Salesforce data is saved |
725 | 725 | // ex: run WordPress methods on an object if it exists, or do something in preparation for it if it doesn't |
726 | - do_action( $this->option_prefix . 'pre_push', $salesforce_id, $mapping, $object, $object_id, $params ); |
|
726 | + do_action($this->option_prefix . 'pre_push', $salesforce_id, $mapping, $object, $object_id, $params); |
|
727 | 727 | |
728 | 728 | // hook to allow other plugins to change params on update actions only |
729 | 729 | // use hook to map fields between the WordPress and Salesforce objects |
730 | 730 | // returns $params. |
731 | - $params = apply_filters( $this->option_prefix . 'push_update_params_modify', $params, $salesforce_id, $mapping, $object ); |
|
731 | + $params = apply_filters($this->option_prefix . 'push_update_params_modify', $params, $salesforce_id, $mapping, $object); |
|
732 | 732 | |
733 | - if ( isset( $prematch_field_wordpress ) || isset( $key_field_wordpress ) || null !== $salesforce_id ) { |
|
733 | + if (isset($prematch_field_wordpress) || isset($key_field_wordpress) || null !== $salesforce_id) { |
|
734 | 734 | |
735 | 735 | // if either prematch criteria exists, make the values queryable |
736 | 736 | |
737 | - if ( isset( $prematch_field_wordpress ) ) { |
|
737 | + if (isset($prematch_field_wordpress)) { |
|
738 | 738 | // a prematch has been specified, attempt an upsert(). |
739 | 739 | // prematch values with punctuation need to be escaped |
740 | - $encoded_prematch_value = rawurlencode( $prematch_value ); |
|
740 | + $encoded_prematch_value = rawurlencode($prematch_value); |
|
741 | 741 | // for at least 'email' fields, periods also need to be escaped: |
742 | 742 | // https://developer.salesforce.com/forums?id=906F000000099xPIAQ |
743 | - $encoded_prematch_value = str_replace( '.', '%2E', $encoded_prematch_value ); |
|
743 | + $encoded_prematch_value = str_replace('.', '%2E', $encoded_prematch_value); |
|
744 | 744 | } |
745 | 745 | |
746 | - if ( isset( $key_field_wordpress ) ) { |
|
746 | + if (isset($key_field_wordpress)) { |
|
747 | 747 | // an external key has been specified, attempt an upsert(). |
748 | 748 | // external key values with punctuation need to be escaped |
749 | - $encoded_key_value = rawurlencode( $key_value ); |
|
749 | + $encoded_key_value = rawurlencode($key_value); |
|
750 | 750 | // for at least 'email' fields, periods also need to be escaped: |
751 | 751 | // https://developer.salesforce.com/forums?id=906F000000099xPIAQ |
752 | - $encoded_key_value = str_replace( '.', '%2E', $encoded_key_value ); |
|
752 | + $encoded_key_value = str_replace('.', '%2E', $encoded_key_value); |
|
753 | 753 | } |
754 | 754 | |
755 | - if ( isset( $prematch_field_wordpress ) ) { |
|
755 | + if (isset($prematch_field_wordpress)) { |
|
756 | 756 | $upsert_key = $prematch_field_salesforce; |
757 | 757 | $upsert_value = $encoded_prematch_value; |
758 | - } elseif ( isset( $key_field_wordpress ) ) { |
|
758 | + } elseif (isset($key_field_wordpress)) { |
|
759 | 759 | $upsert_key = $key_field_salesforce; |
760 | 760 | $upsert_value = $encoded_key_value; |
761 | 761 | } |
762 | 762 | |
763 | - if ( null !== $salesforce_id ) { |
|
763 | + if (null !== $salesforce_id) { |
|
764 | 764 | $upsert_key = 'Id'; |
765 | 765 | $upsert_value = $salesforce_id; |
766 | 766 | } |
767 | 767 | |
768 | 768 | $op = 'Upsert'; |
769 | 769 | |
770 | - $result = $sfapi->object_upsert( $mapping['salesforce_object'], $upsert_key, $upsert_value, $params ); |
|
770 | + $result = $sfapi->object_upsert($mapping['salesforce_object'], $upsert_key, $upsert_value, $params); |
|
771 | 771 | |
772 | 772 | // Handle upsert responses. |
773 | - switch ( $sfapi->response['code'] ) { |
|
773 | + switch ($sfapi->response['code']) { |
|
774 | 774 | // On Upsert:update retrieved object. |
775 | 775 | case '204': |
776 | - $sf_object = $sfapi->object_readby_external_id( $mapping['salesforce_object'], $upsert_key, $upsert_value ); |
|
776 | + $sf_object = $sfapi->object_readby_external_id($mapping['salesforce_object'], $upsert_key, $upsert_value); |
|
777 | 777 | $salesforce_data['id'] = $sf_object['data']['Id']; |
778 | 778 | break; |
779 | 779 | // Handle duplicate records. |
@@ -784,43 +784,43 @@ discard block |
||
784 | 784 | } else { |
785 | 785 | // No key or prematch field exists on this field map object, create a new object in Salesforce. |
786 | 786 | $op = 'Create'; |
787 | - $result = $sfapi->object_create( $mapping['salesforce_object'], $params ); |
|
787 | + $result = $sfapi->object_create($mapping['salesforce_object'], $params); |
|
788 | 788 | } // End if(). |
789 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
789 | + } catch (Object_Sync_Sf_Exception $e) { |
|
790 | 790 | // create log entry for failed create or upsert |
791 | 791 | $status = 'error'; |
792 | 792 | |
793 | - if ( isset( $this->logging ) ) { |
|
793 | + if (isset($this->logging)) { |
|
794 | 794 | $logging = $this->logging; |
795 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
796 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
795 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
796 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | // 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 |
800 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
801 | - esc_attr( $op ), |
|
802 | - esc_attr( $mapping['salesforce_object'] ), |
|
803 | - isset( $salesforce_id ) ? ' ' . esc_attr( $salesforce_id ) : '', |
|
804 | - esc_attr( $mapping['wordpress_object'] ), |
|
805 | - esc_attr( $object_id ), |
|
806 | - esc_attr( $object[ "$object_id" ] ) |
|
800 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
801 | + esc_attr($op), |
|
802 | + esc_attr($mapping['salesforce_object']), |
|
803 | + isset($salesforce_id) ? ' ' . esc_attr($salesforce_id) : '', |
|
804 | + esc_attr($mapping['wordpress_object']), |
|
805 | + esc_attr($object_id), |
|
806 | + esc_attr($object["$object_id"]) |
|
807 | 807 | ); |
808 | 808 | |
809 | 809 | $logging->setup( |
810 | 810 | $title, |
811 | 811 | $e->getMessage(), |
812 | 812 | $sf_sync_trigger, |
813 | - $object[ "$object_id" ], |
|
813 | + $object["$object_id"], |
|
814 | 814 | $status |
815 | 815 | ); |
816 | 816 | |
817 | 817 | // hook for push fail |
818 | - do_action( $this->option_prefix . 'push_fail', $op, $sfapi->response, $synced_object ); |
|
818 | + do_action($this->option_prefix . 'push_fail', $op, $sfapi->response, $synced_object); |
|
819 | 819 | |
820 | 820 | return; |
821 | 821 | } // End try(). |
822 | 822 | |
823 | - if ( ! isset( $salesforce_data ) ) { |
|
823 | + if ( ! isset($salesforce_data)) { |
|
824 | 824 | // if we didn't set $salesforce_data already, set it now to api call result |
825 | 825 | $salesforce_data = $result['data']; |
826 | 826 | } |
@@ -829,78 +829,78 @@ discard block |
||
829 | 829 | // this means the object has already been created/updated in Salesforce |
830 | 830 | // 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) |
831 | 831 | |
832 | - if ( empty( $result['errorCode'] ) ) { |
|
832 | + if (empty($result['errorCode'])) { |
|
833 | 833 | $salesforce_id = $salesforce_data['id']; |
834 | 834 | $status = 'success'; |
835 | 835 | |
836 | - if ( isset( $this->logging ) ) { |
|
836 | + if (isset($this->logging)) { |
|
837 | 837 | $logging = $this->logging; |
838 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
839 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
838 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
839 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | // 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 |
843 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
844 | - esc_attr( $op ), |
|
845 | - esc_attr( $mapping['salesforce_object'] ), |
|
846 | - esc_attr( $salesforce_id ), |
|
847 | - esc_attr( $mapping['wordpress_object'] ), |
|
848 | - esc_attr( $object_id ), |
|
849 | - esc_attr( $object[ "$object_id" ] ) |
|
843 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
844 | + esc_attr($op), |
|
845 | + esc_attr($mapping['salesforce_object']), |
|
846 | + esc_attr($salesforce_id), |
|
847 | + esc_attr($mapping['wordpress_object']), |
|
848 | + esc_attr($object_id), |
|
849 | + esc_attr($object["$object_id"]) |
|
850 | 850 | ); |
851 | 851 | |
852 | 852 | $logging->setup( |
853 | 853 | $title, |
854 | 854 | '', |
855 | 855 | $sf_sync_trigger, |
856 | - $object[ "$object_id" ], |
|
856 | + $object["$object_id"], |
|
857 | 857 | $status |
858 | 858 | ); |
859 | 859 | |
860 | 860 | // update that mapping object |
861 | 861 | $mapping_object['salesforce_id'] = $salesforce_id; |
862 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
863 | - $mapping_object = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
862 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
863 | + $mapping_object = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
864 | 864 | |
865 | 865 | // hook for push success |
866 | - do_action( $this->option_prefix . 'push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
866 | + do_action($this->option_prefix . 'push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
867 | 867 | } else { |
868 | 868 | |
869 | 869 | // create log entry for failed create or upsert |
870 | 870 | // 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 |
871 | 871 | // if we see this in the log entries, we can understand what it does, but probably not until then |
872 | 872 | $status = 'error'; |
873 | - if ( isset( $this->logging ) ) { |
|
873 | + if (isset($this->logging)) { |
|
874 | 874 | $logging = $this->logging; |
875 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
876 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
875 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
876 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | // 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 |
880 | - $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' ), |
|
881 | - absint( $salesforce_data['errorCode'] ), |
|
882 | - esc_attr( $op ), |
|
883 | - esc_attr( $mapping['wordpress_object'] ), |
|
884 | - esc_attr( $object_id ), |
|
885 | - esc_attr( $object[ "$object_id" ] ) |
|
880 | + $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'), |
|
881 | + absint($salesforce_data['errorCode']), |
|
882 | + esc_attr($op), |
|
883 | + esc_attr($mapping['wordpress_object']), |
|
884 | + esc_attr($object_id), |
|
885 | + esc_attr($object["$object_id"]) |
|
886 | 886 | ); |
887 | 887 | |
888 | 888 | // translators: placeholders are 1) the name of the Salesforce object type, 2) the error message returned from the Salesforce APIs |
889 | - $body = sprintf( '<p>' . esc_html__( 'Object: %1$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Message: %2$s', 'object-sync-for-salesforce' ) . '</p>', |
|
890 | - esc_attr( $mapping['salesforce_object'] ), |
|
891 | - esc_html( $salesforce_data['message'] ) |
|
889 | + $body = sprintf('<p>' . esc_html__('Object: %1$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Message: %2$s', 'object-sync-for-salesforce') . '</p>', |
|
890 | + esc_attr($mapping['salesforce_object']), |
|
891 | + esc_html($salesforce_data['message']) |
|
892 | 892 | ); |
893 | 893 | |
894 | 894 | $logging->setup( |
895 | 895 | $title, |
896 | 896 | $body, |
897 | 897 | $sf_sync_trigger, |
898 | - $object[ "$object_id" ], |
|
898 | + $object["$object_id"], |
|
899 | 899 | $status |
900 | 900 | ); |
901 | 901 | |
902 | 902 | // hook for push fail |
903 | - do_action( $this->option_prefix . 'push_fail', $op, $sfapi->response, $synced_object ); |
|
903 | + do_action($this->option_prefix . 'push_fail', $op, $sfapi->response, $synced_object); |
|
904 | 904 | |
905 | 905 | return; |
906 | 906 | } // End if(). |
@@ -908,41 +908,41 @@ discard block |
||
908 | 908 | // $is_new is false here; we are updating an already mapped object |
909 | 909 | |
910 | 910 | // right here we should set the pushing transient |
911 | - set_transient( 'salesforce_pushing_' . $mapping_object['id'], 1, $seconds ); |
|
912 | - set_transient( 'salesforce_pushing_object_id', $mapping_object['id'] ); |
|
911 | + set_transient('salesforce_pushing_' . $mapping_object['id'], 1, $seconds); |
|
912 | + set_transient('salesforce_pushing_object_id', $mapping_object['id']); |
|
913 | 913 | |
914 | 914 | // there is an existing object link |
915 | 915 | // if the last sync is greater than the last time this object was updated, skip it |
916 | 916 | // this keeps us from doing redundant syncs |
917 | - $mapping_object['object_updated'] = current_time( 'mysql' ); |
|
918 | - if ( $mapping_object['last_sync'] > $mapping_object['object_updated'] ) { |
|
917 | + $mapping_object['object_updated'] = current_time('mysql'); |
|
918 | + if ($mapping_object['last_sync'] > $mapping_object['object_updated']) { |
|
919 | 919 | $status = 'notice'; |
920 | - if ( isset( $this->logging ) ) { |
|
920 | + if (isset($this->logging)) { |
|
921 | 921 | $logging = $this->logging; |
922 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
923 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
922 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
923 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | // 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 |
927 | - $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' ), |
|
928 | - esc_attr( $op ), |
|
929 | - esc_attr( $mapping['wordpress_object'] ), |
|
930 | - esc_attr( $object_id ), |
|
931 | - esc_attr( $object[ "$object_id" ] ), |
|
932 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
927 | + $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'), |
|
928 | + esc_attr($op), |
|
929 | + esc_attr($mapping['wordpress_object']), |
|
930 | + esc_attr($object_id), |
|
931 | + esc_attr($object["$object_id"]), |
|
932 | + esc_attr($mapping_object['salesforce_id']) |
|
933 | 933 | ); |
934 | 934 | |
935 | 935 | // translators: placeholders are 1) when a sync on this mapping last occured, 2) when the object was last updated |
936 | - $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>', |
|
937 | - esc_attr( $mapping_object['last_sync'] ), |
|
938 | - esc_html( $mapping_object['object_updated'] ) |
|
936 | + $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>', |
|
937 | + esc_attr($mapping_object['last_sync']), |
|
938 | + esc_html($mapping_object['object_updated']) |
|
939 | 939 | ); |
940 | 940 | |
941 | 941 | $logging->setup( |
942 | 942 | $title, |
943 | 943 | $body, |
944 | 944 | $sf_sync_trigger, |
945 | - $object[ "$object_id" ], |
|
945 | + $object["$object_id"], |
|
946 | 946 | $status |
947 | 947 | ); |
948 | 948 | return; |
@@ -953,71 +953,71 @@ discard block |
||
953 | 953 | |
954 | 954 | // hook to allow other plugins to do something right before Salesforce data is saved |
955 | 955 | // ex: run WordPress methods on an object if it exists, or do something in preparation for it if it doesn't |
956 | - do_action( $this->option_prefix . 'pre_push', $mapping_object['salesforce_id'], $mapping, $object, $object_id, $params ); |
|
956 | + do_action($this->option_prefix . 'pre_push', $mapping_object['salesforce_id'], $mapping, $object, $object_id, $params); |
|
957 | 957 | |
958 | 958 | // hook to allow other plugins to change params on update actions only |
959 | 959 | // use hook to map fields between the WordPress and Salesforce objects |
960 | 960 | // returns $params. |
961 | - $params = apply_filters( $this->option_prefix . 'push_update_params_modify', $params, $mapping_object['salesforce_id'], $mapping, $object ); |
|
961 | + $params = apply_filters($this->option_prefix . 'push_update_params_modify', $params, $mapping_object['salesforce_id'], $mapping, $object); |
|
962 | 962 | |
963 | 963 | $op = 'Update'; |
964 | - $result = $sfapi->object_update( $mapping['salesforce_object'], $mapping_object['salesforce_id'], $params ); |
|
964 | + $result = $sfapi->object_update($mapping['salesforce_object'], $mapping_object['salesforce_id'], $params); |
|
965 | 965 | |
966 | 966 | $mapping_object['last_sync_status'] = $this->mappings->status_success; |
967 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
967 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
968 | 968 | |
969 | 969 | $status = 'success'; |
970 | - if ( isset( $this->logging ) ) { |
|
970 | + if (isset($this->logging)) { |
|
971 | 971 | $logging = $this->logging; |
972 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
973 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
972 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
973 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | // 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 |
977 | - $title = sprintf( esc_html__( 'Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
978 | - esc_attr( $op ), |
|
979 | - esc_attr( $mapping['salesforce_object'] ), |
|
980 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
981 | - esc_attr( $mapping['wordpress_object'] ), |
|
982 | - esc_attr( $object_id ), |
|
983 | - esc_attr( $object[ "$object_id" ] ) |
|
977 | + $title = sprintf(esc_html__('Success: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
978 | + esc_attr($op), |
|
979 | + esc_attr($mapping['salesforce_object']), |
|
980 | + esc_attr($mapping_object['salesforce_id']), |
|
981 | + esc_attr($mapping['wordpress_object']), |
|
982 | + esc_attr($object_id), |
|
983 | + esc_attr($object["$object_id"]) |
|
984 | 984 | ); |
985 | 985 | |
986 | 986 | $logging->setup( |
987 | 987 | $title, |
988 | 988 | '', |
989 | 989 | $sf_sync_trigger, |
990 | - $object[ "$object_id" ], |
|
990 | + $object["$object_id"], |
|
991 | 991 | $status |
992 | 992 | ); |
993 | 993 | |
994 | 994 | // hook for push success |
995 | - do_action( $this->option_prefix . 'push_success', $op, $sfapi->response, $synced_object, $object_id ); |
|
995 | + do_action($this->option_prefix . 'push_success', $op, $sfapi->response, $synced_object, $object_id); |
|
996 | 996 | |
997 | - } catch ( Object_Sync_Sf_Exception $e ) { |
|
997 | + } catch (Object_Sync_Sf_Exception $e) { |
|
998 | 998 | // create log entry for failed update |
999 | 999 | $status = 'error'; |
1000 | - if ( isset( $this->logging ) ) { |
|
1000 | + if (isset($this->logging)) { |
|
1001 | 1001 | $logging = $this->logging; |
1002 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1003 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1002 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1003 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | // 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 |
1007 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce' ), |
|
1008 | - esc_attr( $op ), |
|
1009 | - esc_attr( $mapping['salesforce_object'] ), |
|
1010 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
1011 | - esc_attr( $mapping['wordpress_object'] ), |
|
1012 | - esc_attr( $object_id ), |
|
1013 | - esc_attr( $object[ "$object_id" ] ) |
|
1007 | + $title = sprintf(esc_html__('Error: %1$s %2$s %3$s (WordPress %4$s with %5$s of %6$s)', 'object-sync-for-salesforce'), |
|
1008 | + esc_attr($op), |
|
1009 | + esc_attr($mapping['salesforce_object']), |
|
1010 | + esc_attr($mapping_object['salesforce_id']), |
|
1011 | + esc_attr($mapping['wordpress_object']), |
|
1012 | + esc_attr($object_id), |
|
1013 | + esc_attr($object["$object_id"]) |
|
1014 | 1014 | ); |
1015 | 1015 | |
1016 | 1016 | $logging->setup( |
1017 | 1017 | $title, |
1018 | 1018 | $e->getMessage(), |
1019 | 1019 | $sf_sync_trigger, |
1020 | - $object[ "$object_id" ], |
|
1020 | + $object["$object_id"], |
|
1021 | 1021 | $status |
1022 | 1022 | ); |
1023 | 1023 | |
@@ -1025,16 +1025,16 @@ discard block |
||
1025 | 1025 | $mapping_object['last_sync_message'] = $e->getMessage(); |
1026 | 1026 | |
1027 | 1027 | // hook for push fail |
1028 | - do_action( $this->option_prefix . 'push_fail', $op, $sfapi->response, $synced_object ); |
|
1028 | + do_action($this->option_prefix . 'push_fail', $op, $sfapi->response, $synced_object); |
|
1029 | 1029 | |
1030 | 1030 | } // End try(). |
1031 | 1031 | |
1032 | 1032 | // tell the mapping object - whether it is new or already existed - how we just used it |
1033 | 1033 | $mapping_object['last_sync_action'] = 'push'; |
1034 | - $mapping_object['last_sync'] = current_time( 'mysql' ); |
|
1034 | + $mapping_object['last_sync'] = current_time('mysql'); |
|
1035 | 1035 | |
1036 | 1036 | // update that mapping object |
1037 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1037 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1038 | 1038 | |
1039 | 1039 | } // End if(). this is the end of the if is_new stuff |
1040 | 1040 | |
@@ -1056,9 +1056,9 @@ discard block |
||
1056 | 1056 | * This is the database row for the map object |
1057 | 1057 | * |
1058 | 1058 | */ |
1059 | - private function create_object_map( $wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false ) { |
|
1059 | + private function create_object_map($wordpress_object, $id_field_name, $salesforce_id, $field_mapping, $pending = false) { |
|
1060 | 1060 | |
1061 | - if ( true === $pending ) { |
|
1061 | + if (true === $pending) { |
|
1062 | 1062 | $action = 'pending'; |
1063 | 1063 | } else { |
1064 | 1064 | $action = 'created'; |
@@ -1067,15 +1067,15 @@ discard block |
||
1067 | 1067 | // Create object map and save it |
1068 | 1068 | $mapping_object = $this->mappings->create_object_map( |
1069 | 1069 | array( |
1070 | - 'wordpress_id' => $wordpress_object[ $id_field_name ], // wordpress unique id |
|
1070 | + 'wordpress_id' => $wordpress_object[$id_field_name], // wordpress unique id |
|
1071 | 1071 | 'salesforce_id' => $salesforce_id, // salesforce unique id. we don't care what kind of object it is at this point |
1072 | 1072 | 'wordpress_object' => $field_mapping['wordpress_object'], // keep track of what kind of wp object this is |
1073 | - 'last_sync' => current_time( 'mysql' ), |
|
1073 | + 'last_sync' => current_time('mysql'), |
|
1074 | 1074 | 'last_sync_action' => 'push', |
1075 | 1075 | 'last_sync_status' => $this->mappings->status_success, |
1076 | 1076 | // translators: placeholder is for the action that occurred on the mapping object (pending or created) |
1077 | - 'last_sync_message' => sprintf( esc_html__( 'Mapping object %1$s via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
1078 | - esc_attr( $action ) |
|
1077 | + 'last_sync_message' => sprintf(esc_html__('Mapping object %1$s via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
1078 | + esc_attr($action) |
|
1079 | 1079 | ), |
1080 | 1080 | 'action' => $action, |
1081 | 1081 | ) |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @file |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! class_exists( 'Object_Sync_Salesforce' ) ) { |
|
8 | +if ( ! class_exists('Object_Sync_Salesforce')) { |
|
9 | 9 | die(); |
10 | 10 | } |
11 | 11 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param array $schedulable_classes |
45 | 45 | * array of classes that can have scheduled tasks specific to them |
46 | 46 | */ |
47 | - public function __construct( $consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $option_prefix, $logging, $schedulable_classes ) { |
|
47 | + public function __construct($consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $option_prefix, $logging, $schedulable_classes) { |
|
48 | 48 | $this->consumer_key = $consumer_key; |
49 | 49 | $this->consumer_secret = $consumer_secret; |
50 | 50 | $this->login_url = $login_url; |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | 'type' => 'read', |
64 | 64 | ); |
65 | 65 | |
66 | - $this->success_codes = array( 200, 201, 204 ); |
|
66 | + $this->success_codes = array(200, 201, 204); |
|
67 | 67 | $this->refresh_code = 401; |
68 | 68 | $this->success_or_refresh_codes = $this->success_codes; |
69 | 69 | $this->success_or_refresh_codes[] = $this->refresh_code; |
70 | 70 | |
71 | - $this->debug = get_option( $this->option_prefix . 'debug_mode', false ); |
|
71 | + $this->debug = get_option($this->option_prefix . 'debug_mode', false); |
|
72 | 72 | |
73 | 73 | } |
74 | 74 | |
@@ -81,20 +81,20 @@ discard block |
||
81 | 81 | * @return string |
82 | 82 | * 18-character case-insensitive Salesforce ID |
83 | 83 | */ |
84 | - public static function convert_id( $sf_id_15 ) { |
|
85 | - if ( strlen( $sf_id_15 ) !== 15 ) { |
|
84 | + public static function convert_id($sf_id_15) { |
|
85 | + if (strlen($sf_id_15) !== 15) { |
|
86 | 86 | return $sf_id_15; |
87 | 87 | } |
88 | - $chunks = str_split( $sf_id_15, 5 ); |
|
88 | + $chunks = str_split($sf_id_15, 5); |
|
89 | 89 | $extra = ''; |
90 | - foreach ( $chunks as $chunk ) { |
|
91 | - $chars = str_split( $chunk, 1 ); |
|
90 | + foreach ($chunks as $chunk) { |
|
91 | + $chars = str_split($chunk, 1); |
|
92 | 92 | $bits = ''; |
93 | - foreach ( $chars as $char ) { |
|
94 | - $bits .= ( ! is_numeric( $char ) && strtoupper( $char ) === $char ) ? '1' : '0'; |
|
93 | + foreach ($chars as $char) { |
|
94 | + $bits .= ( ! is_numeric($char) && strtoupper($char) === $char) ? '1' : '0'; |
|
95 | 95 | } |
96 | 96 | $map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345'; |
97 | - $extra .= substr( $map, base_convert( strrev( $bits ), 2, 10 ), 1 ); |
|
97 | + $extra .= substr($map, base_convert(strrev($bits), 2, 10), 1); |
|
98 | 98 | } |
99 | 99 | return $sf_id_15 . $extra; |
100 | 100 | } |
@@ -111,15 +111,15 @@ discard block |
||
111 | 111 | * if no match could be found. |
112 | 112 | * @throws Object_Sync_Sf_Exception |
113 | 113 | */ |
114 | - public function get_sobject_type( $sf_id ) { |
|
114 | + public function get_sobject_type($sf_id) { |
|
115 | 115 | $objects = $this->objects( |
116 | 116 | array( |
117 | - 'keyPrefix' => substr( $sf_id, 0, 3 ), |
|
117 | + 'keyPrefix' => substr($sf_id, 0, 3), |
|
118 | 118 | ) |
119 | 119 | ); |
120 | - if ( 1 === count( $objects ) ) { |
|
120 | + if (1 === count($objects)) { |
|
121 | 121 | // keyPrefix is unique across objects. If there is exactly one return value from objects(), then we have a match. |
122 | - $object = reset( $objects ); |
|
122 | + $object = reset($objects); |
|
123 | 123 | return $object['name']; |
124 | 124 | } |
125 | 125 | // Otherwise, we did not find a match. |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * |
132 | 132 | */ |
133 | 133 | public function is_authorized() { |
134 | - return ! empty( $this->consumer_key ) && ! empty( $this->consumer_secret ) && $this->get_refresh_token(); |
|
134 | + return ! empty($this->consumer_key) && ! empty($this->consumer_secret) && $this->get_refresh_token(); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | 'authenticated' => false, |
144 | 144 | 'full_url' => true, |
145 | 145 | ); |
146 | - return $this->api_call( $this->get_instance_url() . '/services/data', [], 'GET', $options ); |
|
146 | + return $this->api_call($this->get_instance_url() . '/services/data', [], 'GET', $options); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -167,50 +167,50 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @throws Object_Sync_Sf_Exception |
169 | 169 | */ |
170 | - public function api_call( $path, $params = array(), $method = 'GET', $options = array(), $type = 'rest' ) { |
|
171 | - if ( ! $this->get_access_token() ) { |
|
170 | + public function api_call($path, $params = array(), $method = 'GET', $options = array(), $type = 'rest') { |
|
171 | + if ( ! $this->get_access_token()) { |
|
172 | 172 | $this->refresh_token(); |
173 | 173 | } |
174 | - $this->response = $this->api_http_request( $path, $params, $method, $options, $type ); |
|
174 | + $this->response = $this->api_http_request($path, $params, $method, $options, $type); |
|
175 | 175 | |
176 | 176 | // analytic calls that are expired return 404s for some absurd reason |
177 | - if ( $this->response['code'] && 'run_analytics_report' === debug_backtrace()[1]['function'] ) { |
|
177 | + if ($this->response['code'] && 'run_analytics_report' === debug_backtrace()[1]['function']) { |
|
178 | 178 | return $this->response; |
179 | 179 | } |
180 | 180 | |
181 | - switch ( $this->response['code'] ) { |
|
181 | + switch ($this->response['code']) { |
|
182 | 182 | // The session ID or OAuth token used has expired or is invalid. |
183 | 183 | case $this->response['code'] === $this->refresh_code: |
184 | 184 | // Refresh token. |
185 | 185 | $this->refresh_token(); |
186 | 186 | // Rebuild our request and repeat request. |
187 | 187 | $options['is_redo'] = true; |
188 | - $this->response = $this->api_http_request( $path, $params, $method, $options, $type ); |
|
188 | + $this->response = $this->api_http_request($path, $params, $method, $options, $type); |
|
189 | 189 | // Throw an error if we still have bad response. |
190 | - if ( ! in_array( $this->response['code'], $this->success_codes, true ) ) { |
|
191 | - throw new Object_Sync_Sf_Exception( $this->response['data'][0]['message'], $this->response['code'] ); |
|
190 | + if ( ! in_array($this->response['code'], $this->success_codes, true)) { |
|
191 | + throw new Object_Sync_Sf_Exception($this->response['data'][0]['message'], $this->response['code']); |
|
192 | 192 | } |
193 | 193 | break; |
194 | - case in_array( $this->response['code'], $this->success_codes, true ): |
|
194 | + case in_array($this->response['code'], $this->success_codes, true): |
|
195 | 195 | // All clear. |
196 | 196 | break; |
197 | 197 | default: |
198 | 198 | // We have problem and no specific Salesforce error provided. |
199 | - if ( empty( $this->response['data'] ) ) { |
|
200 | - throw new Object_Sync_Sf_Exception( $this->response['error'], $this->response['code'] ); |
|
199 | + if (empty($this->response['data'])) { |
|
200 | + throw new Object_Sync_Sf_Exception($this->response['error'], $this->response['code']); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( ! empty( $this->response['data'][0] ) && 1 === count( $this->response['data'] ) ) { |
|
204 | + if ( ! empty($this->response['data'][0]) && 1 === count($this->response['data'])) { |
|
205 | 205 | $this->response['data'] = $this->response['data'][0]; |
206 | 206 | } |
207 | 207 | |
208 | - if ( isset( $this->response['data']['error'] ) ) { |
|
209 | - throw new Object_Sync_Sf_Exception( $this->response['data']['error_description'], $this->response['data']['error'] ); |
|
208 | + if (isset($this->response['data']['error'])) { |
|
209 | + throw new Object_Sync_Sf_Exception($this->response['data']['error_description'], $this->response['data']['error']); |
|
210 | 210 | } |
211 | 211 | |
212 | - if ( ! empty( $this->response['data']['errorCode'] ) ) { |
|
213 | - throw new Object_Sync_Sf_Exception( $this->response['data']['message'], $this->response['code'] ); |
|
212 | + if ( ! empty($this->response['data']['errorCode'])) { |
|
213 | + throw new Object_Sync_Sf_Exception($this->response['data']['message'], $this->response['code']); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return $this->response; |
@@ -236,73 +236,73 @@ discard block |
||
236 | 236 | * @return array |
237 | 237 | * The requested data. |
238 | 238 | */ |
239 | - protected function api_http_request( $path, $params, $method, $options = array(), $type = 'rest' ) { |
|
240 | - $options = array_merge( $this->options, $options ); // this will override a value in $this->options with the one in $options if there is a matching key |
|
241 | - $url = $this->get_api_endpoint( $type ) . $path; |
|
242 | - if ( isset( $options['full_url'] ) && true === $options['full_url'] ) { |
|
239 | + protected function api_http_request($path, $params, $method, $options = array(), $type = 'rest') { |
|
240 | + $options = array_merge($this->options, $options); // this will override a value in $this->options with the one in $options if there is a matching key |
|
241 | + $url = $this->get_api_endpoint($type) . $path; |
|
242 | + if (isset($options['full_url']) && true === $options['full_url']) { |
|
243 | 243 | $url = $path; |
244 | 244 | } |
245 | 245 | $headers = array( |
246 | 246 | 'Authorization' => 'Authorization: OAuth ' . $this->get_access_token(), |
247 | 247 | 'Accept-Encoding' => 'Accept-Encoding: gzip, deflate', |
248 | 248 | ); |
249 | - if ( 'POST' === $method || 'PATCH' === $method ) { |
|
249 | + if ('POST' === $method || 'PATCH' === $method) { |
|
250 | 250 | $headers['Content-Type'] = 'Content-Type: application/json'; |
251 | 251 | } |
252 | - if ( isset( $options['authenticated'] ) && true === $options['authenticated'] ) { |
|
252 | + if (isset($options['authenticated']) && true === $options['authenticated']) { |
|
253 | 253 | $headers = false; |
254 | 254 | } |
255 | 255 | // if this request should be cached, see if it already exists |
256 | 256 | // if it is already cached, load it. if not, load it and then cache it if it should be cached |
257 | 257 | // add parameters to the array so we can tell if it was cached or not |
258 | - if ( true === $options['cache'] && 'write' !== $options['type'] ) { |
|
259 | - $cached = $this->wordpress->cache_get( $url, $params ); |
|
258 | + if (true === $options['cache'] && 'write' !== $options['type']) { |
|
259 | + $cached = $this->wordpress->cache_get($url, $params); |
|
260 | 260 | // some api calls can send a reset option, in which case we should redo the request anyway |
261 | - if ( is_array( $cached ) && ( ! isset( $options['reset'] ) || true !== $options['reset'] ) ) { |
|
261 | + if (is_array($cached) && ( ! isset($options['reset']) || true !== $options['reset'])) { |
|
262 | 262 | $result = $cached; |
263 | 263 | $result['from_cache'] = true; |
264 | 264 | $result['cached'] = true; |
265 | 265 | } else { |
266 | - $data = wp_json_encode( $params ); |
|
267 | - $result = $this->http_request( $url, $data, $headers, $method, $options ); |
|
268 | - if ( in_array( $result['code'], $this->success_codes, true ) ) { |
|
269 | - $result['cached'] = $this->wordpress->cache_set( $url, $params, $result, $options['cache_expiration'] ); |
|
266 | + $data = wp_json_encode($params); |
|
267 | + $result = $this->http_request($url, $data, $headers, $method, $options); |
|
268 | + if (in_array($result['code'], $this->success_codes, true)) { |
|
269 | + $result['cached'] = $this->wordpress->cache_set($url, $params, $result, $options['cache_expiration']); |
|
270 | 270 | } else { |
271 | 271 | $result['cached'] = false; |
272 | 272 | } |
273 | 273 | $result['from_cache'] = false; |
274 | 274 | } |
275 | 275 | } else { |
276 | - $data = wp_json_encode( $params ); |
|
277 | - $result = $this->http_request( $url, $data, $headers, $method, $options ); |
|
276 | + $data = wp_json_encode($params); |
|
277 | + $result = $this->http_request($url, $data, $headers, $method, $options); |
|
278 | 278 | $result['from_cache'] = false; |
279 | 279 | $result['cached'] = false; |
280 | 280 | } |
281 | 281 | |
282 | - if ( isset( $options['is_redo'] ) && true === $options['is_redo'] ) { |
|
282 | + if (isset($options['is_redo']) && true === $options['is_redo']) { |
|
283 | 283 | $result['is_redo'] = true; |
284 | 284 | } else { |
285 | 285 | $result['is_redo'] = false; |
286 | 286 | } |
287 | 287 | |
288 | 288 | // it would be very unfortunate to ever have to do this in a production site |
289 | - if ( 1 === (int) $this->debug ) { |
|
289 | + if (1 === (int) $this->debug) { |
|
290 | 290 | // create log entry for the api call if debug is true |
291 | 291 | $status = 'debug'; |
292 | - if ( isset( $this->logging ) ) { |
|
292 | + if (isset($this->logging)) { |
|
293 | 293 | $logging = $this->logging; |
294 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
295 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
294 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
295 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | // translators: placeholder is the URL of the Salesforce API request |
299 | - $title = sprintf( esc_html__( 'Debug: on Salesforce API HTTP Request to URL: %1$s.', 'object-sync-for-salesforce' ), |
|
300 | - esc_url( $url ) |
|
299 | + $title = sprintf(esc_html__('Debug: on Salesforce API HTTP Request to URL: %1$s.', 'object-sync-for-salesforce'), |
|
300 | + esc_url($url) |
|
301 | 301 | ); |
302 | 302 | |
303 | 303 | $logging->setup( |
304 | 304 | $title, |
305 | - print_r( $result, true ), // log the result because we are debugging the whole api call |
|
305 | + print_r($result, true), // log the result because we are debugging the whole api call |
|
306 | 306 | 0, |
307 | 307 | 0, |
308 | 308 | $status |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @return array |
330 | 330 | * Salesforce response object. |
331 | 331 | */ |
332 | - protected function http_request( $url, $data, $headers = array(), $method = 'GET', $options = array() ) { |
|
332 | + protected function http_request($url, $data, $headers = array(), $method = 'GET', $options = array()) { |
|
333 | 333 | // Build the request, including path and headers. Internal use. |
334 | 334 | |
335 | 335 | /* |
@@ -338,60 +338,60 @@ discard block |
||
338 | 338 | */ |
339 | 339 | |
340 | 340 | $curl = curl_init(); |
341 | - curl_setopt( $curl, CURLOPT_URL, $url ); |
|
342 | - curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); |
|
343 | - curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true ); |
|
344 | - if ( false !== $headers ) { |
|
345 | - curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers ); |
|
341 | + curl_setopt($curl, CURLOPT_URL, $url); |
|
342 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
343 | + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
344 | + if (false !== $headers) { |
|
345 | + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); |
|
346 | 346 | } else { |
347 | - curl_setopt( $curl, CURLOPT_HEADER, false ); |
|
347 | + curl_setopt($curl, CURLOPT_HEADER, false); |
|
348 | 348 | } |
349 | 349 | |
350 | - if ( 'POST' === $method ) { |
|
351 | - curl_setopt( $curl, CURLOPT_POST, true ); |
|
352 | - curl_setopt( $curl, CURLOPT_POSTFIELDS, $data ); |
|
353 | - } elseif ( 'PATCH' === $method || 'DELETE' === $method ) { |
|
354 | - curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, $method ); |
|
355 | - curl_setopt( $curl, CURLOPT_POSTFIELDS, $data ); |
|
350 | + if ('POST' === $method) { |
|
351 | + curl_setopt($curl, CURLOPT_POST, true); |
|
352 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|
353 | + } elseif ('PATCH' === $method || 'DELETE' === $method) { |
|
354 | + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); |
|
355 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|
356 | 356 | } |
357 | - $json_response = curl_exec( $curl ); // this is possibly gzipped json data |
|
358 | - $code = curl_getinfo( $curl, CURLINFO_HTTP_CODE ); |
|
357 | + $json_response = curl_exec($curl); // this is possibly gzipped json data |
|
358 | + $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
359 | 359 | |
360 | - if ( ( 'PATCH' === $method || 'DELETE' === $method ) && '' === $json_response && 204 === $code ) { |
|
360 | + if (('PATCH' === $method || 'DELETE' === $method) && '' === $json_response && 204 === $code) { |
|
361 | 361 | // delete and patch requests return a 204 with an empty body upon success for whatever reason |
362 | 362 | $data = array( |
363 | 363 | 'success' => true, |
364 | 364 | 'body' => '', |
365 | 365 | ); |
366 | - curl_close( $curl ); |
|
366 | + curl_close($curl); |
|
367 | 367 | return array( |
368 | - 'json' => wp_json_encode( $data ), |
|
368 | + 'json' => wp_json_encode($data), |
|
369 | 369 | 'code' => $code, |
370 | 370 | 'data' => $data, |
371 | 371 | ); |
372 | 372 | } |
373 | 373 | |
374 | - if ( ( ord( $json_response[0] ) == 0x1f ) && ( ord( $json_response[1] ) == 0x8b ) ) { |
|
374 | + if ((ord($json_response[0]) == 0x1f) && (ord($json_response[1]) == 0x8b)) { |
|
375 | 375 | // skip header and ungzip the data |
376 | - $json_response = gzinflate( substr( $json_response, 10 ) ); |
|
376 | + $json_response = gzinflate(substr($json_response, 10)); |
|
377 | 377 | } |
378 | - $data = json_decode( $json_response, true ); // decode it into an array |
|
378 | + $data = json_decode($json_response, true); // decode it into an array |
|
379 | 379 | |
380 | 380 | // don't use the exception if the status is a success one, or if it just needs a refresh token (salesforce uses 401 for this) |
381 | - if ( ! in_array( $code, $this->success_or_refresh_codes, true ) ) { |
|
382 | - $curl_error = curl_error( $curl ); |
|
383 | - if ( '' !== $curl_error ) { |
|
381 | + if ( ! in_array($code, $this->success_or_refresh_codes, true)) { |
|
382 | + $curl_error = curl_error($curl); |
|
383 | + if ('' !== $curl_error) { |
|
384 | 384 | // create log entry for failed curl |
385 | 385 | $status = 'error'; |
386 | - if ( isset( $this->logging ) ) { |
|
386 | + if (isset($this->logging)) { |
|
387 | 387 | $logging = $this->logging; |
388 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
389 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
388 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
389 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | // translators: placeholder is the URL of the Salesforce API request |
393 | - $title = sprintf( esc_html__( 'Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce' ), |
|
394 | - esc_attr( $code ) |
|
393 | + $title = sprintf(esc_html__('Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce'), |
|
394 | + esc_attr($code) |
|
395 | 395 | ); |
396 | 396 | |
397 | 397 | $logging->setup( |
@@ -401,25 +401,25 @@ discard block |
||
401 | 401 | 0, |
402 | 402 | $status |
403 | 403 | ); |
404 | - } elseif ( isset( $data[0]['errorCode'] ) && '' !== $data[0]['errorCode'] ) { // salesforce uses this structure to return errors |
|
404 | + } elseif (isset($data[0]['errorCode']) && '' !== $data[0]['errorCode']) { // salesforce uses this structure to return errors |
|
405 | 405 | // create log entry for failed curl |
406 | 406 | $status = 'error'; |
407 | - if ( isset( $this->logging ) ) { |
|
407 | + if (isset($this->logging)) { |
|
408 | 408 | $logging = $this->logging; |
409 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
410 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
409 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
410 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | // translators: placeholder is the server code returned by the api |
414 | - $title = sprintf( esc_html__( 'Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce' ), |
|
415 | - absint( $code ) |
|
414 | + $title = sprintf(esc_html__('Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce'), |
|
415 | + absint($code) |
|
416 | 416 | ); |
417 | 417 | |
418 | 418 | // translators: placeholders are: 1) the URL requested, 2) the message returned by the error, 3) the server code returned |
419 | - $body = sprintf( '<p>' . esc_html__( 'URL: %1$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Message: %2$s', 'object-sync-for-salesforce' ) . '</p><p>' . esc_html__( 'Code: %3$s', 'object-sync-for-salesforce' ), |
|
420 | - esc_attr( $url ), |
|
421 | - esc_html( $data[0]['message'] ), |
|
422 | - absint( $code ) |
|
419 | + $body = sprintf('<p>' . esc_html__('URL: %1$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Message: %2$s', 'object-sync-for-salesforce') . '</p><p>' . esc_html__('Code: %3$s', 'object-sync-for-salesforce'), |
|
420 | + esc_attr($url), |
|
421 | + esc_html($data[0]['message']), |
|
422 | + absint($code) |
|
423 | 423 | ); |
424 | 424 | |
425 | 425 | $logging->setup( |
@@ -432,20 +432,20 @@ discard block |
||
432 | 432 | } else { |
433 | 433 | // create log entry for failed curl |
434 | 434 | $status = 'error'; |
435 | - if ( isset( $this->logging ) ) { |
|
435 | + if (isset($this->logging)) { |
|
436 | 436 | $logging = $this->logging; |
437 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
438 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
437 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
438 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | // translators: placeholder is the server code returned by Salesforce |
442 | - $title = sprintf( esc_html__( 'Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce' ), |
|
443 | - absint( $code ) |
|
442 | + $title = sprintf(esc_html__('Error: %1$s: on Salesforce http request', 'object-sync-for-salesforce'), |
|
443 | + absint($code) |
|
444 | 444 | ); |
445 | 445 | |
446 | 446 | $logging->setup( |
447 | 447 | $title, |
448 | - print_r( $data, true ), // log the result because we are debugging the whole api call |
|
448 | + print_r($data, true), // log the result because we are debugging the whole api call |
|
449 | 449 | 0, |
450 | 450 | 0, |
451 | 451 | $status |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | } // End if(). |
454 | 454 | } // End if(). |
455 | 455 | |
456 | - curl_close( $curl ); |
|
456 | + curl_close($curl); |
|
457 | 457 | |
458 | 458 | return array( |
459 | 459 | 'json' => $json_response, |
@@ -471,14 +471,14 @@ discard block |
||
471 | 471 | * @return string |
472 | 472 | * Complete URL endpoint for API access. |
473 | 473 | */ |
474 | - public function get_api_endpoint( $api_type = 'rest' ) { |
|
474 | + public function get_api_endpoint($api_type = 'rest') { |
|
475 | 475 | // Special handling for apexrest, since it's not in the identity object. |
476 | - if ( 'apexrest' === $api_type ) { |
|
476 | + if ('apexrest' === $api_type) { |
|
477 | 477 | $url = $this->get_instance_url() . '/services/apexrest/'; |
478 | 478 | } else { |
479 | 479 | $identity = $this->get_identity(); |
480 | - $url = str_replace( '{version}', $this->rest_api_version, $identity['urls'][ $api_type ] ); |
|
481 | - if ( '' === $identity ) { |
|
480 | + $url = str_replace('{version}', $this->rest_api_version, $identity['urls'][$api_type]); |
|
481 | + if ('' === $identity) { |
|
482 | 482 | $url = $this->get_instance_url() . '/services/data/v' . $this->rest_api_version . '/'; |
483 | 483 | } |
484 | 484 | } |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | * Get the SF instance URL. Useful for linking to objects. |
490 | 490 | */ |
491 | 491 | public function get_instance_url() { |
492 | - return get_option( $this->option_prefix . 'instance_url', '' ); |
|
492 | + return get_option($this->option_prefix . 'instance_url', ''); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -498,15 +498,15 @@ discard block |
||
498 | 498 | * @param string $url |
499 | 499 | * URL to set. |
500 | 500 | */ |
501 | - protected function set_instance_url( $url ) { |
|
502 | - update_option( $this->option_prefix . 'instance_url', $url ); |
|
501 | + protected function set_instance_url($url) { |
|
502 | + update_option($this->option_prefix . 'instance_url', $url); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
506 | 506 | * Get the access token. |
507 | 507 | */ |
508 | 508 | public function get_access_token() { |
509 | - return get_option( $this->option_prefix . 'access_token', '' ); |
|
509 | + return get_option($this->option_prefix . 'access_token', ''); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -517,15 +517,15 @@ discard block |
||
517 | 517 | * @param string $token |
518 | 518 | * Access token from Salesforce. |
519 | 519 | */ |
520 | - protected function set_access_token( $token ) { |
|
521 | - update_option( $this->option_prefix . 'access_token', $token ); |
|
520 | + protected function set_access_token($token) { |
|
521 | + update_option($this->option_prefix . 'access_token', $token); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
525 | 525 | * Get refresh token. |
526 | 526 | */ |
527 | 527 | protected function get_refresh_token() { |
528 | - return get_option( $this->option_prefix . 'refresh_token', '' ); |
|
528 | + return get_option($this->option_prefix . 'refresh_token', ''); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -534,8 +534,8 @@ discard block |
||
534 | 534 | * @param string $token |
535 | 535 | * Refresh token from Salesforce. |
536 | 536 | */ |
537 | - protected function set_refresh_token( $token ) { |
|
538 | - update_option( $this->option_prefix . 'refresh_token', $token ); |
|
537 | + protected function set_refresh_token($token) { |
|
538 | + update_option($this->option_prefix . 'refresh_token', $token); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | */ |
550 | 550 | protected function refresh_token() { |
551 | 551 | $refresh_token = $this->get_refresh_token(); |
552 | - if ( empty( $refresh_token ) ) { |
|
553 | - throw new Object_Sync_Sf_Exception( esc_html__( 'There is no refresh token.', 'object-sync-for-salesforce' ) ); |
|
552 | + if (empty($refresh_token)) { |
|
553 | + throw new Object_Sync_Sf_Exception(esc_html__('There is no refresh token.', 'object-sync-for-salesforce')); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | $data = array( |
@@ -568,13 +568,13 @@ discard block |
||
568 | 568 | 'Authorization' => 'Authorization: OAuth ' . $this->get_access_token(), |
569 | 569 | ); |
570 | 570 | $headers = false; |
571 | - $response = $this->http_request( $url, $data, $headers, 'POST' ); |
|
571 | + $response = $this->http_request($url, $data, $headers, 'POST'); |
|
572 | 572 | |
573 | - if ( 200 !== $response['code'] ) { |
|
573 | + if (200 !== $response['code']) { |
|
574 | 574 | throw new Object_Sync_Sf_Exception( |
575 | 575 | esc_html( |
576 | 576 | sprintf( |
577 | - __( 'Unable to get a Salesforce access token. Salesforce returned the following errorCode: ', 'object-sync-for-salesforce' ) . $response['code'] |
|
577 | + __('Unable to get a Salesforce access token. Salesforce returned the following errorCode: ', 'object-sync-for-salesforce') . $response['code'] |
|
578 | 578 | ) |
579 | 579 | ), |
580 | 580 | $response['code'] |
@@ -583,13 +583,13 @@ discard block |
||
583 | 583 | |
584 | 584 | $data = $response['data']; |
585 | 585 | |
586 | - if ( is_array( $data ) && isset( $data['error'] ) ) { |
|
587 | - throw new Object_Sync_Sf_Exception( $data['error_description'], $data['error'] ); |
|
586 | + if (is_array($data) && isset($data['error'])) { |
|
587 | + throw new Object_Sync_Sf_Exception($data['error_description'], $data['error']); |
|
588 | 588 | } |
589 | 589 | |
590 | - $this->set_access_token( $data['access_token'] ); |
|
591 | - $this->set_identity( $data['id'] ); |
|
592 | - $this->set_instance_url( $data['instance_url'] ); |
|
590 | + $this->set_access_token($data['access_token']); |
|
591 | + $this->set_identity($data['id']); |
|
592 | + $this->set_instance_url($data['instance_url']); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | /** |
@@ -600,18 +600,18 @@ discard block |
||
600 | 600 | * |
601 | 601 | * @throws Object_Sync_Sf_Exception |
602 | 602 | */ |
603 | - protected function set_identity( $id ) { |
|
604 | - $headers = array( |
|
603 | + protected function set_identity($id) { |
|
604 | + $headers = array( |
|
605 | 605 | 'Authorization' => 'Authorization: OAuth ' . $this->get_access_token(), |
606 | 606 | //'Content-type' => 'application/json', |
607 | 607 | 'Accept-Encoding' => 'Accept-Encoding: gzip, deflate', |
608 | 608 | ); |
609 | - $response = $this->http_request( $id, null, $headers ); |
|
610 | - if ( 200 !== $response['code'] ) { |
|
611 | - throw new Object_Sync_Sf_Exception( esc_html__( 'Unable to access identity service.', 'object-sync-for-salesforce' ), $response['code'] ); |
|
609 | + $response = $this->http_request($id, null, $headers); |
|
610 | + if (200 !== $response['code']) { |
|
611 | + throw new Object_Sync_Sf_Exception(esc_html__('Unable to access identity service.', 'object-sync-for-salesforce'), $response['code']); |
|
612 | 612 | } |
613 | 613 | $data = $response['data']; |
614 | - update_option( $this->option_prefix . 'identity', $data ); |
|
614 | + update_option($this->option_prefix . 'identity', $data); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | * Returns FALSE if no identity has been stored. |
622 | 622 | */ |
623 | 623 | public function get_identity() { |
624 | - return get_option( $this->option_prefix . 'identity', false ); |
|
624 | + return get_option($this->option_prefix . 'identity', false); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | /** |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | * @param string $code |
646 | 646 | * Code from Salesforce. |
647 | 647 | */ |
648 | - public function request_token( $code ) { |
|
648 | + public function request_token($code) { |
|
649 | 649 | $data = array( |
650 | 650 | 'code' => $code, |
651 | 651 | 'grant_type' => 'authorization_code', |
@@ -660,28 +660,28 @@ discard block |
||
660 | 660 | //'Content-Type' => 'application/x-www-form-urlencoded', |
661 | 661 | 'Accept-Encoding' => 'Accept-Encoding: gzip, deflate', |
662 | 662 | ); |
663 | - $response = $this->http_request( $url, $data, $headers, 'POST' ); |
|
663 | + $response = $this->http_request($url, $data, $headers, 'POST'); |
|
664 | 664 | |
665 | 665 | $data = $response['data']; |
666 | 666 | |
667 | - if ( 200 !== $response['code'] ) { |
|
668 | - $error = isset( $data['error_description'] ) ? $data['error_description'] : $response['error']; |
|
669 | - throw new Object_Sync_Sf_Exception( $error, $response['code'] ); |
|
667 | + if (200 !== $response['code']) { |
|
668 | + $error = isset($data['error_description']) ? $data['error_description'] : $response['error']; |
|
669 | + throw new Object_Sync_Sf_Exception($error, $response['code']); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Ensure all required attributes are returned. They can be omitted if the |
673 | 673 | // OAUTH scope is inadequate. |
674 | - $required = array( 'refresh_token', 'access_token', 'id', 'instance_url' ); |
|
675 | - foreach ( $required as $key ) { |
|
676 | - if ( ! isset( $data[ $key ] ) ) { |
|
674 | + $required = array('refresh_token', 'access_token', 'id', 'instance_url'); |
|
675 | + foreach ($required as $key) { |
|
676 | + if ( ! isset($data[$key])) { |
|
677 | 677 | return false; |
678 | 678 | } |
679 | 679 | } |
680 | 680 | |
681 | - $this->set_refresh_token( $data['refresh_token'] ); |
|
682 | - $this->set_access_token( $data['access_token'] ); |
|
683 | - $this->set_identity( $data['id'] ); |
|
684 | - $this->set_instance_url( $data['instance_url'] ); |
|
681 | + $this->set_refresh_token($data['refresh_token']); |
|
682 | + $this->set_access_token($data['access_token']); |
|
683 | + $this->set_identity($data['id']); |
|
684 | + $this->set_instance_url($data['instance_url']); |
|
685 | 685 | |
686 | 686 | return true; |
687 | 687 | } |
@@ -716,19 +716,19 @@ discard block |
||
716 | 716 | $options = array( |
717 | 717 | 'reset' => $reset, |
718 | 718 | ); |
719 | - $result = $this->api_call( 'sobjects', array(), 'GET', $options ); |
|
719 | + $result = $this->api_call('sobjects', array(), 'GET', $options); |
|
720 | 720 | |
721 | - if ( ! empty( $conditions ) ) { |
|
722 | - foreach ( $result['data']['sobjects'] as $key => $object ) { |
|
723 | - foreach ( $conditions as $condition => $value ) { |
|
724 | - if ( $object[ $condition ] !== $value ) { |
|
725 | - unset( $result['data']['sobjects'][ $key ] ); |
|
721 | + if ( ! empty($conditions)) { |
|
722 | + foreach ($result['data']['sobjects'] as $key => $object) { |
|
723 | + foreach ($conditions as $condition => $value) { |
|
724 | + if ($object[$condition] !== $value) { |
|
725 | + unset($result['data']['sobjects'][$key]); |
|
726 | 726 | } |
727 | 727 | } |
728 | 728 | } |
729 | 729 | } |
730 | 730 | |
731 | - ksort( $result['data']['sobjects'] ); |
|
731 | + ksort($result['data']['sobjects']); |
|
732 | 732 | |
733 | 733 | return $result['data']['sobjects']; |
734 | 734 | } |
@@ -750,21 +750,21 @@ discard block |
||
750 | 750 | * |
751 | 751 | * part of core API calls |
752 | 752 | */ |
753 | - public function query( $query, $options = array(), $all = false, $explain = false ) { |
|
753 | + public function query($query, $options = array(), $all = false, $explain = false) { |
|
754 | 754 | $search_data = [ |
755 | 755 | 'q' => (string) $query, |
756 | 756 | ]; |
757 | - if ( true === $explain ) { |
|
757 | + if (true === $explain) { |
|
758 | 758 | $search_data['explain'] = $search_data['q']; |
759 | - unset( $search_data['q'] ); |
|
759 | + unset($search_data['q']); |
|
760 | 760 | } |
761 | 761 | // all is a search through deleted and merged data as well |
762 | - if ( true === $all ) { |
|
762 | + if (true === $all) { |
|
763 | 763 | $path = 'queryAll'; |
764 | 764 | } else { |
765 | 765 | $path = 'query'; |
766 | 766 | } |
767 | - $result = $this->api_call( $path . '?' . http_build_query( $search_data ), array(), 'GET', $options ); |
|
767 | + $result = $this->api_call($path . '?' . http_build_query($search_data), array(), 'GET', $options); |
|
768 | 768 | return $result; |
769 | 769 | } |
770 | 770 | |
@@ -782,28 +782,28 @@ discard block |
||
782 | 782 | * |
783 | 783 | * part of core API calls |
784 | 784 | */ |
785 | - public function object_describe( $name, $reset = false ) { |
|
786 | - if ( empty( $name ) ) { |
|
785 | + public function object_describe($name, $reset = false) { |
|
786 | + if (empty($name)) { |
|
787 | 787 | return array(); |
788 | 788 | } |
789 | 789 | $options = array( |
790 | 790 | 'reset' => $reset, |
791 | 791 | ); |
792 | - $object = $this->api_call( "sobjects/{$name}/describe", array(), 'GET', $options ); |
|
792 | + $object = $this->api_call("sobjects/{$name}/describe", array(), 'GET', $options); |
|
793 | 793 | // Sort field properties, because salesforce API always provides them in a |
794 | 794 | // random order. We sort them so that stored and exported data are |
795 | 795 | // standardized and predictable. |
796 | 796 | $fields = array(); |
797 | - foreach ( $object['data']['fields'] as &$field ) { |
|
798 | - ksort( $field ); |
|
799 | - if ( ! empty( $field['picklistValues'] ) ) { |
|
800 | - foreach ( $field['picklistValues'] as &$picklist_value ) { |
|
801 | - ksort( $picklist_value ); |
|
797 | + foreach ($object['data']['fields'] as &$field) { |
|
798 | + ksort($field); |
|
799 | + if ( ! empty($field['picklistValues'])) { |
|
800 | + foreach ($field['picklistValues'] as &$picklist_value) { |
|
801 | + ksort($picklist_value); |
|
802 | 802 | } |
803 | 803 | } |
804 | - $fields[ $field['name'] ] = $field; |
|
804 | + $fields[$field['name']] = $field; |
|
805 | 805 | } |
806 | - ksort( $fields ); |
|
806 | + ksort($fields); |
|
807 | 807 | $object['fields'] = $fields; |
808 | 808 | return $object; |
809 | 809 | } |
@@ -829,11 +829,11 @@ discard block |
||
829 | 829 | * |
830 | 830 | * part of core API calls |
831 | 831 | */ |
832 | - public function object_create( $name, $params ) { |
|
832 | + public function object_create($name, $params) { |
|
833 | 833 | $options = array( |
834 | 834 | 'type' => 'write', |
835 | 835 | ); |
836 | - $result = $this->api_call( "sobjects/{$name}", $params, 'POST', $options ); |
|
836 | + $result = $this->api_call("sobjects/{$name}", $params, 'POST', $options); |
|
837 | 837 | return $result; |
838 | 838 | } |
839 | 839 | |
@@ -866,22 +866,22 @@ discard block |
||
866 | 866 | * |
867 | 867 | * part of core API calls |
868 | 868 | */ |
869 | - public function object_upsert( $name, $key, $value, $params ) { |
|
869 | + public function object_upsert($name, $key, $value, $params) { |
|
870 | 870 | $options = array( |
871 | 871 | 'type' => 'write', |
872 | 872 | ); |
873 | 873 | // If key is set, remove from $params to avoid UPSERT errors. |
874 | - if ( isset( $params[ $key ] ) ) { |
|
875 | - unset( $params[ $key ] ); |
|
874 | + if (isset($params[$key])) { |
|
875 | + unset($params[$key]); |
|
876 | 876 | } |
877 | 877 | |
878 | 878 | // allow developers to change both the key and value by which objects should be matched |
879 | - $key = apply_filters( $this->option_prefix . 'modify_upsert_key', $key ); |
|
880 | - $value = apply_filters( $this->option_prefix . 'modify_upsert_value', $value ); |
|
879 | + $key = apply_filters($this->option_prefix . 'modify_upsert_key', $key); |
|
880 | + $value = apply_filters($this->option_prefix . 'modify_upsert_value', $value); |
|
881 | 881 | |
882 | - $data = $this->api_call( "sobjects/{$name}/{$key}/{$value}", $params, 'PATCH', $options ); |
|
883 | - if ( 300 === $this->response['code'] ) { |
|
884 | - $data['message'] = esc_html( 'The value provided is not unique.' ); |
|
882 | + $data = $this->api_call("sobjects/{$name}/{$key}/{$value}", $params, 'PATCH', $options); |
|
883 | + if (300 === $this->response['code']) { |
|
884 | + $data['message'] = esc_html('The value provided is not unique.'); |
|
885 | 885 | } |
886 | 886 | return $data; |
887 | 887 | } |
@@ -908,11 +908,11 @@ discard block |
||
908 | 908 | * cached: |
909 | 909 | * is_redo: |
910 | 910 | */ |
911 | - public function object_update( $name, $id, $params ) { |
|
911 | + public function object_update($name, $id, $params) { |
|
912 | 912 | $options = array( |
913 | 913 | 'type' => 'write', |
914 | 914 | ); |
915 | - $result = $this->api_call( "sobjects/{$name}/{$id}", $params, 'PATCH', $options ); |
|
915 | + $result = $this->api_call("sobjects/{$name}/{$id}", $params, 'PATCH', $options); |
|
916 | 916 | return $result; |
917 | 917 | } |
918 | 918 | |
@@ -929,8 +929,8 @@ discard block |
||
929 | 929 | * |
930 | 930 | * part of core API calls |
931 | 931 | */ |
932 | - public function object_read( $name, $id ) { |
|
933 | - return $this->api_call( "sobjects/{$name}/{$id}", array(), 'GET' ); |
|
932 | + public function object_read($name, $id) { |
|
933 | + return $this->api_call("sobjects/{$name}/{$id}", array(), 'GET'); |
|
934 | 934 | } |
935 | 935 | |
936 | 936 | /** |
@@ -952,8 +952,8 @@ discard block |
||
952 | 952 | * |
953 | 953 | * part of core API calls |
954 | 954 | */ |
955 | - public function analytics_api( $name, $id, $route = '', $params = array(), $method = 'GET' ) { |
|
956 | - return $this->api_call( "analytics/{$name}/{$id}/{$route}", $params, $method ); |
|
955 | + public function analytics_api($name, $id, $route = '', $params = array(), $method = 'GET') { |
|
956 | + return $this->api_call("analytics/{$name}/{$id}/{$route}", $params, $method); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | /** |
@@ -973,19 +973,19 @@ discard block |
||
973 | 973 | * |
974 | 974 | * part of core API calls |
975 | 975 | */ |
976 | - public function run_analytics_report( $id, $async = true, $clear_cache = false, $params = array(), $method = 'GET', $report_cache_expiration = '', $cache_instance = true, $instance_cache_expiration = '' ) { |
|
976 | + public function run_analytics_report($id, $async = true, $clear_cache = false, $params = array(), $method = 'GET', $report_cache_expiration = '', $cache_instance = true, $instance_cache_expiration = '') { |
|
977 | 977 | |
978 | - $id = $this->convert_id( $id ); |
|
978 | + $id = $this->convert_id($id); |
|
979 | 979 | $report_url = 'analytics/reports/' . $id . '/' . 'instances'; |
980 | 980 | |
981 | - if ( true === $clear_cache ) { |
|
982 | - delete_transient( $report_url ); |
|
981 | + if (true === $clear_cache) { |
|
982 | + delete_transient($report_url); |
|
983 | 983 | } |
984 | 984 | |
985 | - $instance_id = $this->wordpress->cache_get( $report_url, '' ); |
|
985 | + $instance_id = $this->wordpress->cache_get($report_url, ''); |
|
986 | 986 | |
987 | 987 | // there is no stored instance id or this is synchronous; retrieve the results for that instance |
988 | - if ( false === $async || false === $instance_id ) { |
|
988 | + if (false === $async || false === $instance_id) { |
|
989 | 989 | |
990 | 990 | $result = $this->analytics_api( |
991 | 991 | 'reports', |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | 'GET' |
996 | 996 | ); |
997 | 997 | // if we get a reportmetadata array out of this, continue |
998 | - if ( is_array( $result['data']['reportMetadata'] ) ) { |
|
998 | + if (is_array($result['data']['reportMetadata'])) { |
|
999 | 999 | $params = array( |
1000 | 1000 | 'reportMetadata' => $result['data']['reportMetadata'], |
1001 | 1001 | ); |
@@ -1007,48 +1007,48 @@ discard block |
||
1007 | 1007 | 'POST' |
1008 | 1008 | ); |
1009 | 1009 | // if we get an id from the post, that is the instance id |
1010 | - if ( isset( $report['data']['id'] ) ) { |
|
1010 | + if (isset($report['data']['id'])) { |
|
1011 | 1011 | $instance_id = $report['data']['id']; |
1012 | 1012 | } else { |
1013 | 1013 | // run the call again if we don't have an instance id |
1014 | 1014 | //error_log('run report again. we have no instance id.'); |
1015 | - $this->run_analytics_report( $id, true ); |
|
1015 | + $this->run_analytics_report($id, true); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | // cache the instance id so we can get the report results if they are applicable |
1019 | - if ( '' === $report_cache_expiration ) { |
|
1019 | + if ('' === $report_cache_expiration) { |
|
1020 | 1020 | $report_cache_expiration = $this->cache_expiration(); |
1021 | 1021 | } |
1022 | - $this->wordpress->cache_set( $report_url, '', $instance_id, $report_cache_expiration ); |
|
1022 | + $this->wordpress->cache_set($report_url, '', $instance_id, $report_cache_expiration); |
|
1023 | 1023 | } else { |
1024 | 1024 | // run the call again if we don't have a reportMetadata array |
1025 | 1025 | //error_log('run report again. we have no reportmetadata.'); |
1026 | - $this->run_analytics_report( $id, true ); |
|
1026 | + $this->run_analytics_report($id, true); |
|
1027 | 1027 | } |
1028 | 1028 | } // End if(). |
1029 | 1029 | |
1030 | - $result = $this->api_call( $report_url . "/{$instance_id}", array(), $method ); |
|
1030 | + $result = $this->api_call($report_url . "/{$instance_id}", array(), $method); |
|
1031 | 1031 | |
1032 | 1032 | // the report instance is expired. rerun it. |
1033 | - if ( 404 === $result['code'] ) { |
|
1033 | + if (404 === $result['code']) { |
|
1034 | 1034 | //error_log('run report again. it expired.'); |
1035 | - $this->run_analytics_report( $id, true, true ); |
|
1035 | + $this->run_analytics_report($id, true, true); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | // cache the instance results as a long fallback if the setting says so |
1039 | 1039 | // do this because salesforce will have errors if the instance has expired or is currently running |
1040 | 1040 | // remember: the result of the above api_call is already cached (or not) according to the plugin's generic settings |
1041 | 1041 | // this is fine I think, although it is a bit of redundancy in this case |
1042 | - if ( true === $cache_instance ) { |
|
1043 | - $cached = $this->wordpress->cache_get( $report_url . '_instance_cached', '' ); |
|
1044 | - if ( is_array( $cached ) ) { |
|
1042 | + if (true === $cache_instance) { |
|
1043 | + $cached = $this->wordpress->cache_get($report_url . '_instance_cached', ''); |
|
1044 | + if (is_array($cached)) { |
|
1045 | 1045 | $result = $cached; |
1046 | 1046 | } else { |
1047 | - if ( 'Success' === $result['data']['attributes']['status'] ) { |
|
1048 | - if ( '' === $instance_cache_expiration ) { |
|
1047 | + if ('Success' === $result['data']['attributes']['status']) { |
|
1048 | + if ('' === $instance_cache_expiration) { |
|
1049 | 1049 | $instance_cache_expiration = $this->cache_expiration(); |
1050 | 1050 | } |
1051 | - $this->wordpress->cache_set( $report_url . '_instance_cached', '', $result, $instance_cache_expiration ); |
|
1051 | + $this->wordpress->cache_set($report_url . '_instance_cached', '', $result, $instance_cache_expiration); |
|
1052 | 1052 | } |
1053 | 1053 | } |
1054 | 1054 | } |
@@ -1072,8 +1072,8 @@ discard block |
||
1072 | 1072 | * |
1073 | 1073 | * part of core API calls |
1074 | 1074 | */ |
1075 | - public function object_readby_external_id( $name, $field, $value ) { |
|
1076 | - return $this->api_call( "sobjects/{$name}/{$field}/{$value}" ); |
|
1075 | + public function object_readby_external_id($name, $field, $value) { |
|
1076 | + return $this->api_call("sobjects/{$name}/{$field}/{$value}"); |
|
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | /** |
@@ -1088,11 +1088,11 @@ discard block |
||
1088 | 1088 | * |
1089 | 1089 | * part of core API calls |
1090 | 1090 | */ |
1091 | - public function object_delete( $name, $id ) { |
|
1091 | + public function object_delete($name, $id) { |
|
1092 | 1092 | $options = array( |
1093 | 1093 | 'type' => 'write', |
1094 | 1094 | ); |
1095 | - $result = $this->api_call( "sobjects/{$name}/{$id}", array(), 'DELETE', $options ); |
|
1095 | + $result = $this->api_call("sobjects/{$name}/{$id}", array(), 'DELETE', $options); |
|
1096 | 1096 | return $result; |
1097 | 1097 | } |
1098 | 1098 | |
@@ -1108,11 +1108,11 @@ discard block |
||
1108 | 1108 | * End date to check for deleted objects (in ISO 8601 format). |
1109 | 1109 | * @return GetDeletedResult |
1110 | 1110 | */ |
1111 | - public function get_deleted( $type, $start_date, $end_date ) { |
|
1111 | + public function get_deleted($type, $start_date, $end_date) { |
|
1112 | 1112 | $options = array( |
1113 | 1113 | 'cache' => false, |
1114 | 1114 | ); // this is timestamp level specific; probably should not cache it |
1115 | - return $this->api_call( "sobjects/{$type}/deleted/?start={$start_date}&end={$end_date}", array(), 'GET', $options ); |
|
1115 | + return $this->api_call("sobjects/{$type}/deleted/?start={$start_date}&end={$end_date}", array(), 'GET', $options); |
|
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | |
@@ -1125,9 +1125,9 @@ discard block |
||
1125 | 1125 | * part of core API calls |
1126 | 1126 | */ |
1127 | 1127 | public function list_resources() { |
1128 | - $resources = $this->api_call( '' ); |
|
1129 | - foreach ( $resources as $key => $path ) { |
|
1130 | - $items[ $key ] = $path; |
|
1128 | + $resources = $this->api_call(''); |
|
1129 | + foreach ($resources as $key => $path) { |
|
1130 | + $items[$key] = $path; |
|
1131 | 1131 | } |
1132 | 1132 | return $items; |
1133 | 1133 | } |
@@ -1158,21 +1158,21 @@ discard block |
||
1158 | 1158 | * |
1159 | 1159 | * part of core API calls |
1160 | 1160 | */ |
1161 | - public function get_updated( $type, $start = null, $end = null ) { |
|
1162 | - if ( empty( $start ) ) { |
|
1163 | - $start = strtotime( '-29 days' ); |
|
1161 | + public function get_updated($type, $start = null, $end = null) { |
|
1162 | + if (empty($start)) { |
|
1163 | + $start = strtotime('-29 days'); |
|
1164 | 1164 | } |
1165 | - $start = rawurlencode( gmdate( DATE_ATOM, $start ) ); |
|
1165 | + $start = rawurlencode(gmdate(DATE_ATOM, $start)); |
|
1166 | 1166 | |
1167 | - if ( empty( $end ) ) { |
|
1167 | + if (empty($end)) { |
|
1168 | 1168 | $end = time(); |
1169 | 1169 | } |
1170 | - $end = rawurlencode( gmdate( DATE_ATOM, $end ) ); |
|
1170 | + $end = rawurlencode(gmdate(DATE_ATOM, $end)); |
|
1171 | 1171 | |
1172 | 1172 | $options = array( |
1173 | 1173 | 'cache' => false, |
1174 | 1174 | ); // this is timestamp level specific; probably should not cache it |
1175 | - return $this->api_call( "sobjects/{$type}/updated/?start=$start&end=$end", array(), 'GET', $options ); |
|
1175 | + return $this->api_call("sobjects/{$type}/updated/?start=$start&end=$end", array(), 'GET', $options); |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | /** |
@@ -1190,28 +1190,28 @@ discard block |
||
1190 | 1190 | * The Salesforce ID of the given Record Type, or null. |
1191 | 1191 | */ |
1192 | 1192 | |
1193 | - public function get_record_type_id_by_developer_name( $name, $devname, $reset = false ) { |
|
1193 | + public function get_record_type_id_by_developer_name($name, $devname, $reset = false) { |
|
1194 | 1194 | |
1195 | 1195 | // example of how this runs: $this->get_record_type_id_by_developer_name( 'Account', 'HH_Account' ); |
1196 | 1196 | |
1197 | - $cached = $this->wordpress->cache_get( 'salesforce_record_types', '' ); |
|
1198 | - if ( is_array( $cached ) && ( ! isset( $reset ) || true !== $reset ) ) { |
|
1199 | - return ! empty( $cached[ $name ][ $devname ] ) ? $cached[ $name ][ $devname ]['Id'] : null; |
|
1197 | + $cached = $this->wordpress->cache_get('salesforce_record_types', ''); |
|
1198 | + if (is_array($cached) && ( ! isset($reset) || true !== $reset)) { |
|
1199 | + return ! empty($cached[$name][$devname]) ? $cached[$name][$devname]['Id'] : null; |
|
1200 | 1200 | } |
1201 | 1201 | |
1202 | - $query = new Object_Sync_Sf_Salesforce_Select_Query( 'RecordType' ); |
|
1203 | - $query->fields = array( 'Id', 'Name', 'DeveloperName', 'SobjectType' ); |
|
1202 | + $query = new Object_Sync_Sf_Salesforce_Select_Query('RecordType'); |
|
1203 | + $query->fields = array('Id', 'Name', 'DeveloperName', 'SobjectType'); |
|
1204 | 1204 | |
1205 | - $result = $this->query( $query ); |
|
1205 | + $result = $this->query($query); |
|
1206 | 1206 | $record_types = array(); |
1207 | 1207 | |
1208 | - foreach ( $result['data']['records'] as $record_type ) { |
|
1209 | - $record_types[ $record_type['SobjectType'] ][ $record_type['DeveloperName'] ] = $record_type; |
|
1208 | + foreach ($result['data']['records'] as $record_type) { |
|
1209 | + $record_types[$record_type['SobjectType']][$record_type['DeveloperName']] = $record_type; |
|
1210 | 1210 | } |
1211 | 1211 | |
1212 | - $cached = $this->wordpress->cache_set( 'salesforce_record_types', '', $record_types, $this->options['cache_expiration'] ); |
|
1212 | + $cached = $this->wordpress->cache_set('salesforce_record_types', '', $record_types, $this->options['cache_expiration']); |
|
1213 | 1213 | |
1214 | - return ! empty( $record_types[ $name ][ $devname ] ) ? $record_types[ $name ][ $devname ]['Id'] : null; |
|
1214 | + return ! empty($record_types[$name][$devname]) ? $record_types[$name][$devname]['Id'] : null; |
|
1215 | 1215 | |
1216 | 1216 | } |
1217 | 1217 | |
@@ -1221,7 +1221,7 @@ discard block |
||
1221 | 1221 | * |
1222 | 1222 | */ |
1223 | 1223 | private function cache_expiration() { |
1224 | - $cache_expiration = $this->wordpress->cache_expiration( $this->option_prefix . 'cache_expiration', 86400 ); |
|
1224 | + $cache_expiration = $this->wordpress->cache_expiration($this->option_prefix . 'cache_expiration', 86400); |
|
1225 | 1225 | return $cache_expiration; |
1226 | 1226 | } |
1227 | 1227 |
@@ -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 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param object $queue |
47 | 47 | * @throws \Exception |
48 | 48 | */ |
49 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
|
49 | + public function __construct($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue) { |
|
50 | 50 | $this->wpdb = $wpdb; |
51 | 51 | $this->version = $version; |
52 | 52 | $this->login_credentials = $login_credentials; |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | $this->schedule_name = 'salesforce_pull'; |
63 | 63 | |
64 | 64 | // Create action hooks for WordPress objects. We run this after plugins are loaded in case something depends on another plugin. |
65 | - add_action( 'plugins_loaded', array( $this, 'add_actions' ) ); |
|
65 | + add_action('plugins_loaded', array($this, 'add_actions')); |
|
66 | 66 | |
67 | - $this->debug = get_option( $this->option_prefix . 'debug_mode', false ); |
|
67 | + $this->debug = get_option($this->option_prefix . 'debug_mode', false); |
|
68 | 68 | |
69 | 69 | } |
70 | 70 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | public function add_actions() { |
76 | 76 | |
77 | 77 | // ajax hook |
78 | - add_action( 'wp_ajax_salesforce_pull_webhook', array( $this, 'salesforce_pull_webhook' ) ); |
|
78 | + add_action('wp_ajax_salesforce_pull_webhook', array($this, 'salesforce_pull_webhook')); |
|
79 | 79 | |
80 | 80 | // action-scheduler needs two hooks: one to check for records, and one to process them |
81 | - add_action( $this->option_prefix . 'pull_check_records', array( $this, 'salesforce_pull' ), 10 ); |
|
82 | - add_action( $this->option_prefix . 'pull_process_records', array( $this, 'salesforce_pull_process_records' ), 10, 4 ); |
|
81 | + add_action($this->option_prefix . 'pull_check_records', array($this, 'salesforce_pull'), 10); |
|
82 | + add_action($this->option_prefix . 'pull_process_records', array($this, 'salesforce_pull_process_records'), 10, 4); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function salesforce_pull_webhook() { |
92 | 92 | |
93 | - if ( true === $this->salesforce_pull() ) { |
|
93 | + if (true === $this->salesforce_pull()) { |
|
94 | 94 | $code = '200'; |
95 | 95 | |
96 | 96 | // single task for action-scheduler to check for data |
97 | 97 | $this->queue->add( |
98 | - $this->schedulable_classes[ $this->schedule_name ]['initializer'], |
|
98 | + $this->schedulable_classes[$this->schedule_name]['initializer'], |
|
99 | 99 | array(), |
100 | 100 | $this->schedule_name |
101 | 101 | ); |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | $code = '403'; |
105 | 105 | } |
106 | 106 | |
107 | - if ( ! empty( $_POST ) ) { // linter flags this, but we're not doing anything with the array just checking to see if it is empty |
|
108 | - wp_send_json_success( $code ); |
|
107 | + if ( ! empty($_POST)) { // linter flags this, but we're not doing anything with the array just checking to see if it is empty |
|
108 | + wp_send_json_success($code); |
|
109 | 109 | } else { |
110 | 110 | return $code; |
111 | 111 | } |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | public function salesforce_pull() { |
119 | 119 | $sfapi = $this->salesforce['sfapi']; |
120 | 120 | |
121 | - if ( true === $this->salesforce['is_authorized'] && true === $this->check_throttle() ) { |
|
121 | + if (true === $this->salesforce['is_authorized'] && true === $this->check_throttle()) { |
|
122 | 122 | |
123 | 123 | $this->get_updated_records(); |
124 | 124 | $this->get_deleted_records(); |
125 | 125 | |
126 | 126 | // Store this request time for the throttle check. |
127 | - update_option( $this->option_prefix . 'pull_last_sync', current_time( 'timestamp', true ) ); |
|
127 | + update_option($this->option_prefix . 'pull_last_sync', current_time('timestamp', true)); |
|
128 | 128 | return true; |
129 | 129 | |
130 | 130 | } else { |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | * Returns false if the time elapsed between recent pulls is too short. |
143 | 143 | */ |
144 | 144 | private function check_throttle() { |
145 | - $pull_throttle = get_option( $this->option_prefix . 'pull_throttle', 5 ); |
|
146 | - $last_sync = get_option( $this->option_prefix . 'pull_last_sync', 0 ); |
|
145 | + $pull_throttle = get_option($this->option_prefix . 'pull_throttle', 5); |
|
146 | + $last_sync = get_option($this->option_prefix . 'pull_last_sync', 0); |
|
147 | 147 | |
148 | - if ( current_time( 'timestamp', true ) > ( $last_sync + $pull_throttle ) ) { |
|
148 | + if (current_time('timestamp', true) > ($last_sync + $pull_throttle)) { |
|
149 | 149 | return true; |
150 | 150 | } else { |
151 | 151 | return false; |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | */ |
164 | 164 | private function get_updated_records() { |
165 | 165 | $sfapi = $this->salesforce['sfapi']; |
166 | - foreach ( $this->mappings->get_fieldmaps() as $salesforce_mapping ) { |
|
166 | + foreach ($this->mappings->get_fieldmaps() as $salesforce_mapping) { |
|
167 | 167 | $map_sync_triggers = $salesforce_mapping['sync_triggers']; // this sets which Salesforce triggers are allowed for the mapping |
168 | 168 | $type = $salesforce_mapping['salesforce_object']; // this sets the salesfore object type for the SOQL query |
169 | 169 | |
170 | - $soql = $this->get_pull_query( $type, $salesforce_mapping ); |
|
170 | + $soql = $this->get_pull_query($type, $salesforce_mapping); |
|
171 | 171 | |
172 | 172 | // get_pull_query returns null if it has no matching fields |
173 | - if ( null === $soql ) { |
|
173 | + if (null === $soql) { |
|
174 | 174 | continue; |
175 | 175 | } |
176 | 176 | |
@@ -185,17 +185,17 @@ discard block |
||
185 | 185 | ); |
186 | 186 | |
187 | 187 | $response = $results['data']; |
188 | - $version_path = wp_parse_url( $sfapi->get_api_endpoint(), PHP_URL_PATH ); |
|
188 | + $version_path = wp_parse_url($sfapi->get_api_endpoint(), PHP_URL_PATH); |
|
189 | 189 | |
190 | - $sf_last_sync = get_option( $this->option_prefix . 'pull_last_sync_' . $type, null ); |
|
191 | - $last_sync = gmdate( 'Y-m-d\TH:i:s\Z', $sf_last_sync ); |
|
190 | + $sf_last_sync = get_option($this->option_prefix . 'pull_last_sync_' . $type, null); |
|
191 | + $last_sync = gmdate('Y-m-d\TH:i:s\Z', $sf_last_sync); |
|
192 | 192 | |
193 | - if ( ! isset( $response['errorCode'] ) ) { |
|
193 | + if ( ! isset($response['errorCode'])) { |
|
194 | 194 | // Write items to the queue. |
195 | - foreach ( $response['records'] as $result ) { |
|
195 | + foreach ($response['records'] as $result) { |
|
196 | 196 | |
197 | 197 | // if this record is new as of the last sync, use the create trigger |
198 | - if ( isset( $result['CreatedDate'] ) && $result['CreatedDate'] > $last_sync ) { |
|
198 | + if (isset($result['CreatedDate']) && $result['CreatedDate'] > $last_sync) { |
|
199 | 199 | $sf_sync_trigger = $this->mappings->sync_sf_create; |
200 | 200 | } else { |
201 | 201 | $sf_sync_trigger = $this->mappings->sync_sf_update; |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | |
204 | 204 | // Only queue when the record's trigger is configured for the mapping |
205 | 205 | // these are bit operators, so we leave out the strict |
206 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
206 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
207 | 207 | $data = array( |
208 | 208 | 'object_type' => $type, |
209 | 209 | 'object' => $result, |
@@ -215,16 +215,16 @@ discard block |
||
215 | 215 | $pull_allowed = true; |
216 | 216 | |
217 | 217 | // if the current fieldmap does not allow create, we need to check if there is an object map for the Salesforce object Id. if not, set pull_allowed to false. |
218 | - if ( isset( $map_sync_triggers ) && ! in_array( $this->mappings->sync_sf_create, $map_sync_triggers ) ) { |
|
219 | - $object_map = $this->mappings->load_by_salesforce( $result['Id'] ); |
|
220 | - if ( empty( $object_map ) ) { |
|
218 | + if (isset($map_sync_triggers) && ! in_array($this->mappings->sync_sf_create, $map_sync_triggers)) { |
|
219 | + $object_map = $this->mappings->load_by_salesforce($result['Id']); |
|
220 | + if (empty($object_map)) { |
|
221 | 221 | $pull_allowed = false; |
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
225 | 225 | // Hook to allow other plugins to prevent a pull per-mapping. |
226 | 226 | // Putting the pull_allowed hook here will keep the queue from storing data when it is not supposed to store it |
227 | - $pull_allowed = apply_filters( $this->option_prefix . 'pull_object_allowed', $pull_allowed, $type, $result, $sf_sync_trigger, $salesforce_mapping ); |
|
227 | + $pull_allowed = apply_filters($this->option_prefix . 'pull_object_allowed', $pull_allowed, $type, $result, $sf_sync_trigger, $salesforce_mapping); |
|
228 | 228 | |
229 | 229 | // example to keep from pulling the Contact with id of abcdef |
230 | 230 | /* |
@@ -237,35 +237,35 @@ discard block |
||
237 | 237 | } |
238 | 238 | */ |
239 | 239 | |
240 | - if ( false === $pull_allowed ) { |
|
241 | - update_option( $this->option_prefix . 'pull_last_sync_' . $type, current_time( 'timestamp', true ) ); |
|
240 | + if (false === $pull_allowed) { |
|
241 | + update_option($this->option_prefix . 'pull_last_sync_' . $type, current_time('timestamp', true)); |
|
242 | 242 | continue; |
243 | 243 | } |
244 | 244 | |
245 | 245 | // add a queue action to save data from salesforce |
246 | 246 | $this->queue->add( |
247 | - $this->schedulable_classes[ $this->schedule_name ]['callback'], |
|
247 | + $this->schedulable_classes[$this->schedule_name]['callback'], |
|
248 | 248 | array( |
249 | 249 | 'object_type' => $type, |
250 | 250 | 'object' => $result['Id'], |
251 | - 'mapping' => filter_var( $salesforce_mapping['id'], FILTER_VALIDATE_INT ), |
|
251 | + 'mapping' => filter_var($salesforce_mapping['id'], FILTER_VALIDATE_INT), |
|
252 | 252 | 'sf_sync_trigger' => $sf_sync_trigger, |
253 | 253 | ), |
254 | 254 | $this->schedule_name |
255 | 255 | ); |
256 | 256 | |
257 | 257 | // Update the last pull sync timestamp for this record type to avoid re-processing in case of error |
258 | - $last_sync_pull_trigger = DateTime::createFromFormat( 'Y-m-d\TH:i:s+', $result[ $salesforce_mapping['pull_trigger_field'] ], new DateTimeZone( 'UTC' ) ); |
|
259 | - update_option( $this->option_prefix . 'pull_last_sync_' . $type, $last_sync_pull_trigger->format( 'U' ) ); |
|
258 | + $last_sync_pull_trigger = DateTime::createFromFormat('Y-m-d\TH:i:s+', $result[$salesforce_mapping['pull_trigger_field']], new DateTimeZone('UTC')); |
|
259 | + update_option($this->option_prefix . 'pull_last_sync_' . $type, $last_sync_pull_trigger->format('U')); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | 263 | // Handle requests larger than the batch limit (usually 2000). |
264 | - $next_records_url = isset( $response['nextRecordsUrl'] ) ? str_replace( $version_path, '', $response['nextRecordsUrl'] ) : false; |
|
264 | + $next_records_url = isset($response['nextRecordsUrl']) ? str_replace($version_path, '', $response['nextRecordsUrl']) : false; |
|
265 | 265 | |
266 | - while ( $next_records_url ) { |
|
266 | + while ($next_records_url) { |
|
267 | 267 | // shouldn't cache this either. it's going into the queue if it exists anyway. |
268 | - $new_results = $sfapi->api_call( |
|
268 | + $new_results = $sfapi->api_call( |
|
269 | 269 | $next_records_url, |
270 | 270 | array(), |
271 | 271 | 'GET', |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | ) |
275 | 275 | ); |
276 | 276 | $new_response = $new_results['data']; |
277 | - if ( ! isset( $new_response['errorCode'] ) ) { |
|
277 | + if ( ! isset($new_response['errorCode'])) { |
|
278 | 278 | // Write items to the queue. |
279 | - foreach ( $new_response['records'] as $result ) { |
|
279 | + foreach ($new_response['records'] as $result) { |
|
280 | 280 | // if this record is new as of the last sync, use the create trigger |
281 | - if ( isset( $result['CreatedDate'] ) && $result['CreatedDate'] > $last_sync ) { |
|
281 | + if (isset($result['CreatedDate']) && $result['CreatedDate'] > $last_sync) { |
|
282 | 282 | $sf_sync_trigger = $this->mappings->sync_sf_create; |
283 | 283 | } else { |
284 | 284 | $sf_sync_trigger = $this->mappings->sync_sf_update; |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | |
287 | 287 | // Only queue when the record's trigger is configured for the mapping |
288 | 288 | // these are bit operators, so we leave out the strict |
289 | - if ( isset( $map_sync_triggers ) && isset( $sf_sync_trigger ) && in_array( $sf_sync_trigger, $map_sync_triggers ) ) { // wp or sf crud event |
|
289 | + if (isset($map_sync_triggers) && isset($sf_sync_trigger) && in_array($sf_sync_trigger, $map_sync_triggers)) { // wp or sf crud event |
|
290 | 290 | $data = array( |
291 | 291 | 'object_type' => $type, |
292 | 292 | 'object' => $result, |
@@ -296,39 +296,39 @@ discard block |
||
296 | 296 | |
297 | 297 | // add a queue action to save data from salesforce |
298 | 298 | $this->queue->add( |
299 | - $this->schedulable_classes[ $this->schedule_name ]['callback'], |
|
299 | + $this->schedulable_classes[$this->schedule_name]['callback'], |
|
300 | 300 | array( |
301 | 301 | 'object_type' => $type, |
302 | 302 | 'object' => $result['Id'], |
303 | - 'mapping' => filter_var( $salesforce_mapping['id'], FILTER_VALIDATE_INT ), |
|
303 | + 'mapping' => filter_var($salesforce_mapping['id'], FILTER_VALIDATE_INT), |
|
304 | 304 | 'sf_sync_trigger' => $sf_sync_trigger, |
305 | 305 | ), |
306 | 306 | $this->schedule_name |
307 | 307 | ); |
308 | 308 | |
309 | 309 | // Update the last pull sync timestamp for this record type to avoid re-processing in case of error |
310 | - $last_sync_pull_trigger = DateTime::createFromFormat( 'Y-m-d\TH:i:s+', $result[ $salesforce_mapping['pull_trigger_field'] ], new DateTimeZone( 'UTC' ) ); |
|
311 | - update_option( $this->option_prefix . 'pull_last_sync_' . $type, $last_sync_pull_trigger->format( 'U' ) ); |
|
310 | + $last_sync_pull_trigger = DateTime::createFromFormat('Y-m-d\TH:i:s+', $result[$salesforce_mapping['pull_trigger_field']], new DateTimeZone('UTC')); |
|
311 | + update_option($this->option_prefix . 'pull_last_sync_' . $type, $last_sync_pull_trigger->format('U')); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
316 | - $next_records_url = isset( $new_response['nextRecordsUrl'] ) ? str_replace( $version_path, '', $new_response['nextRecordsUrl'] ) : false; |
|
316 | + $next_records_url = isset($new_response['nextRecordsUrl']) ? str_replace($version_path, '', $new_response['nextRecordsUrl']) : false; |
|
317 | 317 | } |
318 | 318 | } else { |
319 | 319 | |
320 | 320 | // create log entry for failed pull |
321 | 321 | $status = 'error'; |
322 | 322 | // translators: placeholders are: 1) the server error code, and 2) the name of the Salesforce object |
323 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s', 'object-sync-for-salesforce' ), |
|
324 | - absint( $response['errorCode'] ), |
|
325 | - esc_attr( $salesforce_mapping['salesforce_object'] ) |
|
323 | + $title = sprintf(esc_html__('Error: %1$s %2$s', 'object-sync-for-salesforce'), |
|
324 | + absint($response['errorCode']), |
|
325 | + esc_attr($salesforce_mapping['salesforce_object']) |
|
326 | 326 | ); |
327 | 327 | |
328 | - if ( isset( $this->logging ) ) { |
|
328 | + if (isset($this->logging)) { |
|
329 | 329 | $logging = $this->logging; |
330 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
331 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
330 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
331 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | $logging->setup( |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * @see Object_Sync_Sf_Mapping::get_mapped_fields |
357 | 357 | * @see Object_Sync_Sf_Mapping::get_mapped_record_types |
358 | 358 | */ |
359 | - private function get_pull_query( $type, $salesforce_mapping = array() ) { |
|
359 | + private function get_pull_query($type, $salesforce_mapping = array()) { |
|
360 | 360 | $mapped_fields = array(); |
361 | 361 | $mapped_record_types = array(); |
362 | 362 | |
@@ -368,35 +368,35 @@ discard block |
||
368 | 368 | ); |
369 | 369 | |
370 | 370 | // Iterate over each field mapping to determine our query parameters. |
371 | - foreach ( $mappings as $mapping ) { |
|
371 | + foreach ($mappings as $mapping) { |
|
372 | 372 | |
373 | 373 | // only use fields that come from Salesforce to WordPress, or that sync |
374 | 374 | $mapped_fields = array_merge( |
375 | 375 | $mapped_fields, |
376 | 376 | $this->mappings->get_mapped_fields( |
377 | 377 | $mapping, |
378 | - array( $this->mappings->direction_sync, $this->mappings->direction_sf_wordpress ) |
|
378 | + array($this->mappings->direction_sync, $this->mappings->direction_sf_wordpress) |
|
379 | 379 | ) |
380 | 380 | ); |
381 | 381 | |
382 | 382 | // If Record Type is specified, restrict query. |
383 | - $mapping_record_types = $this->mappings->get_mapped_record_types( $mapping ); |
|
383 | + $mapping_record_types = $this->mappings->get_mapped_record_types($mapping); |
|
384 | 384 | |
385 | 385 | // If Record Type is not specified for a given mapping, ensure query is unrestricted. |
386 | - if ( empty( $mapping_record_types ) ) { |
|
386 | + if (empty($mapping_record_types)) { |
|
387 | 387 | $mapped_record_types = false; |
388 | - } elseif ( is_array( $mapped_record_types ) ) { |
|
389 | - $mapped_record_types = array_merge( $mapped_record_types, $mapping_record_types ); |
|
388 | + } elseif (is_array($mapped_record_types)) { |
|
389 | + $mapped_record_types = array_merge($mapped_record_types, $mapping_record_types); |
|
390 | 390 | } |
391 | 391 | } // End foreach(). |
392 | 392 | |
393 | 393 | // There are no field mappings configured to pull data from Salesforce so |
394 | 394 | // move on to the next mapped object. Prevents querying unmapped data. |
395 | - if ( empty( $mapped_fields ) ) { |
|
395 | + if (empty($mapped_fields)) { |
|
396 | 396 | return null; |
397 | 397 | } |
398 | 398 | |
399 | - $soql = new Object_Sync_Sf_Salesforce_Select_Query( $type ); |
|
399 | + $soql = new Object_Sync_Sf_Salesforce_Select_Query($type); |
|
400 | 400 | |
401 | 401 | // Convert field mappings to SOQL. |
402 | 402 | $soql->fields = array_merge( |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | ); |
409 | 409 | |
410 | 410 | // these are bit operators, so we leave out the strict |
411 | - if ( in_array( $this->mappings->sync_sf_create, $salesforce_mapping['sync_triggers'] ) ) { |
|
411 | + if (in_array($this->mappings->sync_sf_create, $salesforce_mapping['sync_triggers'])) { |
|
412 | 412 | $soql->fields['CreatedDate'] = 'CreatedDate'; |
413 | 413 | } |
414 | 414 | |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | // this should be what keeps it from getting all the records, whether or not they've ever been updated |
417 | 417 | // we also use the option for when the plugin was installed, and don't go back further than that by default |
418 | 418 | |
419 | - $sf_activate_time = get_option( $this->option_prefix . 'activate_time', '' ); |
|
420 | - $sf_last_sync = get_option( $this->option_prefix . 'pull_last_sync_' . $type, null ); |
|
421 | - if ( $sf_last_sync ) { |
|
422 | - $last_sync = gmdate( 'Y-m-d\TH:i:s\Z', $sf_last_sync ); |
|
423 | - $soql->add_condition( $salesforce_mapping['pull_trigger_field'], $last_sync, '>' ); |
|
419 | + $sf_activate_time = get_option($this->option_prefix . 'activate_time', ''); |
|
420 | + $sf_last_sync = get_option($this->option_prefix . 'pull_last_sync_' . $type, null); |
|
421 | + if ($sf_last_sync) { |
|
422 | + $last_sync = gmdate('Y-m-d\TH:i:s\Z', $sf_last_sync); |
|
423 | + $soql->add_condition($salesforce_mapping['pull_trigger_field'], $last_sync, '>'); |
|
424 | 424 | } else { |
425 | - $activated = gmdate( 'Y-m-d\TH:i:s\Z', $sf_activate_time ); |
|
426 | - $soql->add_condition( $salesforce_mapping['pull_trigger_field'], $activated, '>' ); |
|
425 | + $activated = gmdate('Y-m-d\TH:i:s\Z', $sf_activate_time); |
|
426 | + $soql->add_condition($salesforce_mapping['pull_trigger_field'], $activated, '>'); |
|
427 | 427 | // put a hook in here to let devs go retroactive if they want, and sync data from before plugin was activated |
428 | 428 | } |
429 | 429 | |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | ); |
434 | 434 | |
435 | 435 | // Set a limit on the number of records that can be retrieved from the API at one time. |
436 | - $soql->limit = filter_var( get_option( $this->option_prefix . 'pull_query_limit', 25 ), FILTER_VALIDATE_INT ); |
|
436 | + $soql->limit = filter_var(get_option($this->option_prefix . 'pull_query_limit', 25), FILTER_VALIDATE_INT); |
|
437 | 437 | |
438 | 438 | return $soql; |
439 | 439 | |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | // we are not incorporating that part of this branch at this time |
453 | 453 | |
454 | 454 | // Load all unique SF record types that we have mappings for. |
455 | - foreach ( $this->mappings->get_fieldmaps() as $salesforce_mapping ) { |
|
455 | + foreach ($this->mappings->get_fieldmaps() as $salesforce_mapping) { |
|
456 | 456 | |
457 | 457 | $type = $salesforce_mapping['salesforce_object']; |
458 | 458 | |
@@ -464,37 +464,37 @@ discard block |
||
464 | 464 | ); |
465 | 465 | |
466 | 466 | // Iterate over each field mapping to determine our query parameters. |
467 | - foreach ( $mappings as $mapping ) { |
|
467 | + foreach ($mappings as $mapping) { |
|
468 | 468 | |
469 | - $last_delete_sync = get_option( $this->option_prefix . 'pull_delete_last_' . $type, current_time( 'timestamp', true ) ); |
|
470 | - $now = current_time( 'timestamp', true ); |
|
471 | - update_option( $this->option_prefix . 'pull_delete_last_' . $type, $now ); |
|
469 | + $last_delete_sync = get_option($this->option_prefix . 'pull_delete_last_' . $type, current_time('timestamp', true)); |
|
470 | + $now = current_time('timestamp', true); |
|
471 | + update_option($this->option_prefix . 'pull_delete_last_' . $type, $now); |
|
472 | 472 | |
473 | 473 | // get_deleted() constraint: startDate cannot be more than 30 days ago |
474 | 474 | // (using an incompatible date may lead to exceptions). |
475 | - $last_delete_sync = $last_delete_sync > ( current_time( 'timestamp', true ) - 2505600 ) ? $last_delete_sync : ( current_time( 'timestamp', true ) - 2505600 ); |
|
475 | + $last_delete_sync = $last_delete_sync > (current_time('timestamp', true) - 2505600) ? $last_delete_sync : (current_time('timestamp', true) - 2505600); |
|
476 | 476 | |
477 | 477 | // get_deleted() constraint: startDate must be at least one minute greater |
478 | 478 | // than endDate. |
479 | - $now = $now > ( $last_delete_sync + 60 ) ? $now : $now + 60; |
|
479 | + $now = $now > ($last_delete_sync + 60) ? $now : $now + 60; |
|
480 | 480 | |
481 | 481 | // need to be using gmdate for salesforce call |
482 | - $last_delete_sync_sf = gmdate( 'Y-m-d\TH:i:s\Z', $last_delete_sync ); |
|
483 | - $now_sf = gmdate( 'Y-m-d\TH:i:s\Z', $now ); |
|
482 | + $last_delete_sync_sf = gmdate('Y-m-d\TH:i:s\Z', $last_delete_sync); |
|
483 | + $now_sf = gmdate('Y-m-d\TH:i:s\Z', $now); |
|
484 | 484 | |
485 | 485 | // salesforce call |
486 | - $deleted = $sfapi->get_deleted( $type, $last_delete_sync_sf, $now_sf ); |
|
486 | + $deleted = $sfapi->get_deleted($type, $last_delete_sync_sf, $now_sf); |
|
487 | 487 | |
488 | - if ( empty( $deleted['data']['deletedRecords'] ) ) { |
|
488 | + if (empty($deleted['data']['deletedRecords'])) { |
|
489 | 489 | continue; |
490 | 490 | } |
491 | 491 | |
492 | - foreach ( $deleted['data']['deletedRecords'] as $result ) { |
|
492 | + foreach ($deleted['data']['deletedRecords'] as $result) { |
|
493 | 493 | |
494 | 494 | $sf_sync_trigger = $this->mappings->sync_sf_delete; |
495 | 495 | |
496 | 496 | // 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? |
497 | - if ( ! isset( $result['Id'] ) && isset( $result['id'] ) ) { |
|
497 | + if ( ! isset($result['Id']) && isset($result['id'])) { |
|
498 | 498 | $result['Id'] = $result['id']; |
499 | 499 | } |
500 | 500 | $data = array( |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | |
507 | 507 | // Hook to allow other plugins to prevent a pull per-mapping. |
508 | 508 | // Putting the pull_allowed hook here will keep the queue from storing data when it is not supposed to store it |
509 | - $pull_allowed = apply_filters( $this->option_prefix . 'pull_object_allowed', true, $type, $result, $sf_sync_trigger, $salesforce_mapping ); |
|
509 | + $pull_allowed = apply_filters($this->option_prefix . 'pull_object_allowed', true, $type, $result, $sf_sync_trigger, $salesforce_mapping); |
|
510 | 510 | |
511 | 511 | // example to keep from pulling the Contact with id of abcdef |
512 | 512 | /* |
@@ -519,17 +519,17 @@ discard block |
||
519 | 519 | } |
520 | 520 | */ |
521 | 521 | |
522 | - if ( false === $pull_allowed ) { |
|
522 | + if (false === $pull_allowed) { |
|
523 | 523 | continue; |
524 | 524 | } |
525 | 525 | |
526 | 526 | // add a queue action to save data from salesforce |
527 | 527 | $this->queue->add( |
528 | - $this->schedulable_classes[ $this->schedule_name ]['callback'], |
|
528 | + $this->schedulable_classes[$this->schedule_name]['callback'], |
|
529 | 529 | array( |
530 | 530 | 'object_type' => $type, |
531 | 531 | 'object' => $result['Id'], |
532 | - 'mapping' => filter_var( $salesforce_mapping['id'], FILTER_VALIDATE_INT ), |
|
532 | + 'mapping' => filter_var($salesforce_mapping['id'], FILTER_VALIDATE_INT), |
|
533 | 533 | 'sf_sync_trigger' => $sf_sync_trigger, |
534 | 534 | ), |
535 | 535 | $this->schedule_name |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | |
538 | 538 | } |
539 | 539 | |
540 | - update_option( $this->option_prefix . 'pull_delete_last_' . $type, current_time( 'timestamp', true ) ); |
|
540 | + update_option($this->option_prefix . 'pull_delete_last_' . $type, current_time('timestamp', true)); |
|
541 | 541 | |
542 | 542 | } // End foreach(). |
543 | 543 | } // End foreach(). |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | * @param string $wordpress_object |
552 | 552 | * |
553 | 553 | */ |
554 | - public function manual_pull( $object_type, $salesforce_id, $wordpress_object ) { |
|
554 | + public function manual_pull($object_type, $salesforce_id, $wordpress_object) { |
|
555 | 555 | $sfapi = $this->salesforce['sfapi']; |
556 | - $object = $sfapi->api_call( 'sobjects/' . $object_type . '/' . $salesforce_id ); |
|
556 | + $object = $sfapi->api_call('sobjects/' . $object_type . '/' . $salesforce_id); |
|
557 | 557 | $mapping = $this->mappings->get_fieldmaps( |
558 | 558 | null, |
559 | 559 | array( |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | 'wordpress_object' => $wordpress_object, |
562 | 562 | ) |
563 | 563 | ); |
564 | - $this->salesforce_pull_process_records( $object_type, $object['data'], $mapping[0], $this->mappings->sync_sf_update ); |
|
564 | + $this->salesforce_pull_process_records($object_type, $object['data'], $mapping[0], $this->mappings->sync_sf_update); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -579,59 +579,59 @@ discard block |
||
579 | 579 | * @return true or exit the method |
580 | 580 | * |
581 | 581 | */ |
582 | - public function salesforce_pull_process_records( $object_type, $object, $mapping, $sf_sync_trigger ) { |
|
582 | + public function salesforce_pull_process_records($object_type, $object, $mapping, $sf_sync_trigger) { |
|
583 | 583 | |
584 | 584 | $sfapi = $this->salesforce['sfapi']; |
585 | 585 | |
586 | - if ( is_string( $object ) ) { |
|
586 | + if (is_string($object)) { |
|
587 | 587 | $object_id = $object; |
588 | - $object = $sfapi->object_read( $object_type, $object_id )['data']; |
|
588 | + $object = $sfapi->object_read($object_type, $object_id)['data']; |
|
589 | 589 | } |
590 | 590 | |
591 | - if ( is_int( $mapping ) ) { |
|
591 | + if (is_int($mapping)) { |
|
592 | 592 | $mapping_id = $mapping; |
593 | - $mapping = $this->mappings->get_fieldmaps( $mapping_id ); |
|
593 | + $mapping = $this->mappings->get_fieldmaps($mapping_id); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | $mapping_conditions = array( |
597 | 597 | 'salesforce_object' => $object_type, |
598 | 598 | ); |
599 | 599 | |
600 | - if ( isset( $object['RecordTypeId'] ) && $object['RecordTypeId'] !== $this->mappings->salesforce_default_record_type ) { |
|
600 | + if (isset($object['RecordTypeId']) && $object['RecordTypeId'] !== $this->mappings->salesforce_default_record_type) { |
|
601 | 601 | // use this condition to filter the mappings, at that time |
602 | 602 | $mapping_conditions['salesforce_record_type'] = $object['RecordTypeId']; |
603 | 603 | } |
604 | 604 | |
605 | - $salesforce_mappings = $this->mappings->get_fieldmaps( null, $mapping_conditions ); |
|
605 | + $salesforce_mappings = $this->mappings->get_fieldmaps(null, $mapping_conditions); |
|
606 | 606 | |
607 | 607 | // from drupal: if there is more than one mapping, don't throw exceptions |
608 | - $hold_exceptions = count( $salesforce_mappings ) > 1; |
|
608 | + $hold_exceptions = count($salesforce_mappings) > 1; |
|
609 | 609 | $exception = false; |
610 | 610 | |
611 | 611 | $frequencies = $this->queue->get_frequencies(); |
612 | - $seconds = reset( $frequencies )['frequency'] + 60; |
|
612 | + $seconds = reset($frequencies)['frequency'] + 60; |
|
613 | 613 | |
614 | 614 | $transients_to_delete = array(); |
615 | 615 | |
616 | - foreach ( $salesforce_mappings as $salesforce_mapping ) { |
|
616 | + foreach ($salesforce_mappings as $salesforce_mapping) { |
|
617 | 617 | |
618 | 618 | // this returns the row that maps the individual Salesforce row to the individual WordPress row |
619 | - if ( isset( $object['Id'] ) ) { |
|
620 | - $mapping_object = $this->mappings->load_by_salesforce( $object['Id'] ); |
|
619 | + if (isset($object['Id'])) { |
|
620 | + $mapping_object = $this->mappings->load_by_salesforce($object['Id']); |
|
621 | 621 | } else { |
622 | 622 | // if we don't have a Salesforce object id, we've got no business doing stuff in WordPress |
623 | 623 | $status = 'error'; |
624 | - if ( isset( $this->logging ) ) { |
|
624 | + if (isset($this->logging)) { |
|
625 | 625 | $logging = $this->logging; |
626 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
627 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
626 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
627 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
628 | 628 | } |
629 | 629 | |
630 | - $title = sprintf( esc_html__( 'Error: Salesforce Pull: unable to process queue item because it has no Salesforce Id.', 'object-sync-for-salesforce' ) ); |
|
630 | + $title = sprintf(esc_html__('Error: Salesforce Pull: unable to process queue item because it has no Salesforce Id.', 'object-sync-for-salesforce')); |
|
631 | 631 | |
632 | 632 | $logging->setup( |
633 | 633 | $title, |
634 | - print_r( $object, true ), // log whatever we have in the event of this error, so print the array |
|
634 | + print_r($object, true), // log whatever we have in the event of this error, so print the array |
|
635 | 635 | $sf_sync_trigger, |
636 | 636 | 0, // parent id goes here but we don't have one, so make it 0 |
637 | 637 | $status |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | // if it's not already connected (ie on create), the array will be empty |
644 | 644 | |
645 | 645 | // hook to allow other plugins to define or alter the mapping object |
646 | - $mapping_object = apply_filters( $this->option_prefix . 'pull_mapping_object', $mapping_object, $object, $mapping ); |
|
646 | + $mapping_object = apply_filters($this->option_prefix . 'pull_mapping_object', $mapping_object, $object, $mapping); |
|
647 | 647 | |
648 | 648 | // we already have the data from Salesforce at this point; we just need to work with it in WordPress |
649 | 649 | $synced_object = array( |
@@ -652,58 +652,58 @@ discard block |
||
652 | 652 | 'mapping' => $mapping, |
653 | 653 | ); |
654 | 654 | |
655 | - $structure = $this->wordpress->get_wordpress_table_structure( $salesforce_mapping['wordpress_object'] ); |
|
655 | + $structure = $this->wordpress->get_wordpress_table_structure($salesforce_mapping['wordpress_object']); |
|
656 | 656 | $object_id = $structure['id_field']; |
657 | 657 | |
658 | 658 | $op = ''; |
659 | 659 | |
660 | 660 | // are these objects already connected in WordPress? |
661 | - if ( isset( $mapping_object['id'] ) ) { |
|
661 | + if (isset($mapping_object['id'])) { |
|
662 | 662 | $is_new = false; |
663 | 663 | $mapping_object_id_transient = $mapping_object['id']; |
664 | 664 | } else { |
665 | 665 | // there is not a mapping object for this WordPress object id yet |
666 | 666 | // check for that transient with the currently pushing id |
667 | 667 | $is_new = true; |
668 | - $mapping_object_id_transient = get_transient( 'salesforce_pushing_object_id' ); |
|
668 | + $mapping_object_id_transient = get_transient('salesforce_pushing_object_id'); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | // Drupal only does a salesforce_pull flag, but we might as well do push and pull because WordPress |
672 | - $salesforce_pushing = (int) get_transient( 'salesforce_pushing_' . $mapping_object_id_transient ); |
|
673 | - if ( 1 === $salesforce_pushing ) { |
|
672 | + $salesforce_pushing = (int) get_transient('salesforce_pushing_' . $mapping_object_id_transient); |
|
673 | + if (1 === $salesforce_pushing) { |
|
674 | 674 | $transients_to_delete[] = $mapping_object_id_transient; |
675 | 675 | continue; |
676 | 676 | } |
677 | 677 | |
678 | 678 | // deleting mapped objects |
679 | - if ( $sf_sync_trigger == $this->mappings->sync_sf_delete ) { // trigger is a bit operator |
|
680 | - if ( isset( $mapping_object['id'] ) ) { |
|
679 | + if ($sf_sync_trigger == $this->mappings->sync_sf_delete) { // trigger is a bit operator |
|
680 | + if (isset($mapping_object['id'])) { |
|
681 | 681 | |
682 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
683 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
682 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
683 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
684 | 684 | |
685 | 685 | $op = 'Delete'; |
686 | - $wordpress_check = $this->mappings->load_by_wordpress( $mapping_object['wordpress_object'], $mapping_object['wordpress_id'] ); |
|
687 | - if ( count( $wordpress_check ) === count( $wordpress_check, COUNT_RECURSIVE ) ) { |
|
686 | + $wordpress_check = $this->mappings->load_by_wordpress($mapping_object['wordpress_object'], $mapping_object['wordpress_id']); |
|
687 | + if (count($wordpress_check) === count($wordpress_check, COUNT_RECURSIVE)) { |
|
688 | 688 | try { |
689 | - $result = $this->wordpress->object_delete( $salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'] ); |
|
690 | - } catch ( WordpressException $e ) { |
|
689 | + $result = $this->wordpress->object_delete($salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id']); |
|
690 | + } catch (WordpressException $e) { |
|
691 | 691 | $status = 'error'; |
692 | 692 | // create log entry for failed delete |
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__( 'Error: %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__('Error: %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( |
@@ -714,38 +714,38 @@ discard block |
||
714 | 714 | $status |
715 | 715 | ); |
716 | 716 | |
717 | - if ( false === $hold_exceptions ) { |
|
717 | + if (false === $hold_exceptions) { |
|
718 | 718 | throw $e; |
719 | 719 | } |
720 | - if ( empty( $exception ) ) { |
|
720 | + if (empty($exception)) { |
|
721 | 721 | $exception = $e; |
722 | 722 | } else { |
723 | - $my_class = get_class( $e ); |
|
724 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
723 | + $my_class = get_class($e); |
|
724 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | // hook for pull fail |
728 | - do_action( $this->option_prefix . 'pull_fail', $op, $result, $synced_object ); |
|
728 | + do_action($this->option_prefix . 'pull_fail', $op, $result, $synced_object); |
|
729 | 729 | |
730 | 730 | } // End try(). |
731 | 731 | |
732 | - if ( ! isset( $e ) ) { |
|
732 | + if ( ! isset($e)) { |
|
733 | 733 | // create log entry for successful delete if the result had no errors |
734 | 734 | $status = 'success'; |
735 | - if ( isset( $this->logging ) ) { |
|
735 | + if (isset($this->logging)) { |
|
736 | 736 | $logging = $this->logging; |
737 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
738 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
737 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
738 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | // 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 |
742 | - $title = sprintf( esc_html__( 'Success: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce' ), |
|
743 | - esc_attr( $op ), |
|
744 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
745 | - esc_attr( $object_id ), |
|
746 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
747 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
748 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
742 | + $title = sprintf(esc_html__('Success: %1$s WordPress %2$s with %3$s of %4$s (%5$s %6$s)', 'object-sync-for-salesforce'), |
|
743 | + esc_attr($op), |
|
744 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
745 | + esc_attr($object_id), |
|
746 | + esc_attr($mapping_object['wordpress_id']), |
|
747 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
748 | + esc_attr($mapping_object['salesforce_id']) |
|
749 | 749 | ); |
750 | 750 | |
751 | 751 | $logging->setup( |
@@ -757,38 +757,38 @@ discard block |
||
757 | 757 | ); |
758 | 758 | |
759 | 759 | // hook for pull success |
760 | - do_action( $this->option_prefix . 'pull_success', $op, $result, $synced_object ); |
|
760 | + do_action($this->option_prefix . 'pull_success', $op, $result, $synced_object); |
|
761 | 761 | } |
762 | 762 | } else { |
763 | - $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' ) ); |
|
763 | + $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')); |
|
764 | 764 | $i = 0; |
765 | - foreach ( $wordpress_check as $match ) { |
|
765 | + foreach ($wordpress_check as $match) { |
|
766 | 766 | $i++; |
767 | - $more_ids .= sprintf( $match['salesforce_id'] ); |
|
768 | - if ( count( $wordpress_check ) !== $i ) { |
|
769 | - $more_ids .= sprintf( ', ' ); |
|
767 | + $more_ids .= sprintf($match['salesforce_id']); |
|
768 | + if (count($wordpress_check) !== $i) { |
|
769 | + $more_ids .= sprintf(', '); |
|
770 | 770 | } else { |
771 | - $more_ids .= sprintf( '.</p>' ); |
|
771 | + $more_ids .= sprintf('.</p>'); |
|
772 | 772 | } |
773 | 773 | } |
774 | 774 | |
775 | - $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>' ); |
|
775 | + $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>'); |
|
776 | 776 | |
777 | 777 | $status = 'notice'; |
778 | - if ( isset( $this->logging ) ) { |
|
778 | + if (isset($this->logging)) { |
|
779 | 779 | $logging = $this->logging; |
780 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
781 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
780 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
781 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | // 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 |
785 | - $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' ), |
|
786 | - esc_attr( $op ), |
|
787 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
788 | - esc_attr( $object_id ), |
|
789 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
790 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
791 | - esc_attr( $mapping_object['salesforce_id'] ) |
|
785 | + $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'), |
|
786 | + esc_attr($op), |
|
787 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
788 | + esc_attr($object_id), |
|
789 | + esc_attr($mapping_object['wordpress_id']), |
|
790 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
791 | + esc_attr($mapping_object['salesforce_id']) |
|
792 | 792 | ); |
793 | 793 | |
794 | 794 | $logging->setup( |
@@ -802,27 +802,27 @@ discard block |
||
802 | 802 | |
803 | 803 | // delete the map row from WordPress after the WordPress row has been deleted |
804 | 804 | // we delete the map row even if the WordPress delete failed, because the Salesforce object is gone |
805 | - $this->mappings->delete_object_map( $mapping_object['id'] ); |
|
805 | + $this->mappings->delete_object_map($mapping_object['id']); |
|
806 | 806 | // there is no map row if we end this if statement |
807 | 807 | } // End if(). |
808 | 808 | return; |
809 | 809 | } // End if(). |
810 | 810 | |
811 | 811 | // map the Salesforce values to WordPress fields |
812 | - $params = $this->mappings->map_params( $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
812 | + $params = $this->mappings->map_params($mapping, $object, $sf_sync_trigger, false, $is_new); |
|
813 | 813 | |
814 | 814 | // hook to allow other plugins to modify the $params array |
815 | 815 | // use hook to map fields between the WordPress and Salesforce objects |
816 | 816 | // returns $params. |
817 | - $params = apply_filters( $this->option_prefix . 'pull_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new ); |
|
817 | + $params = apply_filters($this->option_prefix . 'pull_params_modify', $params, $mapping, $object, $sf_sync_trigger, false, $is_new); |
|
818 | 818 | |
819 | 819 | // if we don't get any params, there are no fields that should be sent to WordPress |
820 | - if ( empty( $params ) ) { |
|
820 | + if (empty($params)) { |
|
821 | 821 | return; |
822 | 822 | } |
823 | 823 | |
824 | 824 | // if there is a prematch WordPress field - ie email - on the fieldmap object |
825 | - if ( isset( $params['prematch'] ) && is_array( $params['prematch'] ) ) { |
|
825 | + if (isset($params['prematch']) && is_array($params['prematch'])) { |
|
826 | 826 | $prematch_field_wordpress = $params['prematch']['wordpress_field']; |
827 | 827 | $prematch_field_salesforce = $params['prematch']['salesforce_field']; |
828 | 828 | $prematch_value = $params['prematch']['value']; |
@@ -832,22 +832,22 @@ discard block |
||
832 | 832 | 'method_update' => $params['prematch']['method_update'], |
833 | 833 | 'method_read' => $params['prematch']['method_read'], |
834 | 834 | ); |
835 | - unset( $params['prematch'] ); |
|
835 | + unset($params['prematch']); |
|
836 | 836 | } |
837 | 837 | |
838 | 838 | // if there is an external key field in Salesforce - ie a Mailchimp user id - on the fieldmap object, this should not affect how WordPress handles it so we have removed it from the pull parameters. |
839 | 839 | |
840 | 840 | // methods to run the wp create or update operations |
841 | 841 | |
842 | - if ( true === $is_new ) { |
|
842 | + if (true === $is_new) { |
|
843 | 843 | |
844 | 844 | // setup SF record type. CampaignMember objects get their Campaign's type |
845 | 845 | // i am still a bit confused about this |
846 | 846 | // we should store this as a meta field on each object, if it meets these criteria |
847 | 847 | // we need to store the read/modify attributes because the field doesn't exist in the mapping |
848 | - if ( $salesforce_mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty( $params['RecordTypeId'] ) && ( 'CampaignMember' !== $salesforce_mapping['salesforce_object'] ) ) { |
|
848 | + if ($salesforce_mapping['salesforce_record_type_default'] !== $this->mappings->salesforce_default_record_type && empty($params['RecordTypeId']) && ('CampaignMember' !== $salesforce_mapping['salesforce_object'])) { |
|
849 | 849 | $type = $salesforce_mapping['wordpress_object']; |
850 | - if ( 'category' === $salesforce_mapping['wordpress_object'] || 'tag' === $salesforce_mapping['wordpress_object'] || 'post_tag' === $salesforce_mapping['wordpress_object'] ) { |
|
850 | + if ('category' === $salesforce_mapping['wordpress_object'] || 'tag' === $salesforce_mapping['wordpress_object'] || 'post_tag' === $salesforce_mapping['wordpress_object']) { |
|
851 | 851 | $type = 'term'; |
852 | 852 | } |
853 | 853 | $params['RecordTypeId'] = array( |
@@ -865,24 +865,24 @@ discard block |
||
865 | 865 | // returns a $salesforce_id. |
866 | 866 | // it should keep NULL if there is no match |
867 | 867 | // the function that calls this hook needs to check the mapping to make sure the WordPress object is the right type |
868 | - $wordpress_id = apply_filters( $this->option_prefix . 'find_wp_object_match', null, $object, $mapping, 'pull' ); |
|
868 | + $wordpress_id = apply_filters($this->option_prefix . 'find_wp_object_match', null, $object, $mapping, 'pull'); |
|
869 | 869 | |
870 | 870 | // hook to allow other plugins to do something right before WordPress data is saved |
871 | 871 | // ex: run outside methods on an object if it exists, or do something in preparation for it if it doesn't |
872 | - do_action( $this->option_prefix . 'pre_pull', $wordpress_id, $mapping, $object, $object_id, $params ); |
|
872 | + do_action($this->option_prefix . 'pre_pull', $wordpress_id, $mapping, $object, $object_id, $params); |
|
873 | 873 | |
874 | - if ( isset( $prematch_field_salesforce ) || null !== $wordpress_id ) { |
|
874 | + if (isset($prematch_field_salesforce) || null !== $wordpress_id) { |
|
875 | 875 | |
876 | 876 | $op = 'Upsert'; |
877 | 877 | |
878 | 878 | // if either prematch criteria exists, make the values queryable |
879 | - if ( isset( $prematch_field_salesforce ) ) { |
|
879 | + if (isset($prematch_field_salesforce)) { |
|
880 | 880 | $upsert_key = $prematch_field_wordpress; |
881 | 881 | $upsert_value = $prematch_value; |
882 | 882 | $upsert_methods = $prematch_methods; |
883 | 883 | } |
884 | 884 | |
885 | - if ( null !== $wordpress_id ) { |
|
885 | + if (null !== $wordpress_id) { |
|
886 | 886 | $upsert_key = $object_id; |
887 | 887 | $upsert_value = $wordpress_id; |
888 | 888 | $upsert_methods = array(); |
@@ -891,13 +891,13 @@ discard block |
||
891 | 891 | // with the flag at the end, upsert returns a $wordpress_id only |
892 | 892 | // we can then check to see if it has a mapping object |
893 | 893 | // we should only do this if the above hook didn't already set the $wordpress_id |
894 | - if ( null === $wordpress_id ) { |
|
895 | - $wordpress_id = $this->wordpress->object_upsert( $salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'], true ); |
|
894 | + if (null === $wordpress_id) { |
|
895 | + $wordpress_id = $this->wordpress->object_upsert($salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'], true); |
|
896 | 896 | } |
897 | 897 | |
898 | 898 | // find out if there is a mapping object for this WordPress object already |
899 | 899 | // don't do it if the WordPress id is 0. |
900 | - if ( 0 !== $wordpress_id ) { |
|
900 | + if (0 !== $wordpress_id) { |
|
901 | 901 | $mapping_object = $this->mappings->get_object_maps( |
902 | 902 | array( |
903 | 903 | 'wordpress_id' => $wordpress_id, |
@@ -912,35 +912,35 @@ discard block |
||
912 | 912 | ) |
913 | 913 | ); |
914 | 914 | |
915 | - if ( array() !== $mapping_object_debug ) { |
|
915 | + if (array() !== $mapping_object_debug) { |
|
916 | 916 | // create log entry to warn about at least one id of 0 |
917 | 917 | $status = 'error'; |
918 | - $title = sprintf( esc_html__( 'Error: There is at least one object map with a WordPress ID of 0.', 'object-sync-for-salesforce' ) ); |
|
918 | + $title = sprintf(esc_html__('Error: There is at least one object map with a WordPress ID of 0.', 'object-sync-for-salesforce')); |
|
919 | 919 | |
920 | - if ( 1 === count( $mapping_object_debug ) ) { |
|
920 | + if (1 === count($mapping_object_debug)) { |
|
921 | 921 | // 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 |
922 | - $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' ), |
|
923 | - absint( $mapping_object_debug['id'] ), |
|
924 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
925 | - esc_attr( $mapping_object_debug['salesforce_id'] ) |
|
922 | + $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'), |
|
923 | + absint($mapping_object_debug['id']), |
|
924 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
925 | + esc_attr($mapping_object_debug['salesforce_id']) |
|
926 | 926 | ); |
927 | 927 | } else { |
928 | - $body = sprintf( esc_html__( 'There are multiple object maps with WordPress ID of 0. Their IDs are: ', 'object-sync-for-salesforce' ) . '<ul>' ); |
|
929 | - foreach ( $mapping_object_debug as $mapping_object ) { |
|
928 | + $body = sprintf(esc_html__('There are multiple object maps with WordPress ID of 0. Their IDs are: ', 'object-sync-for-salesforce') . '<ul>'); |
|
929 | + foreach ($mapping_object_debug as $mapping_object) { |
|
930 | 930 | // translators: placeholders are: 1) the mapping object row ID, 2) the ID of the Salesforce object, 3) the WordPress object type |
931 | - $body .= sprintf( '<li>' . esc_html__( 'Mapping object id: %1$s. Salesforce Id: %2$s. WordPress object type: %3$s', 'object-sync-for-salesforce' ) . '</li>', |
|
932 | - absint( $mapping_object['id'] ), |
|
933 | - esc_attr( $mapping_object['salesforce_id'] ), |
|
934 | - esc_attr( $salesforce_mapping['wordpress_object'] ) |
|
931 | + $body .= sprintf('<li>' . esc_html__('Mapping object id: %1$s. Salesforce Id: %2$s. WordPress object type: %3$s', 'object-sync-for-salesforce') . '</li>', |
|
932 | + absint($mapping_object['id']), |
|
933 | + esc_attr($mapping_object['salesforce_id']), |
|
934 | + esc_attr($salesforce_mapping['wordpress_object']) |
|
935 | 935 | ); |
936 | 936 | } |
937 | - $body .= sprintf( '</ul>' ); |
|
937 | + $body .= sprintf('</ul>'); |
|
938 | 938 | } |
939 | 939 | |
940 | - if ( isset( $this->logging ) ) { |
|
940 | + if (isset($this->logging)) { |
|
941 | 941 | $logging = $this->logging; |
942 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
943 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
942 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
943 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
944 | 944 | } |
945 | 945 | $parent = 0; |
946 | 946 | $logging->setup( |
@@ -954,37 +954,37 @@ discard block |
||
954 | 954 | } // End if(). |
955 | 955 | |
956 | 956 | // there is already a mapping object. don't change the WordPress data to match this new Salesforce record, but log it |
957 | - if ( isset( $mapping_object['id'] ) ) { |
|
957 | + if (isset($mapping_object['id'])) { |
|
958 | 958 | // set the transient so that salesforce_push doesn't start doing stuff, then return out of here |
959 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
960 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
959 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
960 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
961 | 961 | // create log entry to indicate that nothing happened |
962 | 962 | $status = 'notice'; |
963 | 963 | // translators: placeholders are: 1) mapping object row id, 2) WordPress object tyoe, 3) individual WordPress item ID, 4) individual Salesforce item ID |
964 | - $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' ), |
|
965 | - absint( $mapping_object['id'] ), |
|
966 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
967 | - absint( $wordpress_id ), |
|
968 | - esc_attr( $object['Id'] ) |
|
964 | + $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'), |
|
965 | + absint($mapping_object['id']), |
|
966 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
967 | + absint($wordpress_id), |
|
968 | + esc_attr($object['Id']) |
|
969 | 969 | ); |
970 | 970 | |
971 | 971 | // 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 |
972 | - $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' ), |
|
973 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
974 | - esc_attr( $structure['id_field'] ), |
|
975 | - absint( $wordpress_id ), |
|
976 | - esc_attr( $mapping_object['salesforce_object'] ), |
|
977 | - esc_attr( $object['Id'] ), |
|
978 | - absint( $mapping_object['id'] ) |
|
972 | + $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'), |
|
973 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
974 | + esc_attr($structure['id_field']), |
|
975 | + absint($wordpress_id), |
|
976 | + esc_attr($mapping_object['salesforce_object']), |
|
977 | + esc_attr($object['Id']), |
|
978 | + absint($mapping_object['id']) |
|
979 | 979 | ); |
980 | 980 | |
981 | - if ( isset( $this->logging ) ) { |
|
981 | + if (isset($this->logging)) { |
|
982 | 982 | $logging = $this->logging; |
983 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
984 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
983 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
984 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
985 | 985 | } |
986 | 986 | // if we know the WordPress object id we can put it in there |
987 | - if ( null !== $wordpress_id ) { |
|
987 | + if (null !== $wordpress_id) { |
|
988 | 988 | $parent = $wordpress_id; |
989 | 989 | } else { |
990 | 990 | $parent = 0; |
@@ -1003,9 +1003,9 @@ discard block |
||
1003 | 1003 | // right here we should set the pulling transient |
1004 | 1004 | // this means we have to create the mapping object here as well, and update it with the correct IDs after successful response |
1005 | 1005 | // create the mapping object between the rows |
1006 | - $mapping_object_id = $this->create_object_map( $object, $this->mappings->generate_temporary_id( 'pull' ), $mapping ); |
|
1007 | - set_transient( 'salesforce_pulling_' . $mapping_object_id, 1, $seconds ); |
|
1008 | - set_transient( 'salesforce_pulling_object_id', $mapping_object_id ); |
|
1006 | + $mapping_object_id = $this->create_object_map($object, $this->mappings->generate_temporary_id('pull'), $mapping); |
|
1007 | + set_transient('salesforce_pulling_' . $mapping_object_id, 1, $seconds); |
|
1008 | + set_transient('salesforce_pulling_object_id', $mapping_object_id); |
|
1009 | 1009 | $mapping_object = $this->mappings->get_object_maps( |
1010 | 1010 | array( |
1011 | 1011 | 'id' => $mapping_object_id, |
@@ -1014,50 +1014,50 @@ discard block |
||
1014 | 1014 | |
1015 | 1015 | // now we can upsert the object in wp if we've gotten to this point |
1016 | 1016 | // this command will either create or update the object |
1017 | - $result = $this->wordpress->object_upsert( $salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts'] ); |
|
1017 | + $result = $this->wordpress->object_upsert($salesforce_mapping['wordpress_object'], $upsert_key, $upsert_value, $upsert_methods, $params, $salesforce_mapping['push_drafts']); |
|
1018 | 1018 | |
1019 | 1019 | } else { |
1020 | 1020 | // No key or prematch field exists on this field map object, create a new object in WordPress. |
1021 | 1021 | $op = 'Create'; |
1022 | - $mapping_object_id = $this->create_object_map( $object, $this->mappings->generate_temporary_id( 'pull' ), $mapping ); |
|
1023 | - set_transient( 'salesforce_pulling_' . $mapping_object_id, 1, $seconds ); |
|
1024 | - set_transient( 'salesforce_pulling_object_id', $mapping_object_id ); |
|
1022 | + $mapping_object_id = $this->create_object_map($object, $this->mappings->generate_temporary_id('pull'), $mapping); |
|
1023 | + set_transient('salesforce_pulling_' . $mapping_object_id, 1, $seconds); |
|
1024 | + set_transient('salesforce_pulling_object_id', $mapping_object_id); |
|
1025 | 1025 | $mapping_object = $this->mappings->get_object_maps( |
1026 | 1026 | array( |
1027 | 1027 | 'id' => $mapping_object_id, |
1028 | 1028 | ) |
1029 | 1029 | ); |
1030 | 1030 | |
1031 | - $result = $this->wordpress->object_create( $salesforce_mapping['wordpress_object'], $params ); |
|
1031 | + $result = $this->wordpress->object_create($salesforce_mapping['wordpress_object'], $params); |
|
1032 | 1032 | } // End if(). |
1033 | - } catch ( WordpressException $e ) { |
|
1033 | + } catch (WordpressException $e) { |
|
1034 | 1034 | // create log entry for failed create or upsert |
1035 | 1035 | $status = 'error'; |
1036 | 1036 | |
1037 | 1037 | // translators: placeholders are: 1) what operation is happening, and 2) the name of the WordPress object |
1038 | - $title = sprintf( esc_html__( 'Error: %1$s %2$s', 'object-sync-for-salesforce' ), |
|
1039 | - esc_attr( $op ), |
|
1040 | - esc_attr( $salesforce_mapping['wordpress_object'] ) |
|
1038 | + $title = sprintf(esc_html__('Error: %1$s %2$s', 'object-sync-for-salesforce'), |
|
1039 | + esc_attr($op), |
|
1040 | + esc_attr($salesforce_mapping['wordpress_object']) |
|
1041 | 1041 | ); |
1042 | 1042 | |
1043 | - if ( null !== $salesforce_id ) { |
|
1043 | + if (null !== $salesforce_id) { |
|
1044 | 1044 | $title .= ' ' . $salesforce_id; |
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | // translators: placeholders are: 1) the name of the Salesforce object, and 2) Id of the Salesforce object |
1048 | - $title .= sprintf( esc_html__( ' (Salesforce %1$s with Id of %2$s)', 'object-sync-for-salesforce' ), |
|
1048 | + $title .= sprintf(esc_html__(' (Salesforce %1$s with Id of %2$s)', 'object-sync-for-salesforce'), |
|
1049 | 1049 | $salesforce_mapping['salesforce_object'], |
1050 | 1050 | $object['Id'] |
1051 | 1051 | ); |
1052 | 1052 | |
1053 | - if ( isset( $this->logging ) ) { |
|
1053 | + if (isset($this->logging)) { |
|
1054 | 1054 | $logging = $this->logging; |
1055 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1056 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1055 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1056 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | // if we know the WordPress object id we can put it in there |
1060 | - if ( null !== $wordpress_id ) { |
|
1060 | + if (null !== $wordpress_id) { |
|
1061 | 1061 | $parent = $wordpress_id; |
1062 | 1062 | } else { |
1063 | 1063 | $parent = 0; |
@@ -1071,26 +1071,26 @@ discard block |
||
1071 | 1071 | $status |
1072 | 1072 | ); |
1073 | 1073 | |
1074 | - if ( false === $hold_exceptions ) { |
|
1074 | + if (false === $hold_exceptions) { |
|
1075 | 1075 | throw $e; |
1076 | 1076 | } |
1077 | - if ( empty( $exception ) ) { |
|
1077 | + if (empty($exception)) { |
|
1078 | 1078 | $exception = $e; |
1079 | 1079 | } else { |
1080 | - $my_class = get_class( $e ); |
|
1081 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
1080 | + $my_class = get_class($e); |
|
1081 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | // hook for pull fail |
1085 | - do_action( $this->option_prefix . 'pull_fail', $op, $result, $synced_object ); |
|
1085 | + do_action($this->option_prefix . 'pull_fail', $op, $result, $synced_object); |
|
1086 | 1086 | |
1087 | 1087 | return; |
1088 | 1088 | } // End try(). |
1089 | 1089 | |
1090 | 1090 | // set $wordpress_data to the query result |
1091 | 1091 | $wordpress_data = $result['data']; |
1092 | - if ( isset( $wordpress_data[ "$object_id" ] ) ) { |
|
1093 | - $wordpress_id = $wordpress_data[ "$object_id" ]; |
|
1092 | + if (isset($wordpress_data["$object_id"])) { |
|
1093 | + $wordpress_id = $wordpress_data["$object_id"]; |
|
1094 | 1094 | } else { |
1095 | 1095 | $wordpress_id = 0; |
1096 | 1096 | } |
@@ -1099,23 +1099,23 @@ discard block |
||
1099 | 1099 | // this means the object has already been created/updated in WordPress |
1100 | 1100 | // 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) |
1101 | 1101 | |
1102 | - if ( empty( $result['errors'] ) ) { |
|
1102 | + if (empty($result['errors'])) { |
|
1103 | 1103 | $status = 'success'; |
1104 | 1104 | |
1105 | - if ( isset( $this->logging ) ) { |
|
1105 | + if (isset($this->logging)) { |
|
1106 | 1106 | $logging = $this->logging; |
1107 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1108 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1107 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1108 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | // 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 |
1112 | - $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' ), |
|
1113 | - esc_attr( $op ), |
|
1114 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1115 | - esc_attr( $object_id ), |
|
1116 | - esc_attr( $wordpress_id ), |
|
1117 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1118 | - esc_attr( $object['Id'] ) |
|
1112 | + $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'), |
|
1113 | + esc_attr($op), |
|
1114 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1115 | + esc_attr($object_id), |
|
1116 | + esc_attr($wordpress_id), |
|
1117 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1118 | + esc_attr($object['Id']) |
|
1119 | 1119 | ); |
1120 | 1120 | |
1121 | 1121 | $logging->setup( |
@@ -1128,40 +1128,40 @@ discard block |
||
1128 | 1128 | |
1129 | 1129 | // update that mapping object |
1130 | 1130 | $mapping_object['wordpress_id'] = $wordpress_id; |
1131 | - $mapping_object = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1131 | + $mapping_object = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1132 | 1132 | |
1133 | 1133 | // hook for pull success |
1134 | - do_action( $this->option_prefix . 'pull_success', $op, $result, $synced_object ); |
|
1134 | + do_action($this->option_prefix . 'pull_success', $op, $result, $synced_object); |
|
1135 | 1135 | } else { |
1136 | 1136 | |
1137 | 1137 | // create log entry for failed create or upsert |
1138 | 1138 | // 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 |
1139 | 1139 | // if we see this in the log entries, we can understand what it does, but probably not until then |
1140 | 1140 | $status = 'error'; |
1141 | - if ( isset( $this->logging ) ) { |
|
1141 | + if (isset($this->logging)) { |
|
1142 | 1142 | $logging = $this->logging; |
1143 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1144 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1143 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1144 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | - if ( is_object( $wordpress_id ) ) { |
|
1147 | + if (is_object($wordpress_id)) { |
|
1148 | 1148 | // print this array because if this happens, something weird has happened and we want to log whatever we have |
1149 | - $wordpress_id = print_r( $wordpress_id, true ); |
|
1149 | + $wordpress_id = print_r($wordpress_id, true); |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | // translators: placeholders are: 1) what operation is happening, 2) the name of the Salesforce object type, 3) the Salesforce object Id value |
1153 | - $title = sprintf( esc_html__( 'Error syncing: %1$s to WordPress (Salesforce %2$s Id %3$s)', 'object-sync-for-salesforce' ), |
|
1154 | - esc_attr( $op ), |
|
1155 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1156 | - esc_attr( $object['Id'] ) |
|
1153 | + $title = sprintf(esc_html__('Error syncing: %1$s to WordPress (Salesforce %2$s Id %3$s)', 'object-sync-for-salesforce'), |
|
1154 | + esc_attr($op), |
|
1155 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1156 | + esc_attr($object['Id']) |
|
1157 | 1157 | ); |
1158 | 1158 | |
1159 | 1159 | // 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 |
1160 | - $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', |
|
1161 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1162 | - esc_attr( $object_id ), |
|
1163 | - esc_attr( $wordpress_id ), |
|
1164 | - print_r( $result['errors'], true ) // if we get this error, we need to know whatever we have |
|
1160 | + $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', |
|
1161 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1162 | + esc_attr($object_id), |
|
1163 | + esc_attr($wordpress_id), |
|
1164 | + print_r($result['errors'], true) // if we get this error, we need to know whatever we have |
|
1165 | 1165 | ); |
1166 | 1166 | |
1167 | 1167 | $logging->setup( |
@@ -1173,52 +1173,52 @@ discard block |
||
1173 | 1173 | ); |
1174 | 1174 | |
1175 | 1175 | // hook for pull fail |
1176 | - do_action( $this->option_prefix . 'pull_fail', $op, $result, $synced_object ); |
|
1176 | + do_action($this->option_prefix . 'pull_fail', $op, $result, $synced_object); |
|
1177 | 1177 | |
1178 | 1178 | return; |
1179 | 1179 | } // End if(). |
1180 | - } elseif ( false === $is_new ) { |
|
1180 | + } elseif (false === $is_new) { |
|
1181 | 1181 | |
1182 | 1182 | // right here we should set the pulling transient |
1183 | - set_transient( 'salesforce_pulling_' . $mapping_object['id'], 1, $seconds ); |
|
1184 | - set_transient( 'salesforce_pulling_object_id', $mapping_object['id'] ); |
|
1183 | + set_transient('salesforce_pulling_' . $mapping_object['id'], 1, $seconds); |
|
1184 | + set_transient('salesforce_pulling_object_id', $mapping_object['id']); |
|
1185 | 1185 | |
1186 | 1186 | // there is an existing object link |
1187 | 1187 | // if the last sync is greater than the last time this object was updated by Salesforce, skip it |
1188 | 1188 | // this keeps us from doing redundant syncs |
1189 | 1189 | // because SF stores all DateTimes in UTC. |
1190 | - $mapping_object['object_updated'] = current_time( 'mysql' ); |
|
1190 | + $mapping_object['object_updated'] = current_time('mysql'); |
|
1191 | 1191 | |
1192 | 1192 | $pull_trigger_field = $salesforce_mapping['pull_trigger_field']; |
1193 | - $pull_trigger_value = $object[ $pull_trigger_field ]; |
|
1193 | + $pull_trigger_value = $object[$pull_trigger_field]; |
|
1194 | 1194 | |
1195 | 1195 | try { |
1196 | 1196 | |
1197 | 1197 | // hook to allow other plugins to do something right before WordPress data is saved |
1198 | 1198 | // ex: run outside methods on an object if it exists, or do something in preparation for it if it doesn't |
1199 | - do_action( $this->option_prefix . 'pre_pull', $mapping_object['wordpress_id'], $mapping, $object, $object_id, $params ); |
|
1199 | + do_action($this->option_prefix . 'pre_pull', $mapping_object['wordpress_id'], $mapping, $object, $object_id, $params); |
|
1200 | 1200 | |
1201 | 1201 | $op = 'Update'; |
1202 | - $result = $this->wordpress->object_update( $salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'], $params ); |
|
1202 | + $result = $this->wordpress->object_update($salesforce_mapping['wordpress_object'], $mapping_object['wordpress_id'], $params); |
|
1203 | 1203 | |
1204 | 1204 | $mapping_object['last_sync_status'] = $this->mappings->status_success; |
1205 | - $mapping_object['last_sync_message'] = esc_html__( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__; |
|
1205 | + $mapping_object['last_sync_message'] = esc_html__('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__; |
|
1206 | 1206 | |
1207 | 1207 | $status = 'success'; |
1208 | - if ( isset( $this->logging ) ) { |
|
1208 | + if (isset($this->logging)) { |
|
1209 | 1209 | $logging = $this->logging; |
1210 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1211 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1210 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1211 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // 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 |
1215 | - $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' ), |
|
1216 | - esc_attr( $op ), |
|
1217 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1218 | - esc_attr( $object_id ), |
|
1219 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
1220 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1221 | - esc_attr( $object['Id'] ) |
|
1215 | + $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'), |
|
1216 | + esc_attr($op), |
|
1217 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1218 | + esc_attr($object_id), |
|
1219 | + esc_attr($mapping_object['wordpress_id']), |
|
1220 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1221 | + esc_attr($object['Id']) |
|
1222 | 1222 | ); |
1223 | 1223 | |
1224 | 1224 | $logging->setup( |
@@ -1230,25 +1230,25 @@ discard block |
||
1230 | 1230 | ); |
1231 | 1231 | |
1232 | 1232 | // hook for pull success |
1233 | - do_action( $this->option_prefix . 'pull_success', $op, $result, $synced_object ); |
|
1233 | + do_action($this->option_prefix . 'pull_success', $op, $result, $synced_object); |
|
1234 | 1234 | |
1235 | - } catch ( WordpressException $e ) { |
|
1235 | + } catch (WordpressException $e) { |
|
1236 | 1236 | // create log entry for failed update |
1237 | 1237 | $status = 'error'; |
1238 | - if ( isset( $this->logging ) ) { |
|
1238 | + if (isset($this->logging)) { |
|
1239 | 1239 | $logging = $this->logging; |
1240 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1241 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1240 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1241 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | // 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 |
1245 | - $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' ), |
|
1246 | - esc_attr( $op ), |
|
1247 | - esc_attr( $salesforce_mapping['wordpress_object'] ), |
|
1248 | - esc_attr( $object_id ), |
|
1249 | - esc_attr( $mapping_object['wordpress_id'] ), |
|
1250 | - esc_attr( $salesforce_mapping['salesforce_object'] ), |
|
1251 | - esc_attr( $object['Id'] ) |
|
1245 | + $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'), |
|
1246 | + esc_attr($op), |
|
1247 | + esc_attr($salesforce_mapping['wordpress_object']), |
|
1248 | + esc_attr($object_id), |
|
1249 | + esc_attr($mapping_object['wordpress_id']), |
|
1250 | + esc_attr($salesforce_mapping['salesforce_object']), |
|
1251 | + esc_attr($object['Id']) |
|
1252 | 1252 | ); |
1253 | 1253 | |
1254 | 1254 | $logging->setup( |
@@ -1262,18 +1262,18 @@ discard block |
||
1262 | 1262 | $mapping_object['last_sync_status'] = $this->mappings->status_error; |
1263 | 1263 | $mapping_object['last_sync_message'] = $e->getMessage(); |
1264 | 1264 | |
1265 | - if ( false === $hold_exceptions ) { |
|
1265 | + if (false === $hold_exceptions) { |
|
1266 | 1266 | throw $e; |
1267 | 1267 | } |
1268 | - if ( empty( $exception ) ) { |
|
1268 | + if (empty($exception)) { |
|
1269 | 1269 | $exception = $e; |
1270 | 1270 | } else { |
1271 | - $my_class = get_class( $e ); |
|
1272 | - $exception = new $my_class( $e->getMessage(), $e->getCode(), $exception ); |
|
1271 | + $my_class = get_class($e); |
|
1272 | + $exception = new $my_class($e->getMessage(), $e->getCode(), $exception); |
|
1273 | 1273 | } |
1274 | 1274 | |
1275 | 1275 | // hook for pull fail |
1276 | - do_action( $this->option_prefix . 'pull_fail', $op, $result, $synced_object ); |
|
1276 | + do_action($this->option_prefix . 'pull_fail', $op, $result, $synced_object); |
|
1277 | 1277 | |
1278 | 1278 | } // End try(). |
1279 | 1279 | |
@@ -1282,26 +1282,26 @@ discard block |
||
1282 | 1282 | // maybe can check to see if we actually updated anything in WordPress |
1283 | 1283 | // tell the mapping object - whether it is new or already existed - how we just used it |
1284 | 1284 | $mapping_object['last_sync_action'] = 'pull'; |
1285 | - $mapping_object['last_sync'] = current_time( 'mysql' ); |
|
1285 | + $mapping_object['last_sync'] = current_time('mysql'); |
|
1286 | 1286 | |
1287 | 1287 | // update that mapping object. the Salesforce data version will be set here as well because we set it earlier |
1288 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1288 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1289 | 1289 | // end of the if statement for is_new & update or create trigger |
1290 | 1290 | // 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. |
1291 | 1291 | } // End if(). |
1292 | 1292 | } // End foreach(). |
1293 | 1293 | |
1294 | 1294 | // delete transients that we've already processed |
1295 | - foreach ( $transients_to_delete as $mapping_object_id_transient ) { |
|
1296 | - delete_transient( 'salesforce_pushing_' . $mapping_object_id_transient ); |
|
1295 | + foreach ($transients_to_delete as $mapping_object_id_transient) { |
|
1296 | + delete_transient('salesforce_pushing_' . $mapping_object_id_transient); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | - $pushing_id = get_transient( 'salesforce_pushing_object_id' ); |
|
1300 | - if ( in_array( $pushing_id, $transients_to_delete, true ) ) { |
|
1301 | - delete_transient( 'salesforce_pushing_object_id' ); |
|
1299 | + $pushing_id = get_transient('salesforce_pushing_object_id'); |
|
1300 | + if (in_array($pushing_id, $transients_to_delete, true)) { |
|
1301 | + delete_transient('salesforce_pushing_object_id'); |
|
1302 | 1302 | } |
1303 | 1303 | |
1304 | - if ( ! empty( $exception ) ) { |
|
1304 | + if ( ! empty($exception)) { |
|
1305 | 1305 | throw $exception; |
1306 | 1306 | } |
1307 | 1307 | |
@@ -1321,17 +1321,17 @@ discard block |
||
1321 | 1321 | * This is the database row for the map object |
1322 | 1322 | * |
1323 | 1323 | */ |
1324 | - private function create_object_map( $salesforce_object, $wordpress_id, $field_mapping ) { |
|
1324 | + private function create_object_map($salesforce_object, $wordpress_id, $field_mapping) { |
|
1325 | 1325 | // Create object map and save it |
1326 | 1326 | $mapping_object = $this->mappings->create_object_map( |
1327 | 1327 | array( |
1328 | 1328 | 'wordpress_id' => $wordpress_id, // wordpress unique id |
1329 | 1329 | 'salesforce_id' => $salesforce_object['Id'], // salesforce unique id. we don't care what kind of object it is at this point |
1330 | 1330 | 'wordpress_object' => $field_mapping['wordpress_object'], // keep track of what kind of wp object this is |
1331 | - 'last_sync' => current_time( 'mysql' ), |
|
1331 | + 'last_sync' => current_time('mysql'), |
|
1332 | 1332 | 'last_sync_action' => 'pull', |
1333 | 1333 | 'last_sync_status' => $this->mappings->status_success, |
1334 | - 'last_sync_message' => esc_html__( 'Mapping object created via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
1334 | + 'last_sync_message' => esc_html__('Mapping object created via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
1335 | 1335 | 'action' => 'created', |
1336 | 1336 | ) |
1337 | 1337 | ); |
@@ -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 | |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | * @param string $option_prefix The plugin's option prefix |
33 | 33 | * @throws \Exception |
34 | 34 | */ |
35 | - public function __construct( $wpdb, $version, $slug, $option_prefix ) { |
|
35 | + public function __construct($wpdb, $version, $slug, $option_prefix) { |
|
36 | 36 | $this->wpdb = $wpdb; |
37 | 37 | $this->version = $version; |
38 | 38 | $this->slug = $slug; |
39 | 39 | $this->option_prefix = $option_prefix; |
40 | 40 | |
41 | - $this->enabled = get_option( $this->option_prefix . 'enable_logging', false ); |
|
42 | - $this->statuses_to_log = get_option( $this->option_prefix . 'statuses_to_log', array() ); |
|
41 | + $this->enabled = get_option($this->option_prefix . 'enable_logging', false); |
|
42 | + $this->statuses_to_log = get_option($this->option_prefix . 'statuses_to_log', array()); |
|
43 | 43 | |
44 | 44 | $this->schedule_name = 'wp_logging_prune_routine'; |
45 | 45 | |
@@ -53,26 +53,26 @@ discard block |
||
53 | 53 | * @throws \Exception |
54 | 54 | */ |
55 | 55 | private function init() { |
56 | - if ( '1' === $this->enabled ) { |
|
57 | - add_filter( 'cron_schedules', array( $this, 'add_prune_interval' ) ); |
|
58 | - add_filter( 'wp_log_types', array( $this, 'set_log_types' ), 10, 1 ); |
|
59 | - add_filter( 'wp_logging_should_we_prune', array( $this, 'set_prune_option' ), 10, 1 ); |
|
60 | - add_filter( 'wp_logging_prune_when', array( $this, 'set_prune_age' ), 10, 1 ); |
|
61 | - add_filter( 'wp_logging_prune_query_args', array( $this, 'set_prune_args' ), 10, 1 ); |
|
62 | - add_filter( 'wp_logging_post_type_args', array( $this, 'set_log_visibility' ), 10, 1 ); |
|
63 | - |
|
64 | - $schedule_unit = get_option( $this->option_prefix . 'logs_how_often_unit', '' ); |
|
65 | - $schedule_number = get_option( $this->option_prefix . 'logs_how_often_number', '' ); |
|
66 | - $frequency = $this->get_schedule_frequency( $schedule_unit, $schedule_number ); |
|
56 | + if ('1' === $this->enabled) { |
|
57 | + add_filter('cron_schedules', array($this, 'add_prune_interval')); |
|
58 | + add_filter('wp_log_types', array($this, 'set_log_types'), 10, 1); |
|
59 | + add_filter('wp_logging_should_we_prune', array($this, 'set_prune_option'), 10, 1); |
|
60 | + add_filter('wp_logging_prune_when', array($this, 'set_prune_age'), 10, 1); |
|
61 | + add_filter('wp_logging_prune_query_args', array($this, 'set_prune_args'), 10, 1); |
|
62 | + add_filter('wp_logging_post_type_args', array($this, 'set_log_visibility'), 10, 1); |
|
63 | + |
|
64 | + $schedule_unit = get_option($this->option_prefix . 'logs_how_often_unit', ''); |
|
65 | + $schedule_number = get_option($this->option_prefix . 'logs_how_often_number', ''); |
|
66 | + $frequency = $this->get_schedule_frequency($schedule_unit, $schedule_number); |
|
67 | 67 | $key = $frequency['key']; |
68 | 68 | |
69 | - if ( ! wp_next_scheduled( $this->schedule_name ) ) { |
|
70 | - wp_schedule_event( time(), $key, $this->schedule_name ); |
|
69 | + if ( ! wp_next_scheduled($this->schedule_name)) { |
|
70 | + wp_schedule_event(time(), $key, $this->schedule_name); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - public function set_log_visibility( $log_args ) { |
|
75 | + public function set_log_visibility($log_args) { |
|
76 | 76 | // set public to true overrides the WP_DEBUG setting that is the default on the class |
77 | 77 | // capabilities makes it so (currently) only admin users can see the log posts in their admin view |
78 | 78 | // note: there is no actual "public" view for this post type |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | 'read_private_posts' => 'configure_salesforce', |
89 | 89 | ); |
90 | 90 | |
91 | - $log_args = apply_filters( $this->option_prefix . 'logging_post_type_args', $log_args ); |
|
91 | + $log_args = apply_filters($this->option_prefix . 'logging_post_type_args', $log_args); |
|
92 | 92 | |
93 | 93 | return $log_args; |
94 | 94 | } |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | * @param array $schedules An array of scheduled cron items. |
100 | 100 | * @return array $frequency |
101 | 101 | */ |
102 | - public function add_prune_interval( $schedules ) { |
|
102 | + public function add_prune_interval($schedules) { |
|
103 | 103 | |
104 | - $schedule_unit = get_option( $this->option_prefix . 'logs_how_often_unit', '' ); |
|
105 | - $schedule_number = get_option( $this->option_prefix . 'logs_how_often_number', '' ); |
|
106 | - $frequency = $this->get_schedule_frequency( $schedule_unit, $schedule_number ); |
|
104 | + $schedule_unit = get_option($this->option_prefix . 'logs_how_often_unit', ''); |
|
105 | + $schedule_number = get_option($this->option_prefix . 'logs_how_often_number', ''); |
|
106 | + $frequency = $this->get_schedule_frequency($schedule_unit, $schedule_number); |
|
107 | 107 | $key = $frequency['key']; |
108 | 108 | $seconds = $frequency['seconds']; |
109 | 109 | |
110 | - $schedules[ $key ] = array( |
|
110 | + $schedules[$key] = array( |
|
111 | 111 | 'interval' => $seconds * $schedule_number, |
112 | 112 | 'display' => 'Every ' . $schedule_number . ' ' . $schedule_unit, |
113 | 113 | ); |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * @param number $number The number of those units. |
125 | 125 | * @return array |
126 | 126 | */ |
127 | - public function get_schedule_frequency( $unit, $number ) { |
|
127 | + public function get_schedule_frequency($unit, $number) { |
|
128 | 128 | |
129 | - switch ( $unit ) { |
|
129 | + switch ($unit) { |
|
130 | 130 | case 'minutes': |
131 | 131 | $seconds = 60; |
132 | 132 | break; |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @param array $terms An array of string log types in the WP_Logging class. |
156 | 156 | * @return array $terms |
157 | 157 | */ |
158 | - public function set_log_types( $terms ) { |
|
158 | + public function set_log_types($terms) { |
|
159 | 159 | $terms[] = 'salesforce'; |
160 | 160 | return $terms; |
161 | 161 | } |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | * @param string $should_we_prune Whether to prune old log items. |
167 | 167 | * @return string $should_we_prune Whether to prune old log items. |
168 | 168 | */ |
169 | - public function set_prune_option( $should_we_prune ) { |
|
170 | - $should_we_prune = get_option( $this->option_prefix . 'prune_logs', $should_we_prune ); |
|
171 | - if ( '1' === $should_we_prune ) { |
|
169 | + public function set_prune_option($should_we_prune) { |
|
170 | + $should_we_prune = get_option($this->option_prefix . 'prune_logs', $should_we_prune); |
|
171 | + if ('1' === $should_we_prune) { |
|
172 | 172 | $should_we_prune = true; |
173 | 173 | } |
174 | 174 | return $should_we_prune; |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | * @param string $how_old How old the oldest non-pruned log items should be allowed to be. |
181 | 181 | * @return string $how_old |
182 | 182 | */ |
183 | - public function set_prune_age( $how_old ) { |
|
184 | - $value = get_option( $this->option_prefix . 'logs_how_old', '' ) . ' ago'; |
|
185 | - if ( '' !== $value ) { |
|
183 | + public function set_prune_age($how_old) { |
|
184 | + $value = get_option($this->option_prefix . 'logs_how_old', '') . ' ago'; |
|
185 | + if ('' !== $value) { |
|
186 | 186 | return $value; |
187 | 187 | } else { |
188 | 188 | return $how_old; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param array $args Argument array for get_posts determining what posts are eligible for pruning. |
196 | 196 | * @return array $args |
197 | 197 | */ |
198 | - public function set_prune_args( $args ) { |
|
198 | + public function set_prune_args($args) { |
|
199 | 199 | $args['wp_log_type'] = 'salesforce'; |
200 | 200 | return $args; |
201 | 201 | } |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return void |
221 | 221 | */ |
222 | - public function setup( $title, $message, $trigger = 0, $parent = 0, $status ) { |
|
223 | - if ( '1' === $this->enabled && in_array( $status, maybe_unserialize( $this->statuses_to_log ), true ) ) { |
|
224 | - $triggers_to_log = get_option( $this->option_prefix . 'triggers_to_log', array() ); |
|
222 | + public function setup($title, $message, $trigger = 0, $parent = 0, $status) { |
|
223 | + if ('1' === $this->enabled && in_array($status, maybe_unserialize($this->statuses_to_log), true)) { |
|
224 | + $triggers_to_log = get_option($this->option_prefix . 'triggers_to_log', array()); |
|
225 | 225 | // if we force strict on this in_array, it fails because the mapping triggers are bit operators, as indicated in Object_Sync_Sf_Mapping class's method __construct() |
226 | - if ( in_array( $trigger, maybe_unserialize( $triggers_to_log ) ) || 0 === $trigger ) { |
|
227 | - $this->add( $title, $message, $parent ); |
|
226 | + if (in_array($trigger, maybe_unserialize($triggers_to_log)) || 0 === $trigger) { |
|
227 | + $this->add($title, $message, $parent); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | } |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return int The ID of the new log entry |
249 | 249 | */ |
250 | - public static function add( $title = '', $message = '', $parent = 0, $type = 'salesforce' ) { |
|
250 | + public static function add($title = '', $message = '', $parent = 0, $type = 'salesforce') { |
|
251 | 251 | |
252 | 252 | $log_data = array( |
253 | - 'post_title' => esc_html( $title ), |
|
254 | - 'post_content' => wp_kses_post( $message ), |
|
255 | - 'post_parent' => absint( $parent ), |
|
256 | - 'log_type' => esc_attr( $type ), |
|
253 | + 'post_title' => esc_html($title), |
|
254 | + 'post_content' => wp_kses_post($message), |
|
255 | + 'post_parent' => absint($parent), |
|
256 | + 'log_type' => esc_attr($type), |
|
257 | 257 | ); |
258 | 258 | |
259 | - return self::insert_log( $log_data ); |
|
259 | + return self::insert_log($log_data); |
|
260 | 260 | |
261 | 261 | } |
262 | 262 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @return array |
277 | 277 | */ |
278 | - public static function get_logs( $object_id = 0, $type = 'salesforce', $paged = null ) { |
|
278 | + public static function get_logs($object_id = 0, $type = 'salesforce', $paged = null) { |
|
279 | 279 | return self::get_connected_logs( |
280 | 280 | array( |
281 | 281 | 'post_parent' => (int) $object_id, |
@@ -303,20 +303,20 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @return array / false |
305 | 305 | */ |
306 | - public static function get_connected_logs( $args = array() ) { |
|
306 | + public static function get_connected_logs($args = array()) { |
|
307 | 307 | |
308 | 308 | $defaults = array( |
309 | 309 | 'post_parent' => 0, |
310 | 310 | 'post_type' => 'wp_log', |
311 | 311 | 'posts_per_page' => 10, |
312 | 312 | 'post_status' => 'publish', |
313 | - 'paged' => get_query_var( 'paged' ), |
|
313 | + 'paged' => get_query_var('paged'), |
|
314 | 314 | 'log_type' => 'salesforce', |
315 | 315 | ); |
316 | 316 | |
317 | - $query_args = wp_parse_args( $args, $defaults ); |
|
317 | + $query_args = wp_parse_args($args, $defaults); |
|
318 | 318 | |
319 | - if ( $query_args['log_type'] && self::valid_type( $query_args['log_type'] ) ) { |
|
319 | + if ($query_args['log_type'] && self::valid_type($query_args['log_type'])) { |
|
320 | 320 | |
321 | 321 | $query_args['tax_query'] = array( |
322 | 322 | array( |
@@ -328,9 +328,9 @@ discard block |
||
328 | 328 | |
329 | 329 | } |
330 | 330 | |
331 | - $logs = get_posts( $query_args ); |
|
331 | + $logs = get_posts($query_args); |
|
332 | 332 | |
333 | - if ( $logs ) { |
|
333 | + if ($logs) { |
|
334 | 334 | return $logs; |
335 | 335 | } |
336 | 336 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return int |
357 | 357 | */ |
358 | - public static function get_log_count( $object_id = 0, $type = 'salesforce', $meta_query = null ) { |
|
358 | + public static function get_log_count($object_id = 0, $type = 'salesforce', $meta_query = null) { |
|
359 | 359 | |
360 | 360 | $query_args = array( |
361 | 361 | 'post_parent' => (int) $object_id, |
@@ -364,23 +364,23 @@ discard block |
||
364 | 364 | 'post_status' => 'publish', |
365 | 365 | ); |
366 | 366 | |
367 | - if ( ! empty( $type ) && self::valid_type( $type ) ) { |
|
367 | + if ( ! empty($type) && self::valid_type($type)) { |
|
368 | 368 | |
369 | 369 | $query_args['tax_query'] = array( |
370 | 370 | array( |
371 | 371 | 'taxonomy' => 'wp_log_type', |
372 | 372 | 'field' => 'slug', |
373 | - 'terms' => sanitize_key( $type ), |
|
373 | + 'terms' => sanitize_key($type), |
|
374 | 374 | ), |
375 | 375 | ); |
376 | 376 | |
377 | 377 | } |
378 | 378 | |
379 | - if ( ! empty( $meta_query ) ) { |
|
379 | + if ( ! empty($meta_query)) { |
|
380 | 380 | $query_args['meta_query'] = $meta_query; |
381 | 381 | } |
382 | 382 | |
383 | - $logs = new WP_Query( $query_args ); |
|
383 | + $logs = new WP_Query($query_args); |
|
384 | 384 | |
385 | 385 | return (int) $logs->post_count; |
386 | 386 |
@@ -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 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param object $logging a Object_Sync_Sf_Logging instance. |
33 | 33 | * @throws \Exception |
34 | 34 | */ |
35 | - public function __construct( $wpdb, $version, $slug, $option_prefix, $mappings, $logging ) { |
|
35 | + public function __construct($wpdb, $version, $slug, $option_prefix, $mappings, $logging) { |
|
36 | 36 | $this->wpdb = $wpdb; |
37 | 37 | $this->version = $version; |
38 | 38 | $this->slug = $slug; |
@@ -40,19 +40,19 @@ discard block |
||
40 | 40 | $this->mappings = $mappings; |
41 | 41 | $this->logging = $logging; |
42 | 42 | |
43 | - add_action( 'admin_init', function() { |
|
43 | + add_action('admin_init', function() { |
|
44 | 44 | $this->wordpress_objects = $this->get_object_types(); |
45 | 45 | } ); |
46 | 46 | |
47 | 47 | $this->options = array( |
48 | 48 | 'cache' => true, |
49 | - 'cache_expiration' => $this->cache_expiration( 'wordpress_data_cache', 86400 ), |
|
49 | + 'cache_expiration' => $this->cache_expiration('wordpress_data_cache', 86400), |
|
50 | 50 | 'type' => 'read', |
51 | 51 | ); |
52 | 52 | |
53 | - $this->sfwp_transients = new Object_Sync_Sf_WordPress_Transient( 'sfwp_transients' ); |
|
53 | + $this->sfwp_transients = new Object_Sync_Sf_WordPress_Transient('sfwp_transients'); |
|
54 | 54 | |
55 | - $this->debug = get_option( $this->option_prefix . 'debug_mode', false ); |
|
55 | + $this->debug = get_option($this->option_prefix . 'debug_mode', false); |
|
56 | 56 | |
57 | 57 | } |
58 | 58 | |
@@ -80,20 +80,20 @@ discard block |
||
80 | 80 | */ |
81 | 81 | |
82 | 82 | // this should include the available object types and send them to the hook |
83 | - $wordpress_types_not_posts_include = array( 'user', 'comment', 'category', 'tag' ); |
|
84 | - $wordpress_objects = array_merge( get_post_types(), $wordpress_types_not_posts_include ); |
|
83 | + $wordpress_types_not_posts_include = array('user', 'comment', 'category', 'tag'); |
|
84 | + $wordpress_objects = array_merge(get_post_types(), $wordpress_types_not_posts_include); |
|
85 | 85 | // this should be all the objects |
86 | - $wordpress_objects = apply_filters( $this->option_prefix . 'add_more_wordpress_types', $wordpress_objects ); |
|
86 | + $wordpress_objects = apply_filters($this->option_prefix . 'add_more_wordpress_types', $wordpress_objects); |
|
87 | 87 | |
88 | 88 | // by default, only remove the log type we use in this plugin |
89 | - $types_to_remove = apply_filters( $this->option_prefix . 'remove_wordpress_types', array( 'wp_log' ) ); |
|
89 | + $types_to_remove = apply_filters($this->option_prefix . 'remove_wordpress_types', array('wp_log')); |
|
90 | 90 | |
91 | 91 | // if the hook filters out any types, remove them from the visible list |
92 | - if ( ! empty( $types_to_remove ) ) { |
|
93 | - $wordpress_objects = array_diff( $wordpress_objects, $types_to_remove ); |
|
92 | + if ( ! empty($types_to_remove)) { |
|
93 | + $wordpress_objects = array_diff($wordpress_objects, $types_to_remove); |
|
94 | 94 | } |
95 | 95 | |
96 | - sort( $wordpress_objects ); |
|
96 | + sort($wordpress_objects); |
|
97 | 97 | return $wordpress_objects; |
98 | 98 | } |
99 | 99 | |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @param string $object_type The type of object. |
104 | 104 | * @return array $object_table_structure The table structure. |
105 | 105 | */ |
106 | - public function get_wordpress_table_structure( $object_type ) { |
|
107 | - if ( 'attachment' === $object_type ) { |
|
106 | + public function get_wordpress_table_structure($object_type) { |
|
107 | + if ('attachment' === $object_type) { |
|
108 | 108 | $object_table_structure = array( |
109 | 109 | 'object_name' => 'post', |
110 | 110 | 'content_methods' => array( |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'where' => 'AND ' . $this->wpdb->prefix . 'posts.post_type = "' . $object_type . '"', |
127 | 127 | 'ignore_keys' => array(), |
128 | 128 | ); |
129 | - } elseif ( 'user' === $object_type ) { |
|
129 | + } elseif ('user' === $object_type) { |
|
130 | 130 | // User meta fields need to use update_user_meta for create as well, otherwise it'll just get created twice because apparently when the post is created it's already there. |
131 | 131 | $object_table_structure = array( |
132 | 132 | 'object_name' => 'user', |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | 'session_tokens', |
154 | 154 | ), |
155 | 155 | ); |
156 | - } elseif ( 'post' === $object_type ) { |
|
156 | + } elseif ('post' === $object_type) { |
|
157 | 157 | $object_table_structure = array( |
158 | 158 | 'object_name' => 'post', |
159 | 159 | 'content_methods' => array( |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | 'where' => 'AND ' . $this->wpdb->prefix . 'posts.post_type = "' . $object_type . '"', |
176 | 176 | 'ignore_keys' => array(), |
177 | 177 | ); |
178 | - } elseif ( 'category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type ) { |
|
178 | + } elseif ('category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type) { |
|
179 | 179 | // I am unsure why post_tag wasn't here for so long, but i figure it probably needs to be there. |
180 | 180 | $object_table_structure = array( |
181 | 181 | 'object_name' => 'term', |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | ), |
194 | 194 | 'content_table' => $this->wpdb->prefix . 'terms', |
195 | 195 | 'id_field' => 'term_id', |
196 | - 'meta_table' => array( $this->wpdb->prefix . 'termmeta', $this->wpdb->prefix . 'term_taxonomy' ), |
|
196 | + 'meta_table' => array($this->wpdb->prefix . 'termmeta', $this->wpdb->prefix . 'term_taxonomy'), |
|
197 | 197 | 'meta_join_field' => 'term_id', |
198 | 198 | 'where' => '', |
199 | 199 | 'ignore_keys' => array(), |
200 | 200 | ); |
201 | - } elseif ( 'comment' === $object_type ) { |
|
201 | + } elseif ('comment' === $object_type) { |
|
202 | 202 | $object_table_structure = array( |
203 | 203 | 'object_name' => 'comment', |
204 | 204 | 'content_methods' => array( |
@@ -254,14 +254,14 @@ discard block |
||
254 | 254 | * @param string $id_field The field of that object that corresponds with its ID in the database. |
255 | 255 | * @return array $object_fields |
256 | 256 | */ |
257 | - public function get_wordpress_object_fields( $wordpress_object, $id_field = 'ID' ) { |
|
257 | + public function get_wordpress_object_fields($wordpress_object, $id_field = 'ID') { |
|
258 | 258 | |
259 | - $object_table_structure = $this->get_wordpress_table_structure( $wordpress_object ); |
|
259 | + $object_table_structure = $this->get_wordpress_table_structure($wordpress_object); |
|
260 | 260 | |
261 | 261 | $meta_table = $object_table_structure['meta_table']; |
262 | - $meta_methods = maybe_unserialize( $object_table_structure['meta_methods'] ); |
|
262 | + $meta_methods = maybe_unserialize($object_table_structure['meta_methods']); |
|
263 | 263 | $content_table = $object_table_structure['content_table']; |
264 | - $content_methods = maybe_unserialize( $object_table_structure['content_methods'] ); |
|
264 | + $content_methods = maybe_unserialize($object_table_structure['content_methods']); |
|
265 | 265 | $id_field = $object_table_structure['id_field']; |
266 | 266 | $object_name = $object_table_structure['object_name']; |
267 | 267 | $where = $object_table_structure['where']; |
@@ -270,23 +270,23 @@ discard block |
||
270 | 270 | $object_fields = array(); |
271 | 271 | |
272 | 272 | // Try to find the object fields in cache before acquiring it from other source. |
273 | - if ( true === $this->options['cache'] && 'write' !== $this->options['cache'] ) { |
|
274 | - $cached = $this->cache_get( $wordpress_object, array( 'data', 'meta' ) ); |
|
275 | - if ( is_array( $cached ) ) { |
|
273 | + if (true === $this->options['cache'] && 'write' !== $this->options['cache']) { |
|
274 | + $cached = $this->cache_get($wordpress_object, array('data', 'meta')); |
|
275 | + if (is_array($cached)) { |
|
276 | 276 | $object_fields['data'] = $cached; |
277 | 277 | $object_fields['from_cache'] = true; |
278 | 278 | $object_fields['cached'] = true; |
279 | 279 | } else { |
280 | - $object_fields['data'] = $this->object_fields( $object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys ); |
|
281 | - if ( ! empty( $object_fields['data'] ) ) { |
|
282 | - $object_fields['cached'] = $this->cache_set( $wordpress_object, array( 'data', 'meta' ), $object_fields['data'], $this->options['cache_expiration'] ); |
|
280 | + $object_fields['data'] = $this->object_fields($object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys); |
|
281 | + if ( ! empty($object_fields['data'])) { |
|
282 | + $object_fields['cached'] = $this->cache_set($wordpress_object, array('data', 'meta'), $object_fields['data'], $this->options['cache_expiration']); |
|
283 | 283 | } else { |
284 | 284 | $object_fields['cached'] = false; |
285 | 285 | } |
286 | 286 | $object_fields['from_cache'] = false; |
287 | 287 | } |
288 | 288 | } else { |
289 | - $object_fields['data'] = $this->object_fields( $object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys ); |
|
289 | + $object_fields['data'] = $this->object_fields($object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys); |
|
290 | 290 | $object_fields['from_cache'] = false; |
291 | 291 | $object_fields['cached'] = false; |
292 | 292 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * $object_fields = array( 'data' => array(), 'from_cache' => bool, 'cached' => bool ); |
298 | 298 | * This is useful for custom objects that do not use the normal metadata table structure. |
299 | 299 | */ |
300 | - $object_fields = apply_filters( $this->option_prefix . 'wordpress_object_fields', $object_fields, $wordpress_object ); |
|
300 | + $object_fields = apply_filters($this->option_prefix . 'wordpress_object_fields', $object_fields, $wordpress_object); |
|
301 | 301 | |
302 | 302 | return $object_fields['data']; |
303 | 303 | |
@@ -310,36 +310,36 @@ discard block |
||
310 | 310 | * @param string $object_id The ID of the object. |
311 | 311 | * @return array $wordpress_object |
312 | 312 | */ |
313 | - public function get_wordpress_object_data( $object_type, $object_id ) { |
|
313 | + public function get_wordpress_object_data($object_type, $object_id) { |
|
314 | 314 | |
315 | 315 | $wordpress_object = array(); |
316 | - $object_table_structure = $this->get_wordpress_table_structure( $object_type ); |
|
316 | + $object_table_structure = $this->get_wordpress_table_structure($object_type); |
|
317 | 317 | |
318 | 318 | $meta_table = $object_table_structure['meta_table']; |
319 | - $meta_methods = maybe_unserialize( $object_table_structure['meta_methods'] ); |
|
319 | + $meta_methods = maybe_unserialize($object_table_structure['meta_methods']); |
|
320 | 320 | $content_table = $object_table_structure['content_table']; |
321 | - $content_methods = maybe_unserialize( $object_table_structure['content_methods'] ); |
|
321 | + $content_methods = maybe_unserialize($object_table_structure['content_methods']); |
|
322 | 322 | $id_field = $object_table_structure['id_field']; |
323 | 323 | $object_name = $object_table_structure['object_name']; |
324 | 324 | $where = $object_table_structure['where']; |
325 | 325 | $ignore_keys = $object_table_structure['ignore_keys']; |
326 | 326 | |
327 | - if ( 'user' === $object_type ) { |
|
328 | - $data = get_userdata( $object_id ); |
|
329 | - } elseif ( 'post' === $object_type || 'attachment' === $object_type ) { |
|
330 | - $data = get_post( $object_id ); |
|
331 | - } elseif ( 'category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type ) { |
|
332 | - $data = get_term( $object_id ); |
|
333 | - } elseif ( 'comment' === $object_type ) { |
|
334 | - $data = get_comment( $object_id ); |
|
327 | + if ('user' === $object_type) { |
|
328 | + $data = get_userdata($object_id); |
|
329 | + } elseif ('post' === $object_type || 'attachment' === $object_type) { |
|
330 | + $data = get_post($object_id); |
|
331 | + } elseif ('category' === $object_type || 'tag' === $object_type || 'post_tag' === $object_type) { |
|
332 | + $data = get_term($object_id); |
|
333 | + } elseif ('comment' === $object_type) { |
|
334 | + $data = get_comment($object_id); |
|
335 | 335 | } else { // This is for custom post types. |
336 | - $data = get_post( $object_id ); |
|
336 | + $data = get_post($object_id); |
|
337 | 337 | } |
338 | 338 | |
339 | - $fields = $this->get_wordpress_object_fields( $object_type ); |
|
340 | - foreach ( $fields as $key => $value ) { |
|
339 | + $fields = $this->get_wordpress_object_fields($object_type); |
|
340 | + foreach ($fields as $key => $value) { |
|
341 | 341 | $field = $value['key']; |
342 | - $wordpress_object[ $field ] = $data->{$field}; |
|
342 | + $wordpress_object[$field] = $data->{$field}; |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /* |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | } |
356 | 356 | */ |
357 | 357 | |
358 | - $wordpress_object = apply_filters( $this->option_prefix . 'wordpress_object_data', $wordpress_object ); |
|
358 | + $wordpress_object = apply_filters($this->option_prefix . 'wordpress_object_data', $wordpress_object); |
|
359 | 359 | |
360 | 360 | return $wordpress_object; |
361 | 361 | |
@@ -369,16 +369,16 @@ discard block |
||
369 | 369 | * @param array $args The arguents of the API call. |
370 | 370 | * @return $this->sfwp_transients->get $cachekey |
371 | 371 | */ |
372 | - public function cache_get( $url, $args ) { |
|
373 | - if ( is_array( $args ) ) { |
|
372 | + public function cache_get($url, $args) { |
|
373 | + if (is_array($args)) { |
|
374 | 374 | $args[] = $url; |
375 | - array_multisort( $args ); |
|
375 | + array_multisort($args); |
|
376 | 376 | } else { |
377 | 377 | $args .= $url; |
378 | 378 | } |
379 | 379 | |
380 | - $cachekey = md5( wp_json_encode( $args ) ); |
|
381 | - return $this->sfwp_transients->get( $cachekey ); |
|
380 | + $cachekey = md5(wp_json_encode($args)); |
|
381 | + return $this->sfwp_transients->get($cachekey); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -391,20 +391,20 @@ discard block |
||
391 | 391 | * @return Bool whether or not the value was set |
392 | 392 | * @link https://wordpress.stackexchange.com/questions/174330/transient-storage-location-database-xcache-w3total-cache |
393 | 393 | */ |
394 | - public function cache_set( $url, $args, $data, $cache_expiration = '' ) { |
|
395 | - if ( is_array( $args ) ) { |
|
394 | + public function cache_set($url, $args, $data, $cache_expiration = '') { |
|
395 | + if (is_array($args)) { |
|
396 | 396 | $args[] = $url; |
397 | - array_multisort( $args ); |
|
397 | + array_multisort($args); |
|
398 | 398 | } else { |
399 | 399 | $args .= $url; |
400 | 400 | } |
401 | - $cachekey = md5( wp_json_encode( $args ) ); |
|
401 | + $cachekey = md5(wp_json_encode($args)); |
|
402 | 402 | // Cache_expiration is how long it should be stored in the cache. |
403 | 403 | // If we didn't give a custom one, use the default. |
404 | - if ( '' === $cache_expiration ) { |
|
404 | + if ('' === $cache_expiration) { |
|
405 | 405 | $cache_expiration = $this->options['cache_expiration']; |
406 | 406 | } |
407 | - return $this->sfwp_transients->set( $cachekey, $data, $cache_expiration ); |
|
407 | + return $this->sfwp_transients->set($cachekey, $data, $cache_expiration); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | /** |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | * @param int $expire The default time after which to expire the cache. |
416 | 416 | * @return The cache expiration saved in the database. |
417 | 417 | */ |
418 | - public function cache_expiration( $option_key, $expire ) { |
|
419 | - $cache_expiration = get_option( $option_key, $expire ); |
|
418 | + public function cache_expiration($option_key, $expire) { |
|
419 | + $cache_expiration = get_option($option_key, $expire); |
|
420 | 420 | return $cache_expiration; |
421 | 421 | } |
422 | 422 | |
@@ -437,15 +437,15 @@ discard block |
||
437 | 437 | * @param array $ignore_keys Fields to ignore from the database. |
438 | 438 | * @return array $all_fields The fields for the object. |
439 | 439 | */ |
440 | - private function object_fields( $object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys ) { |
|
440 | + private function object_fields($object_name, $id_field, $content_table, $content_methods, $meta_table, $meta_methods, $where, $ignore_keys) { |
|
441 | 441 | // These two queries load all the fields from the specified object unless they have been specified as ignore fields. |
442 | 442 | // They also load the fields that are meta_keys from the specified object's meta table. |
443 | 443 | // Maybe a box for a custom query, since custom fields get done in so many ways. |
444 | 444 | // Eventually this would be the kind of thing we could use fields api for, if it ever gets done. |
445 | - $data_fields = $this->wpdb->get_col( "DESC {$content_table}", 0 ); |
|
446 | - $data_field_types = $this->wpdb->get_col( "DESC {$content_table}", 1 ); // get the database field types |
|
445 | + $data_fields = $this->wpdb->get_col("DESC {$content_table}", 0); |
|
446 | + $data_field_types = $this->wpdb->get_col("DESC {$content_table}", 1); // get the database field types |
|
447 | 447 | |
448 | - if ( is_array( $meta_table ) ) { |
|
448 | + if (is_array($meta_table)) { |
|
449 | 449 | $tax_table = $meta_table[1]; |
450 | 450 | $meta_table = $meta_table[0]; |
451 | 451 | } |
@@ -457,39 +457,39 @@ discard block |
||
457 | 457 | WHERE ' . $meta_table . '.meta_key != "" |
458 | 458 | ' . $where . ' |
459 | 459 | '; |
460 | - $meta_fields = $this->wpdb->get_results( $select_meta ); |
|
460 | + $meta_fields = $this->wpdb->get_results($select_meta); |
|
461 | 461 | $all_fields = array(); |
462 | 462 | |
463 | - foreach ( $data_fields as $key => $value ) { |
|
464 | - if ( ! in_array( $value, $ignore_keys, true ) ) { |
|
463 | + foreach ($data_fields as $key => $value) { |
|
464 | + if ( ! in_array($value, $ignore_keys, true)) { |
|
465 | 465 | $all_fields[] = array( |
466 | 466 | 'key' => $value, |
467 | 467 | 'table' => $content_table, |
468 | - 'methods' => serialize( $content_methods ), |
|
469 | - 'type' => $data_field_types[ $key ], |
|
468 | + 'methods' => serialize($content_methods), |
|
469 | + 'type' => $data_field_types[$key], |
|
470 | 470 | ); |
471 | 471 | } |
472 | 472 | } |
473 | 473 | |
474 | - foreach ( $meta_fields as $key => $value ) { |
|
475 | - if ( ! in_array( $value->meta_key, $ignore_keys, true ) ) { |
|
474 | + foreach ($meta_fields as $key => $value) { |
|
475 | + if ( ! in_array($value->meta_key, $ignore_keys, true)) { |
|
476 | 476 | $all_fields[] = array( |
477 | 477 | 'key' => $value->meta_key, |
478 | 478 | 'table' => $meta_table, |
479 | - 'methods' => serialize( $meta_methods ), |
|
479 | + 'methods' => serialize($meta_methods), |
|
480 | 480 | ); |
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
484 | - if ( 'term' === $object_name ) { |
|
485 | - $taxonomy = $this->wpdb->get_col( "DESC {$tax_table}", 0 ); |
|
486 | - foreach ( $taxonomy as $key => $value ) { |
|
487 | - $exists = array_search( $value, array_column( $all_fields, 'key' ), true ); |
|
488 | - if ( 0 !== $exists ) { |
|
484 | + if ('term' === $object_name) { |
|
485 | + $taxonomy = $this->wpdb->get_col("DESC {$tax_table}", 0); |
|
486 | + foreach ($taxonomy as $key => $value) { |
|
487 | + $exists = array_search($value, array_column($all_fields, 'key'), true); |
|
488 | + if (0 !== $exists) { |
|
489 | 489 | $all_fields[] = array( |
490 | 490 | 'key' => $value, |
491 | 491 | 'table' => $tax_table, |
492 | - 'methods' => serialize( $content_methods ), |
|
492 | + 'methods' => serialize($content_methods), |
|
493 | 493 | ); |
494 | 494 | } |
495 | 495 | } |
@@ -516,28 +516,28 @@ discard block |
||
516 | 516 | * |
517 | 517 | * part of CRUD for WordPress objects |
518 | 518 | */ |
519 | - public function object_create( $name, $params ) { |
|
519 | + public function object_create($name, $params) { |
|
520 | 520 | |
521 | - $structure = $this->get_wordpress_table_structure( $name ); |
|
521 | + $structure = $this->get_wordpress_table_structure($name); |
|
522 | 522 | $id_field = $structure['id_field']; |
523 | 523 | |
524 | - switch ( $name ) { |
|
524 | + switch ($name) { |
|
525 | 525 | case 'user': |
526 | - $result = $this->user_create( $params, $id_field ); |
|
526 | + $result = $this->user_create($params, $id_field); |
|
527 | 527 | break; |
528 | 528 | case 'post': |
529 | - $result = $this->post_create( $params, $id_field ); |
|
529 | + $result = $this->post_create($params, $id_field); |
|
530 | 530 | break; |
531 | 531 | case 'attachment': |
532 | - $result = $this->attachment_create( $params, $id_field ); |
|
532 | + $result = $this->attachment_create($params, $id_field); |
|
533 | 533 | break; |
534 | 534 | case 'category': |
535 | 535 | case 'tag': |
536 | 536 | case 'post_tag': |
537 | - $result = $this->term_create( $params, $name, $id_field ); |
|
537 | + $result = $this->term_create($params, $name, $id_field); |
|
538 | 538 | break; |
539 | 539 | case 'comment': |
540 | - $result = $this->comment_create( $params, $id_field ); |
|
540 | + $result = $this->comment_create($params, $id_field); |
|
541 | 541 | break; |
542 | 542 | default: |
543 | 543 | /* |
@@ -550,14 +550,14 @@ discard block |
||
550 | 550 | * the one param is: array( 'name' => objecttype, 'params' => array_of_params, 'id_field' => idfield ) |
551 | 551 | */ |
552 | 552 | // Check to see if someone is calling the filter, and apply it if so. |
553 | - if ( ! has_filter( $this->option_prefix . 'create_custom_wordpress_item' ) ) { |
|
554 | - $result = $this->post_create( $params, $id_field, $name ); |
|
553 | + if ( ! has_filter($this->option_prefix . 'create_custom_wordpress_item')) { |
|
554 | + $result = $this->post_create($params, $id_field, $name); |
|
555 | 555 | } else { |
556 | - $result = apply_filters( $this->option_prefix . 'create_custom_wordpress_item', array( |
|
556 | + $result = apply_filters($this->option_prefix . 'create_custom_wordpress_item', array( |
|
557 | 557 | 'params' => $params, |
558 | 558 | 'name' => $name, |
559 | 559 | 'id_field' => $id_field, |
560 | - ) ); |
|
560 | + )); |
|
561 | 561 | } |
562 | 562 | break; |
563 | 563 | } // End switch(). |
@@ -593,37 +593,37 @@ discard block |
||
593 | 593 | * |
594 | 594 | * part of CRUD for WordPress objects |
595 | 595 | */ |
596 | - public function object_upsert( $name, $key, $value, $methods = array(), $params, $push_drafts = false, $check_only = false ) { |
|
596 | + public function object_upsert($name, $key, $value, $methods = array(), $params, $push_drafts = false, $check_only = false) { |
|
597 | 597 | |
598 | - $structure = $this->get_wordpress_table_structure( $name ); |
|
598 | + $structure = $this->get_wordpress_table_structure($name); |
|
599 | 599 | $id_field = $structure['id_field']; |
600 | 600 | |
601 | 601 | // If key is set, remove from $params to avoid SQL errors. |
602 | - if ( isset( $params[ $key ] ) ) { |
|
603 | - unset( $params[ $key ] ); |
|
602 | + if (isset($params[$key])) { |
|
603 | + unset($params[$key]); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | // Allow developers to change both the key and value by which objects should be matched. |
607 | - $key = apply_filters( $this->option_prefix . 'modify_upsert_key', $key ); |
|
608 | - $value = apply_filters( $this->option_prefix . 'modify_upsert_value', $value ); |
|
607 | + $key = apply_filters($this->option_prefix . 'modify_upsert_key', $key); |
|
608 | + $value = apply_filters($this->option_prefix . 'modify_upsert_value', $value); |
|
609 | 609 | |
610 | - switch ( $name ) { |
|
610 | + switch ($name) { |
|
611 | 611 | case 'user': |
612 | - $result = $this->user_upsert( $key, $value, $methods, $params, $id_field, $push_drafts, $check_only ); |
|
612 | + $result = $this->user_upsert($key, $value, $methods, $params, $id_field, $push_drafts, $check_only); |
|
613 | 613 | break; |
614 | 614 | case 'post': |
615 | - $result = $this->post_upsert( $key, $value, $methods, $params, $id_field, $push_drafts, $name, $check_only ); |
|
615 | + $result = $this->post_upsert($key, $value, $methods, $params, $id_field, $push_drafts, $name, $check_only); |
|
616 | 616 | break; |
617 | 617 | case 'attachment': |
618 | - $result = $this->attachment_upsert( $key, $value, $methods, $params, $id_field, $check_only ); |
|
618 | + $result = $this->attachment_upsert($key, $value, $methods, $params, $id_field, $check_only); |
|
619 | 619 | break; |
620 | 620 | case 'category': |
621 | 621 | case 'tag': |
622 | 622 | case 'post_tag': |
623 | - $result = $this->term_upsert( $key, $value, $methods, $params, $name, $id_field, $push_drafts, $check_only ); |
|
623 | + $result = $this->term_upsert($key, $value, $methods, $params, $name, $id_field, $push_drafts, $check_only); |
|
624 | 624 | break; |
625 | 625 | case 'comment': |
626 | - $result = $this->comment_upsert( $key, $value, $methods, $params, $id_field, $push_drafts, $check_only ); |
|
626 | + $result = $this->comment_upsert($key, $value, $methods, $params, $id_field, $push_drafts, $check_only); |
|
627 | 627 | break; |
628 | 628 | default: |
629 | 629 | /* |
@@ -638,10 +638,10 @@ discard block |
||
638 | 638 | * array( 'key' => key, 'value' => value, 'methods' => methods, 'params' => array_of_params, 'id_field' => idfield, 'push_drafts' => pushdrafts, 'name' => name, 'check_only' => $check_only ) |
639 | 639 | */ |
640 | 640 | // Check to see if someone is calling the filter, and apply it if so. |
641 | - if ( ! has_filter( $this->option_prefix . 'upsert_custom_wordpress_item' ) ) { |
|
642 | - $result = $this->post_upsert( $key, $value, $methods, $params, $id_field, $push_drafts, $name, $check_only ); |
|
641 | + if ( ! has_filter($this->option_prefix . 'upsert_custom_wordpress_item')) { |
|
642 | + $result = $this->post_upsert($key, $value, $methods, $params, $id_field, $push_drafts, $name, $check_only); |
|
643 | 643 | } else { |
644 | - $result = apply_filters( $this->option_prefix . 'upsert_custom_wordpress_item', array( |
|
644 | + $result = apply_filters($this->option_prefix . 'upsert_custom_wordpress_item', array( |
|
645 | 645 | 'key' => $key, |
646 | 646 | 'value' => $value, |
647 | 647 | 'methods' => $methods, |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | 'push_drafts' => $push_drafts, |
651 | 651 | 'name' => $name, |
652 | 652 | 'check_only' => $check_only, |
653 | - ) ); |
|
653 | + )); |
|
654 | 654 | } |
655 | 655 | break; |
656 | 656 | } // End switch(). |
@@ -676,29 +676,29 @@ discard block |
||
676 | 676 | * cached: |
677 | 677 | * is_redo: |
678 | 678 | */ |
679 | - public function object_update( $name, $id, $params ) { |
|
679 | + public function object_update($name, $id, $params) { |
|
680 | 680 | |
681 | - $structure = $this->get_wordpress_table_structure( $name ); |
|
681 | + $structure = $this->get_wordpress_table_structure($name); |
|
682 | 682 | $id_field = $structure['id_field']; |
683 | 683 | |
684 | - switch ( $name ) { |
|
684 | + switch ($name) { |
|
685 | 685 | case 'user': |
686 | 686 | // User id does not come through by default, but we need it to pass to wp method. |
687 | - $result = $this->user_update( $id, $params, $id_field ); |
|
687 | + $result = $this->user_update($id, $params, $id_field); |
|
688 | 688 | break; |
689 | 689 | case 'post': |
690 | - $result = $this->post_update( $id, $params, $id_field ); |
|
690 | + $result = $this->post_update($id, $params, $id_field); |
|
691 | 691 | break; |
692 | 692 | case 'attachment': |
693 | - $result = $this->attachment_update( $id, $params, $id_field ); |
|
693 | + $result = $this->attachment_update($id, $params, $id_field); |
|
694 | 694 | break; |
695 | 695 | case 'category': |
696 | 696 | case 'tag': |
697 | 697 | case 'post_tag': |
698 | - $result = $this->term_update( $id, $params, $name, $id_field ); |
|
698 | + $result = $this->term_update($id, $params, $name, $id_field); |
|
699 | 699 | break; |
700 | 700 | case 'comment': |
701 | - $result = $this->comment_update( $id, $params, $id_field ); |
|
701 | + $result = $this->comment_update($id, $params, $id_field); |
|
702 | 702 | break; |
703 | 703 | default: |
704 | 704 | /* |
@@ -713,15 +713,15 @@ discard block |
||
713 | 713 | * array( 'key' => key, 'value' => value, 'name' => objecttype, 'params' => array_of_params, 'push_drafts' => pushdrafts, 'methods' => methods ) |
714 | 714 | */ |
715 | 715 | // Check to see if someone is calling the filter, and apply it if so. |
716 | - if ( ! has_filter( $this->option_prefix . 'update_custom_wordpress_item' ) ) { |
|
717 | - $result = $this->post_update( $id, $params, $id_field, $name ); |
|
716 | + if ( ! has_filter($this->option_prefix . 'update_custom_wordpress_item')) { |
|
717 | + $result = $this->post_update($id, $params, $id_field, $name); |
|
718 | 718 | } else { |
719 | - $result = apply_filters( $this->option_prefix . 'update_custom_wordpress_item', array( |
|
719 | + $result = apply_filters($this->option_prefix . 'update_custom_wordpress_item', array( |
|
720 | 720 | 'id' => $id, |
721 | 721 | 'params' => $params, |
722 | 722 | 'name' => $name, |
723 | 723 | 'id_field' => $id_field, |
724 | - ) ); |
|
724 | + )); |
|
725 | 725 | } |
726 | 726 | break; |
727 | 727 | } // End switch(). |
@@ -742,27 +742,27 @@ discard block |
||
742 | 742 | * |
743 | 743 | * part of CRUD for WordPress objects |
744 | 744 | */ |
745 | - public function object_delete( $name, $id ) { |
|
746 | - $structure = $this->get_wordpress_table_structure( $name ); |
|
745 | + public function object_delete($name, $id) { |
|
746 | + $structure = $this->get_wordpress_table_structure($name); |
|
747 | 747 | $id_field = $structure['id_field']; |
748 | 748 | |
749 | - switch ( $name ) { |
|
749 | + switch ($name) { |
|
750 | 750 | case 'user': |
751 | - $success = $this->user_delete( $id ); |
|
751 | + $success = $this->user_delete($id); |
|
752 | 752 | break; |
753 | 753 | case 'post': |
754 | - $success = $this->post_delete( $id ); |
|
754 | + $success = $this->post_delete($id); |
|
755 | 755 | break; |
756 | 756 | case 'attachment': |
757 | - $success = $this->attachment_delete( $id ); |
|
757 | + $success = $this->attachment_delete($id); |
|
758 | 758 | break; |
759 | 759 | case 'category': |
760 | 760 | case 'tag': |
761 | 761 | case 'post_tag': |
762 | - $success = $this->term_delete( $id, $name ); |
|
762 | + $success = $this->term_delete($id, $name); |
|
763 | 763 | break; |
764 | 764 | case 'comment': |
765 | - $success = $this->comment_delete( $id ); |
|
765 | + $success = $this->comment_delete($id); |
|
766 | 766 | break; |
767 | 767 | default: |
768 | 768 | /* |
@@ -774,16 +774,16 @@ discard block |
||
774 | 774 | * array( 'id' => id, 'name' => objecttype ) |
775 | 775 | */ |
776 | 776 | // Check to see if someone is calling the filter, and apply it if so. |
777 | - if ( ! has_filter( $this->option_prefix . 'delete_custom_wordpress_item' ) ) { |
|
778 | - $success = $this->post_delete( $id ); |
|
777 | + if ( ! has_filter($this->option_prefix . 'delete_custom_wordpress_item')) { |
|
778 | + $success = $this->post_delete($id); |
|
779 | 779 | } else { |
780 | - $success = apply_filters( $this->option_prefix . 'delete_custom_wordpress_item', array( |
|
780 | + $success = apply_filters($this->option_prefix . 'delete_custom_wordpress_item', array( |
|
781 | 781 | 'id' => $id, |
782 | 782 | 'name' => $name, |
783 | - ) ); |
|
783 | + )); |
|
784 | 784 | } |
785 | 785 | |
786 | - $success = $this->post_delete( $id ); |
|
786 | + $success = $this->post_delete($id); |
|
787 | 787 | break; |
788 | 788 | } // End switch(). |
789 | 789 | |
@@ -808,13 +808,13 @@ discard block |
||
808 | 808 | * success: 1 |
809 | 809 | * "errors" : [ ], |
810 | 810 | */ |
811 | - private function user_create( $params, $id_field = 'ID' ) { |
|
811 | + private function user_create($params, $id_field = 'ID') { |
|
812 | 812 | |
813 | 813 | // Allow username to be email address or username. |
814 | 814 | // The username could be autogenerated before this point for the sake of URLs. |
815 | 815 | $username = $params['user_email']['value']; |
816 | 816 | $email_address = $params['user_email']['value']; |
817 | - if ( isset( $params['user_login']['value'] ) ) { // User_login is used by username_exists. |
|
817 | + if (isset($params['user_login']['value'])) { // User_login is used by username_exists. |
|
818 | 818 | $username = $params['user_login']['value']; |
819 | 819 | } else { |
820 | 820 | $params['user_login'] = array( |
@@ -825,44 +825,44 @@ discard block |
||
825 | 825 | } |
826 | 826 | |
827 | 827 | // This is a new user. |
828 | - if ( false === username_exists( $username ) ) { |
|
828 | + if (false === username_exists($username)) { |
|
829 | 829 | |
830 | 830 | // Create the user |
831 | 831 | // WordPress sends a password reset link so this password doesn't get used, but it does exist in the database, which is helpful to prevent access before the user uses their password reset email. |
832 | 832 | $params['user_pass'] = array( |
833 | - 'value' => wp_generate_password( 12, false ), |
|
833 | + 'value' => wp_generate_password(12, false), |
|
834 | 834 | 'method_modify' => 'wp_insert_user', |
835 | 835 | 'method_read' => 'get_user_by', |
836 | 836 | ); |
837 | 837 | // Load all params with a method_modify of the object structure's content_method into $content |
838 | 838 | $content = array(); |
839 | - $structure = $this->get_wordpress_table_structure( 'user' ); |
|
840 | - foreach ( $params as $key => $value ) { |
|
841 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) ) { |
|
842 | - $content[ $key ] = $value['value']; |
|
843 | - unset( $params[ $key ] ); |
|
839 | + $structure = $this->get_wordpress_table_structure('user'); |
|
840 | + foreach ($params as $key => $value) { |
|
841 | + if (in_array($value['method_modify'], $structure['content_methods'])) { |
|
842 | + $content[$key] = $value['value']; |
|
843 | + unset($params[$key]); |
|
844 | 844 | } |
845 | 845 | } |
846 | 846 | |
847 | - $user_id = wp_insert_user( $content ); |
|
847 | + $user_id = wp_insert_user($content); |
|
848 | 848 | |
849 | - if ( is_wp_error( $user_id ) ) { |
|
849 | + if (is_wp_error($user_id)) { |
|
850 | 850 | $success = false; |
851 | 851 | $errors = $user_id; |
852 | 852 | } else { |
853 | 853 | $success = true; |
854 | 854 | $errors = array(); |
855 | - foreach ( $params as $key => $value ) { |
|
855 | + foreach ($params as $key => $value) { |
|
856 | 856 | $method = $value['method_modify']; |
857 | 857 | // we need to provide a way for passing the values in a custom order here |
858 | - $meta_id = $method( $user_id, $key, $value['value'] ); |
|
859 | - if ( false === $meta_id ) { |
|
858 | + $meta_id = $method($user_id, $key, $value['value']); |
|
859 | + if (false === $meta_id) { |
|
860 | 860 | $success = false; |
861 | 861 | $errors[] = array( |
862 | 862 | 'message' => sprintf( |
863 | 863 | // translators: %1$s is a method name. |
864 | - esc_html__( 'Tried to upsert meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
865 | - esc_html( $method ) |
|
864 | + esc_html__('Tried to upsert meta with method %1$s.', 'object-sync-for-salesforce'), |
|
865 | + esc_html($method) |
|
866 | 866 | ), |
867 | 867 | 'key' => $key, |
868 | 868 | 'value' => $value, |
@@ -871,18 +871,18 @@ discard block |
||
871 | 871 | } |
872 | 872 | |
873 | 873 | // Developers can use this hook to set any other user data - permissions, etc. |
874 | - do_action( $this->option_prefix . 'set_more_user_data', $user_id, $params, 'create' ); |
|
874 | + do_action($this->option_prefix . 'set_more_user_data', $user_id, $params, 'create'); |
|
875 | 875 | |
876 | 876 | // Send notification of new user. |
877 | 877 | // todo: Figure out what permissions ought to get notifications for this and make sure it works the right way. |
878 | - wp_new_user_notification( $user_id, null, 'admin user' ); |
|
878 | + wp_new_user_notification($user_id, null, 'admin user'); |
|
879 | 879 | |
880 | 880 | } |
881 | 881 | } else { |
882 | - $user_id = username_exists( $username ); |
|
882 | + $user_id = username_exists($username); |
|
883 | 883 | } // End if(). |
884 | 884 | |
885 | - if ( is_wp_error( $user_id ) ) { |
|
885 | + if (is_wp_error($user_id)) { |
|
886 | 886 | $success = false; |
887 | 887 | $errors = $user_id; |
888 | 888 | } else { |
@@ -919,47 +919,47 @@ discard block |
||
919 | 919 | * success: 1 |
920 | 920 | * "errors" : [ ], |
921 | 921 | */ |
922 | - private function user_upsert( $key, $value, $methods = array(), $params, $id_field = 'ID', $push_drafts = false, $check_only = false ) { |
|
922 | + private function user_upsert($key, $value, $methods = array(), $params, $id_field = 'ID', $push_drafts = false, $check_only = false) { |
|
923 | 923 | |
924 | 924 | // If the key is user_email, we need to make it just email because that is how the WordPress method reads it. |
925 | 925 | $method = $methods['method_match']; |
926 | - if ( '' !== $method ) { |
|
926 | + if ('' !== $method) { |
|
927 | 927 | // This should give us the user object. |
928 | - $user = $method( str_replace( 'user_', '', $key ), $value ); |
|
929 | - if ( isset( $user->{$id_field} ) ) { |
|
928 | + $user = $method(str_replace('user_', '', $key), $value); |
|
929 | + if (isset($user->{$id_field} )) { |
|
930 | 930 | // User does exist after checking the matching value. we want its id. |
931 | 931 | $user_id = $user->{$id_field}; |
932 | 932 | |
933 | - if ( true === $check_only ) { |
|
933 | + if (true === $check_only) { |
|
934 | 934 | // We are just checking to see if there is a match. |
935 | 935 | return $user_id; |
936 | 936 | } |
937 | 937 | |
938 | 938 | // On the prematch fields, we specify the method_update param. |
939 | - if ( isset( $methods['method_update'] ) ) { |
|
939 | + if (isset($methods['method_update'])) { |
|
940 | 940 | $method = $methods['method_update']; |
941 | 941 | } else { |
942 | 942 | $method = $methods['method_modify']; |
943 | 943 | } |
944 | - $params[ $key ] = array( |
|
944 | + $params[$key] = array( |
|
945 | 945 | 'value' => $value, |
946 | 946 | 'method_modify' => $method, |
947 | 947 | 'method_read' => $methods['method_read'], |
948 | 948 | ); |
949 | - } elseif ( false === $check_only ) { |
|
949 | + } elseif (false === $check_only) { |
|
950 | 950 | // User does not exist after checking the matching value. create it. |
951 | 951 | // On the prematch fields, we specify the method_create param. |
952 | - if ( isset( $methods['method_create'] ) ) { |
|
952 | + if (isset($methods['method_create'])) { |
|
953 | 953 | $method = $methods['method_create']; |
954 | 954 | } else { |
955 | 955 | $method = $methods['method_modify']; |
956 | 956 | } |
957 | - $params[ $key ] = array( |
|
957 | + $params[$key] = array( |
|
958 | 958 | 'value' => $value, |
959 | 959 | 'method_modify' => $method, |
960 | 960 | 'method_read' => $methods['method_read'], |
961 | 961 | ); |
962 | - $result = $this->user_create( $params ); |
|
962 | + $result = $this->user_create($params); |
|
963 | 963 | return $result; |
964 | 964 | } else { |
965 | 965 | // Check only is true but there's not a user yet. |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | } // End if(). |
968 | 968 | } else { |
969 | 969 | // There is no method by which to check the user. we can check other ways here. |
970 | - $params[ $key ] = array( |
|
970 | + $params[$key] = array( |
|
971 | 971 | 'value' => $value, |
972 | 972 | 'method_modify' => $methods['method_modify'], |
973 | 973 | 'method_read' => $methods['method_read'], |
@@ -975,21 +975,21 @@ discard block |
||
975 | 975 | |
976 | 976 | // Allow username to be email address or username. |
977 | 977 | // The username could be autogenerated before this point for the sake of URLs. |
978 | - if ( isset( $params['user_email']['value'] ) ) { |
|
978 | + if (isset($params['user_email']['value'])) { |
|
979 | 979 | $username = $params['user_email']['value']; |
980 | 980 | $email_address = $params['user_email']['value']; |
981 | 981 | } |
982 | - if ( isset( $params['user_login']['value'] ) ) { // user_login is used by username_exists. |
|
982 | + if (isset($params['user_login']['value'])) { // user_login is used by username_exists. |
|
983 | 983 | $username = $params['user_login']['value']; |
984 | 984 | } |
985 | 985 | |
986 | - $existing_id = username_exists( $username ); // Returns an id if there is a result. |
|
986 | + $existing_id = username_exists($username); // Returns an id if there is a result. |
|
987 | 987 | |
988 | 988 | // User does not exist after more checking. we want to create it. |
989 | - if ( false === $existing_id && false === $check_only ) { |
|
990 | - $result = $this->user_create( $params ); |
|
989 | + if (false === $existing_id && false === $check_only) { |
|
990 | + $result = $this->user_create($params); |
|
991 | 991 | return $result; |
992 | - } elseif ( true === $check_only ) { |
|
992 | + } elseif (true === $check_only) { |
|
993 | 993 | // We are just checking to see if there is a match. |
994 | 994 | return $existing_id; |
995 | 995 | } else { |
@@ -998,23 +998,23 @@ discard block |
||
998 | 998 | } |
999 | 999 | } // End if(). |
1000 | 1000 | |
1001 | - if ( isset( $user_id ) ) { |
|
1002 | - foreach ( $params as $key => $value ) { |
|
1003 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
1001 | + if (isset($user_id)) { |
|
1002 | + foreach ($params as $key => $value) { |
|
1003 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
1004 | 1004 | } |
1005 | - $result = $this->user_update( $user_id, $params ); |
|
1005 | + $result = $this->user_update($user_id, $params); |
|
1006 | 1006 | return $result; |
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | // Create log entry for lack of a user id. |
1010 | - if ( isset( $this->logging ) ) { |
|
1010 | + if (isset($this->logging)) { |
|
1011 | 1011 | $logging = $this->logging; |
1012 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1013 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1012 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1013 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1014 | 1014 | } |
1015 | 1015 | $logging->setup( |
1016 | 1016 | // todo: can we get any more specific about this? |
1017 | - esc_html__( 'Error: Users: Tried to run user_upsert, and ended up without a user id', 'object-sync-for-salesforce' ), |
|
1017 | + esc_html__('Error: Users: Tried to run user_upsert, and ended up without a user id', 'object-sync-for-salesforce'), |
|
1018 | 1018 | '', |
1019 | 1019 | 0, |
1020 | 1020 | 0, |
@@ -1035,28 +1035,28 @@ discard block |
||
1035 | 1035 | * success: 1 |
1036 | 1036 | * "errors" : [ ], |
1037 | 1037 | */ |
1038 | - private function user_update( $user_id, $params, $id_field = 'ID' ) { |
|
1038 | + private function user_update($user_id, $params, $id_field = 'ID') { |
|
1039 | 1039 | $content = array(); |
1040 | - $content[ $id_field ] = $user_id; |
|
1041 | - foreach ( $params as $key => $value ) { |
|
1042 | - if ( 'wp_update_user' === $value['method_modify'] ) { |
|
1043 | - $content[ $key ] = $value['value']; |
|
1044 | - unset( $params[ $key ] ); |
|
1040 | + $content[$id_field] = $user_id; |
|
1041 | + foreach ($params as $key => $value) { |
|
1042 | + if ('wp_update_user' === $value['method_modify']) { |
|
1043 | + $content[$key] = $value['value']; |
|
1044 | + unset($params[$key]); |
|
1045 | 1045 | } |
1046 | 1046 | } |
1047 | 1047 | |
1048 | - $user_id = wp_update_user( $content ); |
|
1048 | + $user_id = wp_update_user($content); |
|
1049 | 1049 | |
1050 | - if ( is_wp_error( $user_id ) ) { |
|
1050 | + if (is_wp_error($user_id)) { |
|
1051 | 1051 | $success = false; |
1052 | 1052 | $errors = $user_id; |
1053 | 1053 | } else { |
1054 | 1054 | $success = true; |
1055 | 1055 | $errors = array(); |
1056 | - foreach ( $params as $key => $value ) { |
|
1056 | + foreach ($params as $key => $value) { |
|
1057 | 1057 | $method = $value['method_modify']; |
1058 | - $meta_id = $method( $user_id, $key, $value['value'] ); |
|
1059 | - if ( false === $meta_id ) { |
|
1058 | + $meta_id = $method($user_id, $key, $value['value']); |
|
1059 | + if (false === $meta_id) { |
|
1060 | 1060 | $success = false; |
1061 | 1061 | $errors[] = array( |
1062 | 1062 | 'key' => $key, |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | } |
1067 | 1067 | |
1068 | 1068 | // Developers can use this hook to set any other user data - permissions, etc. |
1069 | - do_action( $this->option_prefix . 'set_more_user_data', $user_id, $params, 'update' ); |
|
1069 | + do_action($this->option_prefix . 'set_more_user_data', $user_id, $params, 'update'); |
|
1070 | 1070 | |
1071 | 1071 | } |
1072 | 1072 | |
@@ -1088,10 +1088,10 @@ discard block |
||
1088 | 1088 | * |
1089 | 1089 | * @return boolean true if successful |
1090 | 1090 | */ |
1091 | - private function user_delete( $id, $reassign = null ) { |
|
1091 | + private function user_delete($id, $reassign = null) { |
|
1092 | 1092 | // According to https://codex.wordpress.org/Function_Reference/wp_delete_user we have to include user.php first; otherwise it throws undefined error. |
1093 | - require_once( './wp-admin/includes/user.php' ); |
|
1094 | - $result = wp_delete_user( $id, $reassign ); |
|
1093 | + require_once('./wp-admin/includes/user.php'); |
|
1094 | + $result = wp_delete_user($id, $reassign); |
|
1095 | 1095 | return $result; |
1096 | 1096 | } |
1097 | 1097 | |
@@ -1108,18 +1108,18 @@ discard block |
||
1108 | 1108 | * success: 1 |
1109 | 1109 | * "errors" : [ ], |
1110 | 1110 | */ |
1111 | - private function post_create( $params, $id_field = 'ID', $post_type = 'post' ) { |
|
1111 | + private function post_create($params, $id_field = 'ID', $post_type = 'post') { |
|
1112 | 1112 | // Load all params with a method_modify of the object structure's content_method into $content |
1113 | 1113 | $content = array(); |
1114 | - $structure = $this->get_wordpress_table_structure( $post_type ); |
|
1115 | - foreach ( $params as $key => $value ) { |
|
1116 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) ) { |
|
1117 | - $content[ $key ] = $value['value']; |
|
1118 | - unset( $params[ $key ] ); |
|
1114 | + $structure = $this->get_wordpress_table_structure($post_type); |
|
1115 | + foreach ($params as $key => $value) { |
|
1116 | + if (in_array($value['method_modify'], $structure['content_methods'])) { |
|
1117 | + $content[$key] = $value['value']; |
|
1118 | + unset($params[$key]); |
|
1119 | 1119 | } |
1120 | 1120 | } |
1121 | 1121 | |
1122 | - if ( '' !== $post_type ) { |
|
1122 | + if ('' !== $post_type) { |
|
1123 | 1123 | $content['post_type'] = $post_type; |
1124 | 1124 | } |
1125 | 1125 | |
@@ -1127,31 +1127,31 @@ discard block |
||
1127 | 1127 | // I think we should allow this to happen and not make users' data decisions, so |
1128 | 1128 | // if we're receiving nothing for either of these, create a blank one so it doesn't fail |
1129 | 1129 | // here we have to use $content because $params has already been unset |
1130 | - if ( ! isset( $content['post_title'] ) ) { |
|
1130 | + if ( ! isset($content['post_title'])) { |
|
1131 | 1131 | $content['post_title'] = ' '; |
1132 | 1132 | } |
1133 | - if ( ! isset( $content['post_content'] ) ) { |
|
1133 | + if ( ! isset($content['post_content'])) { |
|
1134 | 1134 | $content['post_content'] = ' '; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - $post_id = wp_insert_post( $content, true ); // return an error instead of a 0 id |
|
1137 | + $post_id = wp_insert_post($content, true); // return an error instead of a 0 id |
|
1138 | 1138 | |
1139 | - if ( is_wp_error( $post_id ) ) { |
|
1139 | + if (is_wp_error($post_id)) { |
|
1140 | 1140 | $success = false; |
1141 | 1141 | $errors = $post_id; |
1142 | 1142 | } else { |
1143 | 1143 | $success = true; |
1144 | 1144 | $errors = array(); |
1145 | 1145 | // If it's a custom post type, fix the methods. |
1146 | - if ( isset( $params['RecordTypeId']['value'] ) ) { |
|
1146 | + if (isset($params['RecordTypeId']['value'])) { |
|
1147 | 1147 | $params['RecordTypeId']['method_modify'] = 'update_post_meta'; |
1148 | 1148 | $params['RecordTypeId']['method_read'] = 'get_post_meta'; |
1149 | 1149 | } |
1150 | - if ( is_array( $params ) && ! empty( $params ) ) { |
|
1151 | - foreach ( $params as $key => $value ) { |
|
1150 | + if (is_array($params) && ! empty($params)) { |
|
1151 | + foreach ($params as $key => $value) { |
|
1152 | 1152 | $method = $value['method_modify']; |
1153 | - $meta_id = $method( $post_id, $key, $value['value'] ); |
|
1154 | - if ( false === $meta_id ) { |
|
1153 | + $meta_id = $method($post_id, $key, $value['value']); |
|
1154 | + if (false === $meta_id) { |
|
1155 | 1155 | $success = false; |
1156 | 1156 | $errors[] = array( |
1157 | 1157 | 'key' => $key, |
@@ -1162,11 +1162,11 @@ discard block |
||
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | // Developers can use this hook to set any other post data. |
1165 | - do_action( $this->option_prefix . 'set_more_post_data', $post_id, $params, 'create' ); |
|
1165 | + do_action($this->option_prefix . 'set_more_post_data', $post_id, $params, 'create'); |
|
1166 | 1166 | |
1167 | 1167 | } |
1168 | 1168 | |
1169 | - if ( is_wp_error( $post_id ) ) { |
|
1169 | + if (is_wp_error($post_id)) { |
|
1170 | 1170 | $success = false; |
1171 | 1171 | $errors = $post_id; |
1172 | 1172 | } else { |
@@ -1204,68 +1204,68 @@ discard block |
||
1204 | 1204 | * success: 1 |
1205 | 1205 | * "errors" : [ ], |
1206 | 1206 | */ |
1207 | - private function post_upsert( $key, $value, $methods = array(), $params, $id_field = 'ID', $push_drafts = false, $post_type = 'post', $check_only = false ) { |
|
1207 | + private function post_upsert($key, $value, $methods = array(), $params, $id_field = 'ID', $push_drafts = false, $post_type = 'post', $check_only = false) { |
|
1208 | 1208 | |
1209 | 1209 | $method = $methods['method_match']; |
1210 | 1210 | |
1211 | - if ( '' !== $method ) { |
|
1211 | + if ('' !== $method) { |
|
1212 | 1212 | // By default, posts use get_posts as the method. args can be like this. |
1213 | 1213 | // The args don't really make sense, and are inconsistently documented. |
1214 | 1214 | // This should give us the post object. |
1215 | 1215 | $args = array(); |
1216 | - if ( 'post_title' === $key ) { |
|
1216 | + if ('post_title' === $key) { |
|
1217 | 1217 | $params['post_title'] = array( |
1218 | 1218 | 'value' => $value, |
1219 | 1219 | 'method_modify' => $method, |
1220 | 1220 | 'method_read' => $methods['method_read'], |
1221 | 1221 | ); |
1222 | - $args['name'] = sanitize_title( $value ); |
|
1222 | + $args['name'] = sanitize_title($value); |
|
1223 | 1223 | } else { |
1224 | - $args[ $key ] = $value; |
|
1224 | + $args[$key] = $value; |
|
1225 | 1225 | } |
1226 | 1226 | $args['post_type'] = $post_type; |
1227 | - $post_statuses = array( 'publish' ); |
|
1228 | - if ( true === $push_drafts ) { |
|
1227 | + $post_statuses = array('publish'); |
|
1228 | + if (true === $push_drafts) { |
|
1229 | 1229 | $post_statuses[] = 'draft'; |
1230 | 1230 | } |
1231 | 1231 | $args['post_status'] = $post_statuses; |
1232 | 1232 | |
1233 | - $posts = $method( $args ); |
|
1233 | + $posts = $method($args); |
|
1234 | 1234 | |
1235 | - if ( isset( $posts[0]->{$id_field} ) ) { |
|
1235 | + if (isset($posts[0]->{$id_field} )) { |
|
1236 | 1236 | // Post does exist after checking the matching value. We want its id. |
1237 | 1237 | $post_id = $posts[0]->{$id_field}; |
1238 | 1238 | |
1239 | - if ( true === $check_only ) { |
|
1239 | + if (true === $check_only) { |
|
1240 | 1240 | // We are just checking to see if there is a match. |
1241 | 1241 | return $post_id; |
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | // On the prematch fields, we specify the method_update param. |
1245 | - if ( isset( $methods['method_update'] ) ) { |
|
1245 | + if (isset($methods['method_update'])) { |
|
1246 | 1246 | $method = $methods['method_update']; |
1247 | 1247 | } else { |
1248 | 1248 | $method = $methods['method_modify']; |
1249 | 1249 | } |
1250 | - $params[ $key ] = array( |
|
1250 | + $params[$key] = array( |
|
1251 | 1251 | 'value' => $value, |
1252 | 1252 | 'method_modify' => $method, |
1253 | 1253 | 'method_read' => $methods['method_read'], |
1254 | 1254 | ); |
1255 | - } elseif ( false === $check_only ) { |
|
1255 | + } elseif (false === $check_only) { |
|
1256 | 1256 | // Post does not exist after checking the matching value. create it. |
1257 | 1257 | // On the prematch fields, we specify the method_create param. |
1258 | - if ( isset( $methods['method_create'] ) ) { |
|
1258 | + if (isset($methods['method_create'])) { |
|
1259 | 1259 | $method = $methods['method_create']; |
1260 | 1260 | } else { |
1261 | 1261 | $method = $methods['method_modify']; |
1262 | 1262 | } |
1263 | - $params[ $key ] = array( |
|
1263 | + $params[$key] = array( |
|
1264 | 1264 | 'value' => $value, |
1265 | 1265 | 'method_modify' => $method, |
1266 | 1266 | 'method_read' => $methods['method_read'], |
1267 | 1267 | ); |
1268 | - $result = $this->post_create( $params, $id_field, $post_type ); |
|
1268 | + $result = $this->post_create($params, $id_field, $post_type); |
|
1269 | 1269 | return $result; |
1270 | 1270 | } else { |
1271 | 1271 | // Check only is true but there's not a post yet. |
@@ -1273,38 +1273,38 @@ discard block |
||
1273 | 1273 | } // End if(). |
1274 | 1274 | } else { |
1275 | 1275 | // There is no method by which to check the post. we can check other ways here. |
1276 | - $params[ $key ] = array( |
|
1276 | + $params[$key] = array( |
|
1277 | 1277 | 'value' => $value, |
1278 | 1278 | 'method_modify' => $methods['method_modify'], |
1279 | 1279 | 'method_read' => $methods['method_read'], |
1280 | 1280 | ); |
1281 | 1281 | |
1282 | 1282 | // If we have a title, use it to check for existing post. |
1283 | - if ( isset( $params['post_title']['value'] ) ) { |
|
1283 | + if (isset($params['post_title']['value'])) { |
|
1284 | 1284 | $title = $params['post_title']['value']; |
1285 | 1285 | } |
1286 | 1286 | |
1287 | 1287 | // If we have content, use it to check for existing post. |
1288 | - if ( isset( $params['post_content']['value'] ) ) { |
|
1288 | + if (isset($params['post_content']['value'])) { |
|
1289 | 1289 | $content = $params['post_content']['value']; |
1290 | 1290 | } else { |
1291 | 1291 | $content = ''; |
1292 | 1292 | } |
1293 | 1293 | |
1294 | 1294 | // If we have a date, use it to check for existing post. |
1295 | - if ( isset( $params['post_date']['value'] ) ) { |
|
1295 | + if (isset($params['post_date']['value'])) { |
|
1296 | 1296 | $date = $params['post_date']['value']; |
1297 | 1297 | } else { |
1298 | 1298 | $date = ''; |
1299 | 1299 | } |
1300 | 1300 | |
1301 | - $existing_id = post_exists( $title, $content, $date ); // Returns an id if there is a result. Returns 0 if not. |
|
1301 | + $existing_id = post_exists($title, $content, $date); // Returns an id if there is a result. Returns 0 if not. |
|
1302 | 1302 | |
1303 | 1303 | // Post does not exist after more checking. maybe we want to create it. |
1304 | - if ( 0 === $existing_id && false === $check_only ) { |
|
1305 | - $result = $this->post_create( $params, $id_field, $post_type ); |
|
1304 | + if (0 === $existing_id && false === $check_only) { |
|
1305 | + $result = $this->post_create($params, $id_field, $post_type); |
|
1306 | 1306 | return $result; |
1307 | - } elseif ( true === $check_only ) { |
|
1307 | + } elseif (true === $check_only) { |
|
1308 | 1308 | // We are just checking to see if there is a match. |
1309 | 1309 | return $existing_id; |
1310 | 1310 | } else { |
@@ -1316,22 +1316,22 @@ discard block |
||
1316 | 1316 | |
1317 | 1317 | } // End if(). |
1318 | 1318 | |
1319 | - if ( isset( $post_id ) ) { |
|
1320 | - foreach ( $params as $key => $value ) { |
|
1321 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
1319 | + if (isset($post_id)) { |
|
1320 | + foreach ($params as $key => $value) { |
|
1321 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
1322 | 1322 | } |
1323 | - $result = $this->post_update( $post_id, $params, $id_field, $post_type ); |
|
1323 | + $result = $this->post_update($post_id, $params, $id_field, $post_type); |
|
1324 | 1324 | return $result; |
1325 | 1325 | } |
1326 | 1326 | // Create log entry for lack of a post id. |
1327 | - if ( isset( $this->logging ) ) { |
|
1327 | + if (isset($this->logging)) { |
|
1328 | 1328 | $logging = $this->logging; |
1329 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1330 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1329 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1330 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1331 | 1331 | } |
1332 | 1332 | $logging->setup( |
1333 | 1333 | // todo: can we be more explicit here about what post upsert failed? |
1334 | - esc_html__( 'Error: Posts: Tried to run post_upsert, and ended up without a post id', 'object-sync-for-salesforce' ), |
|
1334 | + esc_html__('Error: Posts: Tried to run post_upsert, and ended up without a post id', 'object-sync-for-salesforce'), |
|
1335 | 1335 | '', |
1336 | 1336 | 0, |
1337 | 1337 | 0, |
@@ -1353,38 +1353,38 @@ discard block |
||
1353 | 1353 | * success: 1 |
1354 | 1354 | * "errors" : [ ], |
1355 | 1355 | */ |
1356 | - private function post_update( $post_id, $params, $id_field = 'ID', $post_type = '' ) { |
|
1356 | + private function post_update($post_id, $params, $id_field = 'ID', $post_type = '') { |
|
1357 | 1357 | $content = array(); |
1358 | - $content[ $id_field ] = $post_id; |
|
1359 | - foreach ( $params as $key => $value ) { |
|
1360 | - if ( 'wp_update_post' === $value['method_modify'] ) { |
|
1361 | - $content[ $key ] = $value['value']; |
|
1362 | - unset( $params[ $key ] ); |
|
1358 | + $content[$id_field] = $post_id; |
|
1359 | + foreach ($params as $key => $value) { |
|
1360 | + if ('wp_update_post' === $value['method_modify']) { |
|
1361 | + $content[$key] = $value['value']; |
|
1362 | + unset($params[$key]); |
|
1363 | 1363 | } |
1364 | 1364 | } |
1365 | 1365 | |
1366 | - if ( '' !== $post_type ) { |
|
1366 | + if ('' !== $post_type) { |
|
1367 | 1367 | $content['post_type'] = $post_type; |
1368 | 1368 | } |
1369 | 1369 | |
1370 | - $post_id = wp_update_post( $content, true ); // return an error instead of a 0 id |
|
1370 | + $post_id = wp_update_post($content, true); // return an error instead of a 0 id |
|
1371 | 1371 | |
1372 | - if ( is_wp_error( $post_id ) ) { |
|
1372 | + if (is_wp_error($post_id)) { |
|
1373 | 1373 | $success = false; |
1374 | 1374 | $errors = $post_id; |
1375 | 1375 | } else { |
1376 | 1376 | $success = true; |
1377 | 1377 | $errors = array(); |
1378 | 1378 | // If it's a custom post type, fix the methods. |
1379 | - if ( isset( $params['RecordTypeId']['value'] ) ) { |
|
1379 | + if (isset($params['RecordTypeId']['value'])) { |
|
1380 | 1380 | $params['RecordTypeId']['method_modify'] = 'update_post_meta'; |
1381 | 1381 | $params['RecordTypeId']['method_read'] = 'get_post_meta'; |
1382 | 1382 | } |
1383 | - if ( is_array( $params ) && ! empty( $params ) ) { |
|
1384 | - foreach ( $params as $key => $value ) { |
|
1383 | + if (is_array($params) && ! empty($params)) { |
|
1384 | + foreach ($params as $key => $value) { |
|
1385 | 1385 | $method = $value['method_modify']; |
1386 | - $meta_id = $method( $post_id, $key, $value['value'] ); |
|
1387 | - if ( false === $meta_id ) { |
|
1386 | + $meta_id = $method($post_id, $key, $value['value']); |
|
1387 | + if (false === $meta_id) { |
|
1388 | 1388 | $success = false; |
1389 | 1389 | $errors[] = array( |
1390 | 1390 | 'key' => $key, |
@@ -1395,7 +1395,7 @@ discard block |
||
1395 | 1395 | } |
1396 | 1396 | |
1397 | 1397 | // Developers can use this hook to set any other post data. |
1398 | - do_action( $this->option_prefix . 'set_more_post_data', $post_id, $params, 'update' ); |
|
1398 | + do_action($this->option_prefix . 'set_more_post_data', $post_id, $params, 'update'); |
|
1399 | 1399 | |
1400 | 1400 | } |
1401 | 1401 | |
@@ -1417,8 +1417,8 @@ discard block |
||
1417 | 1417 | * |
1418 | 1418 | * @return mixed post object if successful, false if failed |
1419 | 1419 | */ |
1420 | - private function post_delete( $id, $force_delete = false ) { |
|
1421 | - $result = wp_delete_post( $id, $force_delete ); |
|
1420 | + private function post_delete($id, $force_delete = false) { |
|
1421 | + $result = wp_delete_post($id, $force_delete); |
|
1422 | 1422 | return $result; |
1423 | 1423 | } |
1424 | 1424 | |
@@ -1434,56 +1434,56 @@ discard block |
||
1434 | 1434 | * success: 1 |
1435 | 1435 | * "errors" : [ ], |
1436 | 1436 | */ |
1437 | - private function attachment_create( $params, $id_field = 'ID' ) { |
|
1437 | + private function attachment_create($params, $id_field = 'ID') { |
|
1438 | 1438 | // Load all params with a method_modify of the object structure's content_method into $content |
1439 | 1439 | $content = array(); |
1440 | - $structure = $this->get_wordpress_table_structure( 'attachment' ); |
|
1440 | + $structure = $this->get_wordpress_table_structure('attachment'); |
|
1441 | 1441 | // WP requires post_title, post_content (can be empty), post_status, and post_mime_type to create an attachment. |
1442 | - foreach ( $params as $key => $value ) { |
|
1443 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) ) { |
|
1444 | - $content[ $key ] = $value['value']; |
|
1445 | - unset( $params[ $key ] ); |
|
1442 | + foreach ($params as $key => $value) { |
|
1443 | + if (in_array($value['method_modify'], $structure['content_methods'])) { |
|
1444 | + $content[$key] = $value['value']; |
|
1445 | + unset($params[$key]); |
|
1446 | 1446 | } |
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | // Developers can use this hook to pass filename and parent data for the attachment. |
1450 | - $params = apply_filters( $this->option_prefix . 'set_initial_attachment_data', $params ); |
|
1450 | + $params = apply_filters($this->option_prefix . 'set_initial_attachment_data', $params); |
|
1451 | 1451 | |
1452 | - if ( isset( $params['filename']['value'] ) ) { |
|
1452 | + if (isset($params['filename']['value'])) { |
|
1453 | 1453 | $filename = $params['filename']['value']; |
1454 | 1454 | } else { |
1455 | 1455 | $filename = false; |
1456 | 1456 | } |
1457 | 1457 | |
1458 | - if ( isset( $params['parent']['value'] ) ) { |
|
1458 | + if (isset($params['parent']['value'])) { |
|
1459 | 1459 | $parent = $params['parent']['value']; |
1460 | 1460 | } else { |
1461 | 1461 | $parent = 0; |
1462 | 1462 | } |
1463 | 1463 | |
1464 | - $attachment_id = wp_insert_attachment( $content, $filename, $parent ); |
|
1464 | + $attachment_id = wp_insert_attachment($content, $filename, $parent); |
|
1465 | 1465 | |
1466 | - if ( is_wp_error( $attachment_id ) ) { |
|
1466 | + if (is_wp_error($attachment_id)) { |
|
1467 | 1467 | $success = false; |
1468 | 1468 | $errors = $attachment_id; |
1469 | 1469 | } else { |
1470 | 1470 | $success = true; |
1471 | 1471 | $errors = array(); |
1472 | 1472 | |
1473 | - if ( false !== $filename ) { |
|
1473 | + if (false !== $filename) { |
|
1474 | 1474 | // According to https://codex.wordpress.org/Function_Reference/wp_insert_attachment we need this file. |
1475 | - require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
1475 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1476 | 1476 | // Generate metadata for the attachment. |
1477 | - $attach_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
1478 | - wp_update_attachment_metadata( $attachment_id, $attach_data ); |
|
1477 | + $attach_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
1478 | + wp_update_attachment_metadata($attachment_id, $attach_data); |
|
1479 | 1479 | } |
1480 | 1480 | |
1481 | - if ( 0 !== $parent ) { |
|
1482 | - set_post_thumbnail( $parent_post_id, $attachment_id ); |
|
1481 | + if (0 !== $parent) { |
|
1482 | + set_post_thumbnail($parent_post_id, $attachment_id); |
|
1483 | 1483 | } |
1484 | 1484 | |
1485 | 1485 | // Developers can use this hook to set any other attachment data. |
1486 | - do_action( $this->option_prefix . 'set_more_attachment_data', $attachment_id, $params, 'create' ); |
|
1486 | + do_action($this->option_prefix . 'set_more_attachment_data', $attachment_id, $params, 'create'); |
|
1487 | 1487 | |
1488 | 1488 | } |
1489 | 1489 | |
@@ -1515,64 +1515,64 @@ discard block |
||
1515 | 1515 | * success: 1 |
1516 | 1516 | * "errors" : [ ], |
1517 | 1517 | */ |
1518 | - private function attachment_upsert( $key, $value, $methods = array(), $params, $id_field = 'ID', $check_only = false ) { |
|
1518 | + private function attachment_upsert($key, $value, $methods = array(), $params, $id_field = 'ID', $check_only = false) { |
|
1519 | 1519 | |
1520 | 1520 | $method = $methods['method_match']; |
1521 | 1521 | |
1522 | - if ( '' !== $method ) { |
|
1522 | + if ('' !== $method) { |
|
1523 | 1523 | // Get_posts is more helpful here, so that is the method attachment uses for 'read'. |
1524 | 1524 | // By default, posts use get_posts as the method. args can be like this. |
1525 | 1525 | // The args don't really make sense, and are inconsistently documented. |
1526 | 1526 | // This should give us the post object. |
1527 | 1527 | $args = array(); |
1528 | - if ( 'post_title' === $key ) { |
|
1528 | + if ('post_title' === $key) { |
|
1529 | 1529 | $params['post_title'] = array( |
1530 | 1530 | 'value' => $value, |
1531 | 1531 | 'method_modify' => $method, |
1532 | 1532 | 'method_read' => $methods['method_read'], |
1533 | 1533 | ); |
1534 | - $args['name'] = sanitize_title( $value ); |
|
1534 | + $args['name'] = sanitize_title($value); |
|
1535 | 1535 | } else { |
1536 | - $args[ $key ] = $value; |
|
1536 | + $args[$key] = $value; |
|
1537 | 1537 | } |
1538 | 1538 | $args['post_type'] = 'attachment'; |
1539 | 1539 | |
1540 | - $posts = $method( $args ); |
|
1540 | + $posts = $method($args); |
|
1541 | 1541 | |
1542 | - if ( isset( $posts[0]->{$id_field} ) ) { |
|
1542 | + if (isset($posts[0]->{$id_field} )) { |
|
1543 | 1543 | // Attachment does exist after checking the matching value. we want its id. |
1544 | 1544 | $attachment_id = $posts[0]->{$id_field}; |
1545 | 1545 | |
1546 | - if ( true === $check_only ) { |
|
1546 | + if (true === $check_only) { |
|
1547 | 1547 | // We are just checking to see if there is a match. |
1548 | 1548 | return $attachment_id; |
1549 | 1549 | } |
1550 | 1550 | |
1551 | 1551 | // On the prematch fields, we specify the method_update param. |
1552 | - if ( isset( $methods['method_update'] ) ) { |
|
1552 | + if (isset($methods['method_update'])) { |
|
1553 | 1553 | $method = $methods['method_update']; |
1554 | 1554 | } else { |
1555 | 1555 | $method = $methods['method_modify']; |
1556 | 1556 | } |
1557 | - $params[ $key ] = array( |
|
1557 | + $params[$key] = array( |
|
1558 | 1558 | 'value' => $value, |
1559 | 1559 | 'method_modify' => $method, |
1560 | 1560 | 'method_read' => $methods['method_read'], |
1561 | 1561 | ); |
1562 | - } elseif ( false === $check_only ) { |
|
1562 | + } elseif (false === $check_only) { |
|
1563 | 1563 | // Attachment does not exist after checking the matching value. create it. |
1564 | 1564 | // On the prematch fields, we specify the method_create param. |
1565 | - if ( isset( $methods['method_create'] ) ) { |
|
1565 | + if (isset($methods['method_create'])) { |
|
1566 | 1566 | $method = $methods['method_create']; |
1567 | 1567 | } else { |
1568 | 1568 | $method = $methods['method_modify']; |
1569 | 1569 | } |
1570 | - $params[ $key ] = array( |
|
1570 | + $params[$key] = array( |
|
1571 | 1571 | 'value' => $value, |
1572 | 1572 | 'method_modify' => $method, |
1573 | 1573 | 'method_read' => $methods['method_read'], |
1574 | 1574 | ); |
1575 | - $result = $this->attachment_create( $params ); |
|
1575 | + $result = $this->attachment_create($params); |
|
1576 | 1576 | return $result; |
1577 | 1577 | } else { |
1578 | 1578 | // Check only is true but there's not an attachment yet. |
@@ -1580,38 +1580,38 @@ discard block |
||
1580 | 1580 | } // End if(). |
1581 | 1581 | } else { |
1582 | 1582 | // There is no method by which to check the post. we can check other ways here. |
1583 | - $params[ $key ] = array( |
|
1583 | + $params[$key] = array( |
|
1584 | 1584 | 'value' => $value, |
1585 | 1585 | 'method_modify' => $methods['method_modify'], |
1586 | 1586 | 'method_read' => $methods['method_read'], |
1587 | 1587 | ); |
1588 | 1588 | |
1589 | 1589 | // If we have a title, use it to check for existing post. |
1590 | - if ( isset( $params['post_title']['value'] ) ) { |
|
1590 | + if (isset($params['post_title']['value'])) { |
|
1591 | 1591 | $title = $params['post_title']['value']; |
1592 | 1592 | } |
1593 | 1593 | |
1594 | 1594 | // If we have content, use it to check for existing post. |
1595 | - if ( isset( $params['post_content']['value'] ) ) { |
|
1595 | + if (isset($params['post_content']['value'])) { |
|
1596 | 1596 | $content = $params['post_content']['value']; |
1597 | 1597 | } else { |
1598 | 1598 | $content = ''; |
1599 | 1599 | } |
1600 | 1600 | |
1601 | 1601 | // If we have a date, use it to check for existing post. |
1602 | - if ( isset( $params['post_date']['value'] ) ) { |
|
1602 | + if (isset($params['post_date']['value'])) { |
|
1603 | 1603 | $date = $params['post_date']['value']; |
1604 | 1604 | } else { |
1605 | 1605 | $date = ''; |
1606 | 1606 | } |
1607 | 1607 | |
1608 | - $existing_id = post_exists( $title, $content, $date ); // Returns an id if there is a result. Returns 0 if not. |
|
1608 | + $existing_id = post_exists($title, $content, $date); // Returns an id if there is a result. Returns 0 if not. |
|
1609 | 1609 | |
1610 | 1610 | // Attachment does not exist after more checking. maybe we want to create it. |
1611 | - if ( 0 === $existing_id && false === $check_only ) { |
|
1612 | - $result = $this->attachment_create( $params ); |
|
1611 | + if (0 === $existing_id && false === $check_only) { |
|
1612 | + $result = $this->attachment_create($params); |
|
1613 | 1613 | return $result; |
1614 | - } elseif ( true === $check_only ) { |
|
1614 | + } elseif (true === $check_only) { |
|
1615 | 1615 | // We are just checking to see if there is a match. |
1616 | 1616 | return $existing_id; |
1617 | 1617 | } else { |
@@ -1623,22 +1623,22 @@ discard block |
||
1623 | 1623 | |
1624 | 1624 | } // End if(). |
1625 | 1625 | |
1626 | - if ( isset( $attachment_id ) ) { |
|
1627 | - foreach ( $params as $key => $value ) { |
|
1628 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
1626 | + if (isset($attachment_id)) { |
|
1627 | + foreach ($params as $key => $value) { |
|
1628 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
1629 | 1629 | } |
1630 | - $result = $this->attachment_update( $attachment_id, $params ); |
|
1630 | + $result = $this->attachment_update($attachment_id, $params); |
|
1631 | 1631 | return $result; |
1632 | 1632 | } |
1633 | 1633 | |
1634 | 1634 | // Create log entry for lack of an attachment id. |
1635 | - if ( isset( $this->logging ) ) { |
|
1635 | + if (isset($this->logging)) { |
|
1636 | 1636 | $logging = $this->logging; |
1637 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1638 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1637 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1638 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1639 | 1639 | } |
1640 | 1640 | $logging->setup( |
1641 | - esc_html__( 'Error: Attachment: Tried to run attachment_upsert, and ended up without an attachment id', 'object-sync-for-salesforce' ), |
|
1641 | + esc_html__('Error: Attachment: Tried to run attachment_upsert, and ended up without an attachment id', 'object-sync-for-salesforce'), |
|
1642 | 1642 | '', |
1643 | 1643 | 0, |
1644 | 1644 | 0, |
@@ -1663,60 +1663,60 @@ discard block |
||
1663 | 1663 | * it does use wp_update_attachment_metadata for the meta fields, though. |
1664 | 1664 | * Developers should use hooks to change this, if it does not meet their needs. |
1665 | 1665 | */ |
1666 | - private function attachment_update( $attachment_id, $params, $id_field = 'ID' ) { |
|
1666 | + private function attachment_update($attachment_id, $params, $id_field = 'ID') { |
|
1667 | 1667 | $content = array(); |
1668 | - $content[ $id_field ] = $attachment_id; |
|
1669 | - foreach ( $params as $key => $value ) { |
|
1670 | - if ( 'wp_insert_attachment' === $value['method_modify'] ) { // Should also be insert attachment maybe. |
|
1671 | - $content[ $key ] = $value['value']; |
|
1672 | - unset( $params[ $key ] ); |
|
1668 | + $content[$id_field] = $attachment_id; |
|
1669 | + foreach ($params as $key => $value) { |
|
1670 | + if ('wp_insert_attachment' === $value['method_modify']) { // Should also be insert attachment maybe. |
|
1671 | + $content[$key] = $value['value']; |
|
1672 | + unset($params[$key]); |
|
1673 | 1673 | } |
1674 | 1674 | } |
1675 | 1675 | |
1676 | - if ( isset( $params['filename']['value'] ) ) { |
|
1676 | + if (isset($params['filename']['value'])) { |
|
1677 | 1677 | $filename = $params['filename']['value']; |
1678 | 1678 | } else { |
1679 | 1679 | $filename = false; |
1680 | 1680 | } |
1681 | 1681 | |
1682 | - if ( isset( $params['parent']['value'] ) ) { |
|
1682 | + if (isset($params['parent']['value'])) { |
|
1683 | 1683 | $parent = $params['parent']['value']; |
1684 | 1684 | } else { |
1685 | 1685 | $parent = 0; |
1686 | 1686 | } |
1687 | 1687 | |
1688 | - $attachment_id = wp_insert_attachment( $content, $filename, $parent ); |
|
1688 | + $attachment_id = wp_insert_attachment($content, $filename, $parent); |
|
1689 | 1689 | |
1690 | - if ( is_wp_error( $attachment_id ) ) { |
|
1690 | + if (is_wp_error($attachment_id)) { |
|
1691 | 1691 | $success = false; |
1692 | 1692 | $errors = $attachment_id; |
1693 | 1693 | } else { |
1694 | 1694 | $success = true; |
1695 | 1695 | $errors = array(); |
1696 | 1696 | |
1697 | - if ( false !== $filename ) { |
|
1697 | + if (false !== $filename) { |
|
1698 | 1698 | // According to https://codex.wordpress.org/Function_Reference/wp_insert_attachment we need this file. |
1699 | - require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
1699 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1700 | 1700 | // Generate metadata for the attachment. |
1701 | - $attach_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
1701 | + $attach_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
1702 | 1702 | } |
1703 | 1703 | |
1704 | 1704 | // Put the data from salesforce into the meta array. |
1705 | 1705 | $attach_new_data = array(); |
1706 | - foreach ( $params as $key => $value ) { |
|
1706 | + foreach ($params as $key => $value) { |
|
1707 | 1707 | $method = $value['method_modify']; |
1708 | - $attach_new_data[ $key ] = $value['value']; |
|
1708 | + $attach_new_data[$key] = $value['value']; |
|
1709 | 1709 | } |
1710 | 1710 | |
1711 | - if ( isset( $attach_data ) ) { |
|
1712 | - $attach_data = array_merge( $attach_data, $attach_new_data ); |
|
1711 | + if (isset($attach_data)) { |
|
1712 | + $attach_data = array_merge($attach_data, $attach_new_data); |
|
1713 | 1713 | } else { |
1714 | 1714 | $attach_data = $attach_new_data; |
1715 | 1715 | } |
1716 | 1716 | |
1717 | - $meta_updated = wp_update_attachment_metadata( $attachment_id, $attach_data ); |
|
1717 | + $meta_updated = wp_update_attachment_metadata($attachment_id, $attach_data); |
|
1718 | 1718 | |
1719 | - if ( false === $meta_updated ) { |
|
1719 | + if (false === $meta_updated) { |
|
1720 | 1720 | $success = false; |
1721 | 1721 | $errors[] = array( |
1722 | 1722 | 'key' => $key, |
@@ -1724,12 +1724,12 @@ discard block |
||
1724 | 1724 | ); |
1725 | 1725 | } |
1726 | 1726 | |
1727 | - if ( 0 !== $parent ) { |
|
1728 | - set_post_thumbnail( $parent_post_id, $attachment_id ); |
|
1727 | + if (0 !== $parent) { |
|
1728 | + set_post_thumbnail($parent_post_id, $attachment_id); |
|
1729 | 1729 | } |
1730 | 1730 | |
1731 | 1731 | // Developers can use this hook to set any other attachment data. |
1732 | - do_action( $this->option_prefix . 'set_more_attachment_data', $attachment_id, $params, 'update' ); |
|
1732 | + do_action($this->option_prefix . 'set_more_attachment_data', $attachment_id, $params, 'update'); |
|
1733 | 1733 | |
1734 | 1734 | } // End if(). |
1735 | 1735 | |
@@ -1752,8 +1752,8 @@ discard block |
||
1752 | 1752 | * @return mixed |
1753 | 1753 | * attachment object if successful, false if failed |
1754 | 1754 | */ |
1755 | - private function attachment_delete( $id, $force_delete = false ) { |
|
1756 | - $result = wp_delete_attachment( $id, $force_delete ); |
|
1755 | + private function attachment_delete($id, $force_delete = false) { |
|
1756 | + $result = wp_delete_attachment($id, $force_delete); |
|
1757 | 1757 | return $result; |
1758 | 1758 | } |
1759 | 1759 | |
@@ -1770,45 +1770,45 @@ discard block |
||
1770 | 1770 | * success: 1 |
1771 | 1771 | * "errors" : [ ], |
1772 | 1772 | */ |
1773 | - private function term_create( $params, $taxonomy, $id_field = 'ID' ) { |
|
1774 | - if ( 'tag' === $taxonomy ) { |
|
1773 | + private function term_create($params, $taxonomy, $id_field = 'ID') { |
|
1774 | + if ('tag' === $taxonomy) { |
|
1775 | 1775 | $taxonomy = 'post_tag'; |
1776 | 1776 | } |
1777 | 1777 | // Load all params with a method_modify of the object structure's content_method into $content |
1778 | 1778 | $content = array(); |
1779 | - $structure = $this->get_wordpress_table_structure( $taxonomy ); |
|
1779 | + $structure = $this->get_wordpress_table_structure($taxonomy); |
|
1780 | 1780 | $args = array(); |
1781 | - foreach ( $params as $key => $value ) { |
|
1782 | - if ( 'name' === $key ) { |
|
1781 | + foreach ($params as $key => $value) { |
|
1782 | + if ('name' === $key) { |
|
1783 | 1783 | $name = $value['value']; |
1784 | - unset( $params[ $key ] ); |
|
1784 | + unset($params[$key]); |
|
1785 | 1785 | } |
1786 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) && 'name' !== $key ) { |
|
1787 | - $args[ $key ] = $value['value']; |
|
1788 | - unset( $params[ $key ] ); |
|
1786 | + if (in_array($value['method_modify'], $structure['content_methods']) && 'name' !== $key) { |
|
1787 | + $args[$key] = $value['value']; |
|
1788 | + unset($params[$key]); |
|
1789 | 1789 | } |
1790 | 1790 | } |
1791 | - if ( isset( $name ) ) { |
|
1792 | - $term = wp_insert_term( $name, $taxonomy, $args ); |
|
1791 | + if (isset($name)) { |
|
1792 | + $term = wp_insert_term($name, $taxonomy, $args); |
|
1793 | 1793 | } |
1794 | 1794 | |
1795 | - if ( is_wp_error( $term ) ) { |
|
1795 | + if (is_wp_error($term)) { |
|
1796 | 1796 | $success = false; |
1797 | 1797 | $errors = $term; |
1798 | 1798 | } else { |
1799 | - $term_id = $term[ "$id_field" ]; |
|
1799 | + $term_id = $term["$id_field"]; |
|
1800 | 1800 | $success = true; |
1801 | 1801 | $errors = array(); |
1802 | - foreach ( $params as $key => $value ) { |
|
1802 | + foreach ($params as $key => $value) { |
|
1803 | 1803 | $method = $value['method_modify']; |
1804 | - $meta_id = $method( $term_id, $key, $value['value'] ); |
|
1805 | - if ( false === $meta_id ) { |
|
1804 | + $meta_id = $method($term_id, $key, $value['value']); |
|
1805 | + if (false === $meta_id) { |
|
1806 | 1806 | $success = false; |
1807 | 1807 | $errors[] = array( |
1808 | 1808 | 'message' => sprintf( |
1809 | 1809 | // translators: %1$s is a method name. |
1810 | - esc_html__( 'Tried to upsert meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
1811 | - esc_html( $method ) |
|
1810 | + esc_html__('Tried to upsert meta with method %1$s.', 'object-sync-for-salesforce'), |
|
1811 | + esc_html($method) |
|
1812 | 1812 | ), |
1813 | 1813 | 'key' => $key, |
1814 | 1814 | 'value' => $value, |
@@ -1817,11 +1817,11 @@ discard block |
||
1817 | 1817 | } |
1818 | 1818 | |
1819 | 1819 | // Developers can use this hook to set any other term data. |
1820 | - do_action( $this->option_prefix . 'set_more_term_data', $term_id, $params, 'create' ); |
|
1820 | + do_action($this->option_prefix . 'set_more_term_data', $term_id, $params, 'create'); |
|
1821 | 1821 | |
1822 | 1822 | } |
1823 | 1823 | |
1824 | - if ( is_wp_error( $term ) ) { |
|
1824 | + if (is_wp_error($term)) { |
|
1825 | 1825 | $success = false; |
1826 | 1826 | $errors = $term; |
1827 | 1827 | } else { |
@@ -1859,48 +1859,48 @@ discard block |
||
1859 | 1859 | * success: 1 |
1860 | 1860 | * "errors" : [ ], |
1861 | 1861 | */ |
1862 | - private function term_upsert( $key, $value, $methods = array(), $params, $taxonomy, $id_field = 'ID', $push_drafts = false, $check_only = false ) { |
|
1863 | - if ( 'tag' === $taxonomy ) { |
|
1862 | + private function term_upsert($key, $value, $methods = array(), $params, $taxonomy, $id_field = 'ID', $push_drafts = false, $check_only = false) { |
|
1863 | + if ('tag' === $taxonomy) { |
|
1864 | 1864 | $taxonomy = 'post_tag'; |
1865 | 1865 | } |
1866 | 1866 | $method = $methods['method_match']; |
1867 | - if ( '' !== $method ) { |
|
1867 | + if ('' !== $method) { |
|
1868 | 1868 | // This should give us the term object. |
1869 | - $term = $method( $key, $value, $taxonomy ); // We need to put the taxonomy in there probably. |
|
1870 | - if ( isset( $term->{$id_field} ) ) { |
|
1869 | + $term = $method($key, $value, $taxonomy); // We need to put the taxonomy in there probably. |
|
1870 | + if (isset($term->{$id_field} )) { |
|
1871 | 1871 | // Term does exist after checking the matching value. we want its id. |
1872 | 1872 | $term_id = $term->{$id_field}; |
1873 | 1873 | |
1874 | - if ( true === $check_only ) { |
|
1874 | + if (true === $check_only) { |
|
1875 | 1875 | // We are just checking to see if there is a match. |
1876 | 1876 | return $term_id; |
1877 | 1877 | } |
1878 | 1878 | |
1879 | 1879 | // On the prematch fields, we specify the method_update param. |
1880 | - if ( isset( $methods['method_update'] ) ) { |
|
1880 | + if (isset($methods['method_update'])) { |
|
1881 | 1881 | $method = $methods['method_update']; |
1882 | 1882 | } else { |
1883 | 1883 | $method = $methods['method_modify']; |
1884 | 1884 | } |
1885 | - $params[ $key ] = array( |
|
1885 | + $params[$key] = array( |
|
1886 | 1886 | 'value' => $value, |
1887 | 1887 | 'method_modify' => $method, |
1888 | 1888 | 'method_read' => $methods['method_read'], |
1889 | 1889 | ); |
1890 | - } elseif ( false === $check_only ) { |
|
1890 | + } elseif (false === $check_only) { |
|
1891 | 1891 | // Term does not exist after checking the matching value. Create it. |
1892 | 1892 | // On the prematch fields, we specify the method_create param. |
1893 | - if ( isset( $methods['method_create'] ) ) { |
|
1893 | + if (isset($methods['method_create'])) { |
|
1894 | 1894 | $method = $methods['method_create']; |
1895 | 1895 | } else { |
1896 | 1896 | $method = $methods['method_modify']; |
1897 | 1897 | } |
1898 | - $params[ $key ] = array( |
|
1898 | + $params[$key] = array( |
|
1899 | 1899 | 'value' => $value, |
1900 | 1900 | 'method_modify' => $method, |
1901 | 1901 | 'method_read' => $methods['method_read'], |
1902 | 1902 | ); |
1903 | - $result = $this->term_create( $params, $taxonomy, $id_field ); |
|
1903 | + $result = $this->term_create($params, $taxonomy, $id_field); |
|
1904 | 1904 | return $result; |
1905 | 1905 | } else { |
1906 | 1906 | // Check only is true but there's not a term yet. |
@@ -1908,17 +1908,17 @@ discard block |
||
1908 | 1908 | } // End if(). |
1909 | 1909 | } else { |
1910 | 1910 | // There is no method by which to check the term. we can check other ways here. |
1911 | - $params[ $key ] = array( |
|
1911 | + $params[$key] = array( |
|
1912 | 1912 | 'value' => $value, |
1913 | 1913 | 'method_modify' => $methods['method_modify'], |
1914 | 1914 | 'method_read' => $methods['method_read'], |
1915 | 1915 | ); |
1916 | 1916 | |
1917 | - if ( isset( $params['name']['value'] ) ) { |
|
1917 | + if (isset($params['name']['value'])) { |
|
1918 | 1918 | $term = $params['name']['value']; |
1919 | 1919 | } |
1920 | 1920 | |
1921 | - if ( isset( $params['parent']['value'] ) ) { |
|
1921 | + if (isset($params['parent']['value'])) { |
|
1922 | 1922 | $parent = $params['parent']['value']; |
1923 | 1923 | } else { |
1924 | 1924 | $parent = 0; |
@@ -1926,17 +1926,17 @@ discard block |
||
1926 | 1926 | |
1927 | 1927 | // Returns an id if there is a result. Returns null if it does not exist. |
1928 | 1928 | // wpcom_vip_term_exists is cached, and therefore preferred. |
1929 | - if ( function_exists( 'wpcom_vip_term_exists' ) ) { |
|
1930 | - $existing_id = wpcom_vip_term_exists( $term, $taxonomy, $parent ); |
|
1929 | + if (function_exists('wpcom_vip_term_exists')) { |
|
1930 | + $existing_id = wpcom_vip_term_exists($term, $taxonomy, $parent); |
|
1931 | 1931 | } else { |
1932 | - $existing_id = term_exists( $term, $taxonomy, $parent ); |
|
1932 | + $existing_id = term_exists($term, $taxonomy, $parent); |
|
1933 | 1933 | } |
1934 | 1934 | |
1935 | 1935 | // Term does not exist after more checking. maybe we want to create it. |
1936 | - if ( null === $existing_id && false === $check_only ) { |
|
1937 | - $result = $this->term_create( $params, $taxonomy, $id_field ); |
|
1936 | + if (null === $existing_id && false === $check_only) { |
|
1937 | + $result = $this->term_create($params, $taxonomy, $id_field); |
|
1938 | 1938 | return $result; |
1939 | - } elseif ( true === $check_only ) { |
|
1939 | + } elseif (true === $check_only) { |
|
1940 | 1940 | // We are just checking to see if there is a match. |
1941 | 1941 | return $existing_id; |
1942 | 1942 | } else { |
@@ -1945,21 +1945,21 @@ discard block |
||
1945 | 1945 | } |
1946 | 1946 | } // End if(). |
1947 | 1947 | |
1948 | - if ( isset( $term_id ) ) { |
|
1949 | - foreach ( $params as $key => $value ) { |
|
1950 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
1948 | + if (isset($term_id)) { |
|
1949 | + foreach ($params as $key => $value) { |
|
1950 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
1951 | 1951 | } |
1952 | - $result = $this->term_update( $term_id, $params, $taxonomy, $id_field ); |
|
1952 | + $result = $this->term_update($term_id, $params, $taxonomy, $id_field); |
|
1953 | 1953 | return $result; |
1954 | 1954 | } |
1955 | 1955 | // Create log entry for lack of a term id. |
1956 | - if ( isset( $this->logging ) ) { |
|
1956 | + if (isset($this->logging)) { |
|
1957 | 1957 | $logging = $this->logging; |
1958 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
1959 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
1958 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
1959 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
1960 | 1960 | } |
1961 | 1961 | $logging->setup( |
1962 | - esc_html__( 'Error: Terms: Tried to run term_upsert, and ended up without a term id', 'object-sync-for-salesforce' ), |
|
1962 | + esc_html__('Error: Terms: Tried to run term_upsert, and ended up without a term id', 'object-sync-for-salesforce'), |
|
1963 | 1963 | '', |
1964 | 1964 | 0, |
1965 | 1965 | 0, |
@@ -1981,36 +1981,36 @@ discard block |
||
1981 | 1981 | * success: 1 |
1982 | 1982 | * "errors" : [ ], |
1983 | 1983 | */ |
1984 | - private function term_update( $term_id, $params, $taxonomy, $id_field = 'ID' ) { |
|
1985 | - if ( 'tag' === $taxonomy ) { |
|
1984 | + private function term_update($term_id, $params, $taxonomy, $id_field = 'ID') { |
|
1985 | + if ('tag' === $taxonomy) { |
|
1986 | 1986 | $taxonomy = 'post_tag'; |
1987 | 1987 | } |
1988 | 1988 | $args = array(); |
1989 | - foreach ( $params as $key => $value ) { |
|
1990 | - if ( 'wp_update_term' === $value['method_modify'] ) { |
|
1991 | - $args[ $key ] = $value['value']; |
|
1992 | - unset( $params[ $key ] ); |
|
1989 | + foreach ($params as $key => $value) { |
|
1990 | + if ('wp_update_term' === $value['method_modify']) { |
|
1991 | + $args[$key] = $value['value']; |
|
1992 | + unset($params[$key]); |
|
1993 | 1993 | } |
1994 | 1994 | } |
1995 | - $term = wp_update_term( $term_id, $taxonomy, $args ); |
|
1995 | + $term = wp_update_term($term_id, $taxonomy, $args); |
|
1996 | 1996 | |
1997 | - if ( is_wp_error( $term ) ) { |
|
1997 | + if (is_wp_error($term)) { |
|
1998 | 1998 | $success = false; |
1999 | 1999 | $errors = $term; |
2000 | 2000 | } else { |
2001 | - $term_id = $term[ "$id_field" ]; |
|
2001 | + $term_id = $term["$id_field"]; |
|
2002 | 2002 | $success = true; |
2003 | 2003 | $errors = array(); |
2004 | - foreach ( $params as $key => $value ) { |
|
2004 | + foreach ($params as $key => $value) { |
|
2005 | 2005 | $method = $value['method_modify']; |
2006 | - $meta_id = $method( $term_id, $key, $value['value'] ); |
|
2007 | - if ( false === $meta_id ) { |
|
2006 | + $meta_id = $method($term_id, $key, $value['value']); |
|
2007 | + if (false === $meta_id) { |
|
2008 | 2008 | $success = false; |
2009 | 2009 | $errors[] = array( |
2010 | 2010 | 'message' => sprintf( |
2011 | 2011 | // translators: %1$s is a method name. |
2012 | - esc_html__( 'Tried to update meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
2013 | - esc_html( $method ) |
|
2012 | + esc_html__('Tried to update meta with method %1$s.', 'object-sync-for-salesforce'), |
|
2013 | + esc_html($method) |
|
2014 | 2014 | ), |
2015 | 2015 | 'key' => $key, |
2016 | 2016 | 'value' => $value, |
@@ -2019,11 +2019,11 @@ discard block |
||
2019 | 2019 | } |
2020 | 2020 | |
2021 | 2021 | // Developers can use this hook to set any other term data. |
2022 | - do_action( $this->option_prefix . 'set_more_term_data', $term_id, $params, 'update' ); |
|
2022 | + do_action($this->option_prefix . 'set_more_term_data', $term_id, $params, 'update'); |
|
2023 | 2023 | |
2024 | 2024 | } |
2025 | 2025 | |
2026 | - if ( is_wp_error( $term ) ) { |
|
2026 | + if (is_wp_error($term)) { |
|
2027 | 2027 | $success = false; |
2028 | 2028 | $errors = $term; |
2029 | 2029 | } else { |
@@ -2051,11 +2051,11 @@ discard block |
||
2051 | 2051 | * |
2052 | 2052 | * @return bool True if successful, false if failed. |
2053 | 2053 | */ |
2054 | - private function term_delete( $term_id, $taxonomy ) { |
|
2055 | - if ( 'tag' === $taxonomy ) { |
|
2054 | + private function term_delete($term_id, $taxonomy) { |
|
2055 | + if ('tag' === $taxonomy) { |
|
2056 | 2056 | $taxonomy = 'post_tag'; |
2057 | 2057 | } |
2058 | - $result = wp_delete_term( $term_id, $taxonomy ); |
|
2058 | + $result = wp_delete_term($term_id, $taxonomy); |
|
2059 | 2059 | return $result; |
2060 | 2060 | } |
2061 | 2061 | |
@@ -2071,52 +2071,52 @@ discard block |
||
2071 | 2071 | * success: 1 |
2072 | 2072 | * "errors" : [ ], |
2073 | 2073 | */ |
2074 | - private function comment_create( $params, $id_field = 'comment_ID' ) { |
|
2074 | + private function comment_create($params, $id_field = 'comment_ID') { |
|
2075 | 2075 | // Load all params with a method_modify of the object structure's content_method into $content |
2076 | 2076 | $content = array(); |
2077 | - $structure = $this->get_wordpress_table_structure( 'comment' ); |
|
2078 | - foreach ( $params as $key => $value ) { |
|
2079 | - if ( in_array( $value['method_modify'], $structure['content_methods'] ) ) { |
|
2080 | - $content[ $key ] = $value['value']; |
|
2081 | - unset( $params[ $key ] ); |
|
2077 | + $structure = $this->get_wordpress_table_structure('comment'); |
|
2078 | + foreach ($params as $key => $value) { |
|
2079 | + if (in_array($value['method_modify'], $structure['content_methods'])) { |
|
2080 | + $content[$key] = $value['value']; |
|
2081 | + unset($params[$key]); |
|
2082 | 2082 | } |
2083 | 2083 | } |
2084 | 2084 | |
2085 | 2085 | // Fields that are required for comments, even if they are empty values. |
2086 | - if ( ! isset( $content['comment_author'] ) ) { |
|
2086 | + if ( ! isset($content['comment_author'])) { |
|
2087 | 2087 | $content['comment_author'] = ''; |
2088 | 2088 | } |
2089 | - if ( ! isset( $content['comment_author_IP'] ) ) { |
|
2089 | + if ( ! isset($content['comment_author_IP'])) { |
|
2090 | 2090 | $content['comment_author_IP'] = ''; |
2091 | 2091 | } |
2092 | - if ( ! isset( $content['comment_author_email'] ) ) { |
|
2092 | + if ( ! isset($content['comment_author_email'])) { |
|
2093 | 2093 | $content['comment_author_email'] = ''; |
2094 | 2094 | } |
2095 | - if ( ! isset( $content['comment_author_url'] ) ) { |
|
2095 | + if ( ! isset($content['comment_author_url'])) { |
|
2096 | 2096 | $content['comment_author_url'] = ''; |
2097 | 2097 | } |
2098 | - if ( ! isset( $content['comment_type'] ) ) { |
|
2098 | + if ( ! isset($content['comment_type'])) { |
|
2099 | 2099 | $content['comment_type'] = ''; |
2100 | 2100 | } |
2101 | 2101 | |
2102 | - $comment_id = wp_new_comment( $content ); |
|
2102 | + $comment_id = wp_new_comment($content); |
|
2103 | 2103 | |
2104 | - if ( is_wp_error( $comment_id ) ) { |
|
2104 | + if (is_wp_error($comment_id)) { |
|
2105 | 2105 | $success = false; |
2106 | 2106 | $errors = $comment_id; |
2107 | 2107 | } else { |
2108 | 2108 | $success = true; |
2109 | 2109 | $errors = array(); |
2110 | - foreach ( $params as $key => $value ) { |
|
2110 | + foreach ($params as $key => $value) { |
|
2111 | 2111 | $method = $value['method_modify']; |
2112 | - $meta_id = $method( $comment_id, $key, $value['value'] ); |
|
2113 | - if ( false === $meta_id ) { |
|
2112 | + $meta_id = $method($comment_id, $key, $value['value']); |
|
2113 | + if (false === $meta_id) { |
|
2114 | 2114 | $success = false; |
2115 | 2115 | $errors[] = array( |
2116 | 2116 | 'message' => sprintf( |
2117 | 2117 | // translators: %1$s is a method name. |
2118 | - esc_html__( 'Tried to add meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
2119 | - esc_html( $method ) |
|
2118 | + esc_html__('Tried to add meta with method %1$s.', 'object-sync-for-salesforce'), |
|
2119 | + esc_html($method) |
|
2120 | 2120 | ), |
2121 | 2121 | 'key' => $key, |
2122 | 2122 | 'value' => $value, |
@@ -2125,11 +2125,11 @@ discard block |
||
2125 | 2125 | } |
2126 | 2126 | |
2127 | 2127 | // Developers can use this hook to set any other comment data. |
2128 | - do_action( $this->option_prefix . 'set_more_comment_data', $comment_id, $params, 'create' ); |
|
2128 | + do_action($this->option_prefix . 'set_more_comment_data', $comment_id, $params, 'create'); |
|
2129 | 2129 | |
2130 | 2130 | } |
2131 | 2131 | |
2132 | - if ( is_wp_error( $comment_id ) ) { |
|
2132 | + if (is_wp_error($comment_id)) { |
|
2133 | 2133 | $success = false; |
2134 | 2134 | $errors = $comment_id; |
2135 | 2135 | } else { |
@@ -2166,79 +2166,79 @@ discard block |
||
2166 | 2166 | * success: 1 |
2167 | 2167 | * "errors" : [ ], |
2168 | 2168 | */ |
2169 | - private function comment_upsert( $key, $value, $methods, $params, $id_field = 'comment_ID', $push_drafts = false, $check_only = false ) { |
|
2169 | + private function comment_upsert($key, $value, $methods, $params, $id_field = 'comment_ID', $push_drafts = false, $check_only = false) { |
|
2170 | 2170 | $method = $methods['method_match']; |
2171 | - if ( 'get_comment' === $method ) { |
|
2171 | + if ('get_comment' === $method) { |
|
2172 | 2172 | $method = 'get_comments'; |
2173 | 2173 | } |
2174 | - if ( '' !== $method ) { |
|
2174 | + if ('' !== $method) { |
|
2175 | 2175 | // This should give us the comment object. |
2176 | 2176 | $match = array(); |
2177 | - if ( 'comment_author' === $key ) { |
|
2178 | - $match['author__in'] = array( $value ); |
|
2177 | + if ('comment_author' === $key) { |
|
2178 | + $match['author__in'] = array($value); |
|
2179 | 2179 | } else { |
2180 | - $key = str_replace( 'comment_', '', $key ); |
|
2181 | - $match[ $key ] = $value; |
|
2180 | + $key = str_replace('comment_', '', $key); |
|
2181 | + $match[$key] = $value; |
|
2182 | 2182 | } |
2183 | - $comments = $method( $match ); |
|
2183 | + $comments = $method($match); |
|
2184 | 2184 | |
2185 | - if ( 1 === count( $comments ) ) { |
|
2185 | + if (1 === count($comments)) { |
|
2186 | 2186 | $comment = $comments[0]; |
2187 | 2187 | // Comment does exist after checking the matching value. we want its id. |
2188 | 2188 | $comment_id = $comment->{$id_field}; |
2189 | 2189 | |
2190 | - if ( true === $check_only ) { |
|
2190 | + if (true === $check_only) { |
|
2191 | 2191 | // We are just checking to see if there is a match. |
2192 | 2192 | return $comment_id; |
2193 | 2193 | } |
2194 | 2194 | |
2195 | 2195 | // On the prematch fields, we specify the method_update param. |
2196 | - if ( isset( $methods['method_update'] ) ) { |
|
2196 | + if (isset($methods['method_update'])) { |
|
2197 | 2197 | $method = $methods['method_update']; |
2198 | 2198 | } else { |
2199 | 2199 | $method = $methods['method_modify']; |
2200 | 2200 | } |
2201 | - $params[ $key ] = array( |
|
2201 | + $params[$key] = array( |
|
2202 | 2202 | 'value' => $value, |
2203 | 2203 | 'method_modify' => $method, |
2204 | 2204 | 'method_read' => $methods['method_read'], |
2205 | 2205 | ); |
2206 | - } elseif ( count( $comments ) > 1 ) { |
|
2206 | + } elseif (count($comments) > 1) { |
|
2207 | 2207 | $status = 'error'; |
2208 | 2208 | // Create log entry for multiple matches. |
2209 | - if ( isset( $this->logging ) ) { |
|
2209 | + if (isset($this->logging)) { |
|
2210 | 2210 | $logging = $this->logging; |
2211 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
2212 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
2211 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
2212 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
2213 | 2213 | } |
2214 | 2214 | $logging->setup( |
2215 | 2215 | sprintf( |
2216 | 2216 | // translators: %1$s is a number. %2$s is a key. %3$s is the value of that key. %4$s is a var_export'd array of comments. |
2217 | - esc_html__( 'Error: Comments: there are %1$s comment matches for the Salesforce key %2$s with the value of %3$s. Here they are: %4$s', 'object-sync-for-salesforce' ), |
|
2218 | - absint( count( $comments ) ), |
|
2219 | - esc_html( $key ), |
|
2220 | - esc_html( $value ), |
|
2221 | - esc_html( var_export( $comments ) ) // Debugging code in production because having useful error messages is good. |
|
2217 | + esc_html__('Error: Comments: there are %1$s comment matches for the Salesforce key %2$s with the value of %3$s. Here they are: %4$s', 'object-sync-for-salesforce'), |
|
2218 | + absint(count($comments)), |
|
2219 | + esc_html($key), |
|
2220 | + esc_html($value), |
|
2221 | + esc_html(var_export($comments)) // Debugging code in production because having useful error messages is good. |
|
2222 | 2222 | ), |
2223 | 2223 | '', |
2224 | 2224 | 0, |
2225 | 2225 | 0, |
2226 | 2226 | $status |
2227 | 2227 | ); |
2228 | - } elseif ( false === $check_only ) { |
|
2228 | + } elseif (false === $check_only) { |
|
2229 | 2229 | // Comment does not exist after checking the matching value. Create it. |
2230 | 2230 | // On the prematch fields, we specify the method_create param. |
2231 | - if ( isset( $methods['method_create'] ) ) { |
|
2231 | + if (isset($methods['method_create'])) { |
|
2232 | 2232 | $method = $methods['method_create']; |
2233 | 2233 | } else { |
2234 | 2234 | $method = $methods['method_modify']; |
2235 | 2235 | } |
2236 | - $params[ $key ] = array( |
|
2236 | + $params[$key] = array( |
|
2237 | 2237 | 'value' => $value, |
2238 | 2238 | 'method_modify' => $method, |
2239 | 2239 | 'method_read' => $methods['method_read'], |
2240 | 2240 | ); |
2241 | - $result = $this->comment_create( $params, $id_field ); |
|
2241 | + $result = $this->comment_create($params, $id_field); |
|
2242 | 2242 | return $result; |
2243 | 2243 | } else { |
2244 | 2244 | // Check only is true but there's not a comment yet. |
@@ -2246,33 +2246,33 @@ discard block |
||
2246 | 2246 | } // End if(). |
2247 | 2247 | } else { |
2248 | 2248 | // There is no method by which to check the comment. We can check other ways here. |
2249 | - $params[ $key ] = array( |
|
2249 | + $params[$key] = array( |
|
2250 | 2250 | 'value' => $value, |
2251 | 2251 | 'method_modify' => $methods['method_modify'], |
2252 | 2252 | 'method_read' => $methods['method_read'], |
2253 | 2253 | ); |
2254 | 2254 | |
2255 | - if ( isset( $params['comment_author']['value'] ) ) { |
|
2255 | + if (isset($params['comment_author']['value'])) { |
|
2256 | 2256 | $comment_author = $params['comment_author']['value']; |
2257 | 2257 | } |
2258 | 2258 | |
2259 | - if ( isset( $params['comment_date']['value'] ) ) { |
|
2259 | + if (isset($params['comment_date']['value'])) { |
|
2260 | 2260 | $comment_date = $params['comment_date']['value']; |
2261 | 2261 | } |
2262 | 2262 | |
2263 | - if ( isset( $params['timezone']['value'] ) ) { |
|
2263 | + if (isset($params['timezone']['value'])) { |
|
2264 | 2264 | $timezone = $params['timezone']['value']; |
2265 | 2265 | } else { |
2266 | 2266 | $timezone = 'blog'; |
2267 | 2267 | } |
2268 | 2268 | |
2269 | - $existing_id = comment_exists( $comment_author, $comment_date, $timezone ); // Returns an id if there is a result. Uses $wpdb->get_var, so it returns null if there is no value |
|
2269 | + $existing_id = comment_exists($comment_author, $comment_date, $timezone); // Returns an id if there is a result. Uses $wpdb->get_var, so it returns null if there is no value |
|
2270 | 2270 | |
2271 | 2271 | // Comment does not exist after more checking. We want to create it. |
2272 | - if ( null === $existing_id && false === $check_only ) { |
|
2273 | - $result = $this->comment_create( $params, $id_field ); |
|
2272 | + if (null === $existing_id && false === $check_only) { |
|
2273 | + $result = $this->comment_create($params, $id_field); |
|
2274 | 2274 | return $result; |
2275 | - } elseif ( true === $check_only ) { |
|
2275 | + } elseif (true === $check_only) { |
|
2276 | 2276 | // We are just checking to see if there is a match. |
2277 | 2277 | return $existing_id; |
2278 | 2278 | } else { |
@@ -2281,22 +2281,22 @@ discard block |
||
2281 | 2281 | } |
2282 | 2282 | } // End if() that sets up the parameters in the $params array. |
2283 | 2283 | |
2284 | - if ( isset( $comment_id ) ) { |
|
2285 | - foreach ( $params as $key => $value ) { |
|
2286 | - $params[ $key ]['method_modify'] = $methods['method_update']; |
|
2284 | + if (isset($comment_id)) { |
|
2285 | + foreach ($params as $key => $value) { |
|
2286 | + $params[$key]['method_modify'] = $methods['method_update']; |
|
2287 | 2287 | } |
2288 | - $result = $this->comment_update( $comment_id, $params, $id_field ); |
|
2288 | + $result = $this->comment_update($comment_id, $params, $id_field); |
|
2289 | 2289 | return $result; |
2290 | 2290 | } |
2291 | 2291 | |
2292 | 2292 | // Create log entry for lack of a comment id. |
2293 | - if ( isset( $this->logging ) ) { |
|
2293 | + if (isset($this->logging)) { |
|
2294 | 2294 | $logging = $this->logging; |
2295 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
2296 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
2295 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
2296 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
2297 | 2297 | } |
2298 | 2298 | $logging->setup( |
2299 | - esc_html__( 'Error: Comments: Tried to run comment_upsert, and ended up without a comment id', 'object-sync-for-salesforce' ), |
|
2299 | + esc_html__('Error: Comments: Tried to run comment_upsert, and ended up without a comment id', 'object-sync-for-salesforce'), |
|
2300 | 2300 | '', |
2301 | 2301 | 0, |
2302 | 2302 | 0, |
@@ -2317,34 +2317,34 @@ discard block |
||
2317 | 2317 | * success: 1 |
2318 | 2318 | * "errors" : [ ], |
2319 | 2319 | */ |
2320 | - private function comment_update( $comment_id, $params, $id_field = 'comment_ID' ) { |
|
2320 | + private function comment_update($comment_id, $params, $id_field = 'comment_ID') { |
|
2321 | 2321 | $content = array(); |
2322 | - $content[ $id_field ] = $comment_id; |
|
2323 | - foreach ( $params as $key => $value ) { |
|
2324 | - if ( 'wp_update_comment' === $value['method_modify'] ) { |
|
2325 | - $content[ $key ] = $value['value']; |
|
2326 | - unset( $params[ $key ] ); |
|
2322 | + $content[$id_field] = $comment_id; |
|
2323 | + foreach ($params as $key => $value) { |
|
2324 | + if ('wp_update_comment' === $value['method_modify']) { |
|
2325 | + $content[$key] = $value['value']; |
|
2326 | + unset($params[$key]); |
|
2327 | 2327 | } |
2328 | 2328 | } |
2329 | 2329 | |
2330 | - $updated = wp_update_comment( $content ); |
|
2330 | + $updated = wp_update_comment($content); |
|
2331 | 2331 | |
2332 | - if ( 0 === $updated ) { |
|
2332 | + if (0 === $updated) { |
|
2333 | 2333 | $success = false; |
2334 | 2334 | $errors = $updated; |
2335 | 2335 | } else { |
2336 | 2336 | $success = true; |
2337 | 2337 | $errors = array(); |
2338 | - foreach ( $params as $key => $value ) { |
|
2338 | + foreach ($params as $key => $value) { |
|
2339 | 2339 | $method = $value['method_modify']; |
2340 | - $meta_id = $method( $comment_id, $key, $value['value'] ); |
|
2341 | - if ( false === $meta_id ) { |
|
2340 | + $meta_id = $method($comment_id, $key, $value['value']); |
|
2341 | + if (false === $meta_id) { |
|
2342 | 2342 | $success = false; |
2343 | 2343 | $errors[] = array( |
2344 | 2344 | 'message' => sprintf( |
2345 | 2345 | // Translators: %1$s is a method name. |
2346 | - esc_html__( 'Tried to update meta with method %1$s.', 'object-sync-for-salesforce' ), |
|
2347 | - esc_html( $method ) |
|
2346 | + esc_html__('Tried to update meta with method %1$s.', 'object-sync-for-salesforce'), |
|
2347 | + esc_html($method) |
|
2348 | 2348 | ), |
2349 | 2349 | 'key' => $key, |
2350 | 2350 | 'value' => $value, |
@@ -2353,11 +2353,11 @@ discard block |
||
2353 | 2353 | } |
2354 | 2354 | |
2355 | 2355 | // Developers can use this hook to set any other comment data. |
2356 | - do_action( $this->option_prefix . 'set_more_comment_data', $comment_id, $params, 'update' ); |
|
2356 | + do_action($this->option_prefix . 'set_more_comment_data', $comment_id, $params, 'update'); |
|
2357 | 2357 | |
2358 | 2358 | } |
2359 | 2359 | |
2360 | - if ( is_wp_error( $updated ) ) { |
|
2360 | + if (is_wp_error($updated)) { |
|
2361 | 2361 | $success = false; |
2362 | 2362 | $errors = $updated; |
2363 | 2363 | } else { |
@@ -2385,8 +2385,8 @@ discard block |
||
2385 | 2385 | * |
2386 | 2386 | * @return boolean true if successful, false if failed. |
2387 | 2387 | */ |
2388 | - private function comment_delete( $id, $force_delete = false ) { |
|
2389 | - $result = wp_delete_comment( $id, $force_delete ); |
|
2388 | + private function comment_delete($id, $force_delete = false) { |
|
2389 | + $result = wp_delete_comment($id, $force_delete); |
|
2390 | 2390 | return $result; |
2391 | 2391 | } |
2392 | 2392 | |
@@ -2410,9 +2410,9 @@ discard block |
||
2410 | 2410 | * |
2411 | 2411 | * @param string $name The name of the field that lists all cache keys. |
2412 | 2412 | */ |
2413 | - public function __construct( $name ) { |
|
2413 | + public function __construct($name) { |
|
2414 | 2414 | $this->name = $name; |
2415 | - $this->cache_prefix = esc_sql( 'sfwp_' ); |
|
2415 | + $this->cache_prefix = esc_sql('sfwp_'); |
|
2416 | 2416 | } |
2417 | 2417 | |
2418 | 2418 | /** |
@@ -2421,7 +2421,7 @@ discard block |
||
2421 | 2421 | * @return mixed value of transient. False of empty, otherwise array. |
2422 | 2422 | */ |
2423 | 2423 | public function all_keys() { |
2424 | - return get_transient( $this->name ); |
|
2424 | + return get_transient($this->name); |
|
2425 | 2425 | } |
2426 | 2426 | |
2427 | 2427 | /** |
@@ -2432,16 +2432,16 @@ discard block |
||
2432 | 2432 | * @param int $cache_expiration. How long the plugin key cache, and this individual item cache, should last before expiring. |
2433 | 2433 | * @return mixed value of transient. False of empty, otherwise array. |
2434 | 2434 | */ |
2435 | - public function set( $cachekey, $value, $cache_expiration = 0 ) { |
|
2435 | + public function set($cachekey, $value, $cache_expiration = 0) { |
|
2436 | 2436 | |
2437 | 2437 | $prefix = $this->cache_prefix; |
2438 | 2438 | $cachekey = $prefix . $cachekey; |
2439 | 2439 | |
2440 | 2440 | $keys = $this->all_keys(); |
2441 | 2441 | $keys[] = $cachekey; |
2442 | - set_transient( $this->name, $keys, $cache_expiration ); |
|
2442 | + set_transient($this->name, $keys, $cache_expiration); |
|
2443 | 2443 | |
2444 | - return set_transient( $cachekey, $value, $cache_expiration ); |
|
2444 | + return set_transient($cachekey, $value, $cache_expiration); |
|
2445 | 2445 | } |
2446 | 2446 | |
2447 | 2447 | /** |
@@ -2450,10 +2450,10 @@ discard block |
||
2450 | 2450 | * @param string $cachekey the key for this cache item |
2451 | 2451 | * @return mixed value of transient. False of empty, otherwise array. |
2452 | 2452 | */ |
2453 | - public function get( $cachekey ) { |
|
2453 | + public function get($cachekey) { |
|
2454 | 2454 | $prefix = $this->cache_prefix; |
2455 | 2455 | $cachekey = $prefix . $cachekey; |
2456 | - return get_transient( $cachekey ); |
|
2456 | + return get_transient($cachekey); |
|
2457 | 2457 | } |
2458 | 2458 | |
2459 | 2459 | /** |
@@ -2462,10 +2462,10 @@ discard block |
||
2462 | 2462 | * @param string $cachekey the key for this cache item |
2463 | 2463 | * @return bool True if successful, false otherwise. |
2464 | 2464 | */ |
2465 | - public function delete( $cachekey ) { |
|
2465 | + public function delete($cachekey) { |
|
2466 | 2466 | $prefix = $this->cache_prefix; |
2467 | 2467 | $cachekey = $prefix . $cachekey; |
2468 | - return delete_transient( $cachekey ); |
|
2468 | + return delete_transient($cachekey); |
|
2469 | 2469 | } |
2470 | 2470 | |
2471 | 2471 | /** |
@@ -2476,10 +2476,10 @@ discard block |
||
2476 | 2476 | public function flush() { |
2477 | 2477 | $keys = $this->all_keys(); |
2478 | 2478 | $result = true; |
2479 | - foreach ( $keys as $key ) { |
|
2480 | - $result = delete_transient( $key ); |
|
2479 | + foreach ($keys as $key) { |
|
2480 | + $result = delete_transient($key); |
|
2481 | 2481 | } |
2482 | - $result = delete_transient( $this->name ); |
|
2482 | + $result = delete_transient($this->name); |
|
2483 | 2483 | return $result; |
2484 | 2484 | } |
2485 | 2485 |
@@ -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 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param object $queue |
99 | 99 | * @throws \Exception |
100 | 100 | */ |
101 | - public function __construct( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) { |
|
101 | + public function __construct($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue) { |
|
102 | 102 | $this->wpdb = $wpdb; |
103 | 103 | $this->version = $version; |
104 | 104 | $this->login_credentials = $login_credentials; |
@@ -141,35 +141,35 @@ discard block |
||
141 | 141 | * |
142 | 142 | */ |
143 | 143 | public function add_actions() { |
144 | - add_action( 'admin_init', array( $this, 'salesforce_settings_forms' ) ); |
|
145 | - add_action( 'admin_init', array( $this, 'notices' ) ); |
|
146 | - add_action( 'admin_post_post_fieldmap', array( $this, 'prepare_fieldmap_data' ) ); |
|
147 | - |
|
148 | - add_action( 'admin_post_delete_fieldmap', array( $this, 'delete_fieldmap' ) ); |
|
149 | - add_action( 'wp_ajax_get_salesforce_object_description', array( $this, 'get_salesforce_object_description' ) ); |
|
150 | - add_action( 'wp_ajax_get_wordpress_object_description', array( $this, 'get_wordpress_object_fields' ) ); |
|
151 | - add_action( 'wp_ajax_get_wp_sf_object_fields', array( $this, 'get_wp_sf_object_fields' ) ); |
|
152 | - add_action( 'wp_ajax_push_to_salesforce', array( $this, 'push_to_salesforce' ) ); |
|
153 | - add_action( 'wp_ajax_pull_from_salesforce', array( $this, 'pull_from_salesforce' ) ); |
|
154 | - add_action( 'wp_ajax_refresh_mapped_data', array( $this, 'refresh_mapped_data' ) ); |
|
155 | - add_action( 'wp_ajax_clear_sfwp_cache', array( $this, 'clear_sfwp_cache' ) ); |
|
156 | - |
|
157 | - add_action( 'edit_user_profile', array( $this, 'show_salesforce_user_fields' ) ); |
|
158 | - add_action( 'personal_options_update', array( $this, 'save_salesforce_user_fields' ) ); |
|
159 | - add_action( 'edit_user_profile_update', array( $this, 'save_salesforce_user_fields' ) ); |
|
144 | + add_action('admin_init', array($this, 'salesforce_settings_forms')); |
|
145 | + add_action('admin_init', array($this, 'notices')); |
|
146 | + add_action('admin_post_post_fieldmap', array($this, 'prepare_fieldmap_data')); |
|
147 | + |
|
148 | + add_action('admin_post_delete_fieldmap', array($this, 'delete_fieldmap')); |
|
149 | + add_action('wp_ajax_get_salesforce_object_description', array($this, 'get_salesforce_object_description')); |
|
150 | + add_action('wp_ajax_get_wordpress_object_description', array($this, 'get_wordpress_object_fields')); |
|
151 | + add_action('wp_ajax_get_wp_sf_object_fields', array($this, 'get_wp_sf_object_fields')); |
|
152 | + add_action('wp_ajax_push_to_salesforce', array($this, 'push_to_salesforce')); |
|
153 | + add_action('wp_ajax_pull_from_salesforce', array($this, 'pull_from_salesforce')); |
|
154 | + add_action('wp_ajax_refresh_mapped_data', array($this, 'refresh_mapped_data')); |
|
155 | + add_action('wp_ajax_clear_sfwp_cache', array($this, 'clear_sfwp_cache')); |
|
156 | + |
|
157 | + add_action('edit_user_profile', array($this, 'show_salesforce_user_fields')); |
|
158 | + add_action('personal_options_update', array($this, 'save_salesforce_user_fields')); |
|
159 | + add_action('edit_user_profile_update', array($this, 'save_salesforce_user_fields')); |
|
160 | 160 | |
161 | 161 | // when either field for schedule settings changes |
162 | - foreach ( $this->schedulable_classes as $key => $value ) { |
|
163 | - add_filter( 'update_option_' . $this->option_prefix . $key . '_schedule_number', array( $this, 'change_action_schedule' ), 10, 3 ); |
|
164 | - add_filter( 'update_option_' . $this->option_prefix . $key . '_schedule_unit', array( $this, 'change_action_schedule' ), 10, 3 ); |
|
162 | + foreach ($this->schedulable_classes as $key => $value) { |
|
163 | + add_filter('update_option_' . $this->option_prefix . $key . '_schedule_number', array($this, 'change_action_schedule'), 10, 3); |
|
164 | + add_filter('update_option_' . $this->option_prefix . $key . '_schedule_unit', array($this, 'change_action_schedule'), 10, 3); |
|
165 | 165 | } |
166 | 166 | |
167 | - add_action( 'admin_post_delete_object_map', array( $this, 'delete_object_map' ) ); |
|
168 | - add_action( 'admin_post_post_object_map', array( $this, 'prepare_object_map_data' ) ); |
|
167 | + add_action('admin_post_delete_object_map', array($this, 'delete_object_map')); |
|
168 | + add_action('admin_post_post_object_map', array($this, 'prepare_object_map_data')); |
|
169 | 169 | |
170 | 170 | // import and export plugin data |
171 | - add_action( 'admin_post_object_sync_for_salesforce_import', array( $this, 'import_json_file' ) ); |
|
172 | - add_action( 'admin_post_object_sync_for_salesforce_export', array( $this, 'export_json_file' ) ); |
|
171 | + add_action('admin_post_object_sync_for_salesforce_import', array($this, 'import_json_file')); |
|
172 | + add_action('admin_post_object_sync_for_salesforce_export', array($this, 'export_json_file')); |
|
173 | 173 | |
174 | 174 | } |
175 | 175 | |
@@ -177,35 +177,35 @@ discard block |
||
177 | 177 | * Recurring task to check Salesforce for data |
178 | 178 | * |
179 | 179 | */ |
180 | - public function change_action_schedule( $old_schedule, $new_schedule, $option_name ) { |
|
180 | + public function change_action_schedule($old_schedule, $new_schedule, $option_name) { |
|
181 | 181 | |
182 | 182 | // exit if nothing changed |
183 | - if ( $old_schedule === $new_schedule ) { |
|
183 | + if ($old_schedule === $new_schedule) { |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | 187 | // get the current schedule name from the task, based on pattern in the foreach |
188 | - preg_match( '/' . $this->option_prefix . '(.*)_schedule/', $option_name, $matches ); |
|
188 | + preg_match('/' . $this->option_prefix . '(.*)_schedule/', $option_name, $matches); |
|
189 | 189 | $schedule_name = $matches[1]; |
190 | 190 | $action_group_name = $schedule_name . $this->action_group_suffix; |
191 | 191 | |
192 | 192 | // exit if there is no initializer property on this schedule |
193 | - if ( ! isset( $this->schedulable_classes[ $schedule_name ]['initializer'] ) ) { |
|
193 | + if ( ! isset($this->schedulable_classes[$schedule_name]['initializer'])) { |
|
194 | 194 | return; |
195 | 195 | } |
196 | 196 | |
197 | 197 | // cancel previous task |
198 | 198 | $this->queue->cancel( |
199 | - $this->schedulable_classes[ $schedule_name ]['initializer'], |
|
199 | + $this->schedulable_classes[$schedule_name]['initializer'], |
|
200 | 200 | array(), |
201 | 201 | $action_group_name |
202 | 202 | ); |
203 | 203 | |
204 | 204 | // create new recurring task for action-scheduler to check for data to pull from salesforce |
205 | 205 | $this->queue->schedule_recurring( |
206 | - current_time( 'timestamp', true ), // plugin seems to expect UTC |
|
207 | - $this->queue->get_frequency( $schedule_name, 'seconds' ), |
|
208 | - $this->schedulable_classes[ $schedule_name ]['initializer'], |
|
206 | + current_time('timestamp', true), // plugin seems to expect UTC |
|
207 | + $this->queue->get_frequency($schedule_name, 'seconds'), |
|
208 | + $this->schedulable_classes[$schedule_name]['initializer'], |
|
209 | 209 | array(), |
210 | 210 | $action_group_name |
211 | 211 | ); |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | * |
217 | 217 | */ |
218 | 218 | public function create_admin_menu() { |
219 | - $title = __( 'Salesforce', 'object-sync-for-salesforce' ); |
|
220 | - add_options_page( $title, $title, 'configure_salesforce', 'object-sync-salesforce-admin', array( $this, 'show_admin_page' ) ); |
|
219 | + $title = __('Salesforce', 'object-sync-for-salesforce'); |
|
220 | + add_options_page($title, $title, 'configure_salesforce', 'object-sync-salesforce-admin', array($this, 'show_admin_page')); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -228,114 +228,114 @@ discard block |
||
228 | 228 | * |
229 | 229 | */ |
230 | 230 | public function show_admin_page() { |
231 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
231 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
232 | 232 | echo '<div class="wrap">'; |
233 | - echo '<h1>' . esc_html( get_admin_page_title() ) . '</h1>'; |
|
233 | + echo '<h1>' . esc_html(get_admin_page_title()) . '</h1>'; |
|
234 | 234 | $allowed = $this->check_wordpress_admin_permissions(); |
235 | - if ( false === $allowed ) { |
|
235 | + if (false === $allowed) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | $tabs = array( |
239 | - 'settings' => __( 'Settings', 'object-sync-for-salesforce' ), |
|
240 | - 'authorize' => __( 'Authorize', 'object-sync-for-salesforce' ), |
|
241 | - 'fieldmaps' => __( 'Fieldmaps', 'object-sync-for-salesforce' ), |
|
242 | - 'schedule' => __( 'Scheduling', 'object-sync-for-salesforce' ), |
|
243 | - 'import-export' => __( 'Import & Export', 'object-sync-for-salesforce' ), |
|
239 | + 'settings' => __('Settings', 'object-sync-for-salesforce'), |
|
240 | + 'authorize' => __('Authorize', 'object-sync-for-salesforce'), |
|
241 | + 'fieldmaps' => __('Fieldmaps', 'object-sync-for-salesforce'), |
|
242 | + 'schedule' => __('Scheduling', 'object-sync-for-salesforce'), |
|
243 | + 'import-export' => __('Import & Export', 'object-sync-for-salesforce'), |
|
244 | 244 | ); // this creates the tabs for the admin |
245 | 245 | |
246 | 246 | // optionally make tab(s) for logging and log settings |
247 | - $logging_enabled = get_option( $this->option_prefix . 'enable_logging', false ); |
|
248 | - $tabs['log_settings'] = __( 'Log Settings', 'object-sync-for-salesforce' ); |
|
247 | + $logging_enabled = get_option($this->option_prefix . 'enable_logging', false); |
|
248 | + $tabs['log_settings'] = __('Log Settings', 'object-sync-for-salesforce'); |
|
249 | 249 | |
250 | 250 | $mapping_errors = $this->mappings->get_failed_object_maps(); |
251 | - if ( ! empty( $mapping_errors ) ) { |
|
252 | - $tabs['mapping_errors'] = __( 'Mapping Errors', 'object-sync-for-salesforce' ); |
|
251 | + if ( ! empty($mapping_errors)) { |
|
252 | + $tabs['mapping_errors'] = __('Mapping Errors', 'object-sync-for-salesforce'); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | // filter for extending the tabs available on the page |
256 | 256 | // currently it will go into the default switch case for $tab |
257 | - $tabs = apply_filters( 'object_sync_for_salesforce_settings_tabs', $tabs ); |
|
257 | + $tabs = apply_filters('object_sync_for_salesforce_settings_tabs', $tabs); |
|
258 | 258 | |
259 | - $tab = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
260 | - $this->tabs( $tabs, $tab ); |
|
259 | + $tab = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
260 | + $this->tabs($tabs, $tab); |
|
261 | 261 | |
262 | 262 | $consumer_key = $this->login_credentials['consumer_key']; |
263 | 263 | $consumer_secret = $this->login_credentials['consumer_secret']; |
264 | 264 | $callback_url = $this->login_credentials['callback_url']; |
265 | 265 | |
266 | - if ( true !== $this->salesforce['is_authorized'] ) { |
|
267 | - $url = esc_url( $callback_url ); |
|
268 | - $anchor = esc_html__( 'Authorize tab', 'object-sync-for-salesforce' ); |
|
269 | - $message = sprintf( 'Salesforce needs to be authorized to connect to this website. Use the <a href="%s">%s</a> to connect.', $url, $anchor ); |
|
270 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
266 | + if (true !== $this->salesforce['is_authorized']) { |
|
267 | + $url = esc_url($callback_url); |
|
268 | + $anchor = esc_html__('Authorize tab', 'object-sync-for-salesforce'); |
|
269 | + $message = sprintf('Salesforce needs to be authorized to connect to this website. Use the <a href="%s">%s</a> to connect.', $url, $anchor); |
|
270 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
271 | 271 | } |
272 | 272 | |
273 | - if ( 0 === count( $this->mappings->get_fieldmaps() ) ) { |
|
274 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps' ) ); |
|
275 | - $anchor = esc_html__( 'Fieldmaps tab', 'object-sync-for-salesforce' ); |
|
276 | - $message = sprintf( 'No fieldmaps exist yet. Use the <a href="%s">%s</a> to map WordPress and Salesforce objects to each other.', $url, $anchor ); |
|
277 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
273 | + if (0 === count($this->mappings->get_fieldmaps())) { |
|
274 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps')); |
|
275 | + $anchor = esc_html__('Fieldmaps tab', 'object-sync-for-salesforce'); |
|
276 | + $message = sprintf('No fieldmaps exist yet. Use the <a href="%s">%s</a> to map WordPress and Salesforce objects to each other.', $url, $anchor); |
|
277 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
278 | 278 | } |
279 | 279 | |
280 | - $push_schedule_number = get_option( $this->option_prefix . 'salesforce_push_schedule_number', '' ); |
|
281 | - $push_schedule_unit = get_option( $this->option_prefix . 'salesforce_push_schedule_unit', '' ); |
|
282 | - $pull_schedule_number = get_option( $this->option_prefix . 'salesforce_pull_schedule_number', '' ); |
|
283 | - $pull_schedule_unit = get_option( $this->option_prefix . 'salesforce_pull_schedule_unit', '' ); |
|
280 | + $push_schedule_number = get_option($this->option_prefix . 'salesforce_push_schedule_number', ''); |
|
281 | + $push_schedule_unit = get_option($this->option_prefix . 'salesforce_push_schedule_unit', ''); |
|
282 | + $pull_schedule_number = get_option($this->option_prefix . 'salesforce_pull_schedule_number', ''); |
|
283 | + $pull_schedule_unit = get_option($this->option_prefix . 'salesforce_pull_schedule_unit', ''); |
|
284 | 284 | |
285 | - if ( '' === $push_schedule_number && '' === $push_schedule_unit && '' === $pull_schedule_number && '' === $pull_schedule_unit ) { |
|
286 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=schedule' ) ); |
|
287 | - $anchor = esc_html__( 'Scheduling tab', 'object-sync-for-salesforce' ); |
|
288 | - $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 ); |
|
289 | - require( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
285 | + if ('' === $push_schedule_number && '' === $push_schedule_unit && '' === $pull_schedule_number && '' === $pull_schedule_unit) { |
|
286 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=schedule')); |
|
287 | + $anchor = esc_html__('Scheduling tab', 'object-sync-for-salesforce'); |
|
288 | + $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); |
|
289 | + require(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | try { |
293 | - switch ( $tab ) { |
|
293 | + switch ($tab) { |
|
294 | 294 | case 'authorize': |
295 | - if ( isset( $get_data['code'] ) ) { |
|
295 | + if (isset($get_data['code'])) { |
|
296 | 296 | // this string is an oauth token |
297 | - $data = esc_html( wp_unslash( $get_data['code'] ) ); |
|
298 | - $is_authorized = $this->salesforce['sfapi']->request_token( $data ); |
|
297 | + $data = esc_html(wp_unslash($get_data['code'])); |
|
298 | + $is_authorized = $this->salesforce['sfapi']->request_token($data); |
|
299 | 299 | ?> |
300 | - <script>window.location = '<?php echo esc_url_raw( $callback_url ); ?>'</script> |
|
300 | + <script>window.location = '<?php echo esc_url_raw($callback_url); ?>'</script> |
|
301 | 301 | <?php |
302 | - } elseif ( true === $this->salesforce['is_authorized'] ) { |
|
303 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/authorized.php' ); |
|
304 | - $this->status( $this->salesforce['sfapi'] ); |
|
305 | - } elseif ( true === is_object( $this->salesforce['sfapi'] ) && isset( $consumer_key ) && isset( $consumer_secret ) ) { |
|
302 | + } elseif (true === $this->salesforce['is_authorized']) { |
|
303 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/authorized.php'); |
|
304 | + $this->status($this->salesforce['sfapi']); |
|
305 | + } elseif (true === is_object($this->salesforce['sfapi']) && isset($consumer_key) && isset($consumer_secret)) { |
|
306 | 306 | ?> |
307 | - <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> |
|
307 | + <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> |
|
308 | 308 | <?php |
309 | 309 | } else { |
310 | - $url = esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=settings' ) ); |
|
311 | - $anchor = esc_html__( 'Settings', 'object-sync-for-salesforce' ); |
|
310 | + $url = esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=settings')); |
|
311 | + $anchor = esc_html__('Settings', 'object-sync-for-salesforce'); |
|
312 | 312 | // translators: placeholders are for the settings tab link: 1) the url, and 2) the anchor text |
313 | - $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 ); |
|
314 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/error.php' ); |
|
313 | + $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); |
|
314 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/error.php'); |
|
315 | 315 | } |
316 | 316 | break; |
317 | 317 | case 'fieldmaps': |
318 | - if ( isset( $get_data['method'] ) ) { |
|
318 | + if (isset($get_data['method'])) { |
|
319 | 319 | |
320 | - $method = sanitize_key( $get_data['method'] ); |
|
321 | - $error_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps&method=' . $method ); |
|
322 | - $success_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps' ); |
|
320 | + $method = sanitize_key($get_data['method']); |
|
321 | + $error_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps&method=' . $method); |
|
322 | + $success_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=fieldmaps'); |
|
323 | 323 | |
324 | - if ( isset( $get_data['transient'] ) ) { |
|
325 | - $transient = sanitize_key( $get_data['transient'] ); |
|
326 | - $posted = $this->sfwp_transients->get( $transient ); |
|
324 | + if (isset($get_data['transient'])) { |
|
325 | + $transient = sanitize_key($get_data['transient']); |
|
326 | + $posted = $this->sfwp_transients->get($transient); |
|
327 | 327 | } |
328 | 328 | |
329 | - if ( isset( $posted ) && is_array( $posted ) ) { |
|
329 | + if (isset($posted) && is_array($posted)) { |
|
330 | 330 | $map = $posted; |
331 | - } elseif ( 'edit' === $method || 'clone' === $method || 'delete' === $method ) { |
|
332 | - $map = $this->mappings->get_fieldmaps( isset( $get_data['id'] ) ? sanitize_key( $get_data['id'] ) : '' ); |
|
331 | + } elseif ('edit' === $method || 'clone' === $method || 'delete' === $method) { |
|
332 | + $map = $this->mappings->get_fieldmaps(isset($get_data['id']) ? sanitize_key($get_data['id']) : ''); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( isset( $map ) && is_array( $map ) ) { |
|
335 | + if (isset($map) && is_array($map)) { |
|
336 | 336 | $label = $map['label']; |
337 | 337 | $salesforce_object = $map['salesforce_object']; |
338 | - $salesforce_record_types_allowed = maybe_unserialize( $map['salesforce_record_types_allowed'] ); |
|
338 | + $salesforce_record_types_allowed = maybe_unserialize($map['salesforce_record_types_allowed']); |
|
339 | 339 | $salesforce_record_type_default = $map['salesforce_record_type_default']; |
340 | 340 | $wordpress_object = $map['wordpress_object']; |
341 | 341 | $pull_trigger_field = $map['pull_trigger_field']; |
@@ -346,14 +346,14 @@ discard block |
||
346 | 346 | $weight = $map['weight']; |
347 | 347 | } |
348 | 348 | |
349 | - if ( 'add' === $method || 'edit' === $method || 'clone' === $method ) { |
|
350 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-add-edit-clone.php' ); |
|
351 | - } elseif ( 'delete' === $method ) { |
|
352 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-delete.php' ); |
|
349 | + if ('add' === $method || 'edit' === $method || 'clone' === $method) { |
|
350 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-add-edit-clone.php'); |
|
351 | + } elseif ('delete' === $method) { |
|
352 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-delete.php'); |
|
353 | 353 | } |
354 | 354 | } else { |
355 | 355 | $fieldmaps = $this->mappings->get_fieldmaps(); |
356 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/fieldmaps-list.php' ); |
|
356 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/fieldmaps-list.php'); |
|
357 | 357 | } // End if(). |
358 | 358 | break; |
359 | 359 | case 'logout': |
@@ -363,73 +363,73 @@ discard block |
||
363 | 363 | $this->clear_cache(); |
364 | 364 | break; |
365 | 365 | case 'clear_schedule': |
366 | - if ( isset( $get_data['schedule_name'] ) ) { |
|
367 | - $schedule_name = sanitize_key( $get_data['schedule_name'] ); |
|
366 | + if (isset($get_data['schedule_name'])) { |
|
367 | + $schedule_name = sanitize_key($get_data['schedule_name']); |
|
368 | 368 | } |
369 | - $this->clear_schedule( $schedule_name ); |
|
369 | + $this->clear_schedule($schedule_name); |
|
370 | 370 | break; |
371 | 371 | case 'settings': |
372 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/settings.php' ); |
|
372 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/settings.php'); |
|
373 | 373 | break; |
374 | 374 | case 'mapping_errors': |
375 | - if ( isset( $get_data['method'] ) ) { |
|
375 | + if (isset($get_data['method'])) { |
|
376 | 376 | |
377 | - $method = sanitize_key( $get_data['method'] ); |
|
378 | - $error_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors&method=' . $method ); |
|
379 | - $success_url = get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors' ); |
|
377 | + $method = sanitize_key($get_data['method']); |
|
378 | + $error_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors&method=' . $method); |
|
379 | + $success_url = get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=mapping_errors'); |
|
380 | 380 | |
381 | - if ( isset( $get_data['map_transient'] ) ) { |
|
382 | - $transient = sanitize_key( $get_data['map_transient'] ); |
|
383 | - $posted = $this->sfwp_transients->get( $transient ); |
|
381 | + if (isset($get_data['map_transient'])) { |
|
382 | + $transient = sanitize_key($get_data['map_transient']); |
|
383 | + $posted = $this->sfwp_transients->get($transient); |
|
384 | 384 | } |
385 | 385 | |
386 | - if ( isset( $posted ) && is_array( $posted ) ) { |
|
386 | + if (isset($posted) && is_array($posted)) { |
|
387 | 387 | $map_row = $posted; |
388 | - } elseif ( 'edit' === $method || 'delete' === $method ) { |
|
389 | - $map_row = $this->mappings->get_failed_object_map( isset( $get_data['id'] ) ? sanitize_key( $get_data['id'] ) : '' ); |
|
388 | + } elseif ('edit' === $method || 'delete' === $method) { |
|
389 | + $map_row = $this->mappings->get_failed_object_map(isset($get_data['id']) ? sanitize_key($get_data['id']) : ''); |
|
390 | 390 | } |
391 | 391 | |
392 | - if ( isset( $map_row ) && is_array( $map_row ) ) { |
|
392 | + if (isset($map_row) && is_array($map_row)) { |
|
393 | 393 | $salesforce_id = $map_row['salesforce_id']; |
394 | 394 | $wordpress_id = $map_row['wordpress_id']; |
395 | 395 | } |
396 | 396 | |
397 | - if ( 'edit' === $method ) { |
|
398 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors-edit.php' ); |
|
399 | - } elseif ( 'delete' === $method ) { |
|
400 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors-delete.php' ); |
|
397 | + if ('edit' === $method) { |
|
398 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors-edit.php'); |
|
399 | + } elseif ('delete' === $method) { |
|
400 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors-delete.php'); |
|
401 | 401 | } |
402 | 402 | } else { |
403 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/mapping-errors.php' ); |
|
403 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/mapping-errors.php'); |
|
404 | 404 | } |
405 | 405 | break; |
406 | 406 | case 'import-export': |
407 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/import-export.php' ); |
|
407 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/import-export.php'); |
|
408 | 408 | break; |
409 | 409 | default: |
410 | - $include_settings = apply_filters( 'object_sync_for_salesforce_settings_tab_include_settings', true, $tab ); |
|
411 | - $content_before = apply_filters( 'object_sync_for_salesforce_settings_tab_content_before', null, $tab ); |
|
412 | - $content_after = apply_filters( 'object_sync_for_salesforce_settings_tab_content_after', null, $tab ); |
|
413 | - if ( null !== $content_before ) { |
|
414 | - echo esc_html( $content_before ); |
|
410 | + $include_settings = apply_filters('object_sync_for_salesforce_settings_tab_include_settings', true, $tab); |
|
411 | + $content_before = apply_filters('object_sync_for_salesforce_settings_tab_content_before', null, $tab); |
|
412 | + $content_after = apply_filters('object_sync_for_salesforce_settings_tab_content_after', null, $tab); |
|
413 | + if (null !== $content_before) { |
|
414 | + echo esc_html($content_before); |
|
415 | 415 | } |
416 | - if ( true === $include_settings ) { |
|
417 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/settings.php' ); |
|
416 | + if (true === $include_settings) { |
|
417 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/settings.php'); |
|
418 | 418 | } |
419 | - if ( null !== $content_after ) { |
|
420 | - echo esc_html( $content_after ); |
|
419 | + if (null !== $content_after) { |
|
420 | + echo esc_html($content_after); |
|
421 | 421 | } |
422 | 422 | break; |
423 | 423 | } // End switch(). |
424 | - } catch ( SalesforceApiException $ex ) { |
|
425 | - echo sprintf( '<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
426 | - absint( $ex->getCode() ), |
|
427 | - esc_html( $ex->getMessage() ) |
|
424 | + } catch (SalesforceApiException $ex) { |
|
425 | + echo sprintf('<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
426 | + absint($ex->getCode()), |
|
427 | + esc_html($ex->getMessage()) |
|
428 | 428 | ); |
429 | - } catch ( Exception $ex ) { |
|
430 | - echo sprintf( '<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
431 | - absint( $ex->getCode() ), |
|
432 | - esc_html( $ex->getMessage() ) |
|
429 | + } catch (Exception $ex) { |
|
430 | + echo sprintf('<p>Error <strong>%1$s</strong>: %2$s</p>', |
|
431 | + absint($ex->getCode()), |
|
432 | + esc_html($ex->getMessage()) |
|
433 | 433 | ); |
434 | 434 | } // End try(). |
435 | 435 | echo '</div>'; |
@@ -441,14 +441,14 @@ discard block |
||
441 | 441 | * |
442 | 442 | */ |
443 | 443 | public function salesforce_settings_forms() { |
444 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
445 | - $page = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
446 | - $section = isset( $get_data['tab'] ) ? sanitize_key( $get_data['tab'] ) : 'settings'; |
|
444 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
445 | + $page = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
446 | + $section = isset($get_data['tab']) ? sanitize_key($get_data['tab']) : 'settings'; |
|
447 | 447 | |
448 | - $input_callback_default = array( $this, 'display_input_field' ); |
|
449 | - $input_checkboxes_default = array( $this, 'display_checkboxes' ); |
|
450 | - $input_select_default = array( $this, 'display_select' ); |
|
451 | - $link_default = array( $this, 'display_link' ); |
|
448 | + $input_callback_default = array($this, 'display_input_field'); |
|
449 | + $input_checkboxes_default = array($this, 'display_checkboxes'); |
|
450 | + $input_select_default = array($this, 'display_select'); |
|
451 | + $link_default = array($this, 'display_link'); |
|
452 | 452 | |
453 | 453 | $all_field_callbacks = array( |
454 | 454 | 'text' => $input_callback_default, |
@@ -457,10 +457,10 @@ discard block |
||
457 | 457 | 'link' => $link_default, |
458 | 458 | ); |
459 | 459 | |
460 | - $this->fields_settings( 'settings', 'settings', $all_field_callbacks ); |
|
461 | - $this->fields_fieldmaps( 'fieldmaps', 'objects' ); |
|
462 | - $this->fields_scheduling( 'schedule', 'schedule', $all_field_callbacks ); |
|
463 | - $this->fields_log_settings( 'log_settings', 'log_settings', $all_field_callbacks ); |
|
460 | + $this->fields_settings('settings', 'settings', $all_field_callbacks); |
|
461 | + $this->fields_fieldmaps('fieldmaps', 'objects'); |
|
462 | + $this->fields_scheduling('schedule', 'schedule', $all_field_callbacks); |
|
463 | + $this->fields_log_settings('log_settings', 'log_settings', $all_field_callbacks); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -471,11 +471,11 @@ discard block |
||
471 | 471 | * @param string $section |
472 | 472 | * @param string $input_callback |
473 | 473 | */ |
474 | - private function fields_settings( $page, $section, $callbacks ) { |
|
475 | - add_settings_section( $page, ucwords( $page ), null, $page ); |
|
474 | + private function fields_settings($page, $section, $callbacks) { |
|
475 | + add_settings_section($page, ucwords($page), null, $page); |
|
476 | 476 | $salesforce_settings = array( |
477 | 477 | 'consumer_key' => array( |
478 | - 'title' => __( 'Consumer Key', 'object-sync-for-salesforce' ), |
|
478 | + 'title' => __('Consumer Key', 'object-sync-for-salesforce'), |
|
479 | 479 | 'callback' => $callbacks['text'], |
480 | 480 | 'page' => $page, |
481 | 481 | 'section' => $section, |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | |
489 | 489 | ), |
490 | 490 | 'consumer_secret' => array( |
491 | - 'title' => __( 'Consumer Secret', 'object-sync-for-salesforce' ), |
|
491 | + 'title' => __('Consumer Secret', 'object-sync-for-salesforce'), |
|
492 | 492 | 'callback' => $callbacks['text'], |
493 | 493 | 'page' => $page, |
494 | 494 | 'section' => $section, |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | ), |
501 | 501 | ), |
502 | 502 | 'callback_url' => array( |
503 | - 'title' => __( 'Callback URL', 'object-sync-for-salesforce' ), |
|
503 | + 'title' => __('Callback URL', 'object-sync-for-salesforce'), |
|
504 | 504 | 'callback' => $callbacks['text'], |
505 | 505 | 'page' => $page, |
506 | 506 | 'section' => $section, |
@@ -508,14 +508,14 @@ discard block |
||
508 | 508 | 'type' => 'url', |
509 | 509 | 'validate' => 'sanitize_validate_text', |
510 | 510 | // translators: %1$s is the admin URL for the Authorize tab |
511 | - 'desc' => sprintf( __( 'In most cases, you will want to use %1$s for this value.', 'object-sync-for-salesforce' ), |
|
512 | - get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize' ) |
|
511 | + 'desc' => sprintf(__('In most cases, you will want to use %1$s for this value.', 'object-sync-for-salesforce'), |
|
512 | + get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize') |
|
513 | 513 | ), |
514 | 514 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL', |
515 | 515 | ), |
516 | 516 | ), |
517 | 517 | 'login_base_url' => array( |
518 | - 'title' => __( 'Login Base URL', 'object-sync-for-salesforce' ), |
|
518 | + 'title' => __('Login Base URL', 'object-sync-for-salesforce'), |
|
519 | 519 | 'callback' => $callbacks['text'], |
520 | 520 | 'page' => $page, |
521 | 521 | 'section' => $section, |
@@ -523,22 +523,22 @@ discard block |
||
523 | 523 | 'type' => 'url', |
524 | 524 | 'validate' => 'sanitize_validate_text', |
525 | 525 | // translators: 1) production salesforce login, 2) sandbox salesforce login |
526 | - 'desc' => sprintf( __( 'For most Salesforce setups, you should use %1$s for production and %2$s for sandbox.', 'object-sync-for-salesforce' ), |
|
527 | - esc_url( 'https://login.salesforce.com' ), |
|
528 | - esc_url( 'https://test.salesforce.com' ) |
|
526 | + 'desc' => sprintf(__('For most Salesforce setups, you should use %1$s for production and %2$s for sandbox.', 'object-sync-for-salesforce'), |
|
527 | + esc_url('https://login.salesforce.com'), |
|
528 | + esc_url('https://test.salesforce.com') |
|
529 | 529 | ), |
530 | 530 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL', |
531 | 531 | ), |
532 | 532 | ), |
533 | 533 | 'authorize_url_path' => array( |
534 | - 'title' => __( 'Authorize URL Path', 'object-sync-for-salesforce' ), |
|
534 | + 'title' => __('Authorize URL Path', 'object-sync-for-salesforce'), |
|
535 | 535 | 'callback' => $callbacks['text'], |
536 | 536 | 'page' => $page, |
537 | 537 | 'section' => $section, |
538 | 538 | 'args' => array( |
539 | 539 | 'type' => 'text', |
540 | 540 | 'validate' => 'sanitize_validate_text', |
541 | - 'desc' => __( 'For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce' ), |
|
541 | + 'desc' => __('For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce'), |
|
542 | 542 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH', |
543 | 543 | 'default' => $this->default_authorize_url_path, |
544 | 544 | ), |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | 'args' => array( |
552 | 552 | 'type' => 'text', |
553 | 553 | 'validate' => 'sanitize_validate_text', |
554 | - 'desc' => __( 'For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce' ), |
|
554 | + 'desc' => __('For most Salesforce installs, this should not be changed.', 'object-sync-for-salesforce'), |
|
555 | 555 | 'constant' => 'OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH', |
556 | 556 | 'default' => $this->default_token_url_path, |
557 | 557 | ), |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | 'args' => array( |
578 | 578 | 'type' => 'checkboxes', |
579 | 579 | 'validate' => 'sanitize_validate_text', |
580 | - 'desc' => __( 'Allows you to limit which Salesforce objects can be mapped', 'object-sync-for-salesforce' ), |
|
580 | + 'desc' => __('Allows you to limit which Salesforce objects can be mapped', 'object-sync-for-salesforce'), |
|
581 | 581 | 'items' => array( |
582 | 582 | 'triggerable' => array( |
583 | 583 | 'text' => 'Only Triggerable objects', |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | 'constant' => '', |
607 | 607 | 'items' => array( |
608 | 608 | 'field_label' => array( |
609 | - 'text' => __( 'Field Label', 'object-sync-for-salesforce' ), |
|
609 | + 'text' => __('Field Label', 'object-sync-for-salesforce'), |
|
610 | 610 | 'value' => 'field_label', |
611 | 611 | ), |
612 | 612 | /*'field_name' => array( |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | 'value' => 'field_name', |
615 | 615 | ),*/ |
616 | 616 | 'api_name' => array( |
617 | - 'text' => __( 'API Name', 'object-sync-for-salesforce' ), |
|
617 | + 'text' => __('API Name', 'object-sync-for-salesforce'), |
|
618 | 618 | 'value' => 'api_name', |
619 | 619 | ), |
620 | 620 | ), |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | 'args' => array( |
629 | 629 | 'type' => 'number', |
630 | 630 | 'validate' => 'sanitize_validate_text', |
631 | - 'desc' => __( 'Limit the number of records that can be pulled from Salesforce in a single query.', 'object-sync-for-salesforce' ), |
|
631 | + 'desc' => __('Limit the number of records that can be pulled from Salesforce in a single query.', 'object-sync-for-salesforce'), |
|
632 | 632 | 'constant' => '', |
633 | 633 | 'default' => $this->default_pull_limit, |
634 | 634 | ), |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | 'args' => array( |
642 | 642 | 'type' => 'number', |
643 | 643 | 'validate' => 'sanitize_validate_text', |
644 | - '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' ), |
|
644 | + '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'), |
|
645 | 645 | 'constant' => '', |
646 | 646 | 'default' => $this->default_pull_throttle, |
647 | 647 | ), |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | 'args' => array( |
655 | 655 | 'type' => 'checkbox', |
656 | 656 | 'validate' => 'sanitize_validate_text', |
657 | - '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' ), |
|
657 | + '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'), |
|
658 | 658 | 'constant' => '', |
659 | 659 | ), |
660 | 660 | ), |
@@ -666,13 +666,13 @@ discard block |
||
666 | 666 | 'args' => array( |
667 | 667 | 'type' => 'checkbox', |
668 | 668 | 'validate' => 'sanitize_validate_text', |
669 | - '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' ), |
|
669 | + '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'), |
|
670 | 670 | 'constant' => '', |
671 | 671 | ), |
672 | 672 | ), |
673 | 673 | ); |
674 | 674 | |
675 | - if ( true === is_object( $this->salesforce['sfapi'] ) && true === $this->salesforce['sfapi']->is_authorized() ) { |
|
675 | + if (true === is_object($this->salesforce['sfapi']) && true === $this->salesforce['sfapi']->is_authorized()) { |
|
676 | 676 | $salesforce_settings['api_version'] = array( |
677 | 677 | 'title' => 'Salesforce API Version', |
678 | 678 | 'callback' => $callbacks['select'], |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | ); |
689 | 689 | } |
690 | 690 | |
691 | - foreach ( $salesforce_settings as $key => $attributes ) { |
|
691 | + foreach ($salesforce_settings as $key => $attributes) { |
|
692 | 692 | $id = $this->option_prefix . $key; |
693 | 693 | $name = $this->option_prefix . $key; |
694 | 694 | $title = $attributes['title']; |
@@ -707,12 +707,12 @@ discard block |
||
707 | 707 | ); |
708 | 708 | |
709 | 709 | // if there is a constant and it is defined, don't run a validate function |
710 | - if ( isset( $attributes['args']['constant'] ) && defined( $attributes['args']['constant'] ) ) { |
|
710 | + if (isset($attributes['args']['constant']) && defined($attributes['args']['constant'])) { |
|
711 | 711 | $validate = ''; |
712 | 712 | } |
713 | 713 | |
714 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
715 | - register_setting( $page, $id, array( $this, $validate ) ); |
|
714 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
715 | + register_setting($page, $id, array($this, $validate)); |
|
716 | 716 | } |
717 | 717 | } |
718 | 718 | |
@@ -724,8 +724,8 @@ discard block |
||
724 | 724 | * @param string $section |
725 | 725 | * @param string $input_callback |
726 | 726 | */ |
727 | - private function fields_fieldmaps( $page, $section, $input_callback = '' ) { |
|
728 | - add_settings_section( $page, ucwords( $page ), null, $page ); |
|
727 | + private function fields_fieldmaps($page, $section, $input_callback = '') { |
|
728 | + add_settings_section($page, ucwords($page), null, $page); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /** |
@@ -736,12 +736,12 @@ discard block |
||
736 | 736 | * @param string $section |
737 | 737 | * @param string $input_callback |
738 | 738 | */ |
739 | - private function fields_scheduling( $page, $section, $callbacks ) { |
|
739 | + private function fields_scheduling($page, $section, $callbacks) { |
|
740 | 740 | |
741 | - add_settings_section( $page, ucwords( $page ), null, $page ); |
|
741 | + add_settings_section($page, ucwords($page), null, $page); |
|
742 | 742 | $schedule_settings = array( |
743 | 743 | 'action_scheduler_batch_size' => array( |
744 | - 'title' => __( 'Batch size', 'object-sync-for-salesforce' ), |
|
744 | + 'title' => __('Batch size', 'object-sync-for-salesforce'), |
|
745 | 745 | 'callback' => $callbacks['text'], |
746 | 746 | 'page' => $page, |
747 | 747 | 'section' => $section, |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | |
755 | 755 | ), |
756 | 756 | 'action_scheduler_concurrent_batches' => array( |
757 | - 'title' => __( 'Concurrent batches', 'object-sync-for-salesforce' ), |
|
757 | + 'title' => __('Concurrent batches', 'object-sync-for-salesforce'), |
|
758 | 758 | 'callback' => $callbacks['text'], |
759 | 759 | 'page' => $page, |
760 | 760 | 'section' => $section, |
@@ -767,11 +767,11 @@ discard block |
||
767 | 767 | ), |
768 | 768 | ); |
769 | 769 | |
770 | - foreach ( $this->schedulable_classes as $key => $value ) { |
|
771 | - add_settings_section( $key, $value['label'], null, $page ); |
|
772 | - if ( isset( $value['initializer'] ) ) { |
|
773 | - $schedule_settings[ $key . '_schedule_number' ] = array( |
|
774 | - 'title' => __( 'Run schedule every', 'object-sync-for-salesforce' ), |
|
770 | + foreach ($this->schedulable_classes as $key => $value) { |
|
771 | + add_settings_section($key, $value['label'], null, $page); |
|
772 | + if (isset($value['initializer'])) { |
|
773 | + $schedule_settings[$key . '_schedule_number'] = array( |
|
774 | + 'title' => __('Run schedule every', 'object-sync-for-salesforce'), |
|
775 | 775 | 'callback' => $callbacks['text'], |
776 | 776 | 'page' => $page, |
777 | 777 | 'section' => $key, |
@@ -782,8 +782,8 @@ discard block |
||
782 | 782 | 'constant' => '', |
783 | 783 | ), |
784 | 784 | ); |
785 | - $schedule_settings[ $key . '_schedule_unit' ] = array( |
|
786 | - 'title' => __( 'Time unit', 'object-sync-for-salesforce' ), |
|
785 | + $schedule_settings[$key . '_schedule_unit'] = array( |
|
786 | + 'title' => __('Time unit', 'object-sync-for-salesforce'), |
|
787 | 787 | 'callback' => $callbacks['select'], |
788 | 788 | 'page' => $page, |
789 | 789 | 'section' => $key, |
@@ -793,35 +793,35 @@ discard block |
||
793 | 793 | 'desc' => '', |
794 | 794 | 'items' => array( |
795 | 795 | 'minutes' => array( |
796 | - 'text' => __( 'Minutes', 'object-sync-for-salesforce' ), |
|
796 | + 'text' => __('Minutes', 'object-sync-for-salesforce'), |
|
797 | 797 | 'value' => 'minutes', |
798 | 798 | ), |
799 | 799 | 'hours' => array( |
800 | - 'text' => __( 'Hours', 'object-sync-for-salesforce' ), |
|
800 | + 'text' => __('Hours', 'object-sync-for-salesforce'), |
|
801 | 801 | 'value' => 'hours', |
802 | 802 | ), |
803 | 803 | 'days' => array( |
804 | - 'text' => __( 'Days', 'object-sync-for-salesforce' ), |
|
804 | + 'text' => __('Days', 'object-sync-for-salesforce'), |
|
805 | 805 | 'value' => 'days', |
806 | 806 | ), |
807 | 807 | ), |
808 | 808 | ), |
809 | 809 | ); |
810 | 810 | } |
811 | - $schedule_settings[ $key . '_clear_button' ] = array( |
|
811 | + $schedule_settings[$key . '_clear_button'] = array( |
|
812 | 812 | // translators: $this->get_schedule_count is an integer showing how many items are in the current queue |
813 | - 'title' => sprintf( 'This queue has ' . _n( '%s item', '%s items', $this->get_schedule_count( $key ), 'object-sync-for-salesforce' ), $this->get_schedule_count( $key ) ), |
|
813 | + 'title' => sprintf('This queue has ' . _n('%s item', '%s items', $this->get_schedule_count($key), 'object-sync-for-salesforce'), $this->get_schedule_count($key)), |
|
814 | 814 | 'callback' => $callbacks['link'], |
815 | 815 | 'page' => $page, |
816 | 816 | 'section' => $key, |
817 | 817 | 'args' => array( |
818 | - 'label' => __( 'Clear this queue', 'object-sync-for-salesforce' ), |
|
818 | + 'label' => __('Clear this queue', 'object-sync-for-salesforce'), |
|
819 | 819 | 'desc' => '', |
820 | - 'url' => esc_url( '?page=object-sync-salesforce-admin&tab=clear_schedule&schedule_name=' . $key ), |
|
820 | + 'url' => esc_url('?page=object-sync-salesforce-admin&tab=clear_schedule&schedule_name=' . $key), |
|
821 | 821 | 'link_class' => 'button button-secondary', |
822 | 822 | ), |
823 | 823 | ); |
824 | - foreach ( $schedule_settings as $key => $attributes ) { |
|
824 | + foreach ($schedule_settings as $key => $attributes) { |
|
825 | 825 | $id = $this->option_prefix . $key; |
826 | 826 | $name = $this->option_prefix . $key; |
827 | 827 | $title = $attributes['title']; |
@@ -837,8 +837,8 @@ discard block |
||
837 | 837 | 'name' => $name, |
838 | 838 | ) |
839 | 839 | ); |
840 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
841 | - register_setting( $page, $id ); |
|
840 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
841 | + register_setting($page, $id); |
|
842 | 842 | } |
843 | 843 | } // End foreach(). |
844 | 844 | } |
@@ -851,11 +851,11 @@ discard block |
||
851 | 851 | * @param string $section |
852 | 852 | * @param array $callbacks |
853 | 853 | */ |
854 | - private function fields_log_settings( $page, $section, $callbacks ) { |
|
855 | - add_settings_section( $page, ucwords( str_replace( '_', ' ', $page ) ), null, $page ); |
|
854 | + private function fields_log_settings($page, $section, $callbacks) { |
|
855 | + add_settings_section($page, ucwords(str_replace('_', ' ', $page)), null, $page); |
|
856 | 856 | $log_settings = array( |
857 | 857 | 'enable_logging' => array( |
858 | - 'title' => __( 'Enable Logging?', 'object-sync-for-salesforce' ), |
|
858 | + 'title' => __('Enable Logging?', 'object-sync-for-salesforce'), |
|
859 | 859 | 'callback' => $callbacks['text'], |
860 | 860 | 'page' => $page, |
861 | 861 | 'section' => $section, |
@@ -867,32 +867,32 @@ discard block |
||
867 | 867 | ), |
868 | 868 | ), |
869 | 869 | 'statuses_to_log' => array( |
870 | - 'title' => __( 'Statuses to log', 'object-sync-for-salesforce' ), |
|
870 | + 'title' => __('Statuses to log', 'object-sync-for-salesforce'), |
|
871 | 871 | 'callback' => $callbacks['checkboxes'], |
872 | 872 | 'page' => $page, |
873 | 873 | 'section' => $section, |
874 | 874 | 'args' => array( |
875 | 875 | 'type' => 'checkboxes', |
876 | 876 | 'validate' => 'sanitize_validate_text', |
877 | - 'desc' => __( 'these are the statuses to log', 'object-sync-for-salesforce' ), |
|
877 | + 'desc' => __('these are the statuses to log', 'object-sync-for-salesforce'), |
|
878 | 878 | 'items' => array( |
879 | 879 | 'error' => array( |
880 | - 'text' => __( 'Error', 'object-sync-for-salesforce' ), |
|
880 | + 'text' => __('Error', 'object-sync-for-salesforce'), |
|
881 | 881 | 'id' => 'error', |
882 | 882 | 'desc' => '', |
883 | 883 | ), |
884 | 884 | 'success' => array( |
885 | - 'text' => __( 'Success', 'object-sync-for-salesforce' ), |
|
885 | + 'text' => __('Success', 'object-sync-for-salesforce'), |
|
886 | 886 | 'id' => 'success', |
887 | 887 | 'desc' => '', |
888 | 888 | ), |
889 | 889 | 'notice' => array( |
890 | - 'text' => __( 'Notice', 'object-sync-for-salesforce' ), |
|
890 | + 'text' => __('Notice', 'object-sync-for-salesforce'), |
|
891 | 891 | 'id' => 'notice', |
892 | 892 | 'desc' => '', |
893 | 893 | ), |
894 | 894 | 'debug' => array( |
895 | - 'text' => __( 'Debug', 'object-sync-for-salesforce' ), |
|
895 | + 'text' => __('Debug', 'object-sync-for-salesforce'), |
|
896 | 896 | 'id' => 'debug', |
897 | 897 | 'desc' => '', |
898 | 898 | ), |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | ), |
901 | 901 | ), |
902 | 902 | 'prune_logs' => array( |
903 | - 'title' => __( 'Automatically delete old log entries?', 'object-sync-for-salesforce' ), |
|
903 | + 'title' => __('Automatically delete old log entries?', 'object-sync-for-salesforce'), |
|
904 | 904 | 'callback' => $callbacks['text'], |
905 | 905 | 'page' => $page, |
906 | 906 | 'section' => $section, |
@@ -912,20 +912,20 @@ discard block |
||
912 | 912 | ), |
913 | 913 | ), |
914 | 914 | 'logs_how_old' => array( |
915 | - 'title' => __( 'Age to delete log entries', 'object-sync-for-salesforce' ), |
|
915 | + 'title' => __('Age to delete log entries', 'object-sync-for-salesforce'), |
|
916 | 916 | 'callback' => $callbacks['text'], |
917 | 917 | 'page' => $page, |
918 | 918 | 'section' => $section, |
919 | 919 | 'args' => array( |
920 | 920 | 'type' => 'text', |
921 | 921 | 'validate' => 'sanitize_validate_text', |
922 | - 'desc' => __( 'If automatic deleting is enabled, it will affect logs this old.', 'object-sync-for-salesforce' ), |
|
922 | + 'desc' => __('If automatic deleting is enabled, it will affect logs this old.', 'object-sync-for-salesforce'), |
|
923 | 923 | 'default' => '2 weeks', |
924 | 924 | 'constant' => '', |
925 | 925 | ), |
926 | 926 | ), |
927 | 927 | 'logs_how_often_number' => array( |
928 | - 'title' => __( 'Check for old logs every', 'object-sync-for-salesforce' ), |
|
928 | + 'title' => __('Check for old logs every', 'object-sync-for-salesforce'), |
|
929 | 929 | 'callback' => $callbacks['text'], |
930 | 930 | 'page' => $page, |
931 | 931 | 'section' => $section, |
@@ -938,67 +938,67 @@ discard block |
||
938 | 938 | ), |
939 | 939 | ), |
940 | 940 | 'logs_how_often_unit' => array( |
941 | - 'title' => __( 'Time unit', 'object-sync-for-salesforce' ), |
|
941 | + 'title' => __('Time unit', 'object-sync-for-salesforce'), |
|
942 | 942 | 'callback' => $callbacks['select'], |
943 | 943 | 'page' => $page, |
944 | 944 | 'section' => $section, |
945 | 945 | 'args' => array( |
946 | 946 | 'type' => 'select', |
947 | 947 | 'validate' => 'sanitize_validate_text', |
948 | - 'desc' => __( 'These two fields are how often the site will check for logs to delete.', 'object-sync-for-salesforce' ), |
|
948 | + 'desc' => __('These two fields are how often the site will check for logs to delete.', 'object-sync-for-salesforce'), |
|
949 | 949 | 'items' => array( |
950 | 950 | 'minutes' => array( |
951 | - 'text' => __( 'Minutes', 'object-sync-for-salesforce' ), |
|
951 | + 'text' => __('Minutes', 'object-sync-for-salesforce'), |
|
952 | 952 | 'value' => 'minutes', |
953 | 953 | ), |
954 | 954 | 'hours' => array( |
955 | - 'text' => __( 'Hours', 'object-sync-for-salesforce' ), |
|
955 | + 'text' => __('Hours', 'object-sync-for-salesforce'), |
|
956 | 956 | 'value' => 'hours', |
957 | 957 | ), |
958 | 958 | 'days' => array( |
959 | - 'text' => __( 'Days', 'object-sync-for-salesforce' ), |
|
959 | + 'text' => __('Days', 'object-sync-for-salesforce'), |
|
960 | 960 | 'value' => 'days', |
961 | 961 | ), |
962 | 962 | ), |
963 | 963 | ), |
964 | 964 | ), |
965 | 965 | 'triggers_to_log' => array( |
966 | - 'title' => __( 'Triggers to log', 'object-sync-for-salesforce' ), |
|
966 | + 'title' => __('Triggers to log', 'object-sync-for-salesforce'), |
|
967 | 967 | 'callback' => $callbacks['checkboxes'], |
968 | 968 | 'page' => $page, |
969 | 969 | 'section' => $section, |
970 | 970 | 'args' => array( |
971 | 971 | 'type' => 'checkboxes', |
972 | 972 | 'validate' => 'sanitize_validate_text', |
973 | - 'desc' => __( 'these are the triggers to log', 'object-sync-for-salesforce' ), |
|
973 | + 'desc' => __('these are the triggers to log', 'object-sync-for-salesforce'), |
|
974 | 974 | 'items' => array( |
975 | 975 | $this->mappings->sync_wordpress_create => array( |
976 | - 'text' => __( 'WordPress create', 'object-sync-for-salesforce' ), |
|
976 | + 'text' => __('WordPress create', 'object-sync-for-salesforce'), |
|
977 | 977 | 'id' => 'wordpress_create', |
978 | 978 | 'desc' => '', |
979 | 979 | ), |
980 | 980 | $this->mappings->sync_wordpress_update => array( |
981 | - 'text' => __( 'WordPress update', 'object-sync-for-salesforce' ), |
|
981 | + 'text' => __('WordPress update', 'object-sync-for-salesforce'), |
|
982 | 982 | 'id' => 'wordpress_update', |
983 | 983 | 'desc' => '', |
984 | 984 | ), |
985 | 985 | $this->mappings->sync_wordpress_delete => array( |
986 | - 'text' => __( 'WordPress delete', 'object-sync-for-salesforce' ), |
|
986 | + 'text' => __('WordPress delete', 'object-sync-for-salesforce'), |
|
987 | 987 | 'id' => 'wordpress_delete', |
988 | 988 | 'desc' => '', |
989 | 989 | ), |
990 | 990 | $this->mappings->sync_sf_create => array( |
991 | - 'text' => __( 'Salesforce create', 'object-sync-for-salesforce' ), |
|
991 | + 'text' => __('Salesforce create', 'object-sync-for-salesforce'), |
|
992 | 992 | 'id' => 'sf_create', |
993 | 993 | 'desc' => '', |
994 | 994 | ), |
995 | 995 | $this->mappings->sync_sf_update => array( |
996 | - 'text' => __( 'Salesforce update', 'object-sync-for-salesforce' ), |
|
996 | + 'text' => __('Salesforce update', 'object-sync-for-salesforce'), |
|
997 | 997 | 'id' => 'sf_update', |
998 | 998 | 'desc' => '', |
999 | 999 | ), |
1000 | 1000 | $this->mappings->sync_sf_delete => array( |
1001 | - 'text' => __( 'Salesforce delete', 'object-sync-for-salesforce' ), |
|
1001 | + 'text' => __('Salesforce delete', 'object-sync-for-salesforce'), |
|
1002 | 1002 | 'id' => 'sf_delete', |
1003 | 1003 | 'desc' => '', |
1004 | 1004 | ), |
@@ -1006,7 +1006,7 @@ discard block |
||
1006 | 1006 | ), |
1007 | 1007 | ), |
1008 | 1008 | ); |
1009 | - foreach ( $log_settings as $key => $attributes ) { |
|
1009 | + foreach ($log_settings as $key => $attributes) { |
|
1010 | 1010 | $id = $this->option_prefix . $key; |
1011 | 1011 | $name = $this->option_prefix . $key; |
1012 | 1012 | $title = $attributes['title']; |
@@ -1022,8 +1022,8 @@ discard block |
||
1022 | 1022 | 'name' => $name, |
1023 | 1023 | ) |
1024 | 1024 | ); |
1025 | - add_settings_field( $id, $title, $callback, $page, $section, $args ); |
|
1026 | - register_setting( $page, $id ); |
|
1025 | + add_settings_field($id, $title, $callback, $page, $section, $args); |
|
1026 | + register_setting($page, $id); |
|
1027 | 1027 | } |
1028 | 1028 | } |
1029 | 1029 | |
@@ -1034,69 +1034,69 @@ discard block |
||
1034 | 1034 | public function notices() { |
1035 | 1035 | |
1036 | 1036 | // before a notice is displayed, we should make sure we are on a page related to this plugin |
1037 | - if ( ! isset( $_GET['page'] ) || 'object-sync-salesforce-admin' !== $_GET['page'] ) { |
|
1037 | + if ( ! isset($_GET['page']) || 'object-sync-salesforce-admin' !== $_GET['page']) { |
|
1038 | 1038 | return; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
1042 | - require_once plugin_dir_path( __FILE__ ) . '../classes/admin-notice.php'; |
|
1041 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
1042 | + require_once plugin_dir_path(__FILE__) . '../classes/admin-notice.php'; |
|
1043 | 1043 | |
1044 | 1044 | $notices = array( |
1045 | 1045 | 'permission' => array( |
1046 | 1046 | 'condition' => false === $this->check_wordpress_admin_permissions(), |
1047 | - 'message' => __( "Your account does not have permission to edit the Salesforce REST API plugin's settings.", 'object-sync-for-salesforce' ), |
|
1047 | + 'message' => __("Your account does not have permission to edit the Salesforce REST API plugin's settings.", 'object-sync-for-salesforce'), |
|
1048 | 1048 | 'type' => 'error', |
1049 | 1049 | 'dismissible' => false, |
1050 | 1050 | ), |
1051 | 1051 | 'fieldmap' => array( |
1052 | - 'condition' => isset( $get_data['transient'] ), |
|
1053 | - 'message' => __( 'Errors kept this fieldmap from being saved.', 'object-sync-for-salesforce' ), |
|
1052 | + 'condition' => isset($get_data['transient']), |
|
1053 | + 'message' => __('Errors kept this fieldmap from being saved.', 'object-sync-for-salesforce'), |
|
1054 | 1054 | 'type' => 'error', |
1055 | 1055 | 'dismissible' => true, |
1056 | 1056 | ), |
1057 | 1057 | 'object_map' => array( |
1058 | - 'condition' => isset( $get_data['map_transient'] ), |
|
1059 | - 'message' => __( 'Errors kept this object map from being saved.', 'object-sync-for-salesforce' ), |
|
1058 | + 'condition' => isset($get_data['map_transient']), |
|
1059 | + 'message' => __('Errors kept this object map from being saved.', 'object-sync-for-salesforce'), |
|
1060 | 1060 | 'type' => 'error', |
1061 | 1061 | 'dismissible' => true, |
1062 | 1062 | ), |
1063 | 1063 | 'data_saved' => array( |
1064 | - 'condition' => isset( $get_data['data_saved'] ) && 'true' === $get_data['data_saved'], |
|
1065 | - 'message' => __( 'This data was successfully saved.', 'object-sync-for-salesforce' ), |
|
1064 | + 'condition' => isset($get_data['data_saved']) && 'true' === $get_data['data_saved'], |
|
1065 | + 'message' => __('This data was successfully saved.', 'object-sync-for-salesforce'), |
|
1066 | 1066 | 'type' => 'success', |
1067 | 1067 | 'dismissible' => true, |
1068 | 1068 | ), |
1069 | 1069 | 'data_save_error' => array( |
1070 | - 'condition' => isset( $get_data['data_saved'] ) && 'false' === $get_data['data_saved'], |
|
1071 | - 'message' => __( 'This data was not successfully saved. Try again.', 'object-sync-for-salesforce' ), |
|
1070 | + 'condition' => isset($get_data['data_saved']) && 'false' === $get_data['data_saved'], |
|
1071 | + 'message' => __('This data was not successfully saved. Try again.', 'object-sync-for-salesforce'), |
|
1072 | 1072 | 'type' => 'error', |
1073 | 1073 | 'dismissible' => true, |
1074 | 1074 | ), |
1075 | 1075 | ); |
1076 | 1076 | |
1077 | - foreach ( $notices as $key => $value ) { |
|
1077 | + foreach ($notices as $key => $value) { |
|
1078 | 1078 | |
1079 | 1079 | $condition = $value['condition']; |
1080 | 1080 | $message = $value['message']; |
1081 | 1081 | |
1082 | - if ( isset( $value['dismissible'] ) ) { |
|
1082 | + if (isset($value['dismissible'])) { |
|
1083 | 1083 | $dismissible = $value['dismissible']; |
1084 | 1084 | } else { |
1085 | 1085 | $dismissible = false; |
1086 | 1086 | } |
1087 | 1087 | |
1088 | - if ( isset( $value['type'] ) ) { |
|
1088 | + if (isset($value['type'])) { |
|
1089 | 1089 | $type = $value['type']; |
1090 | 1090 | } else { |
1091 | 1091 | $type = ''; |
1092 | 1092 | } |
1093 | 1093 | |
1094 | - if ( ! isset( $value['template'] ) ) { |
|
1094 | + if ( ! isset($value['template'])) { |
|
1095 | 1095 | $template = ''; |
1096 | 1096 | } |
1097 | 1097 | |
1098 | - if ( $condition ) { |
|
1099 | - new Object_Sync_Sf_Admin_Notice( $condition, $message, $dismissible, $type, $template ); |
|
1098 | + if ($condition) { |
|
1099 | + new Object_Sync_Sf_Admin_Notice($condition, $message, $dismissible, $type, $template); |
|
1100 | 1100 | } |
1101 | 1101 | } |
1102 | 1102 | |
@@ -1111,47 +1111,47 @@ discard block |
||
1111 | 1111 | * can optionally contain a type |
1112 | 1112 | * @return array $object_settings |
1113 | 1113 | */ |
1114 | - public function get_salesforce_object_description( $data = array() ) { |
|
1114 | + public function get_salesforce_object_description($data = array()) { |
|
1115 | 1115 | $ajax = false; |
1116 | - if ( empty( $data ) ) { |
|
1117 | - $data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1116 | + if (empty($data)) { |
|
1117 | + $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1118 | 1118 | $ajax = true; |
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | $object_description = array(); |
1122 | 1122 | |
1123 | - if ( ! empty( $data['salesforce_object'] ) ) { |
|
1124 | - $object = $this->salesforce['sfapi']->object_describe( esc_attr( $data['salesforce_object'] ) ); |
|
1123 | + if ( ! empty($data['salesforce_object'])) { |
|
1124 | + $object = $this->salesforce['sfapi']->object_describe(esc_attr($data['salesforce_object'])); |
|
1125 | 1125 | |
1126 | 1126 | $object_fields = array(); |
1127 | 1127 | $include_record_types = array(); |
1128 | 1128 | |
1129 | 1129 | // these can come from ajax |
1130 | - $include = isset( $data['include'] ) ? (array) $data['include'] : array(); |
|
1131 | - $include = array_map( 'esc_attr', $include ); |
|
1132 | - |
|
1133 | - if ( in_array( 'fields', $include, true ) || empty( $include ) ) { |
|
1134 | - $type = isset( $data['field_type'] ) ? esc_attr( $data['field_type'] ) : ''; // can come from ajax |
|
1135 | - foreach ( $object['data']['fields'] as $key => $value ) { |
|
1136 | - if ( '' === $type || $type === $value['type'] ) { |
|
1137 | - $object_fields[ $key ] = $value; |
|
1130 | + $include = isset($data['include']) ? (array) $data['include'] : array(); |
|
1131 | + $include = array_map('esc_attr', $include); |
|
1132 | + |
|
1133 | + if (in_array('fields', $include, true) || empty($include)) { |
|
1134 | + $type = isset($data['field_type']) ? esc_attr($data['field_type']) : ''; // can come from ajax |
|
1135 | + foreach ($object['data']['fields'] as $key => $value) { |
|
1136 | + if ('' === $type || $type === $value['type']) { |
|
1137 | + $object_fields[$key] = $value; |
|
1138 | 1138 | } |
1139 | 1139 | } |
1140 | 1140 | $object_description['fields'] = $object_fields; |
1141 | 1141 | } |
1142 | 1142 | |
1143 | - if ( in_array( 'recordTypeInfos', $include, true ) ) { |
|
1144 | - if ( isset( $object['data']['recordTypeInfos'] ) && count( $object['data']['recordTypeInfos'] ) > 1 ) { |
|
1145 | - foreach ( $object['data']['recordTypeInfos'] as $type ) { |
|
1146 | - $object_record_types[ $type['recordTypeId'] ] = $type['name']; |
|
1143 | + if (in_array('recordTypeInfos', $include, true)) { |
|
1144 | + if (isset($object['data']['recordTypeInfos']) && count($object['data']['recordTypeInfos']) > 1) { |
|
1145 | + foreach ($object['data']['recordTypeInfos'] as $type) { |
|
1146 | + $object_record_types[$type['recordTypeId']] = $type['name']; |
|
1147 | 1147 | } |
1148 | 1148 | $object_description['recordTypeInfos'] = $object_record_types; |
1149 | 1149 | } |
1150 | 1150 | } |
1151 | 1151 | } |
1152 | 1152 | |
1153 | - if ( true === $ajax ) { |
|
1154 | - wp_send_json_success( $object_description ); |
|
1153 | + if (true === $ajax) { |
|
1154 | + wp_send_json_success($object_description); |
|
1155 | 1155 | } else { |
1156 | 1156 | return $object_description; |
1157 | 1157 | } |
@@ -1165,23 +1165,23 @@ discard block |
||
1165 | 1165 | * can optionally contain a type for the field |
1166 | 1166 | * @return array $object_fields |
1167 | 1167 | */ |
1168 | - public function get_salesforce_object_fields( $data = array() ) { |
|
1168 | + public function get_salesforce_object_fields($data = array()) { |
|
1169 | 1169 | |
1170 | - if ( ! empty( $data['salesforce_object'] ) ) { |
|
1171 | - $object = $this->salesforce['sfapi']->object_describe( esc_attr( $data['salesforce_object'] ) ); |
|
1170 | + if ( ! empty($data['salesforce_object'])) { |
|
1171 | + $object = $this->salesforce['sfapi']->object_describe(esc_attr($data['salesforce_object'])); |
|
1172 | 1172 | $object_fields = array(); |
1173 | - $type = isset( $data['type'] ) ? esc_attr( $data['type'] ) : ''; |
|
1174 | - $include_record_types = isset( $data['include_record_types'] ) ? esc_attr( $data['include_record_types'] ) : false; |
|
1175 | - foreach ( $object['data']['fields'] as $key => $value ) { |
|
1176 | - if ( '' === $type || $type === $value['type'] ) { |
|
1177 | - $object_fields[ $key ] = $value; |
|
1173 | + $type = isset($data['type']) ? esc_attr($data['type']) : ''; |
|
1174 | + $include_record_types = isset($data['include_record_types']) ? esc_attr($data['include_record_types']) : false; |
|
1175 | + foreach ($object['data']['fields'] as $key => $value) { |
|
1176 | + if ('' === $type || $type === $value['type']) { |
|
1177 | + $object_fields[$key] = $value; |
|
1178 | 1178 | } |
1179 | 1179 | } |
1180 | - if ( true === $include_record_types ) { |
|
1180 | + if (true === $include_record_types) { |
|
1181 | 1181 | $object_record_types = array(); |
1182 | - if ( isset( $object['data']['recordTypeInfos'] ) && count( $object['data']['recordTypeInfos'] ) > 1 ) { |
|
1183 | - foreach ( $object['data']['recordTypeInfos'] as $type ) { |
|
1184 | - $object_record_types[ $type['recordTypeId'] ] = $type['name']; |
|
1182 | + if (isset($object['data']['recordTypeInfos']) && count($object['data']['recordTypeInfos']) > 1) { |
|
1183 | + foreach ($object['data']['recordTypeInfos'] as $type) { |
|
1184 | + $object_record_types[$type['recordTypeId']] = $type['name']; |
|
1185 | 1185 | } |
1186 | 1186 | } |
1187 | 1187 | } |
@@ -1198,18 +1198,18 @@ discard block |
||
1198 | 1198 | * @param string $wordpress_object |
1199 | 1199 | * @return array $object_fields |
1200 | 1200 | */ |
1201 | - public function get_wordpress_object_fields( $wordpress_object = '' ) { |
|
1201 | + public function get_wordpress_object_fields($wordpress_object = '') { |
|
1202 | 1202 | $ajax = false; |
1203 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1204 | - if ( empty( $wordpress_object ) ) { |
|
1205 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1203 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1204 | + if (empty($wordpress_object)) { |
|
1205 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1206 | 1206 | $ajax = true; |
1207 | 1207 | } |
1208 | 1208 | |
1209 | - $object_fields = $this->wordpress->get_wordpress_object_fields( $wordpress_object ); |
|
1209 | + $object_fields = $this->wordpress->get_wordpress_object_fields($wordpress_object); |
|
1210 | 1210 | |
1211 | - if ( true === $ajax ) { |
|
1212 | - wp_send_json_success( $object_fields ); |
|
1211 | + if (true === $ajax) { |
|
1212 | + wp_send_json_success($object_fields); |
|
1213 | 1213 | } else { |
1214 | 1214 | return $object_fields; |
1215 | 1215 | } |
@@ -1223,24 +1223,24 @@ discard block |
||
1223 | 1223 | * @param string $salesforce_object |
1224 | 1224 | * @return array $object_fields |
1225 | 1225 | */ |
1226 | - public function get_wp_sf_object_fields( $wordpress_object = '', $salesforce = '' ) { |
|
1227 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1228 | - if ( empty( $wordpress_object ) ) { |
|
1229 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1226 | + public function get_wp_sf_object_fields($wordpress_object = '', $salesforce = '') { |
|
1227 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1228 | + if (empty($wordpress_object)) { |
|
1229 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1230 | 1230 | } |
1231 | - if ( empty( $salesforce_object ) ) { |
|
1232 | - $salesforce_object = isset( $post_data['salesforce_object'] ) ? sanitize_text_field( wp_unslash( $post_data['salesforce_object'] ) ) : ''; |
|
1231 | + if (empty($salesforce_object)) { |
|
1232 | + $salesforce_object = isset($post_data['salesforce_object']) ? sanitize_text_field(wp_unslash($post_data['salesforce_object'])) : ''; |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | - $object_fields['wordpress'] = $this->get_wordpress_object_fields( $wordpress_object ); |
|
1235 | + $object_fields['wordpress'] = $this->get_wordpress_object_fields($wordpress_object); |
|
1236 | 1236 | $object_fields['salesforce'] = $this->get_salesforce_object_fields( |
1237 | 1237 | array( |
1238 | 1238 | 'salesforce_object' => $salesforce_object, |
1239 | 1239 | ) |
1240 | 1240 | ); |
1241 | 1241 | |
1242 | - if ( ! empty( $post_data ) ) { |
|
1243 | - wp_send_json_success( $object_fields ); |
|
1242 | + if ( ! empty($post_data)) { |
|
1243 | + wp_send_json_success($object_fields); |
|
1244 | 1244 | } else { |
1245 | 1245 | return $object_fields; |
1246 | 1246 | } |
@@ -1253,17 +1253,17 @@ discard block |
||
1253 | 1253 | * @param string $wordpress_object |
1254 | 1254 | * @param int $wordpress_id |
1255 | 1255 | */ |
1256 | - public function push_to_salesforce( $wordpress_object = '', $wordpress_id = '' ) { |
|
1257 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1258 | - if ( empty( $wordpress_object ) && empty( $wordpress_id ) ) { |
|
1259 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1260 | - $wordpress_id = isset( $post_data['wordpress_id'] ) ? absint( $post_data['wordpress_id'] ) : ''; |
|
1256 | + public function push_to_salesforce($wordpress_object = '', $wordpress_id = '') { |
|
1257 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1258 | + if (empty($wordpress_object) && empty($wordpress_id)) { |
|
1259 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1260 | + $wordpress_id = isset($post_data['wordpress_id']) ? absint($post_data['wordpress_id']) : ''; |
|
1261 | 1261 | } |
1262 | - $data = $this->wordpress->get_wordpress_object_data( $wordpress_object, $wordpress_id ); |
|
1263 | - $result = $this->push->manual_object_update( $data, $wordpress_object ); |
|
1262 | + $data = $this->wordpress->get_wordpress_object_data($wordpress_object, $wordpress_id); |
|
1263 | + $result = $this->push->manual_object_update($data, $wordpress_object); |
|
1264 | 1264 | |
1265 | - if ( ! empty( $post_data['wordpress_object'] ) && ! empty( $post_data['wordpress_id'] ) ) { |
|
1266 | - wp_send_json_success( $result ); |
|
1265 | + if ( ! empty($post_data['wordpress_object']) && ! empty($post_data['wordpress_id'])) { |
|
1266 | + wp_send_json_success($result); |
|
1267 | 1267 | } else { |
1268 | 1268 | return $result; |
1269 | 1269 | } |
@@ -1277,16 +1277,16 @@ discard block |
||
1277 | 1277 | * @param string $salesforce_id |
1278 | 1278 | * @param string $wordpress_object |
1279 | 1279 | */ |
1280 | - public function pull_from_salesforce( $salesforce_id = '', $wordpress_object = '' ) { |
|
1281 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1282 | - if ( empty( $wordpress_object ) && empty( $salesforce_id ) ) { |
|
1283 | - $wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : ''; |
|
1284 | - $salesforce_id = isset( $post_data['salesforce_id'] ) ? sanitize_text_field( wp_unslash( $post_data['salesforce_id'] ) ) : ''; |
|
1285 | - } |
|
1286 | - $type = $this->salesforce['sfapi']->get_sobject_type( $salesforce_id ); |
|
1287 | - $result = $this->pull->manual_pull( $type, $salesforce_id, $wordpress_object ); // we want the wp object to make sure we get the right fieldmap |
|
1288 | - if ( ! empty( $post_data ) ) { |
|
1289 | - wp_send_json_success( $result ); |
|
1280 | + public function pull_from_salesforce($salesforce_id = '', $wordpress_object = '') { |
|
1281 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1282 | + if (empty($wordpress_object) && empty($salesforce_id)) { |
|
1283 | + $wordpress_object = isset($post_data['wordpress_object']) ? sanitize_text_field(wp_unslash($post_data['wordpress_object'])) : ''; |
|
1284 | + $salesforce_id = isset($post_data['salesforce_id']) ? sanitize_text_field(wp_unslash($post_data['salesforce_id'])) : ''; |
|
1285 | + } |
|
1286 | + $type = $this->salesforce['sfapi']->get_sobject_type($salesforce_id); |
|
1287 | + $result = $this->pull->manual_pull($type, $salesforce_id, $wordpress_object); // we want the wp object to make sure we get the right fieldmap |
|
1288 | + if ( ! empty($post_data)) { |
|
1289 | + wp_send_json_success($result); |
|
1290 | 1290 | } else { |
1291 | 1291 | return $result; |
1292 | 1292 | } |
@@ -1298,18 +1298,18 @@ discard block |
||
1298 | 1298 | * |
1299 | 1299 | * @param int $mapping_id |
1300 | 1300 | */ |
1301 | - public function refresh_mapped_data( $mapping_id = '' ) { |
|
1302 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1303 | - if ( empty( $mapping_id ) ) { |
|
1304 | - $mapping_id = isset( $post_data['mapping_id'] ) ? absint( $post_data['mapping_id'] ) : ''; |
|
1301 | + public function refresh_mapped_data($mapping_id = '') { |
|
1302 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1303 | + if (empty($mapping_id)) { |
|
1304 | + $mapping_id = isset($post_data['mapping_id']) ? absint($post_data['mapping_id']) : ''; |
|
1305 | 1305 | } |
1306 | 1306 | $result = $this->mappings->get_object_maps( |
1307 | 1307 | array( |
1308 | 1308 | 'id' => $mapping_id, |
1309 | 1309 | ) |
1310 | 1310 | ); |
1311 | - if ( ! empty( $post_data ) ) { |
|
1312 | - wp_send_json_success( $result ); |
|
1311 | + if ( ! empty($post_data)) { |
|
1312 | + wp_send_json_success($result); |
|
1313 | 1313 | } else { |
1314 | 1314 | return $result; |
1315 | 1315 | } |
@@ -1325,47 +1325,47 @@ discard block |
||
1325 | 1325 | */ |
1326 | 1326 | public function prepare_fieldmap_data() { |
1327 | 1327 | $error = false; |
1328 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1329 | - $cachekey = md5( wp_json_encode( $post_data ) ); |
|
1328 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1329 | + $cachekey = md5(wp_json_encode($post_data)); |
|
1330 | 1330 | |
1331 | - if ( ! isset( $post_data['label'] ) || ! isset( $post_data['salesforce_object'] ) || ! isset( $post_data['wordpress_object'] ) ) { |
|
1331 | + if ( ! isset($post_data['label']) || ! isset($post_data['salesforce_object']) || ! isset($post_data['wordpress_object'])) { |
|
1332 | 1332 | $error = true; |
1333 | 1333 | } |
1334 | - if ( true === $error ) { |
|
1335 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1336 | - if ( '' !== $cachekey ) { |
|
1337 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&transient=' . $cachekey; |
|
1334 | + if (true === $error) { |
|
1335 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1336 | + if ('' !== $cachekey) { |
|
1337 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&transient=' . $cachekey; |
|
1338 | 1338 | } |
1339 | 1339 | } else { // there are no errors |
1340 | 1340 | // send the row to the fieldmap class |
1341 | 1341 | // if it is add or clone, use the create method |
1342 | - $method = esc_attr( $post_data['method'] ); |
|
1342 | + $method = esc_attr($post_data['method']); |
|
1343 | 1343 | $salesforce_fields = $this->get_salesforce_object_fields( |
1344 | 1344 | array( |
1345 | 1345 | 'salesforce_object' => $post_data['salesforce_object'], |
1346 | 1346 | ) |
1347 | 1347 | ); |
1348 | - $wordpress_fields = $this->get_wordpress_object_fields( $post_data['wordpress_object'] ); |
|
1349 | - if ( 'add' === $method || 'clone' === $method ) { |
|
1350 | - $result = $this->mappings->create_fieldmap( $post_data, $wordpress_fields, $salesforce_fields ); |
|
1351 | - } elseif ( 'edit' === $method ) { // if it is edit, use the update method |
|
1352 | - $id = esc_attr( $post_data['id'] ); |
|
1353 | - $result = $this->mappings->update_fieldmap( $post_data, $wordpress_fields, $salesforce_fields, $id ); |
|
1348 | + $wordpress_fields = $this->get_wordpress_object_fields($post_data['wordpress_object']); |
|
1349 | + if ('add' === $method || 'clone' === $method) { |
|
1350 | + $result = $this->mappings->create_fieldmap($post_data, $wordpress_fields, $salesforce_fields); |
|
1351 | + } elseif ('edit' === $method) { // if it is edit, use the update method |
|
1352 | + $id = esc_attr($post_data['id']); |
|
1353 | + $result = $this->mappings->update_fieldmap($post_data, $wordpress_fields, $salesforce_fields, $id); |
|
1354 | 1354 | } |
1355 | - if ( false === $result ) { // if the database didn't save, it's still an error |
|
1356 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1357 | - if ( '' !== $cachekey ) { |
|
1358 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&transient=' . $cachekey; |
|
1355 | + if (false === $result) { // if the database didn't save, it's still an error |
|
1356 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1357 | + if ('' !== $cachekey) { |
|
1358 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&transient=' . $cachekey; |
|
1359 | 1359 | } |
1360 | 1360 | } else { |
1361 | - if ( isset( $post_data['transient'] ) ) { // there was previously an error saved. can delete it now. |
|
1362 | - $this->sfwp_transients->delete( esc_attr( $post_data['map_transient'] ) ); |
|
1361 | + if (isset($post_data['transient'])) { // there was previously an error saved. can delete it now. |
|
1362 | + $this->sfwp_transients->delete(esc_attr($post_data['map_transient'])); |
|
1363 | 1363 | } |
1364 | 1364 | // then send the user to the list of fieldmaps |
1365 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1365 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1366 | 1366 | } |
1367 | 1367 | } |
1368 | - wp_safe_redirect( $url ); |
|
1368 | + wp_safe_redirect($url); |
|
1369 | 1369 | exit(); |
1370 | 1370 | } |
1371 | 1371 | |
@@ -1377,15 +1377,15 @@ discard block |
||
1377 | 1377 | * |
1378 | 1378 | */ |
1379 | 1379 | public function delete_fieldmap() { |
1380 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1381 | - if ( $post_data['id'] ) { |
|
1382 | - $result = $this->mappings->delete_fieldmap( $post_data['id'] ); |
|
1383 | - if ( true === $result ) { |
|
1384 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1380 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1381 | + if ($post_data['id']) { |
|
1382 | + $result = $this->mappings->delete_fieldmap($post_data['id']); |
|
1383 | + if (true === $result) { |
|
1384 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1385 | 1385 | } else { |
1386 | - $url = esc_url_raw( $post_data['redirect_url_error'] . '&id=' . $post_data['id'] ); |
|
1386 | + $url = esc_url_raw($post_data['redirect_url_error'] . '&id=' . $post_data['id']); |
|
1387 | 1387 | } |
1388 | - wp_safe_redirect( $url ); |
|
1388 | + wp_safe_redirect($url); |
|
1389 | 1389 | exit(); |
1390 | 1390 | } |
1391 | 1391 | } |
@@ -1400,38 +1400,38 @@ discard block |
||
1400 | 1400 | */ |
1401 | 1401 | public function prepare_object_map_data() { |
1402 | 1402 | $error = false; |
1403 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1404 | - $cachekey = md5( wp_json_encode( $post_data ) ); |
|
1403 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1404 | + $cachekey = md5(wp_json_encode($post_data)); |
|
1405 | 1405 | |
1406 | - if ( ! isset( $post_data['wordpress_id'] ) || ! isset( $post_data['salesforce_id'] ) ) { |
|
1406 | + if ( ! isset($post_data['wordpress_id']) || ! isset($post_data['salesforce_id'])) { |
|
1407 | 1407 | $error = true; |
1408 | 1408 | } |
1409 | - if ( true === $error ) { |
|
1410 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1411 | - if ( '' !== $cachekey ) { |
|
1412 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&map_transient=' . $cachekey; |
|
1409 | + if (true === $error) { |
|
1410 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1411 | + if ('' !== $cachekey) { |
|
1412 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&map_transient=' . $cachekey; |
|
1413 | 1413 | } |
1414 | 1414 | } else { // there are no errors |
1415 | 1415 | // send the row to the object map class |
1416 | - $method = esc_attr( $post_data['method'] ); |
|
1417 | - if ( 'edit' === $method ) { // if it is edit, use the update method |
|
1418 | - $id = esc_attr( $post_data['id'] ); |
|
1419 | - $result = $this->mappings->update_object_map( $post_data, $id ); |
|
1416 | + $method = esc_attr($post_data['method']); |
|
1417 | + if ('edit' === $method) { // if it is edit, use the update method |
|
1418 | + $id = esc_attr($post_data['id']); |
|
1419 | + $result = $this->mappings->update_object_map($post_data, $id); |
|
1420 | 1420 | } |
1421 | - if ( false === $result ) { // if the database didn't save, it's still an error |
|
1422 | - $this->sfwp_transients->set( $cachekey, $post_data, $this->wordpress->options['cache_expiration'] ); |
|
1423 | - if ( '' !== $cachekey ) { |
|
1424 | - $url = esc_url_raw( $post_data['redirect_url_error'] ) . '&map_transient=' . $cachekey; |
|
1421 | + if (false === $result) { // if the database didn't save, it's still an error |
|
1422 | + $this->sfwp_transients->set($cachekey, $post_data, $this->wordpress->options['cache_expiration']); |
|
1423 | + if ('' !== $cachekey) { |
|
1424 | + $url = esc_url_raw($post_data['redirect_url_error']) . '&map_transient=' . $cachekey; |
|
1425 | 1425 | } |
1426 | 1426 | } else { |
1427 | - if ( isset( $post_data['map_transient'] ) ) { // there was previously an error saved. can delete it now. |
|
1428 | - $this->sfwp_transients->delete( esc_attr( $post_data['map_transient'] ) ); |
|
1427 | + if (isset($post_data['map_transient'])) { // there was previously an error saved. can delete it now. |
|
1428 | + $this->sfwp_transients->delete(esc_attr($post_data['map_transient'])); |
|
1429 | 1429 | } |
1430 | 1430 | // then send the user to the success redirect url |
1431 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1431 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1432 | 1432 | } |
1433 | 1433 | } |
1434 | - wp_safe_redirect( $url ); |
|
1434 | + wp_safe_redirect($url); |
|
1435 | 1435 | exit(); |
1436 | 1436 | } |
1437 | 1437 | |
@@ -1443,15 +1443,15 @@ discard block |
||
1443 | 1443 | * |
1444 | 1444 | */ |
1445 | 1445 | public function delete_object_map() { |
1446 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1447 | - if ( $post_data['id'] ) { |
|
1448 | - $result = $this->mappings->delete_object_map( $post_data['id'] ); |
|
1449 | - if ( true === $result ) { |
|
1450 | - $url = esc_url_raw( $post_data['redirect_url_success'] ); |
|
1446 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1447 | + if ($post_data['id']) { |
|
1448 | + $result = $this->mappings->delete_object_map($post_data['id']); |
|
1449 | + if (true === $result) { |
|
1450 | + $url = esc_url_raw($post_data['redirect_url_success']); |
|
1451 | 1451 | } else { |
1452 | - $url = esc_url_raw( $post_data['redirect_url_error'] . '&id=' . $post_data['id'] ); |
|
1452 | + $url = esc_url_raw($post_data['redirect_url_error'] . '&id=' . $post_data['id']); |
|
1453 | 1453 | } |
1454 | - wp_safe_redirect( $url ); |
|
1454 | + wp_safe_redirect($url); |
|
1455 | 1455 | exit(); |
1456 | 1456 | } |
1457 | 1457 | } |
@@ -1462,95 +1462,95 @@ discard block |
||
1462 | 1462 | */ |
1463 | 1463 | public function import_json_file() { |
1464 | 1464 | |
1465 | - if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_import'], 'object_sync_for_salesforce_nonce_import' ) ) { |
|
1465 | + if ( ! wp_verify_nonce($_POST['object_sync_for_salesforce_nonce_import'], 'object_sync_for_salesforce_nonce_import')) { |
|
1466 | 1466 | return; |
1467 | 1467 | } |
1468 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1468 | + if ( ! current_user_can('manage_options')) { |
|
1469 | 1469 | return; |
1470 | 1470 | } |
1471 | 1471 | $path = $_FILES['import_file']['name']; |
1472 | - $extension = pathinfo( $path, PATHINFO_EXTENSION ); |
|
1473 | - if ( 'json' !== $extension ) { |
|
1474 | - wp_die( __( 'Please upload a valid .json file' ) ); |
|
1472 | + $extension = pathinfo($path, PATHINFO_EXTENSION); |
|
1473 | + if ('json' !== $extension) { |
|
1474 | + wp_die(__('Please upload a valid .json file')); |
|
1475 | 1475 | } |
1476 | 1476 | |
1477 | 1477 | $import_file = $_FILES['import_file']['tmp_name']; |
1478 | - if ( empty( $import_file ) ) { |
|
1479 | - wp_die( __( 'Please upload a file to import' ) ); |
|
1478 | + if (empty($import_file)) { |
|
1479 | + wp_die(__('Please upload a file to import')); |
|
1480 | 1480 | } |
1481 | 1481 | |
1482 | 1482 | // Retrieve the data from the file and convert the json object to an array. |
1483 | - $data = (array) json_decode( file_get_contents( $import_file ), true ); |
|
1483 | + $data = (array) json_decode(file_get_contents($import_file), true); |
|
1484 | 1484 | |
1485 | 1485 | // if there is only one object map, fix the array |
1486 | - if ( isset( $data['object_maps'] ) ) { |
|
1487 | - if ( count( $data['object_maps'] ) === count( $data['object_maps'], COUNT_RECURSIVE ) ) { |
|
1488 | - $data['object_maps'] = array( 0 => $data['object_maps'] ); |
|
1486 | + if (isset($data['object_maps'])) { |
|
1487 | + if (count($data['object_maps']) === count($data['object_maps'], COUNT_RECURSIVE)) { |
|
1488 | + $data['object_maps'] = array(0 => $data['object_maps']); |
|
1489 | 1489 | } |
1490 | 1490 | } |
1491 | 1491 | |
1492 | - $overwrite = isset( $_POST['overwrite'] ) ? esc_attr( $_POST['overwrite'] ) : ''; |
|
1493 | - if ( '1' === $overwrite ) { |
|
1494 | - if ( isset( $data['fieldmaps'] ) ) { |
|
1492 | + $overwrite = isset($_POST['overwrite']) ? esc_attr($_POST['overwrite']) : ''; |
|
1493 | + if ('1' === $overwrite) { |
|
1494 | + if (isset($data['fieldmaps'])) { |
|
1495 | 1495 | $fieldmaps = $this->mappings->get_fieldmaps(); |
1496 | - foreach ( $fieldmaps as $fieldmap ) { |
|
1496 | + foreach ($fieldmaps as $fieldmap) { |
|
1497 | 1497 | $id = $fieldmap['id']; |
1498 | - $delete = $this->mappings->delete_fieldmap( $id ); |
|
1498 | + $delete = $this->mappings->delete_fieldmap($id); |
|
1499 | 1499 | } |
1500 | 1500 | } |
1501 | - if ( isset( $data['object_maps'] ) ) { |
|
1501 | + if (isset($data['object_maps'])) { |
|
1502 | 1502 | $object_maps = $this->mappings->get_object_maps(); |
1503 | 1503 | |
1504 | 1504 | // if there is only one existing object map, fix the array |
1505 | - if ( count( $object_maps ) === count( $object_maps, COUNT_RECURSIVE ) ) { |
|
1506 | - $object_maps = array( 0 => $object_maps ); |
|
1505 | + if (count($object_maps) === count($object_maps, COUNT_RECURSIVE)) { |
|
1506 | + $object_maps = array(0 => $object_maps); |
|
1507 | 1507 | } |
1508 | 1508 | |
1509 | - foreach ( $object_maps as $object_map ) { |
|
1509 | + foreach ($object_maps as $object_map) { |
|
1510 | 1510 | $id = $object_map['id']; |
1511 | - $delete = $this->mappings->delete_object_map( $id ); |
|
1511 | + $delete = $this->mappings->delete_object_map($id); |
|
1512 | 1512 | } |
1513 | 1513 | } |
1514 | - if ( isset( $data['plugin_settings'] ) ) { |
|
1515 | - foreach ( $data['plugin_settings'] as $key => $value ) { |
|
1516 | - delete_option( $value['option_name'] ); |
|
1514 | + if (isset($data['plugin_settings'])) { |
|
1515 | + foreach ($data['plugin_settings'] as $key => $value) { |
|
1516 | + delete_option($value['option_name']); |
|
1517 | 1517 | } |
1518 | 1518 | } |
1519 | 1519 | } |
1520 | 1520 | |
1521 | 1521 | $success = true; |
1522 | 1522 | |
1523 | - if ( isset( $data['fieldmaps'] ) ) { |
|
1524 | - foreach ( $data['fieldmaps'] as $fieldmap ) { |
|
1525 | - unset( $fieldmap['id'] ); |
|
1526 | - $create = $this->mappings->create_fieldmap( $fieldmap ); |
|
1527 | - if ( false === $create ) { |
|
1523 | + if (isset($data['fieldmaps'])) { |
|
1524 | + foreach ($data['fieldmaps'] as $fieldmap) { |
|
1525 | + unset($fieldmap['id']); |
|
1526 | + $create = $this->mappings->create_fieldmap($fieldmap); |
|
1527 | + if (false === $create) { |
|
1528 | 1528 | $success = false; |
1529 | 1529 | } |
1530 | 1530 | } |
1531 | 1531 | } |
1532 | 1532 | |
1533 | - if ( isset( $data['object_maps'] ) ) { |
|
1534 | - foreach ( $data['object_maps'] as $object_map ) { |
|
1535 | - unset( $object_map['id'] ); |
|
1536 | - $create = $this->mappings->create_object_map( $object_map ); |
|
1537 | - if ( false === $create ) { |
|
1533 | + if (isset($data['object_maps'])) { |
|
1534 | + foreach ($data['object_maps'] as $object_map) { |
|
1535 | + unset($object_map['id']); |
|
1536 | + $create = $this->mappings->create_object_map($object_map); |
|
1537 | + if (false === $create) { |
|
1538 | 1538 | $success = false; |
1539 | 1539 | } |
1540 | 1540 | } |
1541 | 1541 | } |
1542 | 1542 | |
1543 | - if ( isset( $data['plugin_settings'] ) ) { |
|
1544 | - foreach ( $data['plugin_settings'] as $key => $value ) { |
|
1545 | - update_option( $value['option_name'], maybe_unserialize( $value['option_value'] ), $value['autoload'] ); |
|
1543 | + if (isset($data['plugin_settings'])) { |
|
1544 | + foreach ($data['plugin_settings'] as $key => $value) { |
|
1545 | + update_option($value['option_name'], maybe_unserialize($value['option_value']), $value['autoload']); |
|
1546 | 1546 | } |
1547 | 1547 | } |
1548 | 1548 | |
1549 | - if ( true === $success ) { |
|
1550 | - wp_safe_redirect( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=true' ) ); |
|
1549 | + if (true === $success) { |
|
1550 | + wp_safe_redirect(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=true')); |
|
1551 | 1551 | exit; |
1552 | 1552 | } else { |
1553 | - wp_safe_redirect( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=false' ) ); |
|
1553 | + wp_safe_redirect(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=import-export&data_saved=false')); |
|
1554 | 1554 | exit; |
1555 | 1555 | } |
1556 | 1556 | |
@@ -1562,28 +1562,28 @@ discard block |
||
1562 | 1562 | */ |
1563 | 1563 | public function export_json_file() { |
1564 | 1564 | |
1565 | - if ( ! wp_verify_nonce( $_POST['object_sync_for_salesforce_nonce_export'], 'object_sync_for_salesforce_nonce_export' ) ) { |
|
1565 | + if ( ! wp_verify_nonce($_POST['object_sync_for_salesforce_nonce_export'], 'object_sync_for_salesforce_nonce_export')) { |
|
1566 | 1566 | return; |
1567 | 1567 | } |
1568 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1568 | + if ( ! current_user_can('manage_options')) { |
|
1569 | 1569 | return; |
1570 | 1570 | } |
1571 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1571 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1572 | 1572 | $export = array(); |
1573 | - if ( in_array( 'fieldmaps', $post_data['export'] ) ) { |
|
1573 | + if (in_array('fieldmaps', $post_data['export'])) { |
|
1574 | 1574 | $export['fieldmaps'] = $this->mappings->get_fieldmaps(); |
1575 | 1575 | } |
1576 | - if ( in_array( 'object_maps', $post_data['export'] ) ) { |
|
1576 | + if (in_array('object_maps', $post_data['export'])) { |
|
1577 | 1577 | $export['object_maps'] = $this->mappings->get_object_maps(); |
1578 | 1578 | } |
1579 | - if ( in_array( 'plugin_settings', $post_data['export'] ) ) { |
|
1580 | - $export['plugin_settings'] = $this->wpdb->get_results( 'SELECT * FROM ' . $this->wpdb->prefix . 'options' . ' WHERE option_name like "' . $this->option_prefix . '%"', ARRAY_A ); |
|
1579 | + if (in_array('plugin_settings', $post_data['export'])) { |
|
1580 | + $export['plugin_settings'] = $this->wpdb->get_results('SELECT * FROM ' . $this->wpdb->prefix . 'options' . ' WHERE option_name like "' . $this->option_prefix . '%"', ARRAY_A); |
|
1581 | 1581 | } |
1582 | 1582 | nocache_headers(); |
1583 | - header( 'Content-Type: application/json; charset=utf-8' ); |
|
1584 | - header( 'Content-Disposition: attachment; filename=object-sync-for-salesforce-data-export-' . date( 'm-d-Y' ) . '.json' ); |
|
1585 | - header( 'Expires: 0' ); |
|
1586 | - echo wp_json_encode( $export ); |
|
1583 | + header('Content-Type: application/json; charset=utf-8'); |
|
1584 | + header('Content-Disposition: attachment; filename=object-sync-for-salesforce-data-export-' . date('m-d-Y') . '.json'); |
|
1585 | + header('Expires: 0'); |
|
1586 | + echo wp_json_encode($export); |
|
1587 | 1587 | exit; |
1588 | 1588 | } |
1589 | 1589 | |
@@ -1592,7 +1592,7 @@ discard block |
||
1592 | 1592 | * |
1593 | 1593 | * @param array $args |
1594 | 1594 | */ |
1595 | - public function display_input_field( $args ) { |
|
1595 | + public function display_input_field($args) { |
|
1596 | 1596 | $type = $args['type']; |
1597 | 1597 | $id = $args['label_for']; |
1598 | 1598 | $name = $args['name']; |
@@ -1601,38 +1601,38 @@ discard block |
||
1601 | 1601 | |
1602 | 1602 | $class = 'regular-text'; |
1603 | 1603 | |
1604 | - if ( 'checkbox' === $type ) { |
|
1604 | + if ('checkbox' === $type) { |
|
1605 | 1605 | $class = 'checkbox'; |
1606 | 1606 | } |
1607 | 1607 | |
1608 | - if ( ! isset( $args['constant'] ) || ! defined( $args['constant'] ) ) { |
|
1609 | - $value = esc_attr( get_option( $id, '' ) ); |
|
1610 | - if ( 'checkbox' === $type ) { |
|
1611 | - if ( '1' === $value ) { |
|
1608 | + if ( ! isset($args['constant']) || ! defined($args['constant'])) { |
|
1609 | + $value = esc_attr(get_option($id, '')); |
|
1610 | + if ('checkbox' === $type) { |
|
1611 | + if ('1' === $value) { |
|
1612 | 1612 | $checked = 'checked '; |
1613 | 1613 | } |
1614 | 1614 | $value = 1; |
1615 | 1615 | } |
1616 | - if ( '' === $value && isset( $args['default'] ) && '' !== $args['default'] ) { |
|
1616 | + if ('' === $value && isset($args['default']) && '' !== $args['default']) { |
|
1617 | 1617 | $value = $args['default']; |
1618 | 1618 | } |
1619 | 1619 | |
1620 | - echo sprintf( '<input type="%1$s" value="%2$s" name="%3$s" id="%4$s" class="%5$s"%6$s>', |
|
1621 | - esc_attr( $type ), |
|
1622 | - esc_attr( $value ), |
|
1623 | - esc_attr( $name ), |
|
1624 | - esc_attr( $id ), |
|
1625 | - sanitize_html_class( $class . esc_html( ' code' ) ), |
|
1626 | - esc_html( $checked ) |
|
1620 | + echo sprintf('<input type="%1$s" value="%2$s" name="%3$s" id="%4$s" class="%5$s"%6$s>', |
|
1621 | + esc_attr($type), |
|
1622 | + esc_attr($value), |
|
1623 | + esc_attr($name), |
|
1624 | + esc_attr($id), |
|
1625 | + sanitize_html_class($class . esc_html(' code')), |
|
1626 | + esc_html($checked) |
|
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 | } else { |
1634 | - echo sprintf( '<p><code>%1$s</code></p>', |
|
1635 | - esc_html__( 'Defined in wp-config.php', 'object-sync-for-salesforce' ) |
|
1634 | + echo sprintf('<p><code>%1$s</code></p>', |
|
1635 | + esc_html__('Defined in wp-config.php', 'object-sync-for-salesforce') |
|
1636 | 1636 | ); |
1637 | 1637 | } |
1638 | 1638 | } |
@@ -1643,33 +1643,33 @@ discard block |
||
1643 | 1643 | * |
1644 | 1644 | * @param array $args |
1645 | 1645 | */ |
1646 | - public function display_checkboxes( $args ) { |
|
1646 | + public function display_checkboxes($args) { |
|
1647 | 1647 | $type = 'checkbox'; |
1648 | 1648 | $name = $args['name']; |
1649 | - $options = get_option( $name, array() ); |
|
1650 | - foreach ( $args['items'] as $key => $value ) { |
|
1649 | + $options = get_option($name, array()); |
|
1650 | + foreach ($args['items'] as $key => $value) { |
|
1651 | 1651 | $text = $value['text']; |
1652 | 1652 | $id = $value['id']; |
1653 | 1653 | $desc = $value['desc']; |
1654 | 1654 | $checked = ''; |
1655 | - if ( is_array( $options ) && in_array( (string) $key, $options, true ) ) { |
|
1655 | + if (is_array($options) && in_array((string) $key, $options, true)) { |
|
1656 | 1656 | $checked = 'checked'; |
1657 | - } elseif ( is_array( $options ) && empty( $options ) ) { |
|
1658 | - if ( isset( $value['default'] ) && true === $value['default'] ) { |
|
1657 | + } elseif (is_array($options) && empty($options)) { |
|
1658 | + if (isset($value['default']) && true === $value['default']) { |
|
1659 | 1659 | $checked = 'checked'; |
1660 | 1660 | } |
1661 | 1661 | } |
1662 | - 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>', |
|
1663 | - esc_attr( $type ), |
|
1664 | - esc_attr( $key ), |
|
1665 | - esc_attr( $name ), |
|
1666 | - esc_attr( $id ), |
|
1667 | - esc_html( $checked ), |
|
1668 | - esc_html( $text ) |
|
1662 | + 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>', |
|
1663 | + esc_attr($type), |
|
1664 | + esc_attr($key), |
|
1665 | + esc_attr($name), |
|
1666 | + esc_attr($id), |
|
1667 | + esc_html($checked), |
|
1668 | + esc_html($text) |
|
1669 | 1669 | ); |
1670 | - if ( '' !== $desc ) { |
|
1671 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1672 | - esc_html( $desc ) |
|
1670 | + if ('' !== $desc) { |
|
1671 | + echo sprintf('<p class="description">%1$s</p>', |
|
1672 | + esc_html($desc) |
|
1673 | 1673 | ); |
1674 | 1674 | } |
1675 | 1675 | } |
@@ -1680,44 +1680,44 @@ discard block |
||
1680 | 1680 | * |
1681 | 1681 | * @param array $args |
1682 | 1682 | */ |
1683 | - public function display_select( $args ) { |
|
1683 | + public function display_select($args) { |
|
1684 | 1684 | $type = $args['type']; |
1685 | 1685 | $id = $args['label_for']; |
1686 | 1686 | $name = $args['name']; |
1687 | 1687 | $desc = $args['desc']; |
1688 | - if ( ! isset( $args['constant'] ) || ! defined( $args['constant'] ) ) { |
|
1689 | - $current_value = get_option( $name ); |
|
1688 | + if ( ! isset($args['constant']) || ! defined($args['constant'])) { |
|
1689 | + $current_value = get_option($name); |
|
1690 | 1690 | |
1691 | - echo sprintf( '<div class="select"><select id="%1$s" name="%2$s"><option value="">- ' . __( 'Select one', 'object-sync-for-salesforce' ) . ' -</option>', |
|
1692 | - esc_attr( $id ), |
|
1693 | - esc_attr( $name ) |
|
1691 | + echo sprintf('<div class="select"><select id="%1$s" name="%2$s"><option value="">- ' . __('Select one', 'object-sync-for-salesforce') . ' -</option>', |
|
1692 | + esc_attr($id), |
|
1693 | + esc_attr($name) |
|
1694 | 1694 | ); |
1695 | 1695 | |
1696 | - foreach ( $args['items'] as $key => $value ) { |
|
1696 | + foreach ($args['items'] as $key => $value) { |
|
1697 | 1697 | $text = $value['text']; |
1698 | 1698 | $value = $value['value']; |
1699 | 1699 | $selected = ''; |
1700 | - if ( $key === $current_value || $value === $current_value ) { |
|
1700 | + if ($key === $current_value || $value === $current_value) { |
|
1701 | 1701 | $selected = ' selected'; |
1702 | 1702 | } |
1703 | 1703 | |
1704 | - echo sprintf( '<option value="%1$s"%2$s>%3$s</option>', |
|
1705 | - esc_attr( $value ), |
|
1706 | - esc_attr( $selected ), |
|
1707 | - esc_html( $text ) |
|
1704 | + echo sprintf('<option value="%1$s"%2$s>%3$s</option>', |
|
1705 | + esc_attr($value), |
|
1706 | + esc_attr($selected), |
|
1707 | + esc_html($text) |
|
1708 | 1708 | ); |
1709 | 1709 | |
1710 | 1710 | } |
1711 | 1711 | echo '</select>'; |
1712 | - if ( '' !== $desc ) { |
|
1713 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1714 | - esc_html( $desc ) |
|
1712 | + if ('' !== $desc) { |
|
1713 | + echo sprintf('<p class="description">%1$s</p>', |
|
1714 | + esc_html($desc) |
|
1715 | 1715 | ); |
1716 | 1716 | } |
1717 | 1717 | echo '</div>'; |
1718 | 1718 | } else { |
1719 | - echo sprintf( '<p><code>%1$s</code></p>', |
|
1720 | - esc_html__( 'Defined in wp-config.php', 'object-sync-for-salesforce' ) |
|
1719 | + echo sprintf('<p><code>%1$s</code></p>', |
|
1720 | + esc_html__('Defined in wp-config.php', 'object-sync-for-salesforce') |
|
1721 | 1721 | ); |
1722 | 1722 | } |
1723 | 1723 | } |
@@ -1730,7 +1730,7 @@ discard block |
||
1730 | 1730 | private function version_options() { |
1731 | 1731 | $versions = $this->salesforce['sfapi']->get_api_versions(); |
1732 | 1732 | $args = array(); |
1733 | - foreach ( $versions['data'] as $key => $value ) { |
|
1733 | + foreach ($versions['data'] as $key => $value) { |
|
1734 | 1734 | $args[] = array( |
1735 | 1735 | 'value' => $value['version'], |
1736 | 1736 | 'text' => $value['label'] . ' (' . $value['version'] . ')', |
@@ -1744,26 +1744,26 @@ discard block |
||
1744 | 1744 | * |
1745 | 1745 | * @param array $args |
1746 | 1746 | */ |
1747 | - public function display_link( $args ) { |
|
1747 | + public function display_link($args) { |
|
1748 | 1748 | $label = $args['label']; |
1749 | 1749 | $desc = $args['desc']; |
1750 | 1750 | $url = $args['url']; |
1751 | - if ( isset( $args['link_class'] ) ) { |
|
1752 | - echo sprintf( '<p><a class="%1$s" href="%2$s">%3$s</a></p>', |
|
1753 | - esc_attr( $args['link_class'] ), |
|
1754 | - esc_url( $url ), |
|
1755 | - esc_html( $label ) |
|
1751 | + if (isset($args['link_class'])) { |
|
1752 | + echo sprintf('<p><a class="%1$s" href="%2$s">%3$s</a></p>', |
|
1753 | + esc_attr($args['link_class']), |
|
1754 | + esc_url($url), |
|
1755 | + esc_html($label) |
|
1756 | 1756 | ); |
1757 | 1757 | } else { |
1758 | - echo sprintf( '<p><a href="%1$s">%2$s</a></p>', |
|
1759 | - esc_url( $url ), |
|
1760 | - esc_html( $label ) |
|
1758 | + echo sprintf('<p><a href="%1$s">%2$s</a></p>', |
|
1759 | + esc_url($url), |
|
1760 | + esc_html($label) |
|
1761 | 1761 | ); |
1762 | 1762 | } |
1763 | 1763 | |
1764 | - if ( '' !== $desc ) { |
|
1765 | - echo sprintf( '<p class="description">%1$s</p>', |
|
1766 | - esc_html( $desc ) |
|
1764 | + if ('' !== $desc) { |
|
1765 | + echo sprintf('<p class="description">%1$s</p>', |
|
1766 | + esc_html($desc) |
|
1767 | 1767 | ); |
1768 | 1768 | } |
1769 | 1769 | |
@@ -1775,15 +1775,15 @@ discard block |
||
1775 | 1775 | * @param string $option |
1776 | 1776 | * @return string $option |
1777 | 1777 | */ |
1778 | - public function sanitize_validate_text( $option ) { |
|
1779 | - if ( is_array( $option ) ) { |
|
1778 | + public function sanitize_validate_text($option) { |
|
1779 | + if (is_array($option)) { |
|
1780 | 1780 | $options = array(); |
1781 | - foreach ( $option as $key => $value ) { |
|
1782 | - $options[ $key ] = sanitize_text_field( $value ); |
|
1781 | + foreach ($option as $key => $value) { |
|
1782 | + $options[$key] = sanitize_text_field($value); |
|
1783 | 1783 | } |
1784 | 1784 | return $options; |
1785 | 1785 | } |
1786 | - $option = sanitize_text_field( $option ); |
|
1786 | + $option = sanitize_text_field($option); |
|
1787 | 1787 | return $option; |
1788 | 1788 | } |
1789 | 1789 | |
@@ -1792,60 +1792,60 @@ discard block |
||
1792 | 1792 | * |
1793 | 1793 | * @param object $sfapi |
1794 | 1794 | */ |
1795 | - private function status( $sfapi ) { |
|
1795 | + private function status($sfapi) { |
|
1796 | 1796 | |
1797 | 1797 | $versions = $sfapi->get_api_versions(); |
1798 | 1798 | |
1799 | 1799 | // format this array into text so users can see the versions |
1800 | - if ( true === $versions['cached'] ) { |
|
1801 | - $versions_is_cached = esc_html__( 'This list is cached, and', 'object-sync-salesforce' ); |
|
1800 | + if (true === $versions['cached']) { |
|
1801 | + $versions_is_cached = esc_html__('This list is cached, and', 'object-sync-salesforce'); |
|
1802 | 1802 | } else { |
1803 | - $versions_is_cached = esc_html__( 'This list is not cached, but', 'object-sync-salesforce' ); |
|
1803 | + $versions_is_cached = esc_html__('This list is not cached, but', 'object-sync-salesforce'); |
|
1804 | 1804 | } |
1805 | 1805 | |
1806 | - if ( true === $versions['from_cache'] ) { |
|
1807 | - $versions_from_cache = esc_html__( 'items were loaded from the cache', 'object-sync-salesforce' ); |
|
1806 | + if (true === $versions['from_cache']) { |
|
1807 | + $versions_from_cache = esc_html__('items were loaded from the cache', 'object-sync-salesforce'); |
|
1808 | 1808 | } else { |
1809 | - $versions_from_cache = esc_html__( 'items were not loaded from the cache', 'object-sync-salesforce' ); |
|
1809 | + $versions_from_cache = esc_html__('items were not loaded from the cache', 'object-sync-salesforce'); |
|
1810 | 1810 | } |
1811 | 1811 | |
1812 | 1812 | // 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 |
1813 | - $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' ), |
|
1813 | + $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'), |
|
1814 | 1814 | $versions_is_cached, |
1815 | 1815 | $versions_from_cache |
1816 | 1816 | ); |
1817 | 1817 | |
1818 | - $contacts = $sfapi->query( 'SELECT Name, Id from Contact LIMIT 100' ); |
|
1818 | + $contacts = $sfapi->query('SELECT Name, Id from Contact LIMIT 100'); |
|
1819 | 1819 | |
1820 | 1820 | // format this array into html so users can see the contacts |
1821 | - if ( true === $contacts['cached'] ) { |
|
1822 | - $contacts_is_cached = esc_html__( 'They are cached, and', 'object-sync-salesforce' ); |
|
1821 | + if (true === $contacts['cached']) { |
|
1822 | + $contacts_is_cached = esc_html__('They are cached, and', 'object-sync-salesforce'); |
|
1823 | 1823 | } else { |
1824 | - $contacts_is_cached = esc_html__( 'They are not cached, but', 'object-sync-salesforce' ); |
|
1824 | + $contacts_is_cached = esc_html__('They are not cached, but', 'object-sync-salesforce'); |
|
1825 | 1825 | } |
1826 | 1826 | |
1827 | - if ( true === $contacts['from_cache'] ) { |
|
1828 | - $contacts_from_cache = esc_html__( 'they were loaded from the cache', 'object-sync-salesforce' ); |
|
1827 | + if (true === $contacts['from_cache']) { |
|
1828 | + $contacts_from_cache = esc_html__('they were loaded from the cache', 'object-sync-salesforce'); |
|
1829 | 1829 | } else { |
1830 | - $contacts_from_cache = esc_html__( 'they were not loaded from the cache', 'object-sync-salesforce' ); |
|
1830 | + $contacts_from_cache = esc_html__('they were not loaded from the cache', 'object-sync-salesforce'); |
|
1831 | 1831 | } |
1832 | 1832 | |
1833 | - if ( true === $contacts['is_redo'] ) { |
|
1834 | - $contacts_refreshed_token = esc_html__( 'This request did require refreshing the Salesforce token', 'object-sync-salesforce' ); |
|
1833 | + if (true === $contacts['is_redo']) { |
|
1834 | + $contacts_refreshed_token = esc_html__('This request did require refreshing the Salesforce token', 'object-sync-salesforce'); |
|
1835 | 1835 | } else { |
1836 | - $contacts_refreshed_token = esc_html__( 'This request did not require refreshing the Salesforce token', 'object-sync-salesforce' ); |
|
1836 | + $contacts_refreshed_token = esc_html__('This request did not require refreshing the Salesforce token', 'object-sync-salesforce'); |
|
1837 | 1837 | } |
1838 | 1838 | |
1839 | 1839 | // 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 |
1840 | - $contacts_apicall_summary = sprintf( esc_html__( 'Salesforce successfully returned %1$s %2$s records. %3$s %4$s. %5$s.', 'object-sync-for-salesforce' ), |
|
1841 | - absint( $contacts['data']['totalSize'] ), |
|
1842 | - esc_html( $contacts['data']['records'][0]['attributes']['type'] ), |
|
1840 | + $contacts_apicall_summary = sprintf(esc_html__('Salesforce successfully returned %1$s %2$s records. %3$s %4$s. %5$s.', 'object-sync-for-salesforce'), |
|
1841 | + absint($contacts['data']['totalSize']), |
|
1842 | + esc_html($contacts['data']['records'][0]['attributes']['type']), |
|
1843 | 1843 | $contacts_is_cached, |
1844 | 1844 | $contacts_from_cache, |
1845 | 1845 | $contacts_refreshed_token |
1846 | 1846 | ); |
1847 | 1847 | |
1848 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/status.php' ); |
|
1848 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/status.php'); |
|
1849 | 1849 | |
1850 | 1850 | } |
1851 | 1851 | |
@@ -1855,12 +1855,12 @@ discard block |
||
1855 | 1855 | * For this plugin at this time, that is the decision we are making: don't do any kind of authorization stuff inside Salesforce |
1856 | 1856 | */ |
1857 | 1857 | private function logout() { |
1858 | - $this->access_token = delete_option( $this->option_prefix . 'access_token' ); |
|
1859 | - $this->instance_url = delete_option( $this->option_prefix . 'instance_url' ); |
|
1860 | - $this->refresh_token = delete_option( $this->option_prefix . 'refresh_token' ); |
|
1861 | - 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>', |
|
1862 | - esc_url( get_admin_url( null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize' ) ), |
|
1863 | - esc_html__( 'Authorize', 'object-sync-for-salesforce' ) |
|
1858 | + $this->access_token = delete_option($this->option_prefix . 'access_token'); |
|
1859 | + $this->instance_url = delete_option($this->option_prefix . 'instance_url'); |
|
1860 | + $this->refresh_token = delete_option($this->option_prefix . 'refresh_token'); |
|
1861 | + 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>', |
|
1862 | + esc_url(get_admin_url(null, 'options-general.php?page=object-sync-salesforce-admin&tab=authorize')), |
|
1863 | + esc_html__('Authorize', 'object-sync-for-salesforce') |
|
1864 | 1864 | ); |
1865 | 1865 | } |
1866 | 1866 | |
@@ -1868,28 +1868,28 @@ discard block |
||
1868 | 1868 | * Ajax call to clear the plugin cache. |
1869 | 1869 | */ |
1870 | 1870 | public function clear_sfwp_cache() { |
1871 | - $result = $this->clear_cache( true ); |
|
1871 | + $result = $this->clear_cache(true); |
|
1872 | 1872 | $response = array( |
1873 | 1873 | 'message' => $result['message'], |
1874 | 1874 | 'success' => $result['success'], |
1875 | 1875 | ); |
1876 | - wp_send_json_success( $response ); |
|
1876 | + wp_send_json_success($response); |
|
1877 | 1877 | } |
1878 | 1878 | |
1879 | 1879 | /** |
1880 | 1880 | * Clear the plugin's cache. |
1881 | 1881 | * This uses the flush method contained in the WordPress cache to clear all of this plugin's cached data. |
1882 | 1882 | */ |
1883 | - private function clear_cache( $ajax = false ) { |
|
1883 | + private function clear_cache($ajax = false) { |
|
1884 | 1884 | $result = (bool) $this->wordpress->sfwp_transients->flush(); |
1885 | - if ( true === $result ) { |
|
1886 | - $message = __( 'The plugin cache has been cleared.', 'object-sync-for-salesforce' ); |
|
1885 | + if (true === $result) { |
|
1886 | + $message = __('The plugin cache has been cleared.', 'object-sync-for-salesforce'); |
|
1887 | 1887 | } else { |
1888 | - $message = __( 'There was an error clearing the plugin cache. Try refreshing this page.', 'object-sync-for-salesforce' ); |
|
1888 | + $message = __('There was an error clearing the plugin cache. Try refreshing this page.', 'object-sync-for-salesforce'); |
|
1889 | 1889 | } |
1890 | - if ( false === $ajax ) { |
|
1890 | + if (false === $ajax) { |
|
1891 | 1891 | // translators: parameter 1 is the result message |
1892 | - echo sprintf( '<p>%1$s</p>', $message ); |
|
1892 | + echo sprintf('<p>%1$s</p>', $message); |
|
1893 | 1893 | } else { |
1894 | 1894 | return array( |
1895 | 1895 | 'message' => $message, |
@@ -1912,7 +1912,7 @@ discard block |
||
1912 | 1912 | // alternatively, other roles can get this capability in whatever other way you like |
1913 | 1913 | // point is: to administer this plugin, you need this capability |
1914 | 1914 | |
1915 | - if ( ! current_user_can( 'configure_salesforce' ) ) { |
|
1915 | + if ( ! current_user_can('configure_salesforce')) { |
|
1916 | 1916 | return false; |
1917 | 1917 | } else { |
1918 | 1918 | return true; |
@@ -1925,23 +1925,23 @@ discard block |
||
1925 | 1925 | * @param object $user |
1926 | 1926 | * |
1927 | 1927 | */ |
1928 | - public function show_salesforce_user_fields( $user ) { |
|
1929 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
1930 | - if ( true === $this->check_wordpress_admin_permissions() ) { |
|
1931 | - $mapping = $this->mappings->load_by_wordpress( 'user', $user->ID ); |
|
1928 | + public function show_salesforce_user_fields($user) { |
|
1929 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
1930 | + if (true === $this->check_wordpress_admin_permissions()) { |
|
1931 | + $mapping = $this->mappings->load_by_wordpress('user', $user->ID); |
|
1932 | 1932 | $fieldmap = $this->mappings->get_fieldmaps( |
1933 | 1933 | null, // id field must be null for multiples |
1934 | 1934 | array( |
1935 | 1935 | 'wordpress_object' => 'user', |
1936 | 1936 | ) |
1937 | 1937 | ); |
1938 | - if ( isset( $mapping['id'] ) && ! isset( $get_data['edit_salesforce_mapping'] ) ) { |
|
1939 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce.php' ); |
|
1940 | - } elseif ( ! empty( $fieldmap ) ) { // is the user mapped to something already? |
|
1941 | - if ( isset( $get_data['edit_salesforce_mapping'] ) && 'true' === sanitize_key( $get_data['edit_salesforce_mapping'] ) ) { |
|
1942 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce-change.php' ); |
|
1938 | + if (isset($mapping['id']) && ! isset($get_data['edit_salesforce_mapping'])) { |
|
1939 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce.php'); |
|
1940 | + } elseif ( ! empty($fieldmap)) { // is the user mapped to something already? |
|
1941 | + if (isset($get_data['edit_salesforce_mapping']) && 'true' === sanitize_key($get_data['edit_salesforce_mapping'])) { |
|
1942 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce-change.php'); |
|
1943 | 1943 | } else { |
1944 | - require_once( plugin_dir_path( __FILE__ ) . '/../templates/admin/user-profile-salesforce-map.php' ); |
|
1944 | + require_once(plugin_dir_path(__FILE__) . '/../templates/admin/user-profile-salesforce-map.php'); |
|
1945 | 1945 | } |
1946 | 1946 | } |
1947 | 1947 | } |
@@ -1952,10 +1952,10 @@ discard block |
||
1952 | 1952 | * @param int $user_id |
1953 | 1953 | * |
1954 | 1954 | */ |
1955 | - public function save_salesforce_user_fields( $user_id ) { |
|
1956 | - $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING ); |
|
1957 | - if ( isset( $post_data['salesforce_update_mapped_user'] ) && '1' === rawurlencode( $post_data['salesforce_update_mapped_user'] ) ) { |
|
1958 | - $mapping_object = $this->mappings->get_object_maps( |
|
1955 | + public function save_salesforce_user_fields($user_id) { |
|
1956 | + $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); |
|
1957 | + if (isset($post_data['salesforce_update_mapped_user']) && '1' === rawurlencode($post_data['salesforce_update_mapped_user'])) { |
|
1958 | + $mapping_object = $this->mappings->get_object_maps( |
|
1959 | 1959 | array( |
1960 | 1960 | 'wordpress_id' => $user_id, |
1961 | 1961 | 'wordpress_object' => 'user', |
@@ -1963,14 +1963,14 @@ discard block |
||
1963 | 1963 | ); |
1964 | 1964 | $mapping_object['salesforce_id'] = $post_data['salesforce_id']; |
1965 | 1965 | |
1966 | - $result = $this->mappings->update_object_map( $mapping_object, $mapping_object['id'] ); |
|
1967 | - } elseif ( isset( $post_data['salesforce_create_mapped_user'] ) && '1' === rawurlencode( $post_data['salesforce_create_mapped_user'] ) ) { |
|
1966 | + $result = $this->mappings->update_object_map($mapping_object, $mapping_object['id']); |
|
1967 | + } elseif (isset($post_data['salesforce_create_mapped_user']) && '1' === rawurlencode($post_data['salesforce_create_mapped_user'])) { |
|
1968 | 1968 | // if a Salesforce ID was entered |
1969 | - if ( isset( $post_data['salesforce_id'] ) && ! empty( $post_data['salesforce_id'] ) ) { |
|
1970 | - $mapping_object = $this->create_object_map( $user_id, 'user', $post_data['salesforce_id'] ); |
|
1971 | - } elseif ( isset( $post_data['push_new_user_to_salesforce'] ) ) { |
|
1969 | + if (isset($post_data['salesforce_id']) && ! empty($post_data['salesforce_id'])) { |
|
1970 | + $mapping_object = $this->create_object_map($user_id, 'user', $post_data['salesforce_id']); |
|
1971 | + } elseif (isset($post_data['push_new_user_to_salesforce'])) { |
|
1972 | 1972 | // otherwise, create a new record in Salesforce |
1973 | - $result = $this->push_to_salesforce( 'user', $user_id ); |
|
1973 | + $result = $this->push_to_salesforce('user', $user_id); |
|
1974 | 1974 | } |
1975 | 1975 | } |
1976 | 1976 | } |
@@ -1980,29 +1980,29 @@ discard block |
||
1980 | 1980 | * @param array $tabs |
1981 | 1981 | * @param string $tab |
1982 | 1982 | */ |
1983 | - private function tabs( $tabs, $tab = '' ) { |
|
1983 | + private function tabs($tabs, $tab = '') { |
|
1984 | 1984 | |
1985 | - $get_data = filter_input_array( INPUT_GET, FILTER_SANITIZE_STRING ); |
|
1985 | + $get_data = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); |
|
1986 | 1986 | $consumer_key = $this->login_credentials['consumer_key']; |
1987 | 1987 | $consumer_secret = $this->login_credentials['consumer_secret']; |
1988 | 1988 | $callback_url = $this->login_credentials['callback_url']; |
1989 | 1989 | |
1990 | 1990 | $current_tab = $tab; |
1991 | 1991 | echo '<h2 class="nav-tab-wrapper">'; |
1992 | - foreach ( $tabs as $tab_key => $tab_caption ) { |
|
1992 | + foreach ($tabs as $tab_key => $tab_caption) { |
|
1993 | 1993 | $active = $current_tab === $tab_key ? ' nav-tab-active' : ''; |
1994 | - if ( 'settings' === $tab_key || ( isset( $consumer_key ) && isset( $consumer_secret ) && ! empty( $consumer_key ) && ! empty( $consumer_secret ) ) ) { |
|
1995 | - echo sprintf( '<a class="nav-tab%1$s" href="%2$s">%3$s</a>', |
|
1996 | - esc_attr( $active ), |
|
1997 | - esc_url( '?page=object-sync-salesforce-admin&tab=' . $tab_key ), |
|
1998 | - esc_html( $tab_caption ) |
|
1994 | + if ('settings' === $tab_key || (isset($consumer_key) && isset($consumer_secret) && ! empty($consumer_key) && ! empty($consumer_secret))) { |
|
1995 | + echo sprintf('<a class="nav-tab%1$s" href="%2$s">%3$s</a>', |
|
1996 | + esc_attr($active), |
|
1997 | + esc_url('?page=object-sync-salesforce-admin&tab=' . $tab_key), |
|
1998 | + esc_html($tab_caption) |
|
1999 | 1999 | ); |
2000 | 2000 | } |
2001 | 2001 | } |
2002 | 2002 | echo '</h2>'; |
2003 | 2003 | |
2004 | - if ( isset( $get_data['tab'] ) ) { |
|
2005 | - $tab = sanitize_key( $get_data['tab'] ); |
|
2004 | + if (isset($get_data['tab'])) { |
|
2005 | + $tab = sanitize_key($get_data['tab']); |
|
2006 | 2006 | } else { |
2007 | 2007 | $tab = ''; |
2008 | 2008 | } |
@@ -2013,13 +2013,13 @@ discard block |
||
2013 | 2013 | * This clears the schedule if the user clicks the button |
2014 | 2014 | * @param string $schedule_name |
2015 | 2015 | */ |
2016 | - private function clear_schedule( $schedule_name = '' ) { |
|
2017 | - if ( '' !== $schedule_name ) { |
|
2018 | - $this->queue->cancel( $schedule_name ); |
|
2016 | + private function clear_schedule($schedule_name = '') { |
|
2017 | + if ('' !== $schedule_name) { |
|
2018 | + $this->queue->cancel($schedule_name); |
|
2019 | 2019 | // translators: $schedule_name is the name of the current queue. Defaults: salesforce_pull, salesforce_push, salesforce |
2020 | - echo sprintf( esc_html__( 'You have cleared the %s schedule.', 'object-sync-for-salesforce' ), esc_html( $schedule_name ) ); |
|
2020 | + echo sprintf(esc_html__('You have cleared the %s schedule.', 'object-sync-for-salesforce'), esc_html($schedule_name)); |
|
2021 | 2021 | } else { |
2022 | - echo esc_html__( 'You need to specify the name of the schedule you want to clear.', 'object-sync-for-salesforce' ); |
|
2022 | + echo esc_html__('You need to specify the name of the schedule you want to clear.', 'object-sync-for-salesforce'); |
|
2023 | 2023 | } |
2024 | 2024 | } |
2025 | 2025 | |
@@ -2028,22 +2028,22 @@ discard block |
||
2028 | 2028 | * @param string $schedule_name |
2029 | 2029 | * @return int $count |
2030 | 2030 | */ |
2031 | - private function get_schedule_count( $schedule_name = '' ) { |
|
2032 | - if ( '' !== $schedule_name ) { |
|
2033 | - $count = count( $this->queue->search( |
|
2031 | + private function get_schedule_count($schedule_name = '') { |
|
2032 | + if ('' !== $schedule_name) { |
|
2033 | + $count = count($this->queue->search( |
|
2034 | 2034 | array( |
2035 | 2035 | 'group' => $schedule_name, |
2036 | 2036 | 'status' => ActionScheduler_Store::STATUS_PENDING, |
2037 | 2037 | ), |
2038 | 2038 | 'ARRAY_A' |
2039 | - ) ); |
|
2040 | - $group_count = count( $this->queue->search( |
|
2039 | + )); |
|
2040 | + $group_count = count($this->queue->search( |
|
2041 | 2041 | array( |
2042 | 2042 | 'group' => $schedule_name . $this->action_group_suffix, |
2043 | 2043 | 'status' => ActionScheduler_Store::STATUS_PENDING, |
2044 | 2044 | ), |
2045 | 2045 | 'ARRAY_A' |
2046 | - ) ); |
|
2046 | + )); |
|
2047 | 2047 | return $count + $group_count; |
2048 | 2048 | } else { |
2049 | 2049 | return 0; |
@@ -2066,17 +2066,17 @@ discard block |
||
2066 | 2066 | * This is the database row for the map object |
2067 | 2067 | * |
2068 | 2068 | */ |
2069 | - private function create_object_map( $wordpress_id, $wordpress_object, $salesforce_id, $action = '' ) { |
|
2069 | + private function create_object_map($wordpress_id, $wordpress_object, $salesforce_id, $action = '') { |
|
2070 | 2070 | // Create object map and save it |
2071 | 2071 | $mapping_object = $this->mappings->create_object_map( |
2072 | 2072 | array( |
2073 | 2073 | 'wordpress_id' => $wordpress_id, // wordpress unique id |
2074 | 2074 | 'salesforce_id' => $salesforce_id, // salesforce unique id. we don't care what kind of object it is at this point |
2075 | 2075 | 'wordpress_object' => $wordpress_object, // keep track of what kind of wp object this is |
2076 | - 'last_sync' => current_time( 'mysql' ), |
|
2076 | + 'last_sync' => current_time('mysql'), |
|
2077 | 2077 | 'last_sync_action' => $action, |
2078 | 2078 | 'last_sync_status' => $this->mappings->status_success, |
2079 | - 'last_sync_message' => __( 'Mapping object updated via function: ', 'object-sync-for-salesforce' ) . __FUNCTION__, |
|
2079 | + 'last_sync_message' => __('Mapping object updated via function: ', 'object-sync-for-salesforce') . __FUNCTION__, |
|
2080 | 2080 | ) |
2081 | 2081 | ); |
2082 | 2082 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Object Sync for Salesforce Queue |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if ( ! defined('ABSPATH')) { |
|
7 | 7 | exit; // Exit if accessed directly. |
8 | 8 | } |
9 | 9 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | protected $option_prefix; |
22 | 22 | protected $schedulable_classes; |
23 | 23 | |
24 | - public function __construct( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ) { |
|
24 | + public function __construct($wpdb, $version, $slug, $option_prefix, $schedulable_classes) { |
|
25 | 25 | $this->wpdb = $wpdb; |
26 | 26 | $this->version = $version; |
27 | 27 | $this->slug = $slug; |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | * |
37 | 37 | */ |
38 | 38 | private function add_actions() { |
39 | - add_filter( 'action_scheduler_queue_runner_batch_size', array( $this, 'action_scheduler_batch_size' ) ); |
|
40 | - add_filter( 'action_scheduler_queue_runner_concurrent_batches', array( $this, 'action_scheduler_concurrent_batches' ) ); |
|
39 | + add_filter('action_scheduler_queue_runner_batch_size', array($this, 'action_scheduler_batch_size')); |
|
40 | + add_filter('action_scheduler_queue_runner_concurrent_batches', array($this, 'action_scheduler_concurrent_batches')); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * @param int $batch_size |
47 | 47 | * @return int $batch_size |
48 | 48 | */ |
49 | - public function action_scheduler_batch_size( $batch_size ) { |
|
49 | + public function action_scheduler_batch_size($batch_size) { |
|
50 | 50 | // default for this library is 20 so that is where we start |
51 | - $batch_size = filter_var( get_option( $this->option_prefix . 'action_scheduler_batch_size', 20 ), FILTER_VALIDATE_INT ); |
|
51 | + $batch_size = filter_var(get_option($this->option_prefix . 'action_scheduler_batch_size', 20), FILTER_VALIDATE_INT); |
|
52 | 52 | return $batch_size; |
53 | 53 | } |
54 | 54 | |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | * @param int $concurrent_batches |
59 | 59 | * @return int $concurrent_batches |
60 | 60 | */ |
61 | - public function action_scheduler_concurrent_batches( $concurrent_batches ) { |
|
61 | + public function action_scheduler_concurrent_batches($concurrent_batches) { |
|
62 | 62 | // default for this library is 5 so that is where we start |
63 | - $concurrent_batches = filter_var( get_option( $this->option_prefix . 'action_scheduler_concurrent_batches', 5 ), FILTER_VALIDATE_INT ); |
|
63 | + $concurrent_batches = filter_var(get_option($this->option_prefix . 'action_scheduler_concurrent_batches', 5), FILTER_VALIDATE_INT); |
|
64 | 64 | return $concurrent_batches; |
65 | 65 | } |
66 | 66 | |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | * @param string $sort Which direction to sort |
72 | 72 | * @return array $this->schedulable_classes |
73 | 73 | */ |
74 | - public function get_frequencies( $unit = 'seconds', $sort = 'asc' ) { |
|
74 | + public function get_frequencies($unit = 'seconds', $sort = 'asc') { |
|
75 | 75 | |
76 | - foreach ( $this->schedulable_classes as $key => $schedule ) { |
|
77 | - $this->schedulable_classes[ $key ]['frequency'] = $this->get_frequency( $key, 'seconds' ); |
|
76 | + foreach ($this->schedulable_classes as $key => $schedule) { |
|
77 | + $this->schedulable_classes[$key]['frequency'] = $this->get_frequency($key, 'seconds'); |
|
78 | 78 | } |
79 | 79 | |
80 | - if ( 'asc' === $sort ) { |
|
81 | - uasort( $this->schedulable_classes, function( $a, $b ) { |
|
80 | + if ('asc' === $sort) { |
|
81 | + uasort($this->schedulable_classes, function($a, $b) { |
|
82 | 82 | // we want zero values at the top of an ascending sort |
83 | - if ( 0 === $a ) { |
|
83 | + if (0 === $a) { |
|
84 | 84 | return 1; |
85 | 85 | } |
86 | - if ( 0 === $b ) { |
|
86 | + if (0 === $b) { |
|
87 | 87 | return -1; |
88 | 88 | } |
89 | 89 | return $a['frequency'] - $b['frequency']; |
90 | 90 | }); |
91 | 91 | } else { |
92 | - uasort( $this->schedulable_classes, function( $a, $b ) { |
|
92 | + uasort($this->schedulable_classes, function($a, $b) { |
|
93 | 93 | return $b['frequency'] - $a['frequency']; |
94 | 94 | }); |
95 | 95 | } |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | * @param string $unit The unit of time |
106 | 106 | * @return int How often it runs in that unit of time |
107 | 107 | */ |
108 | - public function get_frequency( $name, $unit ) { |
|
109 | - $schedule_number = filter_var( get_option( $this->option_prefix . $name . '_schedule_number', '' ), FILTER_VALIDATE_INT ); |
|
110 | - $schedule_unit = get_option( $this->option_prefix . $name . '_schedule_unit', '' ); |
|
108 | + public function get_frequency($name, $unit) { |
|
109 | + $schedule_number = filter_var(get_option($this->option_prefix . $name . '_schedule_number', ''), FILTER_VALIDATE_INT); |
|
110 | + $schedule_unit = get_option($this->option_prefix . $name . '_schedule_unit', ''); |
|
111 | 111 | |
112 | - switch ( $schedule_unit ) { |
|
112 | + switch ($schedule_unit) { |
|
113 | 113 | case 'minutes': |
114 | 114 | $seconds = 60; |
115 | 115 | $minutes = 1; |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | * @param string $group The group to assign this job to. |
141 | 141 | * @return string The action ID. |
142 | 142 | */ |
143 | - public function add( $hook, $args = array(), $group = '' ) { |
|
144 | - return $this->schedule_single( time(), $hook, $args, $group ); |
|
143 | + public function add($hook, $args = array(), $group = '') { |
|
144 | + return $this->schedule_single(time(), $hook, $args, $group); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @param string $group The group to assign this job to. |
154 | 154 | * @return string The action ID. |
155 | 155 | */ |
156 | - public function schedule_single( $timestamp, $hook, $args = array(), $group = '' ) { |
|
157 | - return as_schedule_single_action( $timestamp, $hook, $args, $group ); |
|
156 | + public function schedule_single($timestamp, $hook, $args = array(), $group = '') { |
|
157 | + return as_schedule_single_action($timestamp, $hook, $args, $group); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @param string $group The group to assign this job to. |
168 | 168 | * @return string The action ID. |
169 | 169 | */ |
170 | - public function schedule_recurring( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) { |
|
171 | - return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group ); |
|
170 | + public function schedule_recurring($timestamp, $interval_in_seconds, $hook, $args = array(), $group = '') { |
|
171 | + return as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args, $group); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | * @param string $group The group to assign this job to. |
192 | 192 | * @return string The action ID |
193 | 193 | */ |
194 | - public function schedule_cron( $timestamp, $cron_schedule, $hook, $args = array(), $group = '' ) { |
|
195 | - return as_schedule_cron_action( $timestamp, $cron_schedule, $hook, $args, $group ); |
|
194 | + public function schedule_cron($timestamp, $cron_schedule, $hook, $args = array(), $group = '') { |
|
195 | + return as_schedule_cron_action($timestamp, $cron_schedule, $hook, $args, $group); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @param array $args Args that would have been passed to the job. |
209 | 209 | * @param string $group Group name. |
210 | 210 | */ |
211 | - public function cancel( $hook, $args = array(), $group = '' ) { |
|
212 | - as_unschedule_action( $hook, $args, $group ); |
|
211 | + public function cancel($hook, $args = array(), $group = '') { |
|
212 | + as_unschedule_action($hook, $args, $group); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | * @param string $group Group name. |
222 | 222 | * @return time|null The date and time for the next occurrence, or null if there is no pending, scheduled action for the given hook. |
223 | 223 | */ |
224 | - public function get_next( $hook, $args = null, $group = '' ) { |
|
224 | + public function get_next($hook, $args = null, $group = '') { |
|
225 | 225 | |
226 | - $next_timestamp = as_next_scheduled_action( $hook, $args, $group ); |
|
226 | + $next_timestamp = as_next_scheduled_action($hook, $args, $group); |
|
227 | 227 | |
228 | - if ( $next_timestamp ) { |
|
228 | + if ($next_timestamp) { |
|
229 | 229 | return $next_timestamp; |
230 | 230 | } |
231 | 231 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param string $return_format OBJECT, ARRAY_A, or ids. |
254 | 254 | * @return array |
255 | 255 | */ |
256 | - public function search( $args = array(), $return_format = OBJECT ) { |
|
257 | - return as_get_scheduled_actions( $args, $return_format ); |
|
256 | + public function search($args = array(), $return_format = OBJECT) { |
|
257 | + return as_get_scheduled_actions($args, $return_format); |
|
258 | 258 | } |
259 | 259 | } |
@@ -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 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param object $logging Object_Sync_Sf_Logging. |
63 | 63 | * @throws \Exception |
64 | 64 | */ |
65 | - public function __construct( $wpdb, $version, $slug, $option_prefix, $logging ) { |
|
65 | + public function __construct($wpdb, $version, $slug, $option_prefix, $logging) { |
|
66 | 66 | $this->wpdb = $wpdb; |
67 | 67 | $this->version = $version; |
68 | 68 | $this->slug = $slug; |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | $this->sync_sf_delete = 0x0020; |
87 | 87 | |
88 | 88 | // Define which events are initialized by which system. |
89 | - $this->wordpress_events = array( $this->sync_wordpress_create, $this->sync_wordpress_update, $this->sync_wordpress_delete ); |
|
90 | - $this->salesforce_events = array( $this->sync_sf_create, $this->sync_sf_update, $this->sync_sf_delete ); |
|
89 | + $this->wordpress_events = array($this->sync_wordpress_create, $this->sync_wordpress_update, $this->sync_wordpress_delete); |
|
90 | + $this->salesforce_events = array($this->sync_sf_create, $this->sync_sf_update, $this->sync_sf_delete); |
|
91 | 91 | |
92 | 92 | // Constants for the directions to map things. |
93 | 93 | $this->direction_wordpress_sf = 'wp_sf'; |
94 | 94 | $this->direction_sf_wordpress = 'sf_wp'; |
95 | 95 | $this->direction_sync = 'sync'; |
96 | 96 | |
97 | - $this->direction_wordpress = array( $this->direction_wordpress_sf, $this->direction_sync ); |
|
98 | - $this->direction_salesforce = array( $this->direction_sf_wordpress, $this->direction_sync ); |
|
97 | + $this->direction_wordpress = array($this->direction_wordpress_sf, $this->direction_sync); |
|
98 | + $this->direction_salesforce = array($this->direction_sf_wordpress, $this->direction_sync); |
|
99 | 99 | |
100 | 100 | // This is used when we map a record with default or Master. |
101 | 101 | $this->salesforce_default_record_type = 'default'; |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | // Salesforce has multipicklists and they have a delimiter. |
104 | 104 | $this->array_delimiter = ';'; |
105 | 105 | // What data types in Salesforce should be an array? |
106 | - $this->array_types_from_salesforce = array( 'multipicklist' ); |
|
106 | + $this->array_types_from_salesforce = array('multipicklist'); |
|
107 | 107 | // What data types in Salesforce should be a date field? |
108 | - $this->date_types_from_salesforce = array( 'date', 'datetime' ); |
|
108 | + $this->date_types_from_salesforce = array('date', 'datetime'); |
|
109 | 109 | // What data types in Salesforce should be an integer? |
110 | - $this->int_types_from_salesforce = array( 'integer', 'boolean' ); |
|
110 | + $this->int_types_from_salesforce = array('integer', 'boolean'); |
|
111 | 111 | |
112 | 112 | // Max length for a mapping field. |
113 | 113 | $this->name_length = 128; |
@@ -126,13 +126,13 @@ discard block |
||
126 | 126 | * @param array $salesforce_fields The fields for the Salesforce side of the mapping. |
127 | 127 | * @throws \Exception |
128 | 128 | */ |
129 | - public function create_fieldmap( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array() ) { |
|
130 | - $data = $this->setup_fieldmap_data( $posted, $wordpress_fields, $salesforce_fields ); |
|
131 | - if ( version_compare( $this->version, '1.2.5', '>=' ) ) { |
|
129 | + public function create_fieldmap($posted = array(), $wordpress_fields = array(), $salesforce_fields = array()) { |
|
130 | + $data = $this->setup_fieldmap_data($posted, $wordpress_fields, $salesforce_fields); |
|
131 | + if (version_compare($this->version, '1.2.5', '>=')) { |
|
132 | 132 | $data['version'] = $this->version; |
133 | 133 | } |
134 | - $insert = $this->wpdb->insert( $this->fieldmap_table, $data ); |
|
135 | - if ( 1 === $insert ) { |
|
134 | + $insert = $this->wpdb->insert($this->fieldmap_table, $data); |
|
135 | + if (1 === $insert) { |
|
136 | 136 | return $this->wpdb->insert_id; |
137 | 137 | } else { |
138 | 138 | return false; |
@@ -148,29 +148,29 @@ discard block |
||
148 | 148 | * @return Array $map a single mapping or $mappings, an array of mappings. |
149 | 149 | * @throws \Exception |
150 | 150 | */ |
151 | - public function get_fieldmaps( $id = null, $conditions = array(), $reset = false ) { |
|
151 | + public function get_fieldmaps($id = null, $conditions = array(), $reset = false) { |
|
152 | 152 | $table = $this->fieldmap_table; |
153 | - if ( null !== $id ) { // get one fieldmap. |
|
154 | - $map = $this->wpdb->get_row( 'SELECT * FROM ' . $table . ' WHERE id = ' . $id, ARRAY_A ); |
|
155 | - $map['salesforce_record_types_allowed'] = maybe_unserialize( $map['salesforce_record_types_allowed'] ); |
|
153 | + if (null !== $id) { // get one fieldmap. |
|
154 | + $map = $this->wpdb->get_row('SELECT * FROM ' . $table . ' WHERE id = ' . $id, ARRAY_A); |
|
155 | + $map['salesforce_record_types_allowed'] = maybe_unserialize($map['salesforce_record_types_allowed']); |
|
156 | 156 | |
157 | - $map['fields'] = maybe_unserialize( $map['fields'] ); |
|
158 | - $map['sync_triggers'] = maybe_unserialize( $map['sync_triggers'] ); |
|
157 | + $map['fields'] = maybe_unserialize($map['fields']); |
|
158 | + $map['sync_triggers'] = maybe_unserialize($map['sync_triggers']); |
|
159 | 159 | return $map; |
160 | - } elseif ( ! empty( $conditions ) ) { // get multiple but with a limitation. |
|
160 | + } elseif ( ! empty($conditions)) { // get multiple but with a limitation. |
|
161 | 161 | $mappings = array(); |
162 | 162 | $record_type = ''; |
163 | 163 | |
164 | 164 | // Assemble the SQL. |
165 | - if ( ! empty( $conditions ) ) { |
|
165 | + if ( ! empty($conditions)) { |
|
166 | 166 | $where = ' WHERE '; |
167 | 167 | $i = 0; |
168 | - foreach ( $conditions as $key => $value ) { |
|
169 | - if ( 'salesforce_record_type' === $key ) { |
|
170 | - $record_type = sanitize_text_field( $value ); |
|
168 | + foreach ($conditions as $key => $value) { |
|
169 | + if ('salesforce_record_type' === $key) { |
|
170 | + $record_type = sanitize_text_field($value); |
|
171 | 171 | } else { |
172 | 172 | $i++; |
173 | - if ( $i > 1 ) { |
|
173 | + if ($i > 1) { |
|
174 | 174 | $where .= ' AND '; |
175 | 175 | } |
176 | 176 | $where .= '`' . $key . '` = "' . $value . '"'; |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | $where = ''; |
181 | 181 | } |
182 | 182 | |
183 | - $mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $where . ' ORDER BY `weight`', ARRAY_A ); |
|
183 | + $mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $where . ' ORDER BY `weight`', ARRAY_A); |
|
184 | 184 | |
185 | - if ( ! empty( $mappings ) ) { |
|
186 | - $mappings = $this->prepare_fieldmap_data( $mappings, $record_type ); |
|
185 | + if ( ! empty($mappings)) { |
|
186 | + $mappings = $this->prepare_fieldmap_data($mappings, $record_type); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | return $mappings; |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | } else { // get all of the mappings. ALL THE MAPPINGS. |
192 | 192 | |
193 | 193 | // if the version is greater than or equal to 1.2.5, the fieldmap table has a version column |
194 | - if ( version_compare( $this->version, '1.2.5', '>=' ) ) { |
|
195 | - $mappings = $this->wpdb->get_results( "SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight`, `version` FROM $table", ARRAY_A ); |
|
194 | + if (version_compare($this->version, '1.2.5', '>=')) { |
|
195 | + $mappings = $this->wpdb->get_results("SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight`, `version` FROM $table", ARRAY_A); |
|
196 | 196 | } else { |
197 | - $mappings = $this->wpdb->get_results( "SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight` FROM $table", ARRAY_A ); |
|
197 | + $mappings = $this->wpdb->get_results("SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight` FROM $table", ARRAY_A); |
|
198 | 198 | } |
199 | 199 | |
200 | - if ( ! empty( $mappings ) ) { |
|
201 | - $mappings = $this->prepare_fieldmap_data( $mappings ); |
|
200 | + if ( ! empty($mappings)) { |
|
201 | + $mappings = $this->prepare_fieldmap_data($mappings); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | return $mappings; |
@@ -214,29 +214,29 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return Array of mapped fields |
216 | 216 | */ |
217 | - public function get_mapped_fields( $mapping, $directions = array() ) { |
|
217 | + public function get_mapped_fields($mapping, $directions = array()) { |
|
218 | 218 | $mapped_fields = array(); |
219 | - foreach ( $mapping['fields'] as $fields ) { |
|
220 | - if ( empty( $directions ) || in_array( $fields['direction'], $directions, true ) ) { |
|
219 | + foreach ($mapping['fields'] as $fields) { |
|
220 | + if (empty($directions) || in_array($fields['direction'], $directions, true)) { |
|
221 | 221 | |
222 | - if ( version_compare( $this->version, '1.2.0', '>=' ) && isset( $fields['salesforce_field']['name'] ) ) { |
|
222 | + if (version_compare($this->version, '1.2.0', '>=') && isset($fields['salesforce_field']['name'])) { |
|
223 | 223 | $array_key = 'name'; |
224 | 224 | } else { |
225 | 225 | $array_key = 'label'; |
226 | 226 | } |
227 | 227 | |
228 | 228 | // Some field map types (Relation) store a collection of SF objects. |
229 | - if ( is_array( $fields['salesforce_field'] ) && ! isset( $fields['salesforce_field'][ $array_key ] ) ) { |
|
230 | - foreach ( $fields['salesforce_field'] as $sf_field ) { |
|
231 | - $mapped_fields[ $sf_field[ $array_key ] ] = $sf_field[ $array_key ]; |
|
229 | + if (is_array($fields['salesforce_field']) && ! isset($fields['salesforce_field'][$array_key])) { |
|
230 | + foreach ($fields['salesforce_field'] as $sf_field) { |
|
231 | + $mapped_fields[$sf_field[$array_key]] = $sf_field[$array_key]; |
|
232 | 232 | } |
233 | 233 | } else { // The rest are just a name/value pair. |
234 | - $mapped_fields[ $fields['salesforce_field'][ $array_key ] ] = $fields['salesforce_field'][ $array_key ]; |
|
234 | + $mapped_fields[$fields['salesforce_field'][$array_key]] = $fields['salesforce_field'][$array_key]; |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - if ( ! empty( $this->get_mapped_record_types ) ) { |
|
239 | + if ( ! empty($this->get_mapped_record_types)) { |
|
240 | 240 | $mapped_fields['RecordTypeId'] = 'RecordTypeId'; |
241 | 241 | } |
242 | 242 | |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | * @param Array $mapping A mapping from which we wish to estract the record type. |
250 | 250 | * @return Array of mappings. Empty if the mapping's record type is default, else full of the record types. |
251 | 251 | */ |
252 | - public function get_mapped_record_types( $mapping ) { |
|
253 | - return $mapping['salesforce_record_type_default'] === $this->salesforce_default_record_type ? array() : array_filter( maybe_unserialize( $mapping['salesforce_record_types_allowed'] ) ); |
|
252 | + public function get_mapped_record_types($mapping) { |
|
253 | + return $mapping['salesforce_record_type_default'] === $this->salesforce_default_record_type ? array() : array_filter(maybe_unserialize($mapping['salesforce_record_types_allowed'])); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -263,9 +263,9 @@ discard block |
||
263 | 263 | * @return $map |
264 | 264 | * @throws \Exception |
265 | 265 | */ |
266 | - public function update_fieldmap( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array(), $id = '' ) { |
|
267 | - $data = $this->setup_fieldmap_data( $posted, $wordpress_fields, $salesforce_fields ); |
|
268 | - if ( version_compare( $this->version, '1.2.5', '>=' ) && ! isset( $data['updated'] ) ) { |
|
266 | + public function update_fieldmap($posted = array(), $wordpress_fields = array(), $salesforce_fields = array(), $id = '') { |
|
267 | + $data = $this->setup_fieldmap_data($posted, $wordpress_fields, $salesforce_fields); |
|
268 | + if (version_compare($this->version, '1.2.5', '>=') && ! isset($data['updated'])) { |
|
269 | 269 | $data['version'] = $this->version; |
270 | 270 | } |
271 | 271 | $update = $this->wpdb->update( |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | 'id' => $id, |
276 | 276 | ) |
277 | 277 | ); |
278 | - if ( false === $update ) { |
|
278 | + if (false === $update) { |
|
279 | 279 | return false; |
280 | 280 | } else { |
281 | 281 | return true; |
@@ -291,76 +291,76 @@ discard block |
||
291 | 291 | * @param array $salesforce_fields The fields for the Salesforce side of the mapping. |
292 | 292 | * @return $data |
293 | 293 | */ |
294 | - private function setup_fieldmap_data( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array() ) { |
|
294 | + private function setup_fieldmap_data($posted = array(), $wordpress_fields = array(), $salesforce_fields = array()) { |
|
295 | 295 | $data = array( |
296 | 296 | 'label' => $posted['label'], |
297 | - 'name' => sanitize_title( $posted['label'] ), |
|
297 | + 'name' => sanitize_title($posted['label']), |
|
298 | 298 | 'salesforce_object' => $posted['salesforce_object'], |
299 | 299 | 'wordpress_object' => $posted['wordpress_object'], |
300 | 300 | ); |
301 | - if ( isset( $posted['wordpress_field'] ) && is_array( $posted['wordpress_field'] ) && isset( $posted['salesforce_field'] ) && is_array( $posted['salesforce_field'] ) ) { |
|
301 | + if (isset($posted['wordpress_field']) && is_array($posted['wordpress_field']) && isset($posted['salesforce_field']) && is_array($posted['salesforce_field'])) { |
|
302 | 302 | $setup['fields'] = array(); |
303 | - foreach ( $posted['wordpress_field'] as $key => $value ) { |
|
304 | - $method_key = array_search( $value, array_column( $wordpress_fields, 'key' ), true ); |
|
305 | - if ( ! isset( $posted['direction'][ $key ] ) ) { |
|
306 | - $posted['direction'][ $key ] = 'sync'; |
|
303 | + foreach ($posted['wordpress_field'] as $key => $value) { |
|
304 | + $method_key = array_search($value, array_column($wordpress_fields, 'key'), true); |
|
305 | + if ( ! isset($posted['direction'][$key])) { |
|
306 | + $posted['direction'][$key] = 'sync'; |
|
307 | 307 | } |
308 | - if ( ! isset( $posted['is_prematch'][ $key ] ) ) { |
|
309 | - $posted['is_prematch'][ $key ] = false; |
|
308 | + if ( ! isset($posted['is_prematch'][$key])) { |
|
309 | + $posted['is_prematch'][$key] = false; |
|
310 | 310 | } |
311 | - if ( ! isset( $posted['is_key'][ $key ] ) ) { |
|
312 | - $posted['is_key'][ $key ] = false; |
|
311 | + if ( ! isset($posted['is_key'][$key])) { |
|
312 | + $posted['is_key'][$key] = false; |
|
313 | 313 | } |
314 | - if ( ! isset( $posted['is_delete'][ $key ] ) ) { |
|
315 | - $posted['is_delete'][ $key ] = false; |
|
314 | + if ( ! isset($posted['is_delete'][$key])) { |
|
315 | + $posted['is_delete'][$key] = false; |
|
316 | 316 | } |
317 | - if ( false === $posted['is_delete'][ $key ] ) { |
|
317 | + if (false === $posted['is_delete'][$key]) { |
|
318 | 318 | // I think it's good to over-mention that updateable is really how the Salesforce api spells it. |
319 | - $updateable_key = array_search( $posted['salesforce_field'][ $key ], array_column( $salesforce_fields, 'name' ), true ); |
|
319 | + $updateable_key = array_search($posted['salesforce_field'][$key], array_column($salesforce_fields, 'name'), true); |
|
320 | 320 | |
321 | 321 | $salesforce_field_attributes = array(); |
322 | - foreach ( $salesforce_fields[ $updateable_key ] as $sf_key => $sf_value ) { |
|
323 | - if ( isset( $sf_value ) && ! is_array( $sf_value ) ) { |
|
324 | - $salesforce_field_attributes[ $sf_key ] = esc_attr( $sf_value ); |
|
325 | - } elseif ( ! empty( $sf_value ) && is_array( $sf_value ) ) { |
|
326 | - $salesforce_field_attributes[ $sf_key ] = maybe_unserialize( $sf_value ); |
|
322 | + foreach ($salesforce_fields[$updateable_key] as $sf_key => $sf_value) { |
|
323 | + if (isset($sf_value) && ! is_array($sf_value)) { |
|
324 | + $salesforce_field_attributes[$sf_key] = esc_attr($sf_value); |
|
325 | + } elseif ( ! empty($sf_value) && is_array($sf_value)) { |
|
326 | + $salesforce_field_attributes[$sf_key] = maybe_unserialize($sf_value); |
|
327 | 327 | } else { |
328 | - $salesforce_field_attributes[ $sf_key ] = ''; |
|
328 | + $salesforce_field_attributes[$sf_key] = ''; |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
332 | - $setup['fields'][ $key ] = array( |
|
332 | + $setup['fields'][$key] = array( |
|
333 | 333 | 'wordpress_field' => array( |
334 | - 'label' => sanitize_text_field( $posted['wordpress_field'][ $key ] ), |
|
335 | - 'methods' => maybe_unserialize( $wordpress_fields[ $method_key ]['methods'] ), |
|
336 | - 'type' => isset( $wordpress_fields[ $method_key ]['type'] ) ? sanitize_text_field( $wordpress_fields[ $method_key ]['type'] ) : 'text', |
|
334 | + 'label' => sanitize_text_field($posted['wordpress_field'][$key]), |
|
335 | + 'methods' => maybe_unserialize($wordpress_fields[$method_key]['methods']), |
|
336 | + 'type' => isset($wordpress_fields[$method_key]['type']) ? sanitize_text_field($wordpress_fields[$method_key]['type']) : 'text', |
|
337 | 337 | ), |
338 | 338 | 'salesforce_field' => $salesforce_field_attributes, |
339 | - 'is_prematch' => sanitize_text_field( $posted['is_prematch'][ $key ] ), |
|
340 | - 'is_key' => sanitize_text_field( $posted['is_key'][ $key ] ), |
|
341 | - 'direction' => sanitize_text_field( $posted['direction'][ $key ] ), |
|
342 | - 'is_delete' => sanitize_text_field( $posted['is_delete'][ $key ] ), |
|
339 | + 'is_prematch' => sanitize_text_field($posted['is_prematch'][$key]), |
|
340 | + 'is_key' => sanitize_text_field($posted['is_key'][$key]), |
|
341 | + 'direction' => sanitize_text_field($posted['direction'][$key]), |
|
342 | + 'is_delete' => sanitize_text_field($posted['is_delete'][$key]), |
|
343 | 343 | ); |
344 | 344 | |
345 | 345 | // If the WordPress key or the Salesforce key are blank, remove this incomplete mapping. |
346 | 346 | // This prevents https://github.com/MinnPost/object-sync-for-salesforce/issues/82 . |
347 | 347 | if ( |
348 | - empty( $setup['fields'][ $key ]['wordpress_field']['label'] ) |
|
348 | + empty($setup['fields'][$key]['wordpress_field']['label']) |
|
349 | 349 | || |
350 | - empty( $setup['fields'][ $key ]['salesforce_field']['name'] ) |
|
350 | + empty($setup['fields'][$key]['salesforce_field']['name']) |
|
351 | 351 | ) { |
352 | - unset( $setup['fields'][ $key ] ); |
|
352 | + unset($setup['fields'][$key]); |
|
353 | 353 | } |
354 | 354 | } |
355 | 355 | } // End foreach() on WordPress fields. |
356 | - $data['fields'] = maybe_serialize( $setup['fields'] ); |
|
357 | - } elseif ( isset( $posted['fields'] ) && is_array( $posted['fields'] ) ) { |
|
356 | + $data['fields'] = maybe_serialize($setup['fields']); |
|
357 | + } elseif (isset($posted['fields']) && is_array($posted['fields'])) { |
|
358 | 358 | // if $posted['fields'] is already set, use that |
359 | - $data['fields'] = maybe_serialize( $posted['fields'] ); |
|
359 | + $data['fields'] = maybe_serialize($posted['fields']); |
|
360 | 360 | } // End if() WordPress fields are present. |
361 | 361 | |
362 | - if ( isset( $posted['salesforce_record_types_allowed'] ) ) { |
|
363 | - $data['salesforce_record_types_allowed'] = maybe_serialize( $posted['salesforce_record_types_allowed'] ); |
|
362 | + if (isset($posted['salesforce_record_types_allowed'])) { |
|
363 | + $data['salesforce_record_types_allowed'] = maybe_serialize($posted['salesforce_record_types_allowed']); |
|
364 | 364 | } else { |
365 | 365 | $data['salesforce_record_types_allowed'] = maybe_serialize( |
366 | 366 | array( |
@@ -368,29 +368,29 @@ discard block |
||
368 | 368 | ) |
369 | 369 | ); |
370 | 370 | } |
371 | - if ( isset( $posted['salesforce_record_type_default'] ) ) { |
|
371 | + if (isset($posted['salesforce_record_type_default'])) { |
|
372 | 372 | $data['salesforce_record_type_default'] = $posted['salesforce_record_type_default']; |
373 | 373 | } else { |
374 | - $data['salesforce_record_type_default'] = maybe_serialize( $this->salesforce_default_record_type ); |
|
374 | + $data['salesforce_record_type_default'] = maybe_serialize($this->salesforce_default_record_type); |
|
375 | 375 | } |
376 | - if ( isset( $posted['pull_trigger_field'] ) ) { |
|
376 | + if (isset($posted['pull_trigger_field'])) { |
|
377 | 377 | $data['pull_trigger_field'] = $posted['pull_trigger_field']; |
378 | 378 | } |
379 | - if ( isset( $posted['sync_triggers'] ) && is_array( $posted['sync_triggers'] ) ) { |
|
379 | + if (isset($posted['sync_triggers']) && is_array($posted['sync_triggers'])) { |
|
380 | 380 | $setup['sync_triggers'] = array(); |
381 | - foreach ( $posted['sync_triggers'] as $key => $value ) { |
|
382 | - $setup['sync_triggers'][ $key ] = esc_html( $posted['sync_triggers'][ $key ] ); |
|
381 | + foreach ($posted['sync_triggers'] as $key => $value) { |
|
382 | + $setup['sync_triggers'][$key] = esc_html($posted['sync_triggers'][$key]); |
|
383 | 383 | } |
384 | 384 | } else { |
385 | 385 | $setup['sync_triggers'] = array(); |
386 | 386 | } |
387 | - $data['sync_triggers'] = maybe_serialize( $setup['sync_triggers'] ); |
|
388 | - if ( isset( $posted['pull_trigger_field'] ) ) { |
|
387 | + $data['sync_triggers'] = maybe_serialize($setup['sync_triggers']); |
|
388 | + if (isset($posted['pull_trigger_field'])) { |
|
389 | 389 | $data['pull_trigger_field'] = $posted['pull_trigger_field']; |
390 | 390 | } |
391 | - $data['push_async'] = isset( $posted['push_async'] ) ? $posted['push_async'] : ''; |
|
392 | - $data['push_drafts'] = isset( $posted['push_drafts'] ) ? $posted['push_drafts'] : ''; |
|
393 | - $data['weight'] = isset( $posted['weight'] ) ? $posted['weight'] : ''; |
|
391 | + $data['push_async'] = isset($posted['push_async']) ? $posted['push_async'] : ''; |
|
392 | + $data['push_drafts'] = isset($posted['push_drafts']) ? $posted['push_drafts'] : ''; |
|
393 | + $data['weight'] = isset($posted['weight']) ? $posted['weight'] : ''; |
|
394 | 394 | return $data; |
395 | 395 | } |
396 | 396 | |
@@ -401,12 +401,12 @@ discard block |
||
401 | 401 | * @return Boolean |
402 | 402 | * @throws \Exception |
403 | 403 | */ |
404 | - public function delete_fieldmap( $id = '' ) { |
|
404 | + public function delete_fieldmap($id = '') { |
|
405 | 405 | $data = array( |
406 | 406 | 'id' => $id, |
407 | 407 | ); |
408 | - $delete = $this->wpdb->delete( $this->fieldmap_table, $data ); |
|
409 | - if ( 1 === $delete ) { |
|
408 | + $delete = $this->wpdb->delete($this->fieldmap_table, $data); |
|
409 | + if (1 === $delete) { |
|
410 | 410 | return true; |
411 | 411 | } else { |
412 | 412 | return false; |
@@ -420,27 +420,27 @@ discard block |
||
420 | 420 | * @return false|Int of field mapping between WordPress and Salesforce objects |
421 | 421 | * @throws \Exception |
422 | 422 | */ |
423 | - public function create_object_map( $posted = array() ) { |
|
424 | - $data = $this->setup_object_map_data( $posted ); |
|
425 | - $data['created'] = current_time( 'mysql' ); |
|
423 | + public function create_object_map($posted = array()) { |
|
424 | + $data = $this->setup_object_map_data($posted); |
|
425 | + $data['created'] = current_time('mysql'); |
|
426 | 426 | // Check to see if we don't know the salesforce id and it is not a temporary id, or if this is pending. |
427 | 427 | // If it is using a temporary id, the map will get updated after it finishes running; it won't call this method unless there's an error, which we should log. |
428 | - if ( substr( $data['salesforce_id'], 0, 7 ) !== 'tmp_sf_' || 'pending' === $data['action'] ) { |
|
429 | - unset( $data['action'] ); |
|
430 | - $insert = $this->wpdb->insert( $this->object_map_table, $data ); |
|
428 | + if (substr($data['salesforce_id'], 0, 7) !== 'tmp_sf_' || 'pending' === $data['action']) { |
|
429 | + unset($data['action']); |
|
430 | + $insert = $this->wpdb->insert($this->object_map_table, $data); |
|
431 | 431 | } else { |
432 | 432 | $status = 'error'; |
433 | - if ( isset( $this->logging ) ) { |
|
433 | + if (isset($this->logging)) { |
|
434 | 434 | $logging = $this->logging; |
435 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
436 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
435 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
436 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
437 | 437 | } |
438 | 438 | $logging->setup( |
439 | 439 | sprintf( |
440 | 440 | // translators: %1$s is the name of a WordPress object. %2$s is the id of that object. |
441 | - esc_html__( 'Error Mapping: error caused by trying to map the WordPress %1$s with ID of %2$s to Salesforce ID starting with "tmp_sf_", which is invalid.', 'object-sync-for-salesforce' ), |
|
442 | - esc_attr( $data['wordpress_object'] ), |
|
443 | - absint( $data['wordpress_id'] ) |
|
441 | + esc_html__('Error Mapping: error caused by trying to map the WordPress %1$s with ID of %2$s to Salesforce ID starting with "tmp_sf_", which is invalid.', 'object-sync-for-salesforce'), |
|
442 | + esc_attr($data['wordpress_object']), |
|
443 | + absint($data['wordpress_id']) |
|
444 | 444 | ), |
445 | 445 | '', |
446 | 446 | 0, |
@@ -449,23 +449,23 @@ discard block |
||
449 | 449 | ); |
450 | 450 | return false; |
451 | 451 | } |
452 | - if ( 1 === $insert ) { |
|
452 | + if (1 === $insert) { |
|
453 | 453 | return $this->wpdb->insert_id; |
454 | - } elseif ( false !== strpos( $this->wpdb->last_error, 'Duplicate entry' ) ) { |
|
455 | - $mapping = $this->load_by_salesforce( $data['salesforce_id'] ); |
|
454 | + } elseif (false !== strpos($this->wpdb->last_error, 'Duplicate entry')) { |
|
455 | + $mapping = $this->load_by_salesforce($data['salesforce_id']); |
|
456 | 456 | $id = $mapping['id']; |
457 | 457 | $status = 'error'; |
458 | - if ( isset( $this->logging ) ) { |
|
458 | + if (isset($this->logging)) { |
|
459 | 459 | $logging = $this->logging; |
460 | - } elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) { |
|
461 | - $logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version ); |
|
460 | + } elseif (class_exists('Object_Sync_Sf_Logging')) { |
|
461 | + $logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version); |
|
462 | 462 | } |
463 | 463 | $logging->setup( |
464 | 464 | sprintf( |
465 | 465 | // translators: %1$s is the status word "Error". %1$s is the Id of a Salesforce object. %2$s is the ID of a mapping object. |
466 | - esc_html__( 'Error: Mapping: there is already a WordPress object mapped to the Salesforce object %1$s and the mapping object ID is %2$s', 'object-sync-for-salesforce' ), |
|
467 | - esc_attr( $data['salesforce_id'] ), |
|
468 | - absint( $id ) |
|
466 | + esc_html__('Error: Mapping: there is already a WordPress object mapped to the Salesforce object %1$s and the mapping object ID is %2$s', 'object-sync-for-salesforce'), |
|
467 | + esc_attr($data['salesforce_id']), |
|
468 | + absint($id) |
|
469 | 469 | ), |
470 | 470 | '', |
471 | 471 | 0, |
@@ -486,18 +486,18 @@ discard block |
||
486 | 486 | * @return $map or $mappings |
487 | 487 | * @throws \Exception |
488 | 488 | */ |
489 | - public function get_object_maps( $conditions = array(), $reset = false ) { |
|
489 | + public function get_object_maps($conditions = array(), $reset = false) { |
|
490 | 490 | $table = $this->object_map_table; |
491 | 491 | $order = ' ORDER BY object_updated, created'; |
492 | - if ( ! empty( $conditions ) ) { // get multiple but with a limitation. |
|
492 | + if ( ! empty($conditions)) { // get multiple but with a limitation. |
|
493 | 493 | $mappings = array(); |
494 | 494 | |
495 | - if ( ! empty( $conditions ) ) { |
|
495 | + if ( ! empty($conditions)) { |
|
496 | 496 | $where = ' WHERE '; |
497 | 497 | $i = 0; |
498 | - foreach ( $conditions as $key => $value ) { |
|
498 | + foreach ($conditions as $key => $value) { |
|
499 | 499 | $i++; |
500 | - if ( $i > 1 ) { |
|
500 | + if ($i > 1) { |
|
501 | 501 | $where .= ' AND '; |
502 | 502 | } |
503 | 503 | $where .= '`' . $key . '` = "' . $value . '"'; |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | $where = ''; |
507 | 507 | } |
508 | 508 | |
509 | - $mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $where . $order, ARRAY_A ); |
|
510 | - if ( ! empty( $mappings ) && 1 === $this->wpdb->num_rows ) { |
|
509 | + $mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $where . $order, ARRAY_A); |
|
510 | + if ( ! empty($mappings) && 1 === $this->wpdb->num_rows) { |
|
511 | 511 | $mappings = $mappings[0]; |
512 | 512 | } |
513 | 513 | } else { // get all of the mappings. ALL THE MAPPINGS. |
514 | - $mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $order, ARRAY_A ); |
|
515 | - if ( ! empty( $mappings ) && 1 === $this->wpdb->num_rows ) { |
|
514 | + $mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $order, ARRAY_A); |
|
515 | + if ( ! empty($mappings) && 1 === $this->wpdb->num_rows) { |
|
516 | 516 | $mappings = $mappings[0]; |
517 | 517 | } |
518 | 518 | } |
@@ -529,10 +529,10 @@ discard block |
||
529 | 529 | * @return $map |
530 | 530 | * @throws \Exception |
531 | 531 | */ |
532 | - public function update_object_map( $posted = array(), $id = '' ) { |
|
533 | - $data = $this->setup_object_map_data( $posted ); |
|
534 | - if ( ! isset( $data['object_updated'] ) ) { |
|
535 | - $data['object_updated'] = current_time( 'mysql' ); |
|
532 | + public function update_object_map($posted = array(), $id = '') { |
|
533 | + $data = $this->setup_object_map_data($posted); |
|
534 | + if ( ! isset($data['object_updated'])) { |
|
535 | + $data['object_updated'] = current_time('mysql'); |
|
536 | 536 | } |
537 | 537 | $update = $this->wpdb->update( |
538 | 538 | $this->object_map_table, |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | 'id' => $id, |
542 | 542 | ) |
543 | 543 | ); |
544 | - if ( false === $update ) { |
|
544 | + if (false === $update) { |
|
545 | 545 | return false; |
546 | 546 | } else { |
547 | 547 | return true; |
@@ -554,11 +554,11 @@ discard block |
||
554 | 554 | * @param array $posted It's $_POST. |
555 | 555 | * @return $data Filtered array with only the keys that are in the object map database table. Strips out things from WordPress form if they're present. |
556 | 556 | */ |
557 | - private function setup_object_map_data( $posted = array() ) { |
|
558 | - $allowed_fields = $this->wpdb->get_col( "DESC {$this->object_map_table}", 0 ); |
|
557 | + private function setup_object_map_data($posted = array()) { |
|
558 | + $allowed_fields = $this->wpdb->get_col("DESC {$this->object_map_table}", 0); |
|
559 | 559 | $allowed_fields[] = 'action'; // we use this in both directions even though it isn't in the database; we remove it from the array later if it is present |
560 | 560 | |
561 | - $data = array_intersect_key( $posted, array_flip( $allowed_fields ) ); |
|
561 | + $data = array_intersect_key($posted, array_flip($allowed_fields)); |
|
562 | 562 | return $data; |
563 | 563 | } |
564 | 564 | |
@@ -568,12 +568,12 @@ discard block |
||
568 | 568 | * @param array $id The ID of the object map row. |
569 | 569 | * @throws \Exception |
570 | 570 | */ |
571 | - public function delete_object_map( $id = '' ) { |
|
571 | + public function delete_object_map($id = '') { |
|
572 | 572 | $data = array( |
573 | 573 | 'id' => $id, |
574 | 574 | ); |
575 | - $delete = $this->wpdb->delete( $this->object_map_table, $data ); |
|
576 | - if ( 1 === $delete ) { |
|
575 | + $delete = $this->wpdb->delete($this->object_map_table, $data); |
|
576 | + if (1 === $delete) { |
|
577 | 577 | return true; |
578 | 578 | } else { |
579 | 579 | return false; |
@@ -586,13 +586,13 @@ discard block |
||
586 | 586 | * @param string $direction Whether this is part of a push or pull action |
587 | 587 | * @return $id is a temporary string that will be replaced if the modification is successful |
588 | 588 | */ |
589 | - public function generate_temporary_id( $direction ) { |
|
590 | - if ( 'push' === $direction ) { |
|
589 | + public function generate_temporary_id($direction) { |
|
590 | + if ('push' === $direction) { |
|
591 | 591 | $prefix = 'tmp_sf_'; |
592 | - } elseif ( 'pull' === $direction ) { |
|
592 | + } elseif ('pull' === $direction) { |
|
593 | 593 | $prefix = 'tmp_wp_'; |
594 | 594 | } |
595 | - $id = uniqid( $prefix, true ); |
|
595 | + $id = uniqid($prefix, true); |
|
596 | 596 | return $id; |
597 | 597 | } |
598 | 598 | |
@@ -606,12 +606,12 @@ discard block |
||
606 | 606 | * @return SalesforceMappingObject |
607 | 607 | * The requested SalesforceMappingObject or FALSE if none was found. |
608 | 608 | */ |
609 | - public function load_by_wordpress( $object_type, $object_id, $reset = false ) { |
|
609 | + public function load_by_wordpress($object_type, $object_id, $reset = false) { |
|
610 | 610 | $conditions = array( |
611 | 611 | 'wordpress_id' => $object_id, |
612 | 612 | 'wordpress_object' => $object_type, |
613 | 613 | ); |
614 | - return $this->get_object_maps( $conditions, $reset ); |
|
614 | + return $this->get_object_maps($conditions, $reset); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -623,24 +623,24 @@ discard block |
||
623 | 623 | * @return array $map |
624 | 624 | * The most recent fieldmap |
625 | 625 | */ |
626 | - public function load_by_salesforce( $salesforce_id, $reset = false ) { |
|
626 | + public function load_by_salesforce($salesforce_id, $reset = false) { |
|
627 | 627 | $conditions = array( |
628 | 628 | 'salesforce_id' => $salesforce_id, |
629 | 629 | ); |
630 | 630 | |
631 | - $map = $this->get_object_maps( $conditions, $reset ); |
|
631 | + $map = $this->get_object_maps($conditions, $reset); |
|
632 | 632 | |
633 | - if ( isset( $map[0] ) && is_array( $map[0] ) && count( $map ) > 1 ) { |
|
633 | + if (isset($map[0]) && is_array($map[0]) && count($map) > 1) { |
|
634 | 634 | $status = 'notice'; |
635 | 635 | $log = ''; |
636 | 636 | $log .= 'Mapping: there is more than one mapped WordPress object for the Salesforce object ' . $salesforce_id . '. These WordPress IDs are: '; |
637 | 637 | $i = 0; |
638 | - foreach ( $map as $mapping ) { |
|
638 | + foreach ($map as $mapping) { |
|
639 | 639 | $i++; |
640 | - if ( isset( $mapping['wordpress_id'] ) ) { |
|
640 | + if (isset($mapping['wordpress_id'])) { |
|
641 | 641 | $log .= 'object type: ' . $mapping['wordpress_object'] . ', id: ' . $mapping['wordpress_id']; |
642 | 642 | } |
643 | - if ( count( $map ) !== $i ) { |
|
643 | + if (count($map) !== $i) { |
|
644 | 644 | $log .= '; '; |
645 | 645 | } else { |
646 | 646 | $log .= '.'; |
@@ -648,16 +648,16 @@ discard block |
||
648 | 648 | } |
649 | 649 | $map = $map[0]; |
650 | 650 | // Create log entry for multiple maps. |
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 | $logging->setup( |
657 | 657 | sprintf( |
658 | 658 | // translators: %1$s is the Id of a Salesforce object. |
659 | - esc_html__( 'Notice: Mapping: there is more than one mapped WordPress object for the Salesforce object %2$s', 'object-sync-for-salesforce' ), |
|
660 | - esc_attr( $salesforce_id ) |
|
659 | + esc_html__('Notice: Mapping: there is more than one mapped WordPress object for the Salesforce object %2$s', 'object-sync-for-salesforce'), |
|
660 | + esc_attr($salesforce_id) |
|
661 | 661 | ), |
662 | 662 | $log, |
663 | 663 | 0, |
@@ -680,20 +680,20 @@ discard block |
||
680 | 680 | * |
681 | 681 | * @return array Associative array of key value pairs. |
682 | 682 | */ |
683 | - public function map_params( $mapping, $object, $trigger, $use_soap = false, $is_new = true ) { |
|
683 | + public function map_params($mapping, $object, $trigger, $use_soap = false, $is_new = true) { |
|
684 | 684 | |
685 | 685 | $params = array(); |
686 | 686 | |
687 | - foreach ( $mapping['fields'] as $fieldmap ) { |
|
687 | + foreach ($mapping['fields'] as $fieldmap) { |
|
688 | 688 | |
689 | - $wordpress_haystack = array_values( $this->wordpress_events ); |
|
690 | - $salesforce_haystack = array_values( $this->salesforce_events ); |
|
689 | + $wordpress_haystack = array_values($this->wordpress_events); |
|
690 | + $salesforce_haystack = array_values($this->salesforce_events); |
|
691 | 691 | |
692 | - $fieldmap['wordpress_field']['methods'] = maybe_unserialize( $fieldmap['wordpress_field']['methods'] ); |
|
692 | + $fieldmap['wordpress_field']['methods'] = maybe_unserialize($fieldmap['wordpress_field']['methods']); |
|
693 | 693 | |
694 | 694 | $wordpress_field = $fieldmap['wordpress_field']['label']; |
695 | 695 | |
696 | - if ( version_compare( $this->version, '1.2.0', '>=' ) && isset( $fieldmap['salesforce_field']['name'] ) ) { |
|
696 | + if (version_compare($this->version, '1.2.0', '>=') && isset($fieldmap['salesforce_field']['name'])) { |
|
697 | 697 | $salesforce_field = $fieldmap['salesforce_field']['name']; |
698 | 698 | // Load the type of the Salesforce field. We can use this to handle Salesforce field value issues that come up based on what the field sends into WordPress or expects from WordPress. |
699 | 699 | $salesforce_field_type = $fieldmap['salesforce_field']['type']; |
@@ -702,113 +702,113 @@ discard block |
||
702 | 702 | } |
703 | 703 | |
704 | 704 | // A WordPress event caused this. |
705 | - if ( in_array( $trigger, array_values( $wordpress_haystack ), true ) ) { |
|
705 | + if (in_array($trigger, array_values($wordpress_haystack), true)) { |
|
706 | 706 | |
707 | 707 | // Is the field in WordPress an array, if we unserialize it? Salesforce wants it to be an imploded string. |
708 | - if ( is_array( maybe_unserialize( $object[ $wordpress_field ] ) ) ) { |
|
709 | - $object[ $wordpress_field ] = implode( $this->array_delimiter, $object[ $wordpress_field ] ); |
|
708 | + if (is_array(maybe_unserialize($object[$wordpress_field]))) { |
|
709 | + $object[$wordpress_field] = implode($this->array_delimiter, $object[$wordpress_field]); |
|
710 | 710 | } |
711 | 711 | |
712 | - if ( isset( $salesforce_field_type ) ) { |
|
712 | + if (isset($salesforce_field_type)) { |
|
713 | 713 | // Is the Salesforce field a date, and is the WordPress value a valid date? |
714 | 714 | // According to https://salesforce.stackexchange.com/questions/57032/date-format-with-salesforce-rest-api |
715 | - if ( in_array( $salesforce_field_type, $this->date_types_from_salesforce ) ) { |
|
716 | - if ( '' === $object[ $wordpress_field ] ) { |
|
717 | - $object[ $wordpress_field ] = null; |
|
715 | + if (in_array($salesforce_field_type, $this->date_types_from_salesforce)) { |
|
716 | + if ('' === $object[$wordpress_field]) { |
|
717 | + $object[$wordpress_field] = null; |
|
718 | 718 | } else { |
719 | - if ( false !== strtotime( $object[ $wordpress_field ] ) ) { |
|
720 | - $timestamp = strtotime( $object[ $wordpress_field ] ); |
|
719 | + if (false !== strtotime($object[$wordpress_field])) { |
|
720 | + $timestamp = strtotime($object[$wordpress_field]); |
|
721 | 721 | } else { |
722 | - $timestamp = $object[ $wordpress_field ]; |
|
722 | + $timestamp = $object[$wordpress_field]; |
|
723 | 723 | } |
724 | - if ( 'datetime' === $salesforce_field_type ) { |
|
725 | - $object[ $wordpress_field ] = date_i18n( 'c', $timestamp ); |
|
724 | + if ('datetime' === $salesforce_field_type) { |
|
725 | + $object[$wordpress_field] = date_i18n('c', $timestamp); |
|
726 | 726 | } else { |
727 | - $object[ $wordpress_field ] = date_i18n( 'Y-m-d', $timestamp ); |
|
727 | + $object[$wordpress_field] = date_i18n('Y-m-d', $timestamp); |
|
728 | 728 | } |
729 | 729 | } |
730 | 730 | } |
731 | 731 | |
732 | 732 | // Boolean SF fields only want real boolean values. NULL is also not allowed. |
733 | - if ( 'boolean' === $salesforce_field_type ) { |
|
734 | - $object[ $wordpress_field ] = (bool) $object[ $wordpress_field ]; |
|
733 | + if ('boolean' === $salesforce_field_type) { |
|
734 | + $object[$wordpress_field] = (bool) $object[$wordpress_field]; |
|
735 | 735 | } |
736 | 736 | } |
737 | 737 | |
738 | - $params[ $salesforce_field ] = $object[ $wordpress_field ]; |
|
738 | + $params[$salesforce_field] = $object[$wordpress_field]; |
|
739 | 739 | |
740 | 740 | // If the field is a key in Salesforce, remove it from $params to avoid upsert errors from Salesforce, |
741 | 741 | // but still put its name in the params array so we can check for it later. |
742 | - if ( '1' === $fieldmap['is_key'] ) { |
|
743 | - if ( ! $use_soap ) { |
|
744 | - unset( $params[ $salesforce_field ] ); |
|
742 | + if ('1' === $fieldmap['is_key']) { |
|
743 | + if ( ! $use_soap) { |
|
744 | + unset($params[$salesforce_field]); |
|
745 | 745 | } |
746 | 746 | $params['key'] = array( |
747 | 747 | 'salesforce_field' => $salesforce_field, |
748 | 748 | 'wordpress_field' => $wordpress_field, |
749 | - 'value' => $object[ $wordpress_field ], |
|
749 | + 'value' => $object[$wordpress_field], |
|
750 | 750 | ); |
751 | 751 | } |
752 | 752 | |
753 | 753 | // If the field is a prematch in Salesforce, put its name in the params array so we can check for it later. |
754 | - if ( '1' === $fieldmap['is_prematch'] ) { |
|
754 | + if ('1' === $fieldmap['is_prematch']) { |
|
755 | 755 | $params['prematch'] = array( |
756 | 756 | 'salesforce_field' => $salesforce_field, |
757 | 757 | 'wordpress_field' => $wordpress_field, |
758 | - 'value' => $object[ $wordpress_field ], |
|
758 | + 'value' => $object[$wordpress_field], |
|
759 | 759 | ); |
760 | 760 | } |
761 | 761 | |
762 | 762 | // Skip fields that aren't being pushed to Salesforce. |
763 | - if ( ! in_array( $fieldmap['direction'], array_values( $this->direction_wordpress ), true ) ) { |
|
763 | + if ( ! in_array($fieldmap['direction'], array_values($this->direction_wordpress), true)) { |
|
764 | 764 | // The trigger is a WordPress trigger, but the fieldmap direction is not a WordPress direction. |
765 | - unset( $params[ $salesforce_field ] ); |
|
765 | + unset($params[$salesforce_field]); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | // I think it's good to over-mention that updateable is really how the Salesforce api spells it. |
769 | 769 | // Skip fields that aren't updateable when mapping params because Salesforce will error otherwise. |
770 | 770 | // This happens after dealing with the field types because key and prematch should still be available to the plugin, even if the values are not updateable in Salesforce. |
771 | - if ( 1 !== (int) $fieldmap['salesforce_field']['updateable'] ) { |
|
772 | - unset( $params[ $salesforce_field ] ); |
|
771 | + if (1 !== (int) $fieldmap['salesforce_field']['updateable']) { |
|
772 | + unset($params[$salesforce_field]); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | // we don't need a continue with the unset methods because there's no array being created down here |
776 | - } elseif ( in_array( $trigger, $salesforce_haystack, true ) ) { |
|
776 | + } elseif (in_array($trigger, $salesforce_haystack, true)) { |
|
777 | 777 | |
778 | 778 | // A Salesforce event caused this. |
779 | 779 | |
780 | - if ( isset( $salesforce_field_type ) && ! is_null( $object[ $salesforce_field ] ) ) { |
|
780 | + if (isset($salesforce_field_type) && ! is_null($object[$salesforce_field])) { |
|
781 | 781 | // Salesforce provides multipicklist values as a delimited string. If the |
782 | 782 | // destination field in WordPress accepts multiple values, explode the string into an array and then serialize it. |
783 | - if ( in_array( $salesforce_field_type, $this->array_types_from_salesforce ) ) { |
|
784 | - $object[ $salesforce_field ] = explode( $this->array_delimiter, $object[ $salesforce_field ] ); |
|
783 | + if (in_array($salesforce_field_type, $this->array_types_from_salesforce)) { |
|
784 | + $object[$salesforce_field] = explode($this->array_delimiter, $object[$salesforce_field]); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | // Handle specific data types from Salesforce. |
788 | - switch ( $salesforce_field_type ) { |
|
789 | - case ( in_array( $salesforce_field_type, $this->date_types_from_salesforce ) ): |
|
790 | - $format = get_option( 'date_format', 'U' ); |
|
791 | - if ( isset( $fieldmap['wordpress_field']['type'] ) && 'datetime' === $fieldmap['wordpress_field']['type'] ) { |
|
788 | + switch ($salesforce_field_type) { |
|
789 | + case (in_array($salesforce_field_type, $this->date_types_from_salesforce)): |
|
790 | + $format = get_option('date_format', 'U'); |
|
791 | + if (isset($fieldmap['wordpress_field']['type']) && 'datetime' === $fieldmap['wordpress_field']['type']) { |
|
792 | 792 | $format = 'Y-m-d H:i:s'; |
793 | 793 | } |
794 | - $object[ $salesforce_field ] = date_i18n( $format, strtotime( $object[ $salesforce_field ] ) ); |
|
794 | + $object[$salesforce_field] = date_i18n($format, strtotime($object[$salesforce_field])); |
|
795 | 795 | break; |
796 | - case ( in_array( $salesforce_field_type, $this->int_types_from_salesforce ) ): |
|
797 | - $object[ $salesforce_field ] = isset( $object[ $salesforce_field ] ) ? (int) $object[ $salesforce_field ] : 0; |
|
796 | + case (in_array($salesforce_field_type, $this->int_types_from_salesforce)): |
|
797 | + $object[$salesforce_field] = isset($object[$salesforce_field]) ? (int) $object[$salesforce_field] : 0; |
|
798 | 798 | break; |
799 | 799 | case 'text': |
800 | - $object[ $salesforce_field ] = (string) $object[ $salesforce_field ]; |
|
800 | + $object[$salesforce_field] = (string) $object[$salesforce_field]; |
|
801 | 801 | break; |
802 | 802 | case 'url': |
803 | - $object[ $salesforce_field ] = esc_url_raw( $object[ $salesforce_field ] ); |
|
803 | + $object[$salesforce_field] = esc_url_raw($object[$salesforce_field]); |
|
804 | 804 | break; |
805 | 805 | } |
806 | 806 | } |
807 | 807 | |
808 | 808 | // Make an array because we need to store the methods for each field as well. |
809 | - if ( '' !== $object[ $salesforce_field ] ) { |
|
810 | - $params[ $wordpress_field ] = array(); |
|
811 | - $params[ $wordpress_field ]['value'] = $object[ $salesforce_field ]; |
|
809 | + if ('' !== $object[$salesforce_field]) { |
|
810 | + $params[$wordpress_field] = array(); |
|
811 | + $params[$wordpress_field]['value'] = $object[$salesforce_field]; |
|
812 | 812 | } else { |
813 | 813 | // If we try to save certain fields with empty values, WordPress will silently start skipping stuff. This keeps that from happening. |
814 | 814 | continue; |
@@ -817,11 +817,11 @@ discard block |
||
817 | 817 | // If the field is a key in Salesforce, disregard since this is caused by a Salesforce event. We're setting up data to be stored in WordPress here, and WordPress is not concerned with external key designations in Salesforce. |
818 | 818 | |
819 | 819 | // If the field is a prematch in Salesforce, put its name in the params array so we can check for it later. |
820 | - if ( '1' === $fieldmap['is_prematch'] ) { |
|
820 | + if ('1' === $fieldmap['is_prematch']) { |
|
821 | 821 | $params['prematch'] = array( |
822 | 822 | 'salesforce_field' => $salesforce_field, |
823 | 823 | 'wordpress_field' => $wordpress_field, |
824 | - 'value' => $object[ $salesforce_field ], |
|
824 | + 'value' => $object[$salesforce_field], |
|
825 | 825 | 'method_read' => $fieldmap['wordpress_field']['methods']['read'], |
826 | 826 | 'method_create' => $fieldmap['wordpress_field']['methods']['create'], |
827 | 827 | 'method_update' => $fieldmap['wordpress_field']['methods']['update'], |
@@ -829,26 +829,26 @@ discard block |
||
829 | 829 | } |
830 | 830 | |
831 | 831 | // Skip fields that aren't being pulled from Salesforce. |
832 | - if ( ! in_array( $fieldmap['direction'], array_values( $this->direction_salesforce ), true ) ) { |
|
832 | + if ( ! in_array($fieldmap['direction'], array_values($this->direction_salesforce), true)) { |
|
833 | 833 | // The trigger is a Salesforce trigger, but the fieldmap direction is not a Salesforce direction. |
834 | - unset( $params[ $wordpress_field ] ); |
|
834 | + unset($params[$wordpress_field]); |
|
835 | 835 | // we also need to continue here, so it doesn't create an empty array below for fields that are WordPress -> Salesforce only |
836 | 836 | continue; |
837 | 837 | } |
838 | 838 | |
839 | - switch ( $trigger ) { |
|
839 | + switch ($trigger) { |
|
840 | 840 | case $this->sync_sf_create: |
841 | - $params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['create']; |
|
841 | + $params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['create']; |
|
842 | 842 | break; |
843 | 843 | case $this->sync_sf_update: |
844 | - $params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['update']; |
|
844 | + $params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['update']; |
|
845 | 845 | break; |
846 | 846 | case $this->sync_sf_delete: |
847 | - $params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['delete']; |
|
847 | + $params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['delete']; |
|
848 | 848 | break; |
849 | 849 | } |
850 | 850 | |
851 | - $params[ $wordpress_field ]['method_read'] = $fieldmap['wordpress_field']['methods']['read']; |
|
851 | + $params[$wordpress_field]['method_read'] = $fieldmap['wordpress_field']['methods']['read']; |
|
852 | 852 | |
853 | 853 | } // End if(). |
854 | 854 | } // End foreach(). |
@@ -865,14 +865,14 @@ discard block |
||
865 | 865 | * |
866 | 866 | * @return array $mappings Associative array of field maps ready to use |
867 | 867 | */ |
868 | - private function prepare_fieldmap_data( $mappings, $record_type = '' ) { |
|
869 | - |
|
870 | - foreach ( $mappings as $id => $mapping ) { |
|
871 | - $mappings[ $id ]['salesforce_record_types_allowed'] = maybe_unserialize( $mapping['salesforce_record_types_allowed'] ); |
|
872 | - $mappings[ $id ]['fields'] = maybe_unserialize( $mapping['fields'] ); |
|
873 | - $mappings[ $id ]['sync_triggers'] = maybe_unserialize( $mapping['sync_triggers'] ); |
|
874 | - if ( '' !== $record_type && ! in_array( $record_type, $mappings[ $id ]['salesforce_record_types_allowed'], true ) ) { |
|
875 | - unset( $mappings[ $id ] ); |
|
868 | + private function prepare_fieldmap_data($mappings, $record_type = '') { |
|
869 | + |
|
870 | + foreach ($mappings as $id => $mapping) { |
|
871 | + $mappings[$id]['salesforce_record_types_allowed'] = maybe_unserialize($mapping['salesforce_record_types_allowed']); |
|
872 | + $mappings[$id]['fields'] = maybe_unserialize($mapping['fields']); |
|
873 | + $mappings[$id]['sync_triggers'] = maybe_unserialize($mapping['sync_triggers']); |
|
874 | + if ('' !== $record_type && ! in_array($record_type, $mappings[$id]['salesforce_record_types_allowed'], true)) { |
|
875 | + unset($mappings[$id]); |
|
876 | 876 | } |
877 | 877 | } |
878 | 878 | |
@@ -888,12 +888,12 @@ discard block |
||
888 | 888 | public function get_failed_object_maps() { |
889 | 889 | $table = $this->object_map_table; |
890 | 890 | $errors = array(); |
891 | - $push_errors = $this->wpdb->get_results( 'SELECT * FROM ' . $table . ' WHERE salesforce_id LIKE "tmp_sf_%"', ARRAY_A ); |
|
892 | - $pull_errors = $this->wpdb->get_results( 'SELECT * FROM ' . $table . ' WHERE wordpress_id LIKE "tmp_wp_%"', ARRAY_A ); |
|
893 | - if ( ! empty( $push_errors ) ) { |
|
891 | + $push_errors = $this->wpdb->get_results('SELECT * FROM ' . $table . ' WHERE salesforce_id LIKE "tmp_sf_%"', ARRAY_A); |
|
892 | + $pull_errors = $this->wpdb->get_results('SELECT * FROM ' . $table . ' WHERE wordpress_id LIKE "tmp_wp_%"', ARRAY_A); |
|
893 | + if ( ! empty($push_errors)) { |
|
894 | 894 | $errors['push_errors'] = $push_errors; |
895 | 895 | } |
896 | - if ( ! empty( $pull_errors ) ) { |
|
896 | + if ( ! empty($pull_errors)) { |
|
897 | 897 | $errors['pull_errors'] = $pull_errors; |
898 | 898 | } |
899 | 899 | return $errors; |
@@ -906,11 +906,11 @@ discard block |
||
906 | 906 | * |
907 | 907 | * @return array $error Associative array of single row that failed to finish based on id |
908 | 908 | */ |
909 | - public function get_failed_object_map( $id ) { |
|
909 | + public function get_failed_object_map($id) { |
|
910 | 910 | $table = $this->object_map_table; |
911 | 911 | $error = array(); |
912 | - $error_row = $this->wpdb->get_row( 'SELECT * FROM ' . $table . ' WHERE id = "' . $id . '"', ARRAY_A ); |
|
913 | - if ( ! empty( $error_row ) ) { |
|
912 | + $error_row = $this->wpdb->get_row('SELECT * FROM ' . $table . ' WHERE id = "' . $id . '"', ARRAY_A); |
|
913 | + if ( ! empty($error_row)) { |
|
914 | 914 | $error = $error_row; |
915 | 915 | } |
916 | 916 | return $error; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * |
110 | 110 | */ |
111 | 111 | static public function get_instance() { |
112 | - if ( null === self::$instance ) { |
|
112 | + if (null === self::$instance) { |
|
113 | 113 | self::$instance = new Object_Sync_Salesforce(); |
114 | 114 | } |
115 | 115 | return self::$instance; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | ); |
146 | 146 | |
147 | 147 | // users can modify the list of schedulable classes |
148 | - $this->schedulable_classes = apply_filters( $this->option_prefix . 'modify_schedulable_classes', $this->schedulable_classes ); |
|
148 | + $this->schedulable_classes = apply_filters($this->option_prefix . 'modify_schedulable_classes', $this->schedulable_classes); |
|
149 | 149 | |
150 | 150 | /* |
151 | 151 | * example to modify the array of classes by adding one and removing one |
@@ -170,25 +170,25 @@ discard block |
||
170 | 170 | * } |
171 | 171 | */ |
172 | 172 | |
173 | - $this->load = $this->load( $this->wpdb, $this->version, $this->slug, $this->option_prefix ); |
|
173 | + $this->load = $this->load($this->wpdb, $this->version, $this->slug, $this->option_prefix); |
|
174 | 174 | |
175 | - $this->queue = $this->queue( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes ); |
|
175 | + $this->queue = $this->queue($this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes); |
|
176 | 176 | |
177 | - $this->activated = $this->activate( $this->wpdb, $this->version, $this->slug ); |
|
178 | - $this->deactivate( $this->wpdb, $this->version, $this->slug, $this->schedulable_classes ); |
|
177 | + $this->activated = $this->activate($this->wpdb, $this->version, $this->slug); |
|
178 | + $this->deactivate($this->wpdb, $this->version, $this->slug, $this->schedulable_classes); |
|
179 | 179 | |
180 | - $this->logging = $this->logging( $this->wpdb, $this->version, $this->slug, $this->option_prefix ); |
|
180 | + $this->logging = $this->logging($this->wpdb, $this->version, $this->slug, $this->option_prefix); |
|
181 | 181 | |
182 | - $this->mappings = $this->mappings( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->logging ); |
|
182 | + $this->mappings = $this->mappings($this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->logging); |
|
183 | 183 | |
184 | - $this->wordpress = $this->wordpress( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->mappings, $this->logging ); |
|
184 | + $this->wordpress = $this->wordpress($this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->mappings, $this->logging); |
|
185 | 185 | $this->salesforce = $this->salesforce_get_api(); |
186 | 186 | |
187 | - $this->push = $this->push( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue ); |
|
187 | + $this->push = $this->push($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue); |
|
188 | 188 | |
189 | - $this->pull = $this->pull( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue ); |
|
189 | + $this->pull = $this->pull($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue); |
|
190 | 190 | |
191 | - $this->load_admin( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->push, $this->pull, $this->logging, $this->schedulable_classes, $this->queue ); |
|
191 | + $this->load_admin($this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->push, $this->pull, $this->logging, $this->schedulable_classes, $this->queue); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | * @param string $option_prefix |
202 | 202 | * |
203 | 203 | */ |
204 | - private function load( $wpdb, $version, $slug, $option_prefix ) { |
|
205 | - require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
204 | + private function load($wpdb, $version, $slug, $option_prefix) { |
|
205 | + require_once plugin_dir_path(__FILE__) . 'vendor/autoload.php'; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | * @param array $schedulable_classes |
216 | 216 | * @return Object_Sync_Sf_Queue |
217 | 217 | */ |
218 | - public function queue( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ) { |
|
219 | - require_once plugin_dir_path( __FILE__ ) . 'classes/class-object-sync-sf-queue.php'; |
|
220 | - $queue = new Object_Sync_Sf_Queue( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ); |
|
218 | + public function queue($wpdb, $version, $slug, $option_prefix, $schedulable_classes) { |
|
219 | + require_once plugin_dir_path(__FILE__) . 'classes/class-object-sync-sf-queue.php'; |
|
220 | + $queue = new Object_Sync_Sf_Queue($wpdb, $version, $slug, $option_prefix, $schedulable_classes); |
|
221 | 221 | return $queue; |
222 | 222 | } |
223 | 223 | |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | * @return object |
233 | 233 | * Instance of Object_Sync_Sf_Logging |
234 | 234 | */ |
235 | - private function logging( $wpdb, $version, $slug, $option_prefix ) { |
|
236 | - require_once plugin_dir_path( __FILE__ ) . 'classes/logging.php'; |
|
237 | - $logging = new Object_Sync_Sf_Logging( $wpdb, $version, $slug, $option_prefix ); |
|
235 | + private function logging($wpdb, $version, $slug, $option_prefix) { |
|
236 | + require_once plugin_dir_path(__FILE__) . 'classes/logging.php'; |
|
237 | + $logging = new Object_Sync_Sf_Logging($wpdb, $version, $slug, $option_prefix); |
|
238 | 238 | return $logging; |
239 | 239 | } |
240 | 240 | |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | * @return object |
251 | 251 | * Instance of Object_Sync_Sf_Mapping |
252 | 252 | */ |
253 | - private function mappings( $wpdb, $version, $slug, $option_prefix, $logging ) { |
|
254 | - require_once( plugin_dir_path( __FILE__ ) . 'classes/salesforce_mapping.php' ); |
|
255 | - $mappings = new Object_Sync_Sf_Mapping( $wpdb, $version, $slug, $option_prefix, $logging ); |
|
253 | + private function mappings($wpdb, $version, $slug, $option_prefix, $logging) { |
|
254 | + require_once(plugin_dir_path(__FILE__) . 'classes/salesforce_mapping.php'); |
|
255 | + $mappings = new Object_Sync_Sf_Mapping($wpdb, $version, $slug, $option_prefix, $logging); |
|
256 | 256 | return $mappings; |
257 | 257 | } |
258 | 258 | |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | * @return object |
270 | 270 | * Instance of Object_Sync_Sf_WordPress |
271 | 271 | */ |
272 | - private function wordpress( $wpdb, $version, $slug, $option_prefix, $mappings, $logging ) { |
|
273 | - require_once plugin_dir_path( __FILE__ ) . 'classes/wordpress.php'; |
|
274 | - $wordpress = new Object_Sync_Sf_WordPress( $wpdb, $version, $slug, $option_prefix, $mappings, $logging ); |
|
272 | + private function wordpress($wpdb, $version, $slug, $option_prefix, $mappings, $logging) { |
|
273 | + require_once plugin_dir_path(__FILE__) . 'classes/wordpress.php'; |
|
274 | + $wordpress = new Object_Sync_Sf_WordPress($wpdb, $version, $slug, $option_prefix, $mappings, $logging); |
|
275 | 275 | return $wordpress; |
276 | 276 | } |
277 | 277 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * The sfapi object if it is authenticated (empty, otherwise) |
285 | 285 | */ |
286 | 286 | public function salesforce_get_api() { |
287 | - require_once( plugin_dir_path( __FILE__ ) . 'classes/salesforce.php' ); |
|
288 | - require_once( plugin_dir_path( __FILE__ ) . 'classes/salesforce_query.php' ); // this can be used to generate soql queries, but we don't often need it so it gets initialized whenever it's needed |
|
287 | + require_once(plugin_dir_path(__FILE__) . 'classes/salesforce.php'); |
|
288 | + require_once(plugin_dir_path(__FILE__) . 'classes/salesforce_query.php'); // this can be used to generate soql queries, but we don't often need it so it gets initialized whenever it's needed |
|
289 | 289 | $consumer_key = $this->login_credentials['consumer_key']; |
290 | 290 | $consumer_secret = $this->login_credentials['consumer_secret']; |
291 | 291 | $login_url = $this->login_credentials['login_url']; |
@@ -300,9 +300,9 @@ discard block |
||
300 | 300 | $schedulable_classes = $this->schedulable_classes; |
301 | 301 | $is_authorized = false; |
302 | 302 | $sfapi = ''; |
303 | - if ( $consumer_key && $consumer_secret ) { |
|
304 | - $sfapi = new Object_Sync_Sf_Salesforce( $consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $option_prefix, $logging, $schedulable_classes ); |
|
305 | - if ( $sfapi->is_authorized() === true ) { |
|
303 | + if ($consumer_key && $consumer_secret) { |
|
304 | + $sfapi = new Object_Sync_Sf_Salesforce($consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $option_prefix, $logging, $schedulable_classes); |
|
305 | + if ($sfapi->is_authorized() === true) { |
|
306 | 306 | $is_authorized = true; |
307 | 307 | } |
308 | 308 | } |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | * @return object |
323 | 323 | * Instance of Object_Sync_Sf_Activate |
324 | 324 | */ |
325 | - private function activate( $wpdb, $version, $slug ) { |
|
326 | - require_once plugin_dir_path( __FILE__ ) . 'classes/activate.php'; |
|
327 | - $activate = new Object_Sync_Sf_Activate( $wpdb, $version, $slug ); |
|
325 | + private function activate($wpdb, $version, $slug) { |
|
326 | + require_once plugin_dir_path(__FILE__) . 'classes/activate.php'; |
|
327 | + $activate = new Object_Sync_Sf_Activate($wpdb, $version, $slug); |
|
328 | 328 | return $activate; |
329 | 329 | } |
330 | 330 | |
@@ -339,9 +339,9 @@ discard block |
||
339 | 339 | * @return object |
340 | 340 | * Instance of Object_Sync_Sf_Deactivate |
341 | 341 | */ |
342 | - private function deactivate( $wpdb, $version, $slug, $schedulable_classes ) { |
|
343 | - require_once plugin_dir_path( __FILE__ ) . 'classes/deactivate.php'; |
|
344 | - $deactivate = new Object_Sync_Sf_Deactivate( $wpdb, $version, $slug, $schedulable_classes ); |
|
342 | + private function deactivate($wpdb, $version, $slug, $schedulable_classes) { |
|
343 | + require_once plugin_dir_path(__FILE__) . 'classes/deactivate.php'; |
|
344 | + $deactivate = new Object_Sync_Sf_Deactivate($wpdb, $version, $slug, $schedulable_classes); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | * @return object |
363 | 363 | * Instance of Object_Sync_Sf_Salesforce_Push |
364 | 364 | */ |
365 | - private function push( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
|
366 | - require_once plugin_dir_path( __FILE__ ) . 'classes/salesforce_push.php'; |
|
367 | - $push = new Object_Sync_Sf_Salesforce_Push( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ); |
|
365 | + private function push($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue) { |
|
366 | + require_once plugin_dir_path(__FILE__) . 'classes/salesforce_push.php'; |
|
367 | + $push = new Object_Sync_Sf_Salesforce_Push($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue); |
|
368 | 368 | return $push; |
369 | 369 | } |
370 | 370 | |
@@ -384,9 +384,9 @@ discard block |
||
384 | 384 | * @return object |
385 | 385 | * Instance of Object_Sync_Sf_Salesforce_Pull |
386 | 386 | */ |
387 | - private function pull( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
|
388 | - require_once plugin_dir_path( __FILE__ ) . 'classes/salesforce_pull.php'; |
|
389 | - $pull = new Object_Sync_Sf_Salesforce_Pull( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ); |
|
387 | + private function pull($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue) { |
|
388 | + require_once plugin_dir_path(__FILE__) . 'classes/salesforce_pull.php'; |
|
389 | + $pull = new Object_Sync_Sf_Salesforce_Pull($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue); |
|
390 | 390 | return $pull; |
391 | 391 | } |
392 | 392 | |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | * Instance of Object_Sync_Sf_Admin |
412 | 412 | * |
413 | 413 | */ |
414 | - private function load_admin( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) { |
|
415 | - require_once( plugin_dir_path( __FILE__ ) . 'classes/admin.php' ); |
|
416 | - $admin = new Object_Sync_Sf_Admin( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ); |
|
417 | - add_action( 'admin_menu', array( $admin, 'create_admin_menu' ) ); |
|
418 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_and_styles' ) ); |
|
419 | - add_action( 'plugins_loaded', array( $this, 'textdomain' ) ); |
|
420 | - add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 5 ); |
|
414 | + private function load_admin($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue) { |
|
415 | + require_once(plugin_dir_path(__FILE__) . 'classes/admin.php'); |
|
416 | + $admin = new Object_Sync_Sf_Admin($wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue); |
|
417 | + add_action('admin_menu', array($admin, 'create_admin_menu')); |
|
418 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts_and_styles')); |
|
419 | + add_action('plugins_loaded', array($this, 'textdomain')); |
|
420 | + add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 5); |
|
421 | 421 | return $admin; |
422 | 422 | } |
423 | 423 | |
@@ -429,11 +429,11 @@ discard block |
||
429 | 429 | * @return array $links |
430 | 430 | * These are the links that go with this plugin's entry |
431 | 431 | */ |
432 | - public function plugin_action_links( $links, $file ) { |
|
433 | - if ( plugin_basename( __FILE__ ) === $file ) { |
|
434 | - $settings = '<a href="' . get_admin_url() . 'options-general.php?page=object-sync-salesforce-admin">' . __( 'Settings', 'object-sync-for-salesforce' ) . '</a>'; |
|
432 | + public function plugin_action_links($links, $file) { |
|
433 | + if (plugin_basename(__FILE__) === $file) { |
|
434 | + $settings = '<a href="' . get_admin_url() . 'options-general.php?page=object-sync-salesforce-admin">' . __('Settings', 'object-sync-for-salesforce') . '</a>'; |
|
435 | 435 | // make the 'Settings' link appear first |
436 | - array_unshift( $links, $settings ); |
|
436 | + array_unshift($links, $settings); |
|
437 | 437 | } |
438 | 438 | return $links; |
439 | 439 | } |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | public function admin_scripts_and_styles() { |
448 | 448 | |
449 | 449 | // I think some developers might not want to bother with select2 or selectwoo, so let's allow that to be changeable |
450 | - $select_library = apply_filters( $this->option_prefix . 'select_library', 'selectwoo' ); |
|
450 | + $select_library = apply_filters($this->option_prefix . 'select_library', 'selectwoo'); |
|
451 | 451 | |
452 | 452 | /* |
453 | 453 | * example to modify the select library |
@@ -459,19 +459,19 @@ discard block |
||
459 | 459 | * } |
460 | 460 | */ |
461 | 461 | |
462 | - $javascript_dependencies = array( 'jquery' ); |
|
462 | + $javascript_dependencies = array('jquery'); |
|
463 | 463 | $css_dependencies = array(); |
464 | - if ( '' !== $select_library ) { |
|
465 | - wp_enqueue_script( $select_library . 'js', plugins_url( 'assets/js/' . $select_library . '.min.js', __FILE__ ), array( 'jquery' ), filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/' . $select_library . '.min.js' ), true ); |
|
464 | + if ('' !== $select_library) { |
|
465 | + wp_enqueue_script($select_library . 'js', plugins_url('assets/js/' . $select_library . '.min.js', __FILE__), array('jquery'), filemtime(plugin_dir_path(__FILE__) . 'assets/js/' . $select_library . '.min.js'), true); |
|
466 | 466 | $javascript_dependencies[] = $select_library . 'js'; |
467 | 467 | |
468 | - wp_enqueue_style( $select_library . 'css', plugins_url( 'assets/css/' . $select_library . '.min.css', __FILE__ ), array(), filemtime( plugin_dir_path( __FILE__ ) . 'assets/css/' . $select_library . '.min.css' ), 'all' ); |
|
468 | + wp_enqueue_style($select_library . 'css', plugins_url('assets/css/' . $select_library . '.min.css', __FILE__), array(), filemtime(plugin_dir_path(__FILE__) . 'assets/css/' . $select_library . '.min.css'), 'all'); |
|
469 | 469 | $css_dependencies[] = $select_library . 'css'; |
470 | 470 | } |
471 | 471 | |
472 | - wp_enqueue_script( $this->slug . '-admin', plugins_url( 'assets/js/object-sync-for-salesforce-admin.min.js', __FILE__ ), $javascript_dependencies, filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/object-sync-for-salesforce-admin.min.js' ), true ); |
|
472 | + wp_enqueue_script($this->slug . '-admin', plugins_url('assets/js/object-sync-for-salesforce-admin.min.js', __FILE__), $javascript_dependencies, filemtime(plugin_dir_path(__FILE__) . 'assets/js/object-sync-for-salesforce-admin.min.js'), true); |
|
473 | 473 | |
474 | - wp_enqueue_style( $this->slug . '-admin', plugins_url( 'assets/css/object-sync-for-salesforce-admin.min.css', __FILE__ ), $css_dependencies, filemtime( plugin_dir_path( __FILE__ ) . 'assets/css/object-sync-for-salesforce-admin.min.css' ), 'all' ); |
|
474 | + wp_enqueue_style($this->slug . '-admin', plugins_url('assets/css/object-sync-for-salesforce-admin.min.css', __FILE__), $css_dependencies, filemtime(plugin_dir_path(__FILE__) . 'assets/css/object-sync-for-salesforce-admin.min.css'), 'all'); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return void |
481 | 481 | */ |
482 | 482 | public function textdomain() { |
483 | - load_plugin_textdomain( 'object-sync-for-salesforce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
483 | + load_plugin_textdomain('object-sync-for-salesforce', false, dirname(plugin_basename(__FILE__)) . '/languages/'); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -493,13 +493,13 @@ discard block |
||
493 | 493 | */ |
494 | 494 | private function get_login_credentials() { |
495 | 495 | |
496 | - $consumer_key = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY : get_option( $this->option_prefix . 'consumer_key', '' ); |
|
497 | - $consumer_secret = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET : get_option( $this->option_prefix . 'consumer_secret', '' ); |
|
498 | - $callback_url = defined( 'OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL' ) ? OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL : get_option( $this->option_prefix . 'callback_url', '' ); |
|
499 | - $login_base_url = defined( 'OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL' ) ? OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL : get_option( $this->option_prefix . 'login_base_url', '' ); |
|
500 | - $authorize_url_path = defined( 'OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH' ) ? OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH : get_option( $this->option_prefix . 'authorize_url_path', '' ); |
|
501 | - $token_url_path = defined( 'OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH' ) ? OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH : get_option( $this->option_prefix . 'token_url_path', '' ); |
|
502 | - $api_version = defined( 'OBJECT_SYNC_SF_SALESFORCE_API_VERSION' ) ? OBJECT_SYNC_SF_SALESFORCE_API_VERSION : get_option( $this->option_prefix . 'api_version', '' ); |
|
496 | + $consumer_key = defined('OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY') ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY : get_option($this->option_prefix . 'consumer_key', ''); |
|
497 | + $consumer_secret = defined('OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET') ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET : get_option($this->option_prefix . 'consumer_secret', ''); |
|
498 | + $callback_url = defined('OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL') ? OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL : get_option($this->option_prefix . 'callback_url', ''); |
|
499 | + $login_base_url = defined('OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL') ? OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL : get_option($this->option_prefix . 'login_base_url', ''); |
|
500 | + $authorize_url_path = defined('OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH') ? OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH : get_option($this->option_prefix . 'authorize_url_path', ''); |
|
501 | + $token_url_path = defined('OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH') ? OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH : get_option($this->option_prefix . 'token_url_path', ''); |
|
502 | + $api_version = defined('OBJECT_SYNC_SF_SALESFORCE_API_VERSION') ? OBJECT_SYNC_SF_SALESFORCE_API_VERSION : get_option($this->option_prefix . 'api_version', ''); |
|
503 | 503 | |
504 | 504 | $login_credentials = array( |
505 | 505 | 'consumer_key' => $consumer_key, |