These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | /* |
||
4 | Plugin Name: MslsSelect |
||
5 | Plugin URI: https://github.com/lloc/MslsSelect |
||
6 | Description: Transforms the output of the Multisite Language Switcher to an HTML select |
||
7 | Version: 1.1 |
||
8 | Author: Dennis Ploetner |
||
9 | Author URI: http://lloc.de/ |
||
10 | */ |
||
11 | |||
12 | /* |
||
13 | Copyright 2014 Dennis Ploetner (email : [email protected]) |
||
14 | |||
15 | This program is free software; you can redistribute it and/or modify |
||
16 | it under the terms of the GNU General Public License, version 2, as |
||
17 | published by the Free Software Foundation. |
||
18 | |||
19 | This program is distributed in the hope that it will be useful, |
||
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
22 | GNU General Public License for more details. |
||
23 | |||
24 | You should have received a copy of the GNU General Public License |
||
25 | along with this program; if not, write to the Free Software |
||
26 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
||
27 | */ |
||
28 | |||
29 | /** |
||
30 | * MslsSelect Class |
||
31 | * @package mslsselect |
||
32 | */ |
||
33 | class MslsSelect { |
||
34 | |||
35 | const VERSION = '1.1'; |
||
36 | |||
37 | /** |
||
38 | * Init |
||
39 | * |
||
40 | * @return MslsSelect |
||
41 | */ |
||
42 | public function init() { |
||
43 | if ( ! is_admin() ) { |
||
44 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
||
45 | add_filter( 'msls_output_get_tags', array( $this, 'get_tags' ) ); |
||
46 | add_filter( 'msls_output_get', array( $this, 'output_get' ), 10, 3 ); |
||
47 | } |
||
48 | |||
49 | return $this; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Factory |
||
54 | * |
||
55 | * @return MslsSelect |
||
56 | */ |
||
57 | public static function create() { |
||
58 | $obj = new self; |
||
59 | |||
60 | add_action( 'plugins_loaded', array( $obj, 'init' ) ); |
||
61 | |||
62 | return $obj; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Enqueue scripts action |
||
67 | */ |
||
68 | public function enqueue_scripts() { |
||
69 | wp_enqueue_script( 'mslsselect', plugins_url( '/js/mslsselect.js', __FILE__ ), array( 'jquery' ), self::VERSION, true ); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Filter for the 'msls_output_get'-hook |
||
74 | * |
||
75 | * @param string $url |
||
76 | * @param StdClass $link |
||
77 | * @param bool $current |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | public function output_get( $url, $link, $current ) { |
||
82 | return sprintf( '<option value="%s"%s>%s</option>', $url, ( $current ? ' selected="selected"' : '' ), $link->txt ); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Filter for the 'msls_output_get_tags'-hook |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | public function get_tags() { |
||
91 | return array( |
||
92 | 'before_item' => '', |
||
93 | 'after_item' => '', |
||
94 | 'before_output' => '<select class="msls_languages">', |
||
95 | 'after_output' => '</select>', |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | } |
||
100 | |||
101 | MslsSelect::create(); |
||
102 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.