These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
2 | /** |
||
3 | * Plugin Name: Podlove Subscribe Button |
||
4 | * Plugin URI: http://wordpress.org/extend/plugins/podlove-subscribe-button/ |
||
5 | * Description: Brings the Podlove Subscribe Button to your WordPress installation. |
||
6 | * Version: 1.3.3 |
||
7 | * Author: Podlove |
||
8 | * Author URI: http://podlove.org |
||
9 | * License: MIT |
||
10 | * License URI: license.txt |
||
11 | * Text Domain: podlove-subscribe-button |
||
12 | */ |
||
13 | |||
14 | $correct_php_version = version_compare( phpversion(), "5.3", ">=" ); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
5.3 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 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 ( 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: 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. ![]() |
|||
15 | |||
16 | if ( ! $correct_php_version ) { |
||
17 | _e("Podlove Subscribe Button Plugin requires <strong>PHP 5.3</strong> or higher.<br>", 'podlove-subscribe-button'); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Podlove Subscribe Button.../strong> or higher.<br> 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 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 ( 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: 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. ![]() |
|||
18 | echo __("You are running PHP ", 'podlove-subscribe-button') . phpversion(); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
You are running PHP 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 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 ( 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: 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. ![]() |
|||
19 | exit; |
||
20 | } |
||
21 | |||
22 | // Constants |
||
23 | require('constants.php'); |
||
0 ignored issues
–
show
|
|||
24 | require('settings/buttons.php'); |
||
0 ignored issues
–
show
|
|||
25 | // Models |
||
26 | require('model/base.php'); |
||
0 ignored issues
–
show
|
|||
27 | require('model/button.php'); |
||
0 ignored issues
–
show
|
|||
28 | require('model/network_button.php'); |
||
0 ignored issues
–
show
|
|||
29 | // Table |
||
30 | require('settings/buttons_list_table.php'); |
||
0 ignored issues
–
show
|
|||
31 | // Media Types |
||
32 | require('media_types.php'); |
||
0 ignored issues
–
show
|
|||
33 | // Widget |
||
34 | require('widget.php'); |
||
0 ignored issues
–
show
|
|||
35 | // Version control |
||
36 | require('version.php'); |
||
0 ignored issues
–
show
|
|||
37 | // Helper functions |
||
38 | require('helper.php'); |
||
0 ignored issues
–
show
|
|||
39 | |||
40 | add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu') ); |
||
0 ignored issues
–
show
|
|||
41 | if ( is_multisite() ) |
||
0 ignored issues
–
show
|
|||
42 | add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu') ); |
||
0 ignored issues
–
show
|
|||
43 | |||
44 | add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) ); |
||
45 | register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) ); |
||
46 | |||
47 | add_action( 'admin_enqueue_scripts', function () { |
||
48 | wp_register_style( 'podlove-subscribe-button', plugin_dir_url(__FILE__).'style.css' ); |
||
0 ignored issues
–
show
|
|||
49 | wp_enqueue_style( 'podlove-subscribe-button' ); |
||
50 | |||
51 | wp_enqueue_style('podlove-subscribe-button-spectrum', plugin_dir_url(__FILE__). 'js/spectrum/spectrum.css'); |
||
0 ignored issues
–
show
|
|||
52 | wp_enqueue_script('podlove-subscribe-button-spectrum', plugin_dir_url(__FILE__). 'js/spectrum/spectrum.js', array('jquery')); |
||
0 ignored issues
–
show
|
|||
53 | wp_enqueue_script('podlove-subscribe-button-admin-tools', plugin_dir_url(__FILE__). 'js/admin.js', array('jquery')); |
||
0 ignored issues
–
show
|
|||
54 | } ); |
||
55 | |||
56 | // Register Settings |
||
57 | add_action( 'admin_init', function () { |
||
58 | $settings = array('size', 'autowidth', 'style', 'format', 'color'); |
||
0 ignored issues
–
show
|
|||
59 | |||
60 | foreach ($settings as $setting) { |
||
0 ignored issues
–
show
|
|||
61 | register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting ); |
||
62 | } |
||
63 | } ); |
||
64 | |||
65 | add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) ); |
||
66 | |||
67 | add_action( 'plugins_loaded', function () { |
||
68 | load_plugin_textdomain( 'podlove-subscribe-button' ); |
||
69 | } ); |
||
70 | |||
71 | |||
72 | class PodloveSubscribeButton { |
||
73 | |||
74 | public static function admin_menu() { |
||
75 | add_options_page( |
||
76 | 'Podlove Subscribe Button Options', |
||
0 ignored issues
–
show
|
|||
77 | 'Podlove Subscribe Button', |
||
0 ignored issues
–
show
|
|||
78 | 'manage_options', |
||
0 ignored issues
–
show
|
|||
79 | 'podlove-subscribe-button', |
||
0 ignored issues
–
show
|
|||
80 | array( 'PodloveSubscribeButton\Settings\Buttons', 'page') |
||
0 ignored issues
–
show
|
|||
81 | ); |
||
0 ignored issues
–
show
|
|||
82 | } |
||
83 | |||
84 | public static function admin_network_menu() { |
||
85 | add_submenu_page( |
||
86 | 'settings.php', |
||
0 ignored issues
–
show
|
|||
87 | 'Podlove Subscribe Button Options', |
||
0 ignored issues
–
show
|
|||
88 | 'Podlove Subscribe Button', |
||
0 ignored issues
–
show
|
|||
89 | 'manage_options', |
||
0 ignored issues
–
show
|
|||
90 | 'podlove-subscribe-button', |
||
0 ignored issues
–
show
|
|||
91 | array( 'PodloveSubscribeButton\Settings\Buttons', 'page') |
||
0 ignored issues
–
show
|
|||
92 | ); |
||
0 ignored issues
–
show
|
|||
93 | } |
||
94 | |||
95 | public static function build_models() { |
||
96 | // Build Databases |
||
97 | \PodloveSubscribeButton\Model\Button::build(); |
||
98 | if ( is_multisite() ) |
||
0 ignored issues
–
show
|
|||
99 | \PodloveSubscribeButton\Model\NetworkButton::build(); |
||
100 | |||
101 | // Set Button "default" values |
||
102 | $default_values = array( |
||
103 | 'size' => 'big', |
||
0 ignored issues
–
show
|
|||
104 | 'autowidth' => 'on', |
||
0 ignored issues
–
show
|
|||
105 | 'color' => '#599677', |
||
0 ignored issues
–
show
|
|||
106 | 'style' => 'filled', |
||
0 ignored issues
–
show
|
|||
107 | 'format' => 'rectangle' |
||
0 ignored issues
–
show
|
|||
108 | ); |
||
0 ignored issues
–
show
|
|||
109 | |||
110 | foreach ($default_values as $option => $default_value) { |
||
0 ignored issues
–
show
|
|||
111 | if ( ! get_option('podlove_subscribe_button_default_' . $option ) ) { |
||
0 ignored issues
–
show
|
|||
112 | update_option('podlove_subscribe_button_default_' . $option, $default_value); |
||
0 ignored issues
–
show
|
|||
113 | } |
||
114 | } |
||
115 | } |
||
116 | |||
117 | public static function shortcode( $args ) { |
||
118 | if ( ! $args || ! isset($args['button']) ) { |
||
0 ignored issues
–
show
|
|||
119 | return __('You need to create a Button first and provide its ID.', 'podlove-subscribe-button'); |
||
0 ignored issues
–
show
|
|||
120 | } else { |
||
121 | $buttonid = $args['button']; |
||
122 | } |
||
123 | |||
124 | // Fetch the (network)button by it's name |
||
125 | View Code Duplication | if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) ) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
126 | return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] ); |
||
0 ignored issues
–
show
|
|||
127 | |||
128 | // Get button styling and options |
||
129 | $autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback($args, 'width') ); |
||
0 ignored issues
–
show
|
|||
130 | $size = self::get_attribute( 'size', self::get_array_value_with_fallback($args, 'size') ); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
131 | $style = self::get_attribute( 'style', self::get_array_value_with_fallback($args, 'style') ); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
132 | $format = self::get_attribute( 'format', self::get_array_value_with_fallback($args, 'format') ); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
133 | $color = self::get_attribute( 'color', self::get_array_value_with_fallback($args, 'color') ); |
||
0 ignored issues
–
show
$color is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
134 | |||
135 | if ( isset($args['language']) ) { |
||
0 ignored issues
–
show
|
|||
136 | $language = $args['language']; |
||
137 | } else { |
||
138 | $language = 'en'; |
||
139 | } |
||
140 | |||
141 | if ( isset($args['color']) ) { |
||
0 ignored issues
–
show
|
|||
142 | $color = $args['color']; |
||
143 | } else { |
||
144 | $color = get_option('podlove_subscribe_button_default_color', '#599677'); |
||
0 ignored issues
–
show
|
|||
145 | } |
||
146 | |||
147 | if ( isset($args['hide']) && $args['hide'] == 'true' ) { |
||
0 ignored issues
–
show
|
|||
148 | $hide = TRUE; |
||
0 ignored issues
–
show
|
|||
149 | } else { |
||
150 | $hide = FALSE; |
||
0 ignored issues
–
show
|
|||
151 | } |
||
152 | |||
153 | // Render button |
||
154 | return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid, $language); |
||
0 ignored issues
–
show
|
|||
155 | } |
||
156 | |||
157 | public static function get_array_value_with_fallback($args, $key) { |
||
0 ignored issues
–
show
|
|||
158 | if ( isset($args[$key]) ) |
||
0 ignored issues
–
show
|
|||
159 | return $args[$key]; |
||
0 ignored issues
–
show
|
|||
160 | |||
161 | return FALSE; |
||
0 ignored issues
–
show
|
|||
162 | } |
||
163 | |||
164 | /** |
||
165 | * @param string $attribute |
||
166 | * @param string $attribute_value |
||
167 | * @return string |
||
168 | */ |
||
169 | private static function get_attribute($attribute=NULL, $attribute_value=NULL) { |
||
0 ignored issues
–
show
|
|||
170 | if ( isset($attribute_value) && ctype_alnum($attribute_value) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) { |
||
0 ignored issues
–
show
|
|||
171 | return $attribute_value; |
||
172 | } else { |
||
173 | return get_option('podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[$attribute]); |
||
0 ignored issues
–
show
|
|||
174 | } |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Interprets the provided width attribute and return either auto- or a specific width |
||
179 | * @param string $width_attribute |
||
180 | * @return string |
||
181 | */ |
||
182 | private static function interpret_width_attribute( $width_attribute = NULL ) { |
||
0 ignored issues
–
show
|
|||
183 | if ( $width_attribute == 'auto' ) |
||
0 ignored issues
–
show
|
|||
184 | return 'on'; |
||
185 | if ( $width_attribute && $width_attribute !== 'auto' ) |
||
0 ignored issues
–
show
The expression
$width_attribute of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
186 | return 'off'; |
||
187 | |||
188 | return get_option('podlove_subscribe_button_default_autowidth', 'on'); |
||
0 ignored issues
–
show
|
|||
189 | } |
||
190 | } |