lightspeeddevelopment /
to-team
| 1 | <?php |
||||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||||
| 2 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 3 | * @package LSX_TO_Template_Redirects |
||||
| 4 | * @author LightSpeed |
||||
| 5 | * @license GPL3 |
||||
| 6 | * @link |
||||
| 7 | * @copyright 2016 LightSpeed |
||||
| 8 | * |
||||
| 9 | **/ |
||||
|
0 ignored issues
–
show
|
|||||
| 10 | |||||
| 11 | class LSX_TO_Template_Redirects { |
||||
| 12 | |||||
| 13 | /** |
||||
| 14 | * Plugin Path |
||||
| 15 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 16 | public $plugin_path = false; |
||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * Post Types |
||||
| 20 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 21 | public $post_types = false; |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * Taxonomies |
||||
| 25 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 26 | public $taxonomies = false; |
||||
| 27 | |||||
| 28 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 32 | * @param array $taxonomies an array of the taxonomies to redirect. |
||||
|
0 ignored issues
–
show
|
|||||
| 33 | */ |
||||
| 34 | public function __construct( $plugin_path = false, $post_types = false, $taxonomies = false ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 35 | if ( false !== $plugin_path ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 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
|
|||||
| 47 | if ( false !== $taxonomies ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 48 | $this->taxonomies = $taxonomies; |
||||
| 49 | add_filter( 'template_include', array( $this, 'taxonomy_template_include' ), 99 ); |
||||
| 50 | } |
||||
| 51 | } |
||||
| 52 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 53 | |||||
| 54 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 55 | * Redirect wordpress to the archive template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 56 | * |
||||
| 57 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 58 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 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
|
|||||
| 64 | $template = $this->plugin_path . 'templates/archive-' . $current_post_type . '.php'; |
||||
| 65 | } |
||||
| 66 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 67 | return $template; |
||||
| 68 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 69 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 70 | * Redirect wordpress to the single template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 71 | * |
||||
| 72 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 73 | * |
||||
| 74 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 75 | */ |
||||
| 76 | public function post_type_single_template_include( $template ) { |
||||
| 77 | if ( is_main_query() && is_singular( $this->post_types ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 80 | $template = $this->plugin_path . 'templates/single-' . $current_post_type . '.php'; |
||||
| 81 | } |
||||
| 82 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 83 | return $template; |
||||
| 84 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 85 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 86 | * Redirect wordpress to the taxonomy located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 87 | * |
||||
| 88 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 89 | * |
||||
| 90 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 91 | */ |
||||
| 92 | public function taxonomy_template_include( $template ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 93 | |||||
| 94 | if ( is_main_query() && is_tax( $this->taxonomies ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 97 | $template = $this->plugin_path . 'templates/taxonomy-' . $current_taxonomy . '.php'; |
||||
| 98 | } |
||||
| 99 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 100 | return $template; |
||||
| 101 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 102 | |||||
| 103 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 104 | * Redirect wordpress to the search template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 105 | * |
||||
| 106 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 107 | * |
||||
| 108 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 109 | */ |
||||
| 110 | public function search_template_include( $template ) { |
||||
| 111 | if ( is_main_query() && is_search() ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 112 | if ( file_exists( $this->plugin_path . 'templates/search.php' ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 113 | $template = $this->plugin_path . 'templates/search.php'; |
||||
| 114 | } |
||||
| 115 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 116 | return $template; |
||||
| 117 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 118 | |||||
| 119 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 120 | * Redirect wordpress to the single template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 121 | * |
||||
| 122 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 123 | * |
||||
| 124 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 130 | $template = "{$slug}-{$name}.php"; |
||||
| 131 | } else { |
||||
| 132 | $template = "{$slug}.php"; |
||||
| 133 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 138 | $template = $path . 'templates/' . $template; |
||||
| 139 | } elseif ( file_exists( get_stylesheet_directory() . '/' . $template ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 140 | $template = get_stylesheet_directory() . '/' . $template; |
||||
| 141 | } else { |
||||
| 142 | $template = false; |
||||
| 143 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 144 | if ( false !== $template ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 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
|
|||||
| 150 | |||||
| 151 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 152 | * Redirect wordpress to the widget template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 153 | * |
||||
| 154 | * @param $path |
||||
|
0 ignored issues
–
show
|
|||||
| 155 | * @param $post_type |
||||
|
0 ignored issues
–
show
|
|||||
| 156 | * |
||||
| 157 | * @return $path |
||||
|
0 ignored issues
–
show
|
|||||
| 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
Loading history...
|
|||||
| 161 | || ( false !== $this->taxonomies && in_array( $slug, $this->taxonomies ) ) || 'post' === $slug ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 162 | $path = $this->plugin_path; |
||||
| 163 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 164 | return $path; |
||||
| 165 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 166 | |||||
| 167 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 168 | * Redirect wordpress to the single template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 169 | * |
||||
| 170 | * @param $path |
||||
|
0 ignored issues
–
show
|
|||||
| 171 | * @param $post_type |
||||
|
0 ignored issues
–
show
|
|||||
| 172 | * |
||||
| 173 | * @return $path |
||||
|
0 ignored issues
–
show
|
|||||
| 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
Loading history...
|
|||||
| 177 | || ( false !== $this->taxonomies && in_array( $slug, $this->taxonomies ) ) || 'post' === $slug ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 178 | $path = $this->plugin_path; |
||||
| 179 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 180 | return $path; |
||||
| 181 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 182 | } |
||||
| 183 |