Passed
Push — master ( 64cd18...d5badb )
by Christian
04:09 queued 01:39
created
widget.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -10,14 +10,14 @@  discard block
 block discarded – undo
10 10
 		parent::__construct(
11 11
 					'podlove_subscribe_button_wp_plugin_widget',
12 12
 					( self::is_podlove_publisher_active() ? 'Podlove Subscribe Button (WordPress plugin)' : 'Podlove Subscribe Button' ),
13
-					array( 'description' => __( 'Adds a Podlove Subscribe Button to your Sidebar', 'podlove-subscribe-button' ), )
13
+					array( 'description' => __( 'Adds a Podlove Subscribe Button to your Sidebar', 'podlove-subscribe-button' ),)
14 14
 				);
15 15
 	}
16 16
 
17
-	public static $widget_settings = array('infotext', 'title', 'size', 'style', 'format', 'autowidth', 'button', 'color');
17
+	public static $widget_settings = array( 'infotext', 'title', 'size', 'style', 'format', 'autowidth', 'button', 'color' );
18 18
 
19 19
 	public static function is_podlove_publisher_active() {
20
-		if ( is_plugin_active("podlove-podcasting-plugin-for-wordpress/podlove.php") ) {
20
+		if ( is_plugin_active( "podlove-podcasting-plugin-for-wordpress/podlove.php" ) ) {
21 21
 			return true;
22 22
 		}
23 23
 
@@ -26,38 +26,38 @@  discard block
 block discarded – undo
26 26
 
27 27
 	public function widget( $args, $instance ) {
28 28
 		// Fetch the (network)button by it's name
29
-		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($instance['button']) )
30
-			return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] );
29
+		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $instance[ 'button' ] ) )
30
+			return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args[ 'button' ] );
31 31
 
32
-		echo $args['before_widget'];
33
-		echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
32
+		echo $args[ 'before_widget' ];
33
+		echo $args[ 'before_title' ] . apply_filters( 'widget_title', $instance[ 'title' ] ) . $args[ 'after_title' ];
34 34
 
35 35
 		echo $button->render(
36
-				\PodloveSubscribeButton::get_array_value_with_fallback($instance, 'size'),
37
-				\PodloveSubscribeButton::get_array_value_with_fallback($instance, 'autowidth'),
38
-				\PodloveSubscribeButton::get_array_value_with_fallback($instance, 'style'),
39
-				\PodloveSubscribeButton::get_array_value_with_fallback($instance, 'format'), 
40
-				\PodloveSubscribeButton::get_array_value_with_fallback($instance, 'color')
36
+				\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'size' ),
37
+				\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'autowidth' ),
38
+				\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'style' ),
39
+				\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'format' ), 
40
+				\PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'color' )
41 41
 			);
42 42
 		
43
-		if ( strlen($instance['infotext']) )
44
-			echo wpautop($instance['infotext']);
43
+		if ( strlen( $instance[ 'infotext' ] ) )
44
+			echo wpautop( $instance[ 'infotext' ] );
45 45
 
46
-		echo $args['after_widget'];
46
+		echo $args[ 'after_widget' ];
47 47
 	}	
48 48
 
