@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | * Hook in ajax handlers. |
| 18 | 18 | */ |
| 19 | 19 | public static function init() { |
| 20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
| 21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
| 20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
| 21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
| 22 | 22 | self::add_ajax_events(); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public static function define_ajax() { |
| 29 | 29 | |
| 30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
| 31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
| 32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
| 33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
| 34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
| 30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
| 32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
| 33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
| 34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
| 35 | 35 | } |
| 36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
| 37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | * @since 1.0.18 |
| 45 | 45 | */ |
| 46 | 46 | private static function wpinv_ajax_headers() { |
| 47 | - if ( ! headers_sent() ) { |
|
| 47 | + if (!headers_sent()) { |
|
| 48 | 48 | send_origin_headers(); |
| 49 | 49 | send_nosniff_header(); |
| 50 | 50 | nocache_headers(); |
| 51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
| 52 | - header( 'X-Robots-Tag: noindex' ); |
|
| 53 | - status_header( 200 ); |
|
| 51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
| 52 | + header('X-Robots-Tag: noindex'); |
|
| 53 | + status_header(200); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | public static function do_wpinv_ajax() { |
| 61 | 61 | global $wp_query; |
| 62 | 62 | |
| 63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
| 64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
| 63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
| 67 | + $action = $wp_query->get('wpinv-ajax'); |
|
| 68 | 68 | |
| 69 | - if ( $action ) { |
|
| 69 | + if ($action) { |
|
| 70 | 70 | self::wpinv_ajax_headers(); |
| 71 | - $action = sanitize_text_field( $action ); |
|
| 72 | - do_action( 'wpinv_ajax_' . $action ); |
|
| 71 | + $action = sanitize_text_field($action); |
|
| 72 | + do_action('wpinv_ajax_' . $action); |
|
| 73 | 73 | wp_die(); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -106,36 +106,36 @@ discard block |
||
| 106 | 106 | 'file_upload' => true, |
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
| 110 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 111 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 109 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
| 110 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 111 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 112 | 112 | |
| 113 | - if ( $nopriv ) { |
|
| 114 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 115 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 116 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 113 | + if ($nopriv) { |
|
| 114 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 115 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 116 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | public static function add_note() { |
| 122 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
| 122 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
| 123 | 123 | |
| 124 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 124 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 125 | 125 | die( -1 ); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $post_id = absint( $_POST['post_id'] ); |
|
| 129 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
| 130 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
| 128 | + $post_id = absint($_POST['post_id']); |
|
| 129 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
| 130 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
| 131 | 131 | |
| 132 | 132 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
| 133 | 133 | |
| 134 | - if ( $post_id > 0 ) { |
|
| 135 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
| 134 | + if ($post_id > 0) { |
|
| 135 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
| 136 | 136 | |
| 137 | - if ( $note_id > 0 && ! is_wp_error( $note_id ) ) { |
|
| 138 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
| 137 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
| 138 | + wpinv_get_invoice_note_line_item($note_id); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
@@ -143,16 +143,16 @@ discard block |
||
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | public static function delete_note() { |
| 146 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
| 146 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
| 147 | 147 | |
| 148 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 148 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 149 | 149 | die( -1 ); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $note_id = (int)$_POST['note_id']; |
|
| 152 | + $note_id = (int) $_POST['note_id']; |
|
| 153 | 153 | |
| 154 | - if ( $note_id > 0 ) { |
|
| 155 | - wp_delete_comment( $note_id, true ); |
|
| 154 | + if ($note_id > 0) { |
|
| 155 | + wp_delete_comment($note_id, true); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | die(); |
@@ -170,34 +170,34 @@ discard block |
||
| 170 | 170 | public static function get_billing_details() { |
| 171 | 171 | |
| 172 | 172 | // Verify nonce. |
| 173 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 173 | + check_ajax_referer('wpinv-nonce'); |
|
| 174 | 174 | |
| 175 | 175 | // Can the user manage the plugin? |
| 176 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 176 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 177 | 177 | die( -1 ); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Do we have a user id? |
| 181 | 181 | $user_id = (int) $_GET['user_id']; |
| 182 | 182 | |
| 183 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
| 183 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
| 184 | 184 | die( -1 ); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Fetch the billing details. |
| 188 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
| 189 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
| 188 | + $billing_details = wpinv_get_user_address($user_id); |
|
| 189 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
| 190 | 190 | |
| 191 | 191 | // unset the user id and email. |
| 192 | - $to_ignore = array( 'user_id', 'email' ); |
|
| 192 | + $to_ignore = array('user_id', 'email'); |
|
| 193 | 193 | |
| 194 | - foreach ( $to_ignore as $key ) { |
|
| 195 | - if ( isset( $billing_details[ $key ] ) ) { |
|
| 196 | - unset( $billing_details[ $key ] ); |
|
| 194 | + foreach ($to_ignore as $key) { |
|
| 195 | + if (isset($billing_details[$key])) { |
|
| 196 | + unset($billing_details[$key]); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - wp_send_json_success( $billing_details ); |
|
| 200 | + wp_send_json_success($billing_details); |
|
| 201 | 201 | |
| 202 | 202 | } |
| 203 | 203 | |
@@ -207,47 +207,47 @@ discard block |
||
| 207 | 207 | public static function check_new_user_email() { |
| 208 | 208 | |
| 209 | 209 | // Verify nonce. |
| 210 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 210 | + check_ajax_referer('wpinv-nonce'); |
|
| 211 | 211 | |
| 212 | 212 | // Can the user manage the plugin? |
| 213 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 213 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 214 | 214 | die( -1 ); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | // We need an email address. |
| 218 | - if ( empty( $_GET['email'] ) ) { |
|
| 219 | - esc_html_e( "Provide the new user's email address", 'invoicing' ); |
|
| 218 | + if (empty($_GET['email'])) { |
|
| 219 | + esc_html_e("Provide the new user's email address", 'invoicing'); |
|
| 220 | 220 | exit; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // Ensure the email is valid. |
| 224 | - $email = sanitize_email( $_GET['email'] ); |
|
| 225 | - if ( ! is_email( $email ) ) { |
|
| 226 | - esc_html_e( 'Invalid email address', 'invoicing' ); |
|
| 224 | + $email = sanitize_email($_GET['email']); |
|
| 225 | + if (!is_email($email)) { |
|
| 226 | + esc_html_e('Invalid email address', 'invoicing'); |
|
| 227 | 227 | exit; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // And it does not exist. |
| 231 | - $id = email_exists( $email ); |
|
| 232 | - if ( $id ) { |
|
| 233 | - wp_send_json_success( compact( 'id' ) ); |
|
| 231 | + $id = email_exists($email); |
|
| 232 | + if ($id) { |
|
| 233 | + wp_send_json_success(compact('id')); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - wp_send_json_success( true ); |
|
| 236 | + wp_send_json_success(true); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | public static function run_tool() { |
| 240 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 241 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 240 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 241 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 242 | 242 | die( -1 ); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
| 245 | + $tool = sanitize_text_field($_POST['tool']); |
|
| 246 | 246 | |
| 247 | - do_action( 'wpinv_run_tool' ); |
|
| 247 | + do_action('wpinv_run_tool'); |
|
| 248 | 248 | |
| 249 | - if ( ! empty( $tool ) ) { |
|
| 250 | - do_action( 'wpinv_tool_' . $tool ); |
|
| 249 | + if (!empty($tool)) { |
|
| 250 | + do_action('wpinv_tool_' . $tool); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
@@ -258,14 +258,14 @@ discard block |
||
| 258 | 258 | global $getpaid_force_checkbox; |
| 259 | 259 | |
| 260 | 260 | // Check nonce. |
| 261 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
| 261 | + check_ajax_referer('getpaid_form_nonce'); |
|
| 262 | 262 | |
| 263 | 263 | // Is the request set up correctly? |
| 264 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
| 264 | + if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) { |
|
| 265 | 265 | aui()->alert( |
| 266 | 266 | array( |
| 267 | 267 | 'type' => 'warning', |
| 268 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
| 268 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
| 269 | 269 | ), |
| 270 | 270 | true |
| 271 | 271 | ); |
@@ -273,29 +273,29 @@ discard block |
||
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Payment form or button? |
| 276 | - if ( ! empty( $_GET['form'] ) ) { |
|
| 277 | - $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
|
| 276 | + if (!empty($_GET['form'])) { |
|
| 277 | + $form = sanitize_text_field(urldecode($_GET['form'])); |
|
| 278 | 278 | |
| 279 | - if ( false !== strpos( $form, '|' ) ) { |
|
| 280 | - $form_pos = strpos( $form, '|' ); |
|
| 281 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
| 282 | - $form = substr( $form, 0, $form_pos ); |
|
| 279 | + if (false !== strpos($form, '|')) { |
|
| 280 | + $form_pos = strpos($form, '|'); |
|
| 281 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
| 282 | + $form = substr($form, 0, $form_pos); |
|
| 283 | 283 | |
| 284 | 284 | // Retrieve appropriate payment form. |
| 285 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
| 286 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
| 285 | + $payment_form = new GetPaid_Payment_Form($form); |
|
| 286 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
| 287 | 287 | |
| 288 | 288 | $items = array(); |
| 289 | 289 | $item_ids = array(); |
| 290 | 290 | |
| 291 | - foreach ( $_items as $item_id => $qty ) { |
|
| 292 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
| 293 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 294 | - $item->set_quantity( $qty ); |
|
| 291 | + foreach ($_items as $item_id => $qty) { |
|
| 292 | + if (!in_array($item_id, $item_ids)) { |
|
| 293 | + $item = new GetPaid_Form_Item($item_id); |
|
| 294 | + $item->set_quantity($qty); |
|
| 295 | 295 | |
| 296 | - if ( 0 == $qty ) { |
|
| 297 | - $item->set_allow_quantities( true ); |
|
| 298 | - $item->set_is_required( false ); |
|
| 296 | + if (0 == $qty) { |
|
| 297 | + $item->set_allow_quantities(true); |
|
| 298 | + $item->set_is_required(false); |
|
| 299 | 299 | $getpaid_force_checkbox = true; |
| 300 | 300 | } |
| 301 | 301 | |
@@ -304,32 +304,32 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - if ( ! $payment_form->is_default() ) { |
|
| 307 | + if (!$payment_form->is_default()) { |
|
| 308 | 308 | |
| 309 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 310 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 309 | + foreach ($payment_form->get_items() as $item) { |
|
| 310 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 311 | 311 | $item_ids[] = $item->get_id(); |
| 312 | 312 | $items[] = $item; |
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - $payment_form->set_items( $items ); |
|
| 318 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
| 319 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
| 317 | + $payment_form->set_items($items); |
|
| 318 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
| 319 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
| 320 | 320 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
| 321 | 321 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
| 322 | - $payment_form->display( $extra_items ); |
|
| 322 | + $payment_form->display($extra_items); |
|
| 323 | 323 | $getpaid_force_checkbox = false; |
| 324 | 324 | |
| 325 | 325 | } else { |
| 326 | - getpaid_display_payment_form( $form ); |
|
| 326 | + getpaid_display_payment_form($form); |
|
| 327 | 327 | } |
| 328 | -} elseif ( ! empty( $_GET['invoice'] ) ) { |
|
| 329 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
| 328 | +} elseif (!empty($_GET['invoice'])) { |
|
| 329 | + getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice'])); |
|
| 330 | 330 | } else { |
| 331 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
| 332 | - getpaid_display_item_payment_form( $items ); |
|
| 331 | + $items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item']))); |
|
| 332 | + getpaid_display_item_payment_form($items); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | exit; |
@@ -344,17 +344,17 @@ discard block |
||
| 344 | 344 | public static function payment_form() { |
| 345 | 345 | |
| 346 | 346 | // Check nonce. |
| 347 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
| 347 | + check_ajax_referer('getpaid_form_nonce'); |
|
| 348 | 348 | |
| 349 | 349 | // ... form fields... |
| 350 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 351 | - esc_html_e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
| 350 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
| 351 | + esc_html_e('Error: Reload the page and try again.', 'invoicing'); |
|
| 352 | 352 | exit; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | // Process the payment form. |
| 356 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
| 357 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
| 356 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
| 357 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
| 358 | 358 | $checkout->process_checkout(); |
| 359 | 359 | |
| 360 | 360 | exit; |
@@ -367,55 +367,55 @@ discard block |
||
| 367 | 367 | */ |
| 368 | 368 | public static function get_payment_form_states_field() { |
| 369 | 369 | |
| 370 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
| 370 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
| 371 | 371 | exit; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] ); |
|
| 374 | + $elements = getpaid_get_payment_form_elements((int) $_GET['form']); |
|
| 375 | 375 | |
| 376 | - if ( empty( $elements ) ) { |
|
| 376 | + if (empty($elements)) { |
|
| 377 | 377 | exit; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | $address_fields = array(); |
| 381 | - foreach ( $elements as $element ) { |
|
| 382 | - if ( 'address' === $element['type'] ) { |
|
| 381 | + foreach ($elements as $element) { |
|
| 382 | + if ('address' === $element['type']) { |
|
| 383 | 383 | $address_fields = $element; |
| 384 | 384 | break; |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if ( empty( $address_fields ) ) { |
|
| 388 | + if (empty($address_fields)) { |
|
| 389 | 389 | exit; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
| 392 | + foreach ($address_fields['fields'] as $address_field) { |
|
| 393 | 393 | |
| 394 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
| 394 | + if ('wpinv_state' == $address_field['name']) { |
|
| 395 | 395 | |
| 396 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
| 397 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
| 398 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
| 399 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
| 400 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
| 401 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
| 396 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
| 397 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
| 398 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
| 399 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
| 400 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
| 401 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
| 402 | 402 | |
| 403 | - if ( ! empty( $address_field['required'] ) ) { |
|
| 403 | + if (!empty($address_field['required'])) { |
|
| 404 | 404 | $label .= "<span class='text-danger'> *</span>"; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | $html = getpaid_get_states_select_markup( |
| 408 | - sanitize_text_field( $_GET['country'] ), |
|
| 408 | + sanitize_text_field($_GET['country']), |
|
| 409 | 409 | $value, |
| 410 | 410 | $placeholder, |
| 411 | 411 | $label, |
| 412 | 412 | $description, |
| 413 | - ! empty( $address_field['required'] ), |
|
| 413 | + !empty($address_field['required']), |
|
| 414 | 414 | $wrap_class, |
| 415 | - sanitize_text_field( $_GET['name'] ) |
|
| 415 | + sanitize_text_field($_GET['name']) |
|
| 416 | 416 | ); |
| 417 | 417 | |
| 418 | - wp_send_json_success( $html ); |
|
| 418 | + wp_send_json_success($html); |
|
| 419 | 419 | exit; |
| 420 | 420 | |
| 421 | 421 | } |
@@ -430,66 +430,66 @@ discard block |
||
| 430 | 430 | public static function recalculate_invoice_totals() { |
| 431 | 431 | |
| 432 | 432 | // Verify nonce. |
| 433 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 433 | + check_ajax_referer('wpinv-nonce'); |
|
| 434 | 434 | |
| 435 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 435 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 436 | 436 | exit; |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // We need an invoice. |
| 440 | - if ( empty( $_POST['post_id'] ) ) { |
|
| 440 | + if (empty($_POST['post_id'])) { |
|
| 441 | 441 | exit; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | // Fetch the invoice. |
| 445 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
| 445 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
| 446 | 446 | |
| 447 | 447 | // Ensure it exists. |
| 448 | - if ( ! $invoice->get_id() ) { |
|
| 448 | + if (!$invoice->get_id()) { |
|
| 449 | 449 | exit; |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | // Maybe set the country, state, currency. |
| 453 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
| 454 | - if ( isset( $_POST[ $key ] ) ) { |
|
| 453 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
| 454 | + if (isset($_POST[$key])) { |
|
| 455 | 455 | $method = "set_$key"; |
| 456 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
| 456 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // Maybe disable taxes. |
| 461 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
| 461 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
| 462 | 462 | |
| 463 | 463 | // Discount code. |
| 464 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 465 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 466 | - if ( $discount->exists() ) { |
|
| 467 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 464 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
| 465 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 466 | + if ($discount->exists()) { |
|
| 467 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 468 | 468 | } else { |
| 469 | - $invoice->remove_discount( 'discount_code' ); |
|
| 469 | + $invoice->remove_discount('discount_code'); |
|
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // Recalculate totals. |
| 474 | 474 | $invoice->recalculate_total(); |
| 475 | 475 | |
| 476 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
| 477 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 478 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
| 479 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
| 480 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
| 476 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
| 477 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 478 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
| 479 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
| 480 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | $totals = array( |
| 484 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
| 485 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
| 486 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
| 484 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
| 485 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
| 486 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
| 487 | 487 | 'total' => $total, |
| 488 | 488 | ); |
| 489 | 489 | |
| 490 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
| 490 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
| 491 | 491 | |
| 492 | - wp_send_json_success( compact( 'totals' ) ); |
|
| 492 | + wp_send_json_success(compact('totals')); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -498,33 +498,33 @@ discard block |
||
| 498 | 498 | public static function get_invoice_items() { |
| 499 | 499 | |
| 500 | 500 | // Verify nonce. |
| 501 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 501 | + check_ajax_referer('wpinv-nonce'); |
|
| 502 | 502 | |
| 503 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 503 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 504 | 504 | exit; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // We need an invoice and items. |
| 508 | - if ( empty( $_POST['post_id'] ) ) { |
|
| 508 | + if (empty($_POST['post_id'])) { |
|
| 509 | 509 | exit; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | // Fetch the invoice. |
| 513 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
| 513 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
| 514 | 514 | |
| 515 | 515 | // Ensure it exists. |
| 516 | - if ( ! $invoice->get_id() ) { |
|
| 516 | + if (!$invoice->get_id()) { |
|
| 517 | 517 | exit; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // Return an array of invoice items. |
| 521 | 521 | $items = array(); |
| 522 | 522 | |
| 523 | - foreach ( $invoice->get_items() as $item ) { |
|
| 524 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
| 523 | + foreach ($invoice->get_items() as $item) { |
|
| 524 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - wp_send_json_success( compact( 'items' ) ); |
|
| 527 | + wp_send_json_success(compact('items')); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -533,50 +533,50 @@ discard block |
||
| 533 | 533 | public static function edit_invoice_item() { |
| 534 | 534 | |
| 535 | 535 | // Verify nonce. |
| 536 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 536 | + check_ajax_referer('wpinv-nonce'); |
|
| 537 | 537 | |
| 538 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 538 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 539 | 539 | exit; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | // We need an invoice and item details. |
| 543 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
| 543 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
| 544 | 544 | exit; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | // Fetch the invoice. |
| 548 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
| 548 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
| 549 | 549 | |
| 550 | 550 | // Ensure it exists and its not been paid for. |
| 551 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 551 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 552 | 552 | exit; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | // Format the data. |
| 556 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
| 556 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
| 557 | 557 | |
| 558 | 558 | // Ensure that we have an item id. |
| 559 | - if ( empty( $data['id'] ) ) { |
|
| 559 | + if (empty($data['id'])) { |
|
| 560 | 560 | exit; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | // Abort if the invoice does not have the specified item. |
| 564 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
| 564 | + $item = $invoice->get_item((int) $data['id']); |
|
| 565 | 565 | |
| 566 | - if ( empty( $item ) ) { |
|
| 566 | + if (empty($item)) { |
|
| 567 | 567 | exit; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | // Update the item. |
| 571 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
| 572 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
| 573 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
| 574 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
| 571 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
| 572 | + $item->set_name(sanitize_text_field($data['name'])); |
|
| 573 | + $item->set_description(wp_kses_post($data['description'])); |
|
| 574 | + $item->set_quantity(floatval($data['quantity'])); |
|
| 575 | 575 | |
| 576 | 576 | // Add it to the invoice. |
| 577 | - $error = $invoice->add_item( $item ); |
|
| 577 | + $error = $invoice->add_item($item); |
|
| 578 | 578 | $alert = false; |
| 579 | - if ( is_wp_error( $error ) ) { |
|
| 579 | + if (is_wp_error($error)) { |
|
| 580 | 580 | $alert = $error->get_error_message(); |
| 581 | 581 | } |
| 582 | 582 | |
@@ -589,11 +589,11 @@ discard block |
||
| 589 | 589 | // Return an array of invoice items. |
| 590 | 590 | $items = array(); |
| 591 | 591 | |
| 592 | - foreach ( $invoice->get_items() as $item ) { |
|
| 593 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
| 592 | + foreach ($invoice->get_items() as $item) { |
|
| 593 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
| 596 | + wp_send_json_success(compact('items', 'alert')); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -602,53 +602,53 @@ discard block |
||
| 602 | 602 | public static function create_invoice_item() { |
| 603 | 603 | |
| 604 | 604 | // Verify nonce. |
| 605 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 605 | + check_ajax_referer('wpinv-nonce'); |
|
| 606 | 606 | |
| 607 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 607 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 608 | 608 | exit; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | // We need an invoice and item details. |
| 612 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
| 612 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
| 613 | 613 | exit; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | // Fetch the invoice. |
| 617 | - $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) ); |
|
| 617 | + $invoice = new WPInv_Invoice(intval($_POST['invoice_id'])); |
|
| 618 | 618 | |
| 619 | 619 | // Ensure it exists and its not been paid for. |
| 620 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 620 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 621 | 621 | exit; |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | // Format the data. |
| 625 | - $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) ); |
|
| 625 | + $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick'])); |
|
| 626 | 626 | |
| 627 | 627 | $item = new WPInv_Item(); |
| 628 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
| 629 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
| 630 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
| 631 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
| 632 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
| 633 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
| 634 | - $item->set_status( 'publish' ); |
|
| 628 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
| 629 | + $item->set_name(sanitize_text_field($data['name'])); |
|
| 630 | + $item->set_description(wp_kses_post($data['description'])); |
|
| 631 | + $item->set_type(sanitize_text_field($data['type'])); |
|
| 632 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
| 633 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
| 634 | + $item->set_status('publish'); |
|
| 635 | 635 | $item->save(); |
| 636 | 636 | |
| 637 | - if ( ! $item->exists() ) { |
|
| 638 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
| 639 | - wp_send_json_success( compact( 'alert' ) ); |
|
| 637 | + if (!$item->exists()) { |
|
| 638 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
| 639 | + wp_send_json_success(compact('alert')); |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
| 643 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
| 642 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
| 643 | + $item->set_quantity(floatval($data['qty'])); |
|
| 644 | 644 | |
| 645 | 645 | // Add it to the invoice. |
| 646 | - $error = $invoice->add_item( $item ); |
|
| 646 | + $error = $invoice->add_item($item); |
|
| 647 | 647 | $alert = false; |
| 648 | 648 | |
| 649 | - if ( is_wp_error( $error ) ) { |
|
| 649 | + if (is_wp_error($error)) { |
|
| 650 | 650 | $alert = $error->get_error_message(); |
| 651 | - wp_send_json_success( compact( 'alert' ) ); |
|
| 651 | + wp_send_json_success(compact('alert')); |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | // Update totals. |
@@ -661,9 +661,9 @@ discard block |
||
| 661 | 661 | $invoice->recalculate_total(); |
| 662 | 662 | $invoice->save(); |
| 663 | 663 | ob_start(); |
| 664 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
| 664 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
| 665 | 665 | $row = ob_get_clean(); |
| 666 | - wp_send_json_success( compact( 'row' ) ); |
|
| 666 | + wp_send_json_success(compact('row')); |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -672,33 +672,33 @@ discard block |
||
| 672 | 672 | public static function remove_invoice_item() { |
| 673 | 673 | |
| 674 | 674 | // Verify nonce. |
| 675 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 675 | + check_ajax_referer('wpinv-nonce'); |
|
| 676 | 676 | |
| 677 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 677 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 678 | 678 | exit; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | // We need an invoice and an item. |
| 682 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
| 682 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
| 683 | 683 | exit; |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | // Fetch the invoice. |
| 687 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
| 687 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
| 688 | 688 | |
| 689 | 689 | // Ensure it exists and its not been paid for. |
| 690 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 690 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 691 | 691 | exit; |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | // Abort if the invoice does not have the specified item. |
| 695 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
| 695 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
| 696 | 696 | |
| 697 | - if ( empty( $item ) ) { |
|
| 697 | + if (empty($item)) { |
|
| 698 | 698 | exit; |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
| 701 | + $invoice->remove_item((int) $_POST['item_id']); |
|
| 702 | 702 | |
| 703 | 703 | // Update totals. |
| 704 | 704 | $invoice->recalculate_total(); |
@@ -709,11 +709,11 @@ discard block |
||
| 709 | 709 | // Return an array of invoice items. |
| 710 | 710 | $items = array(); |
| 711 | 711 | |
| 712 | - foreach ( $invoice->get_items() as $item ) { |
|
| 713 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
| 712 | + foreach ($invoice->get_items() as $item) { |
|
| 713 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - wp_send_json_success( compact( 'items' ) ); |
|
| 716 | + wp_send_json_success(compact('items')); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -722,68 +722,68 @@ discard block |
||
| 722 | 722 | public static function recalculate_full_prices() { |
| 723 | 723 | |
| 724 | 724 | // Verify nonce. |
| 725 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 725 | + check_ajax_referer('wpinv-nonce'); |
|
| 726 | 726 | |
| 727 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 727 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 728 | 728 | exit; |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | // We need an invoice and item. |
| 732 | - if ( empty( $_POST['post_id'] ) ) { |
|
| 732 | + if (empty($_POST['post_id'])) { |
|
| 733 | 733 | exit; |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | // Fetch the invoice. |
| 737 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
| 737 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
| 738 | 738 | $alert = false; |
| 739 | 739 | |
| 740 | 740 | // Ensure it exists and its not been paid for. |
| 741 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 741 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 742 | 742 | exit; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - $invoice->set_items( array() ); |
|
| 745 | + $invoice->set_items(array()); |
|
| 746 | 746 | |
| 747 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
| 747 | + if (!empty($_POST['getpaid_items'])) { |
|
| 748 | 748 | |
| 749 | - foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) { |
|
| 750 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 749 | + foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) { |
|
| 750 | + $item = new GetPaid_Form_Item($item_id); |
|
| 751 | 751 | |
| 752 | - if ( $item->exists() ) { |
|
| 753 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
| 754 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
| 755 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
| 756 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
| 757 | - $invoice->add_item( $item ); |
|
| 752 | + if ($item->exists()) { |
|
| 753 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
| 754 | + $item->set_quantity(floatval($args['quantity'])); |
|
| 755 | + $item->set_name(sanitize_text_field($args['name'])); |
|
| 756 | + $item->set_description(wp_kses_post($args['description'])); |
|
| 757 | + $invoice->add_item($item); |
|
| 758 | 758 | } |
| 759 | 759 | } |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
| 762 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
| 763 | 763 | |
| 764 | 764 | // Maybe set the country, state, currency. |
| 765 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
| 766 | - if ( isset( $_POST[ $key ] ) ) { |
|
| 767 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
| 765 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
| 766 | + if (isset($_POST[$key])) { |
|
| 767 | + $_key = str_replace('wpinv_', '', $key); |
|
| 768 | 768 | $method = "set_$_key"; |
| 769 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
| 769 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
| 770 | 770 | } |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 774 | - if ( $discount->exists() ) { |
|
| 775 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 773 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 774 | + if ($discount->exists()) { |
|
| 775 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 776 | 776 | } else { |
| 777 | - $invoice->remove_discount( 'discount_code' ); |
|
| 777 | + $invoice->remove_discount('discount_code'); |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | // Save the invoice. |
| 781 | 781 | $invoice->recalculate_total(); |
| 782 | 782 | $invoice->save(); |
| 783 | 783 | ob_start(); |
| 784 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
| 784 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
| 785 | 785 | $table = ob_get_clean(); |
| 786 | - wp_send_json_success( compact( 'table' ) ); |
|
| 786 | + wp_send_json_success(compact('table')); |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | /** |
@@ -792,42 +792,42 @@ discard block |
||
| 792 | 792 | public static function admin_add_invoice_item() { |
| 793 | 793 | |
| 794 | 794 | // Verify nonce. |
| 795 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 795 | + check_ajax_referer('wpinv-nonce'); |
|
| 796 | 796 | |
| 797 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 797 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 798 | 798 | exit; |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | // We need an invoice and item. |
| 802 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
| 802 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
| 803 | 803 | exit; |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | // Fetch the invoice. |
| 807 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
| 807 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
| 808 | 808 | $alert = false; |
| 809 | 809 | |
| 810 | 810 | // Ensure it exists and its not been paid for. |
| 811 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 811 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 812 | 812 | exit; |
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | // Add the item. |
| 816 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
| 817 | - $error = $invoice->add_item( $item ); |
|
| 816 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
| 817 | + $error = $invoice->add_item($item); |
|
| 818 | 818 | |
| 819 | - if ( is_wp_error( $error ) ) { |
|
| 819 | + if (is_wp_error($error)) { |
|
| 820 | 820 | $alert = $error->get_error_message(); |
| 821 | - wp_send_json_success( compact( 'alert' ) ); |
|
| 821 | + wp_send_json_success(compact('alert')); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | // Save the invoice. |
| 825 | 825 | $invoice->recalculate_total(); |
| 826 | 826 | $invoice->save(); |
| 827 | 827 | ob_start(); |
| 828 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
| 828 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
| 829 | 829 | $row = ob_get_clean(); |
| 830 | - wp_send_json_success( compact( 'row' ) ); |
|
| 830 | + wp_send_json_success(compact('row')); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
@@ -836,39 +836,39 @@ discard block |
||
| 836 | 836 | public static function add_invoice_items() { |
| 837 | 837 | |
| 838 | 838 | // Verify nonce. |
| 839 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 839 | + check_ajax_referer('wpinv-nonce'); |
|
| 840 | 840 | |
| 841 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 841 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 842 | 842 | exit; |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | // We need an invoice and items. |
| 846 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
| 846 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
| 847 | 847 | exit; |
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | // Fetch the invoice. |
| 851 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
| 851 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
| 852 | 852 | $alert = false; |
| 853 | 853 | |
| 854 | 854 | // Ensure it exists and its not been paid for. |
| 855 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 855 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 856 | 856 | exit; |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | // Add the items. |
| 860 | - foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) { |
|
| 860 | + foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) { |
|
| 861 | 861 | |
| 862 | - $item = new GetPaid_Form_Item( (int) $data['id'] ); |
|
| 862 | + $item = new GetPaid_Form_Item((int) $data['id']); |
|
| 863 | 863 | |
| 864 | - if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) { |
|
| 865 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
| 864 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
| 865 | + $item->set_quantity(floatval($data['qty'])); |
|
| 866 | 866 | } |
| 867 | 867 | |
| 868 | - if ( $item->get_id() > 0 ) { |
|
| 869 | - $error = $invoice->add_item( $item ); |
|
| 868 | + if ($item->get_id() > 0) { |
|
| 869 | + $error = $invoice->add_item($item); |
|
| 870 | 870 | |
| 871 | - if ( is_wp_error( $error ) ) { |
|
| 871 | + if (is_wp_error($error)) { |
|
| 872 | 872 | $alert = $error->get_error_message(); |
| 873 | 873 | } |
| 874 | 874 | } |
@@ -881,11 +881,11 @@ discard block |
||
| 881 | 881 | // Return an array of invoice items. |
| 882 | 882 | $items = array(); |
| 883 | 883 | |
| 884 | - foreach ( $invoice->get_items() as $item ) { |
|
| 885 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
| 884 | + foreach ($invoice->get_items() as $item) { |
|
| 885 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
| 888 | + wp_send_json_success(compact('items', 'alert')); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | /** |
@@ -894,15 +894,15 @@ discard block |
||
| 894 | 894 | public static function get_invoicing_items() { |
| 895 | 895 | |
| 896 | 896 | // Verify nonce. |
| 897 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 897 | + check_ajax_referer('wpinv-nonce'); |
|
| 898 | 898 | |
| 899 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 899 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 900 | 900 | exit; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | // We need a search term. |
| 904 | - if ( empty( $_GET['search'] ) ) { |
|
| 905 | - wp_send_json_success( array() ); |
|
| 904 | + if (empty($_GET['search'])) { |
|
| 905 | + wp_send_json_success(array()); |
|
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | // Retrieve items. |
@@ -911,8 +911,8 @@ discard block |
||
| 911 | 911 | 'orderby' => 'title', |
| 912 | 912 | 'order' => 'ASC', |
| 913 | 913 | 'posts_per_page' => -1, |
| 914 | - 'post_status' => array( 'publish' ), |
|
| 915 | - 's' => sanitize_text_field( urldecode( $_GET['search'] ) ), |
|
| 914 | + 'post_status' => array('publish'), |
|
| 915 | + 's' => sanitize_text_field(urldecode($_GET['search'])), |
|
| 916 | 916 | 'meta_query' => array( |
| 917 | 917 | array( |
| 918 | 918 | 'key' => '_wpinv_type', |
@@ -922,25 +922,25 @@ discard block |
||
| 922 | 922 | ), |
| 923 | 923 | ); |
| 924 | 924 | |
| 925 | - if ( ! empty( $_GET['ignore'] ) ) { |
|
| 926 | - $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) ); |
|
| 925 | + if (!empty($_GET['ignore'])) { |
|
| 926 | + $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore'])); |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
| 929 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
| 930 | 930 | $data = array(); |
| 931 | 931 | |
| 932 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) ); |
|
| 932 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id'])); |
|
| 933 | 933 | |
| 934 | - foreach ( $items as $item ) { |
|
| 935 | - $item = new GetPaid_Form_Item( $item ); |
|
| 934 | + foreach ($items as $item) { |
|
| 935 | + $item = new GetPaid_Form_Item($item); |
|
| 936 | 936 | $data[] = array( |
| 937 | 937 | 'id' => (int) $item->get_id(), |
| 938 | - 'text' => strip_tags( $item->get_name() ), |
|
| 939 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
| 938 | + 'text' => strip_tags($item->get_name()), |
|
| 939 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
| 940 | 940 | ); |
| 941 | 941 | } |
| 942 | 942 | |
| 943 | - wp_send_json_success( $data ); |
|
| 943 | + wp_send_json_success($data); |
|
| 944 | 944 | |
| 945 | 945 | } |
| 946 | 946 | |
@@ -950,37 +950,37 @@ discard block |
||
| 950 | 950 | public static function get_customers() { |
| 951 | 951 | |
| 952 | 952 | // Verify nonce. |
| 953 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 953 | + check_ajax_referer('wpinv-nonce'); |
|
| 954 | 954 | |
| 955 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 955 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 956 | 956 | exit; |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | // We need a search term. |
| 960 | - if ( empty( $_GET['search'] ) ) { |
|
| 961 | - wp_send_json_success( array() ); |
|
| 960 | + if (empty($_GET['search'])) { |
|
| 961 | + wp_send_json_success(array()); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | // Retrieve customers. |
| 965 | 965 | |
| 966 | 966 | $customer_args = array( |
| 967 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
| 967 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
| 968 | 968 | 'orderby' => 'display_name', |
| 969 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
| 970 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 969 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
| 970 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
| 971 | 971 | ); |
| 972 | 972 | |
| 973 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
| 973 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
| 974 | 974 | $data = array(); |
| 975 | 975 | |
| 976 | - foreach ( $customers as $customer ) { |
|
| 976 | + foreach ($customers as $customer) { |
|
| 977 | 977 | $data[] = array( |
| 978 | 978 | 'id' => (int) $customer->ID, |
| 979 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
| 979 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
| 980 | 980 | ); |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | - wp_send_json_success( $data ); |
|
| 983 | + wp_send_json_success($data); |
|
| 984 | 984 | |
| 985 | 985 | } |
| 986 | 986 | |
@@ -990,28 +990,28 @@ discard block |
||
| 990 | 990 | public static function get_aui_states_field() { |
| 991 | 991 | |
| 992 | 992 | // Verify nonce. |
| 993 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 993 | + check_ajax_referer('wpinv-nonce'); |
|
| 994 | 994 | |
| 995 | 995 | // We need a country. |
| 996 | - if ( empty( $_GET['country'] ) ) { |
|
| 996 | + if (empty($_GET['country'])) { |
|
| 997 | 997 | exit; |
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
| 1001 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
| 1002 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
| 1003 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
| 1000 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
| 1001 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
| 1002 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
| 1003 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
| 1004 | 1004 | |
| 1005 | - if ( empty( $states ) ) { |
|
| 1005 | + if (empty($states)) { |
|
| 1006 | 1006 | |
| 1007 | 1007 | $html = aui()->input( |
| 1008 | 1008 | array( |
| 1009 | 1009 | 'type' => 'text', |
| 1010 | 1010 | 'id' => 'wpinv_state', |
| 1011 | 1011 | 'name' => $name, |
| 1012 | - 'label' => __( 'State', 'invoicing' ), |
|
| 1012 | + 'label' => __('State', 'invoicing'), |
|
| 1013 | 1013 | 'label_type' => 'vertical', |
| 1014 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
| 1014 | + 'placeholder' => __('State', 'invoicing'), |
|
| 1015 | 1015 | 'class' => $class, |
| 1016 | 1016 | 'value' => $state, |
| 1017 | 1017 | ) |
@@ -1023,9 +1023,9 @@ discard block |
||
| 1023 | 1023 | array( |
| 1024 | 1024 | 'id' => 'wpinv_state', |
| 1025 | 1025 | 'name' => $name, |
| 1026 | - 'label' => __( 'State', 'invoicing' ), |
|
| 1026 | + 'label' => __('State', 'invoicing'), |
|
| 1027 | 1027 | 'label_type' => 'vertical', |
| 1028 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
| 1028 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
| 1029 | 1029 | 'class' => $class, |
| 1030 | 1030 | 'value' => $state, |
| 1031 | 1031 | 'options' => $states, |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | wp_send_json_success( |
| 1040 | 1040 | array( |
| 1041 | 1041 | 'html' => $html, |
| 1042 | - 'select' => ! empty( $states ), |
|
| 1042 | + 'select' => !empty($states), |
|
| 1043 | 1043 | ) |
| 1044 | 1044 | ); |
| 1045 | 1045 | |
@@ -1053,11 +1053,11 @@ discard block |
||
| 1053 | 1053 | public static function payment_form_refresh_prices() { |
| 1054 | 1054 | |
| 1055 | 1055 | // Check nonce. |
| 1056 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
| 1056 | + check_ajax_referer('getpaid_form_nonce'); |
|
| 1057 | 1057 | |
| 1058 | 1058 | // ... form fields... |
| 1059 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 1060 | - esc_html_e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
| 1059 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
| 1060 | + esc_html_e('Error: Reload the page and try again.', 'invoicing'); |
|
| 1061 | 1061 | exit; |
| 1062 | 1062 | } |
| 1063 | 1063 | |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | $submission = new GetPaid_Payment_Form_Submission(); |
| 1066 | 1066 | |
| 1067 | 1067 | // Do we have an error? |
| 1068 | - if ( ! empty( $submission->last_error ) ) { |
|
| 1068 | + if (!empty($submission->last_error)) { |
|
| 1069 | 1069 | wp_send_json_error( |
| 1070 | 1070 | array( |
| 1071 | 1071 | 'code' => $submission->last_error_code, |
@@ -1075,12 +1075,12 @@ discard block |
||
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | // Prepare the response. |
| 1078 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
| 1078 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
| 1079 | 1079 | |
| 1080 | 1080 | // Filter the response. |
| 1081 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
| 1081 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
| 1082 | 1082 | |
| 1083 | - wp_send_json_success( $response ); |
|
| 1083 | + wp_send_json_success($response); |
|
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | /** |
@@ -1092,63 +1092,63 @@ discard block |
||
| 1092 | 1092 | public static function file_upload() { |
| 1093 | 1093 | |
| 1094 | 1094 | // Check nonce. |
| 1095 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
| 1095 | + check_ajax_referer('getpaid_form_nonce'); |
|
| 1096 | 1096 | |
| 1097 | - if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) { |
|
| 1098 | - wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 ); |
|
| 1097 | + if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) { |
|
| 1098 | + wp_die(esc_html_e('Bad Request', 'invoicing'), 400); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | // Fetch form. |
| 1102 | - $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) ); |
|
| 1102 | + $form = new GetPaid_Payment_Form(intval($_POST['form_id'])); |
|
| 1103 | 1103 | |
| 1104 | - if ( ! $form->is_active() ) { |
|
| 1105 | - wp_send_json_error( __( 'Payment form not active', 'invoicing' ) ); |
|
| 1104 | + if (!$form->is_active()) { |
|
| 1105 | + wp_send_json_error(__('Payment form not active', 'invoicing')); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | // Fetch appropriate field. |
| 1109 | - $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) ); |
|
| 1110 | - if ( empty( $upload_field ) ) { |
|
| 1111 | - wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) ); |
|
| 1109 | + $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name'])))); |
|
| 1110 | + if (empty($upload_field)) { |
|
| 1111 | + wp_send_json_error(__('Invalid upload field.', 'invoicing')); |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | // Prepare allowed file types. |
| 1115 | - $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' ); |
|
| 1115 | + $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png'); |
|
| 1116 | 1116 | $all_types = getpaid_get_allowed_mime_types(); |
| 1117 | 1117 | $mime_types = array(); |
| 1118 | 1118 | |
| 1119 | - foreach ( $file_types as $file_type ) { |
|
| 1120 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
| 1121 | - $mime_types[] = $all_types[ $file_type ]; |
|
| 1119 | + foreach ($file_types as $file_type) { |
|
| 1120 | + if (isset($all_types[$file_type])) { |
|
| 1121 | + $mime_types[] = $all_types[$file_type]; |
|
| 1122 | 1122 | } |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | - if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) { |
|
| 1126 | - wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) ); |
|
| 1125 | + if (!in_array($_FILES['file']['type'], $mime_types)) { |
|
| 1126 | + wp_send_json_error(__('Unsupported file type.', 'invoicing')); |
|
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | 1129 | // Upload file. |
| 1130 | - $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) ); |
|
| 1131 | - $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name ); |
|
| 1130 | + $file_name = explode('.', strtolower($_FILES['file']['name'])); |
|
| 1131 | + $file_name = uniqid('getpaid-') . '.' . array_pop($file_name); |
|
| 1132 | 1132 | |
| 1133 | 1133 | $uploaded = wp_upload_bits( |
| 1134 | 1134 | $file_name, |
| 1135 | 1135 | null, |
| 1136 | - file_get_contents( $_FILES['file']['tmp_name'] ) |
|
| 1136 | + file_get_contents($_FILES['file']['tmp_name']) |
|
| 1137 | 1137 | ); |
| 1138 | 1138 | |
| 1139 | - if ( ! empty( $uploaded['error'] ) ) { |
|
| 1140 | - wp_send_json_error( $uploaded['error'] ); |
|
| 1139 | + if (!empty($uploaded['error'])) { |
|
| 1140 | + wp_send_json_error($uploaded['error']); |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | // Retrieve response. |
| 1144 | 1144 | $response = sprintf( |
| 1145 | 1145 | '<input type="hidden" name="%s[%s]" value="%s" />', |
| 1146 | - esc_attr( sanitize_text_field( $_POST['field_name'] ) ), |
|
| 1147 | - esc_url( $uploaded['url'] ), |
|
| 1148 | - esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) ) |
|
| 1146 | + esc_attr(sanitize_text_field($_POST['field_name'])), |
|
| 1147 | + esc_url($uploaded['url']), |
|
| 1148 | + esc_attr(sanitize_text_field(strtolower($_FILES['file']['name']))) |
|
| 1149 | 1149 | ); |
| 1150 | 1150 | |
| 1151 | - wp_send_json_success( $response ); |
|
| 1151 | + wp_send_json_success($response); |
|
| 1152 | 1152 | |
| 1153 | 1153 | } |
| 1154 | 1154 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -14,18 +14,18 @@ discard block |
||
| 14 | 14 | * Hook in methods. |
| 15 | 15 | */ |
| 16 | 16 | public static function init() { |
| 17 | - add_action( 'init', array( __CLASS__, 'init_hooks' ), 0 ); |
|
| 18 | - add_action( 'admin_notices', array( __CLASS__, 'notices' ) ); |
|
| 17 | + add_action('init', array(__CLASS__, 'init_hooks'), 0); |
|
| 18 | + add_action('admin_notices', array(__CLASS__, 'notices')); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public static function init_hooks() { |
| 22 | - if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) { |
|
| 23 | - $checkout_page = wpinv_get_option( 'checkout_page', '' ); |
|
| 24 | - $success_page = wpinv_get_option( 'success_page', '' ); |
|
| 25 | - $failure_page = wpinv_get_option( 'failure_page', '' ); |
|
| 26 | - $history_page = wpinv_get_option( 'invoice_history_page', '' ); |
|
| 27 | - $subscr_page = wpinv_get_option( 'invoice_subscription_page', '' ); |
|
| 28 | - if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) { |
|
| 22 | + if (false === ($page_uris = get_transient('wpinv_cache_excluded_uris'))) { |
|
| 23 | + $checkout_page = wpinv_get_option('checkout_page', ''); |
|
| 24 | + $success_page = wpinv_get_option('success_page', ''); |
|
| 25 | + $failure_page = wpinv_get_option('failure_page', ''); |
|
| 26 | + $history_page = wpinv_get_option('invoice_history_page', ''); |
|
| 27 | + $subscr_page = wpinv_get_option('invoice_subscription_page', ''); |
|
| 28 | + if (empty($checkout_page) || empty($success_page) || empty($failure_page) || empty($history_page) || empty($subscr_page)) { |
|
| 29 | 29 | return; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -39,34 +39,34 @@ discard block |
||
| 39 | 39 | $page_uris[] = 'p=' . $subscr_page; |
| 40 | 40 | |
| 41 | 41 | // Exclude permalinks |
| 42 | - $checkout_page = get_post( $checkout_page ); |
|
| 43 | - $success_page = get_post( $success_page ); |
|
| 44 | - $failure_page = get_post( $failure_page ); |
|
| 45 | - $history_page = get_post( $history_page ); |
|
| 46 | - $subscr_page = get_post( $subscr_page ); |
|
| 42 | + $checkout_page = get_post($checkout_page); |
|
| 43 | + $success_page = get_post($success_page); |
|
| 44 | + $failure_page = get_post($failure_page); |
|
| 45 | + $history_page = get_post($history_page); |
|
| 46 | + $subscr_page = get_post($subscr_page); |
|
| 47 | 47 | |
| 48 | - if ( ! is_null( $checkout_page ) ) { |
|
| 48 | + if (!is_null($checkout_page)) { |
|
| 49 | 49 | $page_uris[] = '/' . $checkout_page->post_name; |
| 50 | 50 | } |
| 51 | - if ( ! is_null( $success_page ) ) { |
|
| 51 | + if (!is_null($success_page)) { |
|
| 52 | 52 | $page_uris[] = '/' . $success_page->post_name; |
| 53 | 53 | } |
| 54 | - if ( ! is_null( $failure_page ) ) { |
|
| 54 | + if (!is_null($failure_page)) { |
|
| 55 | 55 | $page_uris[] = '/' . $failure_page->post_name; |
| 56 | 56 | } |
| 57 | - if ( ! is_null( $history_page ) ) { |
|
| 57 | + if (!is_null($history_page)) { |
|
| 58 | 58 | $page_uris[] = '/' . $history_page->post_name; |
| 59 | 59 | } |
| 60 | - if ( ! is_null( $subscr_page ) ) { |
|
| 60 | + if (!is_null($subscr_page)) { |
|
| 61 | 61 | $page_uris[] = '/' . $subscr_page->post_name; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - set_transient( 'wpinv_cache_excluded_uris', $page_uris ); |
|
| 64 | + set_transient('wpinv_cache_excluded_uris', $page_uris); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ( is_array( $page_uris ) ) { |
|
| 68 | - foreach ( $page_uris as $uri ) { |
|
| 69 | - if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) { |
|
| 67 | + if (is_array($page_uris)) { |
|
| 68 | + foreach ($page_uris as $uri) { |
|
| 69 | + if (strstr($_SERVER['REQUEST_URI'], $uri)) { |
|
| 70 | 70 | self::nocache(); |
| 71 | 71 | break; |
| 72 | 72 | } |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | * @access private |
| 80 | 80 | */ |
| 81 | 81 | private static function nocache() { |
| 82 | - if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
|
| 83 | - define( 'DONOTCACHEPAGE', true ); |
|
| 82 | + if (!defined('DONOTCACHEPAGE')) { |
|
| 83 | + define('DONOTCACHEPAGE', true); |
|
| 84 | 84 | } |
| 85 | - if ( ! defined( 'DONOTCACHEOBJECT' ) ) { |
|
| 86 | - define( 'DONOTCACHEOBJECT', true ); |
|
| 85 | + if (!defined('DONOTCACHEOBJECT')) { |
|
| 86 | + define('DONOTCACHEOBJECT', true); |
|
| 87 | 87 | } |
| 88 | - if ( ! defined( 'DONOTCACHEDB' ) ) { |
|
| 89 | - define( 'DONOTCACHEDB', true ); |
|
| 88 | + if (!defined('DONOTCACHEDB')) { |
|
| 89 | + define('DONOTCACHEDB', true); |
|
| 90 | 90 | } |
| 91 | 91 | nocache_headers(); |
| 92 | 92 | } |
@@ -95,18 +95,18 @@ discard block |
||
| 95 | 95 | * notices function. |
| 96 | 96 | */ |
| 97 | 97 | public static function notices() { |
| 98 | - if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) { |
|
| 98 | + if (!function_exists('w3tc_pgcache_flush') || !function_exists('w3_instance')) { |
|
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $config = w3_instance( 'W3_Config' ); |
|
| 103 | - $enabled = $config->get_integer( 'dbcache.enabled' ); |
|
| 104 | - $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) ); |
|
| 102 | + $config = w3_instance('W3_Config'); |
|
| 103 | + $enabled = $config->get_integer('dbcache.enabled'); |
|
| 104 | + $settings = array_map('trim', $config->get_array('dbcache.reject.sql')); |
|
| 105 | 105 | |
| 106 | - if ( $enabled && ! in_array( '_wp_session_', $settings ) ) { |
|
| 106 | + if ($enabled && !in_array('_wp_session_', $settings)) { |
|
| 107 | 107 | ?> |
| 108 | 108 | <div class="error"> |
| 109 | - <p><?php printf( wp_kses_post( __( 'In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing' ) ), '<code>_wp_session_</code>', esc_url( admin_url( 'admin.php?page=w3tc_dbcache' ) ) ); ?></p> |
|
| 109 | + <p><?php printf(wp_kses_post(__('In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing')), '<code>_wp_session_</code>', esc_url(admin_url('admin.php?page=w3tc_dbcache'))); ?></p> |
|
| 110 | 110 | </div> |
| 111 | 111 | <?php |
| 112 | 112 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Are we supporting item quantities? |
@@ -20,35 +20,35 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | function wpinv_get_ip() { |
| 22 | 22 | |
| 23 | - if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { |
|
| 24 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); |
|
| 23 | + if (isset($_SERVER['HTTP_X_REAL_IP'])) { |
|
| 24 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REAL_IP'])); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
| 27 | + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 28 | 28 | // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
| 29 | 29 | // Make sure we always only send through the first IP in the list which should always be the client IP. |
| 30 | - return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); |
|
| 30 | + return (string) rest_is_ip_address(trim(current(preg_split('/,/', sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR'])))))); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
| 34 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) ); |
|
| 33 | + if (isset($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 34 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP'])); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
|
| 38 | - return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); |
|
| 37 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
| 38 | + return sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | return ''; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | function wpinv_get_user_agent() { |
| 45 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
| 46 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
| 45 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
| 46 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
| 47 | 47 | } else { |
| 48 | 48 | $user_agent = ''; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
| 51 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | * @param string $amount The amount to sanitize. |
| 58 | 58 | * @return float |
| 59 | 59 | */ |
| 60 | -function getpaid_standardize_amount( $amount ) { |
|
| 60 | +function getpaid_standardize_amount($amount) { |
|
| 61 | 61 | |
| 62 | - $amount = str_replace( wpinv_thousands_separator(), '', $amount ); |
|
| 63 | - $amount = str_replace( wpinv_decimal_separator(), '.', $amount ); |
|
| 64 | - if ( is_numeric( $amount ) ) { |
|
| 65 | - return floatval( $amount ); |
|
| 62 | + $amount = str_replace(wpinv_thousands_separator(), '', $amount); |
|
| 63 | + $amount = str_replace(wpinv_decimal_separator(), '.', $amount); |
|
| 64 | + if (is_numeric($amount)) { |
|
| 65 | + return floatval($amount); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Cast the remaining to a float. |
| 69 | - return wpinv_round_amount( preg_replace( '/[^0-9\.\-]/', '', $amount ) ); |
|
| 69 | + return wpinv_round_amount(preg_replace('/[^0-9\.\-]/', '', $amount)); |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @param string $amount The amount to sanitize. |
| 77 | 77 | */ |
| 78 | -function getpaid_unstandardize_amount( $amount ) { |
|
| 79 | - return str_replace( '.', wpinv_decimal_separator(), $amount ); |
|
| 78 | +function getpaid_unstandardize_amount($amount) { |
|
| 79 | + return str_replace('.', wpinv_decimal_separator(), $amount); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -84,23 +84,23 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @param string $amount The amount to sanitize. |
| 86 | 86 | */ |
| 87 | -function wpinv_sanitize_amount( $amount ) { |
|
| 87 | +function wpinv_sanitize_amount($amount) { |
|
| 88 | 88 | |
| 89 | - if ( is_numeric( $amount ) ) { |
|
| 90 | - return floatval( $amount ); |
|
| 89 | + if (is_numeric($amount)) { |
|
| 90 | + return floatval($amount); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Separate the decimals and thousands. |
| 94 | - $amount = explode( wpinv_decimal_separator(), $amount ); |
|
| 94 | + $amount = explode(wpinv_decimal_separator(), $amount); |
|
| 95 | 95 | |
| 96 | 96 | // Remove thousands. |
| 97 | - $amount[0] = str_replace( wpinv_thousands_separator(), '', $amount[0] ); |
|
| 97 | + $amount[0] = str_replace(wpinv_thousands_separator(), '', $amount[0]); |
|
| 98 | 98 | |
| 99 | 99 | // Convert back to string. |
| 100 | - $amount = count( $amount ) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
| 100 | + $amount = count($amount) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
| 101 | 101 | |
| 102 | 102 | // Cast the remaining to a float. |
| 103 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
| 103 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * @param float $amount |
| 111 | 111 | * @param float|string|int|null $decimals |
| 112 | 112 | */ |
| 113 | -function wpinv_round_amount( $amount, $decimals = null, $use_sprintf = false ) { |
|
| 113 | +function wpinv_round_amount($amount, $decimals = null, $use_sprintf = false) { |
|
| 114 | 114 | |
| 115 | - if ( $decimals === null ) { |
|
| 115 | + if ($decimals === null) { |
|
| 116 | 116 | $decimals = wpinv_decimals(); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if ( $use_sprintf ) { |
|
| 120 | - $amount = sprintf( "%.{$decimals}f", (float) $amount ); |
|
| 119 | + if ($use_sprintf) { |
|
| 120 | + $amount = sprintf("%.{$decimals}f", (float) $amount); |
|
| 121 | 121 | } else { |
| 122 | - $amount = round( (float) $amount, absint( $decimals ) ); |
|
| 122 | + $amount = round((float) $amount, absint($decimals)); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
| 125 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -134,32 +134,32 @@ discard block |
||
| 134 | 134 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
| 135 | 135 | * @return array |
| 136 | 136 | */ |
| 137 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
| 137 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
| 138 | 138 | |
| 139 | 139 | $invoice_statuses = array( |
| 140 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
| 141 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
| 142 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
| 143 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
| 144 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
| 145 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
| 146 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
| 147 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
| 140 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
| 141 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
| 142 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
| 143 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
| 144 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
| 145 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
| 146 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
| 147 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
| 148 | 148 | ); |
| 149 | 149 | |
| 150 | - if ( $draft ) { |
|
| 151 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
| 150 | + if ($draft) { |
|
| 151 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if ( $trashed ) { |
|
| 155 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
| 154 | + if ($trashed) { |
|
| 155 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( $invoice instanceof WPInv_Invoice ) { |
|
| 158 | + if ($invoice instanceof WPInv_Invoice) { |
|
| 159 | 159 | $invoice = $invoice->get_post_type(); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
| 162 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | * @param string $status The raw status |
| 169 | 169 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
| 170 | 170 | */ |
| 171 | -function wpinv_status_nicename( $status, $invoice = false ) { |
|
| 172 | - $statuses = wpinv_get_invoice_statuses( true, true, $invoice ); |
|
| 173 | - $status = isset( $statuses[ $status ] ) ? $statuses[ $status ] : $status; |
|
| 171 | +function wpinv_status_nicename($status, $invoice = false) { |
|
| 172 | + $statuses = wpinv_get_invoice_statuses(true, true, $invoice); |
|
| 173 | + $status = isset($statuses[$status]) ? $statuses[$status] : $status; |
|
| 174 | 174 | |
| 175 | - return sanitize_text_field( $status ); |
|
| 175 | + return sanitize_text_field($status); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @param string $current |
| 182 | 182 | */ |
| 183 | -function wpinv_get_currency( $current = '' ) { |
|
| 183 | +function wpinv_get_currency($current = '') { |
|
| 184 | 184 | |
| 185 | - if ( empty( $current ) ) { |
|
| 186 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
| 185 | + if (empty($current)) { |
|
| 186 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - return trim( strtoupper( $current ) ); |
|
| 189 | + return trim(strtoupper($current)); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -194,25 +194,25 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @param string|null $currency The currency code. Defaults to the default currency. |
| 196 | 196 | */ |
| 197 | -function wpinv_currency_symbol( $currency = null ) { |
|
| 197 | +function wpinv_currency_symbol($currency = null) { |
|
| 198 | 198 | |
| 199 | 199 | // Prepare the currency. |
| 200 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
| 200 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
| 201 | 201 | |
| 202 | 202 | // Fetch all symbols. |
| 203 | 203 | $symbols = wpinv_get_currency_symbols(); |
| 204 | 204 | |
| 205 | 205 | // Fetch this currencies symbol. |
| 206 | - $currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : $currency; |
|
| 206 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
| 207 | 207 | |
| 208 | 208 | // Filter the symbol. |
| 209 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
| 209 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function wpinv_currency_position() { |
| 213 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
| 213 | + $position = wpinv_get_option('currency_position', 'left'); |
|
| 214 | 214 | |
| 215 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
| 215 | + return apply_filters('wpinv_currency_position', $position); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @param $string|null $current |
| 222 | 222 | */ |
| 223 | -function wpinv_thousands_separator( $current = null ) { |
|
| 223 | +function wpinv_thousands_separator($current = null) { |
|
| 224 | 224 | |
| 225 | - if ( null == $current ) { |
|
| 226 | - $current = wpinv_get_option( 'thousands_separator', ',' ); |
|
| 225 | + if (null == $current) { |
|
| 226 | + $current = wpinv_get_option('thousands_separator', ','); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - return trim( $current ); |
|
| 229 | + return trim($current); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -234,13 +234,13 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @param $string|null $current |
| 236 | 236 | */ |
| 237 | -function wpinv_decimal_separator( $current = null ) { |
|
| 237 | +function wpinv_decimal_separator($current = null) { |
|
| 238 | 238 | |
| 239 | - if ( null == $current ) { |
|
| 240 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
| 239 | + if (null == $current) { |
|
| 240 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - return trim( $current ); |
|
| 243 | + return trim($current); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -248,27 +248,27 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | * @param $string|null $current |
| 250 | 250 | */ |
| 251 | -function wpinv_decimals( $current = null ) { |
|
| 251 | +function wpinv_decimals($current = null) { |
|
| 252 | 252 | |
| 253 | - if ( null == $current ) { |
|
| 254 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
| 253 | + if (null == $current) { |
|
| 254 | + $current = wpinv_get_option('decimals', 2); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - return absint( $current ); |
|
| 257 | + return absint($current); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * Retrieves a list of all supported currencies. |
| 262 | 262 | */ |
| 263 | 263 | function wpinv_get_currencies() { |
| 264 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
| 264 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
| 268 | 268 | * Retrieves a list of all currency symbols. |
| 269 | 269 | */ |
| 270 | 270 | function wpinv_get_currency_symbols() { |
| 271 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
| 271 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $currency_pos = wpinv_currency_position(); |
| 281 | 281 | $format = '%1$s%2$s'; |
| 282 | 282 | |
| 283 | - switch ( $currency_pos ) { |
|
| 283 | + switch ($currency_pos) { |
|
| 284 | 284 | case 'left': |
| 285 | 285 | $format = '%1$s%2$s'; |
| 286 | 286 | break; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | break; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
| 298 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | * @param string $currency Currency. |
| 306 | 306 | * @return string |
| 307 | 307 | */ |
| 308 | -function wpinv_the_price( $amount = 0, $currency = '' ) { |
|
| 309 | - echo wp_kses_post( wpinv_price( $amount, $currency ) ); |
|
| 308 | +function wpinv_the_price($amount = 0, $currency = '') { |
|
| 309 | + echo wp_kses_post(wpinv_price($amount, $currency)); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -316,25 +316,25 @@ discard block |
||
| 316 | 316 | * @param string $currency Currency. |
| 317 | 317 | * @return string |
| 318 | 318 | */ |
| 319 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
| 319 | +function wpinv_price($amount = 0, $currency = '') { |
|
| 320 | 320 | |
| 321 | 321 | // Backwards compatibility. |
| 322 | - $amount = wpinv_sanitize_amount( $amount ); |
|
| 322 | + $amount = wpinv_sanitize_amount($amount); |
|
| 323 | 323 | |
| 324 | 324 | // Prepare variables. |
| 325 | - $currency = wpinv_get_currency( $currency ); |
|
| 325 | + $currency = wpinv_get_currency($currency); |
|
| 326 | 326 | $amount = (float) $amount; |
| 327 | 327 | $unformatted_amount = $amount; |
| 328 | 328 | $negative = $amount < 0; |
| 329 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
| 330 | - $amount = wpinv_format_amount( $amount ); |
|
| 329 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
| 330 | + $amount = wpinv_format_amount($amount); |
|
| 331 | 331 | |
| 332 | 332 | // Format the amount. |
| 333 | 333 | $format = getpaid_get_price_format(); |
| 334 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
| 334 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
| 335 | 335 | |
| 336 | 336 | // Filter the formatting. |
| 337 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
| 337 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -345,25 +345,25 @@ discard block |
||
| 345 | 345 | * @param bool $calculate Whether or not to apply separators. |
| 346 | 346 | * @return string |
| 347 | 347 | */ |
| 348 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
| 348 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
| 349 | 349 | $thousands_sep = wpinv_thousands_separator(); |
| 350 | 350 | $decimal_sep = wpinv_decimal_separator(); |
| 351 | - $decimals = wpinv_decimals( $decimals ); |
|
| 352 | - $amount = wpinv_sanitize_amount( $amount ); |
|
| 351 | + $decimals = wpinv_decimals($decimals); |
|
| 352 | + $amount = wpinv_sanitize_amount($amount); |
|
| 353 | 353 | |
| 354 | - if ( $calculate ) { |
|
| 354 | + if ($calculate) { |
|
| 355 | 355 | return $amount; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | // Fomart the amount. |
| 359 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
| 359 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | -function wpinv_sanitize_key( $key ) { |
|
| 362 | +function wpinv_sanitize_key($key) { |
|
| 363 | 363 | $raw_key = $key; |
| 364 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
| 364 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
| 365 | 365 | |
| 366 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
| 366 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | * |
| 372 | 372 | * @param $str the file whose extension should be retrieved. |
| 373 | 373 | */ |
| 374 | -function wpinv_get_file_extension( $str ) { |
|
| 375 | - $filetype = wp_check_filetype( $str ); |
|
| 374 | +function wpinv_get_file_extension($str) { |
|
| 375 | + $filetype = wp_check_filetype($str); |
|
| 376 | 376 | return $filetype['ext']; |
| 377 | 377 | } |
| 378 | 378 | |
@@ -381,16 +381,16 @@ discard block |
||
| 381 | 381 | * |
| 382 | 382 | * @param string $string |
| 383 | 383 | */ |
| 384 | -function wpinv_string_is_image_url( $string ) { |
|
| 385 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
| 386 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
| 384 | +function wpinv_string_is_image_url($string) { |
|
| 385 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
| 386 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
| 390 | 390 | * Returns the current URL. |
| 391 | 391 | */ |
| 392 | 392 | function wpinv_get_current_page_url() { |
| 393 | - return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
| 393 | + return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -400,46 +400,46 @@ discard block |
||
| 400 | 400 | * @param string $name Constant name. |
| 401 | 401 | * @param mixed $value Value. |
| 402 | 402 | */ |
| 403 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
| 404 | - if ( ! defined( $name ) ) { |
|
| 405 | - define( $name, $value ); |
|
| 403 | +function getpaid_maybe_define_constant($name, $value) { |
|
| 404 | + if (!defined($name)) { |
|
| 405 | + define($name, $value); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | function wpinv_get_php_arg_separator_output() { |
| 410 | - return ini_get( 'arg_separator.output' ); |
|
| 410 | + return ini_get('arg_separator.output'); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | -function wpinv_rgb_from_hex( $color ) { |
|
| 414 | - $color = str_replace( '#', '', $color ); |
|
| 413 | +function wpinv_rgb_from_hex($color) { |
|
| 414 | + $color = str_replace('#', '', $color); |
|
| 415 | 415 | |
| 416 | 416 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
| 417 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
| 418 | - if ( empty( $color ) ) { |
|
| 417 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
| 418 | + if (empty($color)) { |
|
| 419 | 419 | return null; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - $color = str_split( $color ); |
|
| 422 | + $color = str_split($color); |
|
| 423 | 423 | |
| 424 | 424 | $rgb = array(); |
| 425 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
| 426 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
| 427 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
| 425 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
| 426 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
| 427 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
| 428 | 428 | |
| 429 | 429 | return $rgb; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
| 433 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 432 | +function wpinv_hex_darker($color, $factor = 30) { |
|
| 433 | + $base = wpinv_rgb_from_hex($color); |
|
| 434 | 434 | $color = '#'; |
| 435 | 435 | |
| 436 | - foreach ( $base as $k => $v ) { |
|
| 436 | + foreach ($base as $k => $v) { |
|
| 437 | 437 | $amount = $v / 100; |
| 438 | - $amount = round( $amount * $factor ); |
|
| 438 | + $amount = round($amount * $factor); |
|
| 439 | 439 | $new_decimal = $v - $amount; |
| 440 | 440 | |
| 441 | - $new_hex_component = dechex( $new_decimal ); |
|
| 442 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 441 | + $new_hex_component = dechex($new_decimal); |
|
| 442 | + if (strlen($new_hex_component) < 2) { |
|
| 443 | 443 | $new_hex_component = '0' . $new_hex_component; |
| 444 | 444 | } |
| 445 | 445 | $color .= $new_hex_component; |
@@ -448,18 +448,18 @@ discard block |
||
| 448 | 448 | return $color; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
| 452 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 451 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
| 452 | + $base = wpinv_rgb_from_hex($color); |
|
| 453 | 453 | $color = '#'; |
| 454 | 454 | |
| 455 | - foreach ( $base as $k => $v ) { |
|
| 455 | + foreach ($base as $k => $v) { |
|
| 456 | 456 | $amount = 255 - $v; |
| 457 | 457 | $amount = $amount / 100; |
| 458 | - $amount = round( $amount * $factor ); |
|
| 458 | + $amount = round($amount * $factor); |
|
| 459 | 459 | $new_decimal = $v + $amount; |
| 460 | 460 | |
| 461 | - $new_hex_component = dechex( $new_decimal ); |
|
| 462 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 461 | + $new_hex_component = dechex($new_decimal); |
|
| 462 | + if (strlen($new_hex_component) < 2) { |
|
| 463 | 463 | $new_hex_component = '0' . $new_hex_component; |
| 464 | 464 | } |
| 465 | 465 | $color .= $new_hex_component; |
@@ -468,22 +468,22 @@ discard block |
||
| 468 | 468 | return $color; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
| 472 | - $hex = str_replace( '#', '', $color ); |
|
| 471 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
| 472 | + $hex = str_replace('#', '', $color); |
|
| 473 | 473 | |
| 474 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 475 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 476 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 474 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
| 475 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
| 476 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
| 477 | 477 | |
| 478 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
| 478 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
| 479 | 479 | |
| 480 | 480 | return $brightness > 155 ? $dark : $light; |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | -function wpinv_format_hex( $hex ) { |
|
| 484 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
| 483 | +function wpinv_format_hex($hex) { |
|
| 484 | + $hex = trim(str_replace('#', '', $hex)); |
|
| 485 | 485 | |
| 486 | - if ( strlen( $hex ) == 3 ) { |
|
| 486 | + if (strlen($hex) == 3) { |
|
| 487 | 487 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
| 488 | 488 | } |
| 489 | 489 | |
@@ -503,12 +503,12 @@ discard block |
||
| 503 | 503 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 504 | 504 | * @return string |
| 505 | 505 | */ |
| 506 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
| 507 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 508 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
| 506 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
| 507 | + if (function_exists('mb_strimwidth')) { |
|
| 508 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
| 511 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -520,28 +520,28 @@ discard block |
||
| 520 | 520 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 521 | 521 | * @return int Returns the number of characters in string. |
| 522 | 522 | */ |
| 523 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
| 524 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 525 | - return mb_strlen( $str, $encoding ); |
|
| 523 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
| 524 | + if (function_exists('mb_strlen')) { |
|
| 525 | + return mb_strlen($str, $encoding); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - return strlen( $str ); |
|
| 528 | + return strlen($str); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
| 532 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
| 533 | - return mb_strtolower( $str, $encoding ); |
|
| 531 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
| 532 | + if (function_exists('mb_strtolower')) { |
|
| 533 | + return mb_strtolower($str, $encoding); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - return strtolower( $str ); |
|
| 536 | + return strtolower($str); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
| 540 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
| 541 | - return mb_strtoupper( $str, $encoding ); |
|
| 539 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
| 540 | + if (function_exists('mb_strtoupper')) { |
|
| 541 | + return mb_strtoupper($str, $encoding); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - return strtoupper( $str ); |
|
| 544 | + return strtoupper($str); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -555,12 +555,12 @@ discard block |
||
| 555 | 555 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 556 | 556 | * @return int Returns the position of the first occurrence of search in the string. |
| 557 | 557 | */ |
| 558 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 559 | - if ( function_exists( 'mb_strpos' ) ) { |
|
| 560 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
| 558 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 559 | + if (function_exists('mb_strpos')) { |
|
| 560 | + return mb_strpos($str, $find, $offset, $encoding); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - return strpos( $str, $find, $offset ); |
|
| 563 | + return strpos($str, $find, $offset); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -574,12 +574,12 @@ discard block |
||
| 574 | 574 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 575 | 575 | * @return int Returns the position of the last occurrence of search. |
| 576 | 576 | */ |
| 577 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 578 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
| 579 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
| 577 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 578 | + if (function_exists('mb_strrpos')) { |
|
| 579 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - return strrpos( $str, $find, $offset ); |
|
| 582 | + return strrpos($str, $find, $offset); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -594,16 +594,16 @@ discard block |
||
| 594 | 594 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 595 | 595 | * @return string |
| 596 | 596 | */ |
| 597 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
| 598 | - if ( function_exists( 'mb_substr' ) ) { |
|
| 599 | - if ( $length === null ) { |
|
| 600 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 597 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
| 598 | + if (function_exists('mb_substr')) { |
|
| 599 | + if ($length === null) { |
|
| 600 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 601 | 601 | } else { |
| 602 | - return mb_substr( $str, $start, $length, $encoding ); |
|
| 602 | + return mb_substr($str, $start, $length, $encoding); |
|
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | - return substr( $str, $start, $length ); |
|
| 606 | + return substr($str, $start, $length); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -615,48 +615,48 @@ discard block |
||
| 615 | 615 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 616 | 616 | * @return string The width of string. |
| 617 | 617 | */ |
| 618 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
| 619 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
| 620 | - return mb_strwidth( $str, $encoding ); |
|
| 618 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
| 619 | + if (function_exists('mb_strwidth')) { |
|
| 620 | + return mb_strwidth($str, $encoding); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
| 623 | + return wpinv_utf8_strlen($str, $encoding); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
| 627 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 628 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
| 626 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
| 627 | + if (function_exists('mb_strlen')) { |
|
| 628 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
| 629 | 629 | $str_end = ''; |
| 630 | 630 | |
| 631 | - if ( $lower_str_end ) { |
|
| 632 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
| 631 | + if ($lower_str_end) { |
|
| 632 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
| 633 | 633 | } else { |
| 634 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 634 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | return $first_letter . $str_end; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - return ucfirst( $str ); |
|
| 640 | + return ucfirst($str); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
| 644 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
| 645 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
| 643 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
| 644 | + if (function_exists('mb_convert_case')) { |
|
| 645 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - return ucwords( $str ); |
|
| 648 | + return ucwords($str); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | -function wpinv_period_in_days( $period, $unit ) { |
|
| 652 | - $period = absint( $period ); |
|
| 651 | +function wpinv_period_in_days($period, $unit) { |
|
| 652 | + $period = absint($period); |
|
| 653 | 653 | |
| 654 | - if ( $period > 0 ) { |
|
| 655 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
| 654 | + if ($period > 0) { |
|
| 655 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
| 656 | 656 | $period = $period * 7; |
| 657 | - } elseif ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
| 657 | + } elseif (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
| 658 | 658 | $period = $period * 30; |
| 659 | - } elseif ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
| 659 | + } elseif (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
| 660 | 660 | $period = $period * 365; |
| 661 | 661 | } |
| 662 | 662 | } |
@@ -664,14 +664,14 @@ discard block |
||
| 664 | 664 | return $period; |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
| 668 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
| 669 | - return cal_days_in_month( $calendar, $month, $year ); |
|
| 667 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
| 668 | + if (function_exists('cal_days_in_month')) { |
|
| 669 | + return cal_days_in_month($calendar, $month, $year); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | // Fallback in case the calendar extension is not loaded in PHP |
| 673 | 673 | // Only supports Gregorian calendar |
| 674 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
| 674 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
@@ -682,27 +682,27 @@ discard block |
||
| 682 | 682 | * |
| 683 | 683 | * @return string |
| 684 | 684 | */ |
| 685 | -function wpi_help_tip( $tip, $allow_html = false, $is_vue = false, $echo = false ) { |
|
| 685 | +function wpi_help_tip($tip, $allow_html = false, $is_vue = false, $echo = false) { |
|
| 686 | 686 | |
| 687 | - if ( $allow_html ) { |
|
| 688 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
| 687 | + if ($allow_html) { |
|
| 688 | + $tip = wpi_sanitize_tooltip($tip); |
|
| 689 | 689 | } else { |
| 690 | - $tip = strip_tags( $tip ); |
|
| 690 | + $tip = strip_tags($tip); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | - if ( $is_vue ) { |
|
| 693 | + if ($is_vue) { |
|
| 694 | 694 | |
| 695 | - if ( $echo ) { |
|
| 696 | - echo '<span class="dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
| 695 | + if ($echo) { |
|
| 696 | + echo '<span class="dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
| 697 | 697 | } else { |
| 698 | - return '<span class="dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
| 698 | + return '<span class="dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - if ( $echo ) { |
|
| 703 | - echo '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
| 702 | + if ($echo) { |
|
| 703 | + echo '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
| 704 | 704 | } else { |
| 705 | - return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
| 705 | + return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
| 706 | 706 | } |
| 707 | 707 | } |
| 708 | 708 | |
@@ -714,9 +714,9 @@ discard block |
||
| 714 | 714 | * @param string $var |
| 715 | 715 | * @return string |
| 716 | 716 | */ |
| 717 | -function wpi_sanitize_tooltip( $var ) { |
|
| 717 | +function wpi_sanitize_tooltip($var) { |
|
| 718 | 718 | return wp_kses( |
| 719 | - html_entity_decode( $var ), |
|
| 719 | + html_entity_decode($var), |
|
| 720 | 720 | array( |
| 721 | 721 | 'br' => array(), |
| 722 | 722 | 'em' => array(), |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | */ |
| 740 | 740 | function wpinv_get_screen_ids() { |
| 741 | 741 | |
| 742 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
| 742 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
| 743 | 743 | |
| 744 | 744 | $screen_ids = array( |
| 745 | 745 | 'toplevel_page_' . $screen_id, |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | 'gp-setup', // setup wizard |
| 762 | 762 | ); |
| 763 | 763 | |
| 764 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
| 764 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -772,14 +772,14 @@ discard block |
||
| 772 | 772 | * @param array|string $list List of values. |
| 773 | 773 | * @return array Sanitized array of values. |
| 774 | 774 | */ |
| 775 | -function wpinv_parse_list( $list ) { |
|
| 775 | +function wpinv_parse_list($list) { |
|
| 776 | 776 | |
| 777 | - if ( empty( $list ) ) { |
|
| 777 | + if (empty($list)) { |
|
| 778 | 778 | $list = array(); |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | - if ( ! is_array( $list ) ) { |
|
| 782 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 781 | + if (!is_array($list)) { |
|
| 782 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | return $list; |
@@ -793,16 +793,16 @@ discard block |
||
| 793 | 793 | * @param string $key Type of data to fetch. |
| 794 | 794 | * @return mixed Fetched data. |
| 795 | 795 | */ |
| 796 | -function wpinv_get_data( $key ) { |
|
| 796 | +function wpinv_get_data($key) { |
|
| 797 | 797 | |
| 798 | 798 | // Try fetching it from the cache. |
| 799 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
| 800 | - if ( $data ) { |
|
| 799 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
| 800 | + if ($data) { |
|
| 801 | 801 | return $data; |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
| 805 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
| 804 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
| 805 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
| 806 | 806 | |
| 807 | 807 | return $data; |
| 808 | 808 | } |
@@ -816,10 +816,10 @@ discard block |
||
| 816 | 816 | * @param bool $first_empty Whether or not the first item in the list should be empty |
| 817 | 817 | * @return mixed Fetched data. |
| 818 | 818 | */ |
| 819 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
| 819 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
| 820 | 820 | |
| 821 | - if ( ! empty( $options ) && $first_empty ) { |
|
| 822 | - return array_merge( array( '' => '' ), $options ); |
|
| 821 | + if (!empty($options) && $first_empty) { |
|
| 822 | + return array_merge(array('' => ''), $options); |
|
| 823 | 823 | } |
| 824 | 824 | return $options; |
| 825 | 825 | |
@@ -831,21 +831,21 @@ discard block |
||
| 831 | 831 | * @param mixed $var Data to sanitize. |
| 832 | 832 | * @return string|array |
| 833 | 833 | */ |
| 834 | -function wpinv_clean( $var ) { |
|
| 834 | +function wpinv_clean($var) { |
|
| 835 | 835 | |
| 836 | - if ( is_array( $var ) ) { |
|
| 837 | - return array_map( 'wpinv_clean', $var ); |
|
| 836 | + if (is_array($var)) { |
|
| 837 | + return array_map('wpinv_clean', $var); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | - if ( is_object( $var ) ) { |
|
| 841 | - $object_vars = get_object_vars( $var ); |
|
| 842 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 843 | - $var->$property_name = wpinv_clean( $property_value ); |
|
| 840 | + if (is_object($var)) { |
|
| 841 | + $object_vars = get_object_vars($var); |
|
| 842 | + foreach ($object_vars as $property_name => $property_value) { |
|
| 843 | + $var->$property_name = wpinv_clean($property_value); |
|
| 844 | 844 | } |
| 845 | 845 | return $var; |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | - return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
|
| 848 | + return is_string($var) ? sanitize_text_field(stripslashes($var)) : $var; |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -854,43 +854,43 @@ discard block |
||
| 854 | 854 | * @param string $str Data to convert. |
| 855 | 855 | * @return string|array |
| 856 | 856 | */ |
| 857 | -function getpaid_convert_price_string_to_options( $str ) { |
|
| 857 | +function getpaid_convert_price_string_to_options($str) { |
|
| 858 | 858 | |
| 859 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
| 860 | - $options = array(); |
|
| 859 | + $raw_options = array_map('trim', explode(',', $str)); |
|
| 860 | + $options = array(); |
|
| 861 | 861 | |
| 862 | - foreach ( $raw_options as $option ) { |
|
| 862 | + foreach ($raw_options as $option) { |
|
| 863 | 863 | |
| 864 | - if ( '' == $option ) { |
|
| 864 | + if ('' == $option) { |
|
| 865 | 865 | continue; |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
| 868 | + $option = array_map('trim', explode('|', $option)); |
|
| 869 | 869 | |
| 870 | 870 | $price = null; |
| 871 | 871 | $label = null; |
| 872 | 872 | |
| 873 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
| 874 | - $label = $option[0]; |
|
| 873 | + if (isset($option[0]) && '' != $option[0]) { |
|
| 874 | + $label = $option[0]; |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
| 877 | + if (isset($option[1]) && '' != $option[1]) { |
|
| 878 | 878 | $price = $option[1]; |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - if ( ! isset( $price ) ) { |
|
| 881 | + if (!isset($price)) { |
|
| 882 | 882 | $price = $label; |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
| 885 | + if (!isset($price) || !is_numeric($price)) { |
|
| 886 | 886 | continue; |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | - if ( ! isset( $label ) ) { |
|
| 889 | + if (!isset($label)) { |
|
| 890 | 890 | $label = $price; |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - $options[ "$label|$price" ] = $label; |
|
| 893 | + $options["$label|$price"] = $label; |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | return $options; |
@@ -899,14 +899,14 @@ discard block |
||
| 899 | 899 | /** |
| 900 | 900 | * Returns the help tip. |
| 901 | 901 | */ |
| 902 | -function getpaid_get_help_tip( $tip, $additional_classes = '', $echo = false ) { |
|
| 902 | +function getpaid_get_help_tip($tip, $additional_classes = '', $echo = false) { |
|
| 903 | 903 | $classes = 'wpi-help-tip dashicons dashicons-editor-help ' . $additional_classes; |
| 904 | - $tip = esc_attr( $tip ); |
|
| 904 | + $tip = esc_attr($tip); |
|
| 905 | 905 | |
| 906 | - if ( $echo ) { |
|
| 907 | - echo '<span class="' . esc_attr( $classes ) . '" data-tip="' . esc_attr( $tip ) . '"></span>'; |
|
| 906 | + if ($echo) { |
|
| 907 | + echo '<span class="' . esc_attr($classes) . '" data-tip="' . esc_attr($tip) . '"></span>'; |
|
| 908 | 908 | } else { |
| 909 | - return '<span class="' . esc_attr( $classes ) . '" data-tip="' . esc_attr( $tip ) . '"></span>'; |
|
| 909 | + return '<span class="' . esc_attr($classes) . '" data-tip="' . esc_attr($tip) . '"></span>'; |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | } |
@@ -914,18 +914,18 @@ discard block |
||
| 914 | 914 | /** |
| 915 | 915 | * Formats a date |
| 916 | 916 | */ |
| 917 | -function getpaid_format_date( $date, $with_time = false ) { |
|
| 917 | +function getpaid_format_date($date, $with_time = false) { |
|
| 918 | 918 | |
| 919 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
| 919 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
| 920 | 920 | return ''; |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | $format = getpaid_date_format(); |
| 924 | 924 | |
| 925 | - if ( $with_time ) { |
|
| 925 | + if ($with_time) { |
|
| 926 | 926 | $format .= ' ' . getpaid_time_format(); |
| 927 | 927 | } |
| 928 | - return date_i18n( $format, strtotime( $date ) ); |
|
| 928 | + return date_i18n($format, strtotime($date)); |
|
| 929 | 929 | |
| 930 | 930 | } |
| 931 | 931 | |
@@ -934,9 +934,9 @@ discard block |
||
| 934 | 934 | * |
| 935 | 935 | * @return string |
| 936 | 936 | */ |
| 937 | -function getpaid_format_date_value( $date, $default = '—', $with_time = false ) { |
|
| 938 | - $date = getpaid_format_date( $date, $with_time ); |
|
| 939 | - return empty( $date ) ? $default : $date; |
|
| 937 | +function getpaid_format_date_value($date, $default = '—', $with_time = false) { |
|
| 938 | + $date = getpaid_format_date($date, $with_time); |
|
| 939 | + return empty($date) ? $default : $date; |
|
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | /** |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | * @return string |
| 946 | 946 | */ |
| 947 | 947 | function getpaid_date_format() { |
| 948 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
| 948 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | * @return string |
| 955 | 955 | */ |
| 956 | 956 | function getpaid_time_format() { |
| 957 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
| 957 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -964,16 +964,16 @@ discard block |
||
| 964 | 964 | * @param integer $limit Limit size in characters. |
| 965 | 965 | * @return string |
| 966 | 966 | */ |
| 967 | -function getpaid_limit_length( $string, $limit ) { |
|
| 967 | +function getpaid_limit_length($string, $limit) { |
|
| 968 | 968 | $str_limit = $limit - 3; |
| 969 | 969 | |
| 970 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 971 | - if ( mb_strlen( $string ) > $limit ) { |
|
| 972 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
| 970 | + if (function_exists('mb_strimwidth')) { |
|
| 971 | + if (mb_strlen($string) > $limit) { |
|
| 972 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
| 973 | 973 | } |
| 974 | 974 | } else { |
| 975 | - if ( strlen( $string ) > $limit ) { |
|
| 976 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
| 975 | + if (strlen($string) > $limit) { |
|
| 976 | + $string = substr($string, 0, $str_limit) . '...'; |
|
| 977 | 977 | } |
| 978 | 978 | } |
| 979 | 979 | return $string; |
@@ -987,7 +987,7 @@ discard block |
||
| 987 | 987 | * @since 1.0.19 |
| 988 | 988 | */ |
| 989 | 989 | function getpaid_api() { |
| 990 | - return getpaid()->get( 'api' ); |
|
| 990 | + return getpaid()->get('api'); |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | /** |
@@ -997,7 +997,7 @@ discard block |
||
| 997 | 997 | * @since 1.0.19 |
| 998 | 998 | */ |
| 999 | 999 | function getpaid_post_types() { |
| 1000 | - return getpaid()->get( 'post_types' ); |
|
| 1000 | + return getpaid()->get('post_types'); |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | /** |
@@ -1007,7 +1007,7 @@ discard block |
||
| 1007 | 1007 | * @since 1.0.19 |
| 1008 | 1008 | */ |
| 1009 | 1009 | function getpaid_session() { |
| 1010 | - return getpaid()->get( 'session' ); |
|
| 1010 | + return getpaid()->get('session'); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | /** |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | * @since 1.0.19 |
| 1018 | 1018 | */ |
| 1019 | 1019 | function getpaid_notes() { |
| 1020 | - return getpaid()->get( 'notes' ); |
|
| 1020 | + return getpaid()->get('notes'); |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | /** |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | * @return GetPaid_Admin |
| 1027 | 1027 | */ |
| 1028 | 1028 | function getpaid_admin() { |
| 1029 | - return getpaid()->get( 'admin' ); |
|
| 1029 | + return getpaid()->get('admin'); |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | /** |
@@ -1036,8 +1036,8 @@ discard block |
||
| 1036 | 1036 | * @param string $base the base url |
| 1037 | 1037 | * @return string |
| 1038 | 1038 | */ |
| 1039 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
| 1040 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
| 1039 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
| 1040 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | /** |
@@ -1045,11 +1045,11 @@ discard block |
||
| 1045 | 1045 | * |
| 1046 | 1046 | * @return string |
| 1047 | 1047 | */ |
| 1048 | -function getpaid_get_post_type_label( $post_type, $plural = true ) { |
|
| 1048 | +function getpaid_get_post_type_label($post_type, $plural = true) { |
|
| 1049 | 1049 | |
| 1050 | - $post_type = get_post_type_object( $post_type ); |
|
| 1050 | + $post_type = get_post_type_object($post_type); |
|
| 1051 | 1051 | |
| 1052 | - if ( ! is_object( $post_type ) ) { |
|
| 1052 | + if (!is_object($post_type)) { |
|
| 1053 | 1053 | return null; |
| 1054 | 1054 | } |
| 1055 | 1055 | |
@@ -1062,18 +1062,18 @@ discard block |
||
| 1062 | 1062 | * |
| 1063 | 1063 | * @return mixed|null |
| 1064 | 1064 | */ |
| 1065 | -function getpaid_get_array_field( $array, $key, $secondary_key = null ) { |
|
| 1065 | +function getpaid_get_array_field($array, $key, $secondary_key = null) { |
|
| 1066 | 1066 | |
| 1067 | - if ( ! is_array( $array ) ) { |
|
| 1067 | + if (!is_array($array)) { |
|
| 1068 | 1068 | return null; |
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | - if ( ! empty( $secondary_key ) ) { |
|
| 1072 | - $array = isset( $array[ $secondary_key ] ) ? $array[ $secondary_key ] : array(); |
|
| 1073 | - return getpaid_get_array_field( $array, $key ); |
|
| 1071 | + if (!empty($secondary_key)) { |
|
| 1072 | + $array = isset($array[$secondary_key]) ? $array[$secondary_key] : array(); |
|
| 1073 | + return getpaid_get_array_field($array, $key); |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | - return isset( $array[ $key ] ) ? $array[ $key ] : null; |
|
| 1076 | + return isset($array[$key]) ? $array[$key] : null; |
|
| 1077 | 1077 | |
| 1078 | 1078 | } |
| 1079 | 1079 | |
@@ -1082,12 +1082,12 @@ discard block |
||
| 1082 | 1082 | * |
| 1083 | 1083 | * @return array |
| 1084 | 1084 | */ |
| 1085 | -function getpaid_array_merge_if_empty( $args, $defaults ) { |
|
| 1085 | +function getpaid_array_merge_if_empty($args, $defaults) { |
|
| 1086 | 1086 | |
| 1087 | - foreach ( $defaults as $key => $value ) { |
|
| 1087 | + foreach ($defaults as $key => $value) { |
|
| 1088 | 1088 | |
| 1089 | - if ( array_key_exists( $key, $args ) && empty( $args[ $key ] ) ) { |
|
| 1090 | - $args[ $key ] = $value; |
|
| 1089 | + if (array_key_exists($key, $args) && empty($args[$key])) { |
|
| 1090 | + $args[$key] = $value; |
|
| 1091 | 1091 | } |
| 1092 | 1092 | } |
| 1093 | 1093 | |
@@ -1104,12 +1104,12 @@ discard block |
||
| 1104 | 1104 | |
| 1105 | 1105 | $types = get_allowed_mime_types(); |
| 1106 | 1106 | |
| 1107 | - if ( isset( $types['htm|html'] ) ) { |
|
| 1108 | - unset( $types['htm|html'] ); |
|
| 1107 | + if (isset($types['htm|html'])) { |
|
| 1108 | + unset($types['htm|html']); |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | - if ( isset( $types['js'] ) ) { |
|
| 1112 | - unset( $types['js'] ); |
|
| 1111 | + if (isset($types['js'])) { |
|
| 1112 | + unset($types['js']); |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | return $types; |
@@ -1117,34 +1117,34 @@ discard block |
||
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | |
| 1120 | -function getpaid_user_delete_invoice( $data ) { |
|
| 1120 | +function getpaid_user_delete_invoice($data) { |
|
| 1121 | 1121 | |
| 1122 | 1122 | // Ensure there is an invoice to delete. |
| 1123 | - if ( empty( $data['invoice_id'] ) ) { |
|
| 1123 | + if (empty($data['invoice_id'])) { |
|
| 1124 | 1124 | return; |
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | - $invoice = new WPInv_Invoice( (int) $data['invoice_id'] ); |
|
| 1127 | + $invoice = new WPInv_Invoice((int) $data['invoice_id']); |
|
| 1128 | 1128 | |
| 1129 | 1129 | // Ensure that it exists and that it belongs to the current user. |
| 1130 | - if ( ! $invoice->exists() || $invoice->get_customer_id() != get_current_user_id() ) { |
|
| 1131 | - wpinv_set_error( 'invalid_invoice', __( 'You do not have permission to delete this invoice', 'invoicing' ) ); |
|
| 1130 | + if (!$invoice->exists() || $invoice->get_customer_id() != get_current_user_id()) { |
|
| 1131 | + wpinv_set_error('invalid_invoice', __('You do not have permission to delete this invoice', 'invoicing')); |
|
| 1132 | 1132 | |
| 1133 | 1133 | // Can it be deleted? |
| 1134 | - } elseif ( ! $invoice->needs_payment() ) { |
|
| 1135 | - wpinv_set_error( 'cannot_delete', __( 'This invoice cannot be deleted as it has already been paid.', 'invoicing' ) ); |
|
| 1134 | + } elseif (!$invoice->needs_payment()) { |
|
| 1135 | + wpinv_set_error('cannot_delete', __('This invoice cannot be deleted as it has already been paid.', 'invoicing')); |
|
| 1136 | 1136 | |
| 1137 | 1137 | // Delete it. |
| 1138 | 1138 | } else { |
| 1139 | 1139 | |
| 1140 | 1140 | $invoice->delete(); |
| 1141 | - wpinv_set_error( 'delete', __( 'The invoice has been deleted.', 'invoicing' ), 'info' ); |
|
| 1141 | + wpinv_set_error('delete', __('The invoice has been deleted.', 'invoicing'), 'info'); |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | - $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce', 'invoice_id' ) ); |
|
| 1144 | + $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce', 'invoice_id')); |
|
| 1145 | 1145 | |
| 1146 | - wp_safe_redirect( $redirect ); |
|
| 1146 | + wp_safe_redirect($redirect); |
|
| 1147 | 1147 | exit; |
| 1148 | 1148 | |
| 1149 | 1149 | } |
| 1150 | -add_action( 'getpaid_authenticated_action_delete_invoice', 'getpaid_user_delete_invoice' ); |
|
| 1150 | +add_action('getpaid_authenticated_action_delete_invoice', 'getpaid_user_delete_invoice'); |
|
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Contains gateway functions. |
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | -defined( 'ABSPATH' ) || exit; |
|
| 6 | +defined('ABSPATH') || exit; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Returns an array of payment gateways. |
@@ -11,30 +11,30 @@ discard block |
||
| 11 | 11 | * @return array |
| 12 | 12 | */ |
| 13 | 13 | function wpinv_get_payment_gateways() { |
| 14 | - return apply_filters( 'wpinv_payment_gateways', array() ); |
|
| 14 | + return apply_filters('wpinv_payment_gateways', array()); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
| 17 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
| 18 | 18 | |
| 19 | 19 | $options = wpinv_get_options(); |
| 20 | 20 | $gateways = array(); |
| 21 | - foreach ( $all_gateways as $key => $gateway ) { |
|
| 22 | - if ( ! empty( $options[ $key . '_title' ] ) ) { |
|
| 23 | - $all_gateways[ $key ]['checkout_label'] = __( $options[ $key . '_title' ], 'invoicing' ); |
|
| 21 | + foreach ($all_gateways as $key => $gateway) { |
|
| 22 | + if (!empty($options[$key . '_title'])) { |
|
| 23 | + $all_gateways[$key]['checkout_label'] = __($options[$key . '_title'], 'invoicing'); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - $gateways[ $key ] = isset( $options[ $key . '_ordering' ] ) ? $options[ $key . '_ordering' ] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
| 26 | + $gateways[$key] = isset($options[$key . '_ordering']) ? $options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - asort( $gateways ); |
|
| 29 | + asort($gateways); |
|
| 30 | 30 | |
| 31 | - foreach ( $gateways as $gateway => $key ) { |
|
| 32 | - $gateways[ $gateway ] = $all_gateways[ $gateway ]; |
|
| 31 | + foreach ($gateways as $gateway => $key) { |
|
| 32 | + $gateways[$gateway] = $all_gateways[$gateway]; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | return $gateways; |
| 36 | 36 | } |
| 37 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
| 37 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Returns an array of enabled gateways. |
@@ -42,36 +42,36 @@ discard block |
||
| 42 | 42 | * @param bool $sort |
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
| 45 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
| 46 | 46 | |
| 47 | 47 | $enabled = array(); |
| 48 | 48 | |
| 49 | - foreach ( wpinv_get_payment_gateways() as $gateway => $data ) { |
|
| 49 | + foreach (wpinv_get_payment_gateways() as $gateway => $data) { |
|
| 50 | 50 | |
| 51 | - if ( (int) wpinv_get_option( "{$gateway}_active", $gateway === 'manual' ) === 1 ) { |
|
| 52 | - $enabled[ $gateway ] = $data; |
|
| 51 | + if ((int) wpinv_get_option("{$gateway}_active", $gateway === 'manual') === 1) { |
|
| 52 | + $enabled[$gateway] = $data; |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if ( true === $sort ) { |
|
| 57 | - uasort( $enabled, 'wpinv_sort_gateway_order' ); |
|
| 56 | + if (true === $sort) { |
|
| 57 | + uasort($enabled, 'wpinv_sort_gateway_order'); |
|
| 58 | 58 | |
| 59 | 59 | // Reorder our gateways so the default is first |
| 60 | 60 | $default_gateway_id = wpinv_get_default_gateway(); |
| 61 | - if ( isset( $enabled[ $default_gateway_id ] ) ) { |
|
| 61 | + if (isset($enabled[$default_gateway_id])) { |
|
| 62 | 62 | $default_gateway = array( |
| 63 | - $default_gateway_id => $enabled[ $default_gateway_id ], |
|
| 63 | + $default_gateway_id => $enabled[$default_gateway_id], |
|
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | - unset( $enabled[ $default_gateway_id ] ); |
|
| 67 | - $enabled = array_merge( $default_gateway, $enabled ); |
|
| 66 | + unset($enabled[$default_gateway_id]); |
|
| 67 | + $enabled = array_merge($default_gateway, $enabled); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - return apply_filters( 'wpinv_enabled_payment_gateways', $enabled ); |
|
| 71 | + return apply_filters('wpinv_enabled_payment_gateways', $enabled); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
| 74 | +function wpinv_sort_gateway_order($a, $b) { |
|
| 75 | 75 | return $a['ordering'] - $b['ordering']; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | * @param string $gateway |
| 82 | 82 | * @return bool |
| 83 | 83 | */ |
| 84 | -function wpinv_is_gateway_active( $gateway ) { |
|
| 85 | - $is_active = (int) wpinv_get_option( "{$gateway}_active", $gateway === 'manual' ) === 1; |
|
| 86 | - return apply_filters( 'wpinv_is_gateway_active', $is_active, $gateway ); |
|
| 84 | +function wpinv_is_gateway_active($gateway) { |
|
| 85 | + $is_active = (int) wpinv_get_option("{$gateway}_active", $gateway === 'manual') === 1; |
|
| 86 | + return apply_filters('wpinv_is_gateway_active', $is_active, $gateway); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | * @return string|false |
| 93 | 93 | */ |
| 94 | 94 | function wpinv_get_default_gateway() { |
| 95 | - $default = wpinv_get_option( 'default_gateway' ); |
|
| 95 | + $default = wpinv_get_option('default_gateway'); |
|
| 96 | 96 | $gateways = wpinv_get_enabled_payment_gateways(); |
| 97 | - $default = ! empty( $default ) && isset( $gateways[ $default ] ) ? $default : false; |
|
| 97 | + $default = !empty($default) && isset($gateways[$default]) ? $default : false; |
|
| 98 | 98 | |
| 99 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
| 99 | + return apply_filters('wpinv_default_gateway', $default); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,17 +105,17 @@ discard block |
||
| 105 | 105 | * @param string $gateway The gateway to key. |
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
| 108 | +function wpinv_get_gateway_admin_label($gateway) { |
|
| 109 | 109 | |
| 110 | - if ( empty( $gateway ) || 'none' == $gateway ) { |
|
| 111 | - return esc_html__( 'No Gateway', 'invoicing' ); |
|
| 110 | + if (empty($gateway) || 'none' == $gateway) { |
|
| 111 | + return esc_html__('No Gateway', 'invoicing'); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $gateways = wpinv_get_payment_gateways(); |
| 115 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
| 116 | - $gateway = apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
| 115 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
| 116 | + $gateway = apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
| 117 | 117 | |
| 118 | - return wpinv_clean( $gateway ); |
|
| 118 | + return wpinv_clean($gateway); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -123,48 +123,48 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @param string $gateway |
| 125 | 125 | */ |
| 126 | -function wpinv_get_gateway_description( $gateway ) { |
|
| 126 | +function wpinv_get_gateway_description($gateway) { |
|
| 127 | 127 | |
| 128 | 128 | $options = wpinv_get_options(); |
| 129 | - $description = ! empty( $options[ $gateway . '_desc' ] ) ? $options[ $gateway . '_desc' ] : ''; |
|
| 129 | + $description = !empty($options[$gateway . '_desc']) ? $options[$gateway . '_desc'] : ''; |
|
| 130 | 130 | |
| 131 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
| 131 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
| 135 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
| 134 | +function wpinv_get_gateway_button_label($gateway) { |
|
| 135 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
| 138 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
| 139 | 139 | $gateways = wpinv_get_payment_gateways(); |
| 140 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
| 140 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
| 141 | 141 | |
| 142 | - if ( $gateway == 'none' ) { |
|
| 143 | - $label = __( 'None', 'invoicing' ); |
|
| 142 | + if ($gateway == 'none') { |
|
| 143 | + $label = __('None', 'invoicing'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway ); |
|
| 146 | + return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | -function wpinv_settings_sections_gateways( $settings ) { |
|
| 149 | +function wpinv_settings_sections_gateways($settings) { |
|
| 150 | 150 | $gateways = wpinv_get_payment_gateways(); |
| 151 | - ksort( $gateways ); |
|
| 151 | + ksort($gateways); |
|
| 152 | 152 | |
| 153 | - foreach ( $gateways as $key => $gateway ) { |
|
| 154 | - $settings[ $key ] = $gateway['admin_label']; |
|
| 153 | + foreach ($gateways as $key => $gateway) { |
|
| 154 | + $settings[$key] = $gateway['admin_label']; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | return $settings; |
| 158 | 158 | } |
| 159 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
| 159 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Adds GateWay settings. |
| 163 | 163 | */ |
| 164 | -function wpinv_settings_gateways( $settings ) { |
|
| 164 | +function wpinv_settings_gateways($settings) { |
|
| 165 | 165 | |
| 166 | 166 | // Loop through each gateway. |
| 167 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
| 167 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
| 168 | 168 | |
| 169 | 169 | $gateway_settings = array( |
| 170 | 170 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | "{$key}_header" => array( |
| 173 | 173 | |
| 174 | 174 | 'id' => "{$key}_gateway_header", |
| 175 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
| 175 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
| 176 | 176 | 'custom' => $key, |
| 177 | 177 | 'type' => 'gateway_header', |
| 178 | 178 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | // Activate/Deactivate a gateway. |
| 182 | 182 | "{$key}_active" => array( |
| 183 | 183 | 'id' => $key . '_active', |
| 184 | - 'name' => __( 'Activate', 'invoicing' ), |
|
| 185 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
| 184 | + 'name' => __('Activate', 'invoicing'), |
|
| 185 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
| 186 | 186 | 'type' => 'checkbox', |
| 187 | 187 | 'std' => $key === 'manual' ? '1' : '0', |
| 188 | 188 | ), |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | // Activate/Deactivate sandbox. |
| 191 | 191 | "{$key}_sandbox" => array( |
| 192 | 192 | 'id' => $key . '_sandbox', |
| 193 | - 'name' => __( 'Sandbox', 'invoicing' ), |
|
| 194 | - 'desc' => __( 'Enable sandbox to test payments', 'invoicing' ), |
|
| 193 | + 'name' => __('Sandbox', 'invoicing'), |
|
| 194 | + 'desc' => __('Enable sandbox to test payments', 'invoicing'), |
|
| 195 | 195 | 'type' => 'checkbox', |
| 196 | 196 | 'std' => '1', |
| 197 | 197 | ), |
@@ -199,51 +199,51 @@ discard block |
||
| 199 | 199 | // Checkout title. |
| 200 | 200 | "{$key}_title" => array( |
| 201 | 201 | 'id' => $key . '_title', |
| 202 | - 'name' => __( 'Checkout Title', 'invoicing' ), |
|
| 203 | - 'std' => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '', |
|
| 202 | + 'name' => __('Checkout Title', 'invoicing'), |
|
| 203 | + 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '', |
|
| 204 | 204 | 'type' => 'text', |
| 205 | 205 | ), |
| 206 | 206 | |
| 207 | 207 | // Checkout description. |
| 208 | 208 | "{$key}_desc" => array( |
| 209 | 209 | 'id' => $key . '_desc', |
| 210 | - 'name' => __( 'Checkout Description', 'invoicing' ), |
|
| 211 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
| 210 | + 'name' => __('Checkout Description', 'invoicing'), |
|
| 211 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
| 212 | 212 | 'type' => 'text', |
| 213 | 213 | ), |
| 214 | 214 | |
| 215 | 215 | // Checkout order. |
| 216 | 216 | "{$key}_ordering" => array( |
| 217 | 217 | 'id' => $key . '_ordering', |
| 218 | - 'name' => __( 'Priority', 'invoicing' ), |
|
| 219 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
| 218 | + 'name' => __('Priority', 'invoicing'), |
|
| 219 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
| 220 | 220 | 'type' => 'number', |
| 221 | 221 | 'step' => '1', |
| 222 | 222 | 'min' => '0', |
| 223 | 223 | 'max' => '100000', |
| 224 | - 'std' => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10', |
|
| 224 | + 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
|
| 225 | 225 | ), |
| 226 | 226 | |
| 227 | 227 | ); |
| 228 | 228 | |
| 229 | 229 | // Maybe remove the sandbox. |
| 230 | - if ( ! getpaid_payment_gateway_supports( $key, 'sandbox' ) ) { |
|
| 231 | - unset( $gateway_settings[ "{$key}_sandbox" ] ); |
|
| 230 | + if (!getpaid_payment_gateway_supports($key, 'sandbox')) { |
|
| 231 | + unset($gateway_settings["{$key}_sandbox"]); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway ); |
|
| 235 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway ); |
|
| 234 | + $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway); |
|
| 235 | + $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway); |
|
| 236 | 236 | |
| 237 | - $settings[ $key ] = $gateway_settings; |
|
| 237 | + $settings[$key] = $gateway_settings; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | return $settings; |
| 241 | 241 | |
| 242 | 242 | } |
| 243 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
| 243 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
| 244 | 244 | |
| 245 | -function wpinv_gateway_header_callback( $args ) { |
|
| 246 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
| 245 | +function wpinv_gateway_header_callback($args) { |
|
| 246 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -254,60 +254,60 @@ discard block |
||
| 254 | 254 | * @return bool |
| 255 | 255 | * @since 2.3.0 |
| 256 | 256 | */ |
| 257 | -function getpaid_payment_gateway_supports( $gateway, $feature ) { |
|
| 257 | +function getpaid_payment_gateway_supports($gateway, $feature) { |
|
| 258 | 258 | |
| 259 | 259 | $supports = false; |
| 260 | 260 | |
| 261 | - $supports = apply_filters( "getpaid_{$gateway}_supports_{$feature}", false ); |
|
| 261 | + $supports = apply_filters("getpaid_{$gateway}_supports_{$feature}", false); |
|
| 262 | 262 | |
| 263 | 263 | // Backwards compatibility. |
| 264 | - $supports = apply_filters( "wpinv_{$gateway}_supports_{$feature}", $supports ); |
|
| 265 | - $supports = apply_filters( "wpinv_{$gateway}_support_{$feature}", $supports ); |
|
| 264 | + $supports = apply_filters("wpinv_{$gateway}_supports_{$feature}", $supports); |
|
| 265 | + $supports = apply_filters("wpinv_{$gateway}_support_{$feature}", $supports); |
|
| 266 | 266 | |
| 267 | - $supports = apply_filters( "getpaid_gateway_supports_{$feature}", $supports, $gateway ); |
|
| 268 | - $supports = apply_filters( 'getpaid_payment_gateway_supports', $supports, $feature, $gateway ); |
|
| 267 | + $supports = apply_filters("getpaid_gateway_supports_{$feature}", $supports, $gateway); |
|
| 268 | + $supports = apply_filters('getpaid_payment_gateway_supports', $supports, $feature, $gateway); |
|
| 269 | 269 | |
| 270 | 270 | return $supports; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
| 274 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 273 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
| 274 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 275 | 275 | |
| 276 | 276 | $chosen = false; |
| 277 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
| 277 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
| 278 | 278 | $chosen = $invoice->get_gateway(); |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
| 281 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
| 282 | 282 | |
| 283 | - if ( false !== $chosen ) { |
|
| 284 | - $chosen = preg_replace( '/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
| 283 | + if (false !== $chosen) { |
|
| 284 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - if ( ! empty( $chosen ) ) { |
|
| 288 | - $enabled_gateway = urldecode( $chosen ); |
|
| 289 | - } elseif ( ! empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
| 287 | + if (!empty($chosen)) { |
|
| 288 | + $enabled_gateway = urldecode($chosen); |
|
| 289 | + } elseif (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
| 290 | 290 | $enabled_gateway = 'manual'; |
| 291 | 291 | } else { |
| 292 | 292 | $enabled_gateway = wpinv_get_default_gateway(); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if ( ! wpinv_is_gateway_active( $enabled_gateway ) && ! empty( $gateways ) ) { |
|
| 296 | - if ( wpinv_is_gateway_active( wpinv_get_default_gateway() ) ) { |
|
| 295 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
| 296 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
| 297 | 297 | $enabled_gateway = wpinv_get_default_gateway(); |
| 298 | 298 | } else { |
| 299 | 299 | $enabled_gateway = $gateways[0]; |
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
| 303 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | -function wpinv_record_gateway_error( $title = '', $message = '' ) { |
|
| 307 | - return wpinv_error_log( $message, $title ); |
|
| 306 | +function wpinv_record_gateway_error($title = '', $message = '') { |
|
| 307 | + return wpinv_error_log($message, $title); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
| 310 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
| 311 | 311 | $ret = 0; |
| 312 | 312 | $args = array( |
| 313 | 313 | 'meta_key' => '_wpinv_gateway', |
@@ -318,9 +318,9 @@ discard block |
||
| 318 | 318 | 'fields' => 'ids', |
| 319 | 319 | ); |
| 320 | 320 | |
| 321 | - $payments = new WP_Query( $args ); |
|
| 321 | + $payments = new WP_Query($args); |
|
| 322 | 322 | |
| 323 | - if ( $payments ) { |
|
| 323 | + if ($payments) { |
|
| 324 | 324 | $ret = $payments->post_count; |
| 325 | 325 | } |
| 326 | 326 | return $ret; |
@@ -329,11 +329,11 @@ discard block |
||
| 329 | 329 | /** |
| 330 | 330 | * Displays the ipn url field. |
| 331 | 331 | */ |
| 332 | -function wpinv_ipn_url_callback( $args ) { |
|
| 333 | - $sanitize_id = esc_attr( wpinv_sanitize_key( $args['id'] ) ); |
|
| 332 | +function wpinv_ipn_url_callback($args) { |
|
| 333 | + $sanitize_id = esc_attr(wpinv_sanitize_key($args['id'])); |
|
| 334 | 334 | |
| 335 | - echo '<input class="regular-text" type="text" ' . ( $args['readonly'] ? ' readonly' : '' ) . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" onClick="this.select()">'; |
|
| 336 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']">' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 335 | + echo '<input class="regular-text" type="text" ' . ($args['readonly'] ? ' readonly' : '') . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . esc_attr($sanitize_id) . ']" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" onClick="this.select()">'; |
|
| 336 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']">' . wp_kses_post($args['desc']) . '</label>'; |
|
| 337 | 337 | |
| 338 | 338 | } |
| 339 | 339 | |
@@ -344,10 +344,10 @@ discard block |
||
| 344 | 344 | * |
| 345 | 345 | * @return bool |
| 346 | 346 | */ |
| 347 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
| 348 | - $sandbox = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", true ); |
|
| 349 | - $supports = getpaid_payment_gateway_supports( $gateway, 'sandbox' ); |
|
| 350 | - return apply_filters( 'wpinv_is_test_mode', $sandbox && $supports, $gateway ); |
|
| 347 | +function wpinv_is_test_mode($gateway = '') { |
|
| 348 | + $sandbox = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", true); |
|
| 349 | + $supports = getpaid_payment_gateway_supports($gateway, 'sandbox'); |
|
| 350 | + return apply_filters('wpinv_is_test_mode', $sandbox && $supports, $gateway); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | * |
| 359 | 359 | * @return string |
| 360 | 360 | */ |
| 361 | -function wpinv_get_ipn_url( $gateway = false, $args = array() ) { |
|
| 361 | +function wpinv_get_ipn_url($gateway = false, $args = array()) { |
|
| 362 | 362 | $args = wp_parse_args( |
| 363 | 363 | array( |
| 364 | 364 | 'wpi-listener' => 'IPN', |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | $args |
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - return apply_filters( 'wpinv_ipn_url', add_query_arg( $args, home_url( 'index.php' ) ), $gateway, $args ); |
|
| 370 | + return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args); |
|
| 371 | 371 | |
| 372 | 372 | } |
| 373 | 373 | |
@@ -378,34 +378,34 @@ discard block |
||
| 378 | 378 | * |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | -function getpaid_get_non_query_string_ipn_url( $gateway ) { |
|
| 382 | - $gateway = wpinv_sanitize_key( $gateway ); |
|
| 383 | - return home_url( "getpaid-ipn/$gateway" ); |
|
| 381 | +function getpaid_get_non_query_string_ipn_url($gateway) { |
|
| 382 | + $gateway = wpinv_sanitize_key($gateway); |
|
| 383 | + return home_url("getpaid-ipn/$gateway"); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
| 387 | 387 | /** |
| 388 | 388 | * Retrieves request data with slashes removed slashes. |
| 389 | 389 | */ |
| 390 | -function wpinv_get_post_data( $method = 'request' ) { |
|
| 390 | +function wpinv_get_post_data($method = 'request') { |
|
| 391 | 391 | |
| 392 | - if ( $method == 'post' ) { |
|
| 393 | - return wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 392 | + if ($method == 'post') { |
|
| 393 | + return wp_kses_post_deep(wp_unslash($_POST)); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if ( $method == 'get' ) { |
|
| 397 | - return wp_kses_post_deep( wp_unslash( $_GET ) ); |
|
| 396 | + if ($method == 'get') { |
|
| 397 | + return wp_kses_post_deep(wp_unslash($_GET)); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - return wp_kses_post_deep( wp_unslash( $_REQUEST ) ); |
|
| 400 | + return wp_kses_post_deep(wp_unslash($_REQUEST)); |
|
| 401 | 401 | |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
| 405 | 405 | * Checks if a given gateway supports subscription payments. |
| 406 | 406 | */ |
| 407 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
| 408 | - return getpaid_payment_gateway_supports( $gateway, 'subscription' ); |
|
| 407 | +function wpinv_gateway_support_subscription($gateway) { |
|
| 408 | + return getpaid_payment_gateway_supports($gateway, 'subscription'); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -414,18 +414,18 @@ discard block |
||
| 414 | 414 | * @param array $gateways an array of gateways. |
| 415 | 415 | * @param GetPaid_Payment_Form $form payment form. |
| 416 | 416 | */ |
| 417 | -function wpinv_payment_gateways_on_cart( $gateways, $form ) { |
|
| 417 | +function wpinv_payment_gateways_on_cart($gateways, $form) { |
|
| 418 | 418 | |
| 419 | - if ( $form->is_recurring() ) { |
|
| 419 | + if ($form->is_recurring()) { |
|
| 420 | 420 | |
| 421 | - foreach ( array_keys( $gateways ) as $gateway ) { |
|
| 421 | + foreach (array_keys($gateways) as $gateway) { |
|
| 422 | 422 | |
| 423 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 424 | - unset( $gateways[ $gateway ] ); |
|
| 423 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
| 424 | + unset($gateways[$gateway]); |
|
| 425 | 425 | } |
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | return $gateways; |
| 430 | 430 | } |
| 431 | -add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 ); |
|
| 431 | +add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2); |
|
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * Please use GetPaid_Notification_Email_Sender |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /* |
| 12 | 12 | |-------------------------------------------------------------------------- |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Generates the email header. |
| 19 | 19 | */ |
| 20 | -function wpinv_email_header( $email_heading ) { |
|
| 21 | - wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) ); |
|
| 20 | +function wpinv_email_header($email_heading) { |
|
| 21 | + wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading')); |
|
| 22 | 22 | } |
| 23 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
| 23 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Generates the email footer. |
| 28 | 28 | */ |
| 29 | 29 | function wpinv_email_footer() { |
| 30 | - wpinv_get_template( 'emails/wpinv-email-footer.php' ); |
|
| 30 | + wpinv_get_template('emails/wpinv-email-footer.php'); |
|
| 31 | 31 | } |
| 32 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
| 32 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | * @param string $email_type |
| 40 | 40 | * @param bool $sent_to_admin |
| 41 | 41 | */ |
| 42 | -function wpinv_email_invoice_details( $invoice, $email_type, $sent_to_admin ) { |
|
| 42 | +function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) { |
|
| 43 | 43 | |
| 44 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
| 45 | - wpinv_get_template( 'emails/invoice-details.php', $args ); |
|
| 44 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
| 45 | + wpinv_get_template('emails/invoice-details.php', $args); |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
| 48 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Display line items in emails. |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | * @param string $email_type |
| 55 | 55 | * @param bool $sent_to_admin |
| 56 | 56 | */ |
| 57 | -function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) { |
|
| 57 | +function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) { |
|
| 58 | 58 | |
| 59 | 59 | // Prepare line items. |
| 60 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
| 61 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
| 60 | + $columns = getpaid_invoice_item_columns($invoice); |
|
| 61 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
| 62 | 62 | |
| 63 | 63 | // Load the template. |
| 64 | - wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) ); |
|
| 64 | + wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin')); |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
| 67 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | * @param string $email_type |
| 75 | 75 | * @param bool $sent_to_admin |
| 76 | 76 | */ |
| 77 | -function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) { |
|
| 77 | +function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) { |
|
| 78 | 78 | |
| 79 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
| 80 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args ); |
|
| 79 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
| 80 | + wpinv_get_template('emails/wpinv-email-billing-details.php', $args); |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
| 83 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * Returns email css. |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function getpaid_get_email_css() { |
| 90 | 90 | |
| 91 | - $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' ); |
|
| 92 | - return apply_filters( 'wpinv_email_styles', $css ); |
|
| 91 | + $css = wpinv_get_template_html('emails/wpinv-email-styles.php'); |
|
| 92 | + return apply_filters('wpinv_email_styles', $css); |
|
| 93 | 93 | |
| 94 | 94 | } |
| 95 | 95 | |
@@ -100,26 +100,26 @@ discard block |
||
| 100 | 100 | * @return string |
| 101 | 101 | * |
| 102 | 102 | */ |
| 103 | -function wpinv_email_style_body( $content ) { |
|
| 103 | +function wpinv_email_style_body($content) { |
|
| 104 | 104 | |
| 105 | - if ( ! class_exists( 'DOMDocument' ) ) { |
|
| 105 | + if (!class_exists('DOMDocument')) { |
|
| 106 | 106 | return $content; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $css = getpaid_get_email_css(); |
| 110 | 110 | |
| 111 | 111 | // include css inliner |
| 112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 112 | + if (!class_exists('Emogrifier')) { |
|
| 113 | 113 | include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Inline the css. |
| 117 | 117 | try { |
| 118 | - $emogrifier = new Emogrifier( $content, $css ); |
|
| 118 | + $emogrifier = new Emogrifier($content, $css); |
|
| 119 | 119 | $_content = $emogrifier->emogrify(); |
| 120 | 120 | $content = $_content; |
| 121 | - } catch ( Exception $e ) { |
|
| 122 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
| 121 | + } catch (Exception $e) { |
|
| 122 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | return $content; |
@@ -128,37 +128,37 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | // Backwards compatibility. |
| 130 | 130 | function wpinv_init_transactional_emails() { |
| 131 | - foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) { |
|
| 132 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
| 131 | + foreach (apply_filters('wpinv_email_actions', array()) as $action) { |
|
| 132 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
| 135 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
| 136 | 136 | |
| 137 | 137 | function wpinv_send_transactional_email() { |
| 138 | 138 | $args = func_get_args(); |
| 139 | 139 | $function = current_filter() . '_notification'; |
| 140 | - do_action_ref_array( $function, $args ); |
|
| 140 | + do_action_ref_array($function, $args); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | function wpinv_mail_get_from_address() { |
| 144 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from', get_option( 'admin_email' ) ) ); |
|
| 145 | - return sanitize_email( $from_address ); |
|
| 144 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from', get_option('admin_email'))); |
|
| 145 | + return sanitize_email($from_address); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | function wpinv_mail_get_from_name() { |
| 149 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name', get_bloginfo( 'name', 'display' ) ) ); |
|
| 150 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
| 149 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name', get_bloginfo('name', 'display'))); |
|
| 150 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
| 154 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
| 155 | - return ( $active ? true : false ); |
|
| 153 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
| 154 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
| 155 | + return ($active ? true : false); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
| 159 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
| 158 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
| 159 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
| 160 | 160 | |
| 161 | - switch ( $email_type ) { |
|
| 161 | + switch ($email_type) { |
|
| 162 | 162 | case 'html': |
| 163 | 163 | $content_type = 'text/html'; |
| 164 | 164 | break; |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @param array $attachments Any files to attach to the email. |
| 184 | 184 | * @param string|array $cc An email or array of extra emails to send a copy of the email to. |
| 185 | 185 | */ |
| 186 | -function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) { |
|
| 186 | +function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) { |
|
| 187 | 187 | |
| 188 | 188 | $mailer = new GetPaid_Notification_Email_Sender(); |
| 189 | - $message = wpinv_email_style_body( $message ); |
|
| 190 | - $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
|
| 189 | + $message = wpinv_email_style_body($message); |
|
| 190 | + $to = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc)); |
|
| 191 | 191 | |
| 192 | 192 | return $mailer->send( |
| 193 | 193 | $to, |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @return array |
| 205 | 205 | */ |
| 206 | 206 | function wpinv_get_emails() { |
| 207 | - return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) ); |
|
| 207 | + return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings')); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -213,172 +213,172 @@ discard block |
||
| 213 | 213 | * @param array $settings |
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | -function wpinv_settings_emails( $settings = array() ) { |
|
| 217 | - $settings = array_merge( $settings, wpinv_get_emails() ); |
|
| 218 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
| 216 | +function wpinv_settings_emails($settings = array()) { |
|
| 217 | + $settings = array_merge($settings, wpinv_get_emails()); |
|
| 218 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
| 219 | 219 | } |
| 220 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
| 220 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * Filter email section names. |
| 224 | 224 | * |
| 225 | 225 | */ |
| 226 | -function wpinv_settings_sections_emails( $settings ) { |
|
| 227 | - foreach ( wpinv_get_emails() as $key => $email ) { |
|
| 228 | - $settings[ $key ] = ! empty( $email[ 'email_' . $key . '_header' ]['name'] ) ? strip_tags( $email[ 'email_' . $key . '_header' ]['name'] ) : strip_tags( $key ); |
|
| 226 | +function wpinv_settings_sections_emails($settings) { |
|
| 227 | + foreach (wpinv_get_emails() as $key => $email) { |
|
| 228 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return $settings; |
| 232 | 232 | } |
| 233 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
| 233 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
| 234 | 234 | |
| 235 | -function wpinv_email_is_enabled( $email_type ) { |
|
| 235 | +function wpinv_email_is_enabled($email_type) { |
|
| 236 | 236 | $emails = wpinv_get_emails(); |
| 237 | - $enabled = isset( $emails[ $email_type ] ) && wpinv_get_option( 'email_' . $email_type . '_active', 0 ) ? true : false; |
|
| 237 | + $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false; |
|
| 238 | 238 | |
| 239 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
| 239 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 243 | - switch ( $email_type ) { |
|
| 242 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 243 | + switch ($email_type) { |
|
| 244 | 244 | case 'new_invoice': |
| 245 | 245 | case 'cancelled_invoice': |
| 246 | 246 | case 'failed_invoice': |
| 247 | 247 | $recipient = wpinv_get_admin_email(); |
| 248 | 248 | break; |
| 249 | 249 | default: |
| 250 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 251 | - $recipient = ! empty( $invoice ) ? $invoice->get_email() : ''; |
|
| 250 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 251 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
| 252 | 252 | break; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
| 255 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | 259 | * Returns invoice CC recipients |
| 260 | 260 | */ |
| 261 | -function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 262 | - switch ( $email_type ) { |
|
| 261 | +function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 262 | + switch ($email_type) { |
|
| 263 | 263 | case 'new_invoice': |
| 264 | 264 | case 'cancelled_invoice': |
| 265 | 265 | case 'failed_invoice': |
| 266 | 266 | return array(); |
| 267 | 267 | break; |
| 268 | 268 | default: |
| 269 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 270 | - $recipient = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true ); |
|
| 271 | - if ( empty( $recipient ) ) { |
|
| 269 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 270 | + $recipient = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true); |
|
| 271 | + if (empty($recipient)) { |
|
| 272 | 272 | return array(); |
| 273 | 273 | } |
| 274 | - return array_filter( array_map( 'trim', explode( ',', $recipient ) ) ); |
|
| 274 | + return array_filter(array_map('trim', explode(',', $recipient))); |
|
| 275 | 275 | break; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 281 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
| 282 | - $subject = __( $subject, 'invoicing' ); |
|
| 280 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 281 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
| 282 | + $subject = __($subject, 'invoicing'); |
|
| 283 | 283 | |
| 284 | - $subject = wpinv_email_format_text( $subject, $invoice ); |
|
| 284 | + $subject = wpinv_email_format_text($subject, $invoice); |
|
| 285 | 285 | |
| 286 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
| 286 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 290 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
| 291 | - $email_heading = __( $email_heading, 'invoicing' ); |
|
| 289 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 290 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
| 291 | + $email_heading = __($email_heading, 'invoicing'); |
|
| 292 | 292 | |
| 293 | - $email_heading = wpinv_email_format_text( $email_heading, $invoice ); |
|
| 293 | + $email_heading = wpinv_email_format_text($email_heading, $invoice); |
|
| 294 | 294 | |
| 295 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
| 295 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 299 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
| 300 | - $content = __( $content, 'invoicing' ); |
|
| 298 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 299 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
| 300 | + $content = __($content, 'invoicing'); |
|
| 301 | 301 | |
| 302 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
| 302 | + $content = wpinv_email_format_text($content, $invoice); |
|
| 303 | 303 | |
| 304 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
| 304 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 307 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 308 | 308 | $from_name = wpinv_mail_get_from_address(); |
| 309 | 309 | $from_email = wpinv_mail_get_from_address(); |
| 310 | 310 | |
| 311 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 311 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 312 | 312 | |
| 313 | - $headers = 'From: ' . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
| 313 | + $headers = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
| 314 | 314 | $headers .= 'Reply-To: ' . $from_email . "\r\n"; |
| 315 | 315 | $headers .= 'Content-Type: ' . wpinv_mail_get_content_type() . "\r\n"; |
| 316 | 316 | |
| 317 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
| 317 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 320 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 321 | 321 | $attachments = array(); |
| 322 | 322 | |
| 323 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
| 323 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
| 327 | 327 | * Searches for and replaces certain placeholders in an email. |
| 328 | 328 | */ |
| 329 | -function wpinv_email_format_text( $content, $invoice ) { |
|
| 329 | +function wpinv_email_format_text($content, $invoice) { |
|
| 330 | 330 | |
| 331 | 331 | $replace_array = array( |
| 332 | 332 | '{site_title}' => wpinv_get_blogname(), |
| 333 | - '{date}' => getpaid_format_date( current_time( 'mysql' ) ), |
|
| 333 | + '{date}' => getpaid_format_date(current_time('mysql')), |
|
| 334 | 334 | ); |
| 335 | 335 | |
| 336 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 336 | + $invoice = new WPInv_Invoice($invoice); |
|
| 337 | 337 | |
| 338 | - if ( $invoice->get_id() ) { |
|
| 338 | + if ($invoice->get_id()) { |
|
| 339 | 339 | |
| 340 | 340 | $replace_array = array_merge( |
| 341 | 341 | $replace_array, |
| 342 | 342 | array( |
| 343 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 344 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 345 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
| 346 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
| 347 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
| 348 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
| 349 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total( true ), $invoice->get_currency() ) ), |
|
| 350 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
| 351 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
| 352 | - '{invoice_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ), |
|
| 353 | - '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ), |
|
| 354 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_invoice_quote_type() ), |
|
| 355 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_invoice_quote_type() ) ), |
|
| 356 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
| 343 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
| 344 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
| 345 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
| 346 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
| 347 | + '{email}' => sanitize_email($invoice->get_email()), |
|
| 348 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
| 349 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(true), $invoice->get_currency())), |
|
| 350 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
| 351 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
| 352 | + '{invoice_date}' => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))), |
|
| 353 | + '{invoice_due_date}' => date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))), |
|
| 354 | + '{invoice_quote}' => sanitize_text_field($invoice->get_invoice_quote_type()), |
|
| 355 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_invoice_quote_type())), |
|
| 356 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
| 357 | 357 | ) |
| 358 | 358 | ); |
| 359 | 359 | |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // Let third party plugins filter the arra. |
| 363 | - $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice ); |
|
| 363 | + $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice); |
|
| 364 | 364 | |
| 365 | - foreach ( $replace_array as $key => $value ) { |
|
| 366 | - $content = str_replace( $key, $value, $content ); |
|
| 365 | + foreach ($replace_array as $key => $value) { |
|
| 366 | + $content = str_replace($key, $value, $content); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - return apply_filters( 'wpinv_email_content_replace', $content ); |
|
| 369 | + return apply_filters('wpinv_email_content_replace', $content); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | |
| 373 | -function wpinv_email_wrap_message( $message ) { |
|
| 373 | +function wpinv_email_wrap_message($message) { |
|
| 374 | 374 | // Buffer |
| 375 | 375 | ob_start(); |
| 376 | 376 | |
| 377 | - do_action( 'wpinv_email_header' ); |
|
| 377 | + do_action('wpinv_email_header'); |
|
| 378 | 378 | |
| 379 | - echo wp_kses_post( wpautop( wptexturize( $message ) ) ); |
|
| 379 | + echo wp_kses_post(wpautop(wptexturize($message))); |
|
| 380 | 380 | |
| 381 | - do_action( 'wpinv_email_footer' ); |
|
| 381 | + do_action('wpinv_email_footer'); |
|
| 382 | 382 | |
| 383 | 383 | // Get contents |
| 384 | 384 | $message = ob_get_clean(); |
@@ -386,21 +386,21 @@ discard block |
||
| 386 | 386 | return $message; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) { |
|
| 390 | - if ( ! empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->get_id(), true ) ) { |
|
| 391 | - $date_format = get_option( 'date_format' ); |
|
| 392 | - $time_format = get_option( 'time_format' ); |
|
| 389 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type) { |
|
| 390 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->get_id(), true)) { |
|
| 391 | + $date_format = get_option('date_format'); |
|
| 392 | + $time_format = get_option('time_format'); |
|
| 393 | 393 | ?> |
| 394 | 394 | <div id="wpinv-email-notes"> |
| 395 | - <h3 class="wpinv-notes-t"><?php echo esc_html( apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ) ); ?></h3> |
|
| 395 | + <h3 class="wpinv-notes-t"><?php echo esc_html(apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing'))); ?></h3> |
|
| 396 | 396 | <ol class="wpinv-notes-lists"> |
| 397 | 397 | <?php |
| 398 | - foreach ( $invoice_notes as $note ) { |
|
| 399 | - $note_time = strtotime( $note->comment_date ); |
|
| 398 | + foreach ($invoice_notes as $note) { |
|
| 399 | + $note_time = strtotime($note->comment_date); |
|
| 400 | 400 | ?> |
| 401 | 401 | <li class="comment wpinv-note"> |
| 402 | - <p class="wpinv-note-date meta"><?php printf( esc_html__( '%2$s at %3$s', 'invoicing' ), esc_html( $note->comment_author ), esc_html( date_i18n( $date_format, $note_time ) ), esc_html( date_i18n( $time_format, $note_time ) ), esc_html( $note_time ) ); ?></p> |
|
| 403 | - <div class="wpinv-note-desc description"><?php echo wp_kses_post( wpautop( wptexturize( $note->comment_content ) ) ); ?></div> |
|
| 402 | + <p class="wpinv-note-date meta"><?php printf(esc_html__('%2$s at %3$s', 'invoicing'), esc_html($note->comment_author), esc_html(date_i18n($date_format, $note_time)), esc_html(date_i18n($time_format, $note_time)), esc_html($note_time)); ?></p> |
|
| 403 | + <div class="wpinv-note-desc description"><?php echo wp_kses_post(wpautop(wptexturize($note->comment_content))); ?></div> |
|
| 404 | 404 | </li> |
| 405 | 405 | <?php |
| 406 | 406 | } |
@@ -410,4 +410,4 @@ discard block |
||
| 410 | 410 | <?php |
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
| 413 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|