Issues (1030)

classes/class-lsx-activities.php (15 issues)

1
<?php
2
/**
3
 * LSX_Activities
4
 *
5
 * @package   LSX_Activities
6
 * @author    LightSpeed
7
 * @license   GPL-2.0+
8
 * @link      
9
 * @copyright 2018 LightSpeedDevelopment
10
 */
11
if (!class_exists( 'LSX_Activities' ) ) {
12
	/**
13
	 * Main plugin class.
14
	 *
15
	 * @package LSX_Activities
16
	 * @author  LightSpeed
17
	 */
18
	class LSX_Activities {
19
		
20
		/**
21
		 * The plugins id
22
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
23
		public $plugin_slug = 'lsx-activities';
24
25
		/**
26
		 * The post types the plugin registers
27
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
28
		public $post_types = false;	
29
30
		/**
31
		 * The singular post types the plugin registers
32
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
33
		public $post_types_singular = false;	
34
35
		/**
36
		 * An array of the post types slugs plugin registers
37
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
38
		public $post_type_slugs = false;			
39
40
		/**
41
		 * The taxonomies the plugin registers
42
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
43
		public $taxonomies = false;				
44
45
		/**
46
		 * The taxonomies the plugin registers (plural)
47
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
48
		public $taxonomies_plural = false;
49
50
		/**
51
		 * Hold the TO options
52
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
53
		public $options = array();
54
55
		/**
56
		 * Hold the GoogleMaps API key
57
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
58
		public $api_key = false;
59
60
		/**
61
		 * Constructor
62
		 */
63
		public function __construct() {
64
			//Set the variables
65
			$this->set_vars();
66
			$this->lsx_to_search_integration();
67
68
			// Make TO last plugin to load
69
			add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
70
			
71
			add_action('init',array($this,'load_plugin_textdomain'));
72
73
			if(false !== $this->post_types){
74
				add_filter( 'lsx_to_framework_post_types', array( $this, 'post_types_filter') );
75
				add_filter( 'lsx_to_post_types', array( $this, 'post_types_filter') );
76
				add_filter( 'lsx_to_post_types_singular', array( $this, 'post_types_singular_filter') );
77
				add_filter('lsx_to_settings_path',array( $this, 'plugin_path'),10,2);
78
			}
79
			if(false !== $this->taxonomies){
80
				add_filter( 'lsx_to_framework_taxonomies', array( $this, 'taxonomies_filter') );
81
				add_filter( 'lsx_to_framework_taxonomies_plural', array( $this, 'taxonomies_plural_filter') );
82
			}	
83
84
			require_once(LSX_ACTIVITIES_PATH . '/classes/class-lsx-activities-admin.php');
85
			require_once(LSX_ACTIVITIES_PATH . '/classes/class-lsx-activities-frontend.php');
86
			require_once(LSX_ACTIVITIES_PATH . '/includes/template-tags.php');
87
88
			// flush_rewrite_rules()
89
			register_activation_hook( LSX_ACTIVITIES_CORE, array( $this, 'register_activation_hook' ) );
90
			add_action( 'admin_init', array( $this, 'register_activation_hook_check' ) );
91
		}
92
93
		/**
94
		 * Include the post type for the search integration
95
		 */
96
		public function lsx_to_search_integration(){
97
			add_filter( 'lsx_to_search_post_types', array( $this, 'post_types_filter') );
98
			add_filter( 'lsx_to_search_taxonomies', array( $this, 'taxonomies_filter') );
99
		}
100
	
101
		/**
102
		 * Load the plugin text domain for translation.
103
		 */
104
		public function load_plugin_textdomain() {
105
			load_plugin_textdomain( 'lsx-activities', FALSE, basename( LSX_ACTIVITIES_PATH ) . '/languages');
106
		}
107
108
		/**
109
		 * Sets the plugins variables
110
		 */
111
		public function set_vars() {
112
			$this->post_types = array(
113
				'activity'	=>	__('Activities','lsx-activities')
114
			);
115
			$this->post_types_singular = array(
116
				'activity'	=>	__('Activity','lsx-activities')
117
			);
118
			$this->post_type_slugs = array_keys($this->post_types);
119
120
			$this->options = get_option('_lsx-to_settings',false);
121
			if((false !== $this->options && isset($this->options['api']['googlemaps_key'])) || defined('GOOGLEMAPS_API_KEY')) {
122
123
				if (!defined('GOOGLEMAPS_API_KEY')) {
124
					$this->api_key = $this->options['api']['googlemaps_key'];
125
				} else {
126
					$this->api_key = GOOGLEMAPS_API_KEY;
127
				}
128
			}
129
		}
130
131
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$path" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$post_type" missing
Loading history...
132
		 * Adds our post types to an array via a filter
133
		 */
134
		public function plugin_path($path,$post_type){
135
			if(false !== $this->post_types && array_key_exists($post_type,$this->post_types)){
136
				$path = LSX_ACTIVITIES_PATH;
137
			}
138
			return $path;
139
		}	
140
141
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
142
		 * Adds our post types to an array via a filter
143
		 */
144
		public function post_types_slugs_filter($post_types){
145
			if(is_array($post_types)){
146
				$post_types = array_merge($post_types,$this->post_type_slugs);
147
			}else{
148
				$post_types = $this->post_type_slugs;
149
			}
150
			return $post_types;
151
		}
152
153
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
154
		 * Adds our post types to an array via a filter
155
		 */
156
		public function post_types_filter($post_types){
157
			if(is_array($post_types) && is_array($this->post_types)){
158
				$post_types = array_merge($post_types,$this->post_types);
159
			}elseif(is_array($this->post_types)){
160
				$post_types = $this->post_types;
161
			}
162
			return $post_types;
163
		}	
164
165
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types_singular" missing
Loading history...
166
		 * Adds our post types to an array via a filter
167
		 */
168
		public function post_types_singular_filter($post_types_singular){
169
			if(is_array($post_types_singular) && is_array($this->post_types_singular)){
170
				$post_types_singular = array_merge($post_types_singular,$this->post_types_singular);
171
			}elseif(is_array($this->post_types_singular)){
172
				$post_types_singular = $this->post_types_singular;
173
			}
174
			return $post_types_singular;
175
		}	
176
177
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies" missing
Loading history...
178
		 * Adds our taxonomies to an array via a filter
179
		 */
180
		public function taxonomies_filter($taxonomies){
181
			if(is_array($taxonomies) && is_array($this->taxonomies)){
182
				$taxonomies = array_merge($taxonomies,$this->taxonomies);
183
			}elseif(is_array($this->taxonomies)){
184
				$taxonomies = $this->taxonomies;
185
			}
186
			return $taxonomies;
187
		}
188
189
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies_plural" missing
Loading history...
190
		 * Adds our taxonomies_plural to an array via a filter
191
		 */
192
		public function taxonomies_plural_filter($taxonomies_plural){
193
			if(is_array($taxonomies_plural) && is_array($this->taxonomies_plural)){
194
				$taxonomies_plural = array_merge($taxonomies_plural,$this->taxonomies_plural);
195
			}elseif(is_array($this->taxonomies_plural)){
196
				$taxonomies_plural = $this->taxonomies_plural;
197
			}
198
			return $taxonomies_plural;
199
		}
200
	
201
		/**
202
		 * Make TO last plugin to load.
203
		 */
204
		public function activated_plugin() {
205
			if ( $plugins = get_option( 'active_plugins' ) ) {
206
				$search = preg_grep( '/.*\/tour-operator\.php/', $plugins );
207
				$key = array_search( $search, $plugins );
208
209
				if ( is_array( $search ) && count( $search ) ) {
210
					foreach ( $search as $key => $path ) {
211
						array_splice( $plugins, $key, 1 );
212
						array_push( $plugins, $path );
213
						update_option( 'active_plugins', $plugins );
214
					}
215
				}
216
			}
217
		}
218
	
219
		/**
220
		 * On plugin activation
221
		 */
222
		public function register_activation_hook() {
223
			if ( ! is_network_admin() && ! isset( $_GET['activate-multi'] ) ) {
224
				set_transient( '_tour_operators_activities_flush_rewrite_rules', 1, 30 );
225
			}
226
		}
227
		
228
		/**
229
		 * On plugin activation (check)
230
		 */
231
		public function register_activation_hook_check() {
232
			if ( ! get_transient( '_tour_operators_activities_flush_rewrite_rules' ) ) {
233
				return;
234
			}
235
236
			delete_transient( '_tour_operators_activities_flush_rewrite_rules' );
237
			flush_rewrite_rules();
238
		}
239
240
	}
241
	new LSX_Activities();
242
}