These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * MslsWidget |
||
| 4 | * @author Dennis Ploetner <[email protected]> |
||
| 5 | * @since 0.9.8 |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace lloc\Msls; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * The standard widget of the Multisite Language Switcher |
||
| 12 | * @package Msls |
||
| 13 | */ |
||
| 14 | class MslsWidget extends \WP_Widget { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Constructor |
||
| 18 | */ |
||
| 19 | public function __construct() { |
||
| 20 | parent::__construct( |
||
| 21 | false, |
||
| 22 | $name = __( 'Multisite Language Switcher', 'multisite-language-switcher' ) |
||
| 23 | ); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Output of the widget in the frontend |
||
| 28 | * |
||
| 29 | * @param array $args |
||
| 30 | * @param array $instance |
||
| 31 | * |
||
| 32 | * @user MslsOutput |
||
| 33 | */ |
||
| 34 | public function widget( $args, $instance ) { |
||
| 35 | $args = wp_parse_args( |
||
| 36 | $args, |
||
| 37 | [ |
||
| 38 | 'before_widget' => '', |
||
| 39 | 'after_widget' => '', |
||
| 40 | 'before_title' => '', |
||
| 41 | 'after_title' => '', |
||
| 42 | ] |
||
| 43 | ); |
||
| 44 | |||
| 45 | /** This filter is documented in wp-includes/default-widgets.php */ |
||
| 46 | $title = apply_filters( |
||
| 47 | 'widget_title', |
||
| 48 | ( isset( $instance['title'] ) ? $instance['title'] : '' ), |
||
| 49 | $instance, |
||
| 50 | $this->id_base |
||
| 51 | ); |
||
| 52 | if ( $title ) { |
||
| 53 | $title = $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
||
| 54 | } |
||
| 55 | |||
| 56 | $content = MslsOutput::init()->__toString(); |
||
|
0 ignored issues
–
show
|
|||
| 57 | if ( '' == $content ) { |
||
| 58 | $content = __( 'No available translations found', 'multisite-language-switcher' ); |
||
| 59 | } |
||
| 60 | |||
| 61 | echo $args['before_widget'], $title, $content, $args['after_widget']; // xss ok |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Update widget in the backend |
||
| 66 | * |
||
| 67 | * @param array $new_instance |
||
| 68 | * @param array $old_instance |
||
| 69 | * |
||
| 70 | * @return array |
||
| 71 | */ |
||
| 72 | public function update( $new_instance, $old_instance ) { |
||
| 73 | $instance = $old_instance; |
||
| 74 | if ( isset( $new_instance['title'] ) ) { |
||
| 75 | $instance['title'] = strip_tags( $new_instance['title'] ); |
||
| 76 | } |
||
| 77 | |||
| 78 | return $instance; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Display an input-form in the backend |
||
| 83 | * |
||
| 84 | * @param array $instance |
||
| 85 | * |
||
| 86 | * @codeCoverageIgnore |
||
| 87 | */ |
||
| 88 | public function form( $instance ) { |
||
| 89 | printf( |
||
| 90 | '<p><label for="%1$s">%2$s:</label> <input class="widefat" id="%1$s" name="%3$s" type="text" value="%4$s" /></p>', |
||
| 91 | $this->get_field_id( 'title' ), |
||
| 92 | __( 'Title', 'multisite-language-switcher' ), |
||
| 93 | $this->get_field_name( 'title' ), |
||
| 94 | ( isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '' ) |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | |||
| 98 | } |
||
| 99 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: