Completed
Push — master ( 48bc46...861ddb )
by Jonathan
04:46 queued 34s
created

Object_Sync_Salesforce::pull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 11
dl 0
loc 4
rs 10
c 2
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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.8.3
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.8.3';
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 );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->load is correct as $this->load($this->wpdb,..., $this->option_prefix) targeting Object_Sync_Salesforce::load() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug Best Practice introduced by
The property load does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->salesforce_get_api() of type array<string,Object_Sync...esforce|boolean|string> is incompatible with the declared type object of property $salesforce.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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 );
0 ignored issues
show
Bug introduced by
$this->salesforce of type array<string,Object_Sync...esforce|boolean|string> is incompatible with the type object expected by parameter $salesforce of Object_Sync_Salesforce::push(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

204
		$this->push = $this->push( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, /** @scrutinizer ignore-type */ $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue );
Loading history...
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 );
0 ignored issues
show
Bug introduced by
$this->salesforce of type array<string,Object_Sync...esforce|boolean|string> is incompatible with the type object expected by parameter $salesforce of Object_Sync_Salesforce::pull(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

206
		$this->pull = $this->pull( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, /** @scrutinizer ignore-type */ $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue );
Loading history...
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 );
0 ignored issues
show
Bug Best Practice introduced by
The property rest does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
$this->salesforce of type array<string,Object_Sync...esforce|boolean|string> is incompatible with the type object expected by parameter $salesforce of Object_Sync_Salesforce::rest(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

208
		$this->rest = $this->rest( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->wordpress, /** @scrutinizer ignore-type */ $this->salesforce, $this->mappings, $this->push, $this->pull );
Loading history...
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 );
0 ignored issues
show
Bug introduced by
$this->salesforce of type array<string,Object_Sync...esforce|boolean|string> is incompatible with the type object expected by parameter $salesforce of Object_Sync_Salesforce::load_admin(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

210
		$this->load_admin( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, /** @scrutinizer ignore-type */ $this->salesforce, $this->mappings, $this->push, $this->pull, $this->logging, $this->schedulable_classes, $this->queue );
Loading history...
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 ) {
0 ignored issues
show
Unused Code introduced by
The parameter $wpdb is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

222
	private function load( /** @scrutinizer ignore-unused */ $wpdb, $version, $slug, $option_prefix ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $slug is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

222
	private function load( $wpdb, $version, /** @scrutinizer ignore-unused */ $slug, $option_prefix ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $version is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

222
	private function load( $wpdb, /** @scrutinizer ignore-unused */ $version, $slug, $option_prefix ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $option_prefix is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

222
	private function load( $wpdb, $version, $slug, /** @scrutinizer ignore-unused */ $option_prefix ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
		require_once( plugin_dir_path( __FILE__ ) . 'classes/salesforce_soap_partner.php' );
308
		$consumer_key        = $this->login_credentials['consumer_key'];
309
		$consumer_secret     = $this->login_credentials['consumer_secret'];
310
		$login_url           = $this->login_credentials['login_url'];
311
		$callback_url        = $this->login_credentials['callback_url'];
312
		$authorize_path      = $this->login_credentials['authorize_path'];
313
		$token_path          = $this->login_credentials['token_path'];
314
		$rest_api_version    = $this->login_credentials['rest_api_version'];
315
		$slug                = $this->slug;
316
		$option_prefix       = $this->option_prefix;
317
		$wordpress           = $this->wordpress;
318
		$logging             = $this->logging;
319
		$schedulable_classes = $this->schedulable_classes;
320
		$is_authorized       = false;
321
		$sfapi               = '';
322
		if ( $consumer_key && $consumer_secret ) {
323
			$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 );
324
			if ( $sfapi->is_authorized() === true ) {
0 ignored issues
show
introduced by
Found "=== true". Use Yoda Condition checks, you must
Loading history...
325
				$is_authorized = true;
326
			}
327
		}
328
		return array(
329
			'is_authorized' => $is_authorized,
330
			'sfapi'         => $sfapi,
331
		);
332
	}
333
334
	/**
335
	 * What to do upon activation of the plugin
336
	 *
337
	 * @param object $wpdb
338
	 * @param string $version
339
	 * @param string $slug
340
	 * @param string $option_prefix
341
	 * @param array $schedulable_classes
342
	 * @param object $queue
343
	 *
344
	 * @return object
345
	 *   Instance of Object_Sync_Sf_Activate
346
	 */
347
	private function activate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) {
348
		require_once plugin_dir_path( __FILE__ ) . 'classes/activate.php';
349
		$activate = new Object_Sync_Sf_Activate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue );
350
		return $activate;
351
	}
352
353
	/**
354
	 * What to do upon deactivation of the plugin
355
	 *
356
	 * @param object $wpdb
357
	 * @param string $version
358
	 * @param string $slug
359
	 * @param string $option_prefix
360
	 * @param array $schedulable_classes
361
	 * @param object $queue
362
	 *
363
	 * @return object
364
	 *   Instance of Object_Sync_Sf_Deactivate
365
	 */
366
	private function deactivate( $wpdb, $version, $slug, $option_prefix, $schedulable_classes, $queue ) {
367
		require_once plugin_dir_path( __FILE__ ) . 'classes/deactivate.php';
368
		$deactivate = new Object_Sync_Sf_Deactivate( $wpdb, $version, $slug, $schedulable_classes, $option_prefix, $queue );
369
	}
370
371
372
	/**
373
	 * Methods to push data from WordPress to Salesforce
374
	 *
375
	 * @param object $wpdb
376
	 * @param string $version
377
	 * @param array $login_credentials
378
	 * @param string $slug
379
	 * @param string $object_prefix
380
	 * @param object $wordpress
381
	 * @param object $salesforce
382
	 * @param object $mappings
383
	 * @param object $logging
384
	 * @param array $schedulable_classes
385
	 *
386
	 * @return object
387
	 *   Instance of Object_Sync_Sf_Salesforce_Push
388
	 */
389
	private function push( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) {
390
		require_once plugin_dir_path( __FILE__ ) . 'classes/salesforce_push.php';
391
		$push = new Object_Sync_Sf_Salesforce_Push( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue, $option_prefix );
392
		return $push;
393
	}
394
395
	/**
396
	 * Methods to pull data from Salesforce to WordPress
397
	 *
398
	 * @param object $wpdb
399
	 * @param string $version
400
	 * @param array $login_credentials
401
	 * @param string $slug
402
	 * @param string $option_prefix
403
	 * @param object $wordpress
404
	 * @param object $salesforce
405
	 * @param object $mappings
406
	 * @param object $logging
407
	 * @param array $schedulable_classes
408
	 * @return object
409
	 *   Instance of Object_Sync_Sf_Salesforce_Pull
410
	 */
411
	private function pull( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue ) {
412
		require_once plugin_dir_path( __FILE__ ) . 'classes/salesforce_pull.php';
413
		$pull = new Object_Sync_Sf_Salesforce_Pull( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $logging, $schedulable_classes, $queue, $option_prefix );
414
		return $pull;
415
	}
416
417
	/**
418
	* Load the rest class.
419
	* This handles REST API methods
420
	*
421
	* @param object $wpdb
422
	* @param string $version
423
	* @param array $login_credentials
424
	* @param string $slug
425
	* @param string $option_prefix
426
	* @param object $wordpress
427
	* @param object $salesforce
428
	* @param object $mappings
429
	* @param object $push
430
	* @param object $pull
431
	* @param object $logging
432
	* @param array $schedulable_classes
433
	* @param object $queue
434
	* @return object $admin
435
	*   Instance of Object_Sync_Sf_Rest
436
	*
437
	*/
438
	private function rest( $wpdb, $version, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull ) {
439
		require_once( plugin_dir_path( __FILE__ ) . 'classes/class-object-sync-sf-rest.php' );
440
		$rest = new Object_Sync_Sf_Rest( $wpdb, $version, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull );
441
		return $rest;
442
	}
443
444
	/**
445
	* Load the admin class.
446
	* This also creates admin menu, unless the plugin that calls this library has indicated that it has its own menu
447
	*
448
	* @param object $wpdb
449
	* @param string $version
450
	* @param array $login_credentials
451
	* @param string $slug
452
	* @param string $option_prefix
453
	* @param object $wordpress
454
	* @param object $salesforce
455
	* @param object $mappings
456
	* @param object $push
457
	* @param object $pull
458
	* @param object $logging
459
	* @param array $schedulable_classes
460
	* @param object $queue
461
	* @return object $admin
462
	*   Instance of Object_Sync_Sf_Admin
463
	*
464
	*/
465
	private function load_admin( $wpdb, $version, $login_credentials, $slug, $option_prefix, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue ) {
466
		require_once( plugin_dir_path( __FILE__ ) . 'classes/admin.php' );
467
		$admin = new Object_Sync_Sf_Admin( $wpdb, $version, $login_credentials, $slug, $wordpress, $salesforce, $mappings, $push, $pull, $logging, $schedulable_classes, $queue, $option_prefix );
468
		add_action( 'admin_menu', array( $admin, 'create_admin_menu' ) );
469
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_and_styles' ) );
470
		add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
471
		add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 5 );
472
		return $admin;
473
	}
