lightspeeddevelopment /
to-specials
| 1 | <?php |
||||
|
0 ignored issues
–
show
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 2018 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; |
||||
|
0 ignored issues
–
show
|
|||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * Taxonomies |
||||
| 25 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 26 | public $taxonomies = false; |
||||
|
0 ignored issues
–
show
|
|||||
| 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 ); |
||||
|
0 ignored issues
–
show
|
|||||
| 39 | add_filter( 'lsx_to_content_path', array( $this, 'content_path'), 10, 3 ); |
||||
|
0 ignored issues
–
show
|
|||||
| 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 ); |
||||
|
0 ignored issues
–
show
|
|||||
| 44 | add_filter( 'template_include', array( $this, 'post_type_single_template_include'), 99 ); |
||||
|
0 ignored issues
–
show
|
|||||
| 45 | add_filter( 'template_include', array( $this, 'search_template_include'), 99 ); |
||||
|
0 ignored issues
–
show
|
|||||
| 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 ); |
||||
|
0 ignored issues
–
show
|
|||||
| 50 | } |
||||
| 51 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 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 ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 61 | |||||
| 62 | if ( is_main_query() && is_post_type_archive($this->post_types)) { |
||||
|
0 ignored issues
–
show
|
|||||
| 63 | $current_post_type = get_post_type(); |
||||
| 64 | if ( '' == locate_template( array( 'archive-'.$current_post_type.'.php' ) ) && file_exists( $this->plugin_path.'templates/archive-'.$current_post_type.'.php' )) { |
||||
|
0 ignored issues
–
show
|
|||||
| 65 | $template = $this->plugin_path.'templates/archive-'.$current_post_type.'.php'; |
||||
|
0 ignored issues
–
show
|
|||||
| 66 | } |
||||
| 67 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 68 | return $template; |
||||
| 69 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 70 | |||||
| 71 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 72 | * Redirect wordpress to the single template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 73 | * |
||||
| 74 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 75 | * |
||||
| 76 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 77 | */ |
||||
| 78 | public function post_type_single_template_include($template) { |
||||
|
0 ignored issues
–
show
|
|||||
| 79 | if ( is_main_query() && is_singular($this->post_types) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 80 | $current_post_type = get_post_type(); |
||||
| 81 | |||||
| 82 | if ( '' == locate_template( array( 'single-'.$current_post_type.'.php' ) ) && file_exists( $this->plugin_path.'templates/single-'.$current_post_type.'.php') ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 83 | $template = $this->plugin_path.'templates/single-'.$current_post_type.'.php'; |
||||
|
0 ignored issues
–
show
|
|||||
| 84 | } |
||||
| 85 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 86 | return $template; |
||||
| 87 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 88 | |||||
| 89 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 90 | * Redirect wordpress to the taxonomy located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 91 | * |
||||
| 92 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 93 | * |
||||
| 94 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 95 | */ |
||||
| 96 | public function taxonomy_template_include($template) { |
||||
|
0 ignored issues
–
show
|
|||||
| 97 | |||||
| 98 | if ( is_main_query() && is_tax($this->taxonomies) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 99 | $current_taxonomy = get_query_var('taxonomy'); |
||||
|
0 ignored issues
–
show
|
|||||
| 100 | |||||
| 101 | if ( '' == locate_template( array( 'taxonomy-'.$current_taxonomy.'.php' ) ) && file_exists( $this->plugin_path.'templates/taxonomy-'.$current_taxonomy.'.php') ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 102 | $template = $this->plugin_path.'templates/taxonomy-'.$current_taxonomy.'.php'; |
||||
|
0 ignored issues
–
show
|
|||||
| 103 | } |
||||
| 104 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 105 | return $template; |
||||
| 106 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 107 | |||||
| 108 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 109 | * Redirect wordpress to the search template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 110 | * |
||||
| 111 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 112 | * |
||||
| 113 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 114 | */ |
||||
| 115 | public function search_template_include( $template ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 116 | |||||
| 117 | if ( is_main_query() && is_search() ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 118 | if ( file_exists( $this->plugin_path.'templates/search.php' )) { |
||||
|
0 ignored issues
–
show
|
|||||
| 119 | $template = $this->plugin_path.'templates/search.php'; |
||||
|
0 ignored issues
–
show
|
|||||
| 120 | } |
||||
| 121 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 122 | return $template; |
||||
| 123 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 124 | |||||
| 125 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 126 | * Redirect wordpress to the single template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 127 | * |
||||
| 128 | * @param $template |
||||
|
0 ignored issues
–
show
|
|||||
| 129 | * |
||||
| 130 | * @return $template |
||||
|
0 ignored issues
–
show
|
|||||
| 131 | */ |
||||
| 132 | public function content_part($slug, $name = null) { |
||||
|
0 ignored issues
–
show
|
|||||
| 133 | $template = array(); |
||||
| 134 | $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...
|
|||||
| 135 | if ( '' !== $name ){ |
||||
|
0 ignored issues
–
show
|
|||||
| 136 | $template = "{$slug}-{$name}.php"; |
||||
| 137 | }else{ |
||||
|
0 ignored issues
–
show
|
|||||
| 138 | $template = "{$slug}.php"; |
||||
| 139 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 140 | $original_name = $template; |
||||
| 141 | $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...
|
|||||
| 142 | |||||
| 143 | if ( '' == locate_template( array( $template ) ) && file_exists( $path.'templates/'.$template) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 144 | $template = $path.'templates/'.$template; |
||||
|
0 ignored issues
–
show
|
|||||
| 145 | }elseif(file_exists( get_stylesheet_directory().'/'.$template)){ |
||||
|
0 ignored issues
–
show
|
|||||
| 146 | $template = get_stylesheet_directory().'/'.$template; |
||||
|
0 ignored issues
–
show
|
|||||
| 147 | }else{ |
||||
|
0 ignored issues
–
show
|
|||||
| 148 | $template = false; |
||||
| 149 | } |
||||
| 150 | |||||
| 151 | if(false !== $template){ |
||||
|
0 ignored issues
–
show
|
|||||
| 152 | load_template( $template, false ); |
||||
| 153 | }else { |
||||
| 154 | echo wp_kses_post('<p>No '.$original_name.' can be found.</p>'); |
||||
|
0 ignored issues
–
show
|
|||||
| 155 | } |
||||
| 156 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 157 | |||||
| 158 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 159 | * Redirect wordpress to the widget template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 160 | * |
||||
| 161 | * @param $path |
||||
|
0 ignored issues
–
show
|
|||||
| 162 | * @param $post_type |
||||
|
0 ignored issues
–
show
|
|||||
| 163 | * |
||||
| 164 | * @return $path |
||||
|
0 ignored issues
–
show
|
|||||
| 165 | */ |
||||
| 166 | public function widget_path($path,$slug) { |
||||
|
0 ignored issues
–
show
|
|||||
| 167 | 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...
|
|||||
| 168 | || (false !== $this->taxonomies && in_array($slug,$this->taxonomies)) || 'post' === $slug){ |
||||
|
0 ignored issues
–
show
|
|||||
| 169 | $path = $this->plugin_path; |
||||
| 170 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 171 | return $path; |
||||
| 172 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 173 | |||||
| 174 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 175 | * Redirect wordpress to the single template located in the plugin |
||||
|
0 ignored issues
–
show
|
|||||
| 176 | * |
||||
| 177 | * @param $path |
||||
|
0 ignored issues
–
show
|
|||||
| 178 | * @param $post_type |
||||
|
0 ignored issues
–
show
|
|||||
| 179 | * |
||||
| 180 | * @return $path |
||||
|
0 ignored issues
–
show
|
|||||
| 181 | */ |
||||
| 182 | public function content_path($path,$slug) { |
||||
|
0 ignored issues
–
show
|
|||||
| 183 | 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...
|
|||||
| 184 | || (false !== $this->taxonomies && in_array($slug,$this->taxonomies)) || 'post' === $slug){ |
||||
|
0 ignored issues
–
show
|
|||||
| 185 | $path = $this->plugin_path; |
||||
| 186 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 187 | return $path; |
||||
| 188 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 189 | } |