Issues (1030)

classes/class-lsx-activities.php (131 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' ) ) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
Expected 1 space before "!"; 0 found
Loading history...
Expected 1 space after "!"; 0 found
Loading history...
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
		 */
23
		public $plugin_slug = 'lsx-activities';
24
25
		/**
26
		 * The post types the plugin registers
27
		 */
28
		public $post_types = false;	
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
29
30
		/**
31
		 * The singular post types the plugin registers
32
		 */
33
		public $post_types_singular = false;	
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
34
35
		/**
36
		 * An array of the post types slugs plugin registers
37
		 */
38
		public $post_type_slugs = false;			
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
39
40
		/**
41
		 * The taxonomies the plugin registers
42
		 */
43
		public $taxonomies = false;				
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
44
45
		/**
46
		 * The taxonomies the plugin registers (plural)
47
		 */
48
		public $taxonomies_plural = false;
49
50
		/**
51
		 * Hold the TO options
52
		 */
53
		public $options = array();
54
55
		/**
56
		 * Hold the GoogleMaps API key
57
		 */
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'));
0 ignored issues
show
Missing space after array opener.
Loading history...
Expected 1 space between comma and "'load_plugin_textdomain'"; 0 found
Loading history...
Missing space before array closer.
Loading history...
72
73
			if(false !== $this->post_types){
0 ignored issues
show
The condition false !== $this->post_types is always true.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
74
				add_filter( 'lsx_to_framework_post_types', array( $this, 'post_types_filter') );
0 ignored issues
show
Missing space before array closer.
Loading history...
75
				add_filter( 'lsx_to_post_types', array( $this, 'post_types_filter') );
0 ignored issues
show
Missing space before array closer.
Loading history...
76
				add_filter( 'lsx_to_post_types_singular', array( $this, 'post_types_singular_filter') );
0 ignored issues
show
Missing space before array closer.
Loading history...
77
				add_filter('lsx_to_settings_path',array( $this, 'plugin_path'),10,2);
0 ignored issues
show
Missing space before array closer.
Loading history...
78
			}
79
			if(false !== $this->taxonomies){
0 ignored issues
show
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
80
				add_filter( 'lsx_to_framework_taxonomies', array( $this, 'taxonomies_filter') );
0 ignored issues
show
Missing space before array closer.
Loading history...
81
				add_filter( 'lsx_to_framework_taxonomies_plural', array( $this, 'taxonomies_plural_filter') );
0 ignored issues
show
Missing space before array closer.
Loading history...
82
			}	
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
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') );
0 ignored issues
show
Missing space before array closer.
Loading history...
98
			add_filter( 'lsx_to_search_taxonomies', array( $this, 'taxonomies_filter') );
0 ignored issues
show
Missing space before array closer.
Loading history...
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');
0 ignored issues
show
The parameter "FALSE" at position #2 of load_plugin_textdomain() has been deprecated since WordPress version 2.7.0. Use "" instead.
Loading history...
106
		}
107
108
		/**
109
		 * Sets the plugins variables
110
		 */
111
		public function set_vars() {
112
			$this->post_types = array(
113
				'activity'	=>	__('Activities','lsx-activities')
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
Array double arrow not aligned correctly; expected 1 space(s) between "'activity'" and double arrow, but found 2.
Loading history...
Expected 1 space after "=>"; 2 found
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
114
			);
115
			$this->post_types_singular = array(
116
				'activity'	=>	__('Activity','lsx-activities')
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
Array double arrow not aligned correctly; expected 1 space(s) between "'activity'" and double arrow, but found 2.
Loading history...
Expected 1 space after "=>"; 2 found
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
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')) {
0 ignored issues
show
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
122
123
				if (!defined('GOOGLEMAPS_API_KEY')) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
Expected 1 space before "!"; 0 found
Loading history...
Expected 1 space after "!"; 0 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
124
					$this->api_key = $this->options['api']['googlemaps_key'];
125
				} else {
126
					$this->api_key = GOOGLEMAPS_API_KEY;
127
				}
128
			}
129
		}
130
131
		/**
132
		 * Adds our post types to an array via a filter
133
		 */
134
		public function plugin_path($path,$post_type){
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
135
			if(false !== $this->post_types && array_key_exists($post_type,$this->post_types)){
0 ignored issues
show
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
136
				$path = LSX_ACTIVITIES_PATH;
137
			}
138
			return $path;
139
		}	
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
140
141
		/**
142
		 * Adds our post types to an array via a filter
143
		 */
144
		public function post_types_slugs_filter($post_types){
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
145
			if(is_array($post_types)){
0 ignored issues
show
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
146
				$post_types = array_merge($post_types,$this->post_type_slugs);
147
			}else{
0 ignored issues
show
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
148
				$post_types = $this->post_type_slugs;
149
			}
150
			return $post_types;
151
		}
152
153
		/**
154
		 * Adds our post types to an array via a filter
155
		 */
156
		public function post_types_filter($post_types){
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
157
			if(is_array($post_types) && is_array($this->post_types)){
0 ignored issues
show
The condition is_array($this->post_types) is always false.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
158
				$post_types = array_merge($post_types,$this->post_types);
159
			}elseif(is_array($this->post_types)){
0 ignored issues
show
The condition is_array($this->post_types) is always false.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
160
				$post_types = $this->post_types;
161
			}
162
			return $post_types;
163
		}	
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
164
165
		/**
166
		 * Adds our post types to an array via a filter
167
		 */
168
		public function post_types_singular_filter($post_types_singular){
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
169
			if(is_array($post_types_singular) && is_array($this->post_types_singular)){
0 ignored issues
show
The condition is_array($this->post_types_singular) is always false.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
170
				$post_types_singular = array_merge($post_types_singular,$this->post_types_singular);
171
			}elseif(is_array($this->post_types_singular)){
0 ignored issues
show
The condition is_array($this->post_types_singular) is always false.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
172
				$post_types_singular = $this->post_types_singular;
173
			}
174
			return $post_types_singular;
175
		}	
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
176
177
		/**
178
		 * Adds our taxonomies to an array via a filter
179
		 */
180
		public function taxonomies_filter($taxonomies){
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
181
			if(is_array($taxonomies) && is_array($this->taxonomies)){
0 ignored issues
show
The condition is_array($this->taxonomies) is always false.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
182
				$taxonomies = array_merge($taxonomies,$this->taxonomies);
183
			}elseif(is_array($this->taxonomies)){
0 ignored issues
show
The condition is_array($this->taxonomies) is always false.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
184
				$taxonomies = $this->taxonomies;
185
			}
186
			return $taxonomies;
187
		}
188
189
		/**
190
		 * Adds our taxonomies_plural to an array via a filter
191
		 */
192
		public function taxonomies_plural_filter($taxonomies_plural){
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
193
			if(is_array($taxonomies_plural) && is_array($this->taxonomies_plural)){
0 ignored issues
show
The condition is_array($this->taxonomies_plural) is always false.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
194
				$taxonomies_plural = array_merge($taxonomies_plural,$this->taxonomies_plural);
195
			}elseif(is_array($this->taxonomies_plural)){
0 ignored issues
show
The condition is_array($this->taxonomies_plural) is always false.
Loading history...
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
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' ) ) {
0 ignored issues
show
Variable assignment found within a condition. Did you mean to do a comparison?
Loading history...
206
				$search = preg_grep( '/.*\/tour-operator\.php/', $plugins );
207
				$key = array_search( $search, $plugins );
0 ignored issues
show
Not using strict comparison for array_search; supply true for third argument.
Loading history...
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'] ) ) {
0 ignored issues
show
Processing form data without nonce verification.
Loading history...
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
}