@@ -218,262 +218,262 @@ discard block |
||
| 218 | 218 | add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
| 219 | 219 | |
| 220 | 220 | function wpinv_process_paypal_ipn() { |
| 221 | - // Check the request method is POST |
|
| 222 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 223 | - return; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Set initial post data to empty string |
|
| 227 | - $post_data = ''; |
|
| 228 | - |
|
| 229 | - // Fallback just in case post_max_size is lower than needed |
|
| 230 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 231 | - $post_data = file_get_contents( 'php://input' ); |
|
| 232 | - } else { |
|
| 233 | - // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
| 234 | - ini_set( 'post_max_size', '12M' ); |
|
| 235 | - } |
|
| 236 | - // Start the encoded data collection with notification command |
|
| 237 | - $encoded_data = 'cmd=_notify-validate'; |
|
| 238 | - |
|
| 239 | - // Get current arg separator |
|
| 240 | - $arg_separator = wpinv_get_php_arg_separator_output(); |
|
| 241 | - |
|
| 242 | - // Verify there is a post_data |
|
| 243 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 244 | - // Append the data |
|
| 245 | - $encoded_data .= $arg_separator.$post_data; |
|
| 246 | - } else { |
|
| 247 | - // Check if POST is empty |
|
| 248 | - if ( empty( $_POST ) ) { |
|
| 249 | - // Nothing to do |
|
| 250 | - return; |
|
| 251 | - } else { |
|
| 252 | - // Loop through each POST |
|
| 253 | - foreach ( $_POST as $key => $value ) { |
|
| 254 | - // Encode the value and append the data |
|
| 255 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - // Convert collected post data to an array |
|
| 261 | - parse_str( $encoded_data, $encoded_data_array ); |
|
| 262 | - |
|
| 263 | - foreach ( $encoded_data_array as $key => $value ) { |
|
| 264 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 265 | - $new_key = str_replace( '&', '&', $key ); |
|
| 266 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 267 | - |
|
| 268 | - unset( $encoded_data_array[ $key ] ); |
|
| 269 | - $encoded_data_array[ $new_key ] = $value; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // Get the PayPal redirect uri |
|
| 274 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 275 | - |
|
| 276 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 277 | - // Validate the IPN |
|
| 278 | - |
|
| 279 | - $remote_post_vars = array( |
|
| 280 | - 'method' => 'POST', |
|
| 281 | - 'timeout' => 45, |
|
| 282 | - 'redirection' => 5, |
|
| 283 | - 'httpversion' => '1.1', |
|
| 284 | - 'blocking' => true, |
|
| 285 | - 'headers' => array( |
|
| 286 | - 'host' => 'www.paypal.com', |
|
| 287 | - 'connection' => 'close', |
|
| 288 | - 'content-type' => 'application/x-www-form-urlencoded', |
|
| 289 | - 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
| 290 | - |
|
| 291 | - ), |
|
| 292 | - 'sslverify' => false, |
|
| 293 | - 'body' => $encoded_data_array |
|
| 294 | - ); |
|
| 295 | - |
|
| 296 | - // Get response |
|
| 297 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 298 | - |
|
| 299 | - if ( is_wp_error( $api_response ) ) { |
|
| 300 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 301 | - return; // Something went wrong |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 305 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 306 | - return; // Response not okay |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - // Check if $post_data_array has been populated |
|
| 311 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 312 | - return; |
|
| 313 | - |
|
| 314 | - $defaults = array( |
|
| 315 | - 'txn_type' => '', |
|
| 316 | - 'payment_status' => '' |
|
| 317 | - ); |
|
| 318 | - |
|
| 319 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 320 | - |
|
| 321 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 221 | + // Check the request method is POST |
|
| 222 | + if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 223 | + return; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Set initial post data to empty string |
|
| 227 | + $post_data = ''; |
|
| 228 | + |
|
| 229 | + // Fallback just in case post_max_size is lower than needed |
|
| 230 | + if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 231 | + $post_data = file_get_contents( 'php://input' ); |
|
| 232 | + } else { |
|
| 233 | + // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
| 234 | + ini_set( 'post_max_size', '12M' ); |
|
| 235 | + } |
|
| 236 | + // Start the encoded data collection with notification command |
|
| 237 | + $encoded_data = 'cmd=_notify-validate'; |
|
| 238 | + |
|
| 239 | + // Get current arg separator |
|
| 240 | + $arg_separator = wpinv_get_php_arg_separator_output(); |
|
| 241 | + |
|
| 242 | + // Verify there is a post_data |
|
| 243 | + if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 244 | + // Append the data |
|
| 245 | + $encoded_data .= $arg_separator.$post_data; |
|
| 246 | + } else { |
|
| 247 | + // Check if POST is empty |
|
| 248 | + if ( empty( $_POST ) ) { |
|
| 249 | + // Nothing to do |
|
| 250 | + return; |
|
| 251 | + } else { |
|
| 252 | + // Loop through each POST |
|
| 253 | + foreach ( $_POST as $key => $value ) { |
|
| 254 | + // Encode the value and append the data |
|
| 255 | + $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + // Convert collected post data to an array |
|
| 261 | + parse_str( $encoded_data, $encoded_data_array ); |
|
| 262 | + |
|
| 263 | + foreach ( $encoded_data_array as $key => $value ) { |
|
| 264 | + if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 265 | + $new_key = str_replace( '&', '&', $key ); |
|
| 266 | + $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 267 | + |
|
| 268 | + unset( $encoded_data_array[ $key ] ); |
|
| 269 | + $encoded_data_array[ $new_key ] = $value; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // Get the PayPal redirect uri |
|
| 274 | + $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 275 | + |
|
| 276 | + if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 277 | + // Validate the IPN |
|
| 278 | + |
|
| 279 | + $remote_post_vars = array( |
|
| 280 | + 'method' => 'POST', |
|
| 281 | + 'timeout' => 45, |
|
| 282 | + 'redirection' => 5, |
|
| 283 | + 'httpversion' => '1.1', |
|
| 284 | + 'blocking' => true, |
|
| 285 | + 'headers' => array( |
|
| 286 | + 'host' => 'www.paypal.com', |
|
| 287 | + 'connection' => 'close', |
|
| 288 | + 'content-type' => 'application/x-www-form-urlencoded', |
|
| 289 | + 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
| 290 | + |
|
| 291 | + ), |
|
| 292 | + 'sslverify' => false, |
|
| 293 | + 'body' => $encoded_data_array |
|
| 294 | + ); |
|
| 295 | + |
|
| 296 | + // Get response |
|
| 297 | + $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 298 | + |
|
| 299 | + if ( is_wp_error( $api_response ) ) { |
|
| 300 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 301 | + return; // Something went wrong |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 305 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 306 | + return; // Response not okay |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + // Check if $post_data_array has been populated |
|
| 311 | + if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 312 | + return; |
|
| 313 | + |
|
| 314 | + $defaults = array( |
|
| 315 | + 'txn_type' => '', |
|
| 316 | + 'payment_status' => '' |
|
| 317 | + ); |
|
| 318 | + |
|
| 319 | + $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 320 | + |
|
| 321 | + $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 322 | 322 | |
| 323 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 324 | - wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
| 325 | - |
|
| 326 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 327 | - // Allow PayPal IPN types to be processed separately |
|
| 328 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 329 | - } else { |
|
| 330 | - // Fallback to web accept just in case the txn_type isn't present |
|
| 331 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 332 | - } |
|
| 333 | - exit; |
|
| 323 | + wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 324 | + wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
| 325 | + |
|
| 326 | + if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 327 | + // Allow PayPal IPN types to be processed separately |
|
| 328 | + do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 329 | + } else { |
|
| 330 | + // Fallback to web accept just in case the txn_type isn't present |
|
| 331 | + do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 332 | + } |
|
| 333 | + exit; |
|
| 334 | 334 | } |
| 335 | 335 | add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
| 336 | 336 | |
| 337 | 337 | function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
| 338 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 339 | - return; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - if( empty( $invoice_id ) ) { |
|
| 343 | - return; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Collect payment details |
|
| 347 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 348 | - $paypal_amount = $data['mc_gross']; |
|
| 349 | - $payment_status = strtolower( $data['payment_status'] ); |
|
| 350 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
| 351 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 352 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 353 | - |
|
| 354 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 355 | - return; // this isn't a PayPal standard IPN |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // Verify payment recipient |
|
| 359 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 360 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 361 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 362 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Verify payment currency |
|
| 367 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 368 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 369 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 370 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 371 | - return; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 375 | - // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
| 376 | - // No email associated with purchase, so store from PayPal |
|
| 377 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 378 | - |
|
| 379 | - // Setup and store the customer's details |
|
| 380 | - $user_info = array( |
|
| 381 | - 'user_id' => '-1', |
|
| 382 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 383 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 384 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 385 | - 'discount' => '', |
|
| 386 | - ); |
|
| 387 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 388 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 389 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 390 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 391 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 392 | - |
|
| 393 | - $payment_meta['user_info'] = $user_info; |
|
| 394 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 398 | - // Process a refund |
|
| 399 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 400 | - } else { |
|
| 401 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 402 | - return; // Only paid payments once |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - // Retrieve the total purchase amount (before PayPal) |
|
| 406 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 407 | - |
|
| 408 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 409 | - // The prices don't match |
|
| 410 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 411 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 412 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 413 | - return; |
|
| 414 | - } |
|
| 415 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 416 | - // Purchase keys don't match |
|
| 417 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 418 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 419 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 420 | - return; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 424 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
| 425 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 426 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 427 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 428 | - // Look for possible pending reasons, such as an echeck |
|
| 429 | - $note = ''; |
|
| 430 | - |
|
| 431 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
| 432 | - case 'echeck' : |
|
| 433 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 434 | - break; |
|
| 338 | + if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 339 | + return; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + if( empty( $invoice_id ) ) { |
|
| 343 | + return; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Collect payment details |
|
| 347 | + $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 348 | + $paypal_amount = $data['mc_gross']; |
|
| 349 | + $payment_status = strtolower( $data['payment_status'] ); |
|
| 350 | + $currency_code = strtolower( $data['mc_currency'] ); |
|
| 351 | + $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 352 | + $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 353 | + |
|
| 354 | + if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 355 | + return; // this isn't a PayPal standard IPN |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // Verify payment recipient |
|
| 359 | + if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 360 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 361 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 362 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Verify payment currency |
|
| 367 | + if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 368 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 369 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 370 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 371 | + return; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 375 | + // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
| 376 | + // No email associated with purchase, so store from PayPal |
|
| 377 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 378 | + |
|
| 379 | + // Setup and store the customer's details |
|
| 380 | + $user_info = array( |
|
| 381 | + 'user_id' => '-1', |
|
| 382 | + 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 383 | + 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 384 | + 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 385 | + 'discount' => '', |
|
| 386 | + ); |
|
| 387 | + $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 388 | + $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 389 | + $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 390 | + $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 391 | + $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 392 | + |
|
| 393 | + $payment_meta['user_info'] = $user_info; |
|
| 394 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 398 | + // Process a refund |
|
| 399 | + wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 400 | + } else { |
|
| 401 | + if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 402 | + return; // Only paid payments once |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + // Retrieve the total purchase amount (before PayPal) |
|
| 406 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 407 | + |
|
| 408 | + if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 409 | + // The prices don't match |
|
| 410 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 411 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 412 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 413 | + return; |
|
| 414 | + } |
|
| 415 | + if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 416 | + // Purchase keys don't match |
|
| 417 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 418 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 419 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 420 | + return; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 424 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
| 425 | + wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 426 | + wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 427 | + } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 428 | + // Look for possible pending reasons, such as an echeck |
|
| 429 | + $note = ''; |
|
| 430 | + |
|
| 431 | + switch( strtolower( $data['pending_reason'] ) ) { |
|
| 432 | + case 'echeck' : |
|
| 433 | + $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 434 | + break; |
|
| 435 | 435 | |
| 436 | 436 | case 'address' : |
| 437 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 438 | - break; |
|
| 437 | + $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 438 | + break; |
|
| 439 | 439 | |
| 440 | 440 | case 'intl' : |
| 441 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 442 | - break; |
|
| 441 | + $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 442 | + break; |
|
| 443 | 443 | |
| 444 | 444 | case 'multi-currency' : |
| 445 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 446 | - break; |
|
| 445 | + $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 446 | + break; |
|
| 447 | 447 | |
| 448 | 448 | case 'paymentreview' : |
| 449 | 449 | case 'regulatory_review' : |
| 450 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 451 | - break; |
|
| 450 | + $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 451 | + break; |
|
| 452 | 452 | |
| 453 | 453 | case 'unilateral' : |
| 454 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 455 | - break; |
|
| 454 | + $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 455 | + break; |
|
| 456 | 456 | |
| 457 | 457 | case 'upgrade' : |
| 458 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 459 | - break; |
|
| 458 | + $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 459 | + break; |
|
| 460 | 460 | |
| 461 | 461 | case 'verify' : |
| 462 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 463 | - break; |
|
| 464 | - |
|
| 465 | - case 'other' : |
|
| 466 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 467 | - break; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - if ( ! empty( $note ) ) { |
|
| 471 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
| 472 | - } |
|
| 473 | - } else { |
|
| 474 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
| 475 | - } |
|
| 476 | - } |
|
| 462 | + $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 463 | + break; |
|
| 464 | + |
|
| 465 | + case 'other' : |
|
| 466 | + $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 467 | + break; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + if ( ! empty( $note ) ) { |
|
| 471 | + wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
| 472 | + } |
|
| 473 | + } else { |
|
| 474 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
| 479 | 479 | |
@@ -661,34 +661,34 @@ discard block |
||
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
| 664 | - // Collect payment details |
|
| 664 | + // Collect payment details |
|
| 665 | 665 | |
| 666 | - if( empty( $invoice_id ) ) { |
|
| 667 | - return; |
|
| 668 | - } |
|
| 666 | + if( empty( $invoice_id ) ) { |
|
| 667 | + return; |
|
| 668 | + } |
|
| 669 | 669 | |
| 670 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 671 | - return; // Only refund payments once |
|
| 672 | - } |
|
| 670 | + if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 671 | + return; // Only refund payments once |
|
| 672 | + } |
|
| 673 | 673 | |
| 674 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 675 | - $refund_amount = $data['mc_gross'] * -1; |
|
| 674 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 675 | + $refund_amount = $data['mc_gross'] * -1; |
|
| 676 | 676 | |
| 677 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
| 677 | + do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
| 678 | 678 | |
| 679 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 680 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 679 | + if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 680 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 681 | 681 | |
| 682 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
| 682 | + do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
| 683 | 683 | |
| 684 | - return; // This is a partial refund |
|
| 685 | - } |
|
| 684 | + return; // This is a partial refund |
|
| 685 | + } |
|
| 686 | 686 | |
| 687 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 688 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
| 689 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 687 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 688 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
| 689 | + wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 690 | 690 | |
| 691 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
| 691 | + do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | function wpinv_get_paypal_redirect( $ssl_check = false ) { |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | -add_action( 'wpinv_paypal_cc_form', '__return_false' ); |
|
| 6 | -add_filter( 'wpinv_paypal_support_subscription', '__return_true' ); |
|
| 5 | +add_action('wpinv_paypal_cc_form', '__return_false'); |
|
| 6 | +add_filter('wpinv_paypal_support_subscription', '__return_true'); |
|
| 7 | 7 | |
| 8 | -function wpinv_process_paypal_payment( $purchase_data ) { |
|
| 9 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
| 10 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 8 | +function wpinv_process_paypal_payment($purchase_data) { |
|
| 9 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
| 10 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | // Collect payment data |
@@ -25,30 +25,30 @@ discard block |
||
| 25 | 25 | ); |
| 26 | 26 | |
| 27 | 27 | // Record the pending payment |
| 28 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
| 28 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
| 29 | 29 | |
| 30 | 30 | // Check payment |
| 31 | - if ( ! $invoice ) { |
|
| 31 | + if (!$invoice) { |
|
| 32 | 32 | // Record the error |
| 33 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
| 33 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
| 34 | 34 | // Problems? send back |
| 35 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 35 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 36 | 36 | } else { |
| 37 | 37 | // Only send to PayPal if the pending payment is created successfully |
| 38 | - $listener_url = wpinv_get_ipn_url( 'paypal' ); |
|
| 38 | + $listener_url = wpinv_get_ipn_url('paypal'); |
|
| 39 | 39 | |
| 40 | 40 | // Get the success url |
| 41 | - $return_url = add_query_arg( array( |
|
| 41 | + $return_url = add_query_arg(array( |
|
| 42 | 42 | 'payment-confirm' => 'paypal', |
| 43 | 43 | 'invoice-id' => $invoice->ID |
| 44 | - ), get_permalink( wpinv_get_option( 'success_page', false ) ) ); |
|
| 44 | + ), get_permalink(wpinv_get_option('success_page', false))); |
|
| 45 | 45 | |
| 46 | 46 | // Get the PayPal redirect uri |
| 47 | - $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?'; |
|
| 47 | + $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?'; |
|
| 48 | 48 | |
| 49 | 49 | // Setup PayPal arguments |
| 50 | 50 | $paypal_args = array( |
| 51 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
| 51 | + 'business' => wpinv_get_option('paypal_email', false), |
|
| 52 | 52 | 'email' => $invoice->get_email(), |
| 53 | 53 | 'first_name' => $invoice->get_first_name(), |
| 54 | 54 | 'last_name' => $invoice->get_last_name(), |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | 'shipping' => '0', |
| 58 | 58 | 'no_note' => '1', |
| 59 | 59 | 'currency_code' => wpinv_get_currency(), |
| 60 | - 'charset' => get_bloginfo( 'charset' ), |
|
| 60 | + 'charset' => get_bloginfo('charset'), |
|
| 61 | 61 | 'custom' => $invoice->ID, |
| 62 | 62 | 'rm' => '2', |
| 63 | 63 | 'return' => $return_url, |
| 64 | - 'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ), |
|
| 64 | + 'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID), |
|
| 65 | 65 | 'notify_url' => $listener_url, |
| 66 | - 'cbt' => get_bloginfo( 'name' ), |
|
| 66 | + 'cbt' => get_bloginfo('name'), |
|
| 67 | 67 | 'bn' => 'WPInvoicing_SP', |
| 68 | 68 | 'lc' => 'US', // this will force paypal site to english |
| 69 | - 'landing_page' => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
| 69 | + 'landing_page' => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | $paypal_args['address1'] = $invoice->get_address(); |
@@ -80,57 +80,57 @@ discard block |
||
| 80 | 80 | 'upload' => '1' |
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
| 83 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
| 84 | 84 | |
| 85 | 85 | // Add cart items |
| 86 | 86 | $i = 1; |
| 87 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
| 88 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
| 87 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
| 88 | + foreach ($purchase_data['cart_details'] as $item) { |
|
| 89 | 89 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
| 90 | - $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 ); |
|
| 90 | + $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2); |
|
| 91 | 91 | |
| 92 | - if ( $item_amount <= 0 ) { |
|
| 92 | + if ($item_amount <= 0) { |
|
| 93 | 93 | $item_amount = 0; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
| 97 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
| 98 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
| 99 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
| 100 | - $paypal_args['discount_amount_' . $i ] = wpinv_sanitize_amount( $item['discount'], 2 ); |
|
| 96 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
| 97 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
| 98 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
| 99 | + $paypal_args['amount_' . $i] = $item_amount; |
|
| 100 | + $paypal_args['discount_amount_' . $i] = wpinv_sanitize_amount($item['discount'], 2); |
|
| 101 | 101 | |
| 102 | 102 | $i++; |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Add taxes to the cart |
| 107 | - if ( wpinv_use_taxes() ) { |
|
| 108 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 ); |
|
| 107 | + if (wpinv_use_taxes()) { |
|
| 108 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
| 111 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
| 112 | 112 | |
| 113 | 113 | // Build query |
| 114 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
| 114 | + $paypal_redirect .= http_build_query($paypal_args); |
|
| 115 | 115 | |
| 116 | 116 | // Fix for some sites that encode the entities |
| 117 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
| 117 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
| 118 | 118 | |
| 119 | 119 | // Get rid of cart contents |
| 120 | 120 | wpinv_empty_cart(); |
| 121 | 121 | |
| 122 | 122 | // Redirect to PayPal |
| 123 | - wp_redirect( $paypal_redirect ); |
|
| 123 | + wp_redirect($paypal_redirect); |
|
| 124 | 124 | exit; |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
| 127 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
| 128 | 128 | |
| 129 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
| 130 | - if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) { |
|
| 131 | - $item = new WPInv_Item( $item_id ); |
|
| 129 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
| 130 | + if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) { |
|
| 131 | + $item = new WPInv_Item($item_id); |
|
| 132 | 132 | |
| 133 | - if ( empty( $item ) ) { |
|
| 133 | + if (empty($item)) { |
|
| 134 | 134 | return $paypal_args; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -138,25 +138,25 @@ discard block |
||
| 138 | 138 | $interval = $item->get_recurring_interval(); |
| 139 | 139 | $bill_times = (int)$item->get_recurring_limit(); |
| 140 | 140 | |
| 141 | - $initial_amount = wpinv_sanitize_amount( $invoice->get_total(), 2 ); |
|
| 142 | - $recurring_amount = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 ); |
|
| 141 | + $initial_amount = wpinv_sanitize_amount($invoice->get_total(), 2); |
|
| 142 | + $recurring_amount = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2); |
|
| 143 | 143 | |
| 144 | 144 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
| 145 | 145 | $paypal_args['sra'] = '1'; |
| 146 | 146 | $paypal_args['src'] = '1'; |
| 147 | 147 | |
| 148 | 148 | // Set item description |
| 149 | - $item_name = sprintf( '[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name( array( 'id' => $item->ID ) ) ); |
|
| 150 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( $item_name, ENT_COMPAT, 'UTF-8' ) ); |
|
| 149 | + $item_name = sprintf('[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name(array('id' => $item->ID))); |
|
| 150 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode($item_name, ENT_COMPAT, 'UTF-8')); |
|
| 151 | 151 | |
| 152 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
| 152 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
| 153 | 153 | $paypal_args['a1'] = $initial_amount; |
| 154 | 154 | $paypal_args['p1'] = $item->get_trial_interval(); |
| 155 | 155 | $paypal_args['t1'] = $item->get_trial_period(); |
| 156 | 156 | |
| 157 | 157 | // Set the recurring amount |
| 158 | 158 | $paypal_args['a3'] = $recurring_amount; |
| 159 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
| 159 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
| 160 | 160 | $paypal_args['a1'] = $initial_amount; |
| 161 | 161 | $paypal_args['p1'] = $interval; |
| 162 | 162 | $paypal_args['t1'] = $period; |
@@ -164,63 +164,63 @@ discard block |
||
| 164 | 164 | // Set the recurring amount |
| 165 | 165 | $paypal_args['a3'] = $recurring_amount; |
| 166 | 166 | |
| 167 | - if ( $bill_times > 1 ) { |
|
| 167 | + if ($bill_times > 1) { |
|
| 168 | 168 | $bill_times--; |
| 169 | 169 | } |
| 170 | 170 | } else { |
| 171 | - $paypal_args['a3'] = $initial_amount; |
|
| 171 | + $paypal_args['a3'] = $initial_amount; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $paypal_args['p3'] = $interval; |
| 175 | 175 | $paypal_args['t3'] = $period; |
| 176 | 176 | |
| 177 | - if ( $bill_times > 1 ) { |
|
| 177 | + if ($bill_times > 1) { |
|
| 178 | 178 | // Make sure it's not over the max of 52 |
| 179 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
| 179 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // Remove cart items |
| 183 | 183 | $i = 1; |
| 184 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
| 185 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
| 186 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
| 187 | - unset( $paypal_args['item_number_' . $i] ); |
|
| 184 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
| 185 | + foreach ($purchase_data['cart_details'] as $item) { |
|
| 186 | + if (isset($paypal_args['item_number_' . $i])) { |
|
| 187 | + unset($paypal_args['item_number_' . $i]); |
|
| 188 | 188 | } |
| 189 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
| 190 | - unset( $paypal_args['item_name_' . $i] ); |
|
| 189 | + if (isset($paypal_args['item_name_' . $i])) { |
|
| 190 | + unset($paypal_args['item_name_' . $i]); |
|
| 191 | 191 | } |
| 192 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
| 193 | - unset( $paypal_args['quantity_' . $i] ); |
|
| 192 | + if (isset($paypal_args['quantity_' . $i])) { |
|
| 193 | + unset($paypal_args['quantity_' . $i]); |
|
| 194 | 194 | } |
| 195 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
| 196 | - unset( $paypal_args['amount_' . $i] ); |
|
| 195 | + if (isset($paypal_args['amount_' . $i])) { |
|
| 196 | + unset($paypal_args['amount_' . $i]); |
|
| 197 | 197 | } |
| 198 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
| 199 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
| 198 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
| 199 | + unset($paypal_args['discount_amount_' . $i]); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $i++; |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
| 207 | - unset( $paypal_args['tax_cart'] ); |
|
| 206 | + if (isset($paypal_args['tax_cart'])) { |
|
| 207 | + unset($paypal_args['tax_cart']); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if ( isset( $paypal_args['upload'] ) ) { |
|
| 211 | - unset( $paypal_args['upload'] ); |
|
| 210 | + if (isset($paypal_args['upload'])) { |
|
| 211 | + unset($paypal_args['upload']); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
| 214 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | return $paypal_args; |
| 218 | 218 | } |
| 219 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
| 219 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
| 220 | 220 | |
| 221 | 221 | function wpinv_process_paypal_ipn() { |
| 222 | 222 | // Check the request method is POST |
| 223 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 223 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | $post_data = ''; |
| 229 | 229 | |
| 230 | 230 | // Fallback just in case post_max_size is lower than needed |
| 231 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 232 | - $post_data = file_get_contents( 'php://input' ); |
|
| 231 | + if (ini_get('allow_url_fopen')) { |
|
| 232 | + $post_data = file_get_contents('php://input'); |
|
| 233 | 233 | } else { |
| 234 | 234 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
| 235 | - ini_set( 'post_max_size', '12M' ); |
|
| 235 | + ini_set('post_max_size', '12M'); |
|
| 236 | 236 | } |
| 237 | 237 | // Start the encoded data collection with notification command |
| 238 | 238 | $encoded_data = 'cmd=_notify-validate'; |
@@ -241,43 +241,43 @@ discard block |
||
| 241 | 241 | $arg_separator = wpinv_get_php_arg_separator_output(); |
| 242 | 242 | |
| 243 | 243 | // Verify there is a post_data |
| 244 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 244 | + if ($post_data || strlen($post_data) > 0) { |
|
| 245 | 245 | // Append the data |
| 246 | - $encoded_data .= $arg_separator.$post_data; |
|
| 246 | + $encoded_data .= $arg_separator . $post_data; |
|
| 247 | 247 | } else { |
| 248 | 248 | // Check if POST is empty |
| 249 | - if ( empty( $_POST ) ) { |
|
| 249 | + if (empty($_POST)) { |
|
| 250 | 250 | // Nothing to do |
| 251 | 251 | return; |
| 252 | 252 | } else { |
| 253 | 253 | // Loop through each POST |
| 254 | - foreach ( $_POST as $key => $value ) { |
|
| 254 | + foreach ($_POST as $key => $value) { |
|
| 255 | 255 | // Encode the value and append the data |
| 256 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 256 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Convert collected post data to an array |
| 262 | - parse_str( $encoded_data, $encoded_data_array ); |
|
| 262 | + parse_str($encoded_data, $encoded_data_array); |
|
| 263 | 263 | |
| 264 | - foreach ( $encoded_data_array as $key => $value ) { |
|
| 265 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 266 | - $new_key = str_replace( '&', '&', $key ); |
|
| 267 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 264 | + foreach ($encoded_data_array as $key => $value) { |
|
| 265 | + if (false !== strpos($key, 'amp;')) { |
|
| 266 | + $new_key = str_replace('&', '&', $key); |
|
| 267 | + $new_key = str_replace('amp;', '&', $new_key); |
|
| 268 | 268 | |
| 269 | - unset( $encoded_data_array[ $key ] ); |
|
| 270 | - $encoded_data_array[ $new_key ] = $value; |
|
| 269 | + unset($encoded_data_array[$key]); |
|
| 270 | + $encoded_data_array[$new_key] = $value; |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Get the PayPal redirect uri |
| 275 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 275 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
| 276 | 276 | |
| 277 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 277 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
| 278 | 278 | // Validate the IPN |
| 279 | 279 | |
| 280 | - $remote_post_vars = array( |
|
| 280 | + $remote_post_vars = array( |
|
| 281 | 281 | 'method' => 'POST', |
| 282 | 282 | 'timeout' => 45, |
| 283 | 283 | 'redirection' => 5, |
@@ -295,21 +295,21 @@ discard block |
||
| 295 | 295 | ); |
| 296 | 296 | |
| 297 | 297 | // Get response |
| 298 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 298 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
| 299 | 299 | |
| 300 | - if ( is_wp_error( $api_response ) ) { |
|
| 301 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 300 | + if (is_wp_error($api_response)) { |
|
| 301 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
| 302 | 302 | return; // Something went wrong |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 306 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 305 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
| 306 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
| 307 | 307 | return; // Response not okay |
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // Check if $post_data_array has been populated |
| 312 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 312 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
| 313 | 313 | return; |
| 314 | 314 | |
| 315 | 315 | $defaults = array( |
@@ -317,265 +317,265 @@ discard block |
||
| 317 | 317 | 'payment_status' => '' |
| 318 | 318 | ); |
| 319 | 319 | |
| 320 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 320 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
| 321 | 321 | |
| 322 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 322 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
| 323 | 323 | |
| 324 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 325 | - wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
| 324 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
| 325 | + wpinv_error_log($encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__); |
|
| 326 | 326 | |
| 327 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 327 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
| 328 | 328 | // Allow PayPal IPN types to be processed separately |
| 329 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 329 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
| 330 | 330 | } else { |
| 331 | 331 | // Fallback to web accept just in case the txn_type isn't present |
| 332 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 332 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
| 333 | 333 | } |
| 334 | 334 | exit; |
| 335 | 335 | } |
| 336 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
| 336 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
| 337 | 337 | |
| 338 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
| 339 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 338 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
| 339 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if( empty( $invoice_id ) ) { |
|
| 343 | + if (empty($invoice_id)) { |
|
| 344 | 344 | return; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // Collect payment details |
| 348 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 348 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
| 349 | 349 | $paypal_amount = $data['mc_gross']; |
| 350 | - $payment_status = strtolower( $data['payment_status'] ); |
|
| 351 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
| 352 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 353 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 350 | + $payment_status = strtolower($data['payment_status']); |
|
| 351 | + $currency_code = strtolower($data['mc_currency']); |
|
| 352 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
| 353 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
| 354 | 354 | |
| 355 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 355 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
| 356 | 356 | return; // this isn't a PayPal standard IPN |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | // Verify payment recipient |
| 360 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 361 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 362 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 363 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
| 360 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
| 361 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 362 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 363 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true); |
|
| 364 | 364 | return; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | // Verify payment currency |
| 368 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 369 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 370 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 371 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 368 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
| 369 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 370 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 371 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true); |
|
| 372 | 372 | return; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 375 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
| 376 | 376 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
| 377 | 377 | // No email associated with purchase, so store from PayPal |
| 378 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 378 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
| 379 | 379 | |
| 380 | 380 | // Setup and store the customer's details |
| 381 | 381 | $user_info = array( |
| 382 | 382 | 'user_id' => '-1', |
| 383 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 384 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 385 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 383 | + 'email' => sanitize_text_field($data['payer_email']), |
|
| 384 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
| 385 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
| 386 | 386 | 'discount' => '', |
| 387 | 387 | ); |
| 388 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 389 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 390 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 391 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 392 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 388 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
| 389 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
| 390 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
| 391 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
| 392 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
| 393 | 393 | |
| 394 | 394 | $payment_meta['user_info'] = $user_info; |
| 395 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 395 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 398 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
| 399 | 399 | // Process a refund |
| 400 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 400 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
| 401 | 401 | } else { |
| 402 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 402 | + if (get_post_status($invoice_id) == 'publish') { |
|
| 403 | 403 | return; // Only paid payments once |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | // Retrieve the total purchase amount (before PayPal) |
| 407 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 407 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
| 408 | 408 | |
| 409 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 409 | + if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
| 410 | 410 | // The prices don't match |
| 411 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 412 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 413 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 411 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 412 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 413 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true); |
|
| 414 | 414 | return; |
| 415 | 415 | } |
| 416 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 416 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
| 417 | 417 | // Purchase keys don't match |
| 418 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 419 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 420 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 418 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 419 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 420 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true); |
|
| 421 | 421 | return; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 425 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
| 426 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 427 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 428 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 424 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
| 425 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true); |
|
| 426 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
| 427 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
| 428 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
| 429 | 429 | // Look for possible pending reasons, such as an echeck |
| 430 | 430 | $note = ''; |
| 431 | 431 | |
| 432 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
| 432 | + switch (strtolower($data['pending_reason'])) { |
|
| 433 | 433 | case 'echeck' : |
| 434 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 434 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
| 435 | 435 | break; |
| 436 | 436 | |
| 437 | 437 | case 'address' : |
| 438 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 438 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
| 439 | 439 | break; |
| 440 | 440 | |
| 441 | 441 | case 'intl' : |
| 442 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 442 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
| 443 | 443 | break; |
| 444 | 444 | |
| 445 | 445 | case 'multi-currency' : |
| 446 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 446 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
| 447 | 447 | break; |
| 448 | 448 | |
| 449 | 449 | case 'paymentreview' : |
| 450 | 450 | case 'regulatory_review' : |
| 451 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 451 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
| 452 | 452 | break; |
| 453 | 453 | |
| 454 | 454 | case 'unilateral' : |
| 455 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 455 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
| 456 | 456 | break; |
| 457 | 457 | |
| 458 | 458 | case 'upgrade' : |
| 459 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 459 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
| 460 | 460 | break; |
| 461 | 461 | |
| 462 | 462 | case 'verify' : |
| 463 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 463 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
| 464 | 464 | break; |
| 465 | 465 | |
| 466 | 466 | case 'other' : |
| 467 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 467 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
| 468 | 468 | break; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - if ( ! empty( $note ) ) { |
|
| 472 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
| 471 | + if (!empty($note)) { |
|
| 472 | + wpinv_insert_payment_note($invoice_id, $note, '', '', true); |
|
| 473 | 473 | } |
| 474 | 474 | } else { |
| 475 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
| 475 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true); |
|
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
| 479 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
| 480 | 480 | |
| 481 | 481 | // Process PayPal subscription sign ups |
| 482 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
| 482 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
| 483 | 483 | |
| 484 | 484 | // Process PayPal subscription payments |
| 485 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
| 485 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
| 486 | 486 | |
| 487 | 487 | // Process PayPal subscription cancellations |
| 488 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
| 488 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
| 489 | 489 | |
| 490 | 490 | // Process PayPal subscription end of term notices |
| 491 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
| 491 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
| 492 | 492 | |
| 493 | 493 | // Process PayPal payment failed |
| 494 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
| 494 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
| 495 | 495 | |
| 496 | 496 | |
| 497 | 497 | /** |
| 498 | 498 | * Process the subscription started IPN. |
| 499 | 499 | */ |
| 500 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
| 501 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 502 | - if( empty( $parent_invoice_id ) ) { |
|
| 500 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
| 501 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 502 | + if (empty($parent_invoice_id)) { |
|
| 503 | 503 | return; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 507 | - if ( empty( $invoice ) ) { |
|
| 506 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 507 | + if (empty($invoice)) { |
|
| 508 | 508 | return; |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
| 512 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true); |
|
| 513 | - if ( !empty( $ipn_data['txn_id'] ) ) { |
|
| 514 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
| 511 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
| 512 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true); |
|
| 513 | + if (!empty($ipn_data['txn_id'])) { |
|
| 514 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 519 | - if ( false === $subscription ) { |
|
| 518 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 519 | + if (false === $subscription) { |
|
| 520 | 520 | return; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
| 523 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
| 524 | 524 | sleep(1); |
| 525 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true ); |
|
| 526 | - update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']); |
|
| 525 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true); |
|
| 526 | + update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']); |
|
| 527 | 527 | |
| 528 | 528 | $status = 'trialling' == $subscription->status ? 'trialling' : 'active'; |
| 529 | - $diff_days = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) ); |
|
| 530 | - $created = date_i18n( 'Y-m-d H:i:s' ); |
|
| 531 | - $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) ); |
|
| 529 | + $diff_days = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS)); |
|
| 530 | + $created = date_i18n('Y-m-d H:i:s'); |
|
| 531 | + $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS))); |
|
| 532 | 532 | |
| 533 | 533 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
| 534 | - $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration ) ); |
|
| 534 | + $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration)); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /** |
| 538 | 538 | * Process the subscription payment received IPN. |
| 539 | 539 | */ |
| 540 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
| 541 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 540 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
| 541 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 542 | 542 | |
| 543 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 544 | - if ( empty( $parent_invoice ) ) { |
|
| 543 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 544 | + if (empty($parent_invoice)) { |
|
| 545 | 545 | return; |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 549 | - if ( false === $subscription ) { |
|
| 548 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 549 | + if (false === $subscription) { |
|
| 550 | 550 | return; |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
| 553 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
| 554 | 554 | $times_billed = $subscription->get_times_billed(); |
| 555 | - $signup_date = strtotime( $subscription->created ); |
|
| 556 | - $today = date( 'Ynd', $signup_date ) == date( 'Ynd', strtotime( $ipn_data['payment_date'] ) ); |
|
| 555 | + $signup_date = strtotime($subscription->created); |
|
| 556 | + $today = date('Ynd', $signup_date) == date('Ynd', strtotime($ipn_data['payment_date'])); |
|
| 557 | 557 | |
| 558 | 558 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
| 559 | - if ( (empty($times_billed) || $today) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
| 560 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
| 559 | + if ((empty($times_billed) || $today) && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
| 560 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
| 561 | 561 | sleep(1); |
| 562 | 562 | |
| 563 | 563 | // This is the very first payment |
| 564 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
| 565 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true ); |
|
| 564 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
| 565 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true); |
|
| 566 | 566 | return; |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
| 569 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
| 570 | 570 | return; // Payment already recorded |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
| 573 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
| 574 | 574 | |
| 575 | 575 | // verify details |
| 576 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
| 576 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
| 577 | 577 | // the currency code is invalid |
| 578 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
| 578 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
| 579 | 579 | return; |
| 580 | 580 | } |
| 581 | 581 | |
@@ -585,11 +585,11 @@ discard block |
||
| 585 | 585 | 'gateway' => 'paypal' |
| 586 | 586 | ); |
| 587 | 587 | |
| 588 | - $invoice_id = $subscription->add_payment( $args ); |
|
| 588 | + $invoice_id = $subscription->add_payment($args); |
|
| 589 | 589 | |
| 590 | - if ( $invoice_id > 0 ) { |
|
| 591 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true ); |
|
| 592 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true ); |
|
| 590 | + if ($invoice_id > 0) { |
|
| 591 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true); |
|
| 592 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true); |
|
| 593 | 593 | |
| 594 | 594 | $subscription->renew(); |
| 595 | 595 | } |
@@ -598,10 +598,10 @@ discard block |
||
| 598 | 598 | /** |
| 599 | 599 | * Process the subscription canceled IPN. |
| 600 | 600 | */ |
| 601 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
| 602 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 601 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
| 602 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 603 | 603 | |
| 604 | - if( false === $subscription ) { |
|
| 604 | + if (false === $subscription) { |
|
| 605 | 605 | return; |
| 606 | 606 | } |
| 607 | 607 | |
@@ -611,10 +611,10 @@ discard block |
||
| 611 | 611 | /** |
| 612 | 612 | * Process the subscription expired IPN. |
| 613 | 613 | */ |
| 614 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
| 615 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 614 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
| 615 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 616 | 616 | |
| 617 | - if( false === $subscription ) { |
|
| 617 | + if (false === $subscription) { |
|
| 618 | 618 | return; |
| 619 | 619 | } |
| 620 | 620 | |
@@ -624,40 +624,40 @@ discard block |
||
| 624 | 624 | /** |
| 625 | 625 | * Process the subscription payment failed IPN. |
| 626 | 626 | */ |
| 627 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
| 628 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 627 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
| 628 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 629 | 629 | |
| 630 | - if( false === $subscription ) { |
|
| 630 | + if (false === $subscription) { |
|
| 631 | 631 | return; |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | $subscription->failing(); |
| 635 | 635 | |
| 636 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
| 636 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
| 640 | 640 | * Retrieve the subscription this IPN notice is for. |
| 641 | 641 | */ |
| 642 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
| 643 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 642 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
| 643 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 644 | 644 | |
| 645 | - if( empty( $parent_invoice_id ) ) { |
|
| 645 | + if (empty($parent_invoice_id)) { |
|
| 646 | 646 | return false; |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 650 | - if ( empty( $invoice ) ) { |
|
| 649 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 650 | + if (empty($invoice)) { |
|
| 651 | 651 | return false; |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | - $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true ); |
|
| 654 | + $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true); |
|
| 655 | 655 | |
| 656 | - if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) { |
|
| 657 | - $subscription = wpinv_get_subscription( $parent_invoice_id ); |
|
| 656 | + if (!(!empty($subscription) && $subscription->id > 0)) { |
|
| 657 | + $subscription = wpinv_get_subscription($parent_invoice_id); |
|
| 658 | 658 | |
| 659 | - if ( ! empty( $subscription ) && $subscription->id > 0 ) { |
|
| 660 | - $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
| 659 | + if (!empty($subscription) && $subscription->id > 0) { |
|
| 660 | + $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
| 661 | 661 | } else { |
| 662 | 662 | return false; |
| 663 | 663 | } |
@@ -667,46 +667,46 @@ discard block |
||
| 667 | 667 | |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
| 670 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
| 671 | 671 | // Collect payment details |
| 672 | 672 | |
| 673 | - if( empty( $invoice_id ) ) { |
|
| 673 | + if (empty($invoice_id)) { |
|
| 674 | 674 | return; |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 677 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
| 678 | 678 | return; // Only refund payments once |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 681 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
| 682 | 682 | $refund_amount = $data['mc_gross'] * -1; |
| 683 | 683 | |
| 684 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
| 684 | + do_action('wpinv_paypal_refund_request', $data, $invoice_id); |
|
| 685 | 685 | |
| 686 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 687 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 686 | + if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
| 687 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float)$refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true); |
|
| 688 | 688 | |
| 689 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
| 689 | + do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount); |
|
| 690 | 690 | |
| 691 | 691 | return; // This is a partial refund |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 695 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
| 696 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 694 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true); |
|
| 695 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true); |
|
| 696 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
| 697 | 697 | |
| 698 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
| 698 | + do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id); |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
| 702 | - if ( is_ssl() || ! $ssl_check ) { |
|
| 701 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
| 702 | + if (is_ssl() || !$ssl_check) { |
|
| 703 | 703 | $protocol = 'https://'; |
| 704 | 704 | } else { |
| 705 | 705 | $protocol = 'http://'; |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | // Check the current payment mode |
| 709 | - if ( wpinv_is_test_mode( 'paypal' ) ) { |
|
| 709 | + if (wpinv_is_test_mode('paypal')) { |
|
| 710 | 710 | // Test mode |
| 711 | 711 | $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
| 712 | 712 | } else { |
@@ -714,120 +714,120 @@ discard block |
||
| 714 | 714 | $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - return apply_filters( 'wpinv_paypal_uri', $paypal_uri ); |
|
| 717 | + return apply_filters('wpinv_paypal_uri', $paypal_uri); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | -function wpinv_paypal_success_page_content( $content ) { |
|
| 720 | +function wpinv_paypal_success_page_content($content) { |
|
| 721 | 721 | global $wpi_invoice; |
| 722 | 722 | |
| 723 | 723 | $session = wpinv_get_checkout_session(); |
| 724 | 724 | |
| 725 | - if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] ) ) { |
|
| 725 | + if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) { |
|
| 726 | 726 | return $content; |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
| 729 | + $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
| 730 | 730 | |
| 731 | - if ( empty( $invoice_id ) ) { |
|
| 731 | + if (empty($invoice_id)) { |
|
| 732 | 732 | return $content; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | - $wpi_invoice = wpinv_get_invoice( $invoice_id ); |
|
| 735 | + $wpi_invoice = wpinv_get_invoice($invoice_id); |
|
| 736 | 736 | |
| 737 | - if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) { |
|
| 737 | + if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) { |
|
| 738 | 738 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
| 739 | 739 | ob_start(); |
| 740 | - wpinv_get_template_part( 'wpinv-payment-processing' ); |
|
| 740 | + wpinv_get_template_part('wpinv-payment-processing'); |
|
| 741 | 741 | $content = ob_get_clean(); |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | return $content; |
| 745 | 745 | } |
| 746 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
| 746 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
| 747 | 747 | |
| 748 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
| 748 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
| 749 | 749 | $transaction_id = ''; |
| 750 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
| 750 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
| 751 | 751 | |
| 752 | - foreach ( $notes as $note ) { |
|
| 753 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
| 752 | + foreach ($notes as $note) { |
|
| 753 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
| 754 | 754 | $transaction_id = $match[1]; |
| 755 | 755 | continue; |
| 756 | 756 | } |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
| 759 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
| 760 | 760 | } |
| 761 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
| 761 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
| 762 | 762 | |
| 763 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
| 764 | - if ( $transaction_id == $invoice_id ) { |
|
| 763 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
| 764 | + if ($transaction_id == $invoice_id) { |
|
| 765 | 765 | $transaction_link = $transaction_id; |
| 766 | 766 | } else { |
| 767 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
| 767 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
| 768 | 768 | $mode = $invoice->mode; |
| 769 | 769 | } else { |
| 770 | - $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live'; |
|
| 770 | + $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live'; |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | $sandbox = $mode == 'test' ? '.sandbox' : ''; |
| 774 | 774 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/webscr?cmd=_history-details-from-hub&id=' . $transaction_id; |
| 775 | 775 | |
| 776 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 776 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice ); |
|
| 779 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice); |
|
| 780 | 780 | } |
| 781 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
| 781 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
| 782 | 782 | |
| 783 | -function wpinv_paypal_profile_id_link( $profile_id, $subscription ) { |
|
| 783 | +function wpinv_paypal_profile_id_link($profile_id, $subscription) { |
|
| 784 | 784 | $link = $profile_id; |
| 785 | 785 | |
| 786 | - if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
| 787 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 786 | + if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
| 787 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 788 | 788 | |
| 789 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
| 789 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
| 790 | 790 | $mode = $invoice->mode; |
| 791 | 791 | } else { |
| 792 | - $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live'; |
|
| 792 | + $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live'; |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | $sandbox = $mode == 'test' ? '.sandbox' : ''; |
| 796 | 796 | $url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=' . $profile_id; |
| 797 | 797 | |
| 798 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>'; |
|
| 798 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>'; |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | - return apply_filters( 'wpinv_paypal_profile_id_link', $link, $profile_id, $subscription ); |
|
| 801 | + return apply_filters('wpinv_paypal_profile_id_link', $link, $profile_id, $subscription); |
|
| 802 | 802 | } |
| 803 | -add_filter( 'wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2 ); |
|
| 803 | +add_filter('wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2); |
|
| 804 | 804 | |
| 805 | -function wpinv_paypal_transaction_id_link( $transaction_id, $subscription ) { |
|
| 806 | - if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
| 807 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 805 | +function wpinv_paypal_transaction_id_link($transaction_id, $subscription) { |
|
| 806 | + if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
| 807 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 808 | 808 | |
| 809 | - if ( ! empty( $invoice ) ) { |
|
| 810 | - return wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ); |
|
| 809 | + if (!empty($invoice)) { |
|
| 810 | + return wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice); |
|
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | return $transaction_id; |
| 815 | 815 | } |
| 816 | -add_filter( 'wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2 ); |
|
| 816 | +add_filter('wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2); |
|
| 817 | 817 | |
| 818 | 818 | function wpinv_is_paypal_valid_for_use() { |
| 819 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) ); |
|
| 819 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'))); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | -function wpinv_check_paypal_currency_support( $gateway_list ) { |
|
| 823 | - if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) { |
|
| 824 | - unset( $gateway_list['paypal'] ); |
|
| 822 | +function wpinv_check_paypal_currency_support($gateway_list) { |
|
| 823 | + if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) { |
|
| 824 | + unset($gateway_list['paypal']); |
|
| 825 | 825 | } |
| 826 | 826 | return $gateway_list; |
| 827 | 827 | } |
| 828 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 ); |
|
| 828 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1); |
|
| 829 | 829 | |
| 830 | -function wpinv_gateway_paypal_button_label( $label ) { |
|
| 831 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
| 830 | +function wpinv_gateway_paypal_button_label($label) { |
|
| 831 | + return __('Proceed to PayPal', 'invoicing'); |
|
| 832 | 832 | } |
| 833 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
| 834 | 833 | \ No newline at end of file |
| 834 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
| 835 | 835 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * Bail if we are not in WP. |
| 15 | 15 | */ |
| 16 | 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | - exit; |
|
| 17 | + exit; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -22,259 +22,259 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * A Class to be able to change settings for Font Awesome. |
|
| 27 | - * |
|
| 28 | - * Class WP_Font_Awesome_Settings |
|
| 29 | - * @ver 1.0.0 |
|
| 30 | - * @todo decide how to implement textdomain |
|
| 31 | - */ |
|
| 32 | - class WP_Font_Awesome_Settings { |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Class version version. |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - public $version = '1.0.0'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Latest version of Font Awesome when published. |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - public $latest = "5.5.0"; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * The title. |
|
| 50 | - * |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - public $name = 'Font Awesome'; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Holds the settings values. |
|
| 57 | - * |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - private $settings; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * WP_Font_Awesome_Settings instance. |
|
| 64 | - * |
|
| 65 | - * @access private |
|
| 66 | - * @since 1.0.0 |
|
| 67 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
| 68 | - */ |
|
| 69 | - private static $instance = null; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Main WP_Font_Awesome_Settings Instance. |
|
| 73 | - * |
|
| 74 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
| 75 | - * |
|
| 76 | - * @since 1.0.0 |
|
| 77 | - * @static |
|
| 78 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
| 79 | - */ |
|
| 80 | - public static function instance() { |
|
| 81 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 82 | - self::$instance = new WP_Font_Awesome_Settings; |
|
| 83 | - |
|
| 84 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 85 | - |
|
| 86 | - if(is_admin()){ |
|
| 87 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 88 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return self::$instance; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Initiate the settings and add the required action hooks. |
|
| 99 | - */ |
|
| 100 | - public function init(){ |
|
| 101 | - $this->settings =$this->get_settings(); |
|
| 102 | - |
|
| 103 | - if($this->settings['type']=='CSS'){ |
|
| 104 | - |
|
| 105 | - if($this->settings['enqueue'] == '' || $this->settings['frontend']){ |
|
| 106 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style'), 5000 );//echo '###';exit; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if($this->settings['enqueue'] == '' || $this->settings['backend']){ |
|
| 110 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style'), 5000 ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - }else{ |
|
| 114 | - |
|
| 115 | - if($this->settings['enqueue'] == '' || $this->settings['frontend']){ |
|
| 116 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts'), 5000 );//echo '###';exit; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if($this->settings['enqueue'] == '' || $this->settings['backend']){ |
|
| 120 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts'), 5000 ); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // remove font awesome if set to do so |
|
| 125 | - if($this->settings['dequeue']=='1'){ |
|
| 126 | - add_action( 'clean_url', array( $this, 'remove_font_awesome'), 5000, 3 ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Adds the Font Awesome styles. |
|
| 133 | - */ |
|
| 134 | - public function enqueue_style(){ |
|
| 135 | - // build url |
|
| 136 | - $url = $this->get_url(); |
|
| 137 | - |
|
| 138 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 139 | - wp_register_style( 'font-awesome', $url,array(), null ); |
|
| 140 | - wp_enqueue_style( 'font-awesome' ); |
|
| 141 | - |
|
| 142 | - if($this->settings['shims']){ |
|
| 143 | - $url = $this->get_url(true); |
|
| 144 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 145 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 146 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Adds the Font Awesome JS. |
|
| 152 | - */ |
|
| 153 | - public function enqueue_scripts(){ |
|
| 154 | - // build url |
|
| 155 | - $url = $this->get_url(); |
|
| 156 | - |
|
| 157 | - wp_deregister_script( 'font-awesome' ); // deregister in case its already there |
|
| 158 | - wp_register_script( 'font-awesome', $url,array(), null ); |
|
| 159 | - wp_enqueue_script( 'font-awesome' ); |
|
| 160 | - |
|
| 161 | - if($this->settings['shims']){ |
|
| 162 | - $url = $this->get_url(true); |
|
| 163 | - wp_deregister_script( 'font-awesome-shims' ); // deregister in case its already there |
|
| 164 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 165 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Get the url of the Font Awesome files. |
|
| 171 | - * |
|
| 172 | - * @param bool $shims If this is a shim file or not. |
|
| 173 | - * |
|
| 174 | - * @return string The url to the file. |
|
| 175 | - */ |
|
| 176 | - public function get_url($shims = false){ |
|
| 177 | - $script = $shims ? 'v4-shims' : 'all'; |
|
| 178 | - $type = $this->settings['type']; |
|
| 179 | - $version = $this->settings['version']; |
|
| 180 | - |
|
| 181 | - $url = "https://use.fontawesome.com/releases/"; // CDN |
|
| 182 | - $url .= !empty($version) ? "v".$version.'/' : "v".$this->latest.'/'; // version |
|
| 183 | - $url .= $type=='CSS' ? 'css/' : 'js/'; // type |
|
| 184 | - $url .= $type=='CSS' ? $script.'.css' : $script.'.js'; // type |
|
| 185 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 186 | - |
|
| 187 | - return $url; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
| 192 | - * |
|
| 193 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
| 194 | - * |
|
| 195 | - * @param $url |
|
| 196 | - * @param $original_url |
|
| 197 | - * @param $_context |
|
| 198 | - * |
|
| 199 | - * @return string The filtered url. |
|
| 200 | - */ |
|
| 201 | - public function remove_font_awesome($url, $original_url, $_context){ |
|
| 202 | - |
|
| 203 | - if ($_context=='display' && strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) {// it's a font-awesome-url (probably) |
|
| 204 | - |
|
| 205 | - if(strstr( $url, "wpfas=true" ) !== false){ |
|
| 206 | - if($this->settings['type']=='JS'){ |
|
| 207 | - if($this->settings['js-pseudo']){ |
|
| 208 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
| 209 | - }else{ |
|
| 210 | - $url .= "' defer='defer"; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - else{ |
|
| 215 | - $url = ''; // removing the url removes the file |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $url; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Register the database settings with WordPress. |
|
| 225 | - */ |
|
| 226 | - public function register_settings() { |
|
| 227 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Add the WordPress settings menu item. |
|
| 232 | - */ |
|
| 233 | - public function menu_item(){ |
|
| 234 | - add_options_page( $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array($this,'settings_page') ); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Get the current Font Awesome output settings. |
|
| 239 | - * |
|
| 240 | - * @return array The array of settings. |
|
| 241 | - */ |
|
| 242 | - public function get_settings(){ |
|
| 243 | - |
|
| 244 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 245 | - |
|
| 246 | - $defaults = array( |
|
| 247 | - 'type' => 'CSS', // type to use, CSS or JS |
|
| 248 | - 'version' => '', // latest |
|
| 249 | - 'enqueue' => '', // front and backend |
|
| 250 | - 'shims' => '1', // default on for now, @todo maybe change to off in 2020 |
|
| 251 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
| 252 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
| 253 | - ); |
|
| 254 | - |
|
| 255 | - $settings = wp_parse_args($db_settings,$defaults); |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Filter the Font Awesome settings. |
|
| 259 | - * |
|
| 260 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 261 | - */ |
|
| 262 | - return $this->settings = apply_filters('wp-font-awesome-settings',$settings,$db_settings,$defaults); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - public function settings_page() { |
|
| 267 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 268 | - wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
|
| 269 | - } |
|
| 270 | - ?> |
|
| 25 | + /** |
|
| 26 | + * A Class to be able to change settings for Font Awesome. |
|
| 27 | + * |
|
| 28 | + * Class WP_Font_Awesome_Settings |
|
| 29 | + * @ver 1.0.0 |
|
| 30 | + * @todo decide how to implement textdomain |
|
| 31 | + */ |
|
| 32 | + class WP_Font_Awesome_Settings { |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Class version version. |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + public $version = '1.0.0'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Latest version of Font Awesome when published. |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + public $latest = "5.5.0"; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * The title. |
|
| 50 | + * |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + public $name = 'Font Awesome'; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Holds the settings values. |
|
| 57 | + * |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + private $settings; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * WP_Font_Awesome_Settings instance. |
|
| 64 | + * |
|
| 65 | + * @access private |
|
| 66 | + * @since 1.0.0 |
|
| 67 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
| 68 | + */ |
|
| 69 | + private static $instance = null; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Main WP_Font_Awesome_Settings Instance. |
|
| 73 | + * |
|
| 74 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
| 75 | + * |
|
| 76 | + * @since 1.0.0 |
|
| 77 | + * @static |
|
| 78 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
| 79 | + */ |
|
| 80 | + public static function instance() { |
|
| 81 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 82 | + self::$instance = new WP_Font_Awesome_Settings; |
|
| 83 | + |
|
| 84 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 85 | + |
|
| 86 | + if(is_admin()){ |
|
| 87 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 88 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return self::$instance; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Initiate the settings and add the required action hooks. |
|
| 99 | + */ |
|
| 100 | + public function init(){ |
|
| 101 | + $this->settings =$this->get_settings(); |
|
| 102 | + |
|
| 103 | + if($this->settings['type']=='CSS'){ |
|
| 104 | + |
|
| 105 | + if($this->settings['enqueue'] == '' || $this->settings['frontend']){ |
|
| 106 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style'), 5000 );//echo '###';exit; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if($this->settings['enqueue'] == '' || $this->settings['backend']){ |
|
| 110 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style'), 5000 ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + }else{ |
|
| 114 | + |
|
| 115 | + if($this->settings['enqueue'] == '' || $this->settings['frontend']){ |
|
| 116 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts'), 5000 );//echo '###';exit; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if($this->settings['enqueue'] == '' || $this->settings['backend']){ |
|
| 120 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts'), 5000 ); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // remove font awesome if set to do so |
|
| 125 | + if($this->settings['dequeue']=='1'){ |
|
| 126 | + add_action( 'clean_url', array( $this, 'remove_font_awesome'), 5000, 3 ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Adds the Font Awesome styles. |
|
| 133 | + */ |
|
| 134 | + public function enqueue_style(){ |
|
| 135 | + // build url |
|
| 136 | + $url = $this->get_url(); |
|
| 137 | + |
|
| 138 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 139 | + wp_register_style( 'font-awesome', $url,array(), null ); |
|
| 140 | + wp_enqueue_style( 'font-awesome' ); |
|
| 141 | + |
|
| 142 | + if($this->settings['shims']){ |
|
| 143 | + $url = $this->get_url(true); |
|
| 144 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 145 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 146 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Adds the Font Awesome JS. |
|
| 152 | + */ |
|
| 153 | + public function enqueue_scripts(){ |
|
| 154 | + // build url |
|
| 155 | + $url = $this->get_url(); |
|
| 156 | + |
|
| 157 | + wp_deregister_script( 'font-awesome' ); // deregister in case its already there |
|
| 158 | + wp_register_script( 'font-awesome', $url,array(), null ); |
|
| 159 | + wp_enqueue_script( 'font-awesome' ); |
|
| 160 | + |
|
| 161 | + if($this->settings['shims']){ |
|
| 162 | + $url = $this->get_url(true); |
|
| 163 | + wp_deregister_script( 'font-awesome-shims' ); // deregister in case its already there |
|
| 164 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 165 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Get the url of the Font Awesome files. |
|
| 171 | + * |
|
| 172 | + * @param bool $shims If this is a shim file or not. |
|
| 173 | + * |
|
| 174 | + * @return string The url to the file. |
|
| 175 | + */ |
|
| 176 | + public function get_url($shims = false){ |
|
| 177 | + $script = $shims ? 'v4-shims' : 'all'; |
|
| 178 | + $type = $this->settings['type']; |
|
| 179 | + $version = $this->settings['version']; |
|
| 180 | + |
|
| 181 | + $url = "https://use.fontawesome.com/releases/"; // CDN |
|
| 182 | + $url .= !empty($version) ? "v".$version.'/' : "v".$this->latest.'/'; // version |
|
| 183 | + $url .= $type=='CSS' ? 'css/' : 'js/'; // type |
|
| 184 | + $url .= $type=='CSS' ? $script.'.css' : $script.'.js'; // type |
|
| 185 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 186 | + |
|
| 187 | + return $url; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
| 192 | + * |
|
| 193 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
| 194 | + * |
|
| 195 | + * @param $url |
|
| 196 | + * @param $original_url |
|
| 197 | + * @param $_context |
|
| 198 | + * |
|
| 199 | + * @return string The filtered url. |
|
| 200 | + */ |
|
| 201 | + public function remove_font_awesome($url, $original_url, $_context){ |
|
| 202 | + |
|
| 203 | + if ($_context=='display' && strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) {// it's a font-awesome-url (probably) |
|
| 204 | + |
|
| 205 | + if(strstr( $url, "wpfas=true" ) !== false){ |
|
| 206 | + if($this->settings['type']=='JS'){ |
|
| 207 | + if($this->settings['js-pseudo']){ |
|
| 208 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
| 209 | + }else{ |
|
| 210 | + $url .= "' defer='defer"; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + else{ |
|
| 215 | + $url = ''; // removing the url removes the file |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $url; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Register the database settings with WordPress. |
|
| 225 | + */ |
|
| 226 | + public function register_settings() { |
|
| 227 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Add the WordPress settings menu item. |
|
| 232 | + */ |
|
| 233 | + public function menu_item(){ |
|
| 234 | + add_options_page( $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array($this,'settings_page') ); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Get the current Font Awesome output settings. |
|
| 239 | + * |
|
| 240 | + * @return array The array of settings. |
|
| 241 | + */ |
|
| 242 | + public function get_settings(){ |
|
| 243 | + |
|
| 244 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 245 | + |
|
| 246 | + $defaults = array( |
|
| 247 | + 'type' => 'CSS', // type to use, CSS or JS |
|
| 248 | + 'version' => '', // latest |
|
| 249 | + 'enqueue' => '', // front and backend |
|
| 250 | + 'shims' => '1', // default on for now, @todo maybe change to off in 2020 |
|
| 251 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
| 252 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
| 253 | + ); |
|
| 254 | + |
|
| 255 | + $settings = wp_parse_args($db_settings,$defaults); |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Filter the Font Awesome settings. |
|
| 259 | + * |
|
| 260 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 261 | + */ |
|
| 262 | + return $this->settings = apply_filters('wp-font-awesome-settings',$settings,$db_settings,$defaults); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + public function settings_page() { |
|
| 267 | + if ( !current_user_can( 'manage_options' ) ) { |
|
| 268 | + wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
|
| 269 | + } |
|
| 270 | + ?> |
|
| 271 | 271 | <div class="wrap"> |
| 272 | 272 | <h1><?php echo $this->name; ?></h1> |
| 273 | 273 | <form method="post" action="options.php"> |
| 274 | 274 | <?php |
| 275 | - settings_fields( 'wp-font-awesome-settings' ); |
|
| 276 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 277 | - ?> |
|
| 275 | + settings_fields( 'wp-font-awesome-settings' ); |
|
| 276 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 277 | + ?> |
|
| 278 | 278 | <table class="form-table"> |
| 279 | 279 | <tr valign="top"> |
| 280 | 280 | <th scope="row"><label for="wpfas-type"><?php _e('Type');?></label></th> |
@@ -342,21 +342,21 @@ discard block |
||
| 342 | 342 | |
| 343 | 343 | </table> |
| 344 | 344 | <?php |
| 345 | - submit_button(); |
|
| 346 | - ?> |
|
| 345 | + submit_button(); |
|
| 346 | + ?> |
|
| 347 | 347 | </form> |
| 348 | 348 | |
| 349 | 349 | <div id="wpfas-version"><?php echo $this->version;?></div> |
| 350 | 350 | </div> |
| 351 | 351 | |
| 352 | 352 | <?php |
| 353 | - } |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | 355 | |
| 356 | - } |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Run the class if found. |
|
| 360 | - */ |
|
| 361 | - WP_Font_Awesome_Settings::instance(); |
|
| 358 | + /** |
|
| 359 | + * Run the class if found. |
|
| 360 | + */ |
|
| 361 | + WP_Font_Awesome_Settings::instance(); |
|
| 362 | 362 | } |
| 363 | 363 | \ No newline at end of file |
@@ -13,14 +13,14 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * Bail if we are not in WP. |
| 15 | 15 | */ |
| 16 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 16 | +if (!defined('ABSPATH')) { |
|
| 17 | 17 | exit; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Only add if the class does not already exist. |
| 22 | 22 | */ |
| 23 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
| 23 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * A Class to be able to change settings for Font Awesome. |
@@ -78,17 +78,17 @@ discard block |
||
| 78 | 78 | * @return WP_Font_Awesome_Settings - Main instance. |
| 79 | 79 | */ |
| 80 | 80 | public static function instance() { |
| 81 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 81 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
| 82 | 82 | self::$instance = new WP_Font_Awesome_Settings; |
| 83 | 83 | |
| 84 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 84 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
| 85 | 85 | |
| 86 | - if(is_admin()){ |
|
| 87 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 88 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 86 | + if (is_admin()) { |
|
| 87 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
| 88 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 91 | + do_action('wp_font_awesome_settings_loaded'); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return self::$instance; |
@@ -97,33 +97,33 @@ discard block |
||
| 97 | 97 | /** |
| 98 | 98 | * Initiate the settings and add the required action hooks. |
| 99 | 99 | */ |
| 100 | - public function init(){ |
|
| 101 | - $this->settings =$this->get_settings(); |
|
| 100 | + public function init() { |
|
| 101 | + $this->settings = $this->get_settings(); |
|
| 102 | 102 | |
| 103 | - if($this->settings['type']=='CSS'){ |
|
| 103 | + if ($this->settings['type'] == 'CSS') { |
|
| 104 | 104 | |
| 105 | - if($this->settings['enqueue'] == '' || $this->settings['frontend']){ |
|
| 106 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style'), 5000 );//echo '###';exit; |
|
| 105 | + if ($this->settings['enqueue'] == '' || $this->settings['frontend']) { |
|
| 106 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); //echo '###';exit; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if($this->settings['enqueue'] == '' || $this->settings['backend']){ |
|
| 110 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style'), 5000 ); |
|
| 109 | + if ($this->settings['enqueue'] == '' || $this->settings['backend']) { |
|
| 110 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - }else{ |
|
| 113 | + } else { |
|
| 114 | 114 | |
| 115 | - if($this->settings['enqueue'] == '' || $this->settings['frontend']){ |
|
| 116 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts'), 5000 );//echo '###';exit; |
|
| 115 | + if ($this->settings['enqueue'] == '' || $this->settings['frontend']) { |
|
| 116 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); //echo '###';exit; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if($this->settings['enqueue'] == '' || $this->settings['backend']){ |
|
| 120 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts'), 5000 ); |
|
| 119 | + if ($this->settings['enqueue'] == '' || $this->settings['backend']) { |
|
| 120 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // remove font awesome if set to do so |
| 125 | - if($this->settings['dequeue']=='1'){ |
|
| 126 | - add_action( 'clean_url', array( $this, 'remove_font_awesome'), 5000, 3 ); |
|
| 125 | + if ($this->settings['dequeue'] == '1') { |
|
| 126 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | } |
@@ -131,38 +131,38 @@ discard block |
||
| 131 | 131 | /** |
| 132 | 132 | * Adds the Font Awesome styles. |
| 133 | 133 | */ |
| 134 | - public function enqueue_style(){ |
|
| 134 | + public function enqueue_style() { |
|
| 135 | 135 | // build url |
| 136 | 136 | $url = $this->get_url(); |
| 137 | 137 | |
| 138 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 139 | - wp_register_style( 'font-awesome', $url,array(), null ); |
|
| 140 | - wp_enqueue_style( 'font-awesome' ); |
|
| 138 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
| 139 | + wp_register_style('font-awesome', $url, array(), null); |
|
| 140 | + wp_enqueue_style('font-awesome'); |
|
| 141 | 141 | |
| 142 | - if($this->settings['shims']){ |
|
| 142 | + if ($this->settings['shims']) { |
|
| 143 | 143 | $url = $this->get_url(true); |
| 144 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 145 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 146 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
| 144 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
| 145 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
| 146 | + wp_enqueue_style('font-awesome-shims'); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * Adds the Font Awesome JS. |
| 152 | 152 | */ |
| 153 | - public function enqueue_scripts(){ |
|
| 153 | + public function enqueue_scripts() { |
|
| 154 | 154 | // build url |
| 155 | 155 | $url = $this->get_url(); |
| 156 | 156 | |
| 157 | - wp_deregister_script( 'font-awesome' ); // deregister in case its already there |
|
| 158 | - wp_register_script( 'font-awesome', $url,array(), null ); |
|
| 159 | - wp_enqueue_script( 'font-awesome' ); |
|
| 157 | + wp_deregister_script('font-awesome'); // deregister in case its already there |
|
| 158 | + wp_register_script('font-awesome', $url, array(), null); |
|
| 159 | + wp_enqueue_script('font-awesome'); |
|
| 160 | 160 | |
| 161 | - if($this->settings['shims']){ |
|
| 161 | + if ($this->settings['shims']) { |
|
| 162 | 162 | $url = $this->get_url(true); |
| 163 | - wp_deregister_script( 'font-awesome-shims' ); // deregister in case its already there |
|
| 164 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 165 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
| 163 | + wp_deregister_script('font-awesome-shims'); // deregister in case its already there |
|
| 164 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
| 165 | + wp_enqueue_script('font-awesome-shims'); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
@@ -173,15 +173,15 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @return string The url to the file. |
| 175 | 175 | */ |
| 176 | - public function get_url($shims = false){ |
|
| 176 | + public function get_url($shims = false) { |
|
| 177 | 177 | $script = $shims ? 'v4-shims' : 'all'; |
| 178 | 178 | $type = $this->settings['type']; |
| 179 | 179 | $version = $this->settings['version']; |
| 180 | 180 | |
| 181 | 181 | $url = "https://use.fontawesome.com/releases/"; // CDN |
| 182 | - $url .= !empty($version) ? "v".$version.'/' : "v".$this->latest.'/'; // version |
|
| 183 | - $url .= $type=='CSS' ? 'css/' : 'js/'; // type |
|
| 184 | - $url .= $type=='CSS' ? $script.'.css' : $script.'.js'; // type |
|
| 182 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->latest . '/'; // version |
|
| 183 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
| 184 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
| 185 | 185 | $url .= "?wpfas=true"; // set our var so our version is not removed |
| 186 | 186 | |
| 187 | 187 | return $url; |
@@ -198,20 +198,20 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @return string The filtered url. |
| 200 | 200 | */ |
| 201 | - public function remove_font_awesome($url, $original_url, $_context){ |
|
| 201 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
| 202 | 202 | |
| 203 | - if ($_context=='display' && strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) {// it's a font-awesome-url (probably) |
|
| 203 | + if ($_context == 'display' && strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) {// it's a font-awesome-url (probably) |
|
| 204 | 204 | |
| 205 | - if(strstr( $url, "wpfas=true" ) !== false){ |
|
| 206 | - if($this->settings['type']=='JS'){ |
|
| 207 | - if($this->settings['js-pseudo']){ |
|
| 205 | + if (strstr($url, "wpfas=true") !== false) { |
|
| 206 | + if ($this->settings['type'] == 'JS') { |
|
| 207 | + if ($this->settings['js-pseudo']) { |
|
| 208 | 208 | $url .= "' data-search-pseudo-elements defer='defer"; |
| 209 | - }else{ |
|
| 209 | + } else { |
|
| 210 | 210 | $url .= "' defer='defer"; |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | - else{ |
|
| 214 | + else { |
|
| 215 | 215 | $url = ''; // removing the url removes the file |
| 216 | 216 | } |
| 217 | 217 | |
@@ -224,14 +224,14 @@ discard block |
||
| 224 | 224 | * Register the database settings with WordPress. |
| 225 | 225 | */ |
| 226 | 226 | public function register_settings() { |
| 227 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 227 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
| 231 | 231 | * Add the WordPress settings menu item. |
| 232 | 232 | */ |
| 233 | - public function menu_item(){ |
|
| 234 | - add_options_page( $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array($this,'settings_page') ); |
|
| 233 | + public function menu_item() { |
|
| 234 | + add_options_page($this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array($this, 'settings_page')); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -239,9 +239,9 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @return array The array of settings. |
| 241 | 241 | */ |
| 242 | - public function get_settings(){ |
|
| 242 | + public function get_settings() { |
|
| 243 | 243 | |
| 244 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 244 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
| 245 | 245 | |
| 246 | 246 | $defaults = array( |
| 247 | 247 | 'type' => 'CSS', // type to use, CSS or JS |
@@ -252,90 +252,90 @@ discard block |
||
| 252 | 252 | 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
| 253 | 253 | ); |
| 254 | 254 | |
| 255 | - $settings = wp_parse_args($db_settings,$defaults); |
|
| 255 | + $settings = wp_parse_args($db_settings, $defaults); |
|
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | 258 | * Filter the Font Awesome settings. |
| 259 | 259 | * |
| 260 | 260 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
| 261 | 261 | */ |
| 262 | - return $this->settings = apply_filters('wp-font-awesome-settings',$settings,$db_settings,$defaults); |
|
| 262 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
| 266 | 266 | public function settings_page() { |
| 267 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 268 | - wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
|
| 267 | + if (!current_user_can('manage_options')) { |
|
| 268 | + wp_die(__('You do not have sufficient permissions to access this page.')); |
|
| 269 | 269 | } |
| 270 | 270 | ?> |
| 271 | 271 | <div class="wrap"> |
| 272 | 272 | <h1><?php echo $this->name; ?></h1> |
| 273 | 273 | <form method="post" action="options.php"> |
| 274 | 274 | <?php |
| 275 | - settings_fields( 'wp-font-awesome-settings' ); |
|
| 276 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 275 | + settings_fields('wp-font-awesome-settings'); |
|
| 276 | + do_settings_sections('wp-font-awesome-settings'); |
|
| 277 | 277 | ?> |
| 278 | 278 | <table class="form-table"> |
| 279 | 279 | <tr valign="top"> |
| 280 | - <th scope="row"><label for="wpfas-type"><?php _e('Type');?></label></th> |
|
| 280 | + <th scope="row"><label for="wpfas-type"><?php _e('Type'); ?></label></th> |
|
| 281 | 281 | <td> |
| 282 | 282 | <select name="wp-font-awesome-settings[type]" id="wpfas-type"> |
| 283 | - <option value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e('CSS (default)');?></option> |
|
| 284 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
| 283 | + <option value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)'); ?></option> |
|
| 284 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
| 285 | 285 | </select> |
| 286 | 286 | </td> |
| 287 | 287 | </tr> |
| 288 | 288 | |
| 289 | 289 | <tr valign="top"> |
| 290 | - <th scope="row"><label for="wpfas-version"><?php _e('Version');?></label></th> |
|
| 290 | + <th scope="row"><label for="wpfas-version"><?php _e('Version'); ?></label></th> |
|
| 291 | 291 | <td> |
| 292 | 292 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
| 293 | - <option value="" <?php selected( $this->settings['version'], '' ); ?>><?php _e('Latest (default)');?></option> |
|
| 294 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>5.5.0</option> |
|
| 295 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>5.4.0</option> |
|
| 296 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>5.3.0</option> |
|
| 297 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>5.2.0</option> |
|
| 298 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>5.1.0</option> |
|
| 299 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>4.7.1 (CSS only)</option> |
|
| 293 | + <option value="" <?php selected($this->settings['version'], ''); ?>><?php _e('Latest (default)'); ?></option> |
|
| 294 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>>5.5.0</option> |
|
| 295 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>>5.4.0</option> |
|
| 296 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>>5.3.0</option> |
|
| 297 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>>5.2.0</option> |
|
| 298 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>>5.1.0</option> |
|
| 299 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>>4.7.1 (CSS only)</option> |
|
| 300 | 300 | </select> |
| 301 | 301 | </td> |
| 302 | 302 | </tr> |
| 303 | 303 | |
| 304 | 304 | <tr valign="top"> |
| 305 | - <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue');?></label></th> |
|
| 305 | + <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue'); ?></label></th> |
|
| 306 | 306 | <td> |
| 307 | 307 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
| 308 | - <option value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e('Frontend + Backend (default)');?></option> |
|
| 309 | - <option value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e('Frontend');?></option> |
|
| 310 | - <option value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e('Backend');?></option> |
|
| 308 | + <option value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)'); ?></option> |
|
| 309 | + <option value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend'); ?></option> |
|
| 310 | + <option value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend'); ?></option> |
|
| 311 | 311 | </select> |
| 312 | 312 | </td> |
| 313 | 313 | </tr> |
| 314 | 314 | |
| 315 | 315 | <tr valign="top"> |
| 316 | - <th scope="row"><label for="wpfas-shims"><?php _e('Enable v4 shims compatibility');?></label></th> |
|
| 316 | + <th scope="row"><label for="wpfas-shims"><?php _e('Enable v4 shims compatibility'); ?></label></th> |
|
| 317 | 317 | <td> |
| 318 | 318 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0" /> |
| 319 | - <input type="checkbox" name="wp-font-awesome-settings[shims]" value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims" /> |
|
| 320 | - <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.');?></span> |
|
| 319 | + <input type="checkbox" name="wp-font-awesome-settings[shims]" value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims" /> |
|
| 320 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.'); ?></span> |
|
| 321 | 321 | </td> |
| 322 | 322 | </tr> |
| 323 | 323 | |
| 324 | 324 | <tr valign="top"> |
| 325 | - <th scope="row"><label for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)');?></label></th> |
|
| 325 | + <th scope="row"><label for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)'); ?></label></th> |
|
| 326 | 326 | <td> |
| 327 | 327 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0" /> |
| 328 | - <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> id="wpfas-js-pseudo" /> |
|
| 329 | - <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.');?></span> |
|
| 328 | + <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> id="wpfas-js-pseudo" /> |
|
| 329 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.'); ?></span> |
|
| 330 | 330 | </td> |
| 331 | 331 | </tr> |
| 332 | 332 | |
| 333 | 333 | <tr valign="top"> |
| 334 | - <th scope="row"><label for="wpfas-dequeue"><?php _e('Dequeue');?></label></th> |
|
| 334 | + <th scope="row"><label for="wpfas-dequeue"><?php _e('Dequeue'); ?></label></th> |
|
| 335 | 335 | <td> |
| 336 | 336 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0" /> |
| 337 | - <input type="checkbox" name="wp-font-awesome-settings[dequeue]" value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> id="wpfas-dequeue" /> |
|
| 338 | - <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.');?></span> |
|
| 337 | + <input type="checkbox" name="wp-font-awesome-settings[dequeue]" value="1" <?php checked($this->settings['dequeue'], '1'); ?> id="wpfas-dequeue" /> |
|
| 338 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.'); ?></span> |
|
| 339 | 339 | </td> |
| 340 | 340 | </tr> |
| 341 | 341 | |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | ?> |
| 347 | 347 | </form> |
| 348 | 348 | |
| 349 | - <div id="wpfas-version"><?php echo $this->version;?></div> |
|
| 349 | + <div id="wpfas-version"><?php echo $this->version; ?></div> |
|
| 350 | 350 | </div> |
| 351 | 351 | |
| 352 | 352 | <?php |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style'), 5000 ); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - }else{ |
|
| 113 | + } else{ |
|
| 114 | 114 | |
| 115 | 115 | if($this->settings['enqueue'] == '' || $this->settings['frontend']){ |
| 116 | 116 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts'), 5000 );//echo '###';exit; |
@@ -206,12 +206,11 @@ discard block |
||
| 206 | 206 | if($this->settings['type']=='JS'){ |
| 207 | 207 | if($this->settings['js-pseudo']){ |
| 208 | 208 | $url .= "' data-search-pseudo-elements defer='defer"; |
| 209 | - }else{ |
|
| 209 | + } else{ |
|
| 210 | 210 | $url .= "' defer='defer"; |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | - } |
|
| 214 | - else{ |
|
| 213 | + } else{ |
|
| 215 | 214 | $url = ''; // removing the url removes the file |
| 216 | 215 | } |
| 217 | 216 | |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class WPInv_Plugin { |
| 15 | 15 | private static $instance; |
| 16 | 16 | |
| 17 | 17 | public static function run() { |
| 18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
| 18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
| 19 | 19 | self::$instance = new WPInv_Plugin; |
| 20 | 20 | self::$instance->includes(); |
| 21 | 21 | self::$instance->actions(); |
@@ -31,31 +31,31 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function define_constants() { |
| 34 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 35 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 34 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 35 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | private function actions() { |
| 39 | 39 | /* Internationalize the text strings used. */ |
| 40 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 40 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 41 | 41 | |
| 42 | 42 | /* Perform actions on admin initialization. */ |
| 43 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 44 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
| 45 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
| 46 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 43 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
| 44 | + add_action('init', array(&$this, 'init'), 3); |
|
| 45 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
| 46 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 47 | 47 | |
| 48 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 49 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 48 | + if (class_exists('BuddyPress')) { |
|
| 49 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 52 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 53 | 53 | |
| 54 | - if ( is_admin() ) { |
|
| 55 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 56 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 54 | + if (is_admin()) { |
|
| 55 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
| 56 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
| 57 | 57 | } else { |
| 58 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 58 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
| 67 | 67 | */ |
| 68 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 68 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
| 69 | 69 | |
| 70 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 70 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function plugins_loaded() { |
| 74 | 74 | /* Internationalize the text strings used. */ |
| 75 | 75 | $this->load_textdomain(); |
| 76 | 76 | |
| 77 | - do_action( 'wpinv_loaded' ); |
|
| 77 | + do_action('wpinv_loaded'); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -82,209 +82,209 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @since 1.0 |
| 84 | 84 | */ |
| 85 | - public function load_textdomain( $locale = NULL ) { |
|
| 86 | - if ( empty( $locale ) ) { |
|
| 87 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 85 | + public function load_textdomain($locale = NULL) { |
|
| 86 | + if (empty($locale)) { |
|
| 87 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 90 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 91 | 91 | |
| 92 | - unload_textdomain( 'invoicing' ); |
|
| 93 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 94 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 92 | + unload_textdomain('invoicing'); |
|
| 93 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 94 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Define language constants. |
| 98 | 98 | */ |
| 99 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 99 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function includes() { |
| 103 | 103 | global $wpinv_options; |
| 104 | 104 | |
| 105 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 105 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 106 | 106 | $wpinv_options = wpinv_get_settings(); |
| 107 | 107 | |
| 108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
| 109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
| 116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
| 122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
| 123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
| 124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
| 125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
| 126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
| 130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 132 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 133 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 134 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 135 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 136 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
| 137 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstract-wpinv-privacy.php' ); |
|
| 138 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 139 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wp-font-awesome-settings.php' ); |
|
| 140 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
| 141 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
| 109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
| 116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
| 122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
| 123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
| 124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
| 125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
| 126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
| 130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
| 131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
| 132 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
| 133 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
| 134 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
| 135 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
| 136 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
| 137 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstract-wpinv-privacy.php'); |
|
| 138 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
| 139 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wp-font-awesome-settings.php'); |
|
| 140 | + if (!class_exists('WPInv_EUVat')) { |
|
| 141 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 145 | - if ( !empty( $gateways ) ) { |
|
| 146 | - foreach ( $gateways as $gateway ) { |
|
| 147 | - if ( $gateway == 'manual' ) { |
|
| 144 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 145 | + if (!empty($gateways)) { |
|
| 146 | + foreach ($gateways as $gateway) { |
|
| 147 | + if ($gateway == 'manual') { |
|
| 148 | 148 | continue; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 152 | 152 | |
| 153 | - if ( file_exists( $gateway_file ) ) { |
|
| 154 | - require_once( $gateway_file ); |
|
| 153 | + if (file_exists($gateway_file)) { |
|
| 154 | + require_once($gateway_file); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
| 158 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
| 159 | 159 | |
| 160 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 161 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 162 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 163 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
| 160 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 161 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 162 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 163 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
| 164 | 164 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
| 165 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
| 166 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
| 167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 168 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
| 169 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 170 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 165 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
| 166 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
| 167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 168 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
| 169 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 170 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
| 171 | 171 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 172 | 172 | // load the user class only on the users.php page |
| 173 | 173 | global $pagenow; |
| 174 | - if($pagenow=='users.php'){ |
|
| 174 | + if ($pagenow == 'users.php') { |
|
| 175 | 175 | new WPInv_Admin_Users(); |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // include css inliner |
| 180 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 181 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 180 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 181 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 184 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | public function init() { |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | public function admin_init() { |
| 191 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
| 191 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 194 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | public function activation_redirect() { |
| 198 | 198 | // Bail if no activation redirect |
| 199 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 199 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
| 200 | 200 | return; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // Delete the redirect transient |
| 204 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 204 | + delete_transient('_wpinv_activation_redirect'); |
|
| 205 | 205 | |
| 206 | 206 | // Bail if activating from network, or bulk |
| 207 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 207 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 208 | 208 | return; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 211 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 212 | 212 | exit; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | public function enqueue_scripts() { |
| 216 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 216 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 217 | 217 | |
| 218 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
| 219 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 218 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
| 219 | + wp_enqueue_style('wpinv_front_style'); |
|
| 220 | 220 | |
| 221 | 221 | // Register scripts |
| 222 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 223 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
| 222 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 223 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
| 224 | 224 | |
| 225 | 225 | $localize = array(); |
| 226 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 227 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 226 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 227 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 228 | 228 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 229 | 229 | $localize['currency_pos'] = wpinv_currency_position(); |
| 230 | 230 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 231 | 231 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 232 | 232 | $localize['decimals'] = wpinv_decimals(); |
| 233 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
| 233 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
| 234 | 234 | |
| 235 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 235 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 236 | 236 | |
| 237 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 237 | + wp_enqueue_script('jquery-blockui'); |
|
| 238 | 238 | $autofill_api = wpinv_get_option('address_autofill_api'); |
| 239 | 239 | $autofill_active = wpinv_get_option('address_autofill_active'); |
| 240 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 241 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 242 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 240 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
| 241 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
| 242 | + wp_dequeue_script('google-maps-api'); |
|
| 243 | 243 | } |
| 244 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 245 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 244 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 245 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
| 246 | 246 | } |
| 247 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 248 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 247 | + wp_enqueue_script('wpinv-front-script'); |
|
| 248 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | public function admin_enqueue_scripts() { |
| 252 | 252 | global $post, $pagenow; |
| 253 | 253 | |
| 254 | 254 | $post_type = wpinv_admin_post_type(); |
| 255 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 256 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
| 255 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 256 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
| 257 | 257 | |
| 258 | 258 | $jquery_ui_css = false; |
| 259 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 259 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 260 | 260 | $jquery_ui_css = true; |
| 261 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
| 261 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
| 262 | 262 | $jquery_ui_css = true; |
| 263 | 263 | } |
| 264 | - if ( $jquery_ui_css ) { |
|
| 265 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 266 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 264 | + if ($jquery_ui_css) { |
|
| 265 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
| 266 | + wp_enqueue_style('jquery-ui-css'); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 270 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 269 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
| 270 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
| 271 | 271 | |
| 272 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
| 273 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 272 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
| 273 | + wp_enqueue_style('wpinv_admin_style'); |
|
| 274 | 274 | |
| 275 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
| 276 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 277 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 275 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
| 276 | + if ($page == 'wpinv-subscriptions') { |
|
| 277 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
| 281 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 280 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
| 281 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 285 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 284 | + wp_enqueue_style('wp-color-picker'); |
|
| 285 | + wp_enqueue_script('wp-color-picker'); |
|
| 286 | 286 | |
| 287 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 287 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 288 | 288 | |
| 289 | 289 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
| 290 | 290 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -295,17 +295,17 @@ discard block |
||
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
| 299 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 298 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
| 299 | + wp_enqueue_script('wpinv-admin-script'); |
|
| 300 | 300 | |
| 301 | 301 | $localize = array(); |
| 302 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 303 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 304 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 305 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 306 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 307 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 308 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 302 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 303 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
| 304 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 305 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
| 306 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
| 307 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
| 308 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
| 309 | 309 | $localize['tax'] = wpinv_tax_amount(); |
| 310 | 310 | $localize['discount'] = wpinv_discount_amount(); |
| 311 | 311 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -313,69 +313,69 @@ discard block |
||
| 313 | 313 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 314 | 314 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 315 | 315 | $localize['decimals'] = wpinv_decimals(); |
| 316 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 317 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 318 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 319 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 320 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 321 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 322 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 323 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
| 324 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 325 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
| 326 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 327 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
| 328 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
| 329 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
| 316 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
| 317 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
| 318 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
| 319 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
| 320 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
| 321 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
| 322 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
| 323 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
| 324 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
| 325 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
| 326 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
| 327 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
| 328 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
| 329 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
| 330 | 330 | |
| 331 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 331 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
| 332 | 332 | |
| 333 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 333 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
| 334 | 334 | |
| 335 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 336 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 337 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 335 | + if ($page == 'wpinv-subscriptions') { |
|
| 336 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
| 337 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - public function admin_body_class( $classes ) { |
|
| 341 | + public function admin_body_class($classes) { |
|
| 342 | 342 | global $pagenow, $post, $current_screen; |
| 343 | 343 | |
| 344 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
| 344 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
| 345 | 345 | $classes .= ' wpinv-cpt'; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 348 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
| 349 | 349 | |
| 350 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
| 351 | - if ( $add_class ) { |
|
| 352 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
| 350 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
| 351 | + if ($add_class) { |
|
| 352 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | $settings_class = array(); |
| 356 | - if ( $page == 'wpinv-settings' ) { |
|
| 357 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 358 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 356 | + if ($page == 'wpinv-settings') { |
|
| 357 | + if (!empty($_REQUEST['tab'])) { |
|
| 358 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 362 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 361 | + if (!empty($_REQUEST['section'])) { |
|
| 362 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 365 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - if ( !empty( $settings_class ) ) { |
|
| 369 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 368 | + if (!empty($settings_class)) { |
|
| 369 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | $post_type = wpinv_admin_post_type(); |
| 373 | 373 | |
| 374 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 374 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
| 375 | 375 | return $classes .= ' wpinv'; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 378 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
| 379 | 379 | $classes .= ' wpi-editable-n'; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -387,20 +387,20 @@ discard block |
||
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | public function wpinv_actions() { |
| 390 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 391 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 391 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - public function pre_get_posts( $wp_query ) { |
|
| 396 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 397 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 395 | + public function pre_get_posts($wp_query) { |
|
| 396 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 397 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | return $wp_query; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | public function bp_invoicing_init() { |
| 404 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 404 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | \ No newline at end of file |