Passed
Pull Request — master (#4)
by Warwick
02:43
created

Sharing::set_options()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 11
c 0
b 0
f 0
nc 9
nop 0
dl 0
loc 16
rs 9.2222
1
<?php
2
/**
3
 * LSX_Sharing
4
 *
5
 * @package lsx-sharing
6
 */
7
namespace lsx\sharing;
8
9
/**
10
 * LSX Sharing class.
11
 *
12
 * @package lsx-sharing
13
 */
14
class Sharing {
15
16
	/**
17
	 * Holds class instance
18
	 *
19
	 * @since 1.0.0
20
	 *
21
	 * @var      object \lsx\search\Sharing()
22
	 */
23
	protected static $instance = null;
24
25
	/**
26
	 * Holds class instance
27
	 *
28
	 * @since 1.0.0
29
	 *
30
	 * @var      object \lsx\search\classes\Admin()
31
	 */
32
	public $admin = false;
33
34
	/**
35
	 * If we are using the new options or not.
36
	 *
37
	 * @var boolean
38
	 */
39
	public $is_new_options = false;
40
41
	/**
42
	 * The options for the plugin.
43
	 *
44
	 * @var array
45
	 */
46
	public $options = array();
47
48
	/**
49
	 * Constructor.
50
	 */
51
	public function __construct() {
52
		add_action( 'init', array( $this, 'set_options' ), 50 );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

52
		/** @scrutinizer ignore-call */ 
53
  add_action( 'init', array( $this, 'set_options' ), 50 );
Loading history...
53
		$this->load_vendors();
54
		$this->load_includes();
55
		$this->load_classes();
56
	}
57
58
	/**
59
	 * Return an instance of this class.
60
	 *
61
	 * @since 1.0.0
62
	 *
63
	 * @return    object \lsx\member_directory\search\Admin()    A single instance of this class.
64
	 */
65
	public static function get_instance() {
66
		// If the single instance hasn't been set, set it now.
67
		if ( null === self::$instance ) {
68
			self::$instance = new self();
69
		}
70
		return self::$instance;
71
	}
72
73
	/**
74
	 * Loads the plugin functions.
75
	 */
76
	private function load_vendors() {
77
		// Configure custom fields.
78
		if ( ! class_exists( 'CMB2' ) ) {
79
			require_once LSX_SHARING_PATH . 'vendor/CMB2/init.php';
80
		}
81
	}
82
	/**
83
	 * Loads the plugin functions.
84
	 */
85
	private function load_includes() {
86
		require_once LSX_SHARING_PATH . '/includes/functions.php';
87
	}
88
	/**
89
	 * Loads the plugin functions.
90
	 */
91
	private function load_classes() {
92
		require_once LSX_SHARING_PATH . '/classes/class-admin.php';
93
		global $lsx_sharing_admin;
94
		$this->admin = \lsx\sharing\classes\Admin::get_instance();
95
		$lsx_sharing_admin;
96
97
		require_once LSX_SHARING_PATH . '/classes/class-frontend.php';
98
		$this->frontend = \lsx\sharing\classes\Frontend::get_instance();
0 ignored issues
show
Bug Best Practice introduced by
The property frontend does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
99
		global $lsx_sharing;
100
		$lsx_sharing = $this->frontend->output;
101
102
		require_once LSX_SHARING_PATH . '/classes/deprecated/class-lsx-sharing.php';
103
	}
104
	/**
105
	 * Set options.
106
	 */
107
	public function set_options() {
108
		if ( function_exists( 'tour_operator' ) ) {
109
			$this->options = get_option( '_lsx-to_settings', false );
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

109
			$this->options = /** @scrutinizer ignore-call */ get_option( '_lsx-to_settings', false );
Loading history...
110
		} else {
111
			$this->options = get_option( '_lsx_settings', false );
112
113
			if ( false === $this->options ) {
114
				$this->options = get_option( '_lsx_lsx-settings', false );
115
			}
116
		}
117
118
		$new_options = get_option( 'lsx-sharing-settings' );
119
		if ( ! empty( $new_options ) ) {
120
			if ( '' !== $new_options && false !== $new_options ) {
121
				$this->is_new_options = true;
122
				$this->options        = $new_options;
123
			}
124
		}
125
	}
126
}
127