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.
Completed
Push — master ( 261fa3...d5dc42 )
by Christian
12s queued 10s
created

PodloveSubscribeButton::admin_inline_js()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
0 ignored issues
show
introduced by
Class file names should be based on the class name with "class-" prepended. Expected class-podlovesubscribebutton.php, but found podlove.php.
Loading history...
2
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
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
 * @version   1.4.0-beta
8
 */
9
10
/**
11
 * Plugin Name: Podlove Subscribe Button
12
 * Plugin URI:  https://wordpress.org/plugins/podlove-subscribe-button/
13
 * Description: Brings the Podlove Subscribe Button to your WordPress installation.
14
 * Version:     1.4.0-beta
15
 * Author:      Podlove
16
 * Author URI:  https://podlove.org/
17
 * License:     MIT
18
 * License URI: license.txt
19
 * Text Domain: podlove-subscribe-button
20
 */
21
22
/** Check if PHP version is sufficient */
23
if ( ! version_compare( phpversion(), '5.4', ">=" ) ) {
0 ignored issues
show
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...
24
25
	function podlove_psb_php_notice() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function podlove_psb_php_notice()
Loading history...
26
		?>
27
        <div id="message" class="error">
28
            <p>
29
                <strong>The Podlove Subscribe Button Plugin could not be activated</strong>
30
            </p>
31
            <p>
32
                The Podlove Subscribe Button Plugin requires <code>PHP 5.3</code> or higher.<br>
33
                You are running <code>PHP <?php echo phpversion(); ?></code>.<br>
0 ignored issues
show
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'phpversion'.
Loading history...
34
                Please ask your hoster how to upgrade to an up-to-date PHP version.
35
            </p>
36
        </div>
37
		<?php
38
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
39
40
	function podlove_psb_deactivate() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function podlove_psb_deactivate()
Loading history...
41
		deactivate_plugins( plugin_basename( __FILE__ ) );
42
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
43
44
	add_action( 'admin_notices', 'podlove_psb_php_notice' );
45
	add_action( 'admin_init', 'podlove_psb_deactivate' );
46
47
	return;
48
49
}
50
51
require_once __DIR__ . '/vendor/autoload.php';
52
53
register_activation_hook( __FILE__, array( 'PodloveSubscribeButton\Setup', 'activation' ) );
54
register_uninstall_hook( __FILE__, array( 'PodloveSubscribeButton\Setup', 'uninstall' ) );
55
56
PodloveSubscribeButton\Migration::eval_db();
57
PodloveSubscribeButton::run();
58
59
/**
60
 * Class PodloveSubscribeButton
61
 */
62
class PodloveSubscribeButton {
63
64
	/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
65
	 * @var string current plugin version
66
	 */
67
	public static $version = '1.4.0-beta';
68
69
	public static function run() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function run()
Loading history...
70
71
		add_action( 'plugins_loaded', array( __CLASS__, 'load_translations' ) );
72
		add_action( 'init', array( __CLASS__, 'register_shortcode' ) );
73
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Options', 'register_settings' ) );
74
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) );
75
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
76
		add_action( 'widgets_init', array( __CLASS__, 'widgets' ) );
77
		add_action( 'network_admin_edit_podlove_psb_update_network_options', array( 'PodloveSubscribeButton\Settings\Buttons', 'podlove_psb_update_network_options' ) );
78
79
		if ( is_multisite() ) {
80
			add_filter( 'podlove_psb_defaults_options', array( __CLASS__, 'get_network_defaults' ) );
81
		}
82
83
		self::menu();
84
85
	}
86
87
	public static function get_network_defaults( $options ) {
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
	public static function get_network_defaults( /** @scrutinizer ignore-unused */ $options ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "PodloveSubscribeButton::get_network_defaults" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function get_network_defaults()
Loading history...
88
		$network_defaults = get_site_option( 'podlove_psb_defaults' );
89
90
		return $network_defaults;
91
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
92
93
	public static function widgets() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function widgets()
Loading history...
94
		register_widget( '\PodloveSubscribeButton\Widget' );
95
96
	}
97
98
	public static function menu() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function menu()
Loading history...
99
		add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu' ) );
100
101
		if ( is_network_admin() ) {
102
			add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu' ) );
103
		}
104
105
	}
