|
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->queue = $this->queue( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes ); |
|
179
|
|
|
|
|
180
|
|
|
$this->activated = $this->activate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue ); |
|
181
|
|
|
|
|
182
|
|
|
// Run non-activation things. We do this early because ActionScheduler has to have access to plugins_loaded with priority of zero. |
|
183
|
|
|
add_action( 'plugins_loaded', array( $this, 'run' ), -10 ); |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* run the plugin, independent of activation methods. |
|
189
|
|
|
* |
|
190
|
|
|
*/ |
|
191
|
|
|
public function run() { |
|
192
|
|
|
|
|
193
|
|
|
$this->load = $this->load( $this->wpdb, $this->version, $this->slug, $this->option_prefix ); |
|
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
$this->deactivate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue ); |
|
196
|
|
|
|
|
197
|
|
|
$this->logging = $this->logging( $this->wpdb, $this->version, $this->slug, $this->option_prefix ); |
|
198
|
|
|
|
|
199
|
|
|
$this->mappings = $this->mappings( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->logging ); |
|
200
|
|
|
|
|
201
|
|
|
$this->wordpress = $this->wordpress( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->mappings, $this->logging ); |
|
202
|
|
|
$this->salesforce = $this->salesforce_get_api(); |
|
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
$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 ); |
|
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
$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 ); |
|
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
$this->rest = $this->rest( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->push, $this->pull ); |
|
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
$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 ); |
|
|
|
|
|
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Load immediately required things |
|
215
|
|
|
* |
|
216
|
|
|
* @param object $wpdb |
|
217
|
|
|
* @param string $version |
|
218
|
|
|
* @param string $slug |
|
219
|
|
|
* @param string $option_prefix |
|
220
|
|
|
* |
|
221
|
|
|
*/ |
|
222
|
|
|
private function load( $wpdb, $version, $slug, $option_prefix ) { |
|
223
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Get queue instance. |
|
228
|
|
|
* |
|
229
|
|
|
* @param object $wpdb |
|
230
|
|
|
* @param string $version |
|
231
|
|
|
* @param string $slug |
|
232
|
|
|
* @param string $option_prefix |
|
233
|
|
|
* @param array $schedulable_classes |
|
234
|
|
|
* @return Object_Sync_Sf_Queue |
|
235
|
|
|
*/ |
|
236
|
|
|
private function queue( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ) { |
|
237
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/class-object-sync-sf-queue.php'; |
|
238
|
|
|
$queue = new Object_Sync_Sf_Queue( $wpdb, $version, $slug, $option_prefix, $schedulable_classes ); |
|
239
|
|
|
return $queue; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Log events |
|
244
|
|
|
* |
|
245
|
|
|
* @param object $wpdb |
|
246
|
|
|
* @param string $version |
|
247
|
|
|
* @param string $slug |
|
248
|
|
|
* @param string $option_prefix |
|
249
|
|
|
* |
|
250
|
|
|
* @return object |
|
251
|
|
|
* Instance of Object_Sync_Sf_Logging |
|
252
|
|
|
*/ |
|
253
|
|
|
private function logging( $wpdb, $version, $slug, $option_prefix ) { |
|
254
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/logging.php'; |
|
255
|
|
|
$logging = new Object_Sync_Sf_Logging( $wpdb, $version, $slug, $option_prefix ); |
|
256
|
|
|
return $logging; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Map the Salesforce and WordPress objects and fields to each other |
|
261
|
|
|
* |
|
262
|
|
|
* @param object $wpdb |
|
263
|
|
|
* @param string $version |
|
264
|
|
|
* @param string $slug |
|
265
|
|
|
* @param string $option_prefix |
|
266
|
|
|
* @param object $logging |
|
267
|
|
|
* |
|
268
|
|
|
* @return object |
|
269
|
|
|
* Instance of Object_Sync_Sf_Mapping |
|
270
|
|
|
*/ |
|
271
|
|
|
private function mappings( $wpdb, $version, $slug, $option_prefix, $logging ) { |
|
272
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'classes/salesforce_mapping.php' ); |
|
273
|
|
|
$mappings = new Object_Sync_Sf_Mapping( $wpdb, $version, $slug, $logging, $option_prefix ); |
|
274
|
|
|
return $mappings; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Private helper to load methods for manipulating core WordPress data across the plugin |
|
279
|
|
|
* |
|
280
|
|
|
* @param object $wpdb |
|
281
|
|
|
* @param string $version |
|
282
|
|
|
* @param string $slug |
|
283
|
|
|
* @param string $option_prefix |
|
284
|
|
|
* @param object $mappings |
|
285
|
|
|
* @param object $logging |
|
286
|
|
|
* |
|
287
|
|
|
* @return object |
|
288
|
|
|
* Instance of Object_Sync_Sf_WordPress |
|
289
|
|
|
*/ |
|
290
|
|
|
private function wordpress( $wpdb, $version, $slug, $option_prefix, $mappings, $logging ) { |
|
291
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/wordpress.php'; |
|
292
|
|
|
$wordpress = new Object_Sync_Sf_WordPress( $wpdb, $version, $slug, $mappings, $logging, $option_prefix ); |
|
293
|
|
|
return $wordpress; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Public helper to load the Salesforce API and see if it is authenticated. |
|
298
|
|
|
* This is public so other plugins can access the same SF API instance |
|
299
|
|
|
* |
|
300
|
|
|
* @return array |
|
301
|
|
|
* Whether Salesforce is authenticated (boolean) |
|
302
|
|
|
* The sfapi object if it is authenticated (empty, otherwise) |
|
303
|
|
|
*/ |
|
304
|
|
|
public function salesforce_get_api() { |
|
305
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'classes/salesforce.php' ); |
|
306
|
|
|
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 |
|
307
|
|
|
$consumer_key = $this->login_credentials['consumer_key']; |
|
308
|
|
|
$consumer_secret = $this->login_credentials['consumer_secret']; |
|
309
|
|
|
$login_url = $this->login_credentials['login_url']; |
|
310
|
|
|
$callback_url = $this->login_credentials['callback_url']; |
|
311
|
|
|
$authorize_path = $this->login_credentials['authorize_path']; |
|
312
|
|
|
$token_path = $this->login_credentials['token_path']; |
|
313
|
|
|
$rest_api_version = $this->login_credentials['rest_api_version']; |
|
314
|
|
|
$slug = $this->slug; |
|
315
|
|
|
$option_prefix = $this->option_prefix; |
|
316
|
|
|
$wordpress = $this->wordpress; |
|
317
|
|
|
$logging = $this->logging; |
|
318
|
|
|
$schedulable_classes = $this->schedulable_classes; |
|
319
|
|
|
$is_authorized = false; |
|
320
|
|
|
$sfapi = ''; |
|
321
|
|
|
if ( $consumer_key && $consumer_secret ) { |
|
322
|
|
|
$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 ); |
|
323
|
|
|
if ( $sfapi->is_authorized() === true ) { |
|
|
|
|
|
|
324
|
|
|
$is_authorized = true; |
|
325
|
|
|
} |
|
326
|
|
|
} |
|
327
|
|
|
return array( |
|
328
|
|
|
'is_authorized' => $is_authorized, |
|
329
|
|
|
'sfapi' => $sfapi, |
|
330
|
|
|
); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* What to do upon activation of the plugin |
|
335
|
|
|
* |
|
336
|
|
|
* @param object $wpdb |
|
337
|
|
|
* @param string $version |
|
338
|
|
|
* @param string $slug |
|
339
|
|
|
* @param string $option_prefix |
|
340
|
|
|
* @param array $schedulable_classes |
|
341
|
|
|
* @param object $queue |
|
342
|
|
|
* |
|
343
|
|
|
* @return object |
|
344
|
|
|
* Instance of Object_Sync_Sf_Activate |
|
345
|
|
|
*/ |
|
346
|
|
|
private function activate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) { |
|
347
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/activate.php'; |
|
348
|
|
|
$activate = new Object_Sync_Sf_Activate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ); |
|
349
|
|
|
return $activate; |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
/** |
|
353
|
|
|
* What to do upon deactivation of the plugin |
|
354
|
|
|
* |
|
355
|
|
|
* @param object $wpdb |
|
356
|
|
|
* @param string $version |
|
357
|
|
|
* @param string $slug |
|
358
|
|
|
* @param string $option_prefix |
|
359
|
|
|
* @param array $schedulable_classes |
|
360
|
|
|
* @param object $queue |
|
361
|
|
|
* |
|
362
|
|
|
* @return object |
|
363
|
|
|
* Instance of Object_Sync_Sf_Deactivate |
|
364
|
|
|
*/ |
|
365
|
|
|
private function deactivate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) { |
|
366
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/deactivate.php'; |
|
367
|
|
|
$deactivate = new Object_Sync_Sf_Deactivate( $wpdb, $version, $slug, $schedulable_classes, $option_prefix, $queue ); |
|
|
|
|
|
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
/** |
|
372
|
|
|
* Methods to push data from WordPress to Salesforce |
|
373
|
|
|
* |
|
374
|
|
|
* @param object $wpdb |
|
375
|
|
|
* @param string $version |
|
376
|
|
|
* @param array $login_credentials |
|
377
|
|
|
* @param string $slug |
|
378
|
|
|
* @param string $object_prefix |
|
|
|
|
|
|
379
|
|
|
* @param object $wordpress |
|
380
|
|
|
* @param object $salesforce |
|
381
|
|
|
* @param object $mappings |
|
382
|
|
|
* @param object $logging |
|
383
|
|
|
* @param array $schedulable_classes |
|
384
|
|
|
* |
|
385
|
|
|
* @return object |
|
386
|
|
|
* Instance of Object_Sync_Sf_Salesforce_Push |
|
387
|
|
|
*/ |
|
388
|
|
|
private function push( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
|
389
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/salesforce_push.php'; |
|
390
|
|
|
$push = new Object_Sync_Sf_Salesforce_Push( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue, $option_prefix ); |
|
391
|
|
|
return $push; |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* Methods to pull data from Salesforce to WordPress |
|
396
|
|
|
* |
|
397
|
|
|
* @param object $wpdb |
|
398
|
|
|
* @param string $version |
|
399
|
|
|
* @param array $login_credentials |
|
400
|
|
|
* @param string $slug |
|
401
|
|
|
* @param string $option_prefix |
|
402
|
|
|
* @param object $wordpress |
|
403
|
|
|
* @param object $salesforce |
|
404
|
|
|
* @param object $mappings |
|
405
|
|
|
* @param object $logging |
|
406
|
|
|
* @param array $schedulable_classes |
|
407
|
|
|
* @return object |
|
408
|
|
|
* Instance of Object_Sync_Sf_Salesforce_Pull |
|
409
|
|
|
*/ |
|
410
|
|
|
private function pull( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) { |
|
411
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'classes/salesforce_pull.php'; |
|
412
|
|
|
$pull = new Object_Sync_Sf_Salesforce_Pull( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue, $option_prefix ); |
|
413
|
|
|
return $pull; |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
/** |
|
417
|
|
|
* Load the rest class. |
|
418
|
|
|
* This handles REST API methods |
|
419
|
|
|
* |
|
420
|
|
|
* @param object $wpdb |
|
421
|
|
|
* @param string $version |
|
422
|
|
|
* @param array $login_credentials |
|
|
|
|
|
|
423
|
|
|
* @param string $slug |
|
424
|
|
|
* @param string $option_prefix |
|
425
|
|
|
* @param object $wordpress |
|
426
|
|
|
* @param object $salesforce |
|
427
|
|
|
* @param object $mappings |
|
428
|
|
|
* @param object $push |
|
429
|
|
|
* @param object $pull |
|
430
|
|
|
* @param object $logging |
|
|
|
|
|
|
431
|
|
|
* @param array $schedulable_classes |
|
|
|
|
|
|
432
|
|
|
* @param object $queue |
|
|
|
|
|
|
433
|
|
|
* @return object $admin |
|
434
|
|
|
* Instance of Object_Sync_Sf_Rest |
|
435
|
|
|
* |
|
436
|
|
|
*/ |
|
437
|
|
|
private function rest( $wpdb, $version, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull ) { |
|
438
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'classes/class-object-sync-sf-rest.php' ); |
|
439
|
|
|
$rest = new Object_Sync_Sf_Rest( $wpdb, $version, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull ); |
|
440
|
|
|
return $rest; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* Load the admin class. |
|
445
|
|
|
* This also creates admin menu, unless the plugin that calls this library has indicated that it has its own menu |
|
446
|
|
|
* |
|
447
|
|
|
* @param object $wpdb |
|
448
|
|
|
* @param string $version |
|
449
|
|
|
* @param array $login_credentials |
|
450
|
|
|
* @param string $slug |
|
451
|
|
|
* @param string $option_prefix |
|
452
|
|
|
* @param object $wordpress |
|
453
|
|
|
* @param object $salesforce |
|
454
|
|
|
* @param object $mappings |
|
455
|
|
|
* @param object $push |
|
456
|
|
|
* @param object $pull |
|
457
|
|
|
* @param object $logging |
|
458
|
|
|
* @param array $schedulable_classes |
|
459
|
|
|
* @param object $queue |
|
460
|
|
|
* @return object $admin |
|
461
|
|
|
* Instance of Object_Sync_Sf_Admin |
|
462
|
|
|
* |
|
463
|
|
|
*/ |
|
464
|
|
|
private function load_admin( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) { |
|
465
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'classes/admin.php' ); |
|
466
|
|
|
$admin = new Object_Sync_Sf_Admin( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue, $option_prefix ); |
|
467
|
|
|
add_action( 'admin_menu', array( $admin, 'create_admin_menu' ) ); |
|
468
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_and_styles' ) ); |
|
469
|
|
|
add_action( 'plugins_loaded', array( $this, 'textdomain' ) ); |
|
470
|
|
|
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 5 ); |
|
471
|
|
|
return $admin; |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
/** |
|
475
|
|
|
* Display a Settings link on the main Plugins page |
|
476
|
|
|
* |
|
477
|
|
|
* @param array $links |
|
478
|
|
|
* @param string $file |
|
479
|
|
|
* @return array $links |
|
480
|
|
|
* These are the links that go with this plugin's entry |
|
481
|
|
|
*/ |
|
482
|
|
|
public function plugin_action_links( $links, $file ) { |
|
483
|
|
|
if ( plugin_basename( __FILE__ ) === $file ) { |
|
484
|
|
|
$settings = '<a href="' . get_admin_url() . 'options-general.php?page=object-sync-salesforce-admin">' . __( 'Settings', 'object-sync-for-salesforce' ) . '</a>'; |
|
485
|
|
|
// make the 'Settings' link appear first |
|
486
|
|
|
array_unshift( $links, $settings ); |
|
487
|
|
|
} |
|
488
|
|
|
return $links; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
|
|
492
|
|
|
/** |
|
493
|
|
|
* Admin styles. Load the CSS and JavaScript for the plugin's settings |
|
494
|
|
|
* |
|
495
|
|
|
* @return void |
|
496
|
|
|
*/ |
|
497
|
|
|
public function admin_scripts_and_styles() { |
|
498
|
|
|
|
|
499
|
|
|
// I think some developers might not want to bother with select2 or selectwoo, so let's allow that to be changeable |
|
500
|
|
|
$select_library = apply_filters( $this->option_prefix . 'select_library', 'selectwoo' ); |
|
501
|
|
|
|
|
502
|
|
|
/* |
|
503
|
|
|
* example to modify the select library |
|
504
|
|
|
* add_filter( 'object_sync_for_salesforce_select_library', 'select_library', 10, 1 ); |
|
505
|
|
|
* function select_library( $select_library ) { |
|
506
|
|
|
* $select_library = 'select2'; |
|
507
|
|
|
* // this could also be empty; in that case we would just use default browser select |
|
508
|
|
|
* return $select_library; |
|
509
|
|
|
* } |
|
510
|
|
|
*/ |
|
511
|
|
|
|
|
512
|
|
|
$javascript_dependencies = array( 'jquery' ); |
|
513
|
|
|
$css_dependencies = array(); |
|
514
|
|
|
if ( '' !== $select_library ) { |
|
515
|
|
|
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 ); |
|
516
|
|
|
$javascript_dependencies[] = $select_library . 'js'; |
|
517
|
|
|
|
|
518
|
|
|
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' ); |
|
519
|
|
|
$css_dependencies[] = $select_library . 'css'; |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
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 ); |
|
523
|
|
|
|
|
524
|
|
|
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' ); |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
/** |
|
528
|
|
|
* Load textdomain |
|
529
|
|
|
* |
|
530
|
|
|
* @return void |
|
531
|
|
|
*/ |
|
532
|
|
|
public function textdomain() { |
|
533
|
|
|
load_plugin_textdomain( 'object-sync-for-salesforce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
/** |
|
537
|
|
|
* Get the pre-login Salesforce credentials. |
|
538
|
|
|
* These depend on the plugin's settings or constants defined in wp-config.php. |
|
539
|
|
|
* |
|
540
|
|
|
* @return array $login_credentials |
|
541
|
|
|
* Includes all settings necessary to log into the Salesforce API. |
|
542
|
|
|
* Replaces settings options with wp-config.php values if they exist. |
|
543
|
|
|
*/ |
|
544
|
|
|
private function get_login_credentials() { |
|
545
|
|
|
|
|
546
|
|
|
$consumer_key = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY : get_option( $this->option_prefix . 'consumer_key', '' ); |
|
547
|
|
|
$consumer_secret = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET : get_option( $this->option_prefix . 'consumer_secret', '' ); |
|
548
|
|
|
$callback_url = defined( 'OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL' ) ? OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL : get_option( $this->option_prefix . 'callback_url', '' ); |
|
549
|
|
|
$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', '' ); |
|
550
|
|
|
$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', '' ); |
|
551
|
|
|
$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', '' ); |
|
552
|
|
|
$api_version = defined( 'OBJECT_SYNC_SF_SALESFORCE_API_VERSION' ) ? OBJECT_SYNC_SF_SALESFORCE_API_VERSION : get_option( $this->option_prefix . 'api_version', '' ); |
|
553
|
|
|
|
|
554
|
|
|
$login_credentials = array( |
|
555
|
|
|
'consumer_key' => $consumer_key, |
|
556
|
|
|
'consumer_secret' => $consumer_secret, |
|
557
|
|
|
'callback_url' => $callback_url, |
|
558
|
|
|
'login_url' => $login_base_url, |
|
559
|
|
|
'authorize_path' => $authorize_url_path, |
|
560
|
|
|
'token_path' => $token_url_path, |
|
561
|
|
|
'rest_api_version' => $api_version, |
|
562
|
|
|
); |
|
563
|
|
|
|
|
564
|
|
|
return $login_credentials; |
|
565
|
|
|
|
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
} // end class |
|
569
|
|
|
|
|
570
|
|
|
// Instantiate our class. |
|
571
|
|
|
$object_sync_salesforce = Object_Sync_Salesforce::get_instance(); |
|
572
|
|
|
|
Adding a
@returnannotation 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.