Issues (1110)

classes/class-to-specials.php (78 issues)

1
<?php
0 ignored issues
show
Class file names should be based on the class name with "class-" prepended. Expected class-lsx-to-specials.php, but found class-to-specials.php.
Loading history...
2
/**
3
 * LSX_TO_Specials
4
 *
5
 * @package   LSX_TO_Specials
6
 * @author    LightSpeed
7
 * @license   GPL-3.0+
8
 * @link
9
 * @copyright 2018 LightSpeedDevelopment
10
 */
0 ignored issues
show
There must be exactly one blank line after the file comment
Loading history...
11
if (!class_exists( 'LSX_TO_Specials' ) ) {
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...
Expected 0 spaces before closing bracket; 1 found
Loading history...
12
	/**
13
	 * Main plugin class.
14
	 *
15
	 * @package LSX_Specials
16
	 * @author  LightSpeed
17
	 */
18
	class LSX_TO_Specials {
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 = 'to-specials';
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
		 * Constructor
52
		 */
53
		public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
54
			//Set the variables
0 ignored issues
show
No space found before comment text; expected "// Set the variables" but found "//Set the variables"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
55
			$this->set_vars();
56
			$this->lsx_to_search_integration();
57
58
			// Make TO last plugin to load
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
59
			add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
60
61
			add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
62
63
			if ( false !== $this->post_types ) {
64
				add_filter( 'lsx_to_framework_post_types', array( $this, 'post_types_filter' ) );
65
				add_filter( 'lsx_to_post_types', array( $this, 'post_types_filter' ) );
66
				add_filter( 'lsx_to_post_types_singular', array( $this, 'post_types_singular_filter' ) );
67
				add_filter( 'lsx_to_settings_path', array( $this, 'plugin_path' ), 10, 2 );
68
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
69
			if ( false !== $this->taxonomies ) {
70
				add_filter( 'lsx_to_framework_taxonomies', array( $this, 'taxonomies_filter' ) );
71
				add_filter( 'lsx_to_framework_taxonomies_plural', array( $this, 'taxonomies_plural_filter' ) );
72
			}
73
74
			require_once LSX_TO_SPECIALS_PATH . '/classes/class-to-specials-admin.php';
75
			require_once LSX_TO_SPECIALS_PATH . '/classes/class-to-specials-frontend.php';
76
			require_once LSX_TO_SPECIALS_PATH . '/includes/template-tags.php';
77
78
			// flush_rewrite_rules.
79
			register_activation_hook( LSX_TO_SPECIALS_CORE, array( $this, 'register_activation_hook' ) );
80
			add_action( 'admin_init', array( $this, 'register_activation_hook_check' ) );
81
			add_filter( 'wpseo_schema_graph_pieces', array( $this, 'add_graph_pieces' ), 11, 2 );
82
		}
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...
83
84
		/**
85
		 * Include the post type for the search integration
86
		 */
87
		public function lsx_to_search_integration() {
88
			add_filter( 'lsx_to_search_post_types', array( $this, 'post_types_filter' ) );
89
			add_filter( 'lsx_to_search_taxonomies', array( $this, 'taxonomies_filter' ) );
90
		}
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...
91
92
		/**
93
		 * Load the plugin text domain for translation.
94
		 */
95
		public function load_plugin_textdomain() {
96
			load_plugin_textdomain( 'to-specials', FALSE, basename( LSX_TO_SPECIALS_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...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
TRUE, FALSE and NULL must be lowercase; expected false, but found FALSE.
Loading history...
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
		 * Sets the plugins variables
101
		 */
102
		public function set_vars() {
103
			$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.

Loading history...
104
				'special' => __( 'Specials', 'to-specials' ),
105
			);
106
			$this->post_types_singular = array(
107
				'special' => __( 'Special', 'to-specials' ),
108
			);
109
			$this->post_type_slugs = array_keys( $this->post_types );
110
			$this->taxonomies = 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.

Loading history...
111
				'special-type' => __( 'Special Type', 'to-specials' ),
112
			);
113
			$this->taxonomies_plural = array(
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 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...
114
				'special-type' => __( 'Special Types', 'to-specials' ),
115
			);
116
		}
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...
117
118
		/**
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...
119
		 * Adds our post types to an array via a filter
120
		 */
121
		public function plugin_path( $path, $post_type ) {
122
			if ( false !== $this->post_types && array_key_exists( $post_type, $this->post_types ) ) {
123
				$path = LSX_TO_SPECIALS_PATH;
124
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
125
			return $path;
126
		}
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...
127
128
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
129
		 * Adds our post types to an array via a filter
130
		 */
131
		public function post_types_slugs_filter( $post_types ) {
132
			if ( is_array( $post_types ) ) {
133
				$post_types = array_merge( $post_types, $this->post_type_slugs );
134
			} else {
135
				$post_types = $this->post_type_slugs;
136
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
137
			return $post_types;
138
		}
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...
139
140
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
141
		 * Adds our post types to an array via a filter
142
		 */
143
		public function post_types_filter( $post_types ) {
144
			if ( is_array( $post_types ) && is_array( $this->post_types ) ) {
145
				$post_types = array_merge( $post_types, $this->post_types );
146
			} elseif ( is_array( $this->post_types ) ) {
147
				$post_types = $this->post_types;
148
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
149
			return $post_types;
150
		}
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...
151
152
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types_singular" missing
Loading history...
153
		 * Adds our post types to an array via a filter
154
		 */
155
		public function post_types_singular_filter( $post_types_singular ){
156
			if ( is_array( $post_types_singular ) && is_array( $this->post_types_singular ) ) {
157
				$post_types_singular = array_merge( $post_types_singular, $this->post_types_singular );
158
			} elseif ( is_array( $this->post_types_singular ) ) {
159
				$post_types_singular = $this->post_types_singular;
160
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
161
			return $post_types_singular;
162
		}
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...
163
164
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies" missing
Loading history...
165
		 * Adds our taxonomies to an array via a filter
166
		 */
167
		public function taxonomies_filter( $taxonomies ) {
168
			if ( is_array( $taxonomies ) && is_array( $this->taxonomies ) ) {
169
				$taxonomies = array_merge( $taxonomies, $this->taxonomies );
170
			} elseif ( is_array( $this->taxonomies ) ) {
171
				$taxonomies = $this->taxonomies;
172
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
173
			return $taxonomies;
174
		}
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...
175
176
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies_plural" missing
Loading history...
177
		 * Adds our taxonomies_plural to an array via a filter
178
		 */
179
		public function taxonomies_plural_filter( $taxonomies_plural ) {
180
			if ( is_array( $taxonomies_plural ) && is_array( $this->taxonomies_plural ) ) {
181
				$taxonomies_plural = array_merge( $taxonomies_plural, $this->taxonomies_plural );
182
			} elseif ( is_array( $this->taxonomies_plural ) ) {
183
				$taxonomies_plural = $this->taxonomies_plural;
184
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
185
			return $taxonomies_plural;
186
		}
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...
187
188
		/**
189
		 * Make TO last plugin to load.
190
		 */
191
		public function activated_plugin() {
192
			if ( $plugins = get_option( 'active_plugins' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Variable assignment found within a condition. Did you mean to do a comparison?
Loading history...
Assignments must be the first block of code on a line
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
193
				$search = preg_grep( '/.*\/tour-operator\.php/', $plugins );
194
				$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...
195
196
				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...
197
					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...
198
						array_splice( $plugins, $key, 1 );
199
						array_push( $plugins, $path );
200
						update_option( 'active_plugins', $plugins );
201
					}
202
				}
203
			}
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
		 * On plugin activation
208
		 */
209
		public function register_activation_hook() {
210
			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...
211
				set_transient( '_tour_operators_specials_flush_rewrite_rules', 1, 30 );
212
			}
213
		}
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...
214
215
		/**
216
		 * On plugin activation (check)
217
		 */
218
		public function register_activation_hook_check() {
219
			if ( ! get_transient( '_tour_operators_specials_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...
220
				return;
221
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
222
			delete_transient( '_tour_operators_specials_flush_rewrite_rules' );
223
			flush_rewrite_rules();
224
		}
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...
225
		/**
226
		 * Adds Schema pieces to our output.
227
		 *
228
		 * @param array                 $pieces  Graph pieces to output.
229
		 * @param \WPSEO_Schema_Context $context Object with context variables.
230
		 *
231
		 * @return array $pieces Graph pieces to output.
232
		 */
233
		public function add_graph_pieces( $pieces, $context ) {
234
			if ( class_exists( 'LSX_TO_Schema_Graph_Piece' ) ) {
235
				require_once LSX_TO_SPECIALS_PATH . 'classes/class-to-specials-schema.php';
236
				$pieces[] = new LSX_TO_Specials_Schema( $context );
237
			}
238
			return $pieces;
239
		}
240
	}
241
	new LSX_TO_Specials();
242
}
243