@@ -22,43 +22,43 @@ discard block |
||
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | // Constants |
| 25 | -require('constants.php'); |
|
| 26 | -require('settings/buttons.php'); |
|
| 25 | +require( 'constants.php' ); |
|
| 26 | +require( 'settings/buttons.php' ); |
|
| 27 | 27 | // Models |
| 28 | -require('model/base.php'); |
|
| 29 | -require('model/button.php'); |
|
| 30 | -require('model/network_button.php'); |
|
| 28 | +require( 'model/base.php' ); |
|
| 29 | +require( 'model/button.php' ); |
|
| 30 | +require( 'model/network_button.php' ); |
|
| 31 | 31 | // Table |
| 32 | -require('settings/buttons_list_table.php'); |
|
| 32 | +require( 'settings/buttons_list_table.php' ); |
|
| 33 | 33 | // Media Types |
| 34 | -require('media_types.php'); |
|
| 34 | +require( 'media_types.php' ); |
|
| 35 | 35 | // Widget |
| 36 | -require('widget.php'); |
|
| 36 | +require( 'widget.php' ); |
|
| 37 | 37 | // Version control |
| 38 | -require('version.php'); |
|
| 38 | +require( 'version.php' ); |
|
| 39 | 39 | // Helper functions |
| 40 | -require('helper.php'); |
|
| 40 | +require( 'helper.php' ); |
|
| 41 | 41 | |
| 42 | -add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu') ); |
|
| 42 | +add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu' ) ); |
|
| 43 | 43 | if ( is_multisite() ) |
| 44 | - add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu') ); |
|
| 44 | + add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu' ) ); |
|
| 45 | 45 | |
| 46 | 46 | add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) ); |
| 47 | 47 | register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) ); |
| 48 | 48 | |
| 49 | 49 | // Register Settings |
| 50 | -add_action( 'admin_init', function () { |
|
| 51 | - $settings = array('size', 'autowidth', 'style', 'format', 'color'); |
|
| 50 | +add_action( 'admin_init', function() { |
|
| 51 | + $settings = array( 'size', 'autowidth', 'style', 'format', 'color' ); |
|
| 52 | 52 | |
| 53 | - foreach ($settings as $setting) { |
|
| 53 | + foreach ( $settings as $setting ) { |
|
| 54 | 54 | register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting ); |
| 55 | 55 | } |
| 56 | 56 | } ); |
| 57 | 57 | |
| 58 | 58 | add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) ); |
| 59 | 59 | |
| 60 | -add_action( 'plugins_loaded', function () { |
|
| 61 | - load_plugin_textdomain( 'podlove-subscribe-button', false, dirname(plugin_basename( __FILE__)) . '/languages/'); |
|
| 60 | +add_action( 'plugins_loaded', function() { |
|
| 61 | + load_plugin_textdomain( 'podlove-subscribe-button', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
| 62 | 62 | } ); |
| 63 | 63 | |
| 64 | 64 | PodloveSubscribeButton::run(); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | $pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' ); |
| 83 | 83 | |
| 84 | - if ( ! in_array( $hook, $pages ) ) { |
|
| 84 | + if ( ! in_array( $hook, $pages ) ) { |
|
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | 'Podlove Subscribe Button', |
| 112 | 112 | 'manage_options', |
| 113 | 113 | 'podlove-subscribe-button', |
| 114 | - array( 'PodloveSubscribeButton\Settings\Buttons', 'page') |
|
| 114 | + array( 'PodloveSubscribeButton\Settings\Buttons', 'page' ) |
|
| 115 | 115 | ); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | 'Podlove Subscribe Button', |
| 123 | 123 | 'manage_options', |
| 124 | 124 | 'podlove-subscribe-button', |
| 125 | - array( 'PodloveSubscribeButton\Settings\Buttons', 'page') |
|
| 125 | + array( 'PodloveSubscribeButton\Settings\Buttons', 'page' ) |
|
| 126 | 126 | ); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -141,56 +141,56 @@ discard block |
||
| 141 | 141 | 'format' => 'rectangle' |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - foreach ($default_values as $option => $default_value) { |
|
| 145 | - if ( ! get_option('podlove_subscribe_button_default_' . $option ) ) { |
|
| 146 | - update_option('podlove_subscribe_button_default_' . $option, $default_value); |
|
| 144 | + foreach ( $default_values as $option => $default_value ) { |
|
| 145 | + if ( ! get_option( 'podlove_subscribe_button_default_' . $option ) ) { |
|
| 146 | + update_option( 'podlove_subscribe_button_default_' . $option, $default_value ); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | public static function shortcode( $args ) { |
| 152 | - if ( ! $args || ! isset($args['button']) ) { |
|
| 153 | - return __('You need to create a Button first and provide its ID.', 'podlove-subscribe-button'); |
|
| 152 | + if ( ! $args || ! isset( $args[ 'button' ] ) ) { |
|
| 153 | + return __( 'You need to create a Button first and provide its ID.', 'podlove-subscribe-button' ); |
|
| 154 | 154 | } else { |
| 155 | - $buttonid = $args['button']; |
|
| 155 | + $buttonid = $args[ 'button' ]; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Fetch the (network)button by it's name |
| 159 | - if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) ) |
|
| 160 | - return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] ); |
|
| 159 | + if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $args[ 'button' ] ) ) |
|
| 160 | + return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args[ 'button' ] ); |
|
| 161 | 161 | |
| 162 | 162 | // Get button styling and options |
| 163 | - $autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback($args, 'width') ); |
|
| 164 | - $size = self::get_attribute( 'size', self::get_array_value_with_fallback($args, 'size') ); |
|
| 165 | - $style = self::get_attribute( 'style', self::get_array_value_with_fallback($args, 'style') ); |
|
| 166 | - $format = self::get_attribute( 'format', self::get_array_value_with_fallback($args, 'format') ); |
|
| 167 | - $color = self::get_attribute( 'color', self::get_array_value_with_fallback($args, 'color') ); |
|
| 168 | - |
|
| 169 | - if ( isset($args['language']) ) { |
|
| 170 | - $language = $args['language']; |
|
| 163 | + $autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback( $args, 'width' ) ); |
|
| 164 | + $size = self::get_attribute( 'size', self::get_array_value_with_fallback( $args, 'size' ) ); |
|
| 165 | + $style = self::get_attribute( 'style', self::get_array_value_with_fallback( $args, 'style' ) ); |
|
| 166 | + $format = self::get_attribute( 'format', self::get_array_value_with_fallback( $args, 'format' ) ); |
|
| 167 | + $color = self::get_attribute( 'color', self::get_array_value_with_fallback( $args, 'color' ) ); |
|
| 168 | + |
|
| 169 | + if ( isset( $args[ 'language' ] ) ) { |
|
| 170 | + $language = $args[ 'language' ]; |
|
| 171 | 171 | } else { |
| 172 | 172 | $language = 'en'; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if ( isset($args['color']) ) { |
|
| 176 | - $color = $args['color']; |
|
| 175 | + if ( isset( $args[ 'color' ] ) ) { |
|
| 176 | + $color = $args[ 'color' ]; |
|
| 177 | 177 | } else { |
| 178 | - $color = get_option('podlove_subscribe_button_default_color', '#599677'); |
|
| 178 | + $color = get_option( 'podlove_subscribe_button_default_color', '#599677' ); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if ( isset($args['hide']) && $args['hide'] == 'true' ) { |
|
| 181 | + if ( isset( $args[ 'hide' ] ) && $args[ 'hide' ] == 'true' ) { |
|
| 182 | 182 | $hide = true; |
| 183 | 183 | } else { |
| 184 | 184 | $hide = false; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Render button |
| 188 | - return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid, $language); |
|
| 188 | + return $button->render( $size, $autowidth, $style, $format, $color, $hide, $buttonid, $language ); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - public static function get_array_value_with_fallback($args, $key) { |
|
| 192 | - if ( isset($args[$key]) ) |
|
| 193 | - return $args[$key]; |
|
| 191 | + public static function get_array_value_with_fallback( $args, $key ) { |
|
| 192 | + if ( isset( $args[ $key ] ) ) |
|
| 193 | + return $args[ $key ]; |
|
| 194 | 194 | |
| 195 | 195 | return false; |
| 196 | 196 | } |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | * @param string $attribute_value |
| 201 | 201 | * @return string |
| 202 | 202 | */ |
| 203 | - private static function get_attribute($attribute=null, $attribute_value=null) { |
|
| 204 | - if ( isset($attribute_value) && ctype_alnum($attribute_value) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) { |
|
| 203 | + private static function get_attribute( $attribute = null, $attribute_value = null ) { |
|
| 204 | + if ( isset( $attribute_value ) && ctype_alnum( $attribute_value ) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) { |
|
| 205 | 205 | return $attribute_value; |
| 206 | 206 | } else { |
| 207 | - return get_option('podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[$attribute]); |
|
| 207 | + return get_option( 'podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[ $attribute ] ); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
@@ -219,6 +219,6 @@ discard block |
||
| 219 | 219 | if ( $width_attribute && $width_attribute !== 'auto' ) |
| 220 | 220 | return 'off'; |
| 221 | 221 | |
| 222 | - return get_option('podlove_subscribe_button_default_autowidth', 'on'); |
|
| 222 | + return get_option( 'podlove_subscribe_button_default_autowidth', 'on' ); |
|
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | \ No newline at end of file |
@@ -40,8 +40,9 @@ discard block |
||
| 40 | 40 | require('helper.php'); |
| 41 | 41 | |
| 42 | 42 | add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu') ); |
| 43 | -if ( is_multisite() ) |
|
| 43 | +if ( is_multisite() ) { |
|
| 44 | 44 | add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu') ); |
| 45 | +} |
|
| 45 | 46 | |
| 46 | 47 | add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) ); |
| 47 | 48 | register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) ); |
@@ -129,8 +130,9 @@ discard block |
||
| 129 | 130 | public static function build_models() { |
| 130 | 131 | // Build Databases |
| 131 | 132 | \PodloveSubscribeButton\Model\Button::build(); |
| 132 | - if ( is_multisite() ) |
|
| 133 | - \PodloveSubscribeButton\Model\NetworkButton::build(); |
|
| 133 | + if ( is_multisite() ) { |
|
| 134 | + \PodloveSubscribeButton\Model\NetworkButton::build(); |
|
| 135 | + } |
|
| 134 | 136 | |
| 135 | 137 | // Set Button "default" values |
| 136 | 138 | $default_values = array( |
@@ -156,8 +158,9 @@ discard block |
||
| 156 | 158 | } |
| 157 | 159 | |
| 158 | 160 | // Fetch the (network)button by it's name |
| 159 | - if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) ) |
|
| 160 | - return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] ); |
|
| 161 | + if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) ) { |
|
| 162 | + return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] ); |
|
| 163 | + } |
|
| 161 | 164 | |
| 162 | 165 | // Get button styling and options |
| 163 | 166 | $autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback($args, 'width') ); |
@@ -189,8 +192,9 @@ discard block |
||
| 189 | 192 | } |
| 190 | 193 | |
| 191 | 194 | public static function get_array_value_with_fallback($args, $key) { |
| 192 | - if ( isset($args[$key]) ) |
|
| 193 | - return $args[$key]; |
|
| 195 | + if ( isset($args[$key]) ) { |
|
| 196 | + return $args[$key]; |
|
| 197 | + } |
|
| 194 | 198 | |
| 195 | 199 | return false; |
| 196 | 200 | } |
@@ -214,10 +218,12 @@ discard block |
||
| 214 | 218 | * @return string |
| 215 | 219 | */ |
| 216 | 220 | private static function interpret_width_attribute( $width_attribute = null ) { |
| 217 | - if ( $width_attribute == 'auto' ) |
|
| 218 | - return 'on'; |
|
| 219 | - if ( $width_attribute && $width_attribute !== 'auto' ) |
|
| 220 | - return 'off'; |
|
| 221 | + if ( $width_attribute == 'auto' ) { |
|
| 222 | + return 'on'; |
|
| 223 | + } |
|
| 224 | + if ( $width_attribute && $width_attribute !== 'auto' ) { |
|
| 225 | + return 'off'; |
|
| 226 | + } |
|
| 221 | 227 | |
| 222 | 228 | return get_option('podlove_subscribe_button_default_autowidth', 'on'); |
| 223 | 229 | } |