49 49
 	public function form( $instance ) {
50
-		foreach (self::$widget_settings as $setting) {
51
-			$$setting = isset( $instance[$setting] ) ? $instance[$setting] : '';
50
+		foreach ( self::$widget_settings as $setting ) {
51
+			$$setting = isset( $instance[ $setting ] ) ? $instance[ $setting ] : '';
52 52
 		}
53 53
 
54 54
 		$buttons = \PodloveSubscribeButton\Model\Button::all();
55 55
 		if ( is_multisite() )
56 56
 			$network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all();
57 57
 
58
-		$buttons_as_options = function ($buttons) {
59
-			foreach ($buttons as $subscribebutton) {
60
-				echo "<option value='".$subscribebutton->name."' ".( $subscribebutton->name == $button ? 'selected=\"selected\"' : '' )." >".$subscribebutton->title." (".$subscribebutton->name.")</option>";
58
+		$buttons_as_options = function( $buttons ) {
59
+			foreach ( $buttons as $subscribebutton ) {
60
+				echo "<option value='" . $subscribebutton->name . "' " . ( $subscribebutton->name == $button ? 'selected=\"selected\"' : '' ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>";
61 61
 			}
62 62
 		}
63 63
 		?>
@@ -79,15 +79,15 @@  discard block
 block discarded – undo
79 79
 			<label for="<?php echo $this->get_field_id( 'button' ); ?>"><?php _e( 'Button', 'podlove-subscribe-button' ); ?></label> 
80 80
 			<select class="widefat" id="<?php echo $this->get_field_id( 'button' ); ?>"
81 81
 				      name="<?php echo $this->get_field_name( 'button' ); ?>">
82
-				<?php if ( isset($network_buttons) && count($network_buttons) > 0 ) : ?>
83
-					<optgroup label="<?php _e('Local', 'podlove'); ?>">
84
-						<?php $buttons_as_options($buttons); ?>
82
+				<?php if ( isset( $network_buttons ) && count( $network_buttons ) > 0 ) : ?>
83
+					<optgroup label="<?php _e( 'Local', 'podlove' ); ?>">
84
+						<?php $buttons_as_options( $buttons ); ?>
85 85
 					</optgroup>
86
-					<optgroup label="<?php _e('Network', 'podlove'); ?>">
87
-						<?php $buttons_as_options($network_buttons); ?>
86
+					<optgroup label="<?php _e( 'Network', 'podlove' ); ?>">
87
+						<?php $buttons_as_options( $network_buttons ); ?>
88 88
 					</optgroup>
89 89
 				<?php else : 
90
-					$buttons_as_options($buttons);
90
+					$buttons_as_options( $buttons );
91 91
 				 endif; ?>
92 92
 			</select>
93 93
 
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 						)
112 112
 				);
113 113
 
114
-			foreach ($customize_options as $slug => $properties) : ?>
115
-				<label for="<?php echo $this->get_field_id( $slug ); ?>"><?php _e( $properties['name'], 'podlove-subscribe-button' ); ?></label> 
114
+			foreach ( $customize_options as $slug => $properties ) : ?>
115
+				<label for="<?php echo $this->get_field_id( $slug ); ?>"><?php _e( $properties[ 'name' ], 'podlove-subscribe-button' ); ?></label> 
116 116
 				<select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>">
117
-					<option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php _e( 'Default ' . $properties['name'], 'podlove-subscribe-button' ) ?></option>
117
+					<option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php _e( 'Default ' . $properties[ 'name' ], 'podlove-subscribe-button' ) ?></option>
118 118
 					<optgroup>
119
-						<?php foreach ( $properties['options'] as $property => $name ) : ?>
119
+						<?php foreach ( $properties[ 'options' ] as $property => $name ) : ?>
120 120
 						<option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php _e( $name, 'podlove-subscribe-button' ) ?></option>
121 121
 						<?php endforeach; ?>
122 122
 					</optgroup>
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
 	public function update( $new_instance, $old_instance ) {
133 133
 		$instance = array();
134 134
 
135
-		foreach (self::$widget_settings as $setting) {
136
-			$instance[$setting]  = ( ! empty( $new_instance[$setting] ) ) ? strip_tags( $new_instance[$setting] ) : '';
135
+		foreach ( self::$widget_settings as $setting ) {
136
+			$instance[ $setting ] = ( ! empty( $new_instance[ $setting ] ) ) ? strip_tags( $new_instance[ $setting ] ) : '';
137 137
 		}
138 138
 
139 139
 		return $instance;
140 140
 	}
141 141
 }
142
-add_action( 'widgets_init', function(){
142
+add_action( 'widgets_init', function() {
143 143
      register_widget( '\PodloveSubscribeButton\Podlove_Subscribe_Button_Widget' );
144 144
 });
145 145
\ No newline at end of file
Please login to merge, or discard this patch.
podlove.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -14,48 +14,48 @@  discard block
 block discarded – undo
14 14
 $correct_php_version = version_compare( phpversion(), "5.3", ">=" );
15 15
 
16 16
 if ( ! $correct_php_version ) {
17
-	_e("Podlove Subscribe Button Plugin requires <strong>PHP 5.3</strong> or higher.<br>", 'podlove-subscribe-button');
18
-	echo __("You are running PHP ", 'podlove-subscribe-button') . phpversion();
17
+	_e( "Podlove Subscribe Button Plugin requires <strong>PHP 5.3</strong> or higher.<br>", 'podlove-subscribe-button' );
18
+	echo __( "You are running PHP ", 'podlove-subscribe-button' ) . phpversion();
19 19
 	exit;
20 20
 }
21 21
 
22 22
 // Constants
23
-require('constants.php');
24
-require('settings/buttons.php');
23
+require( 'constants.php' );
24
+require( 'settings/buttons.php' );
25 25
 // Models
26
-require('model/base.php');
27
-require('model/button.php');
28
-require('model/network_button.php');
26
+require( 'model/base.php' );
27
+require( 'model/button.php' );
28
+require( 'model/network_button.php' );
29 29
 // Table
30
-require('settings/buttons_list_table.php');
30
+require( 'settings/buttons_list_table.php' );
31 31
 // Media Types
32
-require('media_types.php');
32
+require( 'media_types.php' );
33 33
 // Widget
34
-require('widget.php');
34
+require( 'widget.php' );
35 35
 // Version control
36
-require('version.php');
36
+require( 'version.php' );
37 37
 // Helper functions
38
-require('helper.php');
38
+require( 'helper.php' );
39 39
 
40
-add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu') );
40
+add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu' ) );
41 41
 if ( is_multisite() )
42
-	add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu') );
42
+	add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu' ) );
43 43
 
44 44
 add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) );
45 45
 register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) );
46 46
 
47 47
 // Register Settings
48
-add_action( 'admin_init', function () {
49
-	$settings = array('size', 'autowidth', 'style', 'format', 'color');
48
+add_action( 'admin_init', function() {
49
+	$settings = array( 'size', 'autowidth', 'style', 'format', 'color' );
50 50
 
51
-	foreach ($settings as $setting) {
51
+	foreach ( $settings as $setting ) {
52 52
 		register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting );
53 53
 	}
54 54
 } );
55 55
 
56 56
 add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) );
57 57
 
58
-add_action( 'plugins_loaded', function () {
58
+add_action( 'plugins_loaded', function() {
59 59
 	load_plugin_textdomain( 'podlove-subscribe-button' );
60 60
 } );
61 61
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
 		$pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' );
74 74
 
75
-		if ( ! in_array( $hook, $pages )  ) {
75
+		if ( ! in_array( $hook, $pages ) ) {
76 76
 			return;
77 77
 		}
78 78
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 				'Podlove Subscribe Button',
103 103
 				'manage_options',
104 104
 				'podlove-subscribe-button',
105
-				array( 'PodloveSubscribeButton\Settings\Buttons', 'page')
105
+				array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
106 106
 			);
107 107
 	}
108 108
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 				'Podlove Subscribe Button',
114 114
 				'manage_options',
115 115
 				'podlove-subscribe-button',
116
-				array( 'PodloveSubscribeButton\Settings\Buttons', 'page')
116
+				array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
117 117
 			);
118 118
 	}