106
107
	public static function enqueue_assets( $hook ) {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::enqueue_assets" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function enqueue_assets()
Loading history...
108
109
		$pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' );
110
111
		if ( ! in_array( $hook, $pages ) ) {
0 ignored issues
show
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
112
			return;
113
		}
114
115
		add_action( 'admin_print_footer_scripts', array( __CLASS__, 'admin_inline_js' ) );
116
117
		$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
118
119
		// CSS Stylesheet
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
120
		wp_register_style( 'podlove-subscribe-button', \PodloveSubscribeButton\Helpers::get_url( '' ) . 'css/style.css', false, self::$version );
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type array expected by parameter $deps of wp_register_style(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

120
		wp_register_style( 'podlove-subscribe-button', \PodloveSubscribeButton\Helpers::get_url( '' ) . 'css/style.css', /** @scrutinizer ignore-type */ false, self::$version );
Loading history...
121
		wp_enqueue_style( 'podlove-subscribe-button' );
122
123
		// Clipboard.js
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
124
		wp_register_script( 'clipboard.js', \PodloveSubscribeButton\Helpers::get_url( '' ) . "js/clipboard{$suffix}.js", array(), '2.0.1' );
0 ignored issues
show
introduced by
In footer ($in_footer) is not set explicitly wp_register_script; It is recommended to load scripts in the footer. Please set this value to true to load it in the footer, or explicitly false if it should be loaded in the header.
Loading history...
125
		wp_enqueue_script( 'clipboard.js' );
126
127
		// Admin JS
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
128
		wp_enqueue_style( 'wp-color-picker' );
129
		wp_register_script( 'podlove-subscribe-button-admin-tools', \PodloveSubscribeButton\Helpers::get_url( '' ) . 'js/admin.js', array( 'jquery', 'wp-color-picker' ), self::$version );
0 ignored issues
show
introduced by
In footer ($in_footer) is not set explicitly wp_register_script; It is recommended to load scripts in the footer. Please set this value to true to load it in the footer, or explicitly false if it should be loaded in the header.
Loading history...
130
		$js_translations = array(
131
			'media_library' => __( 'Media Library', 'podlove-subscribe-button' ),
132
			'use_for'       => __( 'Use for Podcast Cover Art', 'podlove-subscribe-button' ),
133
		);
134
		wp_localize_script( 'podlove-subscribe-button-admin-tools', 'i18n', $js_translations );
135
		wp_enqueue_script( 'podlove-subscribe-button-admin-tools' );
136
137
	}
138
139
	public static function admin_inline_js() {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::admin_inline_js" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function admin_inline_js()
Loading history...
140
	    echo "<script type=\"text/javascript\">var clipboard = new ClipboardJS('.copy-btn');</script>";
141
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
142
143
	public static function admin_menu() {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::admin_menu" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function admin_menu()
Loading history...
144
		add_options_page(
145
			__( 'Podlove Subscribe Button Options', 'podlove-subscribe-button' ),
146
			__( 'Podlove Subscribe Button', 'podlove-subscribe-button' ),
147
			'manage_options',
148
			'podlove-subscribe-button',
149
			array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
150
		);
151
152
	}
153
154
	public static function admin_network_menu() {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::admin_network_menu" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function admin_network_menu()
Loading history...
155
		add_submenu_page(
156
			'settings.php',
157
			__( 'Podlove Subscribe Button Options', 'podlove-subscribe-button' ),
158
			__( 'Podlove Subscribe Button', 'podlove-subscribe-button' ),
159
			'manage_options',
160
			'podlove-subscribe-button',
161
			array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
162
		);
163
164
	}
165
166
	public static function load_translations() {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::load_translations" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function load_translations()
Loading history...
167
		load_plugin_textdomain( 'podlove-subscribe-button' );
168
169
	}
170
171
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$key" missing
Loading history...
172
	 * Get value from the associative array of the plugin defaults option
173
	 *
174
	 * @param $key
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
175
	 * @param bool $default
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
176
	 *
177
	 * @return string|bool
178
	 */
179
	public static function get_option( $key, $default = false ) {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::get_option" is not in camel caps format
Loading history...
180
181
		$options = \get_option( 'podlove_psb_defaults' );
182
183
		if ( array_key_exists( $key, $options ) ) {
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type false; however, parameter $search of array_key_exists() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

183
		if ( array_key_exists( $key, /** @scrutinizer ignore-type */ $options ) ) {
Loading history...
184
			return $options[ $key ];
185
		}
186
187
		return $default;
188
	} // END get_option()
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
189
190
	public static function register_shortcode() {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::register_shortcode" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function register_shortcode()
Loading history...
191
		add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) );
192
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
193
194
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$args" missing
Loading history...
195
	 * Add the shortcode
196
	 *
197
	 * @param $args
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
198
	 *
199
	 * @return string|void
200
	 */
201
	public static function shortcode( $args ) {
202
		if ( ! $args || ! isset( $args['button'] ) ) {
203
			return __( 'You need to create a Button first and provide its ID.', 'podlove-subscribe-button' );
204
		} else {
205
			$buttonid = $args['button'];
206
		}
207
208
		// Fetch the (network)button by it's name
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
209
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $args['button'] ) ) {
0 ignored issues
show
introduced by
Variable assignment found within a condition. Did you mean to do a comparison?
Loading history...
Coding Style introduced by
Assignments must be the first block of code on a line
Loading history...
210
			return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args['button'] );
0 ignored issues
show
introduced by
A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
Loading history...
211
		}
