Issues (1082)

classes/class-lsx-to-template-redirects.php (137 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
3
 * @package   LSX_TO_Template_Redirects
4
 * @author    LightSpeed
5
 * @license   GPL3
6
 * @link
7
 * @copyright 2016 LightSpeed
8
 *
9
 **/
0 ignored issues
show
Additional blank lines found at end of doc comment
Loading history...
There must be no blank lines after the class comment
Loading history...
10
11
class LSX_TO_Template_Redirects {
12
13
	/**
14
	 * Plugin Path
15
	 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
16
	public $plugin_path = false;
17
18
	/**
19
	 * Post Types
20
	 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
21
	public $post_types = false;
22
23
	/**
24
	 * Taxonomies
25
	 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
26
	public $taxonomies = false;
27
28
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$plugin_path" missing
Loading history...
29
	 * Initialize the plugin by setting localization, filters, and administration functions.
30
	 *
31
	 * @param array $post_types an array of the post types to redirect.
0 ignored issues
show
Doc comment for parameter $post_types does not match actual variable name $plugin_path
Loading history...
32
	 * @param array $taxonomies an array of the taxonomies to redirect.
0 ignored issues
show
Doc comment for parameter $taxonomies does not match actual variable name $post_types
Loading history...
33
	 */
34
	public function __construct( $plugin_path = false, $post_types = false, $taxonomies = false ) {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
35
		if ( false !== $plugin_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...
36
			$this->plugin_path = $plugin_path;
37
38
			add_filter( 'lsx_to_widget_path', array( $this, 'widget_path' ), 10, 2 );
39
			add_filter( 'lsx_to_content_path', array( $this, 'content_path' ), 10, 3 );
40
41
			if ( false !== $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...
42
				$this->post_types = $post_types;
43
				add_filter( 'template_include', array( $this, 'post_type_archive_template_include' ), 99 );
44
				add_filter( 'template_include', array( $this, 'post_type_single_template_include' ), 99 );
45
				add_filter( 'template_include', array( $this, 'search_template_include' ), 99 );
46
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
47
			if ( false !== $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...
48
				$this->taxonomies = $taxonomies;
49
				add_filter( 'template_include', array( $this, 'taxonomy_template_include' ), 99 );
50
			}
51
		}
52
	}
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...
53
54
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$template" missing
Loading history...
55
	 * Redirect wordpress to the archive template located in the plugin
0 ignored issues
show
Please spell "WordPress" correctly. Found 1 misspelling(s): wordpress
Loading history...
56
	 *
57
	 * @param	$template
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
58
	 * @return	$template
0 ignored issues
show
Documentation Bug introduced by
The doc comment $template at position 0 could not be parsed: Unknown type name '$template' at position 0 in $template.
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
59
	 */
60
	public function post_type_archive_template_include( $template ) {
61
		if ( is_main_query() && is_post_type_archive( $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...
62
			$current_post_type = get_post_type();
63
			if ( '' == locate_template( array( 'archive-' . $current_post_type . '.php' ) )	&& file_exists( $this->plugin_path . 'templates/archive-' . $current_post_type . '.php' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
64
				$template = $this->plugin_path . 'templates/archive-' . $current_post_type . '.php';
65
			}
66
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
67
		return $template;
68
	}
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...
69
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$template" missing
Loading history...
70
	 * Redirect wordpress to the single template located in the plugin
0 ignored issues
show
Please spell "WordPress" correctly. Found 1 misspelling(s): wordpress
Loading history...
71
	 *
72
	 * @param	$template
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
73
	 *
74
	 * @return	$template
0 ignored issues
show
Documentation Bug introduced by
The doc comment $template at position 0 could not be parsed: Unknown type name '$template' at position 0 in $template.
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
75
	 */
76
	public function post_type_single_template_include( $template ) {
77
		if ( is_main_query() && is_singular( $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...
78
			$current_post_type = get_post_type();
79
			if ( '' == locate_template( array( 'single-' . $current_post_type . '.php' ) )	&& file_exists( $this->plugin_path . 'templates/single-' . $current_post_type . '.php' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
Expected 1 space before "&&"; 2 found
Loading history...
Expected 1 space before logical operator; 2 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
80
					$template = $this->plugin_path . 'templates/single-' . $current_post_type . '.php';
81
			}
82
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
83
		return $template;
84
	}
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...
85
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$template" missing
Loading history...
86
	 * Redirect wordpress to the taxonomy located in the plugin
0 ignored issues
show
Please spell "WordPress" correctly. Found 1 misspelling(s): wordpress
Loading history...
87
	 *
88
	 * @param	$template
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
89
	 *
90
	 * @return	$template
0 ignored issues
show
Documentation Bug introduced by
The doc comment $template at position 0 could not be parsed: Unknown type name '$template' at position 0 in $template.
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
91
	 */
92
	public function taxonomy_template_include( $template ) {
0 ignored issues
show
Expected 0 blank lines after opening function brace; 1 found
Loading history...
93
94
		if ( is_main_query() && is_tax( $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...
95
			$current_taxonomy = get_query_var( 'taxonomy' );
96
			if ( '' == locate_template( array( 'taxonomy-' . $current_taxonomy . '.php' ) ) && file_exists( $this->plugin_path . 'templates/taxonomy-' . $current_taxonomy . '.php' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
97
				$template = $this->plugin_path . 'templates/taxonomy-' . $current_taxonomy . '.php';
98
			}
99
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
100
		return $template;
101
	}
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...
102
103
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$template" missing
Loading history...
104
	 * Redirect wordpress to the search template located in the plugin
0 ignored issues
show
Please spell "WordPress" correctly. Found 1 misspelling(s): wordpress
Loading history...
105
	 *
106
	 * @param	$template
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
107
	 *
108
	 * @return	$template
0 ignored issues
show
Documentation Bug introduced by
The doc comment $template at position 0 could not be parsed: Unknown type name '$template' at position 0 in $template.
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
109
	 */
110
	public function search_template_include( $template ) {
111
		if ( is_main_query() && is_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...
112
			if ( file_exists( $this->plugin_path . 'templates/search.php' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
113
				$template = $this->plugin_path . 'templates/search.php';
114
			}
115
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
116
		return $template;
117
	}
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...
118
119
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$slug" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$name" missing
Loading history...
120
	 * Redirect wordpress to the single template located in the plugin
0 ignored issues
show
Please spell "WordPress" correctly. Found 1 misspelling(s): wordpress
Loading history...
121
	 *
122
	 * @param	$template
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
123
	 *
124
	 * @return	$template
0 ignored issues
show
Documentation Bug introduced by
The doc comment $template at position 0 could not be parsed: Unknown type name '$template' at position 0 in $template.
Loading history...
Function return type is not void, but function has no return statement
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
125
	 */
126
	public function content_part( $slug, $name = null ) {
127
		$template = array();
128
		$name = (string) $name;
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.

Loading history...
129
		if ( '' !== $name ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
130
			$template = "{$slug}-{$name}.php";
131
		} else {
132
			$template = "{$slug}.php";
133
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
134
		$original_name = $template;
135
		$path = apply_filters( 'lsx_to_content_path', '', get_post_type() );
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...
136
137
		if ( '' == locate_template( array( $template ) ) && file_exists( $path . 'templates/' . $template ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
138
			$template = $path . 'templates/' . $template;
139
		} elseif ( file_exists( get_stylesheet_directory() . '/' . $template ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
140
			$template = get_stylesheet_directory() . '/' . $template;
141
		} else {
142
			$template = false;
143
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
144
		if ( false !== $template ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
145
			load_template( $template, false );
146
		} else {
147
			echo wp_kses_post( '<p>No ' . $original_name . ' can be found.</p>' );
148
		}
149
	}
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...
150
151
	/**
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 "$slug" missing
Loading history...
152
	 * Redirect wordpress to the widget template located in the plugin
0 ignored issues
show
Please spell "WordPress" correctly. Found 1 misspelling(s): wordpress
Loading history...
153
	 *
154
	 * @param	$path
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
155
	 * @param	$post_type
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
156
	 *
157
	 * @return	$path
0 ignored issues
show
Documentation Bug introduced by
The doc comment $path at position 0 could not be parsed: Unknown type name '$path' at position 0 in $path.
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
158
	 */
159
	public function widget_path( $path, $slug ) {
160
		if ( ( false !== $this->post_types && in_array( $slug, $this->post_types ) )
0 ignored issues
show
$this->post_types of type true is incompatible with the type array expected by parameter $haystack of in_array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

160
		if ( ( false !== $this->post_types && in_array( $slug, /** @scrutinizer ignore-type */ $this->post_types ) )
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
161
		 || ( false !== $this->taxonomies && in_array( $slug, $this->taxonomies ) ) || 'post' === $slug ) {
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
162
			$path = $this->plugin_path;
163
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
164
		return $path;
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 "$path" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$slug" missing
Loading history...
168
	 * Redirect wordpress to the single template located in the plugin
0 ignored issues
show
Please spell "WordPress" correctly. Found 1 misspelling(s): wordpress
Loading history...
169
	 *
170
	 * @param	$path
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
171
	 * @param	$post_type
0 ignored issues
show
Missing parameter name
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
172
	 *
173
	 * @return	$path
0 ignored issues
show
Documentation Bug introduced by
The doc comment $path at position 0 could not be parsed: Unknown type name '$path' at position 0 in $path.
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
174
	 */
175
	public function content_path( $path, $slug ) {
176
		if ( ( false !== $this->post_types && in_array( $slug, $this->post_types ) )
0 ignored issues
show
$this->post_types of type true is incompatible with the type array expected by parameter $haystack of in_array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

176
		if ( ( false !== $this->post_types && in_array( $slug, /** @scrutinizer ignore-type */ $this->post_types ) )
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
177
		 || ( false !== $this->taxonomies && in_array( $slug, $this->taxonomies ) ) || 'post' === $slug ) {
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
178
			$path = $this->plugin_path;
179
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
180
		return $path;
181
	}
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...
182
}
183