1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
Plugin Name: Object Sync for Salesforce |
4
|
|
|
Description: Object Sync for Salesforce maps and syncs data between Salesforce objects and WordPress objects. |
5
|
|
|
Version: 1.7.0 |
6
|
|
|
Author: MinnPost |
7
|
|
|
Author URI: https://code.minnpost.com |
8
|
|
|
License: GPL2+ |
9
|
|
|
License URI: https://www.gnu.org/licenses/gpl-2.0.html |
10
|
|
|
Text Domain: object-sync-for-salesforce |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Start up the Object Sync for Salesforce plugin; initialize parameters and classes |
15
|
|
|
*/ |
16
|
|
|
class Object_Sync_Salesforce { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var object |
20
|
|
|
* Global object of `$wpdb`, the WordPress database |
21
|
|
|
*/ |
22
|
|
|
private $wpdb; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
* The plugin's slug so we can include it when necessary |
27
|
|
|
*/ |
28
|
|
|
private $slug; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
* The plugin's option prefix |
33
|
|
|
*/ |
34
|
|
|
private $option_prefix; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array |
38
|
|
|
* Login credentials for the Salesforce API; comes from wp-config or from the plugin settings |
39
|
|
|
*/ |
40
|
|
|
private $login_credentials; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array |
44
|
|
|
* Array of what classes in the plugin can be scheduled to occur with `wp_cron` events |
45
|
|
|
*/ |
46
|
|
|
public $schedulable_classes; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
* Current version of the plugin |
51
|
|
|
*/ |
52
|
|
|
private $version; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var object |
56
|
|
|
*/ |
57
|
|
|
private $queue; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var object |
61
|
|
|
*/ |
62
|
|
|
private $activated; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var object |
66
|
|
|
* Load and initialize the Object_Sync_Sf_Logging class |
67
|
|
|
*/ |
68
|
|
|
private $logging; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var object |
72
|
|
|
* Load and initialize the Object_Sync_Sf_Mapping class |
73
|
|
|
*/ |
74
|
|
|
public $mappings; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var object |
78
|
|
|
* Load and initialize the Object_Sync_Sf_WordPress class |
79
|
|
|
*/ |
80
|
|
|
private $wordpress; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var object |
84
|
|
|
* Load and initialize the Object_Sync_Sf_Salesforce class. |
85
|
|
|
* This contains the Salesforce API methods |
86
|
|
|
*/ |
87
|
|
|
public $salesforce; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var object |
91
|
|
|
* Load and initialize the Object_Sync_Sf_Salesforce_Push class |
92
|
|
|
*/ |
93
|
|
|
private $push; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var object |
97
|
|
|
* Load and initialize the Object_Sync_Sf_Salesforce_Pull class |
98
|
|
|
*/ |
99
|
|
|
private $pull; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var object |
103
|
|
|
* Static property to hold an instance of the class; this seems to make it reusable |
104
|
|
|
* |
105
|
|
|
*/ |
106
|
|
|
static $instance = null; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Load the static $instance property that holds the instance of the class. |
110
|
|
|
* This instance makes the class reusable by other plugins |
111
|
|
|
* |
112
|
|
|
* @return object |
113
|
|
|
* The sfapi object if it is authenticated (empty, otherwise) |
114
|
|
|
* |
115
|
|
|
*/ |
116
|
|
|
static public function get_instance() { |
117
|
|
|
if ( null === self::$instance ) { |
118
|
|
|
self::$instance = new Object_Sync_Salesforce(); |
119
|
|
|
} |
120
|
|
|
return self::$instance; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Constructor that sets up the parameters to pass to all the other classes, and the methods that call the other classes |
125
|
|
|
* |
126
|
|
|
* @return void |
|
|
|
|
127
|
|
|
*/ |
128
|
|
|
protected function __construct() { |
129
|
|
|
|
130
|
|
|
global $wpdb; |
131
|
|
|
|
132
|
|
|
$this->wpdb = $wpdb; |
133
|
|
|
$this->version = '1.7.0'; |
134
|
|
|
$this->slug = 'object-sync-for-salesforce'; |
135
|
|
|
$this->option_prefix = 'object_sync_for_salesforce_'; |
136
|
|
|
$this->login_credentials = $this->get_login_credentials(); |
137
|
|
|
|
138
|
|
|
$this->schedulable_classes = array( |
139
|
|
|
'salesforce_push' => array( |
140
|
|
|
'label' => 'Push to Salesforce', |
141
|
|
|
'class' => 'Object_Sync_Sf_Salesforce_Push', |
142
|
|
|
'callback' => $this->option_prefix . 'push_record', |
143
|
|
|
), |
144
|
|
|
'salesforce_pull' => array( |
145
|
|
|
'label' => 'Pull from Salesforce', |
146
|
|
|
'class' => 'Object_Sync_Sf_Salesforce_Pull', |
147
|
|
|
'initializer' => $this->option_prefix . 'pull_check_records', |
148
|
|
|
'callback' => $this->option_prefix . 'pull_process_records', |
149
|
|
|
), |
150
|
|
|
); |
151
|
|
|
|
152
|
|
|
// users can modify the list of schedulable classes |
153
|
|
|
$this->schedulable_classes = apply_filters( $this->option_prefix . 'modify_schedulable_classes', $this->schedulable_classes ); |
154
|
|
|
|
155
|
|
|
/* |
156
|
|
|
* example to modify the array of classes by adding one and removing one |
157
|
|
|
* add_filter( 'object_sync_for_salesforce_modify_schedulable_classes', 'modify_schedulable_classes', 10, 1 ); |
158
|
|
|
* function modify_schedulable_classes( $schedulable_classes ) { |
159
|
|
|
* $schedulable_classes = array( |
160
|
|
|
* 'salesforce_push' => array( |
161
|
|
|
* 'label' => 'Push to Salesforce', |
162
|
|
|
* 'class' => 'Object_Sync_Sf_Salesforce_Push', |
163
|
|
|
* 'callback' => 'salesforce_push_sync_rest', |
164
|
|
|
* ), |
165
|
|
|
* 'wordpress' => array( // WPCS: spelling ok. |
166
|
|
|
* 'label' => 'WordPress', |
167
|
|
|
* 'class' => 'Object_Sync_Sf_WordPress', |
168
|
|
|
* ), |
169
|
|
|
* 'salesforce' => array( |
170
|
|
|
* 'label' => 'Salesforce Authorization', |
171
|
|
|
* 'class' => 'Object_Sync_Sf_Salesforce', |
172
|
|
|
* ), |
173
|
|
|
* ); |
174
|
|
|
* return $schedulable_classes; |
175
|
|
|
* } |
176
|
|
|
*/ |
177
|
|
|
|
178
|
|
|
$this->load = $this->load( $this->wpdb, $this->version, $this->slug, $this->option_prefix ); |
|
|
|
|
179
|
|
|
|
180
|
|
|
$this->queue = $this->queue( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes ); |
181
|
|
|
|
182
|
|
|
$this->activated = $this->activate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue ); |
183
|
|
|
$this->deactivate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue ); |
184
|
|
|
|
185
|
|
|
$this->logging = $this->logging( $this->wpdb, $this->version, $this->slug, $this->option_prefix ); |
186
|
|
|
|
187
|
|
|
$this->mappings = $this->mappings( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->logging ); |
188
|
|
|
|
189
|
|
|
$this->wordpress = $this->wordpress( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->mappings, $this->logging ); |
190
|
|
|
$this->salesforce = $this->salesforce_get_api(); |
|
|
|
|
191
|
|
|
|
192
|
|
|
$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 ); |
|
|
|
|
193
|
|
|
|
194
|
|
|
$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 ); |
|
|
|
|
195
|
|
|
|
196
|
|
|
$this->rest = $this->rest( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->push, $this->pull ); |
|
|
|
|
197
|
|
|
|
198
|
|
|
$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 ); |
|
|
|
|
199
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Load immediately required things |
204
|
|
|
* |
205
|
|
|
* @param object $wpdb |
206
|
|
|
* @param string $version |
207
|
|
|
* @param string $slug |
208
|
|
|
* @param string $option_prefix |
209
|
|
|
* |
210
|
|
|
*/ |
211
|
|
|
private function load( $wpdb, $version, $slug, $option_prefix ) { |
212
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Get queue instance. |
217
|
|
|
* |
218
|
|
|
* @param object $wpdb |
219
|
|
|
* @param string $version |
220
|
|
|
* @param string $slug |
221
|
|
|
* @param string $option_prefix |
222
|
|
|
* @param array $schedulable_classes |
223
|
|
|
* @return Object_Sync_Sf_Queue |
224
|
|
|
*/ |
225
|
|
|
private function queue( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ) { |
226
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/class-object-sync-sf-queue.php'; |
227
|
|
|
$queue = new Object_Sync_Sf_Queue( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ); |
228
|
|
|
return $queue; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Log events |
233
|
|
|
* |
234
|
|
|
* @param object $wpdb |
235
|
|
|
* @param string $version |
236
|
|
|
* @param string $slug |
237
|
|
|
* @param string $option_prefix |
238
|
|
|
* |
239
|
|
|
* @return object |
240
|
|
|
* Instance of Object_Sync_Sf_Logging |
241
|
|
|
*/ |
242
|
|
|
private function logging( $wpdb, $version, $slug, $option_prefix ) { |
243
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/logging.php'; |
244
|
|
|
$logging = new Object_Sync_Sf_Logging( $wpdb, $version, $slug, $option_prefix ); |
245
|
|
|
return $logging; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Map the Salesforce and WordPress objects and fields to each other |
250
|
|
|
* |
251
|
|
|
* @param object $wpdb |
252
|
|
|
* @param string $version |
253
|
|
|
* @param string $slug |
254
|
|
|
* @param string $option_prefix |
255
|
|
|
* @param object $logging |
256
|
|
|
* |
257
|
|
|
* @return object |
258
|
|
|
* Instance of Object_Sync_Sf_Mapping |
259
|
|
|
*/ |
260
|
|
|
private function mappings( $wpdb, $version, $slug, $option_prefix, $logging ) { |
261
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'classes/salesforce_mapping.php' ); |
262
|
|
|
$mappings = new Object_Sync_Sf_Mapping( $wpdb, $version, $slug, $logging, $option_prefix ); |
263
|
|
|
return $mappings; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Private helper to load methods for manipulating core WordPress data across the plugin |
268
|
|
|
* |
269
|
|
|
* @param object $wpdb |
270
|
|
|
* @param string $version |
271
|
|
|
* @param string $slug |
272
|
|
|
* @param string $option_prefix |
273
|
|
|
* @param object $mappings |
274
|
|
|
* @param object $logging |
275
|
|
|
* |
276
|
|
|
* @return object |
277
|
|
|
* Instance of Object_Sync_Sf_WordPress |
278
|
|
|
*/ |
279
|
|
|
private function wordpress( $wpdb, $version, $slug, $option_prefix, $mappings, $logging ) { |
280
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/wordpress.php'; |
281
|
|
|
$wordpress = new Object_Sync_Sf_WordPress( $wpdb, $version, $slug, $mappings, $logging, $option_prefix ); |
282
|
|
|
return $wordpress; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Public helper to load the Salesforce API and see if it is authenticated. |
287
|
|
|
* This is public so other plugins can access the same SF API instance |
288
|
|
|
* |
289
|
|
|
* @return array |
290
|
|
|
* Whether Salesforce is authenticated (boolean) |
291
|
|
|
* The sfapi object if it is authenticated (empty, otherwise) |
292
|
|
|
*/ |
293
|
|
|
public function salesforce_get_api() { |
294
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'classes/salesforce.php' ); |
295
|
|
|
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 |
296
|
|
|
$consumer_key = $this->login_credentials['consumer_key']; |
297
|
|
|
$consumer_secret = $this->login_credentials['consumer_secret']; |
298
|
|
|
$login_url = $this->login_credentials['login_url']; |
299
|
|
|
$callback_url = $this->login_credentials['callback_url']; |
300
|
|
|
$authorize_path = $this->login_credentials['authorize_path']; |
301
|
|
|
$token_path = $this->login_credentials['token_path']; |
302
|
|
|
$rest_api_version = $this->login_credentials['rest_api_version']; |
303
|
|
|
$slug = $this->slug; |
304
|
|
|
$option_prefix = $this->option_prefix; |
305
|
|
|
$wordpress = $this->wordpress; |
306
|
|
|
$logging = $this->logging; |
307
|
|
|
$schedulable_classes = $this->schedulable_classes; |
308
|
|
|
$is_authorized = false; |
309
|
|
|
$sfapi = ''; |
310
|
|
|
if ( $consumer_key && $consumer_secret ) { |
311
|
|
|
$sfapi = new Object_Sync_Sf_Salesforce( $consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $logging, $schedulable_classes, $option_prefix ); |
312
|
|
|
if ( $sfapi->is_authorized() === true ) { |
|
|
|
|
313
|
|
|
$is_authorized = true; |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
return array( |
317
|
|
|
'is_authorized' => $is_authorized, |
318
|
|
|
'sfapi' => $sfapi, |
319
|
|
|
); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* What to do upon activation of the plugin |
324
|
|
|
* |
325
|
|
|
* @param object $wpdb |
326
|
|
|
* @param string $version |
327
|
|
|
* @param string $slug |
328
|
|
|
* @param string $option_prefix |
329
|
|
|
* @param array $schedulable_classes |
330
|
|
|
* @param object $queue |
331
|
|
|
* |
332
|
|
|
* @return object |
333
|
|
|
* Instance of Object_Sync_Sf_Activate |
334
|
|
|
*/ |
335
|
|
|
private function activate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) { |
336
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/activate.php'; |
337
|
|
|
$activate = new Object_Sync_Sf_Activate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ); |
338
|
|
|
return $activate; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* What to do upon deactivation of the plugin |
343
|
|
|
* |
344
|
|
|
* @param object $wpdb |
345
|
|
|
* @param string $version |
346
|
|
|
* @param string $slug |
347
|
|
|
* @param string $option_prefix |
348
|
|
|
* @param array $schedulable_classes |
349
|
|
|
* @param object $queue |
350
|
|
|
* |
351
|
|
|
* @return object |
352
|
|
|
* Instance of Object_Sync_Sf_Deactivate |
353
|
|
|
*/ |
354
|
|
|
private function deactivate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) { |
355
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/deactivate.php'; |
356
|
|
|
$deactivate = new Object_Sync_Sf_Deactivate( $wpdb, $version, $slug, $schedulable_classes, $option_prefix, $queue ); |
|
|
|
|
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Methods to push data from WordPress to Salesforce |
362
|
|
|
* |
363
|
|
|
* @param object $wpdb |
364
|
|
|
* @param string $version |
365
|
|
|
* @param array $login_credentials |
366
|
|
|
* @param string $slug |
367
|
|
|
* @param string $object_prefix |
|
|
|
|
368
|
|
|
* @param object $wordpress |
369
|
|
|
* @param object $salesforce |
370
|
|
|
* @param object $mappings |
371
|
|
|
* @param object $logging |
372
|
|
|
* @param array $schedulable_classes |
373
|
|
|
* |
374
|
|
|
* @return object |
375
|
|
|
* Instance of Object_Sync_Sf_Salesforce_Push |
376
|
|
|
*/ |
377
|
|
|
private function push( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
378
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/salesforce_push.php'; |
379
|
|
|
$push = new Object_Sync_Sf_Salesforce_Push( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue, $option_prefix ); |
380
|
|
|
return $push; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Methods to pull data from Salesforce to WordPress |
385
|
|
|
* |
386
|
|
|
* @param object $wpdb |
387
|
|
|
* @param string $version |
388
|
|
|
* @param array $login_credentials |
389
|
|
|
* @param string $slug |
390
|
|
|
* @param string $option_prefix |
391
|
|
|
* @param object $wordpress |
392
|
|
|
* @param object $salesforce |
393
|
|
|
* @param object $mappings |
394
|
|
|
* @param object $logging |
395
|
|
|
* @param array $schedulable_classes |
396
|
|
|
* @return object |
397
|
|
|
* Instance of Object_Sync_Sf_Salesforce_Pull |
398
|
|
|
*/ |
399
|
|
|
private function pull( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
400
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/salesforce_pull.php'; |
401
|
|
|
$pull = new Object_Sync_Sf_Salesforce_Pull( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue, $option_prefix ); |
402
|
|
|
return $pull; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* Load the rest class. |
407
|
|
|
* This handles REST API methods |
408
|
|
|
* |
409
|
|
|
* @param object $wpdb |
410
|
|
|
* @param string $version |
411
|
|
|
* @param array $login_credentials |
|
|
|
|
412
|
|
|
* @param string $slug |
413
|
|
|
* @param string $option_prefix |
414
|
|
|
* @param object $wordpress |
415
|
|
|
* @param object $salesforce |
416
|
|
|
* @param object $mappings |
417
|
|
|
* @param object $push |
418
|
|
|
* @param object $pull |
419
|
|
|
* @param object $logging |
|
|
|
|
420
|
|
|
* @param array $schedulable_classes |
|
|
|
|
421
|
|
|
* @param object $queue |
|
|
|
|
422
|
|
|
* @return object $admin |
423
|
|
|
* Instance of Object_Sync_Sf_Rest |
424
|
|
|
* |
425
|
|
|
*/ |
426
|
|
|
private function rest( $wpdb, $version, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull ) { |
427
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'classes/class-object-sync-sf-rest.php' ); |
428
|
|
|
$rest = new Object_Sync_Sf_Rest( $wpdb, $version, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull ); |
429
|
|
|
return $rest; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Load the admin class. |
434
|
|
|
* This also creates admin menu, unless the plugin that calls this library has indicated that it has its own menu |
435
|
|
|
* |
436
|
|
|
* @param object $wpdb |
437
|
|
|
* @param string $version |
438
|
|
|
* @param array $login_credentials |
439
|
|
|
* @param string $slug |
440
|
|
|
* @param string $option_prefix |
441
|
|
|
* @param object $wordpress |
442
|
|
|
* @param object $salesforce |
443
|
|
|
* @param object $mappings |
444
|
|
|
* @param object $push |
445
|
|
|
* @param object $pull |
446
|
|
|
* @param object $logging |
447
|
|
|
* @param array $schedulable_classes |
448
|
|
|
* @param object $queue |
449
|
|
|
* @return object $admin |
450
|
|
|
* Instance of Object_Sync_Sf_Admin |
451
|
|
|
* |
452
|
|
|
*/ |
453
|
|
|
private function load_admin( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) { |
454
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'classes/admin.php' ); |
455
|
|
|
$admin = new Object_Sync_Sf_Admin( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue, $option_prefix ); |
456
|
|
|
add_action( 'admin_menu', array( $admin, 'create_admin_menu' ) ); |
457
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_and_styles' ) ); |
458
|
|
|
add_action( 'plugins_loaded', array( $this, 'textdomain' ) ); |
459
|
|
|
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 5 ); |
460
|
|
|
return $admin; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Display a Settings link on the main Plugins page |
465
|
|
|
* |
466
|
|
|
* @param array $links |
467
|
|
|
* @param string $file |
468
|
|
|
* @return array $links |
469
|
|
|
* These are the links that go with this plugin's entry |
470
|
|
|
*/ |
471
|
|
|
public function plugin_action_links( $links, $file ) { |
472
|
|
|
if ( plugin_basename( __FILE__ ) === $file ) { |
473
|
|
|
$settings = '<a href="' . get_admin_url() . 'options-general.php?page=object-sync-salesforce-admin">' . __( 'Settings', 'object-sync-for-salesforce' ) . '</a>'; |
474
|
|
|
// make the 'Settings' link appear first |
475
|
|
|
array_unshift( $links, $settings ); |
476
|
|
|
} |
477
|
|
|
return $links; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Admin styles. Load the CSS and JavaScript for the plugin's settings |
483
|
|
|
* |
484
|
|
|
* @return void |
485
|
|
|
*/ |
486
|
|
|
public function admin_scripts_and_styles() { |
487
|
|
|
|
488
|
|
|
// I think some developers might not want to bother with select2 or selectwoo, so let's allow that to be changeable |
489
|
|
|
$select_library = apply_filters( $this->option_prefix . 'select_library', 'selectwoo' ); |
490
|
|
|
|
491
|
|
|
/* |
492
|
|
|
* example to modify the select library |
493
|
|
|
* add_filter( 'object_sync_for_salesforce_select_library', 'select_library', 10, 1 ); |
494
|
|
|
* function select_library( $select_library ) { |
495
|
|
|
* $select_library = 'select2'; |
496
|
|
|
* // this could also be empty; in that case we would just use default browser select |
497
|
|
|
* return $select_library; |
498
|
|
|
* } |
499
|
|
|
*/ |
500
|
|
|
|
501
|
|
|
$javascript_dependencies = array( 'jquery' ); |
502
|
|
|
$css_dependencies = array(); |
503
|
|
|
if ( '' !== $select_library ) { |
504
|
|
|
wp_enqueue_script( $select_library . 'js', plugins_url( 'assets/js/vendor/' . $select_library . '.min.js', __FILE__ ), array( 'jquery' ), filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/vendor/' . $select_library . '.min.js' ), true ); |
505
|
|
|
$javascript_dependencies[] = $select_library . 'js'; |
506
|
|
|
|
507
|
|
|
wp_enqueue_style( $select_library . 'css', plugins_url( 'assets/css/vendor/' . $select_library . '.min.css', __FILE__ ), array(), filemtime( plugin_dir_path( __FILE__ ) . 'assets/css/vendor/' . $select_library . '.min.css' ), 'all' ); |
508
|
|
|
$css_dependencies[] = $select_library . 'css'; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
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 ); |
512
|
|
|
|
513
|
|
|
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' ); |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* Load textdomain |
518
|
|
|
* |
519
|
|
|
* @return void |
520
|
|
|
*/ |
521
|
|
|
public function textdomain() { |
522
|
|
|
load_plugin_textdomain( 'object-sync-for-salesforce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* Get the pre-login Salesforce credentials. |
527
|
|
|
* These depend on the plugin's settings or constants defined in wp-config.php. |
528
|
|
|
* |
529
|
|
|
* @return array $login_credentials |
530
|
|
|
* Includes all settings necessary to log into the Salesforce API. |
531
|
|
|
* Replaces settings options with wp-config.php values if they exist. |
532
|
|
|
*/ |
533
|
|
|
private function get_login_credentials() { |
534
|
|
|
|
535
|
|
|
$consumer_key = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY : get_option( $this->option_prefix . 'consumer_key', '' ); |
536
|
|
|
$consumer_secret = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET : get_option( $this->option_prefix . 'consumer_secret', '' ); |
537
|
|
|
$callback_url = defined( 'OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL' ) ? OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL : get_option( $this->option_prefix . 'callback_url', '' ); |
538
|
|
|
$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', '' ); |
539
|
|
|
$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', '' ); |
540
|
|
|
$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', '' ); |
541
|
|
|
$api_version = defined( 'OBJECT_SYNC_SF_SALESFORCE_API_VERSION' ) ? OBJECT_SYNC_SF_SALESFORCE_API_VERSION : get_option( $this->option_prefix . 'api_version', '' ); |
542
|
|
|
|
543
|
|
|
$login_credentials = array( |
544
|
|
|
'consumer_key' => $consumer_key, |
545
|
|
|
'consumer_secret' => $consumer_secret, |
546
|
|
|
'callback_url' => $callback_url, |
547
|
|
|
'login_url' => $login_base_url, |
548
|
|
|
'authorize_path' => $authorize_url_path, |
549
|
|
|
'token_path' => $token_url_path, |
550
|
|
|
'rest_api_version' => $api_version, |
551
|
|
|
); |
552
|
|
|
|
553
|
|
|
return $login_credentials; |
554
|
|
|
|
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
} // end class |
558
|
|
|
|
559
|
|
|
// Instantiate our class. We do it early because ActionScheduler has to have access to plugins_loaded with priority of zero. |
560
|
|
|
add_action( 'plugins_loaded', array( 'Object_Sync_Salesforce', 'get_instance' ), -10 ); |
561
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.