119 119
 
@@ -132,56 +132,56 @@  discard block
 block discarded – undo
132 132
 				'format' => 'rectangle'
133 133
 			);
134 134
 
135
-		foreach ($default_values as $option => $default_value) {
136
-			if ( ! get_option('podlove_subscribe_button_default_' . $option ) ) {
137
-				update_option('podlove_subscribe_button_default_' . $option, $default_value);
135
+		foreach ( $default_values as $option => $default_value ) {
136
+			if ( ! get_option( 'podlove_subscribe_button_default_' . $option ) ) {
137
+				update_option( 'podlove_subscribe_button_default_' . $option, $default_value );
138 138
 			}
139 139
 		}
140 140
 	}
141 141
 
142 142
 	public static function shortcode( $args ) {
143
-		if ( ! $args || ! isset($args['button']) ) {
144
-			return __('You need to create a Button first and provide its ID.', 'podlove-subscribe-button');
143
+		if ( ! $args || ! isset( $args[ 'button' ] ) ) {
144
+			return __( 'You need to create a Button first and provide its ID.', 'podlove-subscribe-button' );
145 145
 		} else {
146
-			$buttonid = $args['button'];
146
+			$buttonid = $args[ 'button' ];
147 147
 		}
148 148
 
149 149
 		// Fetch the (network)button by it's name
150
-		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) )
151
-			return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] );
150
+		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $args[ 'button' ] ) )
151
+			return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args[ 'button' ] );
152 152
 
153 153
 		// Get button styling and options
154
-		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback($args, 'width') );
155
-		$size = self::get_attribute( 'size', self::get_array_value_with_fallback($args, 'size') );
156
-		$style = self::get_attribute( 'style', self::get_array_value_with_fallback($args, 'style') );
157
-		$format = self::get_attribute( 'format', self::get_array_value_with_fallback($args, 'format') );
158
-		$color = self::get_attribute( 'color', self::get_array_value_with_fallback($args, 'color') );
159
-
160
-		if ( isset($args['language']) ) {
161
-			$language = $args['language'];
154
+		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback( $args, 'width' ) );
155
+		$size = self::get_attribute( 'size', self::get_array_value_with_fallback( $args, 'size' ) );
156
+		$style = self::get_attribute( 'style', self::get_array_value_with_fallback( $args, 'style' ) );
157
+		$format = self::get_attribute( 'format', self::get_array_value_with_fallback( $args, 'format' ) );
158
+		$color = self::get_attribute( 'color', self::get_array_value_with_fallback( $args, 'color' ) );
159
+
160
+		if ( isset( $args[ 'language' ] ) ) {
161
+			$language = $args[ 'language' ];
162 162
 		} else {
163 163
 			$language = 'en';
164 164
 		}
165 165
 
166
-		if ( isset($args['color']) ) {
167
-			$color = $args['color'];
166
+		if ( isset( $args[ 'color' ] ) ) {
167
+			$color = $args[ 'color' ];
168 168
 		} else {
169
-			$color = get_option('podlove_subscribe_button_default_color', '#599677');
169
+			$color = get_option( 'podlove_subscribe_button_default_color', '#599677' );
170 170
 		}
171 171
 
172
-		if ( isset($args['hide']) && $args['hide'] == 'true' ) {
172
+		if ( isset( $args[ 'hide' ] ) && $args[ 'hide' ] == 'true' ) {
173 173
 			$hide = TRUE;
174 174
 		} else {
175 175
 			$hide = FALSE;
176 176
 		}
177 177
 
178 178
 		// Render button
179
-		return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid, $language);
179
+		return $button->render( $size, $autowidth, $style, $format, $color, $hide, $buttonid, $language );
180 180
 	}
181 181
 
182
-	public static function get_array_value_with_fallback($args, $key) {
183
-		if ( isset($args[$key]) )
184
-			return $args[$key];
182
+	public static function get_array_value_with_fallback( $args, $key ) {
183
+		if ( isset( $args[ $key ] ) )
184
+			return $args[ $key ];
185 185
 
186 186
 		return FALSE;
187 187
 	}
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
 	 * @param  string $attribute_value
192 192
 	 * @return string
193 193
 	 */
194
-	private static function get_attribute($attribute=NULL, $attribute_value=NULL) {
195
-		if ( isset($attribute_value) && ctype_alnum($attribute_value) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
194
+	private static function get_attribute( $attribute = NULL, $attribute_value = NULL ) {
195
+		if ( isset( $attribute_value ) && ctype_alnum( $attribute_value ) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
196 196
 			return $attribute_value;
197 197
 		} else {
198
-			return get_option('podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[$attribute]);
198
+			return get_option( 'podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[ $attribute ] );
199 199
 		}
200 200
 	}
201 201
 
@@ -210,6 +210,6 @@  discard block
 block discarded – undo
210 210
 		if ( $width_attribute && $width_attribute !== 'auto' )
211 211
 			return 'off';
212 212
 
213
-		return get_option('podlove_subscribe_button_default_autowidth', 'on');
213
+		return get_option( 'podlove_subscribe_button_default_autowidth', 'on' );
214 214
 	}
215 215
 }
216 216
\ No newline at end of file
Please login to merge, or discard this patch.