474
475
	/**
476
	* Display a Settings link on the main Plugins page
477
	*
478
	* @param array $links
479
	* @param string $file
480
	* @return array $links
481
	*   These are the links that go with this plugin's entry
482
	*/
483
	public function plugin_action_links( $links, $file ) {
484
		if ( plugin_basename( __FILE__ ) === $file ) {
485
			$settings = '<a href="' . get_admin_url() . 'options-general.php?page=object-sync-salesforce-admin">' . __( 'Settings', 'object-sync-for-salesforce' ) . '</a>';
486
			// make the 'Settings' link appear first
487
			array_unshift( $links, $settings );
488
		}
489
		return $links;
490
	}
491
492
493
	/**
494
	* Admin styles. Load the CSS and JavaScript for the plugin's settings
495
	*
496
	* @return void
497
	*/
498
	public function admin_scripts_and_styles() {
499
500
		// I think some developers might not want to bother with select2 or selectwoo, so let's allow that to be changeable
501
		$select_library = apply_filters( $this->option_prefix . 'select_library', 'selectwoo' );
502
503
		/*
504
		 * example to modify the select library
505
		 * add_filter( 'object_sync_for_salesforce_select_library', 'select_library', 10, 1 );
506
		 * function select_library( $select_library ) {
507
		 * 	$select_library = 'select2';
508
		 *  // this could also be empty; in that case we would just use default browser select
509
		 * 	return $select_library;
510
		 * }
511
		*/
512
513
		$javascript_dependencies = array( 'jquery' );
514
		$css_dependencies        = array();
515
		if ( '' !== $select_library ) {
516
			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 );
517
			$javascript_dependencies[] = $select_library . 'js';
518
519
			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' );
520
			$css_dependencies[] = $select_library . 'css';
521
		}
