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
Pull Request — master (#42)
by Christian
02:49
created

widget.php (2 issues)

1
<?php
0 ignored issues
show
Class file names should be based on the class name with "class-" prepended. Expected class-widget.php, but found widget.php.
Loading history...
2
/**
3
 * @author    Podlove <[email protected]>
4
 * @copyright Copyright (c) 2014-2018, Podlove
5
 * @license   https://github.com/podlove/podlove-subscribe-button-wp-plugin/blob/master/LICENSE MIT
6
 * @package   Podlove\PodloveSubscribeButton
7
 */
8
9
namespace PodloveSubscribeButton;
10
11
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
12
13
class Widget extends \WP_Widget {
14
15
	public static $widget_settings = array(
16
		'infotext',
17
		'title',
18
		'size',
19
		'style',
20
		'format',
21
		'autowidth',
22
		'button',
23
		'color',
24
	);
25
26
	public function __construct() {
27
		parent::__construct(
28
			'podlove_subscribe_button_wp_plugin_widget',
29
			( \PodloveSubscribeButton\is_podlove_publisher_active() ? 'Podlove Subscribe Button (WordPress plugin)' : 'Podlove Subscribe Button' ),
30
			array( 'description' => __( 'Adds a Podlove Subscribe Button to your Sidebar', 'podlove-subscribe-button' ), )
31
		);
32
33
	}
34
35
	public function widget( $args, $instance ) {
36
		// Fetch the (network)button by it's name
37
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $instance[ 'button' ] ) ) {
38
			return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args['button'] );
39
		}
40
41
		echo $args[ 'before_widget' ];
42
		echo $args[ 'before_title' ] . apply_filters( 'widget_title', $instance[ 'title' ] ) . $args[ 'after_title' ];
43
44
		echo $button->render(
45
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'size' ),
46
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'autowidth' ),
47
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'style' ),
48
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'format' ),
49
			\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'color' )
50
		);
51
52
		if ( strlen( $instance[ 'infotext' ] ) ) {
53
			echo wpautop( $instance[ 'infotext' ] );
54
		}
55
56
		echo $args[ 'after_widget' ];
57
58
	}
59
60
	public function form( $instance ) {
61
		$title     = isset( $instance[ 'title' ] )     ? $instance[ 'title' ]     : '';
62
		$button    = isset( $instance[ 'button' ] )    ? $instance[ 'button' ]    : '';
63
		$size      = isset( $instance[ 'size' ] )      ? $instance[ 'size' ]      : 'big';
64
		$style     = isset( $instance[ 'style' ] )     ? $instance[ 'style' ]     : 'filled';
65
		$format    = isset( $instance[ 'format' ] )    ? $instance[ 'format' ]    : 'cover';
66
		$autowidth = isset( $instance[ 'autowidth' ] ) ? $instance[ 'autowidth' ] : true;
67
		$infotext  = isset( $instance[ 'infotext' ] )  ? $instance[ 'infotext' ]  : '';
68
		$color     = isset( $instance[ 'color' ] )     ? $instance[ 'color' ]     : '#75ad91';
69
70
		$buttons = \PodloveSubscribeButton\Model\Button::all();
71
		if ( is_multisite() ) {
72
			$network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all();
73
		}
74
		?>
75
		<p>
76
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'podlove-subscribe-button' ); ?></label>
77
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $title; ?>" />
78
			<label for="<?php echo $this->get_field_id( 'color' ); ?>"><?php _e( 'Color', 'podlove-subscribe-button' ); ?></label>
79
			<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; ?>" />
80
			<style type="text/css">
81
				.sp-replacer {
82
					display: flex;
83
				}
84
				.sp-preview {
85
					flex-grow: 10;
86
				}
87
			</style>
88
			<label for="<?php echo $this->get_field_id( 'button' ); ?>"><?php _e( 'Button', 'podlove-subscribe-button' ); ?></label>
89
            <select class="widefat" id="<?php echo $this->get_field_id( 'button' ); ?>"
90
                    name="<?php echo $this->get_field_name( 'button' ); ?>">
91
				<?php if ( isset( $network_buttons ) && count( $network_buttons ) > 0 ) : ?>
92
                    <optgroup label="<?php _e( 'Local', 'podlove-subscribe-button' ); ?>">
93
						<?php
94
						foreach ( $buttons as $subscribebutton ) {
95
							echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>";
96
						} ?>
0 ignored issues
show
Closing PHP tag must be on a line by itself
Loading history...
97
                    </optgroup>
98
                    <optgroup label="<?php _e( 'Network', 'podlove-subscribe-button' ); ?>">
99
						<?php
100
						foreach ( $network_buttons as $subscribebutton ) {
101
							echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>";
102
						} ?>
103
                    </optgroup>
104
				<?php else :
105
					foreach ( $buttons as $subscribebutton ) {
106
						echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>";
107
					}
108
				endif; ?>
109
            </select>
110
			<?php
111
			$customize_options = array(
112
				'size'      => array(
113
					'name'    => __( 'Size', 'podlove-subscribe-button' ),
114
					'options' => \PodloveSubscribeButton\Model\Button::$size
115
				),
116
				'style'     => array(
117
					'name'    => __( 'Style', 'podlove-subscribe-button' ),
118
					'options' => \PodloveSubscribeButton\Model\Button::$style
119
				),
120
				'format'    => array(
121
					'name'    => __( 'Format', 'podlove-subscribe-button' ),
122
					'options' => \PodloveSubscribeButton\Model\Button::$format
123
				),
124
				'autowidth' => array(
125
					'name'    => __( 'Autowidth', 'podlove-subscribe-button' ),
126
					'options' => \PodloveSubscribeButton\Model\Button::$width
127
				)
128
			);
129
130
			foreach ( $customize_options as $slug => $properties ) : ?>
131
				<label for="<?php echo $this->get_field_id( $slug ); ?>"><?php echo $properties[ 'name' ]; ?></label>
132
				<select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>">
133
					<option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php printf( __( 'Default %s', 'podlove-subscribe-button' ), $properties[ 'name' ] ) ?></option>
134
					<optgroup>
135
						<?php foreach ( $properties[ 'options' ] as $property => $name ) : ?>
136
						<option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php echo $name; ?></option>
137
						<?php endforeach; ?>
138
					</optgroup>
139
				</select>
140
			<?php endforeach; ?>
141
			<label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove-subscribe-button' ); ?></label>
142
			<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>
143
		</p>
144
		<?php
145
146
	}
147
148
	public function update( $new_instance, $old_instance ) {
149
		$instance = array();
150
151
		foreach ( self::$widget_settings as $setting ) {
152
			$instance[ $setting ] = ( ! empty( $new_instance[ $setting ] ) ) ? strip_tags( $new_instance[ $setting ] ) : '';
153
		}
154
155
		return $instance;
156
157
	}
158
159
} // END class
160