1 | <?php |
||||
2 | /** |
||||
3 | * Plugin Name: Podlove Subscribe Button |
||||
4 | * Plugin URI: https://wordpress.org/plugins/podlove-subscribe-button/ |
||||
5 | * Description: Brings the Podlove Subscribe Button to your WordPress installation. |
||||
6 | * Version: 1.4.0-beta |
||||
7 | * Author: Podlove |
||||
8 | * Author URI: https://podlove.org/ |
||||
9 | * License: MIT |
||||
10 | * License URI: license.txt |
||||
11 | * Text Domain: podlove-subscribe-button |
||||
12 | * Domain Path: /languages |
||||
13 | */ |
||||
14 | |||||
15 | $correct_php_version = version_compare( phpversion(), "5.3", ">=" ); |
||||
16 | |||||
17 | if ( ! $correct_php_version ) { |
||||
18 | printf( __( 'Podlove Subscribe Button Plugin requires %s or higher.<br>', 'podlove-subscribe-button' ), '<code>PHP 5.3</code>' ); |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
19 | echo '<br />'; |
||||
20 | printf( __( 'You are running %s', 'podlove-subscribe-button' ), '<code>PHP ' . phpversion() . '</code>' ); |
||||
0 ignored issues
–
show
|
|||||
21 | exit; |
||||
22 | } |
||||
23 | |||||
24 | // Constants |
||||
0 ignored issues
–
show
|
|||||
25 | require('constants.php'); |
||||
0 ignored issues
–
show
|
|||||
26 | require('settings/buttons.php'); |
||||
0 ignored issues
–
show
|
|||||
27 | // Models |
||||
0 ignored issues
–
show
|
|||||
28 | require('model/base.php'); |
||||
0 ignored issues
–
show
|
|||||
29 | require('model/button.php'); |
||||
0 ignored issues
–
show
|
|||||
30 | require('model/network_button.php'); |
||||
0 ignored issues
–
show
|
|||||
31 | // Table |
||||
0 ignored issues
–
show
|
|||||
32 | require('settings/buttons_list_table.php'); |
||||
0 ignored issues
–
show
|
|||||
33 | // Media Types |
||||
0 ignored issues
–
show
|
|||||
34 | require('media_types.php'); |
||||
0 ignored issues
–
show
|
|||||
35 | // Widget |
||||
0 ignored issues
–
show
|
|||||
36 | require('widget.php'); |
||||
0 ignored issues
–
show
|
|||||
37 | // Version control |
||||
0 ignored issues
–
show
|
|||||
38 | require('version.php'); |
||||
0 ignored issues
–
show
|
|||||
39 | // Helper functions |
||||
0 ignored issues
–
show
|
|||||
40 | require('helper.php'); |
||||
0 ignored issues
–
show
|
|||||
41 | |||||
42 | register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) ); |
||||
43 | |||||
44 | PodloveSubscribeButton::run(); |
||||
45 | |||||
46 | /** |
||||
47 | * Class PodloveSubscribeButton |
||||
48 | */ |
||||
49 | class PodloveSubscribeButton { |
||||
50 | |||||
51 | /** |
||||
0 ignored issues
–
show
|
|||||
52 | * @var string current plugin version |
||||
53 | */ |
||||
54 | public static $version = '1.4.0-beta'; |
||||
55 | |||||
56 | public static function run() { |
||||
0 ignored issues
–
show
|
|||||
57 | add_action( 'plugins_loaded', array( __CLASS__, 'load_translations' ) ); |
||||
58 | add_action( 'init', array( __CLASS__, 'register_shortcode' ) ); |
||||
59 | add_action( 'admin_init', array( __CLASS__, 'register_settings' ) ); |
||||
60 | add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) ); |
||||
61 | self::menu(); |
||||
62 | |||||
63 | } |
||||
64 | |||||
65 | public static function menu() { |
||||
0 ignored issues
–
show
|
|||||
66 | add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu' ) ); |
||||
67 | |||||
68 | if ( is_network_admin() ) { |
||||
69 | add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu' ) ); |
||||
70 | } |
||||
71 | |||||
72 | } |
||||
73 | |||||
74 | public static function enqueue_assets( $hook ) { |
||||
0 ignored issues
–
show
|
|||||
75 | |||||
76 | $pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' ); |
||||
77 | |||||
78 | if ( ! in_array( $hook, $pages ) ) { |
||||
0 ignored issues
–
show
|
|||||
79 | return; |
||||
80 | } |
||||
81 | |||||
82 | // CSS Stylesheet |
||||
0 ignored issues
–
show
|
|||||
83 | wp_register_style( 'podlove-subscribe-button', plugin_dir_url( __FILE__ ) . 'style.css', false, self::$version ); |
||||
0 ignored issues
–
show
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
![]() |
|||||
84 | wp_enqueue_style( 'podlove-subscribe-button' ); |
||||
85 | |||||
86 | // Spectrum JS |
||||
0 ignored issues
–
show
|
|||||
87 | wp_enqueue_style( 'podlove-subscribe-button-spectrum', plugin_dir_url( __FILE__ ) . 'js/spectrum/spectrum.css', array(), '1.8.0' ); |
||||
88 | wp_enqueue_script( 'podlove-subscribe-button-spectrum', plugin_dir_url( __FILE__ ) . 'js/spectrum/spectrum.js', array( 'jquery' ), '1.8.0' ); |
||||
0 ignored issues
–
show
|
|||||
89 | |||||
90 | // Admin JS |
||||
0 ignored issues
–
show
|
|||||
91 | wp_register_script( 'podlove-subscribe-button-admin-tools', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ), self::$version ); |
||||
0 ignored issues
–
show
|
|||||
92 | $js_translations = array( |
||||
93 | 'select_color' => __( 'Select Color', 'podlove-subscribe-button' ), |
||||
94 | 'cancel' => __( 'Cancel', 'podlove-subscribe-button' ), |
||||
95 | 'media_library' => __( 'Media Library', 'podlove-subscribe-button' ), |
||||
96 | 'use_for' => __( 'Use for Podcast Cover Art', 'podlove-subscribe-button' ), |
||||
97 | ); |
||||
98 | wp_localize_script( 'podlove-subscribe-button-admin-tools', 'i18n', $js_translations ); |
||||
99 | wp_enqueue_script( 'podlove-subscribe-button-admin-tools' ); |
||||
100 | |||||
101 | } |
||||
102 | |||||
103 | public static function admin_menu() { |
||||
0 ignored issues
–
show
|
|||||
104 | add_options_page( |
||||
105 | 'Podlove Subscribe Button Options', |
||||
106 | 'Podlove Subscribe Button', |
||||
107 | 'manage_options', |
||||
108 | 'podlove-subscribe-button', |
||||
109 | array( 'PodloveSubscribeButton\Settings\Buttons', 'page' ) |
||||
110 | ); |
||||
111 | |||||
112 | } |
||||
113 | |||||
114 | public static function admin_network_menu() { |
||||
0 ignored issues
–
show
|
|||||
115 | add_submenu_page( |
||||
116 | 'settings.php', |
||||
117 | 'Podlove Subscribe Button Options', |
||||
118 | 'Podlove Subscribe Button', |
||||
119 | 'manage_options', |
||||
120 | 'podlove-subscribe-button', |
||||
121 | array( 'PodloveSubscribeButton\Settings\Buttons', 'page' ) |
||||
122 | ); |
||||
123 | |||||
124 | } |
||||
125 | |||||
126 | public static function load_translations() { |
||||
0 ignored issues
–
show
|
|||||
127 | load_plugin_textdomain( 'podlove-subscribe-button', false, dirname(plugin_basename( __FILE__)) . '/languages/' ); |
||||
0 ignored issues
–
show
false of type false is incompatible with the type string expected by parameter $deprecated of load_plugin_textdomain() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
128 | |||||
129 | } |
||||
130 | |||||
131 | public static function register_settings() { |
||||
0 ignored issues
–
show
|
|||||
132 | $settings = array( |
||||
133 | 'size', |
||||
134 | 'autowidth', |
||||
135 | 'style', |
||||
136 | 'format', |
||||
137 | 'color', |
||||
138 | ); |
||||
139 | |||||
140 | foreach ( $settings as $setting ) { |
||||
141 | register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting ); |
||||
142 | } |
||||
143 | |||||
144 | } |
||||
145 | |||||
146 | public static function register_shortcode() { |
||||
0 ignored issues
–
show
|
|||||
147 | add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) ); |
||||
148 | |||||
149 | } |
||||
150 | |||||
151 | public static function build_models() { |
||||
0 ignored issues
–
show
|
|||||
152 | // Build Databases |
||||
0 ignored issues
–
show
|
|||||
153 | \PodloveSubscribeButton\Model\Button::build(); |
||||
154 | if ( is_multisite() ) |
||||
0 ignored issues
–
show
|
|||||
155 | \PodloveSubscribeButton\Model\NetworkButton::build(); |
||||
156 | |||||
157 | // Set Button "default" values |
||||
0 ignored issues
–
show
|
|||||
158 | $default_values = array( |
||||
159 | 'size' => 'big', |
||||
0 ignored issues
–
show
|
|||||
160 | 'autowidth' => 'on', |
||||
0 ignored issues
–
show
|
|||||
161 | 'color' => '#599677', |
||||
0 ignored issues
–
show
|
|||||
162 | 'style' => 'filled', |
||||
0 ignored issues
–
show
|
|||||
163 | 'format' => 'rectangle' |
||||
0 ignored issues
–
show
|
|||||
164 | ); |
||||
0 ignored issues
–
show
|
|||||
165 | |||||
166 | foreach ($default_values as $option => $default_value) { |
||||
0 ignored issues
–
show
|
|||||
167 | if ( ! get_option('podlove_subscribe_button_default_' . $option ) ) { |
||||
0 ignored issues
–
show
|
|||||
168 | update_option('podlove_subscribe_button_default_' . $option, $default_value); |
||||
0 ignored issues
–
show
|
|||||
169 | } |
||||
170 | } |
||||
171 | } |
||||
0 ignored issues
–
show
|
|||||
172 | |||||
173 | public static function shortcode( $args ) { |
||||
0 ignored issues
–
show
|
|||||
174 | if ( ! $args || ! isset($args['button']) ) { |
||||
0 ignored issues
–
show
|
|||||
175 | return __('You need to create a Button first and provide its ID.', 'podlove-subscribe-button'); |
||||
0 ignored issues
–
show
|
|||||
176 | } else { |
||||
177 | $buttonid = $args['button']; |
||||
178 | } |
||||
179 | |||||
180 | // Fetch the (network)button by it's name |
||||
0 ignored issues
–
show
|
|||||
181 | if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) ) |
||||
0 ignored issues
–
show
|
|||||
182 | return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] ); |
||||
0 ignored issues
–
show
|
|||||
183 | |||||
184 | // Get button styling and options |
||||
0 ignored issues
–
show
|
|||||
185 | $autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback($args, 'width') ); |
||||
0 ignored issues
–
show
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
![]() |
|||||
186 | $size = self::get_attribute( 'size', self::get_array_value_with_fallback($args, 'size') ); |
||||
0 ignored issues
–
show
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
![]() 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. ![]() |
|||||
187 | $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. ![]() |
|||||
188 | $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. ![]() |
|||||
189 | $color = self::get_attribute( 'color', self::get_array_value_with_fallback($args, 'color') ); |
||||
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. ![]() |
|||||
190 | |||||
191 | if ( isset($args['language']) ) { |
||||
0 ignored issues
–
show
|
|||||
192 | $language = $args['language']; |
||||
193 | } else { |
||||
194 | $language = 'en'; |
||||
195 | } |
||||
196 | |||||
197 | if ( isset($args['color']) ) { |
||||
0 ignored issues
–
show
|
|||||
198 | $color = $args['color']; |
||||
199 | } else { |
||||
200 | $color = get_option('podlove_subscribe_button_default_color', '#599677'); |
||||
0 ignored issues
–
show
|
|||||
201 | } |
||||
202 | |||||
203 | if ( isset($args['hide']) && $args['hide'] == 'true' ) { |
||||
0 ignored issues
–
show
|
|||||
204 | $hide = true; |
||||
205 | } else { |
||||
206 | $hide = false; |
||||
207 | } |
||||
208 | |||||
209 | // Render button |
||||
0 ignored issues
–
show
|
|||||
210 | return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid, $language); |
||||
0 ignored issues
–
show
|
|||||
211 | } |
||||
0 ignored issues
–
show
|
|||||
212 | |||||
213 | public static function get_array_value_with_fallback($args, $key) { |
||||
0 ignored issues
–
show
|
|||||
214 | if ( isset($args[$key]) ) |
||||
0 ignored issues
–
show
|
|||||
215 | return $args[$key]; |
||||
0 ignored issues
–
show
|
|||||
216 | |||||
217 | return false; |
||||
218 | } |
||||
0 ignored issues
–
show
|
|||||
219 | |||||
220 | /** |
||||
0 ignored issues
–
show
|
|||||
221 | * @param string $attribute |
||||
0 ignored issues
–
show
|
|||||
222 | * @param string $attribute_value |
||||
0 ignored issues
–
show
|
|||||
223 | * @return string |
||||
224 | */ |
||||
225 | private static function get_attribute($attribute=null, $attribute_value=null) { |
||||
0 ignored issues
–
show
|
|||||
226 | if ( isset($attribute_value) && ctype_alnum($attribute_value) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) { |
||||
0 ignored issues
–
show
|
|||||
227 | return $attribute_value; |
||||
228 | } else { |
||||
229 | return get_option('podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[$attribute]); |
||||
0 ignored issues
–
show
|
|||||
230 | } |
||||
231 | } |
||||
0 ignored issues
–
show
|
|||||
232 | |||||
233 | /** |
||||
234 | * Interprets the provided width attribute and return either auto- or a specific width |
||||
235 | * @param string $width_attribute |
||||
0 ignored issues
–
show
|
|||||
236 | * @return string |
||||
237 | */ |
||||
238 | private static function interpret_width_attribute( $width_attribute = null ) { |
||||
0 ignored issues
–
show
|
|||||
239 | if ( $width_attribute == 'auto' ) |
||||
0 ignored issues
–
show
|
|||||
240 | return 'on'; |
||||
241 | if ( $width_attribute && $width_attribute !== 'auto' ) |
||||
0 ignored issues
–
show
|
|||||
242 | return 'off'; |
||||
243 | |||||
244 | return get_option( 'podlove_subscribe_button_default_autowidth', 'on' ); |
||||
245 | } |
||||
0 ignored issues
–
show
|
|||||
246 | } |
||||
247 |