@@ -1,18 +1,18 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // don't load directly |
| 3 | -if ( !defined('ABSPATH') ) |
|
| 3 | +if (!defined('ABSPATH')) |
|
| 4 | 4 | die('-1'); |
| 5 | 5 | |
| 6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
| 6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
| 7 | 7 | |
| 8 | -if ( ! empty( $message_body ) ) { |
|
| 9 | - echo wpautop( wptexturize( $message_body ) ); |
|
| 8 | +if (!empty($message_body)) { |
|
| 9 | + echo wpautop(wptexturize($message_body)); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
| 12 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
| 13 | 13 | |
| 14 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
| 14 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
| 15 | 15 | |
| 16 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
| 16 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
| 17 | 17 | |
| 18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
| 19 | 18 | \ No newline at end of file |
| 19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
| 20 | 20 | \ No newline at end of file |
@@ -1,22 +1,22 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // don't load directly |
| 3 | -if ( !defined('ABSPATH') ) |
|
| 3 | +if (!defined('ABSPATH')) |
|
| 4 | 4 | die('-1'); |
| 5 | 5 | |
| 6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
| 6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
| 7 | 7 | |
| 8 | -do_action( 'wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note ); |
|
| 8 | +do_action('wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note); |
|
| 9 | 9 | |
| 10 | -if ( ! empty( $message_body ) ) { |
|
| 11 | - echo wpautop( wptexturize( $message_body ) ); |
|
| 10 | +if (!empty($message_body)) { |
|
| 11 | + echo wpautop(wptexturize($message_body)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
| 14 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
| 15 | 15 | |
| 16 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
| 16 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
| 17 | 17 | |
| 18 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
| 18 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
| 19 | 19 | |
| 20 | -do_action( 'wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note ); |
|
| 20 | +do_action('wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note); |
|
| 21 | 21 | |
| 22 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
| 23 | 22 | \ No newline at end of file |
| 23 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
| 24 | 24 | \ No newline at end of file |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // don't load directly |
| 3 | -if ( !defined('ABSPATH') ) |
|
| 3 | +if (!defined('ABSPATH')) |
|
| 4 | 4 | die('-1'); |
| 5 | 5 | |
| 6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
| 6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
| 7 | 7 | |
| 8 | -if ( ! empty( $message_body ) ) { |
|
| 9 | - echo wpautop( wptexturize( $message_body ) ); |
|
| 8 | +if (!empty($message_body)) { |
|
| 9 | + echo wpautop(wptexturize($message_body)); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
| 13 | 12 | \ No newline at end of file |
| 13 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
| 14 | 14 | \ No newline at end of file |
@@ -29,16 +29,16 @@ |
||
| 29 | 29 | <table class="table table-bordered table-hover table-responsive wpi-user-subscriptions"> |
| 30 | 30 | <thead> |
| 31 | 31 | <tr> |
| 32 | - <th class="sub-no"><span class="nobr"><?php _e( 'No.', 'invoicing' ); ?></span></th> |
|
| 33 | - <th class="sub-amount"><span class="nobr"><?php _e( 'Initial Amount', 'invoicing' ); ?></span></th> |
|
| 34 | - <th class="sub-cycle"><span class="nobr"><?php _e( 'Billing Cycle', 'invoicing' ); ?></span></th> |
|
| 35 | - <th class="sub-billed"><span class="nobr"><?php _e( 'Times Billed', 'invoicing' ); ?></span></th> |
|
| 36 | - <th class="sub-status"><span class="nobr"><?php _e( 'Status', 'invoicing' ); ?></span></th> |
|
| 37 | - <th class="sub-invoice"><span class="nobr"><?php _e( 'Invoice', 'invoicing' ); ?></span></th> |
|
| 38 | - <th class="sub-item"><span class="nobr"><?php _e( 'Item', 'invoicing' ); ?></span></th> |
|
| 39 | - <th class="sub-gateway"><span class="nobr"><?php _e( 'Gateway', 'invoicing' ); ?></span></th> |
|
| 40 | - <th class="sub-expiry"><span class="nobr"><?php _e( 'Expires On', 'invoicing' ); ?></span></th> |
|
| 41 | - <th class="sub-actions"><span class="nobr"><?php _e( 'Actions', 'invoicing' ); ?></span></th> |
|
| 32 | + <th class="sub-no"><span class="nobr"><?php _e('No.', 'invoicing'); ?></span></th> |
|
| 33 | + <th class="sub-amount"><span class="nobr"><?php _e('Initial Amount', 'invoicing'); ?></span></th> |
|
| 34 | + <th class="sub-cycle"><span class="nobr"><?php _e('Billing Cycle', 'invoicing'); ?></span></th> |
|
| 35 | + <th class="sub-billed"><span class="nobr"><?php _e('Times Billed', 'invoicing'); ?></span></th> |
|
| 36 | + <th class="sub-status"><span class="nobr"><?php _e('Status', 'invoicing'); ?></span></th> |
|
| 37 | + <th class="sub-invoice"><span class="nobr"><?php _e('Invoice', 'invoicing'); ?></span></th> |
|
| 38 | + <th class="sub-item"><span class="nobr"><?php _e('Item', 'invoicing'); ?></span></th> |
|
| 39 | + <th class="sub-gateway"><span class="nobr"><?php _e('Gateway', 'invoicing'); ?></span></th> |
|
| 40 | + <th class="sub-expiry"><span class="nobr"><?php _e('Expires On', 'invoicing'); ?></span></th> |
|
| 41 | + <th class="sub-actions"><span class="nobr"><?php _e('Actions', 'invoicing'); ?></span></th> |
|
| 42 | 42 | </tr> |
| 43 | 43 | </thead> |
| 44 | 44 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -14,18 +14,18 @@ discard block |
||
| 14 | 14 | * Hook in methods. |
| 15 | 15 | */ |
| 16 | 16 | public static function init() { |
| 17 | - add_action( 'init', array( __CLASS__, 'init_hooks' ), 0 ); |
|
| 18 | - add_action( 'admin_notices', array( __CLASS__, 'notices' ) ); |
|
| 17 | + add_action('init', array(__CLASS__, 'init_hooks'), 0); |
|
| 18 | + add_action('admin_notices', array(__CLASS__, 'notices')); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public static function init_hooks() { |
| 22 | - if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) { |
|
| 23 | - $checkout_page = wpinv_get_option( 'checkout_page', '' ); |
|
| 24 | - $success_page = wpinv_get_option( 'success_page', '' ); |
|
| 25 | - $failure_page = wpinv_get_option( 'failure_page', '' ); |
|
| 26 | - $history_page = wpinv_get_option( 'invoice_history_page', '' ); |
|
| 27 | - $subscr_page = wpinv_get_option( 'invoice_subscription_page', '' ); |
|
| 28 | - if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) { |
|
| 22 | + if (false === ($page_uris = get_transient('wpinv_cache_excluded_uris'))) { |
|
| 23 | + $checkout_page = wpinv_get_option('checkout_page', ''); |
|
| 24 | + $success_page = wpinv_get_option('success_page', ''); |
|
| 25 | + $failure_page = wpinv_get_option('failure_page', ''); |
|
| 26 | + $history_page = wpinv_get_option('invoice_history_page', ''); |
|
| 27 | + $subscr_page = wpinv_get_option('invoice_subscription_page', ''); |
|
| 28 | + if (empty($checkout_page) || empty($success_page) || empty($failure_page) || empty($history_page) || empty($subscr_page)) { |
|
| 29 | 29 | return; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -39,34 +39,34 @@ discard block |
||
| 39 | 39 | $page_uris[] = 'p=' . $subscr_page; |
| 40 | 40 | |
| 41 | 41 | // Exclude permalinks |
| 42 | - $checkout_page = get_post( $checkout_page ); |
|
| 43 | - $success_page = get_post( $success_page ); |
|
| 44 | - $failure_page = get_post( $failure_page ); |
|
| 45 | - $history_page = get_post( $history_page ); |
|
| 46 | - $subscr_page = get_post( $subscr_page ); |
|
| 42 | + $checkout_page = get_post($checkout_page); |
|
| 43 | + $success_page = get_post($success_page); |
|
| 44 | + $failure_page = get_post($failure_page); |
|
| 45 | + $history_page = get_post($history_page); |
|
| 46 | + $subscr_page = get_post($subscr_page); |
|
| 47 | 47 | |
| 48 | - if ( ! is_null( $checkout_page ) ) { |
|
| 48 | + if (!is_null($checkout_page)) { |
|
| 49 | 49 | $page_uris[] = '/' . $checkout_page->post_name; |
| 50 | 50 | } |
| 51 | - if ( ! is_null( $success_page ) ) { |
|
| 51 | + if (!is_null($success_page)) { |
|
| 52 | 52 | $page_uris[] = '/' . $success_page->post_name; |
| 53 | 53 | } |
| 54 | - if ( ! is_null( $failure_page ) ) { |
|
| 54 | + if (!is_null($failure_page)) { |
|
| 55 | 55 | $page_uris[] = '/' . $failure_page->post_name; |
| 56 | 56 | } |
| 57 | - if ( ! is_null( $history_page ) ) { |
|
| 57 | + if (!is_null($history_page)) { |
|
| 58 | 58 | $page_uris[] = '/' . $history_page->post_name; |
| 59 | 59 | } |
| 60 | - if ( ! is_null( $subscr_page ) ) { |
|
| 60 | + if (!is_null($subscr_page)) { |
|
| 61 | 61 | $page_uris[] = '/' . $subscr_page->post_name; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - set_transient( 'wpinv_cache_excluded_uris', $page_uris ); |
|
| 64 | + set_transient('wpinv_cache_excluded_uris', $page_uris); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ( is_array( $page_uris ) ) { |
|
| 68 | - foreach( $page_uris as $uri ) { |
|
| 69 | - if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) { |
|
| 67 | + if (is_array($page_uris)) { |
|
| 68 | + foreach ($page_uris as $uri) { |
|
| 69 | + if (strstr($_SERVER['REQUEST_URI'], $uri)) { |
|
| 70 | 70 | self::nocache(); |
| 71 | 71 | break; |
| 72 | 72 | } |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | * @access private |
| 80 | 80 | */ |
| 81 | 81 | private static function nocache() { |
| 82 | - if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
|
| 83 | - define( "DONOTCACHEPAGE", true ); |
|
| 82 | + if (!defined('DONOTCACHEPAGE')) { |
|
| 83 | + define("DONOTCACHEPAGE", true); |
|
| 84 | 84 | } |
| 85 | - if ( ! defined( 'DONOTCACHEOBJECT' ) ) { |
|
| 86 | - define( "DONOTCACHEOBJECT", true ); |
|
| 85 | + if (!defined('DONOTCACHEOBJECT')) { |
|
| 86 | + define("DONOTCACHEOBJECT", true); |
|
| 87 | 87 | } |
| 88 | - if ( ! defined( 'DONOTCACHEDB' ) ) { |
|
| 89 | - define( "DONOTCACHEDB", true ); |
|
| 88 | + if (!defined('DONOTCACHEDB')) { |
|
| 89 | + define("DONOTCACHEDB", true); |
|
| 90 | 90 | } |
| 91 | 91 | nocache_headers(); |
| 92 | 92 | } |
@@ -95,18 +95,18 @@ discard block |
||
| 95 | 95 | * notices function. |
| 96 | 96 | */ |
| 97 | 97 | public static function notices() { |
| 98 | - if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) { |
|
| 98 | + if (!function_exists('w3tc_pgcache_flush') || !function_exists('w3_instance')) { |
|
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $config = w3_instance( 'W3_Config' ); |
|
| 103 | - $enabled = $config->get_integer( 'dbcache.enabled' ); |
|
| 104 | - $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) ); |
|
| 102 | + $config = w3_instance('W3_Config'); |
|
| 103 | + $enabled = $config->get_integer('dbcache.enabled'); |
|
| 104 | + $settings = array_map('trim', $config->get_array('dbcache.reject.sql')); |
|
| 105 | 105 | |
| 106 | - if ( $enabled && ! in_array( '_wp_session_', $settings ) ) { |
|
| 106 | + if ($enabled && !in_array('_wp_session_', $settings)) { |
|
| 107 | 107 | ?> |
| 108 | 108 | <div class="error"> |
| 109 | - <p><?php printf( __( 'In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing' ), '<code>_wp_session_</code>', admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?></p> |
|
| 109 | + <p><?php printf(__('In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing'), '<code>_wp_session_</code>', admin_url('admin.php?page=w3tc_dbcache')); ?></p> |
|
| 110 | 110 | </div> |
| 111 | 111 | <?php |
| 112 | 112 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -16,41 +16,41 @@ discard block |
||
| 16 | 16 | 'wpinv_subscriptions' => __CLASS__ . '::subscriptions', |
| 17 | 17 | ); |
| 18 | 18 | |
| 19 | - foreach ( $shortcodes as $shortcode => $function ) { |
|
| 20 | - add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function ); |
|
| 19 | + foreach ($shortcodes as $shortcode => $function) { |
|
| 20 | + add_shortcode(apply_filters("{$shortcode}_shortcode_tag", $shortcode), $function); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - add_shortcode( 'wpinv_messages', __CLASS__ . '::messages' ); |
|
| 23 | + add_shortcode('wpinv_messages', __CLASS__ . '::messages'); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public static function shortcode_wrapper( $function, $atts = array(), $content = null, $wrapper = array( 'class' => 'wpi-g', 'before' => null, 'after' => null ) ) { |
|
| 26 | + public static function shortcode_wrapper($function, $atts = array(), $content = null, $wrapper = array('class' => 'wpi-g', 'before' => null, 'after' => null)) { |
|
| 27 | 27 | ob_start(); |
| 28 | 28 | |
| 29 | - echo empty( $wrapper['before'] ) ? '<div class="' . esc_attr( $wrapper['class'] ) . '">' : $wrapper['before']; |
|
| 30 | - call_user_func( $function, $atts, $content ); |
|
| 31 | - echo empty( $wrapper['after'] ) ? '</div>' : $wrapper['after']; |
|
| 29 | + echo empty($wrapper['before']) ? '<div class="' . esc_attr($wrapper['class']) . '">' : $wrapper['before']; |
|
| 30 | + call_user_func($function, $atts, $content); |
|
| 31 | + echo empty($wrapper['after']) ? '</div>' : $wrapper['after']; |
|
| 32 | 32 | |
| 33 | 33 | return ob_get_clean(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public static function checkout( $atts = array(), $content = null ) { |
|
| 37 | - return self::shortcode_wrapper( array( __CLASS__, 'checkout_output' ), $atts, $content ); |
|
| 36 | + public static function checkout($atts = array(), $content = null) { |
|
| 37 | + return self::shortcode_wrapper(array(__CLASS__, 'checkout_output'), $atts, $content); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public static function checkout_output( $atts = array(), $content = null ) { |
|
| 41 | - do_action( 'wpinv_checkout_content_before' ); |
|
| 42 | - echo wpinv_checkout_form( $atts, $content ); |
|
| 43 | - do_action( 'wpinv_checkout_content_after' ); |
|
| 40 | + public static function checkout_output($atts = array(), $content = null) { |
|
| 41 | + do_action('wpinv_checkout_content_before'); |
|
| 42 | + echo wpinv_checkout_form($atts, $content); |
|
| 43 | + do_action('wpinv_checkout_content_after'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public static function messages( $atts, $content = null ) { |
|
| 46 | + public static function messages($atts, $content = null) { |
|
| 47 | 47 | ob_start(); |
| 48 | 48 | wpinv_print_errors(); |
| 49 | 49 | return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public static function history( $atts, $content = null ) { |
|
| 53 | - return self::shortcode_wrapper( array( __CLASS__, 'history_output' ), $atts ); |
|
| 52 | + public static function history($atts, $content = null) { |
|
| 53 | + return self::shortcode_wrapper(array(__CLASS__, 'history_output'), $atts); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @param array $atts |
| 60 | 60 | */ |
| 61 | - public static function history_output( $atts ) { |
|
| 62 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
| 63 | - wpinv_get_template_part( 'wpinv-invoice-history', $atts ); |
|
| 64 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
| 61 | + public static function history_output($atts) { |
|
| 62 | + do_action('wpinv_before_user_invoice_history'); |
|
| 63 | + wpinv_get_template_part('wpinv-invoice-history', $atts); |
|
| 64 | + do_action('wpinv_after_user_invoice_history'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - public static function success( $atts, $content = null ) { |
|
| 68 | - return self::shortcode_wrapper( array( __CLASS__, 'success_output' ), $atts, $content ); |
|
| 67 | + public static function success($atts, $content = null) { |
|
| 68 | + return self::shortcode_wrapper(array(__CLASS__, 'success_output'), $atts, $content); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -73,31 +73,31 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @param array $atts |
| 75 | 75 | */ |
| 76 | - public static function success_output( $atts, $content = null ) { |
|
| 77 | - do_action( 'wpinv_success_content_before' ); |
|
| 78 | - echo wpinv_payment_receipt( $atts, $content ); |
|
| 79 | - do_action( 'wpinv_success_content_after' ); |
|
| 76 | + public static function success_output($atts, $content = null) { |
|
| 77 | + do_action('wpinv_success_content_before'); |
|
| 78 | + echo wpinv_payment_receipt($atts, $content); |
|
| 79 | + do_action('wpinv_success_content_after'); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public static function buy( $atts, $content = null ) { |
|
| 83 | - $a = shortcode_atts( array( |
|
| 82 | + public static function buy($atts, $content = null) { |
|
| 83 | + $a = shortcode_atts(array( |
|
| 84 | 84 | 'items' => '', // should be used like: item_id|quantity,item_id|quantity,item_id|quantity |
| 85 | - 'title' => __( 'Buy Now', 'invoicing' ), // the button title |
|
| 85 | + 'title' => __('Buy Now', 'invoicing'), // the button title |
|
| 86 | 86 | 'post_id' => '', // any related post_id |
| 87 | - ), $atts ); |
|
| 87 | + ), $atts); |
|
| 88 | 88 | |
| 89 | - $post_id = isset( $a['post_id'] ) ? (int)$a['post_id'] : ''; |
|
| 89 | + $post_id = isset($a['post_id']) ? (int)$a['post_id'] : ''; |
|
| 90 | 90 | |
| 91 | 91 | $html = '<div class="wpi-buy-button-wrapper wpi-g">'; |
| 92 | 92 | $html .= '<button class="button button-primary wpi-buy-button" type="button" onclick="wpi_buy(this,\'' . $a['items'] . '\',' . $post_id . ');">' . $a['title'] . '</button>'; |
| 93 | - $html .= wp_nonce_field( 'wpinv_buy_items', 'wpinv_buy_nonce', true, false ); |
|
| 93 | + $html .= wp_nonce_field('wpinv_buy_items', 'wpinv_buy_nonce', true, false); |
|
| 94 | 94 | $html .= '</div>'; |
| 95 | 95 | |
| 96 | 96 | return $html; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - public static function subscriptions( $atts, $content = null ) { |
|
| 100 | - return self::shortcode_wrapper( array( __CLASS__, 'subscriptions_output' ), $atts ); |
|
| 99 | + public static function subscriptions($atts, $content = null) { |
|
| 100 | + return self::shortcode_wrapper(array(__CLASS__, 'subscriptions_output'), $atts); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @param array $atts |
| 107 | 107 | */ |
| 108 | - public static function subscriptions_output( $atts ) { |
|
| 109 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 110 | - wpinv_get_template_part( 'wpinv-subscriptions-history', $atts ); |
|
| 111 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 108 | + public static function subscriptions_output($atts) { |
|
| 109 | + do_action('wpinv_before_user_subscriptions'); |
|
| 110 | + wpinv_get_template_part('wpinv-subscriptions-history', $atts); |
|
| 111 | + do_action('wpinv_after_user_subscriptions'); |
|
| 112 | 112 | } |
| 113 | 113 | } |
@@ -7,90 +7,90 @@ 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 | function wpinv_get_discount_types() { |
| 15 | 15 | $discount_types = array( |
| 16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
| 17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
| 16 | + 'percent' => __('Percentage', 'invoicing'), |
|
| 17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
| 18 | 18 | ); |
| 19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
| 19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
| 22 | +function wpinv_get_discount_type_name($type = '') { |
|
| 23 | 23 | $types = wpinv_get_discount_types(); |
| 24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
| 24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -function wpinv_delete_discount( $data ) { |
|
| 28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 27 | +function wpinv_delete_discount($data) { |
|
| 28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 32 | + if (!current_user_can('manage_options')) { |
|
| 33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $discount_id = $data['discount']; |
| 37 | - wpinv_remove_discount( $discount_id ); |
|
| 37 | + wpinv_remove_discount($discount_id); |
|
| 38 | 38 | } |
| 39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
| 39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
| 40 | 40 | |
| 41 | -function wpinv_activate_discount( $data ) { |
|
| 42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 41 | +function wpinv_activate_discount($data) { |
|
| 42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 46 | + if (!current_user_can('manage_options')) { |
|
| 47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $id = absint( $data['discount'] ); |
|
| 51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
| 50 | + $id = absint($data['discount']); |
|
| 51 | + wpinv_update_discount_status($id, 'publish'); |
|
| 52 | 52 | } |
| 53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
| 53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
| 54 | 54 | |
| 55 | -function wpinv_deactivate_discount( $data ) { |
|
| 56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 55 | +function wpinv_deactivate_discount($data) { |
|
| 56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 60 | + if (!current_user_can('manage_options')) { |
|
| 61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $id = absint( $data['discount'] ); |
|
| 65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
| 64 | + $id = absint($data['discount']); |
|
| 65 | + wpinv_update_discount_status($id, 'pending'); |
|
| 66 | 66 | } |
| 67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
| 67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
| 68 | 68 | |
| 69 | -function wpinv_get_discounts( $args = array() ) { |
|
| 69 | +function wpinv_get_discounts($args = array()) { |
|
| 70 | 70 | $defaults = array( |
| 71 | 71 | 'post_type' => 'wpi_discount', |
| 72 | 72 | 'posts_per_page' => 20, |
| 73 | 73 | 'paged' => null, |
| 74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
| 74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | - $args = wp_parse_args( $args, $defaults ); |
|
| 77 | + $args = wp_parse_args($args, $defaults); |
|
| 78 | 78 | |
| 79 | - $discounts = get_posts( $args ); |
|
| 79 | + $discounts = get_posts($args); |
|
| 80 | 80 | |
| 81 | - if ( $discounts ) { |
|
| 81 | + if ($discounts) { |
|
| 82 | 82 | return $discounts; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
| 85 | + if (!$discounts && !empty($args['s'])) { |
|
| 86 | 86 | $args['meta_key'] = '_wpi_discount_code'; |
| 87 | 87 | $args['meta_value'] = $args['s']; |
| 88 | 88 | $args['meta_compare'] = 'LIKE'; |
| 89 | - unset( $args['s'] ); |
|
| 90 | - $discounts = get_posts( $args ); |
|
| 89 | + unset($args['s']); |
|
| 90 | + $discounts = get_posts($args); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if( $discounts ) { |
|
| 93 | + if ($discounts) { |
|
| 94 | 94 | return $discounts; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | $discounts = wpinv_get_discounts(); |
| 104 | 104 | |
| 105 | - if ( $discounts) { |
|
| 106 | - foreach ( $discounts as $discount ) { |
|
| 107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
| 105 | + if ($discounts) { |
|
| 106 | + foreach ($discounts as $discount) { |
|
| 107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
| 108 | 108 | $has_active = true; |
| 109 | 109 | break; |
| 110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
| 113 | 113 | return $has_active; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
| 117 | - if( empty( $discount_id ) ) { |
|
| 116 | +function wpinv_get_discount($discount_id = 0) { |
|
| 117 | + if (empty($discount_id)) { |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
| 121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $discount = get_post( $discount_id ); |
|
| 125 | + $discount = get_post($discount_id); |
|
| 126 | 126 | |
| 127 | 127 | return $discount; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
| 131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
| 130 | +function wpinv_get_discount_by_code($code = '') { |
|
| 131 | + if (empty($code) || !is_string($code)) { |
|
| 132 | 132 | return false; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - return wpinv_get_discount_by( 'code', $code ); |
|
| 135 | + return wpinv_get_discount_by('code', $code); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
| 139 | - if( empty( $field ) || empty( $value ) ) { |
|
| 138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
| 139 | + if (empty($field) || empty($value)) { |
|
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if( ! is_string( $field ) ) { |
|
| 143 | + if (!is_string($field)) { |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - switch( strtolower( $field ) ) { |
|
| 147 | + switch (strtolower($field)) { |
|
| 148 | 148 | |
| 149 | 149 | case 'code': |
| 150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
| 154 | 154 | 'compare' => '=' |
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | - $discount = wpinv_get_discounts( array( |
|
| 157 | + $discount = wpinv_get_discounts(array( |
|
| 158 | 158 | 'posts_per_page' => 1, |
| 159 | 159 | 'post_status' => 'any', |
| 160 | 160 | 'meta_query' => $meta_query, |
| 161 | - ) ); |
|
| 161 | + )); |
|
| 162 | 162 | |
| 163 | - if( $discount ) { |
|
| 163 | + if ($discount) { |
|
| 164 | 164 | $discount = $discount[0]; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | break; |
| 168 | 168 | |
| 169 | 169 | case 'id': |
| 170 | - $discount = wpinv_get_discount( $value ); |
|
| 170 | + $discount = wpinv_get_discount($value); |
|
| 171 | 171 | |
| 172 | 172 | break; |
| 173 | 173 | |
| 174 | 174 | case 'name': |
| 175 | - $discount = get_posts( array( |
|
| 175 | + $discount = get_posts(array( |
|
| 176 | 176 | 'post_type' => 'wpi_discount', |
| 177 | 177 | 'name' => $value, |
| 178 | 178 | 'posts_per_page' => 1, |
| 179 | 179 | 'post_status' => 'any' |
| 180 | - ) ); |
|
| 180 | + )); |
|
| 181 | 181 | |
| 182 | - if( $discount ) { |
|
| 182 | + if ($discount) { |
|
| 183 | 183 | $discount = $discount[0]; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -189,96 +189,96 @@ discard block |
||
| 189 | 189 | return false; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if( ! empty( $discount ) ) { |
|
| 192 | + if (!empty($discount)) { |
|
| 193 | 193 | return $discount; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
| 199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
| 200 | 200 | $meta = array( |
| 201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
| 202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
| 203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
| 204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
| 205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
| 206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
| 207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
| 208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
| 209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
| 210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
| 211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
| 212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
| 213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
| 201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
| 202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
| 203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
| 204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
| 205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
| 206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
| 207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
| 208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
| 209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
| 210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
| 211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
| 212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
| 213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
| 214 | 214 | ); |
| 215 | 215 | |
| 216 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
| 216 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
| 217 | 217 | $meta['amount'] = 100; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( !empty( $meta['start'] ) ) { |
|
| 221 | - $meta['start'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) ); |
|
| 220 | + if (!empty($meta['start'])) { |
|
| 221 | + $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start'])); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if ( !empty( $meta['expiration'] ) ) { |
|
| 225 | - $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) ); |
|
| 224 | + if (!empty($meta['expiration'])) { |
|
| 225 | + $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration'])); |
|
| 226 | 226 | |
| 227 | - if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) { |
|
| 227 | + if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) { |
|
| 228 | 228 | $meta['expiration'] = $meta['start']; |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( $meta['uses'] === false ) { |
|
| 233 | - unset( $meta['uses'] ); |
|
| 232 | + if ($meta['uses'] === false) { |
|
| 233 | + unset($meta['uses']); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if ( ! empty( $meta['items'] ) ) { |
|
| 237 | - foreach ( $meta['items'] as $key => $item ) { |
|
| 238 | - if ( 0 === intval( $item ) ) { |
|
| 239 | - unset( $meta['items'][ $key ] ); |
|
| 236 | + if (!empty($meta['items'])) { |
|
| 237 | + foreach ($meta['items'] as $key => $item) { |
|
| 238 | + if (0 === intval($item)) { |
|
| 239 | + unset($meta['items'][$key]); |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
| 245 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
| 246 | - if ( 0 === intval( $item ) ) { |
|
| 247 | - unset( $meta['excluded_items'][ $key ] ); |
|
| 244 | + if (!empty($meta['excluded_items'])) { |
|
| 245 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
| 246 | + if (0 === intval($item)) { |
|
| 247 | + unset($meta['excluded_items'][$key]); |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
| 252 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
| 253 | 253 | |
| 254 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
| 254 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
| 255 | 255 | |
| 256 | - foreach( $meta as $key => $value ) { |
|
| 257 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
| 256 | + foreach ($meta as $key => $value) { |
|
| 257 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
| 260 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
| 261 | 261 | |
| 262 | 262 | return $post_id; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
| 266 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
| 265 | +function wpinv_remove_discount($discount_id = 0) { |
|
| 266 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
| 267 | 267 | |
| 268 | - wp_delete_post( $discount_id, true ); |
|
| 268 | + wp_delete_post($discount_id, true); |
|
| 269 | 269 | |
| 270 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
| 270 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
| 274 | - $discount = wpinv_get_discount( $code_id ); |
|
| 273 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
| 274 | + $discount = wpinv_get_discount($code_id); |
|
| 275 | 275 | |
| 276 | - if ( $discount ) { |
|
| 277 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
| 276 | + if ($discount) { |
|
| 277 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
| 278 | 278 | |
| 279 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
| 279 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
| 280 | 280 | |
| 281 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
| 281 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
| 282 | 282 | |
| 283 | 283 | return true; |
| 284 | 284 | } |
@@ -286,173 +286,173 @@ discard block |
||
| 286 | 286 | return false; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | -function wpinv_discount_exists( $code_id ) { |
|
| 290 | - if ( wpinv_get_discount( $code_id ) ) { |
|
| 289 | +function wpinv_discount_exists($code_id) { |
|
| 290 | + if (wpinv_get_discount($code_id)) { |
|
| 291 | 291 | return true; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | return false; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | -function wpinv_is_discount_active( $code_id = null ) { |
|
| 298 | - $discount = wpinv_get_discount( $code_id ); |
|
| 297 | +function wpinv_is_discount_active($code_id = null) { |
|
| 298 | + $discount = wpinv_get_discount($code_id); |
|
| 299 | 299 | $return = false; |
| 300 | 300 | |
| 301 | - if ( $discount ) { |
|
| 302 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
| 303 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 304 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
| 301 | + if ($discount) { |
|
| 302 | + if (wpinv_is_discount_expired($code_id)) { |
|
| 303 | + if (defined('DOING_AJAX')) { |
|
| 304 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
| 305 | 305 | } |
| 306 | - } elseif ( $discount->post_status == 'publish' ) { |
|
| 306 | + } elseif ($discount->post_status == 'publish') { |
|
| 307 | 307 | $return = true; |
| 308 | 308 | } else { |
| 309 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 310 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
| 309 | + if (defined('DOING_AJAX')) { |
|
| 310 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
| 315 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | -function wpinv_get_discount_code( $code_id = null ) { |
|
| 319 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
| 318 | +function wpinv_get_discount_code($code_id = null) { |
|
| 319 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
| 320 | 320 | |
| 321 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
| 321 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
| 325 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
| 324 | +function wpinv_get_discount_start_date($code_id = null) { |
|
| 325 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
| 326 | 326 | |
| 327 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
| 327 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
| 331 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
| 330 | +function wpinv_get_discount_expiration($code_id = null) { |
|
| 331 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
| 332 | 332 | |
| 333 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
| 333 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
| 337 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
| 336 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
| 337 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
| 338 | 338 | |
| 339 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
| 339 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
| 343 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
| 342 | +function wpinv_get_discount_uses($code_id = null) { |
|
| 343 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
| 344 | 344 | |
| 345 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
| 345 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
| 349 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
| 348 | +function wpinv_get_discount_min_total($code_id = null) { |
|
| 349 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
| 350 | 350 | |
| 351 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
| 351 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
| 355 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
| 354 | +function wpinv_get_discount_max_total($code_id = null) { |
|
| 355 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
| 356 | 356 | |
| 357 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
| 357 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
| 361 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
| 360 | +function wpinv_get_discount_amount($code_id = null) { |
|
| 361 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
| 362 | 362 | |
| 363 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
| 363 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
| 367 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
| 366 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
| 367 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
| 368 | 368 | |
| 369 | - if ( $name ) { |
|
| 370 | - $name = wpinv_get_discount_type_name( $type ); |
|
| 369 | + if ($name) { |
|
| 370 | + $name = wpinv_get_discount_type_name($type); |
|
| 371 | 371 | |
| 372 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
| 372 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
| 375 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | -function wpinv_discount_status( $status ) { |
|
| 379 | - switch( $status ){ |
|
| 378 | +function wpinv_discount_status($status) { |
|
| 379 | + switch ($status) { |
|
| 380 | 380 | case 'expired' : |
| 381 | - $name = __( 'Expired', 'invoicing' ); |
|
| 381 | + $name = __('Expired', 'invoicing'); |
|
| 382 | 382 | break; |
| 383 | 383 | case 'publish' : |
| 384 | 384 | case 'active' : |
| 385 | - $name = __( 'Active', 'invoicing' ); |
|
| 385 | + $name = __('Active', 'invoicing'); |
|
| 386 | 386 | break; |
| 387 | 387 | default : |
| 388 | - $name = __( 'Inactive', 'invoicing' ); |
|
| 388 | + $name = __('Inactive', 'invoicing'); |
|
| 389 | 389 | break; |
| 390 | 390 | } |
| 391 | 391 | return $name; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
| 395 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
| 394 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
| 395 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
| 396 | 396 | |
| 397 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
| 397 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
| 398 | 398 | $excluded_items = array(); |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
| 401 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
| 405 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
| 404 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
| 405 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
| 406 | 406 | |
| 407 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
| 407 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
| 408 | 408 | $item_reqs = array(); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
| 411 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
| 415 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
| 414 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
| 415 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
| 419 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
| 418 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
| 419 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
| 423 | - $discount = wpinv_get_discount( $code_id ); |
|
| 422 | +function wpinv_is_discount_expired($code_id = null) { |
|
| 423 | + $discount = wpinv_get_discount($code_id); |
|
| 424 | 424 | $return = false; |
| 425 | 425 | |
| 426 | - if ( $discount ) { |
|
| 427 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
| 428 | - if ( $expiration ) { |
|
| 429 | - $expiration = strtotime( $expiration ); |
|
| 430 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
| 426 | + if ($discount) { |
|
| 427 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
| 428 | + if ($expiration) { |
|
| 429 | + $expiration = strtotime($expiration); |
|
| 430 | + if ($expiration < current_time('timestamp')) { |
|
| 431 | 431 | // Discount is expired |
| 432 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
| 432 | + wpinv_update_discount_status($code_id, 'pending'); |
|
| 433 | 433 | $return = true; |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
| 438 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | -function wpinv_is_discount_started( $code_id = null ) { |
|
| 442 | - $discount = wpinv_get_discount( $code_id ); |
|
| 441 | +function wpinv_is_discount_started($code_id = null) { |
|
| 442 | + $discount = wpinv_get_discount($code_id); |
|
| 443 | 443 | $return = false; |
| 444 | 444 | |
| 445 | - if ( $discount ) { |
|
| 446 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
| 445 | + if ($discount) { |
|
| 446 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
| 447 | 447 | |
| 448 | - if ( $start_date ) { |
|
| 449 | - $start_date = strtotime( $start_date ); |
|
| 448 | + if ($start_date) { |
|
| 449 | + $start_date = strtotime($start_date); |
|
| 450 | 450 | |
| 451 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
| 451 | + if ($start_date < current_time('timestamp')) { |
|
| 452 | 452 | // Discount has past the start date |
| 453 | 453 | $return = true; |
| 454 | 454 | } else { |
| 455 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 455 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 456 | 456 | } |
| 457 | 457 | } else { |
| 458 | 458 | // No start date for this discount, so has to be true |
@@ -460,159 +460,159 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
| 463 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
| 467 | - $discount = wpinv_get_discount( $code_id ); |
|
| 466 | +function wpinv_check_discount_dates($code_id = null) { |
|
| 467 | + $discount = wpinv_get_discount($code_id); |
|
| 468 | 468 | $return = false; |
| 469 | 469 | |
| 470 | - if ( $discount ) { |
|
| 471 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
| 470 | + if ($discount) { |
|
| 471 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
| 472 | 472 | |
| 473 | - if ( $start_date ) { |
|
| 474 | - $start_date = strtotime( $start_date ); |
|
| 473 | + if ($start_date) { |
|
| 474 | + $start_date = strtotime($start_date); |
|
| 475 | 475 | |
| 476 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
| 476 | + if ($start_date < current_time('timestamp')) { |
|
| 477 | 477 | // Discount has past the start date |
| 478 | 478 | $return = true; |
| 479 | 479 | } else { |
| 480 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 480 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 481 | 481 | } |
| 482 | 482 | } else { |
| 483 | 483 | // No start date for this discount, so has to be true |
| 484 | 484 | $return = true; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - if ( $return ) { |
|
| 488 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
| 487 | + if ($return) { |
|
| 488 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
| 489 | 489 | |
| 490 | - if ( $expiration ) { |
|
| 491 | - $expiration = strtotime( $expiration ); |
|
| 492 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
| 490 | + if ($expiration) { |
|
| 491 | + $expiration = strtotime($expiration); |
|
| 492 | + if ($expiration < current_time('timestamp')) { |
|
| 493 | 493 | // Discount is expired |
| 494 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
| 494 | + wpinv_update_discount_status($code_id, 'pending'); |
|
| 495 | 495 | $return = true; |
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
| 501 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
| 505 | - $discount = wpinv_get_discount( $code_id ); |
|
| 504 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
| 505 | + $discount = wpinv_get_discount($code_id); |
|
| 506 | 506 | $return = false; |
| 507 | 507 | |
| 508 | - if ( $discount ) { |
|
| 509 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
| 508 | + if ($discount) { |
|
| 509 | + $uses = wpinv_get_discount_uses($code_id); |
|
| 510 | 510 | // Large number that will never be reached |
| 511 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
| 511 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
| 512 | 512 | // Should never be greater than, but just in case |
| 513 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
| 513 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
| 514 | 514 | // Discount is maxed out |
| 515 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
| 515 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
| 516 | 516 | $return = true; |
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
| 520 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
| 524 | - $discount = wpinv_get_discount( $code_id ); |
|
| 523 | +function wpinv_discount_is_min_met($code_id = null) { |
|
| 524 | + $discount = wpinv_get_discount($code_id); |
|
| 525 | 525 | $return = false; |
| 526 | 526 | |
| 527 | - if ( $discount ) { |
|
| 528 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
| 529 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
| 527 | + if ($discount) { |
|
| 528 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
| 529 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
| 530 | 530 | |
| 531 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
| 531 | + if (!$min > 0 || $cart_amount >= $min) { |
|
| 532 | 532 | // Minimum has been met |
| 533 | 533 | $return = true; |
| 534 | 534 | } else { |
| 535 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
| 535 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
| 536 | 536 | } |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
| 539 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
| 543 | - $discount = wpinv_get_discount( $code_id ); |
|
| 542 | +function wpinv_discount_is_max_met($code_id = null) { |
|
| 543 | + $discount = wpinv_get_discount($code_id); |
|
| 544 | 544 | $return = false; |
| 545 | 545 | |
| 546 | - if ( $discount ) { |
|
| 547 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
| 548 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
| 546 | + if ($discount) { |
|
| 547 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
| 548 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
| 549 | 549 | |
| 550 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
| 550 | + if (!$max > 0 || $cart_amount <= $max) { |
|
| 551 | 551 | // Minimum has been met |
| 552 | 552 | $return = true; |
| 553 | 553 | } else { |
| 554 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
| 554 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
| 558 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
| 562 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
| 563 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
| 561 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
| 562 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
| 563 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
| 567 | - if ( $code ) { |
|
| 568 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
| 566 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
| 567 | + if ($code) { |
|
| 568 | + $discount = wpinv_get_discount_by_code($code_id); |
|
| 569 | 569 | |
| 570 | - if ( !empty( $discount ) ) { |
|
| 570 | + if (!empty($discount)) { |
|
| 571 | 571 | $code_id = $discount->ID; |
| 572 | 572 | } |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
| 575 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
| 576 | 576 | |
| 577 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
| 577 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
| 581 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 582 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
| 583 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
| 580 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
| 581 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 582 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
| 583 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
| 584 | 584 | $cart_items = wpinv_get_cart_contents(); |
| 585 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
| 585 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
| 586 | 586 | $ret = false; |
| 587 | 587 | |
| 588 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
| 588 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
| 589 | 589 | $ret = true; |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | // Normalize our data for item requirements, exclusions and cart data |
| 593 | 593 | // First absint the items, then sort, and reset the array keys |
| 594 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
| 595 | - asort( $item_reqs ); |
|
| 596 | - $item_reqs = array_values( $item_reqs ); |
|
| 594 | + $item_reqs = array_map('absint', $item_reqs); |
|
| 595 | + asort($item_reqs); |
|
| 596 | + $item_reqs = array_values($item_reqs); |
|
| 597 | 597 | |
| 598 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
| 599 | - asort( $excluded_ps ); |
|
| 600 | - $excluded_ps = array_values( $excluded_ps ); |
|
| 598 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
| 599 | + asort($excluded_ps); |
|
| 600 | + $excluded_ps = array_values($excluded_ps); |
|
| 601 | 601 | |
| 602 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
| 603 | - asort( $cart_ids ); |
|
| 604 | - $cart_ids = array_values( $cart_ids ); |
|
| 602 | + $cart_ids = array_map('absint', $cart_ids); |
|
| 603 | + asort($cart_ids); |
|
| 604 | + $cart_ids = array_values($cart_ids); |
|
| 605 | 605 | |
| 606 | 606 | // Ensure we have requirements before proceeding |
| 607 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
| 608 | - switch( $condition ) { |
|
| 607 | + if (!$ret && !empty($item_reqs)) { |
|
| 608 | + switch ($condition) { |
|
| 609 | 609 | case 'all' : |
| 610 | 610 | // Default back to true |
| 611 | 611 | $ret = true; |
| 612 | 612 | |
| 613 | - foreach ( $item_reqs as $item_id ) { |
|
| 614 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
| 615 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 613 | + foreach ($item_reqs as $item_id) { |
|
| 614 | + if (!wpinv_item_in_cart($item_id)) { |
|
| 615 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 616 | 616 | $ret = false; |
| 617 | 617 | break; |
| 618 | 618 | } |
@@ -621,15 +621,15 @@ discard block |
||
| 621 | 621 | break; |
| 622 | 622 | |
| 623 | 623 | default : // Any |
| 624 | - foreach ( $item_reqs as $item_id ) { |
|
| 625 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
| 624 | + foreach ($item_reqs as $item_id) { |
|
| 625 | + if (wpinv_item_in_cart($item_id)) { |
|
| 626 | 626 | $ret = true; |
| 627 | 627 | break; |
| 628 | 628 | } |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - if( ! $ret ) { |
|
| 632 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 631 | + if (!$ret) { |
|
| 632 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | break; |
@@ -638,70 +638,70 @@ discard block |
||
| 638 | 638 | $ret = true; |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - if( ! empty( $excluded_ps ) ) { |
|
| 641 | + if (!empty($excluded_ps)) { |
|
| 642 | 642 | // Check that there are items other than excluded ones in the cart |
| 643 | - if( $cart_ids == $excluded_ps ) { |
|
| 644 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
| 643 | + if ($cart_ids == $excluded_ps) { |
|
| 644 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
| 645 | 645 | $ret = false; |
| 646 | 646 | } |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
| 649 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
| 652 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
| 653 | 653 | global $wpi_checkout_id; |
| 654 | 654 | |
| 655 | 655 | $return = false; |
| 656 | 656 | |
| 657 | - if ( empty( $code_id ) ) { |
|
| 658 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
| 657 | + if (empty($code_id)) { |
|
| 658 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
| 659 | 659 | |
| 660 | - if( empty( $code_id ) ) { |
|
| 660 | + if (empty($code_id)) { |
|
| 661 | 661 | return false; // No discount was found |
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
| 665 | + if (wpinv_discount_is_single_use($code_id)) { |
|
| 666 | 666 | $payments = array(); |
| 667 | 667 | |
| 668 | 668 | $user_id = 0; |
| 669 | - if ( is_int( $user ) ) { |
|
| 670 | - $user_id = absint( $user ); |
|
| 671 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
| 669 | + if (is_int($user)) { |
|
| 670 | + $user_id = absint($user); |
|
| 671 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
| 672 | 672 | $user_id = $user_data->ID; |
| 673 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
| 673 | + } else if ($user_data = get_user_by('login', $user)) { |
|
| 674 | 674 | $user_id = $user_data->ID; |
| 675 | - } else if ( absint( $user ) > 0 ) { |
|
| 676 | - $user_id = absint( $user ); |
|
| 675 | + } else if (absint($user) > 0) { |
|
| 676 | + $user_id = absint($user); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - if ( !empty( $user_id ) ) { |
|
| 680 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
| 681 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id |
|
| 679 | + if (!empty($user_id)) { |
|
| 680 | + $query = array('user' => $user_id, 'limit' => false); |
|
| 681 | + $payments = wpinv_get_invoices($query); // Get all payments with matching user id |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | - if ( $payments ) { |
|
| 685 | - foreach ( $payments as $payment ) { |
|
| 684 | + if ($payments) { |
|
| 685 | + foreach ($payments as $payment) { |
|
| 686 | 686 | // Don't count discount used for current invoice chekcout. |
| 687 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
| 687 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
| 688 | 688 | continue; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
| 691 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
| 692 | 692 | continue; |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | - $discounts = $payment->get_discounts( true ); |
|
| 696 | - if ( empty( $discounts ) ) { |
|
| 695 | + $discounts = $payment->get_discounts(true); |
|
| 696 | + if (empty($discounts)) { |
|
| 697 | 697 | continue; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
| 700 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
| 701 | 701 | |
| 702 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
| 703 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
| 704 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
| 702 | + if (!empty($discounts) && is_array($discounts)) { |
|
| 703 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
| 704 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
| 705 | 705 | $return = true; |
| 706 | 706 | break; |
| 707 | 707 | } |
@@ -710,61 +710,61 @@ discard block |
||
| 710 | 710 | } |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
| 713 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
| 716 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
| 717 | 717 | $return = false; |
| 718 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 719 | - $user = trim( $user ); |
|
| 718 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 719 | + $user = trim($user); |
|
| 720 | 720 | |
| 721 | - if ( wpinv_get_cart_contents() ) { |
|
| 722 | - if ( $discount_id ) { |
|
| 721 | + if (wpinv_get_cart_contents()) { |
|
| 722 | + if ($discount_id) { |
|
| 723 | 723 | if ( |
| 724 | - wpinv_is_discount_active( $discount_id ) && |
|
| 725 | - wpinv_check_discount_dates( $discount_id ) && |
|
| 726 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
| 727 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
| 728 | - wpinv_discount_is_min_met( $discount_id ) && |
|
| 729 | - wpinv_discount_is_max_met( $discount_id ) && |
|
| 730 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
| 724 | + wpinv_is_discount_active($discount_id) && |
|
| 725 | + wpinv_check_discount_dates($discount_id) && |
|
| 726 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
| 727 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
| 728 | + wpinv_discount_is_min_met($discount_id) && |
|
| 729 | + wpinv_discount_is_max_met($discount_id) && |
|
| 730 | + wpinv_discount_item_reqs_met($discount_id) |
|
| 731 | 731 | ) { |
| 732 | 732 | $return = true; |
| 733 | 733 | } |
| 734 | - } elseif( $set_error ) { |
|
| 735 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
| 734 | + } elseif ($set_error) { |
|
| 735 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
| 739 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | -function wpinv_get_discount_id_by_code( $code ) { |
|
| 743 | - $discount = wpinv_get_discount_by_code( $code ); |
|
| 744 | - if( $discount ) { |
|
| 742 | +function wpinv_get_discount_id_by_code($code) { |
|
| 743 | + $discount = wpinv_get_discount_by_code($code); |
|
| 744 | + if ($discount) { |
|
| 745 | 745 | return $discount->ID; |
| 746 | 746 | } |
| 747 | 747 | return false; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
| 750 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
| 751 | 751 | $amount = $base_price; |
| 752 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 752 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 753 | 753 | |
| 754 | - if( $discount_id ) { |
|
| 755 | - $type = wpinv_get_discount_type( $discount_id ); |
|
| 756 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
| 754 | + if ($discount_id) { |
|
| 755 | + $type = wpinv_get_discount_type($discount_id); |
|
| 756 | + $rate = wpinv_get_discount_amount($discount_id); |
|
| 757 | 757 | |
| 758 | - if ( $type == 'flat' ) { |
|
| 758 | + if ($type == 'flat') { |
|
| 759 | 759 | // Set amount |
| 760 | 760 | $amount = $base_price - $rate; |
| 761 | - if ( $amount < 0 ) { |
|
| 761 | + if ($amount < 0) { |
|
| 762 | 762 | $amount = 0; |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | } else { |
| 766 | 766 | // Percentage discount |
| 767 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
| 767 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | } else { |
@@ -773,108 +773,108 @@ discard block |
||
| 773 | 773 | |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
| 776 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | -function wpinv_increase_discount_usage( $code ) { |
|
| 779 | +function wpinv_increase_discount_usage($code) { |
|
| 780 | 780 | |
| 781 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
| 782 | - $uses = wpinv_get_discount_uses( $id ); |
|
| 781 | + $id = wpinv_get_discount_id_by_code($code); |
|
| 782 | + $uses = wpinv_get_discount_uses($id); |
|
| 783 | 783 | |
| 784 | - if ( $uses ) { |
|
| 784 | + if ($uses) { |
|
| 785 | 785 | $uses++; |
| 786 | 786 | } else { |
| 787 | 787 | $uses = 1; |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
| 790 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
| 791 | 791 | |
| 792 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
| 792 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
| 793 | 793 | |
| 794 | 794 | return $uses; |
| 795 | 795 | |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | -function wpinv_decrease_discount_usage( $code ) { |
|
| 798 | +function wpinv_decrease_discount_usage($code) { |
|
| 799 | 799 | |
| 800 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
| 801 | - $uses = wpinv_get_discount_uses( $id ); |
|
| 800 | + $id = wpinv_get_discount_id_by_code($code); |
|
| 801 | + $uses = wpinv_get_discount_uses($id); |
|
| 802 | 802 | |
| 803 | - if ( $uses ) { |
|
| 803 | + if ($uses) { |
|
| 804 | 804 | $uses--; |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | - if ( $uses < 0 ) { |
|
| 807 | + if ($uses < 0) { |
|
| 808 | 808 | $uses = 0; |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
| 811 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
| 812 | 812 | |
| 813 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
| 813 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
| 814 | 814 | |
| 815 | 815 | return $uses; |
| 816 | 816 | |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
| 820 | - if ( $type == 'flat' ) { |
|
| 821 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
| 819 | +function wpinv_format_discount_rate($type, $amount) { |
|
| 820 | + if ($type == 'flat') { |
|
| 821 | + return wpinv_price(wpinv_format_amount($amount)); |
|
| 822 | 822 | } else { |
| 823 | 823 | return $amount . '%'; |
| 824 | 824 | } |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | -function wpinv_set_cart_discount( $code = '' ) { |
|
| 828 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
| 827 | +function wpinv_set_cart_discount($code = '') { |
|
| 828 | + if (wpinv_multiple_discounts_allowed()) { |
|
| 829 | 829 | // Get all active cart discounts |
| 830 | 830 | $discounts = wpinv_get_cart_discounts(); |
| 831 | 831 | } else { |
| 832 | 832 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
| 833 | 833 | } |
| 834 | 834 | |
| 835 | - if ( $discounts ) { |
|
| 836 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
| 837 | - if( false !== $key ) { |
|
| 838 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
| 835 | + if ($discounts) { |
|
| 836 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
| 837 | + if (false !== $key) { |
|
| 838 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
| 839 | 839 | } |
| 840 | 840 | $discounts[] = $code; |
| 841 | 841 | } else { |
| 842 | 842 | $discounts = array(); |
| 843 | 843 | $discounts[] = $code; |
| 844 | 844 | } |
| 845 | - $discounts = array_values( $discounts ); |
|
| 845 | + $discounts = array_values($discounts); |
|
| 846 | 846 | |
| 847 | 847 | $data = wpinv_get_checkout_session(); |
| 848 | - if ( empty( $data ) ) { |
|
| 848 | + if (empty($data)) { |
|
| 849 | 849 | $data = array(); |
| 850 | 850 | } else { |
| 851 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 852 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
| 853 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 851 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 852 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
| 853 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | 856 | $data['cart_discounts'] = $discounts; |
| 857 | 857 | |
| 858 | - wpinv_set_checkout_session( $data ); |
|
| 858 | + wpinv_set_checkout_session($data); |
|
| 859 | 859 | |
| 860 | 860 | return $discounts; |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
| 863 | +function wpinv_unset_cart_discount($code = '') { |
|
| 864 | 864 | $discounts = wpinv_get_cart_discounts(); |
| 865 | 865 | |
| 866 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
| 867 | - $key = array_search( $code, $discounts ); |
|
| 868 | - unset( $discounts[ $key ] ); |
|
| 866 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
| 867 | + $key = array_search($code, $discounts); |
|
| 868 | + unset($discounts[$key]); |
|
| 869 | 869 | |
| 870 | 870 | $data = wpinv_get_checkout_session(); |
| 871 | 871 | $data['cart_discounts'] = $discounts; |
| 872 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 873 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
| 874 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 872 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 873 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
| 874 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - wpinv_set_checkout_session( $data ); |
|
| 877 | + wpinv_set_checkout_session($data); |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | return $discounts; |
@@ -883,27 +883,27 @@ discard block |
||
| 883 | 883 | function wpinv_unset_all_cart_discounts() { |
| 884 | 884 | $data = wpinv_get_checkout_session(); |
| 885 | 885 | |
| 886 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
| 887 | - unset( $data['cart_discounts'] ); |
|
| 886 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
| 887 | + unset($data['cart_discounts']); |
|
| 888 | 888 | |
| 889 | - wpinv_set_checkout_session( $data ); |
|
| 889 | + wpinv_set_checkout_session($data); |
|
| 890 | 890 | return true; |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | return false; |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
| 896 | +function wpinv_get_cart_discounts($items = array()) { |
|
| 897 | 897 | $session = wpinv_get_checkout_session(); |
| 898 | 898 | |
| 899 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
| 899 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
| 900 | 900 | return $discounts; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
| 903 | +function wpinv_cart_has_discounts($items = array()) { |
|
| 904 | 904 | $ret = false; |
| 905 | 905 | |
| 906 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
| 906 | + if (wpinv_get_cart_discounts($items)) { |
|
| 907 | 907 | $ret = true; |
| 908 | 908 | } |
| 909 | 909 | |
@@ -914,131 +914,131 @@ discard block |
||
| 914 | 914 | } |
| 915 | 915 | */ |
| 916 | 916 | |
| 917 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
| 917 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
| 920 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
| 921 | 921 | $amount = 0.00; |
| 922 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 922 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 923 | 923 | |
| 924 | - if ( $items ) { |
|
| 925 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
| 924 | + if ($items) { |
|
| 925 | + $discounts = wp_list_pluck($items, 'discount'); |
|
| 926 | 926 | |
| 927 | - if ( is_array( $discounts ) ) { |
|
| 928 | - $discounts = array_map( 'floatval', $discounts ); |
|
| 929 | - $amount = array_sum( $discounts ); |
|
| 927 | + if (is_array($discounts)) { |
|
| 928 | + $discounts = array_map('floatval', $discounts); |
|
| 929 | + $amount = array_sum($discounts); |
|
| 930 | 930 | } |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
| 933 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
| 937 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 936 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
| 937 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 938 | 938 | |
| 939 | - if ( empty( $discount ) || empty( $items ) ) { |
|
| 939 | + if (empty($discount) || empty($items)) { |
|
| 940 | 940 | return 0; |
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | $amount = 0; |
| 944 | 944 | |
| 945 | - foreach ( $items as $item ) { |
|
| 946 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
| 945 | + foreach ($items as $item) { |
|
| 946 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
| 947 | 947 | } |
| 948 | 948 | |
| 949 | - $amount = wpinv_round_amount( $amount ); |
|
| 949 | + $amount = wpinv_round_amount($amount); |
|
| 950 | 950 | |
| 951 | 951 | return $amount; |
| 952 | 952 | } |
| 953 | 953 | |
| 954 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
| 954 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
| 955 | 955 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 956 | 956 | |
| 957 | 957 | $amount = 0; |
| 958 | 958 | |
| 959 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
| 959 | + if (empty($item) || empty($item['id'])) { |
|
| 960 | 960 | return $amount; |
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - if ( empty( $item['quantity'] ) ) { |
|
| 963 | + if (empty($item['quantity'])) { |
|
| 964 | 964 | return $amount; |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | - if ( empty( $item['options'] ) ) { |
|
| 967 | + if (empty($item['options'])) { |
|
| 968 | 968 | $item['options'] = array(); |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
| 971 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
| 972 | 972 | $discounted_price = $price; |
| 973 | 973 | |
| 974 | 974 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
| 975 | - if ( empty( $discounts ) ) { |
|
| 975 | + if (empty($discounts)) { |
|
| 976 | 976 | return $amount; |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | - if ( $discounts ) { |
|
| 980 | - if ( is_array( $discounts ) ) { |
|
| 981 | - $discounts = array_values( $discounts ); |
|
| 979 | + if ($discounts) { |
|
| 980 | + if (is_array($discounts)) { |
|
| 981 | + $discounts = array_values($discounts); |
|
| 982 | 982 | } else { |
| 983 | - $discounts = explode( ',', $discounts ); |
|
| 983 | + $discounts = explode(',', $discounts); |
|
| 984 | 984 | } |
| 985 | 985 | } |
| 986 | 986 | |
| 987 | - if( $discounts ) { |
|
| 988 | - foreach ( $discounts as $discount ) { |
|
| 989 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 987 | + if ($discounts) { |
|
| 988 | + foreach ($discounts as $discount) { |
|
| 989 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
| 990 | 990 | |
| 991 | 991 | // Check discount exists |
| 992 | - if( ! $code_id ) { |
|
| 992 | + if (!$code_id) { |
|
| 993 | 993 | continue; |
| 994 | 994 | } |
| 995 | 995 | |
| 996 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 997 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 996 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 997 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 998 | 998 | |
| 999 | 999 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
| 1000 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
| 1001 | - foreach ( $reqs as $item_id ) { |
|
| 1002 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
| 1003 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
| 1000 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
| 1001 | + foreach ($reqs as $item_id) { |
|
| 1002 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
| 1003 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
| 1004 | 1004 | } |
| 1005 | 1005 | } |
| 1006 | 1006 | } else { |
| 1007 | 1007 | // This is a global cart discount |
| 1008 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
| 1009 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
| 1008 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 1009 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
| 1010 | 1010 | $items_subtotal = 0.00; |
| 1011 | 1011 | $cart_items = wpinv_get_cart_contents(); |
| 1012 | 1012 | |
| 1013 | - foreach ( $cart_items as $cart_item ) { |
|
| 1014 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
| 1015 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
| 1016 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
| 1013 | + foreach ($cart_items as $cart_item) { |
|
| 1014 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
| 1015 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
| 1016 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
| 1017 | 1017 | $items_subtotal += $item_price * $cart_item['quantity']; |
| 1018 | 1018 | } |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
| 1022 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
| 1021 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
| 1022 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
| 1023 | 1023 | $discounted_amount = $code_amount * $subtotal_percent; |
| 1024 | 1024 | $discounted_price -= $discounted_amount; |
| 1025 | 1025 | |
| 1026 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
| 1026 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
| 1027 | 1027 | |
| 1028 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
| 1028 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
| 1029 | 1029 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
| 1030 | 1030 | $discounted_price -= $adjustment; |
| 1031 | 1031 | } |
| 1032 | 1032 | } else { |
| 1033 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
| 1033 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | } |
| 1036 | 1036 | } |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
| 1039 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
| 1040 | 1040 | |
| 1041 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
| 1041 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
| 1042 | 1042 | $amount = $amount * $item['quantity']; |
| 1043 | 1043 | } |
| 1044 | 1044 | } |
@@ -1046,59 +1046,59 @@ discard block |
||
| 1046 | 1046 | return $amount; |
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
| 1050 | - echo wpinv_get_cart_discounts_html( $items ); |
|
| 1049 | +function wpinv_cart_discounts_html($items = array()) { |
|
| 1050 | + echo wpinv_get_cart_discounts_html($items); |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
| 1053 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
| 1054 | 1054 | global $wpi_cart_columns; |
| 1055 | 1055 | |
| 1056 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 1056 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 1057 | 1057 | |
| 1058 | - if ( !$discounts ) { |
|
| 1059 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
| 1058 | + if (!$discounts) { |
|
| 1059 | + $discounts = wpinv_get_cart_discounts($items); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | - if ( !$discounts ) { |
|
| 1062 | + if (!$discounts) { |
|
| 1063 | 1063 | return; |
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
| 1066 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
| 1067 | 1067 | |
| 1068 | 1068 | $html = ''; |
| 1069 | 1069 | |
| 1070 | - foreach ( $discounts as $discount ) { |
|
| 1071 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 1072 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
| 1073 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
| 1074 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
| 1075 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
| 1070 | + foreach ($discounts as $discount) { |
|
| 1071 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
| 1072 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
| 1073 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
| 1074 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
| 1075 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
| 1076 | 1076 | |
| 1077 | 1077 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
| 1078 | 1078 | ob_start(); |
| 1079 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
| 1079 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
| 1080 | 1080 | $html .= ob_get_clean(); |
| 1081 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
| 1081 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
| 1082 | 1082 | ob_start(); |
| 1083 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
| 1083 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
| 1084 | 1084 | $html .= ob_get_clean(); |
| 1085 | 1085 | $html .= '</tr>'; |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
| 1088 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
| 1091 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
| 1092 | 1092 | $discounts = wpinv_get_cart_discounts(); |
| 1093 | 1093 | |
| 1094 | - if ( empty( $discounts ) ) { |
|
| 1094 | + if (empty($discounts)) { |
|
| 1095 | 1095 | return false; |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
| 1099 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
| 1098 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
| 1099 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
| 1100 | 1100 | |
| 1101 | - if ( $echo ) { |
|
| 1101 | + if ($echo) { |
|
| 1102 | 1102 | echo $amount; |
| 1103 | 1103 | } |
| 1104 | 1104 | |
@@ -1106,135 +1106,135 @@ discard block |
||
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | function wpinv_remove_cart_discount() { |
| 1109 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
| 1109 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
| 1110 | 1110 | return; |
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1113 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1114 | 1114 | |
| 1115 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
| 1115 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
| 1116 | 1116 | |
| 1117 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1117 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1118 | 1118 | |
| 1119 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
| 1119 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
| 1120 | 1120 | } |
| 1121 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
| 1121 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
| 1122 | 1122 | |
| 1123 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
| 1123 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
| 1124 | 1124 | $discounts = wpinv_get_cart_discounts(); |
| 1125 | 1125 | |
| 1126 | - if ( !$discounts ) { |
|
| 1126 | + if (!$discounts) { |
|
| 1127 | 1127 | return; |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | - foreach ( $discounts as $discount ) { |
|
| 1131 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
| 1132 | - wpinv_unset_cart_discount( $discount ); |
|
| 1130 | + foreach ($discounts as $discount) { |
|
| 1131 | + if (!wpinv_is_discount_valid($discount)) { |
|
| 1132 | + wpinv_unset_cart_discount($discount); |
|
| 1133 | 1133 | } |
| 1134 | 1134 | } |
| 1135 | 1135 | } |
| 1136 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
| 1136 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
| 1137 | 1137 | |
| 1138 | 1138 | function wpinv_multiple_discounts_allowed() { |
| 1139 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
| 1140 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
| 1139 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
| 1140 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | function wpinv_listen_for_cart_discount() { |
| 1144 | 1144 | global $wpi_session; |
| 1145 | 1145 | |
| 1146 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
| 1146 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
| 1147 | 1147 | return; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
| 1150 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
| 1151 | 1151 | |
| 1152 | - $wpi_session->set( 'preset_discount', $code ); |
|
| 1152 | + $wpi_session->set('preset_discount', $code); |
|
| 1153 | 1153 | } |
| 1154 | 1154 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
| 1155 | 1155 | |
| 1156 | 1156 | function wpinv_apply_preset_discount() { |
| 1157 | 1157 | global $wpi_session; |
| 1158 | 1158 | |
| 1159 | - $code = $wpi_session->get( 'preset_discount' ); |
|
| 1159 | + $code = $wpi_session->get('preset_discount'); |
|
| 1160 | 1160 | |
| 1161 | - if ( !$code ) { |
|
| 1161 | + if (!$code) { |
|
| 1162 | 1162 | return; |
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
| 1165 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
| 1166 | 1166 | return; |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
| 1169 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
| 1170 | 1170 | |
| 1171 | - wpinv_set_cart_discount( $code ); |
|
| 1171 | + wpinv_set_cart_discount($code); |
|
| 1172 | 1172 | |
| 1173 | - $wpi_session->set( 'preset_discount', null ); |
|
| 1173 | + $wpi_session->set('preset_discount', null); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
| 1176 | 1176 | |
| 1177 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
| 1178 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
| 1179 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
| 1177 | +function wpinv_get_discount_label($code, $echo = true) { |
|
| 1178 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
| 1179 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
| 1180 | 1180 | |
| 1181 | - if ( $echo ) { |
|
| 1181 | + if ($echo) { |
|
| 1182 | 1182 | echo $label; |
| 1183 | 1183 | } else { |
| 1184 | 1184 | return $label; |
| 1185 | 1185 | } |
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
| 1189 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
| 1190 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
| 1188 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
| 1189 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
| 1190 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
| 1191 | 1191 | |
| 1192 | - if ( $echo ) { |
|
| 1192 | + if ($echo) { |
|
| 1193 | 1193 | echo $label; |
| 1194 | 1194 | } else { |
| 1195 | 1195 | return $label; |
| 1196 | 1196 | } |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
| 1200 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
| 1199 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
| 1200 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
| 1201 | 1201 | return true; |
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | return $check; |
| 1205 | 1205 | } |
| 1206 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
| 1206 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
| 1207 | 1207 | |
| 1208 | 1208 | function wpinv_checkout_form_validate_discounts() { |
| 1209 | 1209 | global $wpi_checkout_id; |
| 1210 | 1210 | |
| 1211 | 1211 | $discounts = wpinv_get_cart_discounts(); |
| 1212 | 1212 | |
| 1213 | - if ( !empty( $discounts ) ) { |
|
| 1213 | + if (!empty($discounts)) { |
|
| 1214 | 1214 | $invalid = false; |
| 1215 | 1215 | |
| 1216 | - foreach ( $discounts as $key => $code ) { |
|
| 1217 | - if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) { |
|
| 1216 | + foreach ($discounts as $key => $code) { |
|
| 1217 | + if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) { |
|
| 1218 | 1218 | $invalid = true; |
| 1219 | 1219 | |
| 1220 | - wpinv_unset_cart_discount( $code ); |
|
| 1220 | + wpinv_unset_cart_discount($code); |
|
| 1221 | 1221 | } |
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | - if ( $invalid ) { |
|
| 1224 | + if ($invalid) { |
|
| 1225 | 1225 | $errors = wpinv_get_errors(); |
| 1226 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1227 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
| 1228 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
| 1226 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1227 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
| 1228 | + wpinv_set_error('wpinv-discount-error', $error); |
|
| 1229 | 1229 | |
| 1230 | - wpinv_recalculate_tax( true ); |
|
| 1230 | + wpinv_recalculate_tax(true); |
|
| 1231 | 1231 | } |
| 1232 | 1232 | } |
| 1233 | 1233 | } |
| 1234 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
| 1234 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
| 1235 | 1235 | |
| 1236 | 1236 | function wpinv_discount_amount() { |
| 1237 | 1237 | $output = 0.00; |
| 1238 | 1238 | |
| 1239 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
| 1239 | + return apply_filters('wpinv_discount_amount', $output); |
|
| 1240 | 1240 | } |
| 1241 | 1241 | \ No newline at end of file |
@@ -1,12 +1,12 @@ 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_manual_cc_form', '__return_false' ); |
|
| 5 | +add_action('wpinv_manual_cc_form', '__return_false'); |
|
| 6 | 6 | |
| 7 | -function wpinv_process_manual_payment( $purchase_data ) { |
|
| 8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
| 9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 7 | +function wpinv_process_manual_payment($purchase_data) { |
|
| 8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
| 9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /* |
@@ -41,22 +41,22 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | 43 | // Record the pending payment |
| 44 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
| 44 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
| 45 | 45 | |
| 46 | - if ( !empty( $invoice ) ) { |
|
| 47 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
| 48 | - wpinv_update_payment_status( $invoice, 'publish' ); |
|
| 46 | + if (!empty($invoice)) { |
|
| 47 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
| 48 | + wpinv_update_payment_status($invoice, 'publish'); |
|
| 49 | 49 | |
| 50 | 50 | // Empty the shopping cart |
| 51 | 51 | wpinv_empty_cart(); |
| 52 | 52 | |
| 53 | - do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data ); |
|
| 53 | + do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data); |
|
| 54 | 54 | |
| 55 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 55 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 56 | 56 | } else { |
| 57 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
| 57 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
| 58 | 58 | // If errors are present, send the user back to the purchase page so they can be corrected |
| 59 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 59 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | -add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' ); |
|
| 63 | 62 | \ No newline at end of file |
| 63 | +add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment'); |
|
| 64 | 64 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * The Subscriptions DB Class |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | 'transaction_id' => '', |
| 69 | 69 | 'parent_payment_id' => 0, |
| 70 | 70 | 'product_id' => 0, |
| 71 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
| 72 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
| 71 | + 'created' => date('Y-m-d H:i:s'), |
|
| 72 | + 'expiration' => date('Y-m-d H:i:s'), |
|
| 73 | 73 | 'trial_period' => '', |
| 74 | 74 | 'status' => '', |
| 75 | 75 | 'profile_id' => '', |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | * @access public |
| 83 | 83 | * @since 1.0.0 |
| 84 | 84 | */ |
| 85 | - public function get_subscriptions( $args = array() ) { |
|
| 85 | + public function get_subscriptions($args = array()) { |
|
| 86 | 86 | global $wpdb; |
| 87 | 87 | |
| 88 | 88 | $defaults = array( |
| 89 | - 'number' => get_option( 'posts_per_page' ), |
|
| 89 | + 'number' => get_option('posts_per_page'), |
|
| 90 | 90 | 'offset' => 0, |
| 91 | 91 | 'search' => '', |
| 92 | 92 | 'customer_id' => 0, |
@@ -94,21 +94,21 @@ discard block |
||
| 94 | 94 | 'order' => 'DESC' |
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | - $args = wp_parse_args( $args, $defaults ); |
|
| 97 | + $args = wp_parse_args($args, $defaults); |
|
| 98 | 98 | |
| 99 | - if( $args['number'] < 1 ) { |
|
| 99 | + if ($args['number'] < 1) { |
|
| 100 | 100 | $args['number'] = 999999999999; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $where = ' WHERE 1=1 '; |
| 104 | 104 | |
| 105 | 105 | // specific customers |
| 106 | - if( ! empty( $args['id'] ) ) { |
|
| 106 | + if (!empty($args['id'])) { |
|
| 107 | 107 | |
| 108 | - if( is_array( $args['id'] ) ) { |
|
| 109 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
| 108 | + if (is_array($args['id'])) { |
|
| 109 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
| 110 | 110 | } else { |
| 111 | - $ids = intval( $args['id'] ); |
|
| 111 | + $ids = intval($args['id']); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Specific products |
| 119 | - if( ! empty( $args['product_id'] ) ) { |
|
| 119 | + if (!empty($args['product_id'])) { |
|
| 120 | 120 | |
| 121 | - if( is_array( $args['product_id'] ) ) { |
|
| 122 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
| 121 | + if (is_array($args['product_id'])) { |
|
| 122 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
| 123 | 123 | } else { |
| 124 | - $product_ids = intval( $args['product_id'] ); |
|
| 124 | + $product_ids = intval($args['product_id']); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Specific parent payments |
| 132 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
| 132 | + if (!empty($args['parent_payment_id'])) { |
|
| 133 | 133 | |
| 134 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
| 135 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
| 134 | + if (is_array($args['parent_payment_id'])) { |
|
| 135 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
| 136 | 136 | } else { |
| 137 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
| 137 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -142,12 +142,12 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // Specific transaction IDs |
| 145 | - if( ! empty( $args['transaction_id'] ) ) { |
|
| 145 | + if (!empty($args['transaction_id'])) { |
|
| 146 | 146 | |
| 147 | - if( is_array( $args['transaction_id'] ) ) { |
|
| 148 | - $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
| 147 | + if (is_array($args['transaction_id'])) { |
|
| 148 | + $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id'])); |
|
| 149 | 149 | } else { |
| 150 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
| 150 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) "; |
@@ -155,12 +155,12 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Subscriptoins for specific customers |
| 158 | - if( ! empty( $args['customer_id'] ) ) { |
|
| 158 | + if (!empty($args['customer_id'])) { |
|
| 159 | 159 | |
| 160 | - if( is_array( $args['customer_id'] ) ) { |
|
| 161 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
| 160 | + if (is_array($args['customer_id'])) { |
|
| 161 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
| 162 | 162 | } else { |
| 163 | - $customer_ids = intval( $args['customer_id'] ); |
|
| 163 | + $customer_ids = intval($args['customer_id']); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Subscriptions for specific profile IDs |
| 171 | - if( ! empty( $args['profile_id'] ) ) { |
|
| 171 | + if (!empty($args['profile_id'])) { |
|
| 172 | 172 | |
| 173 | - if( is_array( $args['profile_id'] ) ) { |
|
| 174 | - $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) ); |
|
| 173 | + if (is_array($args['profile_id'])) { |
|
| 174 | + $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id'])); |
|
| 175 | 175 | } else { |
| 176 | - $profile_ids = sanitize_text_field( $args['profile_id'] ); |
|
| 176 | + $profile_ids = sanitize_text_field($args['profile_id']); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | $where .= " AND `profile_id` IN( '{$profile_ids}' ) "; |
@@ -181,12 +181,12 @@ discard block |
||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Subscriptions for specific statuses |
| 184 | - if( ! empty( $args['status'] ) ) { |
|
| 184 | + if (!empty($args['status'])) { |
|
| 185 | 185 | |
| 186 | - if( is_array( $args['status'] ) ) { |
|
| 187 | - $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) ); |
|
| 186 | + if (is_array($args['status'])) { |
|
| 187 | + $statuses = implode("','", array_map('sanitize_text_field', $args['status'])); |
|
| 188 | 188 | } else { |
| 189 | - $statuses = sanitize_text_field( $args['status'] ); |
|
| 189 | + $statuses = sanitize_text_field($args['status']); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $where .= " AND `status` IN( '{$statuses}' ) "; |
@@ -194,21 +194,21 @@ discard block |
||
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // Subscriptions created for a specific date or in a date range |
| 197 | - if( ! empty( $args['date'] ) ) { |
|
| 197 | + if (!empty($args['date'])) { |
|
| 198 | 198 | |
| 199 | - if( is_array( $args['date'] ) ) { |
|
| 199 | + if (is_array($args['date'])) { |
|
| 200 | 200 | |
| 201 | - if( ! empty( $args['date']['start'] ) ) { |
|
| 201 | + if (!empty($args['date']['start'])) { |
|
| 202 | 202 | |
| 203 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
| 203 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
| 204 | 204 | |
| 205 | 205 | $where .= " AND `created` >= '{$start}'"; |
| 206 | 206 | |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if( ! empty( $args['date']['end'] ) ) { |
|
| 209 | + if (!empty($args['date']['end'])) { |
|
| 210 | 210 | |
| 211 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
| 211 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
| 212 | 212 | |
| 213 | 213 | $where .= " AND `created` <= '{$end}'"; |
| 214 | 214 | |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | } else { |
| 218 | 218 | |
| 219 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
| 220 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
| 221 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
| 219 | + $year = date('Y', strtotime($args['date'])); |
|
| 220 | + $month = date('m', strtotime($args['date'])); |
|
| 221 | + $day = date('d', strtotime($args['date'])); |
|
| 222 | 222 | |
| 223 | 223 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
| 224 | 224 | } |
@@ -226,21 +226,21 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // Subscriptions with a specific expiration date or in an expiration date range |
| 229 | - if( ! empty( $args['expiration'] ) ) { |
|
| 229 | + if (!empty($args['expiration'])) { |
|
| 230 | 230 | |
| 231 | - if( is_array( $args['expiration'] ) ) { |
|
| 231 | + if (is_array($args['expiration'])) { |
|
| 232 | 232 | |
| 233 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
| 233 | + if (!empty($args['expiration']['start'])) { |
|
| 234 | 234 | |
| 235 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
| 235 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
| 236 | 236 | |
| 237 | 237 | $where .= " AND `expiration` >= '{$start}'"; |
| 238 | 238 | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
| 241 | + if (!empty($args['expiration']['end'])) { |
|
| 242 | 242 | |
| 243 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
| 243 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
| 244 | 244 | |
| 245 | 245 | $where .= " AND `expiration` <= '{$end}'"; |
| 246 | 246 | |
@@ -248,73 +248,73 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | } else { |
| 250 | 250 | |
| 251 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
| 252 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
| 253 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
| 251 | + $year = date('Y', strtotime($args['expiration'])); |
|
| 252 | + $month = date('m', strtotime($args['expiration'])); |
|
| 253 | + $day = date('d', strtotime($args['expiration'])); |
|
| 254 | 254 | |
| 255 | 255 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ( ! empty( $args['search'] ) ) { |
|
| 260 | + if (!empty($args['search'])) { |
|
| 261 | 261 | |
| 262 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
| 262 | + if (false !== strpos('id:', $args['search'])) { |
|
| 263 | 263 | |
| 264 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
| 265 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 264 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
| 265 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
| 266 | 266 | |
| 267 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
| 267 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
| 268 | 268 | |
| 269 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
| 270 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 269 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
| 270 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
| 271 | 271 | |
| 272 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
| 272 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
| 273 | 273 | |
| 274 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
| 275 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 274 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
| 275 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
| 276 | 276 | |
| 277 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
| 277 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
| 278 | 278 | |
| 279 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
| 280 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 279 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
| 280 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
| 281 | 281 | |
| 282 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
| 282 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
| 283 | 283 | |
| 284 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
| 285 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 284 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
| 285 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
| 286 | 286 | |
| 287 | 287 | } else { |
| 288 | 288 | |
| 289 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
| 289 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
| 290 | 290 | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby']; |
|
| 295 | + $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby']; |
|
| 296 | 296 | |
| 297 | - if( 'amount' == $args['orderby'] ) { |
|
| 297 | + if ('amount' == $args['orderby']) { |
|
| 298 | 298 | $args['orderby'] = 'amount+0'; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) ); |
|
| 301 | + $cache_key = md5('wpinv_subscriptions_' . serialize($args)); |
|
| 302 | 302 | |
| 303 | - $subscriptions = wp_cache_get( $cache_key, 'subscriptions' ); |
|
| 303 | + $subscriptions = wp_cache_get($cache_key, 'subscriptions'); |
|
| 304 | 304 | |
| 305 | - $args['orderby'] = esc_sql( $args['orderby'] ); |
|
| 306 | - $args['order'] = esc_sql( $args['order'] ); |
|
| 305 | + $args['orderby'] = esc_sql($args['orderby']); |
|
| 306 | + $args['order'] = esc_sql($args['order']); |
|
| 307 | 307 | |
| 308 | - if( $subscriptions === false ) { |
|
| 309 | - $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT ); |
|
| 308 | + if ($subscriptions === false) { |
|
| 309 | + $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT); |
|
| 310 | 310 | |
| 311 | - if( ! empty( $subscriptions ) ) { |
|
| 311 | + if (!empty($subscriptions)) { |
|
| 312 | 312 | |
| 313 | - foreach( $subscriptions as $key => $subscription ) { |
|
| 314 | - $subscriptions[ $key ] = new WPInv_Subscription( $subscription ); |
|
| 313 | + foreach ($subscriptions as $key => $subscription) { |
|
| 314 | + $subscriptions[$key] = new WPInv_Subscription($subscription); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 ); |
|
| 317 | + wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600); |
|
| 318 | 318 | |
| 319 | 319 | } |
| 320 | 320 | |
@@ -329,19 +329,19 @@ discard block |
||
| 329 | 329 | * @access public |
| 330 | 330 | * @since 1.0.0 |
| 331 | 331 | */ |
| 332 | - public function count( $args = array() ) { |
|
| 332 | + public function count($args = array()) { |
|
| 333 | 333 | |
| 334 | 334 | global $wpdb; |
| 335 | 335 | |
| 336 | 336 | $where = ' WHERE 1=1 '; |
| 337 | 337 | |
| 338 | 338 | // specific customers |
| 339 | - if( ! empty( $args['id'] ) ) { |
|
| 339 | + if (!empty($args['id'])) { |
|
| 340 | 340 | |
| 341 | - if( is_array( $args['id'] ) ) { |
|
| 342 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
| 341 | + if (is_array($args['id'])) { |
|
| 342 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
| 343 | 343 | } else { |
| 344 | - $ids = intval( $args['id'] ); |
|
| 344 | + $ids = intval($args['id']); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | $where .= " AND `id` IN( {$ids} ) "; |
@@ -349,12 +349,12 @@ discard block |
||
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | // Specific products |
| 352 | - if( ! empty( $args['product_id'] ) ) { |
|
| 352 | + if (!empty($args['product_id'])) { |
|
| 353 | 353 | |
| 354 | - if( is_array( $args['product_id'] ) ) { |
|
| 355 | - $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); |
|
| 354 | + if (is_array($args['product_id'])) { |
|
| 355 | + $product_ids = implode(',', array_map('intval', $args['product_id'])); |
|
| 356 | 356 | } else { |
| 357 | - $product_ids = intval( $args['product_id'] ); |
|
| 357 | + $product_ids = intval($args['product_id']); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $where .= " AND `product_id` IN( {$product_ids} ) "; |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Specific parent payments |
| 365 | - if( ! empty( $args['parent_payment_id'] ) ) { |
|
| 365 | + if (!empty($args['parent_payment_id'])) { |
|
| 366 | 366 | |
| 367 | - if( is_array( $args['parent_payment_id'] ) ) { |
|
| 368 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); |
|
| 367 | + if (is_array($args['parent_payment_id'])) { |
|
| 368 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); |
|
| 369 | 369 | } else { |
| 370 | - $parent_payment_ids = intval( $args['parent_payment_id'] ); |
|
| 370 | + $parent_payment_ids = intval($args['parent_payment_id']); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; |
@@ -375,12 +375,12 @@ discard block |
||
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // Subscriptoins for specific customers |
| 378 | - if( ! empty( $args['customer_id'] ) ) { |
|
| 378 | + if (!empty($args['customer_id'])) { |
|
| 379 | 379 | |
| 380 | - if( is_array( $args['customer_id'] ) ) { |
|
| 381 | - $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); |
|
| 380 | + if (is_array($args['customer_id'])) { |
|
| 381 | + $customer_ids = implode(',', array_map('intval', $args['customer_id'])); |
|
| 382 | 382 | } else { |
| 383 | - $customer_ids = intval( $args['customer_id'] ); |
|
| 383 | + $customer_ids = intval($args['customer_id']); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $where .= " AND `customer_id` IN( {$customer_ids} ) "; |
@@ -388,12 +388,12 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // Subscriptions for specific profile IDs |
| 391 | - if( ! empty( $args['profile_id'] ) ) { |
|
| 391 | + if (!empty($args['profile_id'])) { |
|
| 392 | 392 | |
| 393 | - if( is_array( $args['profile_id'] ) ) { |
|
| 394 | - $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) ); |
|
| 393 | + if (is_array($args['profile_id'])) { |
|
| 394 | + $profile_ids = implode(',', array_map('intval', $args['profile_id'])); |
|
| 395 | 395 | } else { |
| 396 | - $profile_ids = intval( $args['profile_id'] ); |
|
| 396 | + $profile_ids = intval($args['profile_id']); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | $where .= " AND `profile_id` IN( {$profile_ids} ) "; |
@@ -401,12 +401,12 @@ discard block |
||
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | // Specific transaction IDs |
| 404 | - if( ! empty( $args['transaction_id'] ) ) { |
|
| 404 | + if (!empty($args['transaction_id'])) { |
|
| 405 | 405 | |
| 406 | - if( is_array( $args['transaction_id'] ) ) { |
|
| 407 | - $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
| 406 | + if (is_array($args['transaction_id'])) { |
|
| 407 | + $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id'])); |
|
| 408 | 408 | } else { |
| 409 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
| 409 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | $where .= " AND `transaction_id` IN( {$transaction_ids} ) "; |
@@ -414,10 +414,10 @@ discard block |
||
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | // Subscriptions for specific statuses |
| 417 | - if( ! empty( $args['status'] ) ) { |
|
| 417 | + if (!empty($args['status'])) { |
|
| 418 | 418 | |
| 419 | - if( is_array( $args['status'] ) ) { |
|
| 420 | - $statuses = implode( ',', $args['status'] ); |
|
| 419 | + if (is_array($args['status'])) { |
|
| 420 | + $statuses = implode(',', $args['status']); |
|
| 421 | 421 | $where .= " AND `status` IN( {$statuses} ) "; |
| 422 | 422 | } else { |
| 423 | 423 | $statuses = $args['status']; |
@@ -429,21 +429,21 @@ discard block |
||
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | // Subscriptions created for a specific date or in a date range |
| 432 | - if( ! empty( $args['date'] ) ) { |
|
| 432 | + if (!empty($args['date'])) { |
|
| 433 | 433 | |
| 434 | - if( is_array( $args['date'] ) ) { |
|
| 434 | + if (is_array($args['date'])) { |
|
| 435 | 435 | |
| 436 | - if( ! empty( $args['date']['start'] ) ) { |
|
| 436 | + if (!empty($args['date']['start'])) { |
|
| 437 | 437 | |
| 438 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
| 438 | + $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
| 439 | 439 | |
| 440 | 440 | $where .= " AND `created` >= '{$start}'"; |
| 441 | 441 | |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - if( ! empty( $args['date']['end'] ) ) { |
|
| 444 | + if (!empty($args['date']['end'])) { |
|
| 445 | 445 | |
| 446 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
| 446 | + $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
| 447 | 447 | |
| 448 | 448 | $where .= " AND `created` <= '{$end}'"; |
| 449 | 449 | |
@@ -451,9 +451,9 @@ discard block |
||
| 451 | 451 | |
| 452 | 452 | } else { |
| 453 | 453 | |
| 454 | - $year = date( 'Y', strtotime( $args['date'] ) ); |
|
| 455 | - $month = date( 'm', strtotime( $args['date'] ) ); |
|
| 456 | - $day = date( 'd', strtotime( $args['date'] ) ); |
|
| 454 | + $year = date('Y', strtotime($args['date'])); |
|
| 455 | + $month = date('m', strtotime($args['date'])); |
|
| 456 | + $day = date('d', strtotime($args['date'])); |
|
| 457 | 457 | |
| 458 | 458 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )"; |
| 459 | 459 | } |
@@ -461,21 +461,21 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | // Subscriptions with a specific expiration date or in an expiration date range |
| 464 | - if( ! empty( $args['expiration'] ) ) { |
|
| 464 | + if (!empty($args['expiration'])) { |
|
| 465 | 465 | |
| 466 | - if( is_array( $args['expiration'] ) ) { |
|
| 466 | + if (is_array($args['expiration'])) { |
|
| 467 | 467 | |
| 468 | - if( ! empty( $args['expiration']['start'] ) ) { |
|
| 468 | + if (!empty($args['expiration']['start'])) { |
|
| 469 | 469 | |
| 470 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
| 470 | + $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
| 471 | 471 | |
| 472 | 472 | $where .= " AND `expiration` >= '{$start}'"; |
| 473 | 473 | |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - if( ! empty( $args['expiration']['end'] ) ) { |
|
| 476 | + if (!empty($args['expiration']['end'])) { |
|
| 477 | 477 | |
| 478 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
| 478 | + $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
| 479 | 479 | |
| 480 | 480 | $where .= " AND `expiration` <= '{$end}'"; |
| 481 | 481 | |
@@ -483,64 +483,64 @@ discard block |
||
| 483 | 483 | |
| 484 | 484 | } else { |
| 485 | 485 | |
| 486 | - $year = date( 'Y', strtotime( $args['expiration'] ) ); |
|
| 487 | - $month = date( 'm', strtotime( $args['expiration'] ) ); |
|
| 488 | - $day = date( 'd', strtotime( $args['expiration'] ) ); |
|
| 486 | + $year = date('Y', strtotime($args['expiration'])); |
|
| 487 | + $month = date('m', strtotime($args['expiration'])); |
|
| 488 | + $day = date('d', strtotime($args['expiration'])); |
|
| 489 | 489 | |
| 490 | 490 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )"; |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - if ( ! empty( $args['search'] ) ) { |
|
| 495 | + if (!empty($args['search'])) { |
|
| 496 | 496 | |
| 497 | - if( false !== strpos( 'id:', $args['search'] ) ) { |
|
| 497 | + if (false !== strpos('id:', $args['search'])) { |
|
| 498 | 498 | |
| 499 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
| 500 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 499 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
| 500 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
| 501 | 501 | |
| 502 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
| 502 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
| 503 | 503 | |
| 504 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
| 505 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 504 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
| 505 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
| 506 | 506 | |
| 507 | - } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
| 507 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
| 508 | 508 | |
| 509 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
| 510 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 509 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
| 510 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
| 511 | 511 | |
| 512 | - } else if( false !== strpos( $args['search'], 'product_id:' ) ) { |
|
| 512 | + } else if (false !== strpos($args['search'], 'product_id:')) { |
|
| 513 | 513 | |
| 514 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) ); |
|
| 515 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 514 | + $args['search'] = trim(str_replace('product_id:', '', $args['search'])); |
|
| 515 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'"; |
|
| 516 | 516 | |
| 517 | - } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { |
|
| 517 | + } else if (false !== strpos($args['search'], 'customer_id:')) { |
|
| 518 | 518 | |
| 519 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) ); |
|
| 520 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 519 | + $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); |
|
| 520 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'"; |
|
| 521 | 521 | |
| 522 | 522 | } else { |
| 523 | 523 | |
| 524 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
| 524 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
| 525 | 525 | |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) ); |
|
| 530 | + $cache_key = md5('wpinv_subscriptions_count' . serialize($args)); |
|
| 531 | 531 | |
| 532 | - $count = wp_cache_get( $cache_key, 'subscriptions' ); |
|
| 532 | + $count = wp_cache_get($cache_key, 'subscriptions'); |
|
| 533 | 533 | |
| 534 | - if( $count === false ) { |
|
| 534 | + if ($count === false) { |
|
| 535 | 535 | |
| 536 | 536 | $sql = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};"; |
| 537 | - $count = $wpdb->get_var( $sql ); |
|
| 537 | + $count = $wpdb->get_var($sql); |
|
| 538 | 538 | |
| 539 | - wp_cache_set( $cache_key, $count, 'subscriptions', 3600 ); |
|
| 539 | + wp_cache_set($cache_key, $count, 'subscriptions', 3600); |
|
| 540 | 540 | |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - return absint( $count ); |
|
| 543 | + return absint($count); |
|
| 544 | 544 | |
| 545 | 545 | } |
| 546 | 546 | |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | public function create_table() { |
| 554 | 554 | global $wpdb; |
| 555 | 555 | |
| 556 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 556 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 557 | 557 | |
| 558 | 558 | $sql = "CREATE TABLE " . $this->table_name . " ( |
| 559 | 559 | id bigint(20) NOT NULL AUTO_INCREMENT, |
@@ -578,9 +578,9 @@ discard block |
||
| 578 | 578 | KEY customer_and_status ( customer_id, status) |
| 579 | 579 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
| 580 | 580 | |
| 581 | - dbDelta( $sql ); |
|
| 581 | + dbDelta($sql); |
|
| 582 | 582 | |
| 583 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
| 583 | + update_option($this->table_name . '_db_version', $this->version); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | } |
| 587 | 587 | \ No newline at end of file |