522
523
		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 );
524
525
		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' );
526
	}
527
528
	/**
529
	 * Load textdomain
530
	 *
531
	 * @return void
532
	 */
533
	public function textdomain() {
534
		load_plugin_textdomain( 'object-sync-for-salesforce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $deprecated of load_plugin_textdomain(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

534
		load_plugin_textdomain( 'object-sync-for-salesforce', /** @scrutinizer ignore-type */ false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
Loading history...
535
	}
536
537
	/**
538
	* Get the pre-login Salesforce credentials.
539
	* These depend on the plugin's settings or constants defined in wp-config.php.
540
	*
541
	* @return array $login_credentials
542
	*   Includes all settings necessary to log into the Salesforce API.
543
	*   Replaces settings options with wp-config.php values if they exist.
544
	*/
545
	private function get_login_credentials() {
546
547
		$consumer_key       = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY : get_option( $this->option_prefix . 'consumer_key', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
548
		$consumer_secret    = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET : get_option( $this->option_prefix . 'consumer_secret', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
549
		$callback_url       = defined( 'OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL' ) ? OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL : get_option( $this->option_prefix . 'callback_url', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
550
		$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', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
551
		$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', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
552
		$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', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
553
		$api_version        = defined( 'OBJECT_SYNC_SF_SALESFORCE_API_VERSION' ) ? OBJECT_SYNC_SF_SALESFORCE_API_VERSION : get_option( $this->option_prefix . 'api_version', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_API_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
554
555
		$login_credentials = array(
556
			'consumer_key'     => $consumer_key,
557
			'consumer_secret'  => $consumer_secret,
558
			'callback_url'     => $callback_url,
559
			'login_url'        => $login_base_url,
560
			'authorize_path'   => $authorize_url_path,
561
			'token_path'       => $token_url_path,
562
			'rest_api_version' => $api_version,
563
		);
564
565
		return $login_credentials;
566
567
	}
568
569
} // end class
570
571
// Instantiate our class.
572
$object_sync_salesforce = Object_Sync_Salesforce::get_instance();
573