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 | */ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
11 | if (!class_exists( 'LSX_Activities' ) ) { |
||
0 ignored issues
–
show
|
|||
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
|
|||
23 | public $plugin_slug = 'lsx-activities'; |
||
24 | |||
25 | /** |
||
26 | * The post types the plugin registers |
||
27 | */ |
||
0 ignored issues
–
show
|
|||
28 | public $post_types = false; |
||
29 | |||
30 | /** |
||
31 | * The singular post types the plugin registers |
||
32 | */ |
||
0 ignored issues
–
show
|
|||
33 | public $post_types_singular = false; |
||
34 | |||
35 | /** |
||
36 | * An array of the post types slugs plugin registers |
||
37 | */ |
||
0 ignored issues
–
show
|
|||
38 | public $post_type_slugs = false; |
||
39 | |||
40 | /** |
||
41 | * The taxonomies the plugin registers |
||
42 | */ |
||
0 ignored issues
–
show
|
|||
43 | public $taxonomies = false; |
||
44 | |||
45 | /** |
||
46 | * The taxonomies the plugin registers (plural) |
||
47 | */ |
||
0 ignored issues
–
show
|
|||
48 | public $taxonomies_plural = false; |
||
49 | |||
50 | /** |
||
51 | * Hold the TO options |
||
52 | */ |
||
0 ignored issues
–
show
|
|||
53 | public $options = array(); |
||
54 | |||
55 | /** |
||
56 | * Hold the GoogleMaps API key |
||
57 | */ |
||
0 ignored issues
–
show
|
|||
58 | public $api_key = false; |
||
59 | |||
60 | /** |
||
61 | * Constructor |
||
62 | */ |
||
63 | public function __construct() { |
||
0 ignored issues
–
show
|
|||
64 | //Set the variables |
||
0 ignored issues
–
show
|
|||
65 | $this->set_vars(); |
||
66 | $this->lsx_to_search_integration(); |
||
67 | |||
68 | // Make TO last plugin to load |
||
0 ignored issues
–
show
|
|||
69 | add_action( 'activated_plugin', array( $this, 'activated_plugin' ) ); |
||
70 | |||
71 | add_action('init',array($this,'load_plugin_textdomain')); |
||
0 ignored issues
–
show
|
|||
72 | |||
73 | if(false !== $this->post_types){ |
||
0 ignored issues
–
show
|
|||
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); |
||
0 ignored issues
–
show
|
|||
78 | } |
||
0 ignored issues
–
show
|
|||
79 | if(false !== $this->taxonomies){ |
||
0 ignored issues
–
show
|
|||
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'); |
||
0 ignored issues
–
show
|
|||
85 | require_once(LSX_ACTIVITIES_PATH . '/classes/class-lsx-activities-frontend.php'); |
||
0 ignored issues
–
show
|
|||
86 | require_once(LSX_ACTIVITIES_PATH . '/includes/template-tags.php'); |
||
0 ignored issues
–
show
|
|||
87 | |||
88 | // flush_rewrite_rules() |
||
0 ignored issues
–
show
|
|||
89 | register_activation_hook( LSX_ACTIVITIES_CORE, array( $this, 'register_activation_hook' ) ); |
||
90 | add_action( 'admin_init', array( $this, 'register_activation_hook_check' ) ); |
||
91 | } |
||
0 ignored issues
–
show
|
|||
92 | |||
93 | /** |
||
94 | * Include the post type for the search integration |
||
95 | */ |
||
96 | public function lsx_to_search_integration(){ |
||
0 ignored issues
–
show
|
|||
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 | } |
||
0 ignored issues
–
show
|
|||
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
|
|||
106 | } |
||
0 ignored issues
–
show
|
|||
107 | |||
108 | /** |
||
109 | * Sets the plugins variables |
||
110 | */ |
||
111 | public function set_vars() { |
||
112 | $this->post_types = array( |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
113 | 'activity' => __('Activities','lsx-activities') |
||
0 ignored issues
–
show
|
|||
114 | ); |
||
115 | $this->post_types_singular = array( |
||
116 | 'activity' => __('Activity','lsx-activities') |
||
0 ignored issues
–
show
|
|||
117 | ); |
||
118 | $this->post_type_slugs = array_keys($this->post_types); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
119 | |||
120 | $this->options = get_option('_lsx-to_settings',false); |
||
0 ignored issues
–
show
|
|||
121 | if((false !== $this->options && isset($this->options['api']['googlemaps_key'])) || defined('GOOGLEMAPS_API_KEY')) { |
||
0 ignored issues
–
show
|
|||
122 | |||
123 | if (!defined('GOOGLEMAPS_API_KEY')) { |
||
0 ignored issues
–
show
|
|||
124 | $this->api_key = $this->options['api']['googlemaps_key']; |
||
125 | } else { |
||
126 | $this->api_key = GOOGLEMAPS_API_KEY; |
||
127 | } |
||
128 | } |
||
129 | } |
||
0 ignored issues
–
show
|
|||
130 | |||
131 | /** |
||
0 ignored issues
–
show
|
|||
132 | * Adds our post types to an array via a filter |
||
133 | */ |
||
134 | public function plugin_path($path,$post_type){ |
||
0 ignored issues
–
show
|
|||
135 | if(false !== $this->post_types && array_key_exists($post_type,$this->post_types)){ |
||
0 ignored issues
–
show
|
|||
136 | $path = LSX_ACTIVITIES_PATH; |
||
137 | } |
||
0 ignored issues
–
show
|
|||
138 | return $path; |
||
139 | } |
||
0 ignored issues
–
show
|
|||
140 | |||
141 | /** |
||
0 ignored issues
–
show
|
|||
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
|
|||
145 | if(is_array($post_types)){ |
||
0 ignored issues
–
show
|
|||
146 | $post_types = array_merge($post_types,$this->post_type_slugs); |
||
0 ignored issues
–
show
|
|||
147 | }else{ |
||
0 ignored issues
–
show
|
|||
148 | $post_types = $this->post_type_slugs; |
||
149 | } |
||
0 ignored issues
–
show
|
|||
150 | return $post_types; |
||
151 | } |
||
0 ignored issues
–
show
|
|||
152 | |||
153 | /** |
||
0 ignored issues
–
show
|
|||
154 | * Adds our post types to an array via a filter |
||
155 | */ |
||
156 | public function post_types_filter($post_types){ |
||
0 ignored issues
–
show
|
|||
157 | if(is_array($post_types) && is_array($this->post_types)){ |
||
0 ignored issues
–
show
|
|||
158 | $post_types = array_merge($post_types,$this->post_types); |
||
0 ignored issues
–
show
|
|||
159 | }elseif(is_array($this->post_types)){ |
||
0 ignored issues
–
show
|
|||
160 | $post_types = $this->post_types; |
||
161 | } |
||
0 ignored issues
–
show
|
|||
162 | return $post_types; |
||
163 | } |
||
0 ignored issues
–
show
|
|||
164 | |||
165 | /** |
||
0 ignored issues
–
show
|
|||
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
|
|||
169 | if(is_array($post_types_singular) && is_array($this->post_types_singular)){ |
||
0 ignored issues
–
show
|
|||
170 | $post_types_singular = array_merge($post_types_singular,$this->post_types_singular); |
||
0 ignored issues
–
show
|
|||
171 | }elseif(is_array($this->post_types_singular)){ |
||
0 ignored issues
–
show
|
|||
172 | $post_types_singular = $this->post_types_singular; |
||
173 | } |
||
0 ignored issues
–
show
|
|||
174 | return $post_types_singular; |
||
175 | } |
||
0 ignored issues
–
show
|
|||
176 | |||
177 | /** |
||
0 ignored issues
–
show
|
|||
178 | * Adds our taxonomies to an array via a filter |
||
179 | */ |
||
180 | public function taxonomies_filter($taxonomies){ |
||
0 ignored issues
–
show
|
|||
181 | if(is_array($taxonomies) && is_array($this->taxonomies)){ |
||
0 ignored issues
–
show
|
|||
182 | $taxonomies = array_merge($taxonomies,$this->taxonomies); |
||
0 ignored issues
–
show
|
|||
183 | }elseif(is_array($this->taxonomies)){ |
||
0 ignored issues
–
show
|
|||
184 | $taxonomies = $this->taxonomies; |
||
185 | } |
||
0 ignored issues
–
show
|
|||
186 | return $taxonomies; |
||
187 | } |
||
0 ignored issues
–
show
|
|||
188 | |||
189 | /** |
||
0 ignored issues
–
show
|
|||
190 | * Adds our taxonomies_plural to an array via a filter |
||
191 | */ |
||
192 | public function taxonomies_plural_filter($taxonomies_plural){ |
||
0 ignored issues
–
show
|
|||
193 | if(is_array($taxonomies_plural) && is_array($this->taxonomies_plural)){ |
||
0 ignored issues
–
show
|
|||
194 | $taxonomies_plural = array_merge($taxonomies_plural,$this->taxonomies_plural); |
||
0 ignored issues
–
show
|
|||
195 | }elseif(is_array($this->taxonomies_plural)){ |
||
0 ignored issues
–
show
|
|||
196 | $taxonomies_plural = $this->taxonomies_plural; |
||
197 | } |
||
0 ignored issues
–
show
|
|||
198 | return $taxonomies_plural; |
||
199 | } |
||
0 ignored issues
–
show
|
|||
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
|
|||
206 | $search = preg_grep( '/.*\/tour-operator\.php/', $plugins ); |
||
207 | $key = array_search( $search, $plugins ); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
208 | |||
209 | if ( is_array( $search ) && count( $search ) ) { |
||
0 ignored issues
–
show
|
|||
210 | foreach ( $search as $key => $path ) { |
||
0 ignored issues
–
show
|
|||
211 | array_splice( $plugins, $key, 1 ); |
||
212 | array_push( $plugins, $path ); |
||
213 | update_option( 'active_plugins', $plugins ); |
||
214 | } |
||
215 | } |
||
216 | } |
||
217 | } |
||
0 ignored issues
–
show
|
|||
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
|
|||
224 | set_transient( '_tour_operators_activities_flush_rewrite_rules', 1, 30 ); |
||
225 | } |
||
226 | } |
||
0 ignored issues
–
show
|
|||
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' ) ) { |
||
0 ignored issues
–
show
|
|||
233 | return; |
||
234 | } |
||
235 | |||
236 | delete_transient( '_tour_operators_activities_flush_rewrite_rules' ); |
||
237 | flush_rewrite_rules(); |
||
238 | } |
||
0 ignored issues
–
show
|
|||
239 | |||
240 | } |
||
241 | new LSX_Activities(); |
||
242 | } |