GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( ff4be0...20f741 )
by Christian
03:51
created

widget.php (15 issues)

1
<?php
2
3
namespace PodloveSubscribeButton;
4
5
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
6
7
class Widget extends \WP_Widget {
8
9
	public static $widget_settings = array(
10
		'infotext',
11
		'title',
12
		'size',
13
		'style',
14
		'format',
15
		'autowidth',
16
		'button',
17
		'color',
18
	);
19
20
	public function __construct() {
21
		parent::__construct(
22
			'podlove_subscribe_button_wp_plugin_widget',
23
			( self::is_podlove_publisher_active() ? 'Podlove Subscribe Button (WordPress plugin)' : 'Podlove Subscribe Button' ),
24
			array( 'description' => __( 'Adds a Podlove Subscribe Button to your Sidebar', 'podlove-subscribe-button' ), )
25
		);
26
27
	}
28
29
	public static function is_podlove_publisher_active() {
30
		if ( is_plugin_active( "podlove-podcasting-plugin-for-wordpress/podlove.php" ) ) {
31
			return true;
32
		}
33
34
		return false;
35
36
	}
37
38
	public function widget( $args, $instance ) {
39
		// Fetch the (network)button by it's name
40
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $instance[ 'button' ] ) ) {
41
			return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args['button'] );
42
		}
43
44
		echo $args[ 'before_widget' ];
45
		echo $args[ 'before_title' ] . apply_filters( 'widget_title', $instance[ 'title' ] ) . $args[ 'after_title' ];
46
47
		echo $button->render(
48
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'size' ),
49
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'autowidth' ),
50
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'style' ),
51
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'format' ),
52
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'color' )
53
		);
54
55
		if ( strlen( $instance[ 'infotext' ] ) ) {
56
			echo wpautop( $instance[ 'infotext' ] );
57
		}
58
59
		echo $args[ 'after_widget' ];
60
61
	}
62
63
	public function form( $instance ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function form()
Loading history...
64
		foreach ( self::$widget_settings as $setting ) {
65
			$$setting = isset( $instance[ $setting ] ) ? $instance[ $setting ] : '';
66
		}
67
68
		$buttons = \PodloveSubscribeButton\Model\Button::all();
69
		if ( is_multisite() ) {
70
			$network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all();
71
		}
72
73
		$buttons_as_options = function( $buttons ) {
74
			foreach ( $buttons as $subscribebutton ) {
75
				echo "<option value='" . $subscribebutton->name . "' " . ( $subscribebutton->name == $button ? 'selected=\"selected\"' : '' ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $button does not exist. Did you maybe mean $buttons?
Loading history...
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$subscribebutton'.
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Coding Style Comprehensibility introduced by
The string literal > does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ( does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal )</option> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
76
			}
77
		} ?>
78
		<p>
79
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'podlove-subscribe-button' ); ?></label>
80
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $title; ?>" />
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $title seems to be never defined.
Loading history...
81
			<label for="<?php echo $this->get_field_id( 'color' ); ?>"><?php _e( 'Color', 'podlove-subscribe-button' ); ?></label>
82
			<input class="podlove_subscribe_button_color" id="<?php echo $this->get_field_id( 'color' ); ?>" name="<?php echo $this->get_field_name( 'color' ); ?>" value="<?php echo $color; ?>" />
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $color seems to be never defined.
Loading history...
83
			<style type="text/css">
84
				.sp-replacer {
85
					display: flex;
86
				}
87
				.sp-preview {
88
					flex-grow: 10;
89
				}
90
			</style>
91
			<label for="<?php echo $this->get_field_id( 'button' ); ?>"><?php _e( 'Button', 'podlove-subscribe-button' ); ?></label>
92
			<select class="widefat" id="<?php echo $this->get_field_id( 'button' ); ?>"
93
				      name="<?php echo $this->get_field_name( 'button' ); ?>">
0 ignored issues
show
Found precision alignment of 2 spaces.
Loading history...
94
				<?php if ( isset( $network_buttons ) && count( $network_buttons ) > 0 ) : ?>
95
					<optgroup label="<?php _e( 'Local', 'podlove-subscribe-button' ); ?>">
96
						<?php $buttons_as_options( $buttons ); ?>
97
					</optgroup>
98
					<optgroup label="<?php _e( 'Network', 'podlove-subscribe-button' ); ?>">
99
						<?php $buttons_as_options( $network_buttons ); ?>
100
					</optgroup>
101
				<?php else :
0 ignored issues
show
Opening PHP tag must be on a line by itself
Loading history...
102
					$buttons_as_options( $buttons );
103
				 endif; ?>
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Closing brace indented incorrectly; expected 16 spaces, found 17
Loading history...
Closing PHP tag must be on a line by itself
Loading history...
104
			</select>
105
			<?php
106
			$customize_options = array(
107
				'size'      => array(
108
					'name'    => __( 'Size', 'podlove-subscribe-button' ),
109
					'options' => \PodloveSubscribeButton\Model\Button::$size
110
				),
111
				'style'     => array(
112
					'name'    => __( 'Style', 'podlove-subscribe-button' ),
113
					'options' => \PodloveSubscribeButton\Model\Button::$style
114
				),
115
				'format'    => array(
116
					'name'    => __( 'Format', 'podlove-subscribe-button' ),
117
					'options' => \PodloveSubscribeButton\Model\Button::$format
118
				),
119
				'autowidth' => array(
120
					'name'    => __( 'Autowidth', 'podlove-subscribe-button' ),
121
					'options' => \PodloveSubscribeButton\Model\Button::$width
122
				)
123
			);
124
125
			foreach ( $customize_options as $slug => $properties ) : ?>
126
				<label for="<?php echo $this->get_field_id( $slug ); ?>"><?php echo $properties[ 'name' ]; ?></label>
127
				<select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>">
128
					<option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php printf( __( 'Default %s', 'podlove-subscribe-button' ), $properties[ 'name' ] ) ?></option>
129
					<optgroup>
130
						<?php foreach ( $properties[ 'options' ] as $property => $name ) : ?>
131
						<option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php echo $name; ?></option>
132
						<?php endforeach; ?>
133
					</optgroup>
134
				</select>
135
			<?php endforeach; ?>
136
			<label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove-subscribe-button' ); ?></label>
137
			<textarea class="widefat" rows="10" id="<?php echo $this->get_field_id( 'infotext' ); ?>" name="<?php echo $this->get_field_name( 'infotext' ); ?>"><?php echo $infotext; ?></textarea>
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $infotext seems to be never defined.
Loading history...
138
		</p>
139
		<?php
140
141
	}
142
143
	public function update( $new_instance, $old_instance ) {
144
		$instance = array();
145
146
		foreach ( self::$widget_settings as $setting ) {
147
			$instance[ $setting ] = ( ! empty( $new_instance[ $setting ] ) ) ? strip_tags( $new_instance[ $setting ] ) : '';
148
		}
149
150
		return $instance;
151
152
	}
153
154
} // END class
155