212
213
		// Get button styling and options
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
214
		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback( $args, 'width' ) );
0 ignored issues
show
Bug introduced by
It seems like self::get_array_value_wi...allback($args, 'width') can also be of type false; however, parameter $width_attribute of PodloveSubscribeButton::...rpret_width_attribute() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

214
		$autowidth = self::interpret_width_attribute( /** @scrutinizer ignore-type */ self::get_array_value_with_fallback( $args, 'width' ) );
Loading history...
215
		$size      = self::get_attribute( 'size', self::get_array_value_with_fallback( $args, 'size' ) );
0 ignored issues
show
Bug introduced by
It seems like self::get_array_value_wi...fallback($args, 'size') can also be of type false; however, parameter $attribute_value of PodloveSubscribeButton::get_attribute() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

215
		$size      = self::get_attribute( 'size', /** @scrutinizer ignore-type */ self::get_array_value_with_fallback( $args, 'size' ) );
Loading history...
216
		$style     = self::get_attribute( 'style', self::get_array_value_with_fallback( $args, 'style' ) );
217
		$format    = self::get_attribute( 'format', self::get_array_value_with_fallback( $args, 'format' ) );
218
219
		if ( isset( $args['language'] ) ) {
220
			$language = $args['language'];
221
		} else {
222
			$language = self::get_attribute( 'language', self::get_array_value_with_fallback( $args, 'language' ) );
223
		}
224
225
		if ( isset( $args['color'] ) ) {
226
			$color = $args['color'];
227
		} else {
228
			$color = self::get_attribute( 'color', self::get_array_value_with_fallback( $args, 'color' ) );
229
		}
230
231
		if ( isset( $args['hide'] ) && $args['hide'] == 'true' ) {
0 ignored issues
show
introduced by
Found: ==. Use strict comparisons (=== or !==).
Loading history...
introduced by
Use Yoda Condition checks, you must.
Loading history...
232
			$hide = true;
233
		} else {
234
			$hide = false;
235
		}
236
237
		// Render button
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
238
		return $button->render( $size, $autowidth, $style, $format, $color, $hide, $buttonid, $language );
239
240
	}
241
242
	public static function get_array_value_with_fallback( $args, $key ) {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::get_array_value_with_fallback" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function get_array_value_with_fallback()
Loading history...
243
		if ( isset( $args[ $key ] ) ) {
244
			return $args[ $key ];
245
		}
246
247
		return false;
248
249
	}
250
251
	/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
252
	 * @param  string $attribute
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
253
	 * @param  string $attribute_value
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
254
	 *
255
	 * @return string
256
	 */
257
	private static function get_attribute( $attribute = null, $attribute_value = null ) {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::get_attribute" is not in camel caps format
Loading history...
258
		if ( isset( $attribute_value ) && ctype_alnum( $attribute_value ) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
259
			return $attribute_value;
260
		} else {
261
			$default = get_option( 'podlove_psb_defaults', \PodloveSubscribeButton\Defaults::options() );
262
263
			return $default[ $attribute ];
264
		}
265
266
	}
267
268
	/**
269
	 * Interprets the provided width attribute and return either auto- or a specific width
270
	 *
271
	 * @param  string $width_attribute
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
272
	 *
273
	 * @return string
274
	 */
275
	private static function interpret_width_attribute( $width_attribute = null ) {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::interpret_width_attribute" is not in camel caps format
Loading history...
276
		if ( $width_attribute == 'auto' ) {
0 ignored issues
show
introduced by
Found: ==. Use strict comparisons (=== or !==).
Loading history...
introduced by
Use Yoda Condition checks, you must.
Loading history...
277
			return 'on';
278
		}
279
280
		if ( $width_attribute && $width_attribute !== 'auto' ) {
0 ignored issues
show
introduced by
Use Yoda Condition checks, you must.
Loading history...
281
			return 'off';
282
		}
283
284
		return self::get_option( 'autowidth', 'on' );
0 ignored issues
show
Bug introduced by
'on' of type string is incompatible with the type boolean expected by parameter $default of PodloveSubscribeButton::get_option(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

284
		return self::get_option( 'autowidth', /** @scrutinizer ignore-type */ 'on' );
Loading history...
285
286
	}
287
288
	public static function plugin_file() {
0 ignored issues
show
Coding Style introduced by
Method name "PodloveSubscribeButton::plugin_file" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function plugin_file()
Loading history...
289
		return __FILE__;
290
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
291
292
} // END class
293