Issues (1082)

classes/class-lsx-to-team.php (96 issues)

1
<?php
2
/**
3
 * LSX_TO_Team
4
 *
5
 * @package   LSX_TO_Team
6
 * @author    LightSpeed
7
 * @license   GPL-2.0+
8
 * @link
9
 * @copyright {year} LightSpeedDevelopment
10
 */
11
12
if ( ! class_exists( 'LSX_TO_Team' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
13
14
	/**
15
	 * Main plugin class.
16
	 *
17
	 * @package LSX_TO_Team
18
	 * @author  LightSpeed
19
	 */
20
	class LSX_TO_Team {
21
22
		/**
23
		 * The plugins id
24
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
25
		public $plugin_slug = 'to-team';
26
27
		/**
28
		 * The post types the plugin registers
29
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
30
		public $post_types = false;
31
32
		/**
33
		 * The singular post types the plugin registers
34
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
35
		public $post_types_singular = false;
36
37
		/**
38
		 * An array of the post types slugs plugin registers
39
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
40
		public $post_type_slugs = false;
41
42
		/**
43
		 * The taxonomies the plugin registers
44
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
45
		public $taxonomies = false;
46
47
		/**
48
		 * The taxonomies the plugin registers (plural)
49
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
50
		public $taxonomies_plural = false;
51
52
		/**
53
		 * Site users
54
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
55
		public $site_users = array();
56
57
		/**
58
		 * Constructor
59
		 */
60
		public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
61
			// Set the variables.
62
			$this->set_vars();
63
			$this->lsx_to_search_integration();
64
65
			// Make TO last plugin to load.
66
			add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
67
68
			add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
69
70
			if ( false !== $this->post_types ) {
0 ignored issues
show
The condition false !== $this->post_types is always true.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
71
				add_filter( 'lsx_to_framework_post_types', array( $this, 'post_types_filter' ) );
72
				add_filter( 'lsx_to_post_types', array( $this, 'post_types_filter' ) );
73
				add_filter( 'lsx_to_post_types_singular', array( $this, 'post_types_singular_filter' ) );
74
				add_filter( 'lsx_to_settings_path', array( $this, 'plugin_path' ), 10, 2 );
75
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
76
			if ( false !== $this->taxonomies ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
77
				add_filter( 'lsx_to_framework_taxonomies', array( $this, 'taxonomies_filter' ) );
78
				add_filter( 'lsx_to_framework_taxonomies_plural', array( $this, 'taxonomies_plural_filter' ) );
79
			}
80
81
			require_once LSX_TO_TEAM_PATH . '/classes/class-lsx-to-team-admin.php';
82
			require_once LSX_TO_TEAM_PATH . '/classes/class-lsx-to-team-frontend.php';
83
			require_once LSX_TO_TEAM_PATH . '/includes/template-tags.php';
84
85
			// flush_rewrite_rules.
86
			register_activation_hook( LSX_TO_TEAM_CORE, array( $this, 'register_activation_hook' ) );
87
			add_action( 'admin_init', array( $this, 'register_activation_hook_check' ) );
88
			add_filter( 'wpseo_schema_graph_pieces', array( $this, 'add_graph_pieces' ), 11, 2 );
89
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
90
91
		/**
92
		 * Include the post type for the search integration
93
		 */
94
		public function lsx_to_search_integration() {
95
			add_filter( 'lsx_to_search_post_types', array( $this, 'post_types_filter' ) );
96
			add_filter( 'lsx_to_search_taxonomies', array( $this, 'taxonomies_filter' ) );
97
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
98
99
		/**
100
		 * Load the plugin text domain for translation.
101
		 */
102
		public function load_plugin_textdomain() {
103
			load_plugin_textdomain( 'to-team', false, basename( LSX_TO_TEAM_PATH ) . '/languages' );
104
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
105
106
		/**
107
		 * Sets the plugins variables
108
		 */
109
		public function set_vars() {
110
			$this->post_types = array(
111
				'team' => __( 'Team', 'to-team' ),
112
			);
113
114
			$this->post_types_singular = array(
115
				'team' => __( 'Team Member', 'to-team' ),
116
			);
117
118
			$this->post_type_slugs = array_keys( $this->post_types );
119
120
			$users = get_users();
121
122
			foreach ( $users as $user ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
123
				$this->site_users[] = array(
124
					'name' => $user->display_name,
0 ignored issues
show
Array double arrow not aligned correctly; expected 2 space(s) between "'name'" and double arrow, but found 1.
Loading history...
125
					'value' => $user->ID,
126
				);
127
			}
128
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
129
130
		/**
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...
131
		 * Adds our post types to an array via a filter
132
		 */
133
		public function plugin_path( $path, $post_type ) {
134
			if ( false !== $this->post_types && array_key_exists( $post_type, $this->post_types ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
135
				$path = LSX_TO_TEAM_PATH;
136
			}
137
138
			return $path;
139
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
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 ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
146
				$post_types = array_merge( $post_types, $this->post_type_slugs );
147
			} else {
148
				$post_types = $this->post_type_slugs;
149
			}
150
151
			return $post_types;
152
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
153
154
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
155
		 * Adds our post types to an array via a filter
156
		 */
157
		public function post_types_filter( $post_types ) {
158
			if ( is_array( $post_types ) && is_array( $this->post_types ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
159
				$post_types = array_merge( $post_types, $this->post_types );
160
			} elseif ( is_array( $this->post_types ) ) {
0 ignored issues
show
The condition is_array($this->post_types) is always true.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
161
				$post_types = $this->post_types;
162
			}
163
164
			return $post_types;
165
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
166
167
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types_singular" missing
Loading history...
168
		 * Adds our post types to an array via a filter
169
		 */
170
		public function post_types_singular_filter( $post_types_singular ) {
171
			if ( is_array( $post_types_singular ) && is_array( $this->post_types_singular ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
172
				$post_types_singular = array_merge( $post_types_singular, $this->post_types_singular );
173
			} elseif ( is_array( $this->post_types_singular ) ) {
0 ignored issues
show
The condition is_array($this->post_types_singular) is always true.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
174
				$post_types_singular = $this->post_types_singular;
175
			}
176
177
			return $post_types_singular;
178
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
179
180
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies" missing
Loading history...
181
		 * Adds our taxonomies to an array via a filter
182
		 */
183
		public function taxonomies_filter( $taxonomies ) {
184
			if ( is_array( $taxonomies ) && is_array( $this->taxonomies ) ) {
0 ignored issues
show
The condition is_array($this->taxonomies) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
185
				$taxonomies = array_merge( $taxonomies, $this->taxonomies );
186
			} elseif ( is_array( $this->taxonomies ) ) {
0 ignored issues
show
The condition is_array($this->taxonomies) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
187
				$taxonomies = $this->taxonomies;
188
			}
189
190
			return $taxonomies;
191
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
192
193
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies_plural" missing
Loading history...
194
		 * Adds our taxonomies_plural to an array via a filter
195
		 */
196
		public function taxonomies_plural_filter( $taxonomies_plural ) {
197
			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...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
198
				$taxonomies_plural = array_merge( $taxonomies_plural, $this->taxonomies_plural );
199
			} elseif ( is_array( $this->taxonomies_plural ) ) {
0 ignored issues
show
The condition is_array($this->taxonomies_plural) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
200
				$taxonomies_plural = $this->taxonomies_plural;
201
			}
202
203
			return $taxonomies_plural;
204
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
205
206
		/**
207
		 * Make TO last plugin to load.
208
		 */
209
		public function activated_plugin() {
210
			// @codingStandardsIgnoreLine
211
			if ( $plugins = get_option( 'active_plugins' ) ) {
212
				$search = preg_grep( '/.*\/tour-operator\.php/', $plugins );
213
				$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.

Loading history...
Not using strict comparison for array_search; supply true for third argument.
Loading history...
214
215
				if ( is_array( $search ) && count( $search ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
216
					foreach ( $search as $key => $path ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
217
						array_splice( $plugins, $key, 1 );
218
						array_push( $plugins, $path );
219
						update_option( 'active_plugins', $plugins );
220
					}
221
				}
222
			}
223
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
224
225
		/**
226
		 * On plugin activation
227
		 */
228
		public function register_activation_hook() {
229
			if ( ! is_network_admin() && ! isset( $_GET['activate-multi'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Processing form data without nonce verification.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
230
				set_transient( '_tour_operators_team_flush_rewrite_rules', 1, 30 );
231
			}
232
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
233
234
		/**
235
		 * On plugin activation (check)
236
		 */
237
		public function register_activation_hook_check() {
238
			if ( ! get_transient( '_tour_operators_team_flush_rewrite_rules' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
239
				return;
240
			}
241
242
			delete_transient( '_tour_operators_team_flush_rewrite_rules' );
243
			flush_rewrite_rules();
244
		}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
245
246
		/**
247
		 * Adds Schema pieces to our output.
248
		 *
249
		 * @param array                 $pieces  Graph pieces to output.
250
		 * @param \WPSEO_Schema_Context $context Object with context variables.
0 ignored issues
show
The type WPSEO_Schema_Context was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
251
		 *
252
		 * @return array $pieces Graph pieces to output.
253
		 */
254
		public function add_graph_pieces( $pieces, $context ) {
255
			if ( class_exists( 'LSX_TO_Schema_Graph_Piece' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
256
				require_once LSX_TO_TEAM_PATH . 'classes/class-lsx-to-team-schema.php';
257
				$pieces[] = new LSX_TO_Team_Schema( $context );
258
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
259
			return $pieces;
260
		}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
261
	}
262
263
	global $lsx_to_team;
264
	$lsx_to_team = new LSX_TO_Team();
265
0 ignored issues
show
Blank line found at end of control structure
Loading history...
266
}
267