@@ -12,144 +12,144 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Daily_Maintenance { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - */ |
|
| 18 | - public function __construct() { |
|
| 19 | - |
|
| 20 | - // Clear deprecated events. |
|
| 21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
| 22 | - |
|
| 23 | - // (Maybe) schedule a cron that runs daily. |
|
| 24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
| 25 | - |
|
| 26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
| 27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
| 28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
| 29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
| 30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
| 31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
| 32 | - |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Schedules a cron to run every day at 7 a.m |
|
| 37 | - * |
|
| 38 | - */ |
|
| 39 | - public function maybe_create_scheduled_event() { |
|
| 40 | - |
|
| 41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
| 42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
| 43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Clears deprecated events. |
|
| 50 | - * |
|
| 51 | - */ |
|
| 52 | - public function maybe_clear_deprecated_events() { |
|
| 53 | - |
|
| 54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
| 55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
| 56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
| 57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Fires the old hook for backwards compatibility. |
|
| 64 | - * |
|
| 65 | - */ |
|
| 66 | - public function backwards_compat() { |
|
| 67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Checks for subscriptions that are scheduled to renew. |
|
| 72 | - * |
|
| 73 | - */ |
|
| 74 | - public function check_renewing_subscriptions() { |
|
| 75 | - |
|
| 76 | - // Fetch subscriptions that expire today. |
|
| 77 | - $args = array( |
|
| 78 | - 'number' => -1, |
|
| 79 | - 'count_total' => false, |
|
| 80 | - 'status' => 'trialling active', |
|
| 81 | - 'date_expires_query' => array( |
|
| 82 | - array( |
|
| 83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
| 84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
| 85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
| 86 | - 'compare' => '=', |
|
| 87 | - ), |
|
| 88 | - ), |
|
| 89 | - ); |
|
| 90 | - |
|
| 91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 92 | - |
|
| 93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 94 | - |
|
| 95 | - /** @var WPInv_Subscription $subscription */ |
|
| 96 | - if ( $subscription->is_last_renewal() ) { |
|
| 97 | - $subscription->complete(); |
|
| 98 | - } else { |
|
| 99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
| 100 | - } |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + */ |
|
| 18 | + public function __construct() { |
|
| 19 | + |
|
| 20 | + // Clear deprecated events. |
|
| 21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
| 22 | + |
|
| 23 | + // (Maybe) schedule a cron that runs daily. |
|
| 24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
| 25 | + |
|
| 26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
| 27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
| 28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
| 29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
| 30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
| 31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
| 32 | + |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Schedules a cron to run every day at 7 a.m |
|
| 37 | + * |
|
| 38 | + */ |
|
| 39 | + public function maybe_create_scheduled_event() { |
|
| 40 | + |
|
| 41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
| 42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
| 43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Clears deprecated events. |
|
| 50 | + * |
|
| 51 | + */ |
|
| 52 | + public function maybe_clear_deprecated_events() { |
|
| 53 | + |
|
| 54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
| 55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
| 56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
| 57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Fires the old hook for backwards compatibility. |
|
| 64 | + * |
|
| 65 | + */ |
|
| 66 | + public function backwards_compat() { |
|
| 67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Checks for subscriptions that are scheduled to renew. |
|
| 72 | + * |
|
| 73 | + */ |
|
| 74 | + public function check_renewing_subscriptions() { |
|
| 75 | + |
|
| 76 | + // Fetch subscriptions that expire today. |
|
| 77 | + $args = array( |
|
| 78 | + 'number' => -1, |
|
| 79 | + 'count_total' => false, |
|
| 80 | + 'status' => 'trialling active', |
|
| 81 | + 'date_expires_query' => array( |
|
| 82 | + array( |
|
| 83 | + 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
| 84 | + 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
| 85 | + 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
| 86 | + 'compare' => '=', |
|
| 87 | + ), |
|
| 88 | + ), |
|
| 89 | + ); |
|
| 90 | + |
|
| 91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 92 | + |
|
| 93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 94 | + |
|
| 95 | + /** @var WPInv_Subscription $subscription */ |
|
| 96 | + if ( $subscription->is_last_renewal() ) { |
|
| 97 | + $subscription->complete(); |
|
| 98 | + } else { |
|
| 99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
| 100 | + } |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Expires expired subscriptions. |
|
| 107 | - * |
|
| 108 | - */ |
|
| 109 | - public function maybe_expire_subscriptions() { |
|
| 110 | - |
|
| 111 | - // Fetch expired subscriptions (skips those that expire today). |
|
| 112 | - $args = array( |
|
| 113 | - 'number' => -1, |
|
| 114 | - 'count_total' => false, |
|
| 115 | - 'status' => 'trialling active failing cancelled', |
|
| 116 | - 'date_expires_query' => array( |
|
| 117 | - 'before' => 'yesterday', |
|
| 118 | - 'inclusive' => false, |
|
| 119 | - ), |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 123 | - |
|
| 124 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 125 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
| 126 | - $subscription->set_status( 'expired' ); |
|
| 127 | - $subscription->save(); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Logs cron runs. |
|
| 135 | - * |
|
| 136 | - */ |
|
| 137 | - public function log_cron_run() { |
|
| 138 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Updates GeoIP databases. |
|
| 143 | - * |
|
| 144 | - */ |
|
| 145 | - public function maybe_update_geoip_databases() { |
|
| 146 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
| 147 | - |
|
| 148 | - if ( false === $updated ) { |
|
| 149 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
| 150 | - do_action( 'getpaid_update_geoip_databases' ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Expires expired subscriptions. |
|
| 107 | + * |
|
| 108 | + */ |
|
| 109 | + public function maybe_expire_subscriptions() { |
|
| 110 | + |
|
| 111 | + // Fetch expired subscriptions (skips those that expire today). |
|
| 112 | + $args = array( |
|
| 113 | + 'number' => -1, |
|
| 114 | + 'count_total' => false, |
|
| 115 | + 'status' => 'trialling active failing cancelled', |
|
| 116 | + 'date_expires_query' => array( |
|
| 117 | + 'before' => 'yesterday', |
|
| 118 | + 'inclusive' => false, |
|
| 119 | + ), |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 123 | + |
|
| 124 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
| 125 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
| 126 | + $subscription->set_status( 'expired' ); |
|
| 127 | + $subscription->save(); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Logs cron runs. |
|
| 135 | + * |
|
| 136 | + */ |
|
| 137 | + public function log_cron_run() { |
|
| 138 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Updates GeoIP databases. |
|
| 143 | + * |
|
| 144 | + */ |
|
| 145 | + public function maybe_update_geoip_databases() { |
|
| 146 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
| 147 | + |
|
| 148 | + if ( false === $updated ) { |
|
| 149 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
| 150 | + do_action( 'getpaid_update_geoip_databases' ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | } |
@@ -12,125 +12,125 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Session_Handler extends WPInv_Session { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Cookie name used for the session. |
|
| 17 | - * |
|
| 18 | - * @var string cookie name |
|
| 19 | - */ |
|
| 20 | - protected $_cookie; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Stores session expiry. |
|
| 24 | - * |
|
| 25 | - * @var int session due to expire timestamp |
|
| 26 | - */ |
|
| 27 | - protected $_session_expiring; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Stores session due to expire timestamp. |
|
| 31 | - * |
|
| 32 | - * @var string session expiration timestamp |
|
| 33 | - */ |
|
| 34 | - protected $_session_expiration; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * True when the cookie exists. |
|
| 38 | - * |
|
| 39 | - * @var bool Based on whether a cookie exists. |
|
| 40 | - */ |
|
| 41 | - protected $_has_cookie = false; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Table name for session data. |
|
| 45 | - * |
|
| 46 | - * @var string Custom session table name |
|
| 47 | - */ |
|
| 48 | - protected $_table; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Constructor for the session class. |
|
| 52 | - */ |
|
| 53 | - public function __construct() { |
|
| 54 | - |
|
| 55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 15 | + /** |
|
| 16 | + * Cookie name used for the session. |
|
| 17 | + * |
|
| 18 | + * @var string cookie name |
|
| 19 | + */ |
|
| 20 | + protected $_cookie; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Stores session expiry. |
|
| 24 | + * |
|
| 25 | + * @var int session due to expire timestamp |
|
| 26 | + */ |
|
| 27 | + protected $_session_expiring; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Stores session due to expire timestamp. |
|
| 31 | + * |
|
| 32 | + * @var string session expiration timestamp |
|
| 33 | + */ |
|
| 34 | + protected $_session_expiration; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * True when the cookie exists. |
|
| 38 | + * |
|
| 39 | + * @var bool Based on whether a cookie exists. |
|
| 40 | + */ |
|
| 41 | + protected $_has_cookie = false; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Table name for session data. |
|
| 45 | + * |
|
| 46 | + * @var string Custom session table name |
|
| 47 | + */ |
|
| 48 | + protected $_table; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Constructor for the session class. |
|
| 52 | + */ |
|
| 53 | + public function __construct() { |
|
| 54 | + |
|
| 55 | + $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 56 | 56 | add_action( 'init', array( $this, 'init' ), -1 ); |
| 57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Init hooks and session data. |
|
| 65 | - * |
|
| 66 | - * @since 3.3.0 |
|
| 67 | - */ |
|
| 68 | - public function init() { |
|
| 69 | - $this->init_session_cookie(); |
|
| 70 | - |
|
| 71 | - if ( ! is_user_logged_in() ) { |
|
| 72 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 ); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Setup cookie and customer ID. |
|
| 78 | - * |
|
| 79 | - * @since 3.6.0 |
|
| 80 | - */ |
|
| 81 | - public function init_session_cookie() { |
|
| 82 | - $cookie = $this->get_session_cookie(); |
|
| 83 | - |
|
| 84 | - if ( $cookie ) { |
|
| 85 | - $this->_customer_id = $cookie[0]; |
|
| 86 | - $this->_session_expiration = $cookie[1]; |
|
| 87 | - $this->_session_expiring = $cookie[2]; |
|
| 88 | - $this->_has_cookie = true; |
|
| 89 | - $this->_data = $this->get_session_data(); |
|
| 90 | - |
|
| 91 | - // If the user logs in, update session. |
|
| 92 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 93 | - $this->_customer_id = get_current_user_id(); |
|
| 94 | - $this->_dirty = true; |
|
| 95 | - $this->save_data(); |
|
| 96 | - $this->set_customer_session_cookie( true ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // Update session if its close to expiring. |
|
| 100 | - if ( time() > $this->_session_expiring ) { |
|
| 101 | - $this->set_session_expiration(); |
|
| 102 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 103 | - } |
|
| 104 | - } else { |
|
| 105 | - $this->set_session_expiration(); |
|
| 106 | - $this->_customer_id = $this->generate_customer_id(); |
|
| 107 | - $this->_data = $this->get_session_data(); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
| 113 | - * |
|
| 114 | - * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
| 115 | - * |
|
| 116 | - * Warning: Cookies will only be set if this is called before the headers are sent. |
|
| 117 | - * |
|
| 118 | - * @param bool $set Should the session cookie be set. |
|
| 119 | - */ |
|
| 120 | - public function set_customer_session_cookie( $set ) { |
|
| 121 | - if ( $set ) { |
|
| 122 | - $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
| 123 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 124 | - $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
| 125 | - $this->_has_cookie = true; |
|
| 126 | - |
|
| 127 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 128 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) { |
|
| 57 | + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | + add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Init hooks and session data. |
|
| 65 | + * |
|
| 66 | + * @since 3.3.0 |
|
| 67 | + */ |
|
| 68 | + public function init() { |
|
| 69 | + $this->init_session_cookie(); |
|
| 70 | + |
|
| 71 | + if ( ! is_user_logged_in() ) { |
|
| 72 | + add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 ); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Setup cookie and customer ID. |
|
| 78 | + * |
|
| 79 | + * @since 3.6.0 |
|
| 80 | + */ |
|
| 81 | + public function init_session_cookie() { |
|
| 82 | + $cookie = $this->get_session_cookie(); |
|
| 83 | + |
|
| 84 | + if ( $cookie ) { |
|
| 85 | + $this->_customer_id = $cookie[0]; |
|
| 86 | + $this->_session_expiration = $cookie[1]; |
|
| 87 | + $this->_session_expiring = $cookie[2]; |
|
| 88 | + $this->_has_cookie = true; |
|
| 89 | + $this->_data = $this->get_session_data(); |
|
| 90 | + |
|
| 91 | + // If the user logs in, update session. |
|
| 92 | + if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 93 | + $this->_customer_id = get_current_user_id(); |
|
| 94 | + $this->_dirty = true; |
|
| 95 | + $this->save_data(); |
|
| 96 | + $this->set_customer_session_cookie( true ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // Update session if its close to expiring. |
|
| 100 | + if ( time() > $this->_session_expiring ) { |
|
| 101 | + $this->set_session_expiration(); |
|
| 102 | + $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 103 | + } |
|
| 104 | + } else { |
|
| 105 | + $this->set_session_expiration(); |
|
| 106 | + $this->_customer_id = $this->generate_customer_id(); |
|
| 107 | + $this->_data = $this->get_session_data(); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
| 113 | + * |
|
| 114 | + * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
| 115 | + * |
|
| 116 | + * Warning: Cookies will only be set if this is called before the headers are sent. |
|
| 117 | + * |
|
| 118 | + * @param bool $set Should the session cookie be set. |
|
| 119 | + */ |
|
| 120 | + public function set_customer_session_cookie( $set ) { |
|
| 121 | + if ( $set ) { |
|
| 122 | + $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
| 123 | + $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 124 | + $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
| 125 | + $this->_has_cookie = true; |
|
| 126 | + |
|
| 127 | + if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 128 | + $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) { |
|
| 134 | 134 | if ( ! headers_sent() ) { |
| 135 | 135 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
| 136 | 136 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
@@ -139,86 +139,86 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Should the session cookie be secure? |
|
| 144 | - * |
|
| 145 | - * @since 3.6.0 |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - protected function use_secure_cookie() { |
|
| 142 | + /** |
|
| 143 | + * Should the session cookie be secure? |
|
| 144 | + * |
|
| 145 | + * @since 3.6.0 |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + protected function use_secure_cookie() { |
|
| 149 | 149 | $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
| 150 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
| 155 | - * |
|
| 156 | - * @return bool |
|
| 157 | - */ |
|
| 158 | - public function has_session() { |
|
| 159 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Set session expiration. |
|
| 164 | - */ |
|
| 165 | - public function set_session_expiration() { |
|
| 166 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 167 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Generates session ids. |
|
| 172 | - * |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function generate_customer_id() { |
|
| 176 | - require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
| 177 | - $hasher = new PasswordHash( 8, false ); |
|
| 178 | - return md5( $hasher->get_random_bytes( 32 ) ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the session cookie, if set. Otherwise return false. |
|
| 183 | - * |
|
| 184 | - * Session cookies without a customer ID are invalid. |
|
| 185 | - * |
|
| 186 | - * @return bool|array |
|
| 187 | - */ |
|
| 188 | - public function get_session_cookie() { |
|
| 189 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 190 | - |
|
| 191 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 196 | - |
|
| 197 | - if ( empty( $customer_id ) ) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Validate hash. |
|
| 202 | - $to_hash = $customer_id . '|' . $session_expiration; |
|
| 203 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 204 | - |
|
| 205 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Get session data. |
|
| 214 | - * |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - public function get_session_data() { |
|
| 218 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - public function generate_key( $customer_id ) { |
|
| 150 | + return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
| 155 | + * |
|
| 156 | + * @return bool |
|
| 157 | + */ |
|
| 158 | + public function has_session() { |
|
| 159 | + return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Set session expiration. |
|
| 164 | + */ |
|
| 165 | + public function set_session_expiration() { |
|
| 166 | + $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 167 | + $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Generates session ids. |
|
| 172 | + * |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function generate_customer_id() { |
|
| 176 | + require_once ABSPATH . 'wp-includes/class-phpass.php'; |
|
| 177 | + $hasher = new PasswordHash( 8, false ); |
|
| 178 | + return md5( $hasher->get_random_bytes( 32 ) ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the session cookie, if set. Otherwise return false. |
|
| 183 | + * |
|
| 184 | + * Session cookies without a customer ID are invalid. |
|
| 185 | + * |
|
| 186 | + * @return bool|array |
|
| 187 | + */ |
|
| 188 | + public function get_session_cookie() { |
|
| 189 | + $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 190 | + |
|
| 191 | + if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 196 | + |
|
| 197 | + if ( empty( $customer_id ) ) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Validate hash. |
|
| 202 | + $to_hash = $customer_id . '|' . $session_expiration; |
|
| 203 | + $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 204 | + |
|
| 205 | + if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Get session data. |
|
| 214 | + * |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + public function get_session_data() { |
|
| 218 | + return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + public function generate_key( $customer_id ) { |
|
| 222 | 222 | if ( ! $customer_id ) { |
| 223 | 223 | return; |
| 224 | 224 | } |
@@ -226,68 +226,68 @@ discard block |
||
| 226 | 226 | return 'wpi_trans_' . $customer_id; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Save data. |
|
| 231 | - */ |
|
| 232 | - public function save_data() { |
|
| 233 | - // Dirty if something changed - prevents saving nothing new. |
|
| 234 | - if ( $this->_dirty && $this->has_session() ) { |
|
| 229 | + /** |
|
| 230 | + * Save data. |
|
| 231 | + */ |
|
| 232 | + public function save_data() { |
|
| 233 | + // Dirty if something changed - prevents saving nothing new. |
|
| 234 | + if ( $this->_dirty && $this->has_session() ) { |
|
| 235 | 235 | |
| 236 | 236 | set_transient( $this->generate_key( $this->_customer_id ), $this->_data, $this->_session_expiration ); |
| 237 | 237 | |
| 238 | - $this->_dirty = false; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Destroy all session data. |
|
| 244 | - */ |
|
| 245 | - public function destroy_session() { |
|
| 246 | - $this->delete_session( $this->_customer_id ); |
|
| 247 | - $this->forget_session(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Forget all session data without destroying it. |
|
| 252 | - */ |
|
| 253 | - public function forget_session() { |
|
| 254 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 255 | - |
|
| 256 | - wpinv_empty_cart(); |
|
| 257 | - |
|
| 258 | - $this->_data = array(); |
|
| 259 | - $this->_dirty = false; |
|
| 260 | - $this->_customer_id = $this->generate_customer_id(); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
| 265 | - * |
|
| 266 | - * @param int $uid User ID. |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - public function nonce_user_logged_out( $uid ) { |
|
| 270 | - |
|
| 271 | - // Check if one of our nonces. |
|
| 272 | - if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) { |
|
| 273 | - return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return $uid; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Returns the session. |
|
| 281 | - * |
|
| 282 | - * @param string $customer_id Customer ID. |
|
| 283 | - * @param mixed $default Default session value. |
|
| 284 | - * @return string|array |
|
| 285 | - */ |
|
| 286 | - public function get_session( $customer_id, $default = false ) { |
|
| 287 | - |
|
| 288 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 289 | - return array(); |
|
| 290 | - } |
|
| 238 | + $this->_dirty = false; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Destroy all session data. |
|
| 244 | + */ |
|
| 245 | + public function destroy_session() { |
|
| 246 | + $this->delete_session( $this->_customer_id ); |
|
| 247 | + $this->forget_session(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Forget all session data without destroying it. |
|
| 252 | + */ |
|
| 253 | + public function forget_session() { |
|
| 254 | + $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 255 | + |
|
| 256 | + wpinv_empty_cart(); |
|
| 257 | + |
|
| 258 | + $this->_data = array(); |
|
| 259 | + $this->_dirty = false; |
|
| 260 | + $this->_customer_id = $this->generate_customer_id(); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
| 265 | + * |
|
| 266 | + * @param int $uid User ID. |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + public function nonce_user_logged_out( $uid ) { |
|
| 270 | + |
|
| 271 | + // Check if one of our nonces. |
|
| 272 | + if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) { |
|
| 273 | + return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + return $uid; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Returns the session. |
|
| 281 | + * |
|
| 282 | + * @param string $customer_id Customer ID. |
|
| 283 | + * @param mixed $default Default session value. |
|
| 284 | + * @return string|array |
|
| 285 | + */ |
|
| 286 | + public function get_session( $customer_id, $default = false ) { |
|
| 287 | + |
|
| 288 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 289 | + return array(); |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | 292 | $key = $this->generate_key( $customer_id ); |
| 293 | 293 | $value = get_transient( $key ); |
@@ -296,30 +296,30 @@ discard block |
||
| 296 | 296 | $value = $default; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - return maybe_unserialize( $value ); |
|
| 300 | - } |
|
| 299 | + return maybe_unserialize( $value ); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Delete the session from the cache and database. |
|
| 304 | - * |
|
| 305 | - * @param int $customer_id Customer ID. |
|
| 306 | - */ |
|
| 307 | - public function delete_session( $customer_id ) { |
|
| 302 | + /** |
|
| 303 | + * Delete the session from the cache and database. |
|
| 304 | + * |
|
| 305 | + * @param int $customer_id Customer ID. |
|
| 306 | + */ |
|
| 307 | + public function delete_session( $customer_id ) { |
|
| 308 | 308 | |
| 309 | 309 | $key = $this->generate_key( $customer_id ); |
| 310 | 310 | |
| 311 | - delete_transient( $key ); |
|
| 312 | - } |
|
| 311 | + delete_transient( $key ); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Update the session expiry timestamp. |
|
| 316 | - * |
|
| 317 | - * @param string $customer_id Customer ID. |
|
| 318 | - * @param int $timestamp Timestamp to expire the cookie. |
|
| 319 | - */ |
|
| 320 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 314 | + /** |
|
| 315 | + * Update the session expiry timestamp. |
|
| 316 | + * |
|
| 317 | + * @param string $customer_id Customer ID. |
|
| 318 | + * @param int $timestamp Timestamp to expire the cookie. |
|
| 319 | + */ |
|
| 320 | + public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 321 | 321 | |
| 322 | 322 | set_transient( $this->generate_key( $customer_id ), maybe_serialize( $this->_data ), $timestamp ); |
| 323 | 323 | |
| 324 | - } |
|
| 324 | + } |
|
| 325 | 325 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * Checks if the current user cna view an invoice receipt. |
| 68 | 68 | */ |
| 69 | 69 | function wpinv_can_view_receipt( $invoice ) { |
| 70 | - return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice ); |
|
| 70 | + return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -556,37 +556,37 @@ discard block |
||
| 556 | 556 | $label = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label ); |
| 557 | 557 | $columns = array( |
| 558 | 558 | |
| 559 | - 'invoice-number' => array( |
|
| 560 | - 'title' => $label, |
|
| 561 | - 'class' => 'text-left', |
|
| 562 | - ), |
|
| 559 | + 'invoice-number' => array( |
|
| 560 | + 'title' => $label, |
|
| 561 | + 'class' => 'text-left', |
|
| 562 | + ), |
|
| 563 | 563 | |
| 564 | - 'created-date' => array( |
|
| 565 | - 'title' => __( 'Created Date', 'invoicing' ), |
|
| 566 | - 'class' => 'text-left', |
|
| 567 | - ), |
|
| 564 | + 'created-date' => array( |
|
| 565 | + 'title' => __( 'Created Date', 'invoicing' ), |
|
| 566 | + 'class' => 'text-left', |
|
| 567 | + ), |
|
| 568 | 568 | |
| 569 | - 'payment-date' => array( |
|
| 570 | - 'title' => __( 'Payment Date', 'invoicing' ), |
|
| 571 | - 'class' => 'text-left', |
|
| 572 | - ), |
|
| 569 | + 'payment-date' => array( |
|
| 570 | + 'title' => __( 'Payment Date', 'invoicing' ), |
|
| 571 | + 'class' => 'text-left', |
|
| 572 | + ), |
|
| 573 | 573 | |
| 574 | - 'invoice-status' => array( |
|
| 575 | - 'title' => __( 'Status', 'invoicing' ), |
|
| 576 | - 'class' => 'text-center', |
|
| 577 | - ), |
|
| 574 | + 'invoice-status' => array( |
|
| 575 | + 'title' => __( 'Status', 'invoicing' ), |
|
| 576 | + 'class' => 'text-center', |
|
| 577 | + ), |
|
| 578 | 578 | |
| 579 | - 'invoice-total' => array( |
|
| 580 | - 'title' => __( 'Total', 'invoicing' ), |
|
| 581 | - 'class' => 'text-right', |
|
| 582 | - ), |
|
| 579 | + 'invoice-total' => array( |
|
| 580 | + 'title' => __( 'Total', 'invoicing' ), |
|
| 581 | + 'class' => 'text-right', |
|
| 582 | + ), |
|
| 583 | 583 | |
| 584 | - 'invoice-actions' => array( |
|
| 585 | - 'title' => ' ', |
|
| 586 | - 'class' => 'text-center', |
|
| 587 | - ), |
|
| 584 | + 'invoice-actions' => array( |
|
| 585 | + 'title' => ' ', |
|
| 586 | + 'class' => 'text-center', |
|
| 587 | + ), |
|
| 588 | 588 | |
| 589 | - ); |
|
| 589 | + ); |
|
| 590 | 590 | |
| 591 | 591 | return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type ); |
| 592 | 592 | } |
@@ -1274,22 +1274,22 @@ discard block |
||
| 1274 | 1274 | */ |
| 1275 | 1275 | function getpaid_get_invoice_status_classes() { |
| 1276 | 1276 | |
| 1277 | - return apply_filters( |
|
| 1278 | - 'getpaid_get_invoice_status_classes', |
|
| 1279 | - array( |
|
| 1277 | + return apply_filters( |
|
| 1278 | + 'getpaid_get_invoice_status_classes', |
|
| 1279 | + array( |
|
| 1280 | 1280 | 'wpi-quote-declined' => 'badge-danger', |
| 1281 | 1281 | 'wpi-failed' => 'badge-danger', |
| 1282 | - 'wpi-processing' => 'badge-info', |
|
| 1283 | - 'wpi-onhold' => 'badge-warning', |
|
| 1284 | - 'wpi-quote-accepted' => 'badge-success', |
|
| 1285 | - 'publish' => 'badge-success', |
|
| 1286 | - 'wpi-renewal' => 'badge-primary', |
|
| 1282 | + 'wpi-processing' => 'badge-info', |
|
| 1283 | + 'wpi-onhold' => 'badge-warning', |
|
| 1284 | + 'wpi-quote-accepted' => 'badge-success', |
|
| 1285 | + 'publish' => 'badge-success', |
|
| 1286 | + 'wpi-renewal' => 'badge-primary', |
|
| 1287 | 1287 | 'wpi-cancelled' => 'badge-secondary', |
| 1288 | 1288 | 'wpi-pending' => 'badge-dark', |
| 1289 | 1289 | 'wpi-quote-pending' => 'badge-dark', |
| 1290 | 1290 | 'wpi-refunded' => 'badge-secondary', |
| 1291 | - ) |
|
| 1292 | - ); |
|
| 1291 | + ) |
|
| 1292 | + ); |
|
| 1293 | 1293 | |
| 1294 | 1294 | } |
| 1295 | 1295 | |
@@ -1303,7 +1303,7 @@ discard block |
||
| 1303 | 1303 | function getpaid_get_invoice_tax_rate( $invoice, $item ) { |
| 1304 | 1304 | |
| 1305 | 1305 | $rates = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() ); |
| 1306 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 1306 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 1307 | 1307 | $rates = wp_list_pluck( $rates, 'rate' ); |
| 1308 | 1308 | |
| 1309 | 1309 | return array_sum( $rates ); |
@@ -13,17 +13,17 @@ discard block |
||
| 13 | 13 | class GetPaid_Notification_Email_Sender { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Whether or not we should inline CSS into the email. |
|
| 17 | - */ |
|
| 18 | - public $inline_css = true; |
|
| 16 | + * Whether or not we should inline CSS into the email. |
|
| 17 | + */ |
|
| 18 | + public $inline_css = true; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * The wp_mail() data. |
|
| 22 | - */ |
|
| 21 | + * The wp_mail() data. |
|
| 22 | + */ |
|
| 23 | 23 | public $wp_mail_data = null; |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * Sends a new email. |
|
| 26 | + * Sends a new email. |
|
| 27 | 27 | * |
| 28 | 28 | * @param string|array $to The recipients email or an array of recipient emails. |
| 29 | 29 | * @param string $subject The email's subject. |
@@ -31,49 +31,49 @@ discard block |
||
| 31 | 31 | * @param array $attachments The email attachments. |
| 32 | 32 | * |
| 33 | 33 | * @return bool |
| 34 | - */ |
|
| 35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
| 34 | + */ |
|
| 35 | + public function send( $to, $subject, $email, $attachments = array() ) { |
|
| 36 | 36 | |
| 37 | - /* |
|
| 37 | + /* |
|
| 38 | 38 | * Allow to filter data on per-email basis. |
| 39 | 39 | */ |
| 40 | - $data = apply_filters( |
|
| 41 | - 'getpaid_email_data', |
|
| 42 | - array( |
|
| 43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
| 44 | - 'subject' => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ), |
|
| 45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
| 46 | - 'headers' => $this->get_headers(), |
|
| 47 | - 'attachments' => $attachments, |
|
| 48 | - ), |
|
| 49 | - $this |
|
| 50 | - ); |
|
| 40 | + $data = apply_filters( |
|
| 41 | + 'getpaid_email_data', |
|
| 42 | + array( |
|
| 43 | + 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
| 44 | + 'subject' => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ), |
|
| 45 | + 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
| 46 | + 'headers' => $this->get_headers(), |
|
| 47 | + 'attachments' => $attachments, |
|
| 48 | + ), |
|
| 49 | + $this |
|
| 50 | + ); |
|
| 51 | 51 | |
| 52 | 52 | // Remove slashes. |
| 53 | 53 | $data = (array) wp_unslash( $data ); |
| 54 | 54 | |
| 55 | 55 | // Cache it. |
| 56 | - $this->wp_mail_data = $data; |
|
| 56 | + $this->wp_mail_data = $data; |
|
| 57 | 57 | |
| 58 | - // Attach our own hooks. |
|
| 59 | - $this->before_sending(); |
|
| 58 | + // Attach our own hooks. |
|
| 59 | + $this->before_sending(); |
|
| 60 | 60 | |
| 61 | 61 | $result = false; |
| 62 | 62 | |
| 63 | 63 | foreach ( $this->wp_mail_data['to'] as $to ) { |
| 64 | - $result = $this->_send( $to, $data ); |
|
| 64 | + $result = $this->_send( $to, $data ); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - // Remove our hooks. |
|
| 68 | - $this->after_sending(); |
|
| 67 | + // Remove our hooks. |
|
| 68 | + $this->after_sending(); |
|
| 69 | 69 | |
| 70 | - $this->wp_mail_data = null; |
|
| 70 | + $this->wp_mail_data = null; |
|
| 71 | 71 | |
| 72 | - return $result; |
|
| 73 | - } |
|
| 72 | + return $result; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Does the actual sending. |
|
| 75 | + /** |
|
| 76 | + * Does the actual sending. |
|
| 77 | 77 | * |
| 78 | 78 | * @param string $to The recipient's email. |
| 79 | 79 | * @param array $data The email's data. |
@@ -81,81 +81,81 @@ discard block |
||
| 81 | 81 | * @param array $attachments The email attachments. |
| 82 | 82 | * |
| 83 | 83 | * @return bool |
| 84 | - */ |
|
| 85 | - protected function _send( $to, $data ) { |
|
| 86 | - |
|
| 87 | - // Prepare the sending function. |
|
| 88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
| 89 | - |
|
| 90 | - // Send the actual email. |
|
| 91 | - $result = call_user_func( |
|
| 92 | - $sending_function, |
|
| 93 | - $to, |
|
| 94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
| 95 | - $data['email'], |
|
| 96 | - $data['headers'], |
|
| 97 | - $data['attachments'] |
|
| 98 | - ); |
|
| 99 | - |
|
| 100 | - if ( ! $result ) { |
|
| 101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
| 102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $result; |
|
| 106 | - } |
|
| 84 | + */ |
|
| 85 | + protected function _send( $to, $data ) { |
|
| 86 | + |
|
| 87 | + // Prepare the sending function. |
|
| 88 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
| 89 | + |
|
| 90 | + // Send the actual email. |
|
| 91 | + $result = call_user_func( |
|
| 92 | + $sending_function, |
|
| 93 | + $to, |
|
| 94 | + html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
| 95 | + $data['email'], |
|
| 96 | + $data['headers'], |
|
| 97 | + $data['attachments'] |
|
| 98 | + ); |
|
| 99 | + |
|
| 100 | + if ( ! $result ) { |
|
| 101 | + $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
| 102 | + wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $result; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | - * Retrieves email headers. |
|
| 110 | - */ |
|
| 111 | - public function get_headers() { |
|
| 109 | + * Retrieves email headers. |
|
| 110 | + */ |
|
| 111 | + public function get_headers() { |
|
| 112 | 112 | |
| 113 | - $name = $this->get_from_name(); |
|
| 114 | - $reply_to = $this->get_reply_to(); |
|
| 115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
| 113 | + $name = $this->get_from_name(); |
|
| 114 | + $reply_to = $this->get_reply_to(); |
|
| 115 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
| 116 | 116 | |
| 117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
| 117 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
| 118 | 118 | |
| 119 | - } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | - * Fires before an email is sent |
|
| 123 | - * |
|
| 124 | - * @since 1.0.0 |
|
| 125 | - */ |
|
| 126 | - public function before_sending() { |
|
| 122 | + * Fires before an email is sent |
|
| 123 | + * |
|
| 124 | + * @since 1.0.0 |
|
| 125 | + */ |
|
| 126 | + public function before_sending() { |
|
| 127 | 127 | |
| 128 | 128 | do_action( 'getpaid_before_send_email', $this ); |
| 129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
| 130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
| 131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
| 132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
| 129 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
| 130 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
| 131 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
| 132 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
| 133 | 133 | |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | - * Returns the from name. |
|
| 138 | - */ |
|
| 139 | - public function get_from_name() { |
|
| 137 | + * Returns the from name. |
|
| 138 | + */ |
|
| 139 | + public function get_from_name() { |
|
| 140 | 140 | |
| 141 | 141 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
| 142 | 142 | |
| 143 | - if ( empty( $from_name ) ) { |
|
| 144 | - $from_name = get_bloginfo( 'name' ); |
|
| 143 | + if ( empty( $from_name ) ) { |
|
| 144 | + $from_name = get_bloginfo( 'name' ); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
| 147 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | - * Returns the from email. |
|
| 152 | - */ |
|
| 153 | - public function get_from_address() { |
|
| 151 | + * Returns the from email. |
|
| 152 | + */ |
|
| 153 | + public function get_from_address() { |
|
| 154 | 154 | |
| 155 | 155 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
| 156 | 156 | |
| 157 | - if ( ! is_email( $from_address ) ) { |
|
| 158 | - $from_address = $this->default_from_address(); |
|
| 157 | + if ( ! is_email( $from_address ) ) { |
|
| 158 | + $from_address = $this->default_from_address(); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | return $from_address; |
@@ -163,75 +163,75 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * The default emails from address. |
|
| 167 | - * |
|
| 168 | - * Defaults to wordpress@$sitename |
|
| 169 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
| 170 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
| 171 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
| 172 | - * |
|
| 173 | - */ |
|
| 174 | - public function default_from_address() { |
|
| 175 | - |
|
| 176 | - // Get the site domain and get rid of www. |
|
| 177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
| 178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
| 179 | - $sitename = substr( $sitename, 4 ); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $from_email = 'wordpress@' . $sitename; |
|
| 183 | - |
|
| 184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
| 166 | + * The default emails from address. |
|
| 167 | + * |
|
| 168 | + * Defaults to wordpress@$sitename |
|
| 169 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
| 170 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
| 171 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
| 172 | + * |
|
| 173 | + */ |
|
| 174 | + public function default_from_address() { |
|
| 175 | + |
|
| 176 | + // Get the site domain and get rid of www. |
|
| 177 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
| 178 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
| 179 | + $sitename = substr( $sitename, 4 ); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $from_email = 'wordpress@' . $sitename; |
|
| 183 | + |
|
| 184 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
| 185 | 185 | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
| 189 | - * Get the email reply-to. |
|
| 190 | - * |
|
| 191 | - * |
|
| 192 | - * @return string The email reply-to address. |
|
| 193 | - */ |
|
| 194 | - public function get_reply_to() { |
|
| 189 | + * Get the email reply-to. |
|
| 190 | + * |
|
| 191 | + * |
|
| 192 | + * @return string The email reply-to address. |
|
| 193 | + */ |
|
| 194 | + public function get_reply_to() { |
|
| 195 | 195 | |
| 196 | - $reply_to = wpinv_get_admin_email(); |
|
| 196 | + $reply_to = wpinv_get_admin_email(); |
|
| 197 | 197 | |
| 198 | - if ( ! is_email( $reply_to ) ) { |
|
| 199 | - $reply_to = get_option( 'admin_email' ); |
|
| 200 | - } |
|
| 198 | + if ( ! is_email( $reply_to ) ) { |
|
| 199 | + $reply_to = get_option( 'admin_email' ); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return $reply_to; |
|
| 202 | + return $reply_to; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | - * Get the email content type. |
|
| 207 | - * |
|
| 208 | - */ |
|
| 209 | - public function get_content_type() { |
|
| 210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
| 206 | + * Get the email content type. |
|
| 207 | + * |
|
| 208 | + */ |
|
| 209 | + public function get_content_type() { |
|
| 210 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | - * Ensures that our email messages are not messed up by template plugins. |
|
| 215 | - * |
|
| 216 | - * @return array wp_mail_data. |
|
| 217 | - */ |
|
| 218 | - public function ensure_email_content( $args ) { |
|
| 219 | - $args['message'] = $this->wp_mail_data['email']; |
|
| 220 | - return $args; |
|
| 214 | + * Ensures that our email messages are not messed up by template plugins. |
|
| 215 | + * |
|
| 216 | + * @return array wp_mail_data. |
|
| 217 | + */ |
|
| 218 | + public function ensure_email_content( $args ) { |
|
| 219 | + $args['message'] = $this->wp_mail_data['email']; |
|
| 220 | + return $args; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
| 224 | - * A little house keeping after an email is sent. |
|
| 225 | - * |
|
| 226 | - */ |
|
| 227 | - public function after_sending() { |
|
| 224 | + * A little house keeping after an email is sent. |
|
| 225 | + * |
|
| 226 | + */ |
|
| 227 | + public function after_sending() { |
|
| 228 | 228 | |
| 229 | 229 | do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
| 230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
| 231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
| 232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
| 233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
| 230 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
| 231 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
| 232 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
| 233 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
| 234 | 234 | |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | 237 | } |
@@ -14,617 +14,617 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array An array of payment gateways. |
|
| 40 | - */ |
|
| 41 | - public $gateways; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Class constructor. |
|
| 45 | - */ |
|
| 46 | - public function __construct() { |
|
| 47 | - $this->define_constants(); |
|
| 48 | - $this->includes(); |
|
| 49 | - $this->init_hooks(); |
|
| 50 | - $this->set_properties(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Sets a custom data property. |
|
| 55 | - * |
|
| 56 | - * @param string $prop The prop to set. |
|
| 57 | - * @param mixed $value The value to retrieve. |
|
| 58 | - */ |
|
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets a custom data property. |
|
| 65 | - * |
|
| 66 | - * @param string $prop The prop to set. |
|
| 67 | - * @return mixed The value. |
|
| 68 | - */ |
|
| 69 | - public function get( $prop ) { |
|
| 70 | - |
|
| 71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | - return $this->data[ $prop ]; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return null; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Define class properties. |
|
| 80 | - */ |
|
| 81 | - public function set_properties() { |
|
| 82 | - |
|
| 83 | - // Sessions. |
|
| 84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 87 | - |
|
| 88 | - // Init other objects. |
|
| 89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 91 | - $this->set( 'api', new WPInv_API() ); |
|
| 92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 93 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Define plugin constants. |
|
| 106 | - */ |
|
| 107 | - public function define_constants() { |
|
| 108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | - $this->version = WPINV_VERSION; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Hook into actions and filters. |
|
| 115 | - * |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - */ |
|
| 118 | - protected function init_hooks() { |
|
| 119 | - /* Internationalize the text strings used. */ |
|
| 120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 121 | - |
|
| 122 | - // Init the plugin after WordPress inits. |
|
| 123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 130 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | - |
|
| 134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array An array of payment gateways. |
|
| 40 | + */ |
|
| 41 | + public $gateways; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Class constructor. |
|
| 45 | + */ |
|
| 46 | + public function __construct() { |
|
| 47 | + $this->define_constants(); |
|
| 48 | + $this->includes(); |
|
| 49 | + $this->init_hooks(); |
|
| 50 | + $this->set_properties(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Sets a custom data property. |
|
| 55 | + * |
|
| 56 | + * @param string $prop The prop to set. |
|
| 57 | + * @param mixed $value The value to retrieve. |
|
| 58 | + */ |
|
| 59 | + public function set( $prop, $value ) { |
|
| 60 | + $this->data[ $prop ] = $value; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets a custom data property. |
|
| 65 | + * |
|
| 66 | + * @param string $prop The prop to set. |
|
| 67 | + * @return mixed The value. |
|
| 68 | + */ |
|
| 69 | + public function get( $prop ) { |
|
| 70 | + |
|
| 71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 72 | + return $this->data[ $prop ]; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return null; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Define class properties. |
|
| 80 | + */ |
|
| 81 | + public function set_properties() { |
|
| 82 | + |
|
| 83 | + // Sessions. |
|
| 84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 87 | + |
|
| 88 | + // Init other objects. |
|
| 89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 91 | + $this->set( 'api', new WPInv_API() ); |
|
| 92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 93 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Define plugin constants. |
|
| 106 | + */ |
|
| 107 | + public function define_constants() { |
|
| 108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 110 | + $this->version = WPINV_VERSION; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Hook into actions and filters. |
|
| 115 | + * |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + */ |
|
| 118 | + protected function init_hooks() { |
|
| 119 | + /* Internationalize the text strings used. */ |
|
| 120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 121 | + |
|
| 122 | + // Init the plugin after WordPress inits. |
|
| 123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 128 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 129 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 130 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 131 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 133 | + |
|
| 134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
| 136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 137 | - |
|
| 138 | - // Fires after registering actions. |
|
| 139 | - do_action( 'wpinv_actions', $this ); |
|
| 140 | - do_action( 'getpaid_actions', $this ); |
|
| 141 | - |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function plugins_loaded() { |
|
| 145 | - /* Internationalize the text strings used. */ |
|
| 146 | - $this->load_textdomain(); |
|
| 147 | - |
|
| 148 | - do_action( 'wpinv_loaded' ); |
|
| 149 | - |
|
| 150 | - // Fix oxygen page builder conflict |
|
| 151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 152 | - wpinv_oxygen_fix_conflict(); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Load Localisation files. |
|
| 158 | - * |
|
| 159 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 160 | - * |
|
| 161 | - * Locales found in: |
|
| 162 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 163 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 164 | - * |
|
| 165 | - * @since 1.0.0 |
|
| 166 | - */ |
|
| 167 | - public function load_textdomain() { |
|
| 168 | - |
|
| 169 | - load_plugin_textdomain( |
|
| 170 | - 'invoicing', |
|
| 171 | - false, |
|
| 172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Include required core files used in admin and on the frontend. |
|
| 179 | - */ |
|
| 180 | - public function includes() { |
|
| 181 | - |
|
| 182 | - // Start with the settings. |
|
| 183 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 184 | - |
|
| 185 | - // Packages/libraries. |
|
| 186 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 187 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 188 | - |
|
| 189 | - // Load functions. |
|
| 190 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 191 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 192 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 193 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 194 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 195 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 197 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 198 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 203 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 204 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 205 | - |
|
| 206 | - // Register autoloader. |
|
| 207 | - try { |
|
| 208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 209 | - } catch ( Exception $e ) { |
|
| 210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 214 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 215 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 216 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 217 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 218 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 219 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 221 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 222 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 224 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 226 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 227 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 228 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 229 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 230 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 231 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 232 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 234 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 235 | - |
|
| 236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 237 | - GetPaid_Post_Types_Admin::init(); |
|
| 238 | - |
|
| 239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 241 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 242 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 243 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 245 | - // load the user class only on the users.php page |
|
| 246 | - global $pagenow; |
|
| 247 | - if ( $pagenow == 'users.php' ) { |
|
| 248 | - new WPInv_Admin_Users(); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // Register cli commands |
|
| 253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 254 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Class autoloader |
|
| 262 | - * |
|
| 263 | - * @param string $class_name The name of the class to load. |
|
| 264 | - * @access public |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @return void |
|
| 267 | - */ |
|
| 268 | - public function autoload( $class_name ) { |
|
| 269 | - |
|
| 270 | - // Normalize the class name... |
|
| 271 | - $class_name = strtolower( $class_name ); |
|
| 272 | - |
|
| 273 | - // ... and make sure it is our class. |
|
| 274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // Next, prepare the file name from the class. |
|
| 279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 280 | - |
|
| 281 | - // Base path of the classes. |
|
| 282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 283 | - |
|
| 284 | - // And an array of possible locations in order of importance. |
|
| 285 | - $locations = array( |
|
| 286 | - "$plugin_path/includes", |
|
| 287 | - "$plugin_path/includes/data-stores", |
|
| 288 | - "$plugin_path/includes/gateways", |
|
| 289 | - "$plugin_path/includes/payments", |
|
| 290 | - "$plugin_path/includes/geolocation", |
|
| 291 | - "$plugin_path/includes/reports", |
|
| 292 | - "$plugin_path/includes/api", |
|
| 293 | - "$plugin_path/includes/admin", |
|
| 294 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 295 | - ); |
|
| 296 | - |
|
| 297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 298 | - |
|
| 299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | - include trailingslashit( $location ) . $file_name; |
|
| 301 | - break; |
|
| 302 | - } |
|
| 136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 137 | + |
|
| 138 | + // Fires after registering actions. |
|
| 139 | + do_action( 'wpinv_actions', $this ); |
|
| 140 | + do_action( 'getpaid_actions', $this ); |
|
| 141 | + |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function plugins_loaded() { |
|
| 145 | + /* Internationalize the text strings used. */ |
|
| 146 | + $this->load_textdomain(); |
|
| 147 | + |
|
| 148 | + do_action( 'wpinv_loaded' ); |
|
| 149 | + |
|
| 150 | + // Fix oxygen page builder conflict |
|
| 151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 152 | + wpinv_oxygen_fix_conflict(); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Load Localisation files. |
|
| 158 | + * |
|
| 159 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 160 | + * |
|
| 161 | + * Locales found in: |
|
| 162 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 163 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 164 | + * |
|
| 165 | + * @since 1.0.0 |
|
| 166 | + */ |
|
| 167 | + public function load_textdomain() { |
|
| 168 | + |
|
| 169 | + load_plugin_textdomain( |
|
| 170 | + 'invoicing', |
|
| 171 | + false, |
|
| 172 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Include required core files used in admin and on the frontend. |
|
| 179 | + */ |
|
| 180 | + public function includes() { |
|
| 181 | + |
|
| 182 | + // Start with the settings. |
|
| 183 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 184 | + |
|
| 185 | + // Packages/libraries. |
|
| 186 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 187 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 188 | + |
|
| 189 | + // Load functions. |
|
| 190 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 191 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 192 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 193 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 194 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 195 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 197 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 198 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 203 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 204 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 205 | + |
|
| 206 | + // Register autoloader. |
|
| 207 | + try { |
|
| 208 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 209 | + } catch ( Exception $e ) { |
|
| 210 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 214 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 215 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 216 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 217 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 218 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 219 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 221 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 222 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 224 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 226 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 227 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 228 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 229 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 230 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 231 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 232 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 234 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 235 | + |
|
| 236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 237 | + GetPaid_Post_Types_Admin::init(); |
|
| 238 | + |
|
| 239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 241 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 242 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 243 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 245 | + // load the user class only on the users.php page |
|
| 246 | + global $pagenow; |
|
| 247 | + if ( $pagenow == 'users.php' ) { |
|
| 248 | + new WPInv_Admin_Users(); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // Register cli commands |
|
| 253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 254 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Class autoloader |
|
| 262 | + * |
|
| 263 | + * @param string $class_name The name of the class to load. |
|
| 264 | + * @access public |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @return void |
|
| 267 | + */ |
|
| 268 | + public function autoload( $class_name ) { |
|
| 269 | + |
|
| 270 | + // Normalize the class name... |
|
| 271 | + $class_name = strtolower( $class_name ); |
|
| 272 | + |
|
| 273 | + // ... and make sure it is our class. |
|
| 274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // Next, prepare the file name from the class. |
|
| 279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 280 | + |
|
| 281 | + // Base path of the classes. |
|
| 282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 283 | + |
|
| 284 | + // And an array of possible locations in order of importance. |
|
| 285 | + $locations = array( |
|
| 286 | + "$plugin_path/includes", |
|
| 287 | + "$plugin_path/includes/data-stores", |
|
| 288 | + "$plugin_path/includes/gateways", |
|
| 289 | + "$plugin_path/includes/payments", |
|
| 290 | + "$plugin_path/includes/geolocation", |
|
| 291 | + "$plugin_path/includes/reports", |
|
| 292 | + "$plugin_path/includes/api", |
|
| 293 | + "$plugin_path/includes/admin", |
|
| 294 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 295 | + ); |
|
| 296 | + |
|
| 297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 298 | + |
|
| 299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 300 | + include trailingslashit( $location ) . $file_name; |
|
| 301 | + break; |
|
| 302 | + } |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Inits hooks etc. |
|
| 309 | - */ |
|
| 310 | - public function init() { |
|
| 311 | - |
|
| 312 | - // Fires before getpaid inits. |
|
| 313 | - do_action( 'before_getpaid_init', $this ); |
|
| 314 | - |
|
| 315 | - // Maybe upgrade. |
|
| 316 | - $this->maybe_upgrade_database(); |
|
| 317 | - |
|
| 318 | - // Load default gateways. |
|
| 319 | - $gateways = apply_filters( |
|
| 320 | - 'getpaid_default_gateways', |
|
| 321 | - array( |
|
| 322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | - ) |
|
| 328 | - ); |
|
| 329 | - |
|
| 330 | - foreach ( $gateways as $id => $class ) { |
|
| 331 | - $this->gateways[ $id ] = new $class(); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | - GetPaid_Installer::rename_gateways_label(); |
|
| 336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // Fires after getpaid inits. |
|
| 340 | - do_action( 'getpaid_init', $this ); |
|
| 341 | - |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Checks if this is an IPN request and processes it. |
|
| 346 | - */ |
|
| 347 | - public function maybe_process_ipn() { |
|
| 348 | - |
|
| 349 | - // Ensure that this is an IPN request. |
|
| 350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 351 | - return; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 355 | - |
|
| 356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 358 | - exit; |
|
| 359 | - |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - public function enqueue_scripts() { |
|
| 363 | - |
|
| 364 | - // Fires before adding scripts. |
|
| 365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 366 | - |
|
| 367 | - $localize = array(); |
|
| 368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 369 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
| 370 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
| 371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 377 | - |
|
| 378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 379 | - |
|
| 380 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 381 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 382 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - public function wpinv_actions() { |
|
| 386 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 387 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 391 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Inits hooks etc. |
|
| 309 | + */ |
|
| 310 | + public function init() { |
|
| 311 | + |
|
| 312 | + // Fires before getpaid inits. |
|
| 313 | + do_action( 'before_getpaid_init', $this ); |
|
| 314 | + |
|
| 315 | + // Maybe upgrade. |
|
| 316 | + $this->maybe_upgrade_database(); |
|
| 317 | + |
|
| 318 | + // Load default gateways. |
|
| 319 | + $gateways = apply_filters( |
|
| 320 | + 'getpaid_default_gateways', |
|
| 321 | + array( |
|
| 322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | + ) |
|
| 328 | + ); |
|
| 329 | + |
|
| 330 | + foreach ( $gateways as $id => $class ) { |
|
| 331 | + $this->gateways[ $id ] = new $class(); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | + GetPaid_Installer::rename_gateways_label(); |
|
| 336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // Fires after getpaid inits. |
|
| 340 | + do_action( 'getpaid_init', $this ); |
|
| 341 | + |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Checks if this is an IPN request and processes it. |
|
| 346 | + */ |
|
| 347 | + public function maybe_process_ipn() { |
|
| 348 | + |
|
| 349 | + // Ensure that this is an IPN request. |
|
| 350 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 351 | + return; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 355 | + |
|
| 356 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 357 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 358 | + exit; |
|
| 359 | + |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + public function enqueue_scripts() { |
|
| 363 | + |
|
| 364 | + // Fires before adding scripts. |
|
| 365 | + do_action( 'getpaid_enqueue_scripts' ); |
|
| 366 | + |
|
| 367 | + $localize = array(); |
|
| 368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 369 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
| 370 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
| 371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 375 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 377 | + |
|
| 378 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 379 | + |
|
| 380 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 381 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 382 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + public function wpinv_actions() { |
|
| 386 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 387 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 391 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | 396 | * Fires an action after verifying that a user can fire them. |
| 397 | - * |
|
| 398 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 399 | - * current user owns the invoice/subscription. |
|
| 397 | + * |
|
| 398 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 399 | + * current user owns the invoice/subscription. |
|
| 400 | 400 | */ |
| 401 | 401 | public function maybe_do_authenticated_action() { |
| 402 | 402 | |
| 403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 403 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 404 | 404 | |
| 405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | - $data = wp_unslash( $_REQUEST ); |
|
| 407 | - if ( is_user_logged_in() ) { |
|
| 408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 409 | - } |
|
| 405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | + $data = wp_unslash( $_REQUEST ); |
|
| 407 | + if ( is_user_logged_in() ) { |
|
| 408 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 411 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 412 | 412 | |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - public function pre_get_posts( $wp_query ) { |
|
| 418 | - |
|
| 419 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 420 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $wp_query; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Register widgets |
|
| 428 | - * |
|
| 429 | - */ |
|
| 430 | - public function register_widgets() { |
|
| 431 | - global $pagenow; |
|
| 432 | - |
|
| 433 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 434 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 435 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 436 | - return; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 440 | - |
|
| 441 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 442 | - // don't initiate in these conditions. |
|
| 443 | - } else { |
|
| 444 | - |
|
| 445 | - // Only load allowed widgets. |
|
| 446 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 447 | - $widgets = apply_filters( |
|
| 448 | - 'getpaid_widget_classes', |
|
| 449 | - array( |
|
| 450 | - 'WPInv_Checkout_Widget', |
|
| 451 | - 'WPInv_History_Widget', |
|
| 452 | - 'WPInv_Receipt_Widget', |
|
| 453 | - 'WPInv_Subscriptions_Widget', |
|
| 454 | - 'WPInv_Buy_Item_Widget', |
|
| 455 | - 'WPInv_Messages_Widget', |
|
| 456 | - 'WPInv_GetPaid_Widget', |
|
| 457 | - 'WPInv_Invoice_Widget', |
|
| 458 | - ) |
|
| 459 | - ); |
|
| 460 | - |
|
| 461 | - // For each widget... |
|
| 462 | - foreach ( $widgets as $widget ) { |
|
| 463 | - |
|
| 464 | - // Abort early if it is excluded for this page. |
|
| 465 | - if ( in_array( $widget, $exclude ) ) { |
|
| 466 | - continue; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 470 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 471 | - register_widget( $widget ); |
|
| 472 | - } else { |
|
| 473 | - new $widget(); |
|
| 474 | - } |
|
| 417 | + public function pre_get_posts( $wp_query ) { |
|
| 418 | + |
|
| 419 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 420 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $wp_query; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Register widgets |
|
| 428 | + * |
|
| 429 | + */ |
|
| 430 | + public function register_widgets() { |
|
| 431 | + global $pagenow; |
|
| 432 | + |
|
| 433 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 434 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 435 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 436 | + return; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 440 | + |
|
| 441 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 442 | + // don't initiate in these conditions. |
|
| 443 | + } else { |
|
| 444 | + |
|
| 445 | + // Only load allowed widgets. |
|
| 446 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 447 | + $widgets = apply_filters( |
|
| 448 | + 'getpaid_widget_classes', |
|
| 449 | + array( |
|
| 450 | + 'WPInv_Checkout_Widget', |
|
| 451 | + 'WPInv_History_Widget', |
|
| 452 | + 'WPInv_Receipt_Widget', |
|
| 453 | + 'WPInv_Subscriptions_Widget', |
|
| 454 | + 'WPInv_Buy_Item_Widget', |
|
| 455 | + 'WPInv_Messages_Widget', |
|
| 456 | + 'WPInv_GetPaid_Widget', |
|
| 457 | + 'WPInv_Invoice_Widget', |
|
| 458 | + ) |
|
| 459 | + ); |
|
| 460 | + |
|
| 461 | + // For each widget... |
|
| 462 | + foreach ( $widgets as $widget ) { |
|
| 463 | + |
|
| 464 | + // Abort early if it is excluded for this page. |
|
| 465 | + if ( in_array( $widget, $exclude ) ) { |
|
| 466 | + continue; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 470 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 471 | + register_widget( $widget ); |
|
| 472 | + } else { |
|
| 473 | + new $widget(); |
|
| 474 | + } |
|
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - } |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - /** |
|
| 481 | - * Upgrades the database. |
|
| 482 | - * |
|
| 483 | - * @since 2.0.2 |
|
| 484 | - */ |
|
| 485 | - public function maybe_upgrade_database() { |
|
| 480 | + /** |
|
| 481 | + * Upgrades the database. |
|
| 482 | + * |
|
| 483 | + * @since 2.0.2 |
|
| 484 | + */ |
|
| 485 | + public function maybe_upgrade_database() { |
|
| 486 | 486 | |
| 487 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 487 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 488 | 488 | |
| 489 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 490 | - return; |
|
| 491 | - } |
|
| 489 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 490 | + return; |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | - $installer = new GetPaid_Installer(); |
|
| 493 | + $installer = new GetPaid_Installer(); |
|
| 494 | 494 | |
| 495 | - if ( empty( $wpi_version ) ) { |
|
| 496 | - return $installer->upgrade_db( 0 ); |
|
| 497 | - } |
|
| 495 | + if ( empty( $wpi_version ) ) { |
|
| 496 | + return $installer->upgrade_db( 0 ); |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | - $upgrades = array( |
|
| 500 | - '0.0.5' => '004', |
|
| 501 | - '1.0.3' => '102', |
|
| 502 | - '2.0.0' => '118', |
|
| 503 | - '2.0.8' => '207', |
|
| 504 | - ); |
|
| 499 | + $upgrades = array( |
|
| 500 | + '0.0.5' => '004', |
|
| 501 | + '1.0.3' => '102', |
|
| 502 | + '2.0.0' => '118', |
|
| 503 | + '2.0.8' => '207', |
|
| 504 | + ); |
|
| 505 | 505 | |
| 506 | - foreach ( $upgrades as $key => $method ) { |
|
| 506 | + foreach ( $upgrades as $key => $method ) { |
|
| 507 | 507 | |
| 508 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 509 | - return $installer->upgrade_db( $method ); |
|
| 510 | - } |
|
| 508 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 509 | + return $installer->upgrade_db( $method ); |
|
| 510 | + } |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Flushes the permalinks if needed. |
|
| 517 | - * |
|
| 518 | - * @since 2.0.8 |
|
| 519 | - */ |
|
| 520 | - public function maybe_flush_permalinks() { |
|
| 521 | - |
|
| 522 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 523 | - |
|
| 524 | - if ( ! empty( $flush ) ) { |
|
| 525 | - flush_rewrite_rules(); |
|
| 526 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Remove our pages from yoast sitemaps. |
|
| 533 | - * |
|
| 534 | - * @since 1.0.19 |
|
| 535 | - * @param int[] $excluded_posts_ids |
|
| 536 | - */ |
|
| 537 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 538 | - |
|
| 539 | - // Ensure that we have an array. |
|
| 540 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 541 | - $excluded_posts_ids = array(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // Prepare our pages. |
|
| 545 | - $our_pages = array(); |
|
| 546 | - |
|
| 547 | - // Checkout page. |
|
| 548 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 549 | - |
|
| 550 | - // Success page. |
|
| 551 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 552 | - |
|
| 553 | - // Failure page. |
|
| 554 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 555 | - |
|
| 556 | - // History page. |
|
| 557 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 558 | - |
|
| 559 | - // Subscriptions page. |
|
| 560 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 561 | - |
|
| 562 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 563 | - |
|
| 564 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 565 | - return array_unique( $excluded_posts_ids ); |
|
| 566 | - |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Displays additional footer code. |
|
| 571 | - * |
|
| 572 | - * @since 2.0.0 |
|
| 573 | - */ |
|
| 574 | - public function wp_footer() { |
|
| 575 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Displays additional header code. |
|
| 580 | - * |
|
| 581 | - * @since 2.0.0 |
|
| 582 | - */ |
|
| 583 | - public function wp_head() { |
|
| 584 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Custom query vars. |
|
| 589 | - * |
|
| 590 | - */ |
|
| 591 | - public function custom_query_vars( $vars ) { |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Flushes the permalinks if needed. |
|
| 517 | + * |
|
| 518 | + * @since 2.0.8 |
|
| 519 | + */ |
|
| 520 | + public function maybe_flush_permalinks() { |
|
| 521 | + |
|
| 522 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 523 | + |
|
| 524 | + if ( ! empty( $flush ) ) { |
|
| 525 | + flush_rewrite_rules(); |
|
| 526 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Remove our pages from yoast sitemaps. |
|
| 533 | + * |
|
| 534 | + * @since 1.0.19 |
|
| 535 | + * @param int[] $excluded_posts_ids |
|
| 536 | + */ |
|
| 537 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 538 | + |
|
| 539 | + // Ensure that we have an array. |
|
| 540 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 541 | + $excluded_posts_ids = array(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // Prepare our pages. |
|
| 545 | + $our_pages = array(); |
|
| 546 | + |
|
| 547 | + // Checkout page. |
|
| 548 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 549 | + |
|
| 550 | + // Success page. |
|
| 551 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 552 | + |
|
| 553 | + // Failure page. |
|
| 554 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 555 | + |
|
| 556 | + // History page. |
|
| 557 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 558 | + |
|
| 559 | + // Subscriptions page. |
|
| 560 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 561 | + |
|
| 562 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 563 | + |
|
| 564 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 565 | + return array_unique( $excluded_posts_ids ); |
|
| 566 | + |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Displays additional footer code. |
|
| 571 | + * |
|
| 572 | + * @since 2.0.0 |
|
| 573 | + */ |
|
| 574 | + public function wp_footer() { |
|
| 575 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Displays additional header code. |
|
| 580 | + * |
|
| 581 | + * @since 2.0.0 |
|
| 582 | + */ |
|
| 583 | + public function wp_head() { |
|
| 584 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Custom query vars. |
|
| 589 | + * |
|
| 590 | + */ |
|
| 591 | + public function custom_query_vars( $vars ) { |
|
| 592 | 592 | $vars[] = 'getpaid-ipn'; |
| 593 | 593 | return $vars; |
| 594 | - } |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - /** |
|
| 597 | - * Add rewrite tags and rules. |
|
| 598 | - * |
|
| 599 | - */ |
|
| 600 | - public function add_rewrite_rule() { |
|
| 596 | + /** |
|
| 597 | + * Add rewrite tags and rules. |
|
| 598 | + * |
|
| 599 | + */ |
|
| 600 | + public function add_rewrite_rule() { |
|
| 601 | 601 | $tag = 'getpaid-ipn'; |
| 602 | 602 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
| 603 | 603 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
| 604 | - } |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | - /** |
|
| 607 | - * Processes non-query string ipns. |
|
| 608 | - * |
|
| 609 | - */ |
|
| 610 | - public function maybe_process_new_ipn( $query ) { |
|
| 606 | + /** |
|
| 607 | + * Processes non-query string ipns. |
|
| 608 | + * |
|
| 609 | + */ |
|
| 610 | + public function maybe_process_new_ipn( $query ) { |
|
| 611 | 611 | |
| 612 | 612 | if ( is_admin() || ! $query->is_main_query() ) { |
| 613 | 613 | return; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 616 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 617 | 617 | |
| 618 | 618 | if ( ! empty( $gateway ) ) { |
| 619 | 619 | |
| 620 | - $gateway = sanitize_text_field( $gateway ); |
|
| 621 | - nocache_headers(); |
|
| 622 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 623 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 624 | - exit; |
|
| 620 | + $gateway = sanitize_text_field( $gateway ); |
|
| 621 | + nocache_headers(); |
|
| 622 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 623 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 624 | + exit; |
|
| 625 | 625 | |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - } |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | 630 | } |
@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | function wpinv_can_checkout() { |
| 34 | - $can_checkout = true; // Always true for now |
|
| 34 | + $can_checkout = true; // Always true for now |
|
| 35 | 35 | |
| 36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 36 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | function wpinv_get_success_page_uri() { |
| 40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 41 | - $page_id = absint( $page_id ); |
|
| 40 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 41 | + $page_id = absint( $page_id ); |
|
| 42 | 42 | |
| 43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 43 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -51,22 +51,22 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
| 53 | 53 | $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
| 54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
| 55 | - $page_id = absint( $page_id ); |
|
| 56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
| 54 | + $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
| 55 | + $page_id = absint( $page_id ); |
|
| 56 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function wpinv_is_success_page() { |
| 60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 60 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 61 | + $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 62 | 62 | |
| 63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 63 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function wpinv_is_invoice_history_page() { |
| 67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 68 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 67 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 68 | + $ret = $ret ? is_page( $ret ) : false; |
|
| 69 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function wpinv_is_subscriptions_history_page() { |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | function wpinv_send_to_failed_page( $args = null ) { |
| 95 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
| 95 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
| 96 | 96 | |
| 97 | 97 | if ( ! empty( $args ) ) { |
| 98 | 98 | // Check for backward compatibility |
@@ -113,58 +113,58 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | function wpinv_get_checkout_uri( $args = array() ) { |
| 116 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 117 | - $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
| 116 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 117 | + $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
| 118 | 118 | |
| 119 | - if ( ! empty( $args ) ) { |
|
| 120 | - // Check for backward compatibility |
|
| 121 | - if ( is_string( $args ) ) { |
|
| 122 | - $args = str_replace( '?', '', $args ); |
|
| 119 | + if ( ! empty( $args ) ) { |
|
| 120 | + // Check for backward compatibility |
|
| 121 | + if ( is_string( $args ) ) { |
|
| 122 | + $args = str_replace( '?', '', $args ); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $args = wp_parse_args( $args ); |
|
| 125 | + $args = wp_parse_args( $args ); |
|
| 126 | 126 | |
| 127 | - $uri = add_query_arg( $args, $uri ); |
|
| 128 | - } |
|
| 127 | + $uri = add_query_arg( $args, $uri ); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 130 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 131 | 131 | |
| 132 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 132 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 133 | 133 | |
| 134 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 135 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 136 | - } |
|
| 134 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 135 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 138 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function wpinv_get_success_page_url( $query_string = null ) { |
| 142 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 143 | - $success_page = get_permalink( $success_page ); |
|
| 142 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 143 | + $success_page = get_permalink( $success_page ); |
|
| 144 | 144 | |
| 145 | - if ( $query_string ) { |
|
| 146 | - $success_page .= $query_string; |
|
| 145 | + if ( $query_string ) { |
|
| 146 | + $success_page .= $query_string; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 149 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
| 153 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 154 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 153 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 154 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 155 | 155 | |
| 156 | - if ( $extras ) { |
|
| 157 | - $uri .= $extras; |
|
| 156 | + if ( $extras ) { |
|
| 157 | + $uri .= $extras; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 160 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function wpinv_is_failed_transaction_page() { |
| 164 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
| 165 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 164 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
| 165 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 166 | 166 | |
| 167 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 167 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -244,36 +244,36 @@ discard block |
||
| 244 | 244 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
| 245 | 245 | |
| 246 | 246 | if ( $require_billing_details ) { |
| 247 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
| 248 | - $required_fields['first_name'] = array( |
|
| 249 | - 'error_id' => 'invalid_first_name', |
|
| 250 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
| 251 | - ); |
|
| 252 | - } |
|
| 253 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
| 254 | - $required_fields['address'] = array( |
|
| 255 | - 'error_id' => 'invalid_address', |
|
| 256 | - 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
| 257 | - ); |
|
| 258 | - } |
|
| 259 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
| 260 | - $required_fields['city'] = array( |
|
| 261 | - 'error_id' => 'invalid_city', |
|
| 262 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
| 266 | - $required_fields['state'] = array( |
|
| 267 | - 'error_id' => 'invalid_state', |
|
| 268 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
| 272 | - $required_fields['country'] = array( |
|
| 273 | - 'error_id' => 'invalid_country', |
|
| 274 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
| 275 | - ); |
|
| 276 | - } |
|
| 247 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
| 248 | + $required_fields['first_name'] = array( |
|
| 249 | + 'error_id' => 'invalid_first_name', |
|
| 250 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
| 251 | + ); |
|
| 252 | + } |
|
| 253 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
| 254 | + $required_fields['address'] = array( |
|
| 255 | + 'error_id' => 'invalid_address', |
|
| 256 | + 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
| 257 | + ); |
|
| 258 | + } |
|
| 259 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
| 260 | + $required_fields['city'] = array( |
|
| 261 | + 'error_id' => 'invalid_city', |
|
| 262 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
| 266 | + $required_fields['state'] = array( |
|
| 267 | + 'error_id' => 'invalid_state', |
|
| 268 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
| 272 | + $required_fields['country'] = array( |
|
| 273 | + 'error_id' => 'invalid_country', |
|
| 274 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -160,50 +160,50 @@ |
||
| 160 | 160 | */ |
| 161 | 161 | function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
| 162 | 162 | |
| 163 | - $initial_discount = 0; |
|
| 164 | - $recurring_discount = 0; |
|
| 163 | + $initial_discount = 0; |
|
| 164 | + $recurring_discount = 0; |
|
| 165 | 165 | |
| 166 | - foreach ( $invoice->get_items() as $item ) { |
|
| 166 | + foreach ( $invoice->get_items() as $item ) { |
|
| 167 | 167 | |
| 168 | - // Abort if it is not valid for this item. |
|
| 169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 170 | - continue; |
|
| 171 | - } |
|
| 168 | + // Abort if it is not valid for this item. |
|
| 169 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 170 | + continue; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - // Calculate the initial amount... |
|
| 174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 175 | - $recurring_item_discount = 0; |
|
| 173 | + // Calculate the initial amount... |
|
| 174 | + $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 175 | + $recurring_item_discount = 0; |
|
| 176 | 176 | |
| 177 | - // ... and maybe the recurring amount. |
|
| 178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 180 | - } |
|
| 177 | + // ... and maybe the recurring amount. |
|
| 178 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | + $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - // Discount should not exceed discounted amount. |
|
| 183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
| 182 | + // Discount should not exceed discounted amount. |
|
| 183 | + if ( ! $discount->is_type( 'percent' ) ) { |
|
| 184 | 184 | |
| 185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 186 | - $item_discount = $discount->get_amount() - $initial_discount; |
|
| 187 | - } |
|
| 185 | + if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 186 | + $item_discount = $discount->get_amount() - $initial_discount; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 190 | - $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
| 191 | - } |
|
| 189 | + if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 190 | + $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
| 191 | + } |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $initial_discount += $item_discount; |
|
| 195 | - $recurring_discount += $recurring_item_discount; |
|
| 196 | - $item->item_discount = $item_discount; |
|
| 197 | - $item->recurring_item_discount = $recurring_item_discount; |
|
| 194 | + $initial_discount += $item_discount; |
|
| 195 | + $recurring_discount += $recurring_item_discount; |
|
| 196 | + $item->item_discount = $item_discount; |
|
| 197 | + $item->recurring_item_discount = $recurring_item_discount; |
|
| 198 | 198 | |
| 199 | - } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return array( |
|
| 202 | - 'name' => 'discount_code', |
|
| 203 | - 'discount_code' => $discount->get_code(), |
|
| 204 | - 'initial_discount' => $initial_discount, |
|
| 205 | - 'recurring_discount' => $recurring_discount, |
|
| 206 | - ); |
|
| 201 | + return array( |
|
| 202 | + 'name' => 'discount_code', |
|
| 203 | + 'discount_code' => $discount->get_code(), |
|
| 204 | + 'initial_discount' => $initial_discount, |
|
| 205 | + 'recurring_discount' => $recurring_discount, |
|
| 206 | + ); |
|
| 207 | 207 | |
| 208 | 208 | } |
| 209 | 209 | |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | $css = getpaid_get_email_css(); |
| 110 | 110 | |
| 111 | 111 | // include css inliner |
| 112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | - include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 112 | + if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | + include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Inline the css. |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $message = wpinv_email_style_body( $message ); |
| 190 | 190 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
| 191 | 191 | |
| 192 | - return $mailer->send( |
|
| 192 | + return $mailer->send( |
|
| 193 | 193 | $to, |
| 194 | 194 | $subject, |
| 195 | 195 | $message, |
@@ -12,207 +12,207 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Notes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - */ |
|
| 18 | - public function __construct() { |
|
| 19 | - |
|
| 20 | - // Filter inovice notes. |
|
| 21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | - |
|
| 24 | - // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | - |
|
| 28 | - // Count comments. |
|
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | - |
|
| 31 | - // Fires after notes are loaded. |
|
| 32 | - do_action( 'wpinv_notes_init', $this ); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Filters invoice notes query to only include our notes. |
|
| 37 | - * |
|
| 38 | - * @param WP_Comment_Query $query |
|
| 39 | - */ |
|
| 40 | - public function set_invoice_note_type( $query ) { |
|
| 41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | - |
|
| 43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | - $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | - } else { |
|
| 46 | - |
|
| 47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | - $query->query_vars['type__not_in'] = array(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $query; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Exclude notes from the comments feed. |
|
| 60 | - */ |
|
| 61 | - function wpinv_comment_feed_where( $where ) { |
|
| 62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Delete comments count cache whenever there is |
|
| 67 | - * new comment or the status of a comment changes. Cache |
|
| 68 | - * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | - * is called. |
|
| 70 | - */ |
|
| 71 | - public function delete_comments_count_cache() { |
|
| 72 | - delete_transient( 'getpaid_count_comments' ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Remove invoice notes from wp_count_comments(). |
|
| 77 | - * |
|
| 78 | - * @since 2.2 |
|
| 79 | - * @param object $stats Comment stats. |
|
| 80 | - * @param int $post_id Post ID. |
|
| 81 | - * @return object |
|
| 82 | - */ |
|
| 83 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | - global $wpdb; |
|
| 85 | - |
|
| 86 | - if ( empty( $post_id ) ) { |
|
| 87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | - |
|
| 89 | - if ( ! $stats ) { |
|
| 90 | - $stats = array( |
|
| 91 | - 'total_comments' => 0, |
|
| 92 | - 'all' => 0, |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $count = $wpdb->get_results( |
|
| 96 | - " |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + */ |
|
| 18 | + public function __construct() { |
|
| 19 | + |
|
| 20 | + // Filter inovice notes. |
|
| 21 | + add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | + add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | + |
|
| 24 | + // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | + add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | + add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | + |
|
| 28 | + // Count comments. |
|
| 29 | + add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | + |
|
| 31 | + // Fires after notes are loaded. |
|
| 32 | + do_action( 'wpinv_notes_init', $this ); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Filters invoice notes query to only include our notes. |
|
| 37 | + * |
|
| 38 | + * @param WP_Comment_Query $query |
|
| 39 | + */ |
|
| 40 | + public function set_invoice_note_type( $query ) { |
|
| 41 | + $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | + |
|
| 43 | + if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | + $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | + } else { |
|
| 46 | + |
|
| 47 | + if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | + $query->query_vars['type__not_in'] = array(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | + $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $query; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Exclude notes from the comments feed. |
|
| 60 | + */ |
|
| 61 | + function wpinv_comment_feed_where( $where ) { |
|
| 62 | + return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Delete comments count cache whenever there is |
|
| 67 | + * new comment or the status of a comment changes. Cache |
|
| 68 | + * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | + * is called. |
|
| 70 | + */ |
|
| 71 | + public function delete_comments_count_cache() { |
|
| 72 | + delete_transient( 'getpaid_count_comments' ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Remove invoice notes from wp_count_comments(). |
|
| 77 | + * |
|
| 78 | + * @since 2.2 |
|
| 79 | + * @param object $stats Comment stats. |
|
| 80 | + * @param int $post_id Post ID. |
|
| 81 | + * @return object |
|
| 82 | + */ |
|
| 83 | + public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | + global $wpdb; |
|
| 85 | + |
|
| 86 | + if ( empty( $post_id ) ) { |
|
| 87 | + $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | + |
|
| 89 | + if ( ! $stats ) { |
|
| 90 | + $stats = array( |
|
| 91 | + 'total_comments' => 0, |
|
| 92 | + 'all' => 0, |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $count = $wpdb->get_results( |
|
| 96 | + " |
|
| 97 | 97 | SELECT comment_approved, COUNT(*) AS num_comments |
| 98 | 98 | FROM {$wpdb->comments} |
| 99 | 99 | WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note') |
| 100 | 100 | GROUP BY comment_approved |
| 101 | 101 | ", |
| 102 | - ARRAY_A |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $approved = array( |
|
| 106 | - '0' => 'moderated', |
|
| 107 | - '1' => 'approved', |
|
| 108 | - 'spam' => 'spam', |
|
| 109 | - 'trash' => 'trash', |
|
| 110 | - 'post-trashed' => 'post-trashed', |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - foreach ( (array) $count as $row ) { |
|
| 114 | - // Don't count post-trashed toward totals. |
|
| 115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | - $stats['all'] += $row['num_comments']; |
|
| 117 | - $stats['total_comments'] += $row['num_comments']; |
|
| 118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | - $stats['total_comments'] += $row['num_comments']; |
|
| 120 | - } |
|
| 121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - foreach ( $approved as $key ) { |
|
| 127 | - if ( empty( $stats[ $key ] ) ) { |
|
| 128 | - $stats[ $key ] = 0; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $stats = (object) $stats; |
|
| 133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | - } |
|
| 102 | + ARRAY_A |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $approved = array( |
|
| 106 | + '0' => 'moderated', |
|
| 107 | + '1' => 'approved', |
|
| 108 | + 'spam' => 'spam', |
|
| 109 | + 'trash' => 'trash', |
|
| 110 | + 'post-trashed' => 'post-trashed', |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + foreach ( (array) $count as $row ) { |
|
| 114 | + // Don't count post-trashed toward totals. |
|
| 115 | + if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | + $stats['all'] += $row['num_comments']; |
|
| 117 | + $stats['total_comments'] += $row['num_comments']; |
|
| 118 | + } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | + $stats['total_comments'] += $row['num_comments']; |
|
| 120 | + } |
|
| 121 | + if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | + $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + foreach ( $approved as $key ) { |
|
| 127 | + if ( empty( $stats[ $key ] ) ) { |
|
| 128 | + $stats[ $key ] = 0; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $stats = (object) $stats; |
|
| 133 | + set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return $stats; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns an array of invoice notes. |
|
| 142 | - * |
|
| 143 | - * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | - * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | - * @return WP_Comment[] |
|
| 146 | - */ |
|
| 147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | - |
|
| 149 | - // Default comment args. |
|
| 150 | - $args = array( |
|
| 151 | - 'post_id' => $invoice_id, |
|
| 152 | - 'orderby' => 'comment_ID', |
|
| 153 | - 'order' => 'ASC', |
|
| 154 | - ); |
|
| 155 | - |
|
| 156 | - // Maybe only show customer comments. |
|
| 157 | - if ( $type == 'customer' ) { |
|
| 158 | - $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | - $args['meta_value'] = 1; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | - |
|
| 164 | - return get_comments( $args ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Saves an invoice comment. |
|
| 169 | - * |
|
| 170 | - * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | - * @param string $note The note content. |
|
| 172 | - * @param string $note_author The name of the author of the note. |
|
| 173 | - * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | - * @return int|false The new note's ID on success, false on failure. |
|
| 175 | - */ |
|
| 176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | - |
|
| 178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Insert the comment. |
|
| 182 | - */ |
|
| 183 | - $note_id = wp_insert_comment( |
|
| 184 | - wp_filter_comment( |
|
| 185 | - array( |
|
| 186 | - 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | - 'comment_content' => $note, |
|
| 188 | - 'comment_agent' => 'Invoicing', |
|
| 189 | - 'user_id' => get_current_user_id(), |
|
| 190 | - 'comment_author' => $note_author, |
|
| 191 | - 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | - 'comment_author_email' => $author_email, |
|
| 193 | - 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | - 'comment_type' => 'wpinv_note', |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - |
|
| 199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | - |
|
| 201 | - // Are we notifying the customer? |
|
| 202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | - return $note_id; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | - do_action( |
|
| 137 | + return $stats; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns an array of invoice notes. |
|
| 142 | + * |
|
| 143 | + * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | + * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | + * @return WP_Comment[] |
|
| 146 | + */ |
|
| 147 | + public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | + |
|
| 149 | + // Default comment args. |
|
| 150 | + $args = array( |
|
| 151 | + 'post_id' => $invoice_id, |
|
| 152 | + 'orderby' => 'comment_ID', |
|
| 153 | + 'order' => 'ASC', |
|
| 154 | + ); |
|
| 155 | + |
|
| 156 | + // Maybe only show customer comments. |
|
| 157 | + if ( $type == 'customer' ) { |
|
| 158 | + $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | + $args['meta_value'] = 1; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | + |
|
| 164 | + return get_comments( $args ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Saves an invoice comment. |
|
| 169 | + * |
|
| 170 | + * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | + * @param string $note The note content. |
|
| 172 | + * @param string $note_author The name of the author of the note. |
|
| 173 | + * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | + * @return int|false The new note's ID on success, false on failure. |
|
| 175 | + */ |
|
| 176 | + function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | + |
|
| 178 | + do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Insert the comment. |
|
| 182 | + */ |
|
| 183 | + $note_id = wp_insert_comment( |
|
| 184 | + wp_filter_comment( |
|
| 185 | + array( |
|
| 186 | + 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | + 'comment_content' => $note, |
|
| 188 | + 'comment_agent' => 'Invoicing', |
|
| 189 | + 'user_id' => get_current_user_id(), |
|
| 190 | + 'comment_author' => $note_author, |
|
| 191 | + 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | + 'comment_author_email' => $author_email, |
|
| 193 | + 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | + 'comment_type' => 'wpinv_note', |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + |
|
| 199 | + do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | + |
|
| 201 | + // Are we notifying the customer? |
|
| 202 | + if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | + return $note_id; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | + do_action( |
|
| 208 | 208 | 'wpinv_new_customer_note', |
| 209 | 209 | array( |
| 210 | - 'invoice_id' => $invoice->get_id(), |
|
| 211 | - 'user_note' => $note, |
|
| 210 | + 'invoice_id' => $invoice->get_id(), |
|
| 211 | + 'user_note' => $note, |
|
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | - return $note_id; |
|
| 216 | - } |
|
| 214 | + do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | + return $note_id; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | } |