@@ -30,23 +30,23 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return string|WP_Error |
| 32 | 32 | */ |
| 33 | - public static function remote_get_body( $url, $required_response_code = 200, array $args = array() ) { |
|
| 34 | - $result = wp_remote_request( $url, $args ); |
|
| 33 | + public static function remote_get_body($url, $required_response_code = 200, array $args = array()) { |
|
| 34 | + $result = wp_remote_request($url, $args); |
|
| 35 | 35 | |
| 36 | - if ( is_wp_error( $result ) ) { |
|
| 36 | + if (is_wp_error($result)) { |
|
| 37 | 37 | return $result; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - $response_code = wp_remote_retrieve_response_code( $result ); |
|
| 40 | + $response_code = wp_remote_retrieve_response_code($result); |
|
| 41 | 41 | |
| 42 | - if ( $response_code === $required_response_code ) { |
|
| 43 | - return wp_remote_retrieve_body( $result ); |
|
| 42 | + if ($response_code === $required_response_code) { |
|
| 43 | + return wp_remote_retrieve_body($result); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | return new WP_Error( |
| 47 | 47 | 'wrong_response_code', |
| 48 | 48 | sprintf( |
| 49 | - __( 'The response code (<code>%1$s<code>) was incorrect, required response code <code>%2$s</code>.', 'pronamic_ideal' ), |
|
| 49 | + __('The response code (<code>%1$s<code>) was incorrect, required response code <code>%2$s</code>.', 'pronamic_ideal'), |
|
| 50 | 50 | $response_code, |
| 51 | 51 | $required_response_code |
| 52 | 52 | ) |
@@ -60,22 +60,22 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @return SimpleXMLElement|WP_Error |
| 62 | 62 | */ |
| 63 | - public static function simplexml_load_string( $string ) { |
|
| 63 | + public static function simplexml_load_string($string) { |
|
| 64 | 64 | $result = false; |
| 65 | 65 | |
| 66 | 66 | // Suppress all XML errors. |
| 67 | - $use_errors = libxml_use_internal_errors( true ); |
|
| 67 | + $use_errors = libxml_use_internal_errors(true); |
|
| 68 | 68 | |
| 69 | 69 | // Load. |
| 70 | - $xml = simplexml_load_string( $string ); |
|
| 70 | + $xml = simplexml_load_string($string); |
|
| 71 | 71 | |
| 72 | - if ( false !== $xml ) { |
|
| 72 | + if (false !== $xml) { |
|
| 73 | 73 | $result = $xml; |
| 74 | 74 | } else { |
| 75 | - $error = new WP_Error( 'simplexml_load_error', __( 'Could not load the XML string.', 'pronamic_ideal' ) ); |
|
| 75 | + $error = new WP_Error('simplexml_load_error', __('Could not load the XML string.', 'pronamic_ideal')); |
|
| 76 | 76 | |
| 77 | - foreach ( libxml_get_errors() as $e ) { |
|
| 78 | - $error->add( 'libxml_error', $e->message, $e ); |
|
| 77 | + foreach (libxml_get_errors() as $e) { |
|
| 78 | + $error->add('libxml_error', $e->message, $e); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | libxml_clear_errors(); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Set back to previous value. |
| 87 | - libxml_use_internal_errors( $use_errors ); |
|
| 87 | + libxml_use_internal_errors($use_errors); |
|
| 88 | 88 | |
| 89 | 89 | return $result; |
| 90 | 90 | } |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @return int |
| 98 | 98 | */ |
| 99 | - public static function amount_to_cents( $price ) { |
|
| 100 | - return round( $price * 100 ); |
|
| 99 | + public static function amount_to_cents($price) { |
|
| 100 | + return round($price * 100); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return float |
| 109 | 109 | */ |
| 110 | - public static function cents_to_amount( $cents ) { |
|
| 110 | + public static function cents_to_amount($cents) { |
|
| 111 | 111 | return $cents / 100; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @return int |
| 122 | 122 | */ |
| 123 | - public static function boolean_to_numeric( $boolean ) { |
|
| 123 | + public static function boolean_to_numeric($boolean) { |
|
| 124 | 124 | return $boolean ? 1 : 0; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @return int |
| 135 | 135 | */ |
| 136 | - public static function boolean_to_string( $boolean ) { |
|
| 136 | + public static function boolean_to_string($boolean) { |
|
| 137 | 137 | return $boolean ? 'true' : 'false'; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | * @param DateTime $date The date to format. |
| 145 | 145 | * @return string |
| 146 | 146 | */ |
| 147 | - public static function format_date( $format, DateTime $date = null ) { |
|
| 147 | + public static function format_date($format, DateTime $date = null) { |
|
| 148 | 148 | $result = null; |
| 149 | 149 | |
| 150 | - if ( null !== $date ) { |
|
| 151 | - $result = $date->format( $format ); |
|
| 150 | + if (null !== $date) { |
|
| 151 | + $result = $date->format($format); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return $result; |
@@ -165,18 +165,18 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * @return string |
| 167 | 167 | */ |
| 168 | - public static function format_price( $amount, $currency = null ) { |
|
| 169 | - $float = filter_var( $amount, FILTER_VALIDATE_FLOAT ); |
|
| 168 | + public static function format_price($amount, $currency = null) { |
|
| 169 | + $float = filter_var($amount, FILTER_VALIDATE_FLOAT); |
|
| 170 | 170 | |
| 171 | - if ( false === $float ) { |
|
| 171 | + if (false === $float) { |
|
| 172 | 172 | return; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - $currency = ( null === $currency ) ? 'EUR' : $currency; |
|
| 175 | + $currency = (null === $currency) ? 'EUR' : $currency; |
|
| 176 | 176 | |
| 177 | 177 | $currency_symbol = $currency; |
| 178 | 178 | |
| 179 | - switch ( $currency ) { |
|
| 179 | + switch ($currency) { |
|
| 180 | 180 | case 'EUR': |
| 181 | 181 | $currency_symbol = '€'; |
| 182 | 182 | break; |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | // @see https://en.wikipedia.org/wiki/Non-breaking_space#Keyboard_entry_methods |
| 189 | 189 | $non_breaking_space = ' '; |
| 190 | 190 | |
| 191 | - return '' . $currency_symbol . $non_breaking_space . number_format_i18n( $float, 2 ); |
|
| 191 | + return '' . $currency_symbol . $non_breaking_space . number_format_i18n($float, 2); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,24 +199,24 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public static function format_interval( $interval, $period ) { |
|
| 203 | - switch ( $period ) { |
|
| 202 | + public static function format_interval($interval, $period) { |
|
| 203 | + switch ($period) { |
|
| 204 | 204 | case 'D': |
| 205 | 205 | case 'day': |
| 206 | 206 | case 'days': |
| 207 | - return sprintf( _n( 'Every %s day', 'Every %s days', $interval, 'pronamic_ideal' ), $interval ); |
|
| 207 | + return sprintf(_n('Every %s day', 'Every %s days', $interval, 'pronamic_ideal'), $interval); |
|
| 208 | 208 | case 'W': |
| 209 | 209 | case 'week': |
| 210 | 210 | case 'weeks': |
| 211 | - return sprintf( _n( 'Every %s week', 'Every %s weeks', $interval, 'pronamic_ideal' ), $interval ); |
|
| 211 | + return sprintf(_n('Every %s week', 'Every %s weeks', $interval, 'pronamic_ideal'), $interval); |
|
| 212 | 212 | case 'M': |
| 213 | 213 | case 'month': |
| 214 | 214 | case 'months': |
| 215 | - return sprintf( _n( 'Every %s month', 'Every %s months', $interval, 'pronamic_ideal' ), $interval ); |
|
| 215 | + return sprintf(_n('Every %s month', 'Every %s months', $interval, 'pronamic_ideal'), $interval); |
|
| 216 | 216 | case 'Y': |
| 217 | 217 | case 'year': |
| 218 | 218 | case 'years': |
| 219 | - return sprintf( _n( 'Every %s year', 'Every %s years', $interval, 'pronamic_ideal' ), $interval ); |
|
| 219 | + return sprintf(_n('Every %s year', 'Every %s years', $interval, 'pronamic_ideal'), $interval); |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
@@ -227,8 +227,8 @@ discard block |
||
| 227 | 227 | * |
| 228 | 228 | * @return string |
| 229 | 229 | */ |
| 230 | - public static function to_interval_name( $interval_period ) { |
|
| 231 | - switch ( $interval_period ) { |
|
| 230 | + public static function to_interval_name($interval_period) { |
|
| 231 | + switch ($interval_period) { |
|
| 232 | 232 | case 'D': |
| 233 | 233 | return 'days'; |
| 234 | 234 | case 'W': |
@@ -249,12 +249,12 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | - public static function format_frequency( $frequency ) { |
|
| 253 | - if ( '' === $frequency ) { |
|
| 254 | - return _x( 'Unlimited', 'Recurring payment', 'pronamic_ideal' ); |
|
| 252 | + public static function format_frequency($frequency) { |
|
| 253 | + if ('' === $frequency) { |
|
| 254 | + return _x('Unlimited', 'Recurring payment', 'pronamic_ideal'); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - return sprintf( _n( '%s time', '%s times', $frequency, 'pronamic_ideal' ), $frequency ); |
|
| 257 | + return sprintf(_n('%s time', '%s times', $frequency, 'pronamic_ideal'), $frequency); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | * |
| 266 | 266 | * @return string |
| 267 | 267 | */ |
| 268 | - public static function build_url( $url, array $parameters ) { |
|
| 269 | - return $url . '?' . _http_build_query( $parameters, null, '&' ); |
|
| 268 | + public static function build_url($url, array $parameters) { |
|
| 269 | + return $url . '?' . _http_build_query($parameters, null, '&'); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return string |
| 278 | 278 | */ |
| 279 | - public static function html_hidden_fields( $data ) { |
|
| 279 | + public static function html_hidden_fields($data) { |
|
| 280 | 280 | $html = ''; |
| 281 | 281 | |
| 282 | - foreach ( $data as $name => $value ) { |
|
| 283 | - $html .= sprintf( '<input type="hidden" name="%s" value="%s" />', esc_attr( $name ), esc_attr( $value ) ); |
|
| 282 | + foreach ($data as $name => $value) { |
|
| 283 | + $html .= sprintf('<input type="hidden" name="%s" value="%s" />', esc_attr($name), esc_attr($value)); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | return $html; |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | * |
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | - public static function array_to_html_attributes( array $attributes ) { |
|
| 296 | + public static function array_to_html_attributes(array $attributes) { |
|
| 297 | 297 | $html = ''; |
| 298 | 298 | |
| 299 | - foreach ( $attributes as $key => $value ) { |
|
| 300 | - $html .= sprintf( '%s="%s"', $key, esc_attr( $value ) ); |
|
| 299 | + foreach ($attributes as $key => $value) { |
|
| 300 | + $html .= sprintf('%s="%s"', $key, esc_attr($value)); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - $html = trim( $html ); |
|
| 303 | + $html = trim($html); |
|
| 304 | 304 | |
| 305 | 305 | return $html; |
| 306 | 306 | } |
@@ -313,22 +313,22 @@ discard block |
||
| 313 | 313 | * |
| 314 | 314 | * @return string |
| 315 | 315 | */ |
| 316 | - public static function select_options_grouped( $groups, $selected_value = null ) { |
|
| 316 | + public static function select_options_grouped($groups, $selected_value = null) { |
|
| 317 | 317 | $html = ''; |
| 318 | 318 | |
| 319 | - if ( is_array( $groups ) ) { |
|
| 320 | - foreach ( $groups as $group ) { |
|
| 321 | - $optgroup = isset( $group['name'] ) && ! empty( $group['name'] ); |
|
| 319 | + if (is_array($groups)) { |
|
| 320 | + foreach ($groups as $group) { |
|
| 321 | + $optgroup = isset($group['name']) && ! empty($group['name']); |
|
| 322 | 322 | |
| 323 | - if ( $optgroup ) { |
|
| 323 | + if ($optgroup) { |
|
| 324 | 324 | $html .= '<optgroup label="' . $group['name'] . '">'; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - foreach ( $group['options'] as $value => $label ) { |
|
| 328 | - $html .= '<option value="' . $value . '" ' . selected( $selected_value, $value, false ) . '>' . $label . '</option>'; |
|
| 327 | + foreach ($group['options'] as $value => $label) { |
|
| 328 | + $html .= '<option value="' . $value . '" ' . selected($selected_value, $value, false) . '>' . $label . '</option>'; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - if ( $optgroup ) { |
|
| 331 | + if ($optgroup) { |
|
| 332 | 332 | $html .= '</optgroup>'; |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @see https://github.com/WordPress/WordPress/blob/4.0/wp-includes/post.php#L167 |
| 39 | 39 | */ |
| 40 | - add_action( 'init', array( $this, 'register_gateway_post_type' ), 0 ); // Highest priority. |
|
| 40 | + add_action('init', array($this, 'register_gateway_post_type'), 0); // Highest priority. |
|
| 41 | 41 | |
| 42 | - add_action( 'save_post_' . self::POST_TYPE, array( $this, 'maybe_set_default_gateway' ) ); |
|
| 42 | + add_action('save_post_' . self::POST_TYPE, array($this, 'maybe_set_default_gateway')); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -50,23 +50,23 @@ discard block |
||
| 50 | 50 | public function register_gateway_post_type() { |
| 51 | 51 | register_post_type( |
| 52 | 52 | 'pronamic_gateway', array( |
| 53 | - 'label' => __( 'Payment Gateway Configurations', 'pronamic_ideal' ), |
|
| 53 | + 'label' => __('Payment Gateway Configurations', 'pronamic_ideal'), |
|
| 54 | 54 | 'labels' => array( |
| 55 | - 'name' => __( 'Payment Gateway Configurations', 'pronamic_ideal' ), |
|
| 56 | - 'singular_name' => __( 'Payment Gateway Configuration', 'pronamic_ideal' ), |
|
| 57 | - 'add_new' => __( 'Add New', 'pronamic_ideal' ), |
|
| 58 | - 'add_new_item' => __( 'Add New Payment Gateway Configuration', 'pronamic_ideal' ), |
|
| 59 | - 'edit_item' => __( 'Edit Payment Gateway Configuration', 'pronamic_ideal' ), |
|
| 60 | - 'new_item' => __( 'New Payment Gateway Configuration', 'pronamic_ideal' ), |
|
| 61 | - 'all_items' => __( 'All Payment Gateway Configurations', 'pronamic_ideal' ), |
|
| 62 | - 'view_item' => __( 'View Payment Gateway Configuration', 'pronamic_ideal' ), |
|
| 63 | - 'search_items' => __( 'Search Payment Gateway Configurations', 'pronamic_ideal' ), |
|
| 64 | - 'not_found' => __( 'No payment gateway configurations found.', 'pronamic_ideal' ), |
|
| 65 | - 'not_found_in_trash' => __( 'No payment gateway configurations found in Trash.', 'pronamic_ideal' ), |
|
| 66 | - 'menu_name' => __( 'Configurations', 'pronamic_ideal' ), |
|
| 67 | - 'filter_items_list' => __( 'Filter payment gateway configurations list', 'pronamic_ideal' ), |
|
| 68 | - 'items_list_navigation' => __( 'Payment gateway configurations list navigation', 'pronamic_ideal' ), |
|
| 69 | - 'items_list' => __( 'Payment gateway configurations list', 'pronamic_ideal' ), |
|
| 55 | + 'name' => __('Payment Gateway Configurations', 'pronamic_ideal'), |
|
| 56 | + 'singular_name' => __('Payment Gateway Configuration', 'pronamic_ideal'), |
|
| 57 | + 'add_new' => __('Add New', 'pronamic_ideal'), |
|
| 58 | + 'add_new_item' => __('Add New Payment Gateway Configuration', 'pronamic_ideal'), |
|
| 59 | + 'edit_item' => __('Edit Payment Gateway Configuration', 'pronamic_ideal'), |
|
| 60 | + 'new_item' => __('New Payment Gateway Configuration', 'pronamic_ideal'), |
|
| 61 | + 'all_items' => __('All Payment Gateway Configurations', 'pronamic_ideal'), |
|
| 62 | + 'view_item' => __('View Payment Gateway Configuration', 'pronamic_ideal'), |
|
| 63 | + 'search_items' => __('Search Payment Gateway Configurations', 'pronamic_ideal'), |
|
| 64 | + 'not_found' => __('No payment gateway configurations found.', 'pronamic_ideal'), |
|
| 65 | + 'not_found_in_trash' => __('No payment gateway configurations found in Trash.', 'pronamic_ideal'), |
|
| 66 | + 'menu_name' => __('Configurations', 'pronamic_ideal'), |
|
| 67 | + 'filter_items_list' => __('Filter payment gateway configurations list', 'pronamic_ideal'), |
|
| 68 | + 'items_list_navigation' => __('Payment gateway configurations list navigation', 'pronamic_ideal'), |
|
| 69 | + 'items_list' => __('Payment gateway configurations list', 'pronamic_ideal'), |
|
| 70 | 70 | ), |
| 71 | 71 | 'public' => false, |
| 72 | 72 | 'publicly_queryable' => false, |
@@ -93,21 +93,21 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @param int $post_id Post ID. |
| 95 | 95 | */ |
| 96 | - public function maybe_set_default_gateway( $post_id ) { |
|
| 96 | + public function maybe_set_default_gateway($post_id) { |
|
| 97 | 97 | // Don't set the default gateway if the post is not published. |
| 98 | - if ( 'publish' !== get_post_status( $post_id ) ) { |
|
| 98 | + if ('publish' !== get_post_status($post_id)) { |
|
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // Don't set the default gateway if there is already a published gateway set. |
| 103 | - $config_id = get_option( 'pronamic_pay_config_id' ); |
|
| 103 | + $config_id = get_option('pronamic_pay_config_id'); |
|
| 104 | 104 | |
| 105 | - if ( ! empty( $config_id ) && 'publish' === get_post_status( $config_id ) ) { |
|
| 105 | + if ( ! empty($config_id) && 'publish' === get_post_status($config_id)) { |
|
| 106 | 106 | return; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Update. |
| 110 | - update_option( 'pronamic_pay_config_id', $post_id ); |
|
| 110 | + update_option('pronamic_pay_config_id', $post_id); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |