@@ -13,450 +13,450 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GetPaid_Payment_Gateway { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Set if the place checkout button should be renamed on selection. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $checkout_button_text; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Boolean whether the method is enabled. |
|
| 25 | - * |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - public $enabled = true; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Payment method id. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Payment method order. |
|
| 39 | - * |
|
| 40 | - * @var int |
|
| 41 | - */ |
|
| 42 | - public $order = 10; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Payment method title for the frontend. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - public $title; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Payment method description for the frontend. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - public $description; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Gateway title. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $method_title = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gateway description. |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $method_description = ''; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Countries this gateway is allowed for. |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - public $countries; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Currencies this gateway is allowed for. |
|
| 81 | - * |
|
| 82 | - * @var array |
|
| 83 | - */ |
|
| 84 | - public $currencies; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Currencies this gateway is not allowed for. |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - public $exclude_currencies; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | - * |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - public $max_amount = 0; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Optional URL to view a transaction. |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $view_transaction_url = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Optional URL to view a subscription. |
|
| 109 | - * |
|
| 110 | - * @var string |
|
| 111 | - */ |
|
| 112 | - public $view_subscription_url = ''; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Optional label to show for "new payment method" in the payment |
|
| 116 | - * method/token selection radio selection. |
|
| 117 | - * |
|
| 118 | - * @var string |
|
| 119 | - */ |
|
| 120 | - public $new_method_label = ''; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Contains a user's saved tokens for this gateway. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - protected $tokens = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * An array of features that this gateway supports. |
|
| 131 | - * |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - protected $supports = array(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Class constructor. |
|
| 138 | - */ |
|
| 139 | - public function __construct() { |
|
| 140 | - |
|
| 141 | - // Register gateway. |
|
| 142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | - |
|
| 144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | - |
|
| 146 | - // Enable Subscriptions. |
|
| 147 | - if ( $this->supports( 'subscription' ) ) { |
|
| 148 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Enable sandbox. |
|
| 152 | - if ( $this->supports( 'sandbox' ) ) { |
|
| 153 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // Gateway settings. |
|
| 157 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 16 | + /** |
|
| 17 | + * Set if the place checkout button should be renamed on selection. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $checkout_button_text; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Boolean whether the method is enabled. |
|
| 25 | + * |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + public $enabled = true; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Payment method id. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Payment method order. |
|
| 39 | + * |
|
| 40 | + * @var int |
|
| 41 | + */ |
|
| 42 | + public $order = 10; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Payment method title for the frontend. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + public $title; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Payment method description for the frontend. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + public $description; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Gateway title. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $method_title = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gateway description. |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $method_description = ''; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Countries this gateway is allowed for. |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + public $countries; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Currencies this gateway is allowed for. |
|
| 81 | + * |
|
| 82 | + * @var array |
|
| 83 | + */ |
|
| 84 | + public $currencies; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Currencies this gateway is not allowed for. |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + public $exclude_currencies; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | + * |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + public $max_amount = 0; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Optional URL to view a transaction. |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $view_transaction_url = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Optional URL to view a subscription. |
|
| 109 | + * |
|
| 110 | + * @var string |
|
| 111 | + */ |
|
| 112 | + public $view_subscription_url = ''; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Optional label to show for "new payment method" in the payment |
|
| 116 | + * method/token selection radio selection. |
|
| 117 | + * |
|
| 118 | + * @var string |
|
| 119 | + */ |
|
| 120 | + public $new_method_label = ''; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Contains a user's saved tokens for this gateway. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + protected $tokens = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * An array of features that this gateway supports. |
|
| 131 | + * |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + protected $supports = array(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Class constructor. |
|
| 138 | + */ |
|
| 139 | + public function __construct() { |
|
| 140 | + |
|
| 141 | + // Register gateway. |
|
| 142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | + |
|
| 144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | + |
|
| 146 | + // Enable Subscriptions. |
|
| 147 | + if ( $this->supports( 'subscription' ) ) { |
|
| 148 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Enable sandbox. |
|
| 152 | + if ( $this->supports( 'sandbox' ) ) { |
|
| 153 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // Gateway settings. |
|
| 157 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - // Gateway checkout fiellds. |
|
| 161 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 162 | - |
|
| 163 | - // Process payment. |
|
| 164 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 160 | + // Gateway checkout fiellds. |
|
| 161 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 162 | + |
|
| 163 | + // Process payment. |
|
| 164 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 165 | + |
|
| 166 | + // Change the checkout button text. |
|
| 167 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
| 168 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // Check if a gateway is valid for a given currency. |
|
| 172 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 173 | + |
|
| 174 | + // Generate the transaction url. |
|
| 175 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 176 | + |
|
| 177 | + // Generate the subscription url. |
|
| 178 | + add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
| 179 | + |
|
| 180 | + // Confirm payments. |
|
| 181 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 182 | + |
|
| 183 | + // Verify IPNs. |
|
| 184 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 185 | + |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Checks if this gateway is a given gateway. |
|
| 190 | + * |
|
| 191 | + * @since 1.0.19 |
|
| 192 | + * @return bool |
|
| 193 | + */ |
|
| 194 | + public function is( $gateway ) { |
|
| 195 | + return $gateway == $this->id; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Returns a users saved tokens for this gateway. |
|
| 200 | + * |
|
| 201 | + * @since 1.0.19 |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + public function get_tokens( $sandbox = null ) { |
|
| 205 | + |
|
| 206 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 207 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 208 | + |
|
| 209 | + if ( is_array( $tokens ) ) { |
|
| 210 | + $this->tokens = $tokens; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + if ( ! is_bool( $sandbox ) ) { |
|
| 216 | + return $this->tokens; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 220 | + return wp_list_filter( $this->tokens, $args ); |
|
| 221 | + |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Saves a token for this gateway. |
|
| 226 | + * |
|
| 227 | + * @since 1.0.19 |
|
| 228 | + */ |
|
| 229 | + public function save_token( $token ) { |
|
| 230 | + |
|
| 231 | + $tokens = $this->get_tokens(); |
|
| 232 | + $tokens[] = $token; |
|
| 233 | + |
|
| 234 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 235 | + |
|
| 236 | + $this->tokens = $tokens; |
|
| 237 | + |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Return the title for admin screens. |
|
| 242 | + * |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function get_method_title() { |
|
| 246 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Return the description for admin screens. |
|
| 251 | + * |
|
| 252 | + * @return string |
|
| 253 | + */ |
|
| 254 | + public function get_method_description() { |
|
| 255 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Get the success url. |
|
| 260 | + * |
|
| 261 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + public function get_return_url( $invoice ) { |
|
| 265 | + |
|
| 266 | + // Payment success url |
|
| 267 | + $return_url = add_query_arg( |
|
| 268 | + array( |
|
| 269 | + 'payment-confirm' => $this->id, |
|
| 270 | + 'invoice_key' => $invoice->get_key(), |
|
| 271 | + 'utm_nooverride' => 1 |
|
| 272 | + ), |
|
| 273 | + wpinv_get_success_page_uri() |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Confirms payments when rendering the success page. |
|
| 281 | + * |
|
| 282 | + * @param string $content Success page content. |
|
| 283 | + * @return string |
|
| 284 | + */ |
|
| 285 | + public function confirm_payment( $content ) { |
|
| 286 | + |
|
| 287 | + // Retrieve the invoice. |
|
| 288 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
| 289 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 290 | + |
|
| 291 | + // Ensure that it exists and that it is pending payment. |
|
| 292 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 293 | + return $content; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + // Can the user view this invoice?? |
|
| 297 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 298 | + return $content; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + // Show payment processing indicator. |
|
| 302 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Processes ipns and marks payments as complete. |
|
| 307 | + * |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + public function verify_ipn() {} |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 314 | + * |
|
| 315 | + * @param string $transaction_url transaction url. |
|
| 316 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 317 | + * @return string transaction URL, or empty string. |
|
| 318 | + */ |
|
| 319 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 320 | + |
|
| 321 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 322 | + |
|
| 323 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 324 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 325 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 326 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return $transaction_url; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 334 | + * |
|
| 335 | + * @param string $subscription_url transaction url. |
|
| 336 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 337 | + * @return string subscription URL, or empty string. |
|
| 338 | + */ |
|
| 339 | + public function filter_subscription_url( $subscription_url, $invoice ) { |
|
| 340 | + |
|
| 341 | + $profile_id = $invoice->get_subscription_id(); |
|
| 342 | + |
|
| 343 | + if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 344 | + |
|
| 345 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 346 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 347 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 348 | + |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return $subscription_url; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Check if the gateway is available for use. |
|
| 356 | + * |
|
| 357 | + * @return bool |
|
| 358 | + */ |
|
| 359 | + public function is_available() { |
|
| 360 | + return ! empty( $this->enabled ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Return the gateway's title. |
|
| 365 | + * |
|
| 366 | + * @return string |
|
| 367 | + */ |
|
| 368 | + public function get_title() { |
|
| 369 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Return the gateway's description. |
|
| 374 | + * |
|
| 375 | + * @return string |
|
| 376 | + */ |
|
| 377 | + public function get_description() { |
|
| 378 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Process Payment. |
|
| 383 | + * |
|
| 384 | + * |
|
| 385 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 386 | + * @param array $submission_data Posted checkout fields. |
|
| 387 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 388 | + * @return void |
|
| 389 | + */ |
|
| 390 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 391 | + // Process the payment then either redirect to the success page or the gateway. |
|
| 392 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Process refund. |
|
| 397 | + * |
|
| 398 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 399 | + * a passed in amount. |
|
| 400 | + * |
|
| 401 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 402 | + * @param float $amount Refund amount. |
|
| 403 | + * @param string $reason Refund reason. |
|
| 404 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 405 | + */ |
|
| 406 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 407 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Displays the payment fields, credit cards etc. |
|
| 412 | + * |
|
| 413 | + * @param int $invoice_id 0 or invoice id. |
|
| 414 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 415 | + */ |
|
| 416 | + public function payment_fields( $invoice_id, $form ) { |
|
| 417 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * Filters the gateway settings. |
|
| 422 | + * |
|
| 423 | + * @param array $admin_settings |
|
| 424 | + */ |
|
| 425 | + public function admin_settings( $admin_settings ) { |
|
| 426 | + return $admin_settings; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Retrieves the value of a gateway setting. |
|
| 431 | + * |
|
| 432 | + * @param string $option |
|
| 433 | + */ |
|
| 434 | + public function get_option( $option, $default = false ) { |
|
| 435 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Check if a gateway supports a given feature. |
|
| 440 | + * |
|
| 441 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 442 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 443 | + * |
|
| 444 | + * @param string $feature string The name of a feature to test support for. |
|
| 445 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
| 446 | + * @since 1.0.19 |
|
| 447 | + */ |
|
| 448 | + public function supports( $feature ) { |
|
| 449 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 450 | + } |
|
| 165 | 451 | |
| 166 | - // Change the checkout button text. |
|
| 167 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 168 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // Check if a gateway is valid for a given currency. |
|
| 172 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 173 | - |
|
| 174 | - // Generate the transaction url. |
|
| 175 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 176 | - |
|
| 177 | - // Generate the subscription url. |
|
| 178 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
| 179 | - |
|
| 180 | - // Confirm payments. |
|
| 181 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 182 | - |
|
| 183 | - // Verify IPNs. |
|
| 184 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 185 | - |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Checks if this gateway is a given gateway. |
|
| 190 | - * |
|
| 191 | - * @since 1.0.19 |
|
| 192 | - * @return bool |
|
| 193 | - */ |
|
| 194 | - public function is( $gateway ) { |
|
| 195 | - return $gateway == $this->id; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Returns a users saved tokens for this gateway. |
|
| 200 | - * |
|
| 201 | - * @since 1.0.19 |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - public function get_tokens( $sandbox = null ) { |
|
| 205 | - |
|
| 206 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 207 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 208 | - |
|
| 209 | - if ( is_array( $tokens ) ) { |
|
| 210 | - $this->tokens = $tokens; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - if ( ! is_bool( $sandbox ) ) { |
|
| 216 | - return $this->tokens; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 220 | - return wp_list_filter( $this->tokens, $args ); |
|
| 221 | - |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Saves a token for this gateway. |
|
| 226 | - * |
|
| 227 | - * @since 1.0.19 |
|
| 228 | - */ |
|
| 229 | - public function save_token( $token ) { |
|
| 230 | - |
|
| 231 | - $tokens = $this->get_tokens(); |
|
| 232 | - $tokens[] = $token; |
|
| 233 | - |
|
| 234 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 235 | - |
|
| 236 | - $this->tokens = $tokens; |
|
| 237 | - |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Return the title for admin screens. |
|
| 242 | - * |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function get_method_title() { |
|
| 246 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Return the description for admin screens. |
|
| 251 | - * |
|
| 252 | - * @return string |
|
| 253 | - */ |
|
| 254 | - public function get_method_description() { |
|
| 255 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Get the success url. |
|
| 260 | - * |
|
| 261 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - public function get_return_url( $invoice ) { |
|
| 265 | - |
|
| 266 | - // Payment success url |
|
| 267 | - $return_url = add_query_arg( |
|
| 268 | - array( |
|
| 269 | - 'payment-confirm' => $this->id, |
|
| 270 | - 'invoice_key' => $invoice->get_key(), |
|
| 271 | - 'utm_nooverride' => 1 |
|
| 272 | - ), |
|
| 273 | - wpinv_get_success_page_uri() |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Confirms payments when rendering the success page. |
|
| 281 | - * |
|
| 282 | - * @param string $content Success page content. |
|
| 283 | - * @return string |
|
| 284 | - */ |
|
| 285 | - public function confirm_payment( $content ) { |
|
| 286 | - |
|
| 287 | - // Retrieve the invoice. |
|
| 288 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
| 289 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 290 | - |
|
| 291 | - // Ensure that it exists and that it is pending payment. |
|
| 292 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 293 | - return $content; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - // Can the user view this invoice?? |
|
| 297 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 298 | - return $content; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - // Show payment processing indicator. |
|
| 302 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Processes ipns and marks payments as complete. |
|
| 307 | - * |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - public function verify_ipn() {} |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 314 | - * |
|
| 315 | - * @param string $transaction_url transaction url. |
|
| 316 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 317 | - * @return string transaction URL, or empty string. |
|
| 318 | - */ |
|
| 319 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 320 | - |
|
| 321 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 322 | - |
|
| 323 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 324 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 325 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 326 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return $transaction_url; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 334 | - * |
|
| 335 | - * @param string $subscription_url transaction url. |
|
| 336 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 337 | - * @return string subscription URL, or empty string. |
|
| 338 | - */ |
|
| 339 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
| 340 | - |
|
| 341 | - $profile_id = $invoice->get_subscription_id(); |
|
| 342 | - |
|
| 343 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 344 | - |
|
| 345 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 346 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 347 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 348 | - |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return $subscription_url; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Check if the gateway is available for use. |
|
| 356 | - * |
|
| 357 | - * @return bool |
|
| 358 | - */ |
|
| 359 | - public function is_available() { |
|
| 360 | - return ! empty( $this->enabled ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Return the gateway's title. |
|
| 365 | - * |
|
| 366 | - * @return string |
|
| 367 | - */ |
|
| 368 | - public function get_title() { |
|
| 369 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Return the gateway's description. |
|
| 374 | - * |
|
| 375 | - * @return string |
|
| 376 | - */ |
|
| 377 | - public function get_description() { |
|
| 378 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Process Payment. |
|
| 383 | - * |
|
| 384 | - * |
|
| 385 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 386 | - * @param array $submission_data Posted checkout fields. |
|
| 387 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 388 | - * @return void |
|
| 389 | - */ |
|
| 390 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 391 | - // Process the payment then either redirect to the success page or the gateway. |
|
| 392 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Process refund. |
|
| 397 | - * |
|
| 398 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 399 | - * a passed in amount. |
|
| 400 | - * |
|
| 401 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 402 | - * @param float $amount Refund amount. |
|
| 403 | - * @param string $reason Refund reason. |
|
| 404 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 405 | - */ |
|
| 406 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 407 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Displays the payment fields, credit cards etc. |
|
| 412 | - * |
|
| 413 | - * @param int $invoice_id 0 or invoice id. |
|
| 414 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 415 | - */ |
|
| 416 | - public function payment_fields( $invoice_id, $form ) { |
|
| 417 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * Filters the gateway settings. |
|
| 422 | - * |
|
| 423 | - * @param array $admin_settings |
|
| 424 | - */ |
|
| 425 | - public function admin_settings( $admin_settings ) { |
|
| 426 | - return $admin_settings; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Retrieves the value of a gateway setting. |
|
| 431 | - * |
|
| 432 | - * @param string $option |
|
| 433 | - */ |
|
| 434 | - public function get_option( $option, $default = false ) { |
|
| 435 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Check if a gateway supports a given feature. |
|
| 440 | - * |
|
| 441 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 442 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 443 | - * |
|
| 444 | - * @param string $feature string The name of a feature to test support for. |
|
| 445 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
| 446 | - * @since 1.0.19 |
|
| 447 | - */ |
|
| 448 | - public function supports( $feature ) { |
|
| 449 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Returns the credit card form html. |
|
| 454 | - * |
|
| 455 | - * @param bool $save whether or not to display the save button. |
|
| 456 | - */ |
|
| 452 | + /** |
|
| 453 | + * Returns the credit card form html. |
|
| 454 | + * |
|
| 455 | + * @param bool $save whether or not to display the save button. |
|
| 456 | + */ |
|
| 457 | 457 | public function get_cc_form( $save = false ) { |
| 458 | 458 | |
| 459 | - ob_start(); |
|
| 459 | + ob_start(); |
|
| 460 | 460 | |
| 461 | 461 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
| 462 | 462 | |
@@ -551,8 +551,8 @@ discard block |
||
| 551 | 551 | 'name' => $this->id . '[cc_cvv2]', |
| 552 | 552 | 'id' => "$id_prefix-cc-cvv2", |
| 553 | 553 | 'label' => __( 'CCV', 'invoicing' ), |
| 554 | - 'label_type' => 'vertical', |
|
| 555 | - 'class' => 'form-control-sm', |
|
| 554 | + 'label_type' => 'vertical', |
|
| 555 | + 'class' => 'form-control-sm', |
|
| 556 | 556 | ) |
| 557 | 557 | ); |
| 558 | 558 | ?> |
@@ -562,175 +562,175 @@ discard block |
||
| 562 | 562 | |
| 563 | 563 | <?php |
| 564 | 564 | |
| 565 | - if ( $save ) { |
|
| 566 | - echo $this->save_payment_method_checkbox(); |
|
| 567 | - } |
|
| 565 | + if ( $save ) { |
|
| 566 | + echo $this->save_payment_method_checkbox(); |
|
| 567 | + } |
|
| 568 | 568 | |
| 569 | - ?> |
|
| 569 | + ?> |
|
| 570 | 570 | </div> |
| 571 | 571 | |
| 572 | 572 | </div> |
| 573 | 573 | <?php |
| 574 | 574 | |
| 575 | - return ob_get_clean(); |
|
| 575 | + return ob_get_clean(); |
|
| 576 | 576 | |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - /** |
|
| 580 | - * Displays a new payment method entry form. |
|
| 581 | - * |
|
| 582 | - * @since 1.0.19 |
|
| 583 | - */ |
|
| 584 | - public function new_payment_method_entry( $form ) { |
|
| 585 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Grab and display our saved payment methods. |
|
| 590 | - * |
|
| 591 | - * @since 1.0.19 |
|
| 592 | - */ |
|
| 593 | - public function saved_payment_methods() { |
|
| 594 | - $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 595 | - |
|
| 596 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 597 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $html .= $this->get_new_payment_method_option_html(); |
|
| 601 | - $html .= '</ul>'; |
|
| 602 | - |
|
| 603 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Gets saved payment method HTML from a token. |
|
| 608 | - * |
|
| 609 | - * @since 1.0.19 |
|
| 610 | - * @param array $token Payment Token. |
|
| 611 | - * @return string Generated payment method HTML |
|
| 612 | - */ |
|
| 613 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 614 | - |
|
| 615 | - return sprintf( |
|
| 616 | - '<li class="getpaid-payment-method form-group"> |
|
| 579 | + /** |
|
| 580 | + * Displays a new payment method entry form. |
|
| 581 | + * |
|
| 582 | + * @since 1.0.19 |
|
| 583 | + */ |
|
| 584 | + public function new_payment_method_entry( $form ) { |
|
| 585 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Grab and display our saved payment methods. |
|
| 590 | + * |
|
| 591 | + * @since 1.0.19 |
|
| 592 | + */ |
|
| 593 | + public function saved_payment_methods() { |
|
| 594 | + $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 595 | + |
|
| 596 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 597 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $html .= $this->get_new_payment_method_option_html(); |
|
| 601 | + $html .= '</ul>'; |
|
| 602 | + |
|
| 603 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * Gets saved payment method HTML from a token. |
|
| 608 | + * |
|
| 609 | + * @since 1.0.19 |
|
| 610 | + * @param array $token Payment Token. |
|
| 611 | + * @return string Generated payment method HTML |
|
| 612 | + */ |
|
| 613 | + public function get_saved_payment_method_option_html( $token ) { |
|
| 614 | + |
|
| 615 | + return sprintf( |
|
| 616 | + '<li class="getpaid-payment-method form-group"> |
|
| 617 | 617 | <label> |
| 618 | 618 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
| 619 | 619 | <span>%3$s</span> |
| 620 | 620 | </label> |
| 621 | 621 | </li>', |
| 622 | - esc_attr( $this->id ), |
|
| 623 | - esc_attr( $token['id'] ), |
|
| 624 | - esc_html( $token['name'] ), |
|
| 625 | - checked( empty( $token['default'] ), false, false ) |
|
| 626 | - ); |
|
| 622 | + esc_attr( $this->id ), |
|
| 623 | + esc_attr( $token['id'] ), |
|
| 624 | + esc_html( $token['name'] ), |
|
| 625 | + checked( empty( $token['default'] ), false, false ) |
|
| 626 | + ); |
|
| 627 | 627 | |
| 628 | - } |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | - /** |
|
| 631 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 632 | - * |
|
| 633 | - * @since 1.0.19 |
|
| 634 | - */ |
|
| 635 | - public function get_new_payment_method_option_html() { |
|
| 630 | + /** |
|
| 631 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 632 | + * |
|
| 633 | + * @since 1.0.19 |
|
| 634 | + */ |
|
| 635 | + public function get_new_payment_method_option_html() { |
|
| 636 | 636 | |
| 637 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 637 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 638 | 638 | |
| 639 | - return sprintf( |
|
| 640 | - '<li class="getpaid-new-payment-method"> |
|
| 639 | + return sprintf( |
|
| 640 | + '<li class="getpaid-new-payment-method"> |
|
| 641 | 641 | <label> |
| 642 | 642 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
| 643 | 643 | <span>%2$s</span> |
| 644 | 644 | </label> |
| 645 | 645 | </li>', |
| 646 | - esc_attr( $this->id ), |
|
| 647 | - esc_html( $label ) |
|
| 648 | - ); |
|
| 646 | + esc_attr( $this->id ), |
|
| 647 | + esc_html( $label ) |
|
| 648 | + ); |
|
| 649 | 649 | |
| 650 | - } |
|
| 650 | + } |
|
| 651 | 651 | |
| 652 | - /** |
|
| 653 | - * Outputs a checkbox for saving a new payment method to the database. |
|
| 654 | - * |
|
| 655 | - * @since 1.0.19 |
|
| 656 | - */ |
|
| 657 | - public function save_payment_method_checkbox() { |
|
| 652 | + /** |
|
| 653 | + * Outputs a checkbox for saving a new payment method to the database. |
|
| 654 | + * |
|
| 655 | + * @since 1.0.19 |
|
| 656 | + */ |
|
| 657 | + public function save_payment_method_checkbox() { |
|
| 658 | 658 | |
| 659 | - return sprintf( |
|
| 660 | - '<p class="form-group getpaid-save-payment-method"> |
|
| 659 | + return sprintf( |
|
| 660 | + '<p class="form-group getpaid-save-payment-method"> |
|
| 661 | 661 | <label> |
| 662 | 662 | <input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
| 663 | 663 | <span>%2$s</span> |
| 664 | 664 | </label> |
| 665 | 665 | </p>', |
| 666 | - esc_attr( $this->id ), |
|
| 667 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
| 668 | - ); |
|
| 666 | + esc_attr( $this->id ), |
|
| 667 | + esc_html__( 'Save payment method', 'invoicing' ) |
|
| 668 | + ); |
|
| 669 | 669 | |
| 670 | - } |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | - /** |
|
| 673 | - * Registers the gateway. |
|
| 674 | - * |
|
| 675 | - * @return array |
|
| 676 | - */ |
|
| 677 | - public function register_gateway( $gateways ) { |
|
| 672 | + /** |
|
| 673 | + * Registers the gateway. |
|
| 674 | + * |
|
| 675 | + * @return array |
|
| 676 | + */ |
|
| 677 | + public function register_gateway( $gateways ) { |
|
| 678 | 678 | |
| 679 | - $gateways[ $this->id ] = array( |
|
| 679 | + $gateways[ $this->id ] = array( |
|
| 680 | 680 | |
| 681 | - 'admin_label' => $this->method_title, |
|
| 681 | + 'admin_label' => $this->method_title, |
|
| 682 | 682 | 'checkout_label' => $this->title, |
| 683 | - 'ordering' => $this->order, |
|
| 684 | - |
|
| 685 | - ); |
|
| 686 | - |
|
| 687 | - return $gateways; |
|
| 688 | - |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Checks whether or not this is a sandbox request. |
|
| 693 | - * |
|
| 694 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 695 | - * @return bool |
|
| 696 | - */ |
|
| 697 | - public function is_sandbox( $invoice = null ) { |
|
| 698 | - |
|
| 699 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 700 | - return $invoice->get_mode() == 'test'; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - return wpinv_is_test_mode( $this->id ); |
|
| 704 | - |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Renames the checkout button |
|
| 709 | - * |
|
| 710 | - * @return string |
|
| 711 | - */ |
|
| 712 | - public function rename_checkout_button() { |
|
| 713 | - return $this->checkout_button_text; |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * Validate gateway currency |
|
| 718 | - * |
|
| 719 | - * @return bool |
|
| 720 | - */ |
|
| 721 | - public function validate_currency( $validation, $currency ) { |
|
| 722 | - |
|
| 723 | - // Required currencies. |
|
| 724 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 725 | - return false; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // Excluded currencies. |
|
| 729 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 730 | - return false; |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - return $validation; |
|
| 734 | - } |
|
| 683 | + 'ordering' => $this->order, |
|
| 684 | + |
|
| 685 | + ); |
|
| 686 | + |
|
| 687 | + return $gateways; |
|
| 688 | + |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Checks whether or not this is a sandbox request. |
|
| 693 | + * |
|
| 694 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 695 | + * @return bool |
|
| 696 | + */ |
|
| 697 | + public function is_sandbox( $invoice = null ) { |
|
| 698 | + |
|
| 699 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 700 | + return $invoice->get_mode() == 'test'; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + return wpinv_is_test_mode( $this->id ); |
|
| 704 | + |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * Renames the checkout button |
|
| 709 | + * |
|
| 710 | + * @return string |
|
| 711 | + */ |
|
| 712 | + public function rename_checkout_button() { |
|
| 713 | + return $this->checkout_button_text; |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * Validate gateway currency |
|
| 718 | + * |
|
| 719 | + * @return bool |
|
| 720 | + */ |
|
| 721 | + public function validate_currency( $validation, $currency ) { |
|
| 722 | + |
|
| 723 | + // Required currencies. |
|
| 724 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 725 | + return false; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // Excluded currencies. |
|
| 729 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 730 | + return false; |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + return $validation; |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | 736 | } |
@@ -229,7 +229,7 @@ |
||
| 229 | 229 | */ |
| 230 | 230 | function wpinv_send_back_to_checkout() { |
| 231 | 231 | |
| 232 | - // Do we have any errors? |
|
| 232 | + // Do we have any errors? |
|
| 233 | 233 | if ( wpinv_get_errors() ) { |
| 234 | 234 | wp_send_json_error( getpaid_get_errors_html( true, false ) ); |
| 235 | 235 | } |
@@ -12,431 +12,431 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $id = 'paypal'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Payment method object. |
|
| 24 | - * |
|
| 25 | - * @var GetPaid_Paypal_Gateway |
|
| 26 | - */ |
|
| 27 | - protected $gateway; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Class constructor. |
|
| 31 | - * |
|
| 32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | - */ |
|
| 34 | - public function __construct( $gateway ) { |
|
| 35 | - $this->gateway = $gateway; |
|
| 36 | - $this->verify_ipn(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Processes ipns and marks payments as complete. |
|
| 41 | - * |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function verify_ipn() { |
|
| 45 | - |
|
| 46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
| 47 | - |
|
| 48 | - // Validate the IPN. |
|
| 49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // Process the IPN. |
|
| 54 | - $posted = wp_unslash( $_POST ); |
|
| 55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | - |
|
| 57 | - // Abort if it was not paid by our gateway. |
|
| 58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
| 60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | - |
|
| 66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
| 67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
| 68 | - |
|
| 69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | - wpinv_error_log( 'Done processing IPN' ); |
|
| 72 | - wp_die( 'Processed', 200 ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
| 76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Retrieves IPN Invoice. |
|
| 82 | - * |
|
| 83 | - * @param array $posted |
|
| 84 | - * @return WPInv_Invoice |
|
| 85 | - */ |
|
| 86 | - protected function get_ipn_invoice( $posted ) { |
|
| 87 | - |
|
| 88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
| 89 | - |
|
| 90 | - if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 92 | - |
|
| 93 | - if ( $invoice->exists() ) { |
|
| 94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
| 95 | - return $invoice; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
| 101 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Check PayPal IPN validity. |
|
| 106 | - */ |
|
| 107 | - protected function validate_ipn() { |
|
| 108 | - |
|
| 109 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
| 110 | - |
|
| 111 | - // Retrieve the associated invoice. |
|
| 112 | - $posted = wp_unslash( $_POST ); |
|
| 113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 114 | - |
|
| 115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Validate the IPN. |
|
| 120 | - $posted['cmd'] = '_notify-validate'; |
|
| 121 | - |
|
| 122 | - // Send back post vars to paypal. |
|
| 123 | - $params = array( |
|
| 124 | - 'body' => $posted, |
|
| 125 | - 'timeout' => 60, |
|
| 126 | - 'httpversion' => '1.1', |
|
| 127 | - 'compress' => false, |
|
| 128 | - 'decompress' => false, |
|
| 129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - // Post back to get a response. |
|
| 133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 134 | - |
|
| 135 | - // Check to see if the request was valid. |
|
| 136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
| 138 | - return true; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if ( is_wp_error( $response ) ) { |
|
| 142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 15 | + /** |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $id = 'paypal'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Payment method object. |
|
| 24 | + * |
|
| 25 | + * @var GetPaid_Paypal_Gateway |
|
| 26 | + */ |
|
| 27 | + protected $gateway; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Class constructor. |
|
| 31 | + * |
|
| 32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | + */ |
|
| 34 | + public function __construct( $gateway ) { |
|
| 35 | + $this->gateway = $gateway; |
|
| 36 | + $this->verify_ipn(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Processes ipns and marks payments as complete. |
|
| 41 | + * |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function verify_ipn() { |
|
| 45 | + |
|
| 46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
| 47 | + |
|
| 48 | + // Validate the IPN. |
|
| 49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // Process the IPN. |
|
| 54 | + $posted = wp_unslash( $_POST ); |
|
| 55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | + |
|
| 57 | + // Abort if it was not paid by our gateway. |
|
| 58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
| 60 | + wp_die( 'Invoice not paid via PayPal', 500 ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | + |
|
| 66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
| 67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
| 68 | + |
|
| 69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | + wpinv_error_log( 'Done processing IPN' ); |
|
| 72 | + wp_die( 'Processed', 200 ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
| 76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Retrieves IPN Invoice. |
|
| 82 | + * |
|
| 83 | + * @param array $posted |
|
| 84 | + * @return WPInv_Invoice |
|
| 85 | + */ |
|
| 86 | + protected function get_ipn_invoice( $posted ) { |
|
| 87 | + |
|
| 88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
| 89 | + |
|
| 90 | + if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 92 | + |
|
| 93 | + if ( $invoice->exists() ) { |
|
| 94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
| 95 | + return $invoice; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
| 101 | + wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Check PayPal IPN validity. |
|
| 106 | + */ |
|
| 107 | + protected function validate_ipn() { |
|
| 108 | + |
|
| 109 | + wpinv_error_log( 'Validating PayPal IPN response' ); |
|
| 110 | + |
|
| 111 | + // Retrieve the associated invoice. |
|
| 112 | + $posted = wp_unslash( $_POST ); |
|
| 113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 114 | + |
|
| 115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Validate the IPN. |
|
| 120 | + $posted['cmd'] = '_notify-validate'; |
|
| 121 | + |
|
| 122 | + // Send back post vars to paypal. |
|
| 123 | + $params = array( |
|
| 124 | + 'body' => $posted, |
|
| 125 | + 'timeout' => 60, |
|
| 126 | + 'httpversion' => '1.1', |
|
| 127 | + 'compress' => false, |
|
| 128 | + 'decompress' => false, |
|
| 129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + // Post back to get a response. |
|
| 133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 134 | + |
|
| 135 | + // Check to see if the request was valid. |
|
| 136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | + wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
| 138 | + return true; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if ( is_wp_error( $response ) ) { |
|
| 142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 147 | - return false; |
|
| 148 | - |
|
| 149 | - } |
|
| 146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 147 | + return false; |
|
| 148 | + |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Check currency from IPN matches the invoice. |
|
| 153 | - * |
|
| 154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | - * @param string $currency currency to validate. |
|
| 156 | - */ |
|
| 157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 151 | + /** |
|
| 152 | + * Check currency from IPN matches the invoice. |
|
| 153 | + * |
|
| 154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | + * @param string $currency currency to validate. |
|
| 156 | + */ |
|
| 157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 158 | 158 | |
| 159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 160 | 160 | |
| 161 | - /* translators: %s: currency code. */ |
|
| 162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 161 | + /* translators: %s: currency code. */ |
|
| 162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 163 | 163 | |
| 164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 165 | - } |
|
| 164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
| 168 | - } |
|
| 167 | + wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Check payment amount from IPN matches the invoice. |
|
| 172 | - * |
|
| 173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 174 | - * @param float $amount amount to validate. |
|
| 175 | - */ |
|
| 176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 170 | + /** |
|
| 171 | + * Check payment amount from IPN matches the invoice. |
|
| 172 | + * |
|
| 173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 174 | + * @param float $amount amount to validate. |
|
| 175 | + */ |
|
| 176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 178 | 178 | |
| 179 | - /* translators: %s: Amount. */ |
|
| 180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 179 | + /* translators: %s: Amount. */ |
|
| 180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 181 | 181 | |
| 182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 183 | - } |
|
| 182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
| 186 | - } |
|
| 185 | + wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Verify receiver email from PayPal. |
|
| 190 | - * |
|
| 191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 192 | - * @param string $receiver_email Email to validate. |
|
| 193 | - */ |
|
| 194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 188 | + /** |
|
| 189 | + * Verify receiver email from PayPal. |
|
| 190 | + * |
|
| 191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 192 | + * @param string $receiver_email Email to validate. |
|
| 193 | + */ |
|
| 194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 196 | 196 | |
| 197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 199 | 199 | |
| 200 | - /* translators: %s: email address . */ |
|
| 201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 200 | + /* translators: %s: email address . */ |
|
| 201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 202 | 202 | |
| 203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 204 | - } |
|
| 203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
| 207 | - } |
|
| 206 | + wpinv_error_log( 'Validated PayPal Email' ); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Handles one time payments. |
|
| 211 | - * |
|
| 212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 213 | - * @param array $posted Posted data. |
|
| 214 | - */ |
|
| 215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 216 | - |
|
| 217 | - // Collect payment details |
|
| 218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 220 | - |
|
| 221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 223 | - |
|
| 224 | - // Update the transaction id. |
|
| 225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 227 | - $invoice->save(); |
|
| 228 | - } |
|
| 209 | + /** |
|
| 210 | + * Handles one time payments. |
|
| 211 | + * |
|
| 212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 213 | + * @param array $posted Posted data. |
|
| 214 | + */ |
|
| 215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 216 | + |
|
| 217 | + // Collect payment details |
|
| 218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 220 | + |
|
| 221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 223 | + |
|
| 224 | + // Update the transaction id. |
|
| 225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 227 | + $invoice->save(); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - // Process a refund. |
|
| 231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 230 | + // Process a refund. |
|
| 231 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 232 | 232 | |
| 233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 233 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 234 | 234 | |
| 235 | - if ( ! $invoice->is_refunded() ) { |
|
| 236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 237 | - } |
|
| 235 | + if ( ! $invoice->is_refunded() ) { |
|
| 236 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
| 240 | - } |
|
| 239 | + return wpinv_error_log( $posted['reason_code'] ); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - // Process payments. |
|
| 243 | - if ( $payment_status == 'completed' ) { |
|
| 242 | + // Process payments. |
|
| 243 | + if ( $payment_status == 'completed' ) { |
|
| 244 | 244 | |
| 245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
| 247 | - } |
|
| 245 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 249 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 250 | 250 | |
| 251 | - $note = ''; |
|
| 252 | - |
|
| 253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 255 | - } |
|
| 251 | + $note = ''; |
|
| 252 | + |
|
| 253 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | + $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 259 | - } |
|
| 257 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | + $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
| 261 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | + return wpinv_error_log( 'Invoice marked as paid.' ); |
|
| 263 | 263 | |
| 264 | - } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - // Pending payments. |
|
| 267 | - if ( $payment_status == 'pending' ) { |
|
| 266 | + // Pending payments. |
|
| 267 | + if ( $payment_status == 'pending' ) { |
|
| 268 | 268 | |
| 269 | - /* translators: %s: pending reason. */ |
|
| 270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 269 | + /* translators: %s: pending reason. */ |
|
| 270 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 271 | 271 | |
| 272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
| 273 | - } |
|
| 272 | + return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /* translators: %s: payment status. */ |
|
| 276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 275 | + /* translators: %s: payment status. */ |
|
| 276 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 277 | 277 | |
| 278 | - } |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * Handles one time payments. |
|
| 282 | - * |
|
| 283 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 284 | - * @param array $posted Posted data. |
|
| 285 | - */ |
|
| 286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 288 | - } |
|
| 280 | + /** |
|
| 281 | + * Handles one time payments. |
|
| 282 | + * |
|
| 283 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 284 | + * @param array $posted Posted data. |
|
| 285 | + */ |
|
| 286 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Handles subscription sign ups. |
|
| 292 | - * |
|
| 293 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 294 | - * @param array $posted Posted data. |
|
| 295 | - */ |
|
| 296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 290 | + /** |
|
| 291 | + * Handles subscription sign ups. |
|
| 292 | + * |
|
| 293 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 294 | + * @param array $posted Posted data. |
|
| 295 | + */ |
|
| 296 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 297 | 297 | |
| 298 | - wpinv_error_log( 'Processing subscription signup' ); |
|
| 298 | + wpinv_error_log( 'Processing subscription signup' ); |
|
| 299 | 299 | |
| 300 | - // Make sure the invoice has a subscription. |
|
| 301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 300 | + // Make sure the invoice has a subscription. |
|
| 301 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 302 | 302 | |
| 303 | - if ( empty( $subscription ) ) { |
|
| 304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 305 | - } |
|
| 303 | + if ( empty( $subscription ) ) { |
|
| 304 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - // Validate the IPN. |
|
| 308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 307 | + // Validate the IPN. |
|
| 308 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 309 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 310 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 311 | 311 | |
| 312 | - // Activate the subscription. |
|
| 313 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 314 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 315 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 316 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 317 | - $subscription->activate(); |
|
| 312 | + // Activate the subscription. |
|
| 313 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 314 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 315 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 316 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 317 | + $subscription->activate(); |
|
| 318 | 318 | |
| 319 | - // Set the transaction id. |
|
| 320 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 321 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 322 | - } |
|
| 319 | + // Set the transaction id. |
|
| 320 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 321 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - // Update the payment status. |
|
| 325 | - $invoice->mark_paid(); |
|
| 324 | + // Update the payment status. |
|
| 325 | + $invoice->mark_paid(); |
|
| 326 | 326 | |
| 327 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 327 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 328 | 328 | |
| 329 | - wpinv_error_log( 'Subscription started.' ); |
|
| 330 | - } |
|
| 329 | + wpinv_error_log( 'Subscription started.' ); |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - /** |
|
| 333 | - * Handles subscription renewals. |
|
| 334 | - * |
|
| 335 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 336 | - * @param array $posted Posted data. |
|
| 337 | - */ |
|
| 338 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 332 | + /** |
|
| 333 | + * Handles subscription renewals. |
|
| 334 | + * |
|
| 335 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 336 | + * @param array $posted Posted data. |
|
| 337 | + */ |
|
| 338 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 339 | 339 | |
| 340 | - // Make sure the invoice has a subscription. |
|
| 341 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 340 | + // Make sure the invoice has a subscription. |
|
| 341 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 342 | 342 | |
| 343 | - if ( empty( $subscription ) ) { |
|
| 344 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 345 | - } |
|
| 343 | + if ( empty( $subscription ) ) { |
|
| 344 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - // Abort if this is the first payment. |
|
| 348 | - if ( date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
| 349 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 350 | - $invoice->save(); |
|
| 351 | - return; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
| 347 | + // Abort if this is the first payment. |
|
| 348 | + if ( date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
| 349 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 350 | + $invoice->save(); |
|
| 351 | + return; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
| 355 | 355 | |
| 356 | - // Abort if the payment is already recorded. |
|
| 357 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 358 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
| 359 | - } |
|
| 356 | + // Abort if the payment is already recorded. |
|
| 357 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 358 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - $args = array( |
|
| 362 | - 'transaction_id' => $posted['txn_id'], |
|
| 363 | - 'gateway' => $this->id, |
|
| 364 | - ); |
|
| 365 | - |
|
| 366 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 367 | - |
|
| 368 | - if ( empty( $invoice ) ) { |
|
| 369 | - return; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 374 | - |
|
| 375 | - $subscription->renew(); |
|
| 376 | - wpinv_error_log( 'Subscription renewed.' ); |
|
| 377 | - |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Handles subscription cancelations. |
|
| 382 | - * |
|
| 383 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 384 | - */ |
|
| 385 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 386 | - |
|
| 387 | - // Make sure the invoice has a subscription. |
|
| 388 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 389 | - |
|
| 390 | - if ( empty( $subscription ) ) { |
|
| 391 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
| 395 | - $subscription->cancel(); |
|
| 396 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
| 361 | + $args = array( |
|
| 362 | + 'transaction_id' => $posted['txn_id'], |
|
| 363 | + 'gateway' => $this->id, |
|
| 364 | + ); |
|
| 365 | + |
|
| 366 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 367 | + |
|
| 368 | + if ( empty( $invoice ) ) { |
|
| 369 | + return; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 373 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 374 | + |
|
| 375 | + $subscription->renew(); |
|
| 376 | + wpinv_error_log( 'Subscription renewed.' ); |
|
| 377 | + |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Handles subscription cancelations. |
|
| 382 | + * |
|
| 383 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 384 | + */ |
|
| 385 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 386 | + |
|
| 387 | + // Make sure the invoice has a subscription. |
|
| 388 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 389 | + |
|
| 390 | + if ( empty( $subscription ) ) { |
|
| 391 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
| 395 | + $subscription->cancel(); |
|
| 396 | + wpinv_error_log( 'Subscription cancelled.' ); |
|
| 397 | 397 | |
| 398 | - } |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | - /** |
|
| 401 | - * Handles subscription completions. |
|
| 402 | - * |
|
| 403 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 404 | - * @param array $posted Posted data. |
|
| 405 | - */ |
|
| 406 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 407 | - |
|
| 408 | - // Make sure the invoice has a subscription. |
|
| 409 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 400 | + /** |
|
| 401 | + * Handles subscription completions. |
|
| 402 | + * |
|
| 403 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 404 | + * @param array $posted Posted data. |
|
| 405 | + */ |
|
| 406 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 407 | + |
|
| 408 | + // Make sure the invoice has a subscription. |
|
| 409 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 410 | 410 | |
| 411 | - if ( empty( $subscription ) ) { |
|
| 412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 413 | - } |
|
| 411 | + if ( empty( $subscription ) ) { |
|
| 412 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
| 416 | - $subscription->complete(); |
|
| 417 | - wpinv_error_log( 'Subscription completed.' ); |
|
| 415 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
| 416 | + $subscription->complete(); |
|
| 417 | + wpinv_error_log( 'Subscription completed.' ); |
|
| 418 | 418 | |
| 419 | - } |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * Handles subscription fails. |
|
| 423 | - * |
|
| 424 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 425 | - * @param array $posted Posted data. |
|
| 426 | - */ |
|
| 427 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 421 | + /** |
|
| 422 | + * Handles subscription fails. |
|
| 423 | + * |
|
| 424 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 425 | + * @param array $posted Posted data. |
|
| 426 | + */ |
|
| 427 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 428 | 428 | |
| 429 | - // Make sure the invoice has a subscription. |
|
| 430 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 429 | + // Make sure the invoice has a subscription. |
|
| 430 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 431 | 431 | |
| 432 | - if ( empty( $subscription ) ) { |
|
| 433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 434 | - } |
|
| 432 | + if ( empty( $subscription ) ) { |
|
| 433 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
| 437 | - $subscription->failing(); |
|
| 438 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
| 436 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
| 437 | + $subscription->failing(); |
|
| 438 | + wpinv_error_log( 'Subscription marked as failing.' ); |
|
| 439 | 439 | |
| 440 | - } |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | 442 | } |
@@ -43,64 +43,64 @@ discard block |
||
| 43 | 43 | <td class="w-75"> |
| 44 | 44 | <?php |
| 45 | 45 | |
| 46 | - switch ( $key ) { |
|
| 46 | + switch ( $key ) { |
|
| 47 | 47 | |
| 48 | - case 'status': |
|
| 49 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
| 50 | - break; |
|
| 48 | + case 'status': |
|
| 49 | + echo sanitize_text_field( $subscription->get_status_label() ); |
|
| 50 | + break; |
|
| 51 | 51 | |
| 52 | - case 'start_date': |
|
| 53 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 54 | - break; |
|
| 52 | + case 'start_date': |
|
| 53 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
| 54 | + break; |
|
| 55 | 55 | |
| 56 | - case 'expiry_date': |
|
| 57 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
| 58 | - break; |
|
| 56 | + case 'expiry_date': |
|
| 57 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
| 58 | + break; |
|
| 59 | 59 | |
| 60 | - case 'initial_amount': |
|
| 61 | - echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
| 60 | + case 'initial_amount': |
|
| 61 | + echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
| 62 | 62 | |
| 63 | - if ( $subscription->has_trial_period() ) { |
|
| 63 | + if ( $subscription->has_trial_period() ) { |
|
| 64 | 64 | |
| 65 | - echo "<small class='text-muted'> "; |
|
| 66 | - printf( |
|
| 67 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
| 68 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
| 69 | - ); |
|
| 70 | - echo '</small>'; |
|
| 65 | + echo "<small class='text-muted'> "; |
|
| 66 | + printf( |
|
| 67 | + _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
| 68 | + sanitize_text_field( $subscription->get_trial_period() ) |
|
| 69 | + ); |
|
| 70 | + echo '</small>'; |
|
| 71 | 71 | |
| 72 | - } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - break; |
|
| 74 | + break; |
|
| 75 | 75 | |
| 76 | - case 'recurring_amount': |
|
| 77 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 78 | - $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
| 79 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
| 80 | - break; |
|
| 76 | + case 'recurring_amount': |
|
| 77 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 78 | + $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
| 79 | + echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
| 80 | + break; |
|
| 81 | 81 | |
| 82 | - case 'item': |
|
| 83 | - $item = get_post( $subscription->get_product_id() ); |
|
| 82 | + case 'item': |
|
| 83 | + $item = get_post( $subscription->get_product_id() ); |
|
| 84 | 84 | |
| 85 | - if ( ! empty( $item ) ) { |
|
| 86 | - echo esc_html( get_the_title( $item ) ); |
|
| 87 | - } else { |
|
| 88 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 89 | - } |
|
| 85 | + if ( ! empty( $item ) ) { |
|
| 86 | + echo esc_html( get_the_title( $item ) ); |
|
| 87 | + } else { |
|
| 88 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - break; |
|
| 91 | + break; |
|
| 92 | 92 | |
| 93 | - case 'payments': |
|
| 93 | + case 'payments': |
|
| 94 | 94 | |
| 95 | - $max_activations = (int) $subscription->get_bill_times(); |
|
| 96 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
| 95 | + $max_activations = (int) $subscription->get_bill_times(); |
|
| 96 | + echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
| 97 | 97 | |
| 98 | - break; |
|
| 98 | + break; |
|
| 99 | 99 | |
| 100 | - } |
|
| 101 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
| 100 | + } |
|
| 101 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
| 102 | 102 | |
| 103 | - ?> |
|
| 103 | + ?> |
|
| 104 | 104 | </td> |
| 105 | 105 | |
| 106 | 106 | </tr> |
@@ -117,17 +117,17 @@ discard block |
||
| 117 | 117 | <span class="form-text"> |
| 118 | 118 | |
| 119 | 119 | <?php |
| 120 | - if ( $subscription->can_cancel() ) { |
|
| 121 | - printf( |
|
| 122 | - '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
| 123 | - esc_url( $subscription->get_cancel_url() ), |
|
| 124 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
| 125 | - __( 'Cancel Subscription', 'invoicing' ) |
|
| 126 | - ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
| 130 | - ?> |
|
| 120 | + if ( $subscription->can_cancel() ) { |
|
| 121 | + printf( |
|
| 122 | + '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
| 123 | + esc_url( $subscription->get_cancel_url() ), |
|
| 124 | + esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
| 125 | + __( 'Cancel Subscription', 'invoicing' ) |
|
| 126 | + ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
| 130 | + ?> |
|
| 131 | 131 | |
| 132 | 132 | <a href="<?php echo esc_url( get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
| 133 | 133 | </span> |
| 134 | 134 | \ No newline at end of file |
@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | // Define constants. |
| 21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
| 22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
| 26 | - define( 'WPINV_VERSION', '1.1.0' ); |
|
| 26 | + define( 'WPINV_VERSION', '1.1.0' ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Include the main Invoicing class. |
| 30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
| 31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return $GLOBALS['invoicing']; |
|
| 46 | + return $GLOBALS['invoicing']; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
| 10 | 10 | class WPInv_Item extends GetPaid_Data { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Which data store to load. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 13 | + * Which data store to load. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | 17 | protected $data_store_name = 'item'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * This is the name of this object type. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $object_type = 'item'; |
|
| 20 | + * This is the name of this object type. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $object_type = 'item'; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array( |
|
| 33 | - 'parent_id' => 0, |
|
| 34 | - 'status' => 'draft', |
|
| 35 | - 'version' => '', |
|
| 36 | - 'date_created' => null, |
|
| 27 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array( |
|
| 33 | + 'parent_id' => 0, |
|
| 34 | + 'status' => 'draft', |
|
| 35 | + 'version' => '', |
|
| 36 | + 'date_created' => null, |
|
| 37 | 37 | 'date_modified' => null, |
| 38 | 38 | 'name' => '', |
| 39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * Stores meta in cache for future reads. |
|
| 62 | - * |
|
| 63 | - * A group must be set to to enable caching. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - protected $cache_group = 'getpaid_items'; |
|
| 61 | + * Stores meta in cache for future reads. |
|
| 62 | + * |
|
| 63 | + * A group must be set to to enable caching. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + protected $cache_group = 'getpaid_items'; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
| 74 | 74 | protected $post = null; |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | - * |
|
| 79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | - */ |
|
| 81 | - public function __construct( $item = 0 ) { |
|
| 82 | - parent::__construct( $item ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | - $this->set_id( $item ); |
|
| 86 | - } elseif ( $item instanceof self ) { |
|
| 87 | - $this->set_id( $item->get_id() ); |
|
| 88 | - } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | - $this->set_id( $item->ID ); |
|
| 90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | - $this->set_id( $item_id ); |
|
| 92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | - $this->set_id( $item_id ); |
|
| 94 | - } else { |
|
| 95 | - $this->set_object_read( true ); |
|
| 96 | - } |
|
| 77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | + * |
|
| 79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | + */ |
|
| 81 | + public function __construct( $item = 0 ) { |
|
| 82 | + parent::__construct( $item ); |
|
| 83 | + |
|
| 84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | + $this->set_id( $item ); |
|
| 86 | + } elseif ( $item instanceof self ) { |
|
| 87 | + $this->set_id( $item->get_id() ); |
|
| 88 | + } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | + $this->set_id( $item->ID ); |
|
| 90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | + $this->set_id( $item_id ); |
|
| 92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | + $this->set_id( $item_id ); |
|
| 94 | + } else { |
|
| 95 | + $this->set_object_read( true ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | // Load the datastore. |
| 99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 100 | 100 | |
| 101 | - if ( $this->get_id() > 0 ) { |
|
| 101 | + if ( $this->get_id() > 0 ) { |
|
| 102 | 102 | $this->post = get_post( $this->get_id() ); |
| 103 | 103 | $this->ID = $this->get_id(); |
| 104 | - $this->data_store->read( $this ); |
|
| 104 | + $this->data_store->read( $this ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | /* |
| 110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Get parent item ID. |
|
| 126 | - * |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @param string $context View or edit context. |
|
| 129 | - * @return int |
|
| 130 | - */ |
|
| 131 | - public function get_parent_id( $context = 'view' ) { |
|
| 132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 125 | + * Get parent item ID. |
|
| 126 | + * |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @param string $context View or edit context. |
|
| 129 | + * @return int |
|
| 130 | + */ |
|
| 131 | + public function get_parent_id( $context = 'view' ) { |
|
| 132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | - * Get item status. |
|
| 137 | - * |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @param string $context View or edit context. |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function get_status( $context = 'view' ) { |
|
| 143 | - return $this->get_prop( 'status', $context ); |
|
| 136 | + * Get item status. |
|
| 137 | + * |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @param string $context View or edit context. |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function get_status( $context = 'view' ) { |
|
| 143 | + return $this->get_prop( 'status', $context ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | - * Get plugin version when the item was created. |
|
| 148 | - * |
|
| 149 | - * @since 1.0.19 |
|
| 150 | - * @param string $context View or edit context. |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function get_version( $context = 'view' ) { |
|
| 154 | - return $this->get_prop( 'version', $context ); |
|
| 147 | + * Get plugin version when the item was created. |
|
| 148 | + * |
|
| 149 | + * @since 1.0.19 |
|
| 150 | + * @param string $context View or edit context. |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function get_version( $context = 'view' ) { |
|
| 154 | + return $this->get_prop( 'version', $context ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | - * Get date when the item was created. |
|
| 159 | - * |
|
| 160 | - * @since 1.0.19 |
|
| 161 | - * @param string $context View or edit context. |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function get_date_created( $context = 'view' ) { |
|
| 165 | - return $this->get_prop( 'date_created', $context ); |
|
| 158 | + * Get date when the item was created. |
|
| 159 | + * |
|
| 160 | + * @since 1.0.19 |
|
| 161 | + * @param string $context View or edit context. |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function get_date_created( $context = 'view' ) { |
|
| 165 | + return $this->get_prop( 'date_created', $context ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | - * Get GMT date when the item was created. |
|
| 170 | - * |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - * @param string $context View or edit context. |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 169 | + * Get GMT date when the item was created. |
|
| 170 | + * |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + * @param string $context View or edit context. |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 176 | 176 | $date = $this->get_date_created( $context ); |
| 177 | 177 | |
| 178 | 178 | if ( $date ) { |
| 179 | 179 | $date = get_gmt_from_date( $date ); |
| 180 | 180 | } |
| 181 | - return $date; |
|
| 181 | + return $date; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Get date when the item was last modified. |
|
| 186 | - * |
|
| 187 | - * @since 1.0.19 |
|
| 188 | - * @param string $context View or edit context. |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 191 | - public function get_date_modified( $context = 'view' ) { |
|
| 192 | - return $this->get_prop( 'date_modified', $context ); |
|
| 185 | + * Get date when the item was last modified. |
|
| 186 | + * |
|
| 187 | + * @since 1.0.19 |
|
| 188 | + * @param string $context View or edit context. |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | + public function get_date_modified( $context = 'view' ) { |
|
| 192 | + return $this->get_prop( 'date_modified', $context ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Get GMT date when the item was last modified. |
|
| 197 | - * |
|
| 198 | - * @since 1.0.19 |
|
| 199 | - * @param string $context View or edit context. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 196 | + * Get GMT date when the item was last modified. |
|
| 197 | + * |
|
| 198 | + * @since 1.0.19 |
|
| 199 | + * @param string $context View or edit context. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 203 | 203 | $date = $this->get_date_modified( $context ); |
| 204 | 204 | |
| 205 | 205 | if ( $date ) { |
| 206 | 206 | $date = get_gmt_from_date( $date ); |
| 207 | 207 | } |
| 208 | - return $date; |
|
| 208 | + return $date; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | - * Get the item name. |
|
| 213 | - * |
|
| 214 | - * @since 1.0.19 |
|
| 215 | - * @param string $context View or edit context. |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function get_name( $context = 'view' ) { |
|
| 219 | - return $this->get_prop( 'name', $context ); |
|
| 212 | + * Get the item name. |
|
| 213 | + * |
|
| 214 | + * @since 1.0.19 |
|
| 215 | + * @param string $context View or edit context. |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function get_name( $context = 'view' ) { |
|
| 219 | + return $this->get_prop( 'name', $context ); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | - * Alias of self::get_name(). |
|
| 224 | - * |
|
| 225 | - * @since 1.0.19 |
|
| 226 | - * @param string $context View or edit context. |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public function get_title( $context = 'view' ) { |
|
| 230 | - return $this->get_name( $context ); |
|
| 223 | + * Alias of self::get_name(). |
|
| 224 | + * |
|
| 225 | + * @since 1.0.19 |
|
| 226 | + * @param string $context View or edit context. |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public function get_title( $context = 'view' ) { |
|
| 230 | + return $this->get_name( $context ); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | - * Get the item description. |
|
| 235 | - * |
|
| 236 | - * @since 1.0.19 |
|
| 237 | - * @param string $context View or edit context. |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - public function get_description( $context = 'view' ) { |
|
| 241 | - return $this->get_prop( 'description', $context ); |
|
| 234 | + * Get the item description. |
|
| 235 | + * |
|
| 236 | + * @since 1.0.19 |
|
| 237 | + * @param string $context View or edit context. |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + public function get_description( $context = 'view' ) { |
|
| 241 | + return $this->get_prop( 'description', $context ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * Alias of self::get_description(). |
|
| 246 | - * |
|
| 247 | - * @since 1.0.19 |
|
| 248 | - * @param string $context View or edit context. |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function get_excerpt( $context = 'view' ) { |
|
| 252 | - return $this->get_description( $context ); |
|
| 245 | + * Alias of self::get_description(). |
|
| 246 | + * |
|
| 247 | + * @since 1.0.19 |
|
| 248 | + * @param string $context View or edit context. |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function get_excerpt( $context = 'view' ) { |
|
| 252 | + return $this->get_description( $context ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | - * Alias of self::get_description(). |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - * @param string $context View or edit context. |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function get_summary( $context = 'view' ) { |
|
| 263 | - return $this->get_description( $context ); |
|
| 256 | + * Alias of self::get_description(). |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + * @param string $context View or edit context. |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function get_summary( $context = 'view' ) { |
|
| 263 | + return $this->get_description( $context ); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | - * Get the owner of the item. |
|
| 268 | - * |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @param string $context View or edit context. |
|
| 271 | - * @return int |
|
| 272 | - */ |
|
| 273 | - public function get_author( $context = 'view' ) { |
|
| 274 | - return (int) $this->get_prop( 'author', $context ); |
|
| 275 | - } |
|
| 267 | + * Get the owner of the item. |
|
| 268 | + * |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @param string $context View or edit context. |
|
| 271 | + * @return int |
|
| 272 | + */ |
|
| 273 | + public function get_author( $context = 'view' ) { |
|
| 274 | + return (int) $this->get_prop( 'author', $context ); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Alias of self::get_author(). |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @param string $context View or edit context. |
|
| 282 | - * @return int |
|
| 283 | - */ |
|
| 284 | - public function get_owner( $context = 'view' ) { |
|
| 285 | - return $this->get_author( $context ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Get the price of the item. |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @param string $context View or edit context. |
|
| 293 | - * @return float |
|
| 294 | - */ |
|
| 295 | - public function get_price( $context = 'view' ) { |
|
| 277 | + /** |
|
| 278 | + * Alias of self::get_author(). |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @param string $context View or edit context. |
|
| 282 | + * @return int |
|
| 283 | + */ |
|
| 284 | + public function get_owner( $context = 'view' ) { |
|
| 285 | + return $this->get_author( $context ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Get the price of the item. |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @param string $context View or edit context. |
|
| 293 | + * @return float |
|
| 294 | + */ |
|
| 295 | + public function get_price( $context = 'view' ) { |
|
| 296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
| 297 | - } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Get the inital price of the item. |
|
| 301 | - * |
|
| 302 | - * @since 1.0.19 |
|
| 303 | - * @param string $context View or edit context. |
|
| 304 | - * @return float |
|
| 305 | - */ |
|
| 306 | - public function get_initial_price( $context = 'view' ) { |
|
| 299 | + /** |
|
| 300 | + * Get the inital price of the item. |
|
| 301 | + * |
|
| 302 | + * @since 1.0.19 |
|
| 303 | + * @param string $context View or edit context. |
|
| 304 | + * @return float |
|
| 305 | + */ |
|
| 306 | + public function get_initial_price( $context = 'view' ) { |
|
| 307 | 307 | |
| 308 | - $price = (float) $this->get_price( $context ); |
|
| 308 | + $price = (float) $this->get_price( $context ); |
|
| 309 | 309 | |
| 310 | - if ( $this->has_free_trial() ) { |
|
| 311 | - $price = 0; |
|
| 312 | - } |
|
| 310 | + if ( $this->has_free_trial() ) { |
|
| 311 | + $price = 0; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | - * Returns a formated price. |
|
| 319 | - * |
|
| 320 | - * @since 1.0.19 |
|
| 321 | - * @param string $context View or edit context. |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 318 | + * Returns a formated price. |
|
| 319 | + * |
|
| 320 | + * @since 1.0.19 |
|
| 321 | + * @param string $context View or edit context. |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | 324 | public function get_the_price() { |
| 325 | 325 | return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Returns the formated initial price. |
|
| 330 | - * |
|
| 331 | - * @since 1.0.19 |
|
| 332 | - * @param string $context View or edit context. |
|
| 333 | - * @return string |
|
| 334 | - */ |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Returns the formated initial price. |
|
| 330 | + * |
|
| 331 | + * @since 1.0.19 |
|
| 332 | + * @param string $context View or edit context. |
|
| 333 | + * @return string |
|
| 334 | + */ |
|
| 335 | 335 | public function get_the_initial_price() { |
| 336 | 336 | return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | - * Get the VAT rule of the item. |
|
| 341 | - * |
|
| 342 | - * @since 1.0.19 |
|
| 343 | - * @param string $context View or edit context. |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public function get_vat_rule( $context = 'view' ) { |
|
| 340 | + * Get the VAT rule of the item. |
|
| 341 | + * |
|
| 342 | + * @since 1.0.19 |
|
| 343 | + * @param string $context View or edit context. |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public function get_vat_rule( $context = 'view' ) { |
|
| 347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
| 351 | - * Get the VAT class of the item. |
|
| 352 | - * |
|
| 353 | - * @since 1.0.19 |
|
| 354 | - * @param string $context View or edit context. |
|
| 355 | - * @return string |
|
| 356 | - */ |
|
| 357 | - public function get_vat_class( $context = 'view' ) { |
|
| 351 | + * Get the VAT class of the item. |
|
| 352 | + * |
|
| 353 | + * @since 1.0.19 |
|
| 354 | + * @param string $context View or edit context. |
|
| 355 | + * @return string |
|
| 356 | + */ |
|
| 357 | + public function get_vat_class( $context = 'view' ) { |
|
| 358 | 358 | return $this->get_prop( 'vat_class', $context ); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | - * Get the type of the item. |
|
| 363 | - * |
|
| 364 | - * @since 1.0.19 |
|
| 365 | - * @param string $context View or edit context. |
|
| 366 | - * @return string |
|
| 367 | - */ |
|
| 368 | - public function get_type( $context = 'view' ) { |
|
| 362 | + * Get the type of the item. |
|
| 363 | + * |
|
| 364 | + * @since 1.0.19 |
|
| 365 | + * @param string $context View or edit context. |
|
| 366 | + * @return string |
|
| 367 | + */ |
|
| 368 | + public function get_type( $context = 'view' ) { |
|
| 369 | 369 | return $this->get_prop( 'type', $context ); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | - * Get the custom id of the item. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $context View or edit context. |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_custom_id( $context = 'view' ) { |
|
| 373 | + * Get the custom id of the item. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $context View or edit context. |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_custom_id( $context = 'view' ) { |
|
| 380 | 380 | return $this->get_prop( 'custom_id', $context ); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
| 384 | - * Get the custom name of the item. |
|
| 385 | - * |
|
| 386 | - * @since 1.0.19 |
|
| 387 | - * @param string $context View or edit context. |
|
| 388 | - * @return string |
|
| 389 | - */ |
|
| 390 | - public function get_custom_name( $context = 'view' ) { |
|
| 384 | + * Get the custom name of the item. |
|
| 385 | + * |
|
| 386 | + * @since 1.0.19 |
|
| 387 | + * @param string $context View or edit context. |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 390 | + public function get_custom_name( $context = 'view' ) { |
|
| 391 | 391 | return $this->get_prop( 'custom_name', $context ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
| 395 | - * Get the custom singular name of the item. |
|
| 396 | - * |
|
| 397 | - * @since 1.0.19 |
|
| 398 | - * @param string $context View or edit context. |
|
| 399 | - * @return string |
|
| 400 | - */ |
|
| 401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
| 395 | + * Get the custom singular name of the item. |
|
| 396 | + * |
|
| 397 | + * @since 1.0.19 |
|
| 398 | + * @param string $context View or edit context. |
|
| 399 | + * @return string |
|
| 400 | + */ |
|
| 401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
| 402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
| 406 | - * Checks if an item is editable.. |
|
| 407 | - * |
|
| 408 | - * @since 1.0.19 |
|
| 409 | - * @param string $context View or edit context. |
|
| 410 | - * @return int |
|
| 411 | - */ |
|
| 412 | - public function get_is_editable( $context = 'view' ) { |
|
| 406 | + * Checks if an item is editable.. |
|
| 407 | + * |
|
| 408 | + * @since 1.0.19 |
|
| 409 | + * @param string $context View or edit context. |
|
| 410 | + * @return int |
|
| 411 | + */ |
|
| 412 | + public function get_is_editable( $context = 'view' ) { |
|
| 413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
| 417 | - * Alias of self::get_is_editable(). |
|
| 418 | - * |
|
| 419 | - * @since 1.0.19 |
|
| 420 | - * @param string $context View or edit context. |
|
| 421 | - * @return int |
|
| 422 | - */ |
|
| 423 | - public function get_editable( $context = 'view' ) { |
|
| 424 | - return $this->get_is_editable( $context ); |
|
| 417 | + * Alias of self::get_is_editable(). |
|
| 418 | + * |
|
| 419 | + * @since 1.0.19 |
|
| 420 | + * @param string $context View or edit context. |
|
| 421 | + * @return int |
|
| 422 | + */ |
|
| 423 | + public function get_editable( $context = 'view' ) { |
|
| 424 | + return $this->get_is_editable( $context ); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | - * Checks if dynamic pricing is enabled. |
|
| 429 | - * |
|
| 430 | - * @since 1.0.19 |
|
| 431 | - * @param string $context View or edit context. |
|
| 432 | - * @return int |
|
| 433 | - */ |
|
| 434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 428 | + * Checks if dynamic pricing is enabled. |
|
| 429 | + * |
|
| 430 | + * @since 1.0.19 |
|
| 431 | + * @param string $context View or edit context. |
|
| 432 | + * @return int |
|
| 433 | + */ |
|
| 434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
| 439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
| 440 | - * |
|
| 441 | - * @since 1.0.19 |
|
| 442 | - * @param string $context View or edit context. |
|
| 443 | - * @return float |
|
| 444 | - */ |
|
| 445 | - public function get_minimum_price( $context = 'view' ) { |
|
| 439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
| 440 | + * |
|
| 441 | + * @since 1.0.19 |
|
| 442 | + * @param string $context View or edit context. |
|
| 443 | + * @return float |
|
| 444 | + */ |
|
| 445 | + public function get_minimum_price( $context = 'view' ) { |
|
| 446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
| 450 | - * Checks if this is a recurring item. |
|
| 451 | - * |
|
| 452 | - * @since 1.0.19 |
|
| 453 | - * @param string $context View or edit context. |
|
| 454 | - * @return int |
|
| 455 | - */ |
|
| 456 | - public function get_is_recurring( $context = 'view' ) { |
|
| 450 | + * Checks if this is a recurring item. |
|
| 451 | + * |
|
| 452 | + * @since 1.0.19 |
|
| 453 | + * @param string $context View or edit context. |
|
| 454 | + * @return int |
|
| 455 | + */ |
|
| 456 | + public function get_is_recurring( $context = 'view' ) { |
|
| 457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - /** |
|
| 461 | - * Get the recurring price of the item. |
|
| 462 | - * |
|
| 463 | - * @since 1.0.19 |
|
| 464 | - * @param string $context View or edit context. |
|
| 465 | - * @return float |
|
| 466 | - */ |
|
| 467 | - public function get_recurring_price( $context = 'view' ) { |
|
| 468 | - $price = $this->get_price( $context ); |
|
| 460 | + /** |
|
| 461 | + * Get the recurring price of the item. |
|
| 462 | + * |
|
| 463 | + * @since 1.0.19 |
|
| 464 | + * @param string $context View or edit context. |
|
| 465 | + * @return float |
|
| 466 | + */ |
|
| 467 | + public function get_recurring_price( $context = 'view' ) { |
|
| 468 | + $price = $this->get_price( $context ); |
|
| 469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Get the formatted recurring price of the item. |
|
| 474 | - * |
|
| 475 | - * @since 1.0.19 |
|
| 476 | - * @param string $context View or edit context. |
|
| 477 | - * @return string |
|
| 478 | - */ |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Get the formatted recurring price of the item. |
|
| 474 | + * |
|
| 475 | + * @since 1.0.19 |
|
| 476 | + * @param string $context View or edit context. |
|
| 477 | + * @return string |
|
| 478 | + */ |
|
| 479 | 479 | public function get_the_recurring_price() { |
| 480 | 480 | return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) ); |
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Get the first renewal date (in timestamps) of the item. |
|
| 485 | - * |
|
| 486 | - * @since 1.0.19 |
|
| 487 | - * @return int |
|
| 488 | - */ |
|
| 489 | - public function get_first_renewal_date() { |
|
| 490 | - |
|
| 491 | - $periods = array( |
|
| 492 | - 'D' => 'days', |
|
| 493 | - 'W' => 'weeks', |
|
| 494 | - 'M' => 'months', |
|
| 495 | - 'Y' => 'years', |
|
| 496 | - ); |
|
| 497 | - |
|
| 498 | - $period = $this->get_recurring_period(); |
|
| 499 | - $interval = $this->get_recurring_interval(); |
|
| 500 | - |
|
| 501 | - if ( $this->has_free_trial() ) { |
|
| 502 | - $period = $this->get_trial_period(); |
|
| 503 | - $interval = $this->get_trial_interval(); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - $period = $periods[ $period ]; |
|
| 507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Get the first renewal date (in timestamps) of the item. |
|
| 485 | + * |
|
| 486 | + * @since 1.0.19 |
|
| 487 | + * @return int |
|
| 488 | + */ |
|
| 489 | + public function get_first_renewal_date() { |
|
| 490 | + |
|
| 491 | + $periods = array( |
|
| 492 | + 'D' => 'days', |
|
| 493 | + 'W' => 'weeks', |
|
| 494 | + 'M' => 'months', |
|
| 495 | + 'Y' => 'years', |
|
| 496 | + ); |
|
| 497 | + |
|
| 498 | + $period = $this->get_recurring_period(); |
|
| 499 | + $interval = $this->get_recurring_interval(); |
|
| 500 | + |
|
| 501 | + if ( $this->has_free_trial() ) { |
|
| 502 | + $period = $this->get_trial_period(); |
|
| 503 | + $interval = $this->get_trial_interval(); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + $period = $periods[ $period ]; |
|
| 507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
| 513 | - * Get the recurring period. |
|
| 514 | - * |
|
| 515 | - * @since 1.0.19 |
|
| 516 | - * @param bool $full Return abbreviation or in full. |
|
| 517 | - * @return string |
|
| 518 | - */ |
|
| 519 | - public function get_recurring_period( $full = false ) { |
|
| 513 | + * Get the recurring period. |
|
| 514 | + * |
|
| 515 | + * @since 1.0.19 |
|
| 516 | + * @param bool $full Return abbreviation or in full. |
|
| 517 | + * @return string |
|
| 518 | + */ |
|
| 519 | + public function get_recurring_period( $full = false ) { |
|
| 520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
| 521 | 521 | |
| 522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,63 +527,63 @@ discard block |
||
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
| 530 | - * Get the recurring interval. |
|
| 531 | - * |
|
| 532 | - * @since 1.0.19 |
|
| 533 | - * @param string $context View or edit context. |
|
| 534 | - * @return int |
|
| 535 | - */ |
|
| 536 | - public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 530 | + * Get the recurring interval. |
|
| 531 | + * |
|
| 532 | + * @since 1.0.19 |
|
| 533 | + * @param string $context View or edit context. |
|
| 534 | + * @return int |
|
| 535 | + */ |
|
| 536 | + public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 538 | 538 | |
| 539 | - if ( $interval < 1 ) { |
|
| 540 | - $interval = 1; |
|
| 541 | - } |
|
| 539 | + if ( $interval < 1 ) { |
|
| 540 | + $interval = 1; |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | 543 | return $interval; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
| 547 | - * Get the recurring limit. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param string $context View or edit context. |
|
| 551 | - * @return int |
|
| 552 | - */ |
|
| 553 | - public function get_recurring_limit( $context = 'view' ) { |
|
| 547 | + * Get the recurring limit. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param string $context View or edit context. |
|
| 551 | + * @return int |
|
| 552 | + */ |
|
| 553 | + public function get_recurring_limit( $context = 'view' ) { |
|
| 554 | 554 | return (int) $this->get_prop( 'recurring_limit', $context ); |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
| 558 | - * Checks if we have a free trial. |
|
| 559 | - * |
|
| 560 | - * @since 1.0.19 |
|
| 561 | - * @param string $context View or edit context. |
|
| 562 | - * @return int |
|
| 563 | - */ |
|
| 564 | - public function get_is_free_trial( $context = 'view' ) { |
|
| 558 | + * Checks if we have a free trial. |
|
| 559 | + * |
|
| 560 | + * @since 1.0.19 |
|
| 561 | + * @param string $context View or edit context. |
|
| 562 | + * @return int |
|
| 563 | + */ |
|
| 564 | + public function get_is_free_trial( $context = 'view' ) { |
|
| 565 | 565 | return (int) $this->get_prop( 'is_free_trial', $context ); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
| 569 | - * Alias for self::get_is_free_trial(). |
|
| 570 | - * |
|
| 571 | - * @since 1.0.19 |
|
| 572 | - * @param string $context View or edit context. |
|
| 573 | - * @return int |
|
| 574 | - */ |
|
| 575 | - public function get_free_trial( $context = 'view' ) { |
|
| 569 | + * Alias for self::get_is_free_trial(). |
|
| 570 | + * |
|
| 571 | + * @since 1.0.19 |
|
| 572 | + * @param string $context View or edit context. |
|
| 573 | + * @return int |
|
| 574 | + */ |
|
| 575 | + public function get_free_trial( $context = 'view' ) { |
|
| 576 | 576 | return $this->get_is_free_trial( $context ); |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
| 580 | - * Get the trial period. |
|
| 581 | - * |
|
| 582 | - * @since 1.0.19 |
|
| 583 | - * @param bool $full Return abbreviation or in full. |
|
| 584 | - * @return string |
|
| 585 | - */ |
|
| 586 | - public function get_trial_period( $full = false ) { |
|
| 580 | + * Get the trial period. |
|
| 581 | + * |
|
| 582 | + * @since 1.0.19 |
|
| 583 | + * @param bool $full Return abbreviation or in full. |
|
| 584 | + * @return string |
|
| 585 | + */ |
|
| 586 | + public function get_trial_period( $full = false ) { |
|
| 587 | 587 | $period = $this->get_prop( 'trial_period', 'view' ); |
| 588 | 588 | |
| 589 | 589 | if ( $full && ! is_bool( $full ) ) { |
@@ -594,104 +594,104 @@ discard block |
||
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
| 597 | - * Get the trial interval. |
|
| 598 | - * |
|
| 599 | - * @since 1.0.19 |
|
| 600 | - * @param string $context View or edit context. |
|
| 601 | - * @return int |
|
| 602 | - */ |
|
| 603 | - public function get_trial_interval( $context = 'view' ) { |
|
| 597 | + * Get the trial interval. |
|
| 598 | + * |
|
| 599 | + * @since 1.0.19 |
|
| 600 | + * @param string $context View or edit context. |
|
| 601 | + * @return int |
|
| 602 | + */ |
|
| 603 | + public function get_trial_interval( $context = 'view' ) { |
|
| 604 | 604 | return (int) $this->get_prop( 'trial_interval', $context ); |
| 605 | - } |
|
| 605 | + } |
|
| 606 | 606 | |
| 607 | - /** |
|
| 608 | - * Get the item's edit url. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @return string |
|
| 612 | - */ |
|
| 613 | - public function get_edit_url() { |
|
| 607 | + /** |
|
| 608 | + * Get the item's edit url. |
|
| 609 | + * |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @return string |
|
| 612 | + */ |
|
| 613 | + public function get_edit_url() { |
|
| 614 | 614 | return get_edit_post_link( $this->get_id() ); |
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Given an item's name/custom id, it returns its id. |
|
| 619 | - * |
|
| 620 | - * |
|
| 621 | - * @static |
|
| 622 | - * @param string $value The item name or custom id. |
|
| 623 | - * @param string $field Either name or custom_id. |
|
| 624 | - * @param string $type in case you need to search for a given type. |
|
| 625 | - * @since 1.0.15 |
|
| 626 | - * @return int |
|
| 627 | - */ |
|
| 628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 629 | - |
|
| 630 | - // Trim the value. |
|
| 631 | - $value = sanitize_text_field( $value ); |
|
| 632 | - if ( empty( $value ) ) { |
|
| 633 | - return 0; |
|
| 634 | - } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Given an item's name/custom id, it returns its id. |
|
| 619 | + * |
|
| 620 | + * |
|
| 621 | + * @static |
|
| 622 | + * @param string $value The item name or custom id. |
|
| 623 | + * @param string $field Either name or custom_id. |
|
| 624 | + * @param string $type in case you need to search for a given type. |
|
| 625 | + * @since 1.0.15 |
|
| 626 | + * @return int |
|
| 627 | + */ |
|
| 628 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 629 | + |
|
| 630 | + // Trim the value. |
|
| 631 | + $value = sanitize_text_field( $value ); |
|
| 632 | + if ( empty( $value ) ) { |
|
| 633 | + return 0; |
|
| 634 | + } |
|
| 635 | 635 | |
| 636 | 636 | // Valid fields. |
| 637 | 637 | $fields = array( 'custom_id', 'name', 'slug' ); |
| 638 | 638 | |
| 639 | - // Ensure a field has been passed. |
|
| 640 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 641 | - return 0; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if ( $field == 'name' ) { |
|
| 645 | - $field = 'slug'; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - // Maybe retrieve from the cache. |
|
| 649 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 650 | - if ( ! empty( $item_id ) ) { |
|
| 651 | - return $item_id; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - // Fetch from the db. |
|
| 655 | - $items = array(); |
|
| 656 | - if ( $field == 'slug' ) { |
|
| 657 | - $items = get_posts( |
|
| 658 | - array( |
|
| 659 | - 'post_type' => 'wpi_item', |
|
| 660 | - 'name' => $value, |
|
| 661 | - 'posts_per_page' => 1, |
|
| 662 | - 'post_status' => 'any', |
|
| 663 | - ) |
|
| 664 | - ); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - if ( $field =='custom_id' ) { |
|
| 668 | - $items = get_posts( |
|
| 669 | - array( |
|
| 670 | - 'post_type' => 'wpi_item', |
|
| 671 | - 'posts_per_page' => 1, |
|
| 672 | - 'post_status' => 'any', |
|
| 673 | - 'meta_query' => array( |
|
| 674 | - array( |
|
| 675 | - 'key' => '_wpinv_type', |
|
| 676 | - 'value' => $type, |
|
| 677 | - ), |
|
| 678 | - array( |
|
| 679 | - 'key' => '_wpinv_custom_id', |
|
| 680 | - 'value' => $value, |
|
| 681 | - ) |
|
| 682 | - ) |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - if ( empty( $items ) ) { |
|
| 688 | - return 0; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - // Update the cache with our data |
|
| 692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 693 | - |
|
| 694 | - return $items[0]->ID; |
|
| 639 | + // Ensure a field has been passed. |
|
| 640 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 641 | + return 0; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if ( $field == 'name' ) { |
|
| 645 | + $field = 'slug'; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + // Maybe retrieve from the cache. |
|
| 649 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 650 | + if ( ! empty( $item_id ) ) { |
|
| 651 | + return $item_id; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + // Fetch from the db. |
|
| 655 | + $items = array(); |
|
| 656 | + if ( $field == 'slug' ) { |
|
| 657 | + $items = get_posts( |
|
| 658 | + array( |
|
| 659 | + 'post_type' => 'wpi_item', |
|
| 660 | + 'name' => $value, |
|
| 661 | + 'posts_per_page' => 1, |
|
| 662 | + 'post_status' => 'any', |
|
| 663 | + ) |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + if ( $field =='custom_id' ) { |
|
| 668 | + $items = get_posts( |
|
| 669 | + array( |
|
| 670 | + 'post_type' => 'wpi_item', |
|
| 671 | + 'posts_per_page' => 1, |
|
| 672 | + 'post_status' => 'any', |
|
| 673 | + 'meta_query' => array( |
|
| 674 | + array( |
|
| 675 | + 'key' => '_wpinv_type', |
|
| 676 | + 'value' => $type, |
|
| 677 | + ), |
|
| 678 | + array( |
|
| 679 | + 'key' => '_wpinv_custom_id', |
|
| 680 | + 'value' => $value, |
|
| 681 | + ) |
|
| 682 | + ) |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + if ( empty( $items ) ) { |
|
| 688 | + return 0; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + // Update the cache with our data |
|
| 692 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 693 | + |
|
| 694 | + return $items[0]->ID; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -724,52 +724,52 @@ discard block |
||
| 724 | 724 | */ |
| 725 | 725 | |
| 726 | 726 | /** |
| 727 | - * Set parent order ID. |
|
| 728 | - * |
|
| 729 | - * @since 1.0.19 |
|
| 730 | - */ |
|
| 731 | - public function set_parent_id( $value ) { |
|
| 732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 733 | - return; |
|
| 734 | - } |
|
| 735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * Sets item status. |
|
| 740 | - * |
|
| 741 | - * @since 1.0.19 |
|
| 742 | - * @param string $status New status. |
|
| 743 | - * @return array details of change. |
|
| 744 | - */ |
|
| 745 | - public function set_status( $status ) { |
|
| 727 | + * Set parent order ID. |
|
| 728 | + * |
|
| 729 | + * @since 1.0.19 |
|
| 730 | + */ |
|
| 731 | + public function set_parent_id( $value ) { |
|
| 732 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 733 | + return; |
|
| 734 | + } |
|
| 735 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * Sets item status. |
|
| 740 | + * |
|
| 741 | + * @since 1.0.19 |
|
| 742 | + * @param string $status New status. |
|
| 743 | + * @return array details of change. |
|
| 744 | + */ |
|
| 745 | + public function set_status( $status ) { |
|
| 746 | 746 | $old_status = $this->get_status(); |
| 747 | 747 | |
| 748 | 748 | $this->set_prop( 'status', $status ); |
| 749 | 749 | |
| 750 | - return array( |
|
| 751 | - 'from' => $old_status, |
|
| 752 | - 'to' => $status, |
|
| 753 | - ); |
|
| 750 | + return array( |
|
| 751 | + 'from' => $old_status, |
|
| 752 | + 'to' => $status, |
|
| 753 | + ); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | /** |
| 757 | - * Set plugin version when the item was created. |
|
| 758 | - * |
|
| 759 | - * @since 1.0.19 |
|
| 760 | - */ |
|
| 761 | - public function set_version( $value ) { |
|
| 762 | - $this->set_prop( 'version', $value ); |
|
| 757 | + * Set plugin version when the item was created. |
|
| 758 | + * |
|
| 759 | + * @since 1.0.19 |
|
| 760 | + */ |
|
| 761 | + public function set_version( $value ) { |
|
| 762 | + $this->set_prop( 'version', $value ); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
| 766 | - * Set date when the item was created. |
|
| 767 | - * |
|
| 768 | - * @since 1.0.19 |
|
| 769 | - * @param string $value Value to set. |
|
| 766 | + * Set date when the item was created. |
|
| 767 | + * |
|
| 768 | + * @since 1.0.19 |
|
| 769 | + * @param string $value Value to set. |
|
| 770 | 770 | * @return bool Whether or not the date was set. |
| 771 | - */ |
|
| 772 | - public function set_date_created( $value ) { |
|
| 771 | + */ |
|
| 772 | + public function set_date_created( $value ) { |
|
| 773 | 773 | $date = strtotime( $value ); |
| 774 | 774 | |
| 775 | 775 | if ( $date ) { |
@@ -782,13 +782,13 @@ discard block |
||
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
| 785 | - * Set date when the item was last modified. |
|
| 786 | - * |
|
| 787 | - * @since 1.0.19 |
|
| 788 | - * @param string $value Value to set. |
|
| 785 | + * Set date when the item was last modified. |
|
| 786 | + * |
|
| 787 | + * @since 1.0.19 |
|
| 788 | + * @param string $value Value to set. |
|
| 789 | 789 | * @return bool Whether or not the date was set. |
| 790 | - */ |
|
| 791 | - public function set_date_modified( $value ) { |
|
| 790 | + */ |
|
| 791 | + public function set_date_modified( $value ) { |
|
| 792 | 792 | $date = strtotime( $value ); |
| 793 | 793 | |
| 794 | 794 | if ( $date ) { |
@@ -801,115 +801,115 @@ discard block |
||
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
| 804 | - * Set the item name. |
|
| 805 | - * |
|
| 806 | - * @since 1.0.19 |
|
| 807 | - * @param string $value New name. |
|
| 808 | - */ |
|
| 809 | - public function set_name( $value ) { |
|
| 804 | + * Set the item name. |
|
| 805 | + * |
|
| 806 | + * @since 1.0.19 |
|
| 807 | + * @param string $value New name. |
|
| 808 | + */ |
|
| 809 | + public function set_name( $value ) { |
|
| 810 | 810 | $name = sanitize_text_field( $value ); |
| 811 | - $this->set_prop( 'name', $name ); |
|
| 811 | + $this->set_prop( 'name', $name ); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
| 815 | - * Alias of self::set_name(). |
|
| 816 | - * |
|
| 817 | - * @since 1.0.19 |
|
| 818 | - * @param string $value New name. |
|
| 819 | - */ |
|
| 820 | - public function set_title( $value ) { |
|
| 821 | - $this->set_name( $value ); |
|
| 815 | + * Alias of self::set_name(). |
|
| 816 | + * |
|
| 817 | + * @since 1.0.19 |
|
| 818 | + * @param string $value New name. |
|
| 819 | + */ |
|
| 820 | + public function set_title( $value ) { |
|
| 821 | + $this->set_name( $value ); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
| 825 | - * Set the item description. |
|
| 826 | - * |
|
| 827 | - * @since 1.0.19 |
|
| 828 | - * @param string $value New description. |
|
| 829 | - */ |
|
| 830 | - public function set_description( $value ) { |
|
| 825 | + * Set the item description. |
|
| 826 | + * |
|
| 827 | + * @since 1.0.19 |
|
| 828 | + * @param string $value New description. |
|
| 829 | + */ |
|
| 830 | + public function set_description( $value ) { |
|
| 831 | 831 | $description = wp_kses_post( $value ); |
| 832 | - return $this->set_prop( 'description', $description ); |
|
| 832 | + return $this->set_prop( 'description', $description ); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /** |
| 836 | - * Alias of self::set_description(). |
|
| 837 | - * |
|
| 838 | - * @since 1.0.19 |
|
| 839 | - * @param string $value New description. |
|
| 840 | - */ |
|
| 841 | - public function set_excerpt( $value ) { |
|
| 842 | - $this->set_description( $value ); |
|
| 836 | + * Alias of self::set_description(). |
|
| 837 | + * |
|
| 838 | + * @since 1.0.19 |
|
| 839 | + * @param string $value New description. |
|
| 840 | + */ |
|
| 841 | + public function set_excerpt( $value ) { |
|
| 842 | + $this->set_description( $value ); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | /** |
| 846 | - * Alias of self::set_description(). |
|
| 847 | - * |
|
| 848 | - * @since 1.0.19 |
|
| 849 | - * @param string $value New description. |
|
| 850 | - */ |
|
| 851 | - public function set_summary( $value ) { |
|
| 852 | - $this->set_description( $value ); |
|
| 846 | + * Alias of self::set_description(). |
|
| 847 | + * |
|
| 848 | + * @since 1.0.19 |
|
| 849 | + * @param string $value New description. |
|
| 850 | + */ |
|
| 851 | + public function set_summary( $value ) { |
|
| 852 | + $this->set_description( $value ); |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | /** |
| 856 | - * Set the owner of the item. |
|
| 857 | - * |
|
| 858 | - * @since 1.0.19 |
|
| 859 | - * @param int $value New author. |
|
| 860 | - */ |
|
| 861 | - public function set_author( $value ) { |
|
| 862 | - $this->set_prop( 'author', (int) $value ); |
|
| 863 | - } |
|
| 856 | + * Set the owner of the item. |
|
| 857 | + * |
|
| 858 | + * @since 1.0.19 |
|
| 859 | + * @param int $value New author. |
|
| 860 | + */ |
|
| 861 | + public function set_author( $value ) { |
|
| 862 | + $this->set_prop( 'author', (int) $value ); |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | - /** |
|
| 866 | - * Alias of self::set_author(). |
|
| 867 | - * |
|
| 868 | - * @since 1.0.19 |
|
| 869 | - * @param int $value New author. |
|
| 870 | - */ |
|
| 871 | - public function set_owner( $value ) { |
|
| 872 | - $this->set_author( $value ); |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * Set the price of the item. |
|
| 877 | - * |
|
| 878 | - * @since 1.0.19 |
|
| 879 | - * @param float $value New price. |
|
| 880 | - */ |
|
| 881 | - public function set_price( $value ) { |
|
| 865 | + /** |
|
| 866 | + * Alias of self::set_author(). |
|
| 867 | + * |
|
| 868 | + * @since 1.0.19 |
|
| 869 | + * @param int $value New author. |
|
| 870 | + */ |
|
| 871 | + public function set_owner( $value ) { |
|
| 872 | + $this->set_author( $value ); |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * Set the price of the item. |
|
| 877 | + * |
|
| 878 | + * @since 1.0.19 |
|
| 879 | + * @param float $value New price. |
|
| 880 | + */ |
|
| 881 | + public function set_price( $value ) { |
|
| 882 | 882 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | /** |
| 886 | - * Set the VAT rule of the item. |
|
| 887 | - * |
|
| 888 | - * @since 1.0.19 |
|
| 889 | - * @param string $value new rule. |
|
| 890 | - */ |
|
| 891 | - public function set_vat_rule( $value ) { |
|
| 886 | + * Set the VAT rule of the item. |
|
| 887 | + * |
|
| 888 | + * @since 1.0.19 |
|
| 889 | + * @param string $value new rule. |
|
| 890 | + */ |
|
| 891 | + public function set_vat_rule( $value ) { |
|
| 892 | 892 | $this->set_prop( 'vat_rule', $value ); |
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
| 896 | - * Set the VAT class of the item. |
|
| 897 | - * |
|
| 898 | - * @since 1.0.19 |
|
| 899 | - * @param string $value new class. |
|
| 900 | - */ |
|
| 901 | - public function set_vat_class( $value ) { |
|
| 896 | + * Set the VAT class of the item. |
|
| 897 | + * |
|
| 898 | + * @since 1.0.19 |
|
| 899 | + * @param string $value new class. |
|
| 900 | + */ |
|
| 901 | + public function set_vat_class( $value ) { |
|
| 902 | 902 | $this->set_prop( 'vat_class', $value ); |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
| 906 | - * Set the type of the item. |
|
| 907 | - * |
|
| 908 | - * @since 1.0.19 |
|
| 909 | - * @param string $value new item type. |
|
| 910 | - * @return string |
|
| 911 | - */ |
|
| 912 | - public function set_type( $value ) { |
|
| 906 | + * Set the type of the item. |
|
| 907 | + * |
|
| 908 | + * @since 1.0.19 |
|
| 909 | + * @param string $value new item type. |
|
| 910 | + * @return string |
|
| 911 | + */ |
|
| 912 | + public function set_type( $value ) { |
|
| 913 | 913 | |
| 914 | 914 | if ( empty( $value ) ) { |
| 915 | 915 | $value = 'custom'; |
@@ -919,132 +919,132 @@ discard block |
||
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | /** |
| 922 | - * Set the custom id of the item. |
|
| 923 | - * |
|
| 924 | - * @since 1.0.19 |
|
| 925 | - * @param string $value new custom id. |
|
| 926 | - */ |
|
| 927 | - public function set_custom_id( $value ) { |
|
| 922 | + * Set the custom id of the item. |
|
| 923 | + * |
|
| 924 | + * @since 1.0.19 |
|
| 925 | + * @param string $value new custom id. |
|
| 926 | + */ |
|
| 927 | + public function set_custom_id( $value ) { |
|
| 928 | 928 | $this->set_prop( 'custom_id', $value ); |
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | /** |
| 932 | - * Set the custom name of the item. |
|
| 933 | - * |
|
| 934 | - * @since 1.0.19 |
|
| 935 | - * @param string $value new custom name. |
|
| 936 | - */ |
|
| 937 | - public function set_custom_name( $value ) { |
|
| 932 | + * Set the custom name of the item. |
|
| 933 | + * |
|
| 934 | + * @since 1.0.19 |
|
| 935 | + * @param string $value new custom name. |
|
| 936 | + */ |
|
| 937 | + public function set_custom_name( $value ) { |
|
| 938 | 938 | $this->set_prop( 'custom_name', $value ); |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
| 942 | - * Set the custom singular name of the item. |
|
| 943 | - * |
|
| 944 | - * @since 1.0.19 |
|
| 945 | - * @param string $value new custom singular name. |
|
| 946 | - */ |
|
| 947 | - public function set_custom_singular_name( $value ) { |
|
| 942 | + * Set the custom singular name of the item. |
|
| 943 | + * |
|
| 944 | + * @since 1.0.19 |
|
| 945 | + * @param string $value new custom singular name. |
|
| 946 | + */ |
|
| 947 | + public function set_custom_singular_name( $value ) { |
|
| 948 | 948 | $this->set_prop( 'custom_singular_name', $value ); |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
| 952 | - * Sets if an item is editable.. |
|
| 953 | - * |
|
| 954 | - * @since 1.0.19 |
|
| 955 | - * @param int|bool $value whether or not the item is editable. |
|
| 956 | - */ |
|
| 957 | - public function set_is_editable( $value ) { |
|
| 958 | - $this->set_prop( 'is_editable', (int) $value ); |
|
| 952 | + * Sets if an item is editable.. |
|
| 953 | + * |
|
| 954 | + * @since 1.0.19 |
|
| 955 | + * @param int|bool $value whether or not the item is editable. |
|
| 956 | + */ |
|
| 957 | + public function set_is_editable( $value ) { |
|
| 958 | + $this->set_prop( 'is_editable', (int) $value ); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
| 962 | - * Sets if dynamic pricing is enabled. |
|
| 963 | - * |
|
| 964 | - * @since 1.0.19 |
|
| 965 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 966 | - */ |
|
| 967 | - public function set_is_dynamic_pricing( $value ) { |
|
| 962 | + * Sets if dynamic pricing is enabled. |
|
| 963 | + * |
|
| 964 | + * @since 1.0.19 |
|
| 965 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 966 | + */ |
|
| 967 | + public function set_is_dynamic_pricing( $value ) { |
|
| 968 | 968 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
| 972 | - * Sets the minimum price if dynamic pricing is enabled. |
|
| 973 | - * |
|
| 974 | - * @since 1.0.19 |
|
| 975 | - * @param float $value minimum price. |
|
| 976 | - */ |
|
| 977 | - public function set_minimum_price( $value ) { |
|
| 972 | + * Sets the minimum price if dynamic pricing is enabled. |
|
| 973 | + * |
|
| 974 | + * @since 1.0.19 |
|
| 975 | + * @param float $value minimum price. |
|
| 976 | + */ |
|
| 977 | + public function set_minimum_price( $value ) { |
|
| 978 | 978 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | /** |
| 982 | - * Sets if this is a recurring item. |
|
| 983 | - * |
|
| 984 | - * @since 1.0.19 |
|
| 985 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 986 | - */ |
|
| 987 | - public function set_is_recurring( $value ) { |
|
| 982 | + * Sets if this is a recurring item. |
|
| 983 | + * |
|
| 984 | + * @since 1.0.19 |
|
| 985 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 986 | + */ |
|
| 987 | + public function set_is_recurring( $value ) { |
|
| 988 | 988 | $this->set_prop( 'is_recurring', (int) $value ); |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
| 992 | - * Set the recurring period. |
|
| 993 | - * |
|
| 994 | - * @since 1.0.19 |
|
| 995 | - * @param string $value new period. |
|
| 996 | - */ |
|
| 997 | - public function set_recurring_period( $value ) { |
|
| 992 | + * Set the recurring period. |
|
| 993 | + * |
|
| 994 | + * @since 1.0.19 |
|
| 995 | + * @param string $value new period. |
|
| 996 | + */ |
|
| 997 | + public function set_recurring_period( $value ) { |
|
| 998 | 998 | $this->set_prop( 'recurring_period', $value ); |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | /** |
| 1002 | - * Set the recurring interval. |
|
| 1003 | - * |
|
| 1004 | - * @since 1.0.19 |
|
| 1005 | - * @param int $value recurring interval. |
|
| 1006 | - */ |
|
| 1007 | - public function set_recurring_interval( $value ) { |
|
| 1002 | + * Set the recurring interval. |
|
| 1003 | + * |
|
| 1004 | + * @since 1.0.19 |
|
| 1005 | + * @param int $value recurring interval. |
|
| 1006 | + */ |
|
| 1007 | + public function set_recurring_interval( $value ) { |
|
| 1008 | 1008 | return $this->set_prop( 'recurring_interval', (int) $value ); |
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | /** |
| 1012 | - * Get the recurring limit. |
|
| 1013 | - * @since 1.0.19 |
|
| 1014 | - * @param int $value The recurring limit. |
|
| 1015 | - * @return int |
|
| 1016 | - */ |
|
| 1017 | - public function set_recurring_limit( $value ) { |
|
| 1012 | + * Get the recurring limit. |
|
| 1013 | + * @since 1.0.19 |
|
| 1014 | + * @param int $value The recurring limit. |
|
| 1015 | + * @return int |
|
| 1016 | + */ |
|
| 1017 | + public function set_recurring_limit( $value ) { |
|
| 1018 | 1018 | $this->set_prop( 'recurring_limit', (int) $value ); |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | /** |
| 1022 | - * Checks if we have a free trial. |
|
| 1023 | - * |
|
| 1024 | - * @since 1.0.19 |
|
| 1025 | - * @param int|bool $value whether or not it has a free trial. |
|
| 1026 | - */ |
|
| 1027 | - public function set_is_free_trial( $value ) { |
|
| 1022 | + * Checks if we have a free trial. |
|
| 1023 | + * |
|
| 1024 | + * @since 1.0.19 |
|
| 1025 | + * @param int|bool $value whether or not it has a free trial. |
|
| 1026 | + */ |
|
| 1027 | + public function set_is_free_trial( $value ) { |
|
| 1028 | 1028 | $this->set_prop( 'is_free_trial', (int) $value ); |
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | /** |
| 1032 | - * Set the trial period. |
|
| 1033 | - * |
|
| 1034 | - * @since 1.0.19 |
|
| 1035 | - * @param string $value trial period. |
|
| 1036 | - */ |
|
| 1037 | - public function set_trial_period( $value ) { |
|
| 1032 | + * Set the trial period. |
|
| 1033 | + * |
|
| 1034 | + * @since 1.0.19 |
|
| 1035 | + * @param string $value trial period. |
|
| 1036 | + */ |
|
| 1037 | + public function set_trial_period( $value ) { |
|
| 1038 | 1038 | $this->set_prop( 'trial_period', $value ); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
| 1042 | - * Set the trial interval. |
|
| 1043 | - * |
|
| 1044 | - * @since 1.0.19 |
|
| 1045 | - * @param int $value trial interval. |
|
| 1046 | - */ |
|
| 1047 | - public function set_trial_interval( $value ) { |
|
| 1042 | + * Set the trial interval. |
|
| 1043 | + * |
|
| 1044 | + * @since 1.0.19 |
|
| 1045 | + * @param int $value trial interval. |
|
| 1046 | + */ |
|
| 1047 | + public function set_trial_interval( $value ) { |
|
| 1048 | 1048 | $this->set_prop( 'trial_interval', $value ); |
| 1049 | 1049 | } |
| 1050 | 1050 | |
@@ -1052,17 +1052,17 @@ discard block |
||
| 1052 | 1052 | * Create an item. For backwards compatibilty. |
| 1053 | 1053 | * |
| 1054 | 1054 | * @deprecated |
| 1055 | - * @return int item id |
|
| 1055 | + * @return int item id |
|
| 1056 | 1056 | */ |
| 1057 | 1057 | public function create( $data = array() ) { |
| 1058 | 1058 | |
| 1059 | - // Set the properties. |
|
| 1060 | - if ( is_array( $data ) ) { |
|
| 1061 | - $this->set_props( $data ); |
|
| 1062 | - } |
|
| 1059 | + // Set the properties. |
|
| 1060 | + if ( is_array( $data ) ) { |
|
| 1061 | + $this->set_props( $data ); |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - // Save the item. |
|
| 1065 | - return $this->save(); |
|
| 1064 | + // Save the item. |
|
| 1065 | + return $this->save(); |
|
| 1066 | 1066 | |
| 1067 | 1067 | } |
| 1068 | 1068 | |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | * Updates an item. For backwards compatibilty. |
| 1071 | 1071 | * |
| 1072 | 1072 | * @deprecated |
| 1073 | - * @return int item id |
|
| 1073 | + * @return int item id |
|
| 1074 | 1074 | */ |
| 1075 | 1075 | public function update( $data = array() ) { |
| 1076 | 1076 | return $this->create( $data ); |
@@ -1086,84 +1086,84 @@ discard block |
||
| 1086 | 1086 | */ |
| 1087 | 1087 | |
| 1088 | 1088 | /** |
| 1089 | - * Checks whether the item has enabled dynamic pricing. |
|
| 1090 | - * |
|
| 1091 | - * @since 1.0.19 |
|
| 1092 | - * @return bool |
|
| 1093 | - */ |
|
| 1094 | - public function user_can_set_their_price() { |
|
| 1089 | + * Checks whether the item has enabled dynamic pricing. |
|
| 1090 | + * |
|
| 1091 | + * @since 1.0.19 |
|
| 1092 | + * @return bool |
|
| 1093 | + */ |
|
| 1094 | + public function user_can_set_their_price() { |
|
| 1095 | 1095 | return (bool) $this->get_is_dynamic_pricing(); |
| 1096 | - } |
|
| 1096 | + } |
|
| 1097 | 1097 | |
| 1098 | - /** |
|
| 1099 | - * Checks whether the item is recurring. |
|
| 1100 | - * |
|
| 1101 | - * @since 1.0.19 |
|
| 1102 | - * @return bool |
|
| 1103 | - */ |
|
| 1104 | - public function is_recurring() { |
|
| 1098 | + /** |
|
| 1099 | + * Checks whether the item is recurring. |
|
| 1100 | + * |
|
| 1101 | + * @since 1.0.19 |
|
| 1102 | + * @return bool |
|
| 1103 | + */ |
|
| 1104 | + public function is_recurring() { |
|
| 1105 | 1105 | return (bool) $this->get_is_recurring(); |
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
| 1109 | - * Checks whether the item has a free trial. |
|
| 1110 | - * |
|
| 1111 | - * @since 1.0.19 |
|
| 1112 | - * @return bool |
|
| 1113 | - */ |
|
| 1109 | + * Checks whether the item has a free trial. |
|
| 1110 | + * |
|
| 1111 | + * @since 1.0.19 |
|
| 1112 | + * @return bool |
|
| 1113 | + */ |
|
| 1114 | 1114 | public function has_free_trial() { |
| 1115 | 1115 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
| 1116 | 1116 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | /** |
| 1120 | - * Checks whether the item is free. |
|
| 1121 | - * |
|
| 1122 | - * @since 1.0.19 |
|
| 1123 | - * @return bool |
|
| 1124 | - */ |
|
| 1120 | + * Checks whether the item is free. |
|
| 1121 | + * |
|
| 1122 | + * @since 1.0.19 |
|
| 1123 | + * @return bool |
|
| 1124 | + */ |
|
| 1125 | 1125 | public function is_free() { |
| 1126 | 1126 | $is_free = $this->get_price() == 0; |
| 1127 | 1127 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | /** |
| 1131 | - * Checks the item status against a passed in status. |
|
| 1132 | - * |
|
| 1133 | - * @param array|string $status Status to check. |
|
| 1134 | - * @return bool |
|
| 1135 | - */ |
|
| 1136 | - public function has_status( $status ) { |
|
| 1137 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1138 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1131 | + * Checks the item status against a passed in status. |
|
| 1132 | + * |
|
| 1133 | + * @param array|string $status Status to check. |
|
| 1134 | + * @return bool |
|
| 1135 | + */ |
|
| 1136 | + public function has_status( $status ) { |
|
| 1137 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1138 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | /** |
| 1142 | - * Checks the item type against a passed in types. |
|
| 1143 | - * |
|
| 1144 | - * @param array|string $type Type to check. |
|
| 1145 | - * @return bool |
|
| 1146 | - */ |
|
| 1147 | - public function is_type( $type ) { |
|
| 1148 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1149 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1150 | - } |
|
| 1142 | + * Checks the item type against a passed in types. |
|
| 1143 | + * |
|
| 1144 | + * @param array|string $type Type to check. |
|
| 1145 | + * @return bool |
|
| 1146 | + */ |
|
| 1147 | + public function is_type( $type ) { |
|
| 1148 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1149 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1150 | + } |
|
| 1151 | 1151 | |
| 1152 | 1152 | /** |
| 1153 | - * Checks whether the item is editable. |
|
| 1154 | - * |
|
| 1155 | - * @since 1.0.19 |
|
| 1156 | - * @return bool |
|
| 1157 | - */ |
|
| 1153 | + * Checks whether the item is editable. |
|
| 1154 | + * |
|
| 1155 | + * @since 1.0.19 |
|
| 1156 | + * @return bool |
|
| 1157 | + */ |
|
| 1158 | 1158 | public function is_editable() { |
| 1159 | 1159 | $is_editable = $this->get_is_editable(); |
| 1160 | 1160 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
| 1161 | - } |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | - /** |
|
| 1164 | - * Returns an array of cart fees. |
|
| 1165 | - */ |
|
| 1166 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
| 1163 | + /** |
|
| 1164 | + * Returns an array of cart fees. |
|
| 1165 | + */ |
|
| 1166 | + public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
| 1167 | 1167 | |
| 1168 | 1168 | $fees = getpaid_session()->get( 'wpi_cart_fees' ); |
| 1169 | 1169 | |
@@ -1206,11 +1206,11 @@ discard block |
||
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | 1208 | /** |
| 1209 | - * Checks whether the item is purchasable. |
|
| 1210 | - * |
|
| 1211 | - * @since 1.0.19 |
|
| 1212 | - * @return bool |
|
| 1213 | - */ |
|
| 1209 | + * Checks whether the item is purchasable. |
|
| 1210 | + * |
|
| 1211 | + * @since 1.0.19 |
|
| 1212 | + * @return bool |
|
| 1213 | + */ |
|
| 1214 | 1214 | public function can_purchase() { |
| 1215 | 1215 | $can_purchase = $this->exists(); |
| 1216 | 1216 | |
@@ -1222,11 +1222,11 @@ discard block |
||
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | 1224 | /** |
| 1225 | - * Checks whether the item supports dynamic pricing. |
|
| 1226 | - * |
|
| 1227 | - * @since 1.0.19 |
|
| 1228 | - * @return bool |
|
| 1229 | - */ |
|
| 1225 | + * Checks whether the item supports dynamic pricing. |
|
| 1226 | + * |
|
| 1227 | + * @since 1.0.19 |
|
| 1228 | + * @return bool |
|
| 1229 | + */ |
|
| 1230 | 1230 | public function supports_dynamic_pricing() { |
| 1231 | 1231 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
| 1232 | 1232 | } |
@@ -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' => $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' => $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: %s\nTo: %s\nSubject: %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: %s\nTo: %s\nSubject: %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' ), 1000000 ); |
|
| 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' ), 1000000 ); |
|
| 234 | 234 | |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | 237 | } |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
| 197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
| 198 | 198 | |
| 199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
| 200 | - $tip = esc_attr( $option['desc'] ); |
|
| 201 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
| 202 | - unset( $option['desc'] ); |
|
| 203 | - } |
|
| 199 | + if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
| 200 | + $tip = esc_attr( $option['desc'] ); |
|
| 201 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
| 202 | + unset( $option['desc'] ); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | 205 | // Loop through all tabs. |
| 206 | 206 | add_settings_field( |
@@ -425,333 +425,333 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
| 428 | - $pages_options = array(); |
|
| 428 | + $pages_options = array(); |
|
| 429 | 429 | |
| 430 | - if( $default_label !== NULL && $default_label !== false ) { |
|
| 431 | - $pages_options = array( '' => $default_label ); // Blank option |
|
| 432 | - } |
|
| 430 | + if( $default_label !== NULL && $default_label !== false ) { |
|
| 431 | + $pages_options = array( '' => $default_label ); // Blank option |
|
| 432 | + } |
|
| 433 | 433 | |
| 434 | - $pages = get_pages(); |
|
| 435 | - if ( $pages ) { |
|
| 436 | - foreach ( $pages as $page ) { |
|
| 437 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
| 434 | + $pages = get_pages(); |
|
| 435 | + if ( $pages ) { |
|
| 436 | + foreach ( $pages as $page ) { |
|
| 437 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
| 438 | 438 | $pages_options[ $page->ID ] = $title; |
| 439 | - } |
|
| 440 | - } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - return $pages_options; |
|
| 442 | + return $pages_options; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | function wpinv_header_callback( $args ) { |
| 446 | - if ( !empty( $args['desc'] ) ) { |
|
| 446 | + if ( !empty( $args['desc'] ) ) { |
|
| 447 | 447 | echo $args['desc']; |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | function wpinv_hidden_callback( $args ) { |
| 452 | - global $wpinv_options; |
|
| 453 | - |
|
| 454 | - if ( isset( $args['set_value'] ) ) { |
|
| 455 | - $value = $args['set_value']; |
|
| 456 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 457 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 458 | - } else { |
|
| 459 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 463 | - $args['readonly'] = true; |
|
| 464 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 465 | - $name = ''; |
|
| 466 | - } else { |
|
| 467 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 452 | + global $wpinv_options; |
|
| 453 | + |
|
| 454 | + if ( isset( $args['set_value'] ) ) { |
|
| 455 | + $value = $args['set_value']; |
|
| 456 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 457 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 458 | + } else { |
|
| 459 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 463 | + $args['readonly'] = true; |
|
| 464 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 465 | + $name = ''; |
|
| 466 | + } else { |
|
| 467 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 471 | 471 | |
| 472 | - echo $html; |
|
| 472 | + echo $html; |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | function wpinv_checkbox_callback( $args ) { |
| 476 | - global $wpinv_options; |
|
| 476 | + global $wpinv_options; |
|
| 477 | 477 | |
| 478 | 478 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 479 | 479 | |
| 480 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 481 | - $name = ''; |
|
| 482 | - } else { |
|
| 483 | - $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
| 484 | - } |
|
| 480 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 481 | + $name = ''; |
|
| 482 | + } else { |
|
| 483 | + $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
| 484 | + } |
|
| 485 | 485 | |
| 486 | - $std = isset( $args['std'] ) ? $args['std'] : 0; |
|
| 487 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
| 488 | - $checked = checked( empty( $value ), false, false ); |
|
| 486 | + $std = isset( $args['std'] ) ? $args['std'] : 0; |
|
| 487 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
| 488 | + $checked = checked( empty( $value ), false, false ); |
|
| 489 | 489 | |
| 490 | - $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
| 491 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 490 | + $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
| 491 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 492 | 492 | |
| 493 | - echo $html; |
|
| 493 | + echo $html; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | function wpinv_multicheck_callback( $args ) { |
| 497 | - global $wpinv_options; |
|
| 497 | + global $wpinv_options; |
|
| 498 | 498 | |
| 499 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 500 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 499 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 500 | + $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 501 | 501 | |
| 502 | - if ( ! empty( $args['options'] ) ) { |
|
| 502 | + if ( ! empty( $args['options'] ) ) { |
|
| 503 | 503 | |
| 504 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
| 505 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
| 504 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
| 505 | + $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
| 506 | 506 | |
| 507 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
| 507 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
| 508 | 508 | foreach( $args['options'] as $key => $option ): |
| 509 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 510 | - if ( in_array( $sanitize_key, $value ) ) { |
|
| 511 | - $enabled = $sanitize_key; |
|
| 512 | - } else { |
|
| 513 | - $enabled = NULL; |
|
| 514 | - } |
|
| 515 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 516 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
| 517 | - endforeach; |
|
| 518 | - echo '</div>'; |
|
| 519 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
| 520 | - } |
|
| 509 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 510 | + if ( in_array( $sanitize_key, $value ) ) { |
|
| 511 | + $enabled = $sanitize_key; |
|
| 512 | + } else { |
|
| 513 | + $enabled = NULL; |
|
| 514 | + } |
|
| 515 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 516 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
| 517 | + endforeach; |
|
| 518 | + echo '</div>'; |
|
| 519 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
| 520 | + } |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | function wpinv_payment_icons_callback( $args ) { |
| 524 | - global $wpinv_options; |
|
| 524 | + global $wpinv_options; |
|
| 525 | 525 | |
| 526 | 526 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 527 | 527 | |
| 528 | - if ( ! empty( $args['options'] ) ) { |
|
| 529 | - foreach( $args['options'] as $key => $option ) { |
|
| 528 | + if ( ! empty( $args['options'] ) ) { |
|
| 529 | + foreach( $args['options'] as $key => $option ) { |
|
| 530 | 530 | $sanitize_key = wpinv_sanitize_key( $key ); |
| 531 | 531 | |
| 532 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
| 533 | - $enabled = $option; |
|
| 534 | - } else { |
|
| 535 | - $enabled = NULL; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
| 539 | - |
|
| 540 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 541 | - |
|
| 542 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
| 543 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 544 | - } else { |
|
| 545 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 546 | - |
|
| 547 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 548 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 549 | - } else { |
|
| 550 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 551 | - $content_dir = WP_CONTENT_DIR; |
|
| 552 | - |
|
| 553 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 554 | - // Replaces backslashes with forward slashes for Windows systems |
|
| 555 | - $image = wp_normalize_path( $image ); |
|
| 556 | - $content_dir = wp_normalize_path( $content_dir ); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 563 | - } |
|
| 564 | - echo $option . '</label>'; |
|
| 565 | - } |
|
| 566 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 567 | - } |
|
| 532 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
| 533 | + $enabled = $option; |
|
| 534 | + } else { |
|
| 535 | + $enabled = NULL; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
| 539 | + |
|
| 540 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 541 | + |
|
| 542 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
| 543 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 544 | + } else { |
|
| 545 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 546 | + |
|
| 547 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 548 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 549 | + } else { |
|
| 550 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 551 | + $content_dir = WP_CONTENT_DIR; |
|
| 552 | + |
|
| 553 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 554 | + // Replaces backslashes with forward slashes for Windows systems |
|
| 555 | + $image = wp_normalize_path( $image ); |
|
| 556 | + $content_dir = wp_normalize_path( $content_dir ); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 563 | + } |
|
| 564 | + echo $option . '</label>'; |
|
| 565 | + } |
|
| 566 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 567 | + } |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | function wpinv_radio_callback( $args ) { |
| 571 | - global $wpinv_options; |
|
| 571 | + global $wpinv_options; |
|
| 572 | 572 | |
| 573 | 573 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 574 | 574 | |
| 575 | 575 | foreach ( $args['options'] as $key => $option ) : |
| 576 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 576 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 577 | 577 | |
| 578 | 578 | $checked = false; |
| 579 | 579 | |
| 580 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
| 581 | - $checked = true; |
|
| 582 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
| 583 | - $checked = true; |
|
| 580 | + if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
| 581 | + $checked = true; |
|
| 582 | + elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
| 583 | + $checked = true; |
|
| 584 | 584 | |
| 585 | - echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
| 586 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
| 587 | - endforeach; |
|
| 585 | + echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
| 586 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
| 587 | + endforeach; |
|
| 588 | 588 | |
| 589 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 589 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | function wpinv_gateways_callback( $args ) { |
| 593 | - global $wpinv_options; |
|
| 593 | + global $wpinv_options; |
|
| 594 | 594 | |
| 595 | 595 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 596 | 596 | |
| 597 | - foreach ( $args['options'] as $key => $option ) : |
|
| 598 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 597 | + foreach ( $args['options'] as $key => $option ) : |
|
| 598 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 599 | 599 | |
| 600 | 600 | if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
| 601 | - $enabled = '1'; |
|
| 602 | - else |
|
| 603 | - $enabled = null; |
|
| 601 | + $enabled = '1'; |
|
| 602 | + else |
|
| 603 | + $enabled = null; |
|
| 604 | 604 | |
| 605 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
| 606 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
| 607 | - endforeach; |
|
| 605 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
| 606 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
| 607 | + endforeach; |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | function wpinv_gateway_select_callback($args) { |
| 611 | - global $wpinv_options; |
|
| 611 | + global $wpinv_options; |
|
| 612 | 612 | |
| 613 | 613 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 614 | 614 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
| 615 | 615 | |
| 616 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
| 616 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
| 617 | 617 | |
| 618 | - foreach ( $args['options'] as $key => $option ) : |
|
| 619 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 618 | + foreach ( $args['options'] as $key => $option ) : |
|
| 619 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 620 | 620 | $selected = selected( $key, $args['selected'], false ); |
| 621 | 621 | } else { |
| 622 | 622 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
| 623 | 623 | } |
| 624 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 625 | - endforeach; |
|
| 624 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 625 | + endforeach; |
|
| 626 | 626 | |
| 627 | - echo '</select>'; |
|
| 628 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 627 | + echo '</select>'; |
|
| 628 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | function wpinv_text_callback( $args ) { |
| 632 | - global $wpinv_options; |
|
| 632 | + global $wpinv_options; |
|
| 633 | 633 | |
| 634 | 634 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 635 | 635 | |
| 636 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 637 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 638 | - } else { |
|
| 639 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 643 | - $args['readonly'] = true; |
|
| 644 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 645 | - $name = ''; |
|
| 646 | - } else { |
|
| 647 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 648 | - } |
|
| 649 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 650 | - |
|
| 651 | - $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
| 652 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 653 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
| 654 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 655 | - |
|
| 656 | - echo $html; |
|
| 636 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 637 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 638 | + } else { |
|
| 639 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 643 | + $args['readonly'] = true; |
|
| 644 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 645 | + $name = ''; |
|
| 646 | + } else { |
|
| 647 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 648 | + } |
|
| 649 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 650 | + |
|
| 651 | + $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
| 652 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 653 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
| 654 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 655 | + |
|
| 656 | + echo $html; |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | function wpinv_number_callback( $args ) { |
| 660 | - global $wpinv_options; |
|
| 660 | + global $wpinv_options; |
|
| 661 | 661 | |
| 662 | 662 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 663 | 663 | |
| 664 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 665 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 666 | - } else { |
|
| 667 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 671 | - $args['readonly'] = true; |
|
| 672 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 673 | - $name = ''; |
|
| 674 | - } else { |
|
| 675 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
| 679 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
| 680 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
| 681 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 682 | - |
|
| 683 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 684 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 685 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 686 | - |
|
| 687 | - echo $html; |
|
| 664 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 665 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 666 | + } else { |
|
| 667 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 671 | + $args['readonly'] = true; |
|
| 672 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 673 | + $name = ''; |
|
| 674 | + } else { |
|
| 675 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
| 679 | + $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
| 680 | + $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
| 681 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 682 | + |
|
| 683 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 684 | + $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 685 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 686 | + |
|
| 687 | + echo $html; |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | function wpinv_textarea_callback( $args ) { |
| 691 | - global $wpinv_options; |
|
| 691 | + global $wpinv_options; |
|
| 692 | 692 | |
| 693 | 693 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 694 | 694 | |
| 695 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 696 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 697 | - } else { |
|
| 698 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 699 | - } |
|
| 695 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 696 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 697 | + } else { |
|
| 698 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 699 | + } |
|
| 700 | 700 | |
| 701 | 701 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 702 | 702 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
| 703 | 703 | |
| 704 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 705 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 704 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 705 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 706 | 706 | |
| 707 | - echo $html; |
|
| 707 | + echo $html; |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | function wpinv_password_callback( $args ) { |
| 711 | - global $wpinv_options; |
|
| 711 | + global $wpinv_options; |
|
| 712 | 712 | |
| 713 | 713 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 714 | 714 | |
| 715 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 716 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 717 | - } else { |
|
| 718 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 719 | - } |
|
| 715 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 716 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 717 | + } else { |
|
| 718 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 722 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 723 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 721 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 722 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 723 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 724 | 724 | |
| 725 | - echo $html; |
|
| 725 | + echo $html; |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | function wpinv_missing_callback($args) { |
| 729 | - printf( |
|
| 730 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 731 | - '<strong>' . $args['id'] . '</strong>' |
|
| 732 | - ); |
|
| 729 | + printf( |
|
| 730 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 731 | + '<strong>' . $args['id'] . '</strong>' |
|
| 732 | + ); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | function wpinv_select_callback($args) { |
| 736 | - global $wpinv_options; |
|
| 736 | + global $wpinv_options; |
|
| 737 | 737 | |
| 738 | 738 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 739 | 739 | |
| 740 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 741 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 742 | - } else { |
|
| 743 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 744 | - } |
|
| 740 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 741 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 742 | + } else { |
|
| 743 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 744 | + } |
|
| 745 | 745 | |
| 746 | 746 | if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
| 747 | 747 | $value = $args['selected']; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - if ( isset( $args['placeholder'] ) ) { |
|
| 751 | - $placeholder = $args['placeholder']; |
|
| 752 | - } else { |
|
| 753 | - $placeholder = ''; |
|
| 754 | - } |
|
| 750 | + if ( isset( $args['placeholder'] ) ) { |
|
| 751 | + $placeholder = $args['placeholder']; |
|
| 752 | + } else { |
|
| 753 | + $placeholder = ''; |
|
| 754 | + } |
|
| 755 | 755 | |
| 756 | 756 | if( !empty( $args['onchange'] ) ) { |
| 757 | 757 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
@@ -761,143 +761,143 @@ discard block |
||
| 761 | 761 | |
| 762 | 762 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
| 763 | 763 | |
| 764 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
| 764 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
| 765 | 765 | |
| 766 | - foreach ( $args['options'] as $option => $name ) { |
|
| 767 | - $selected = selected( $option, $value, false ); |
|
| 768 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 769 | - } |
|
| 766 | + foreach ( $args['options'] as $option => $name ) { |
|
| 767 | + $selected = selected( $option, $value, false ); |
|
| 768 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 769 | + } |
|
| 770 | 770 | |
| 771 | - $html .= '</select>'; |
|
| 772 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 771 | + $html .= '</select>'; |
|
| 772 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 773 | 773 | |
| 774 | - echo $html; |
|
| 774 | + echo $html; |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | function wpinv_color_select_callback( $args ) { |
| 778 | - global $wpinv_options; |
|
| 778 | + global $wpinv_options; |
|
| 779 | 779 | |
| 780 | 780 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 781 | 781 | |
| 782 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 783 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 784 | - } else { |
|
| 785 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 786 | - } |
|
| 782 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 783 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 784 | + } else { |
|
| 785 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 786 | + } |
|
| 787 | 787 | |
| 788 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 788 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 789 | 789 | |
| 790 | - foreach ( $args['options'] as $option => $color ) { |
|
| 791 | - $selected = selected( $option, $value, false ); |
|
| 792 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 793 | - } |
|
| 790 | + foreach ( $args['options'] as $option => $color ) { |
|
| 791 | + $selected = selected( $option, $value, false ); |
|
| 792 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - $html .= '</select>'; |
|
| 796 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 795 | + $html .= '</select>'; |
|
| 796 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 797 | 797 | |
| 798 | - echo $html; |
|
| 798 | + echo $html; |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | function wpinv_rich_editor_callback( $args ) { |
| 802 | - global $wpinv_options, $wp_version; |
|
| 802 | + global $wpinv_options, $wp_version; |
|
| 803 | 803 | |
| 804 | 804 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 805 | 805 | |
| 806 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 807 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 806 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 807 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 808 | 808 | |
| 809 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 810 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 811 | - } |
|
| 812 | - } else { |
|
| 813 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 814 | - } |
|
| 809 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 810 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 811 | + } |
|
| 812 | + } else { |
|
| 813 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 814 | + } |
|
| 815 | 815 | |
| 816 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 816 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 817 | 817 | |
| 818 | - $html = '<div class="getpaid-settings-editor-input">'; |
|
| 819 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 820 | - ob_start(); |
|
| 821 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
| 822 | - $html .= ob_get_clean(); |
|
| 823 | - } else { |
|
| 824 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 825 | - } |
|
| 818 | + $html = '<div class="getpaid-settings-editor-input">'; |
|
| 819 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 820 | + ob_start(); |
|
| 821 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
| 822 | + $html .= ob_get_clean(); |
|
| 823 | + } else { |
|
| 824 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 827 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 828 | 828 | |
| 829 | - echo $html; |
|
| 829 | + echo $html; |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | function wpinv_upload_callback( $args ) { |
| 833 | - global $wpinv_options; |
|
| 833 | + global $wpinv_options; |
|
| 834 | 834 | |
| 835 | 835 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 836 | 836 | |
| 837 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 838 | - $value = $wpinv_options[$args['id']]; |
|
| 839 | - } else { |
|
| 840 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
| 841 | - } |
|
| 837 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 838 | + $value = $wpinv_options[$args['id']]; |
|
| 839 | + } else { |
|
| 840 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 841 | + } |
|
| 842 | 842 | |
| 843 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 844 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 845 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 846 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 843 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 844 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 845 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 846 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 847 | 847 | |
| 848 | - echo $html; |
|
| 848 | + echo $html; |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | function wpinv_color_callback( $args ) { |
| 852 | - global $wpinv_options; |
|
| 852 | + global $wpinv_options; |
|
| 853 | 853 | |
| 854 | 854 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 855 | 855 | |
| 856 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 857 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 858 | - } else { |
|
| 859 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 860 | - } |
|
| 856 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 857 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 858 | + } else { |
|
| 859 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 860 | + } |
|
| 861 | 861 | |
| 862 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 862 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 863 | 863 | |
| 864 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
| 865 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 864 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
| 865 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 866 | 866 | |
| 867 | - echo $html; |
|
| 867 | + echo $html; |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | function wpinv_country_states_callback($args) { |
| 871 | - global $wpinv_options; |
|
| 871 | + global $wpinv_options; |
|
| 872 | 872 | |
| 873 | 873 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 874 | 874 | |
| 875 | - if ( isset( $args['placeholder'] ) ) { |
|
| 876 | - $placeholder = $args['placeholder']; |
|
| 877 | - } else { |
|
| 878 | - $placeholder = ''; |
|
| 879 | - } |
|
| 875 | + if ( isset( $args['placeholder'] ) ) { |
|
| 876 | + $placeholder = $args['placeholder']; |
|
| 877 | + } else { |
|
| 878 | + $placeholder = ''; |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - $states = wpinv_get_country_states(); |
|
| 881 | + $states = wpinv_get_country_states(); |
|
| 882 | 882 | |
| 883 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
| 884 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 883 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
| 884 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 885 | 885 | |
| 886 | - foreach ( $states as $option => $name ) { |
|
| 887 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
| 888 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 889 | - } |
|
| 886 | + foreach ( $states as $option => $name ) { |
|
| 887 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
| 888 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 889 | + } |
|
| 890 | 890 | |
| 891 | - $html .= '</select>'; |
|
| 892 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 891 | + $html .= '</select>'; |
|
| 892 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 893 | 893 | |
| 894 | - echo $html; |
|
| 894 | + echo $html; |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | function wpinv_tax_rates_callback($args) { |
| 898 | - global $wpinv_options; |
|
| 899 | - $rates = wpinv_get_tax_rates(); |
|
| 900 | - ob_start(); ?> |
|
| 898 | + global $wpinv_options; |
|
| 899 | + $rates = wpinv_get_tax_rates(); |
|
| 900 | + ob_start(); ?> |
|
| 901 | 901 | </td><tr> |
| 902 | 902 | <td colspan="2" class="wpinv_tax_tdbox"> |
| 903 | 903 | <p><?php echo $args['desc']; ?></p> |
@@ -921,40 +921,40 @@ discard block |
||
| 921 | 921 | <tr> |
| 922 | 922 | <td class="wpinv_tax_country"> |
| 923 | 923 | <?php |
| 924 | - echo wpinv_html_select( array( |
|
| 925 | - 'options' => wpinv_get_country_list( true ), |
|
| 926 | - 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
| 924 | + echo wpinv_html_select( array( |
|
| 925 | + 'options' => wpinv_get_country_list( true ), |
|
| 926 | + 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
| 927 | 927 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
| 928 | - 'selected' => $rate['country'], |
|
| 929 | - 'show_option_all' => false, |
|
| 930 | - 'show_option_none' => false, |
|
| 931 | - 'class' => 'wpinv-tax-country wpi_select2', |
|
| 932 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 933 | - ) ); |
|
| 934 | - ?> |
|
| 928 | + 'selected' => $rate['country'], |
|
| 929 | + 'show_option_all' => false, |
|
| 930 | + 'show_option_none' => false, |
|
| 931 | + 'class' => 'wpinv-tax-country wpi_select2', |
|
| 932 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 933 | + ) ); |
|
| 934 | + ?> |
|
| 935 | 935 | </td> |
| 936 | 936 | <td class="wpinv_tax_state"> |
| 937 | 937 | <?php |
| 938 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
| 939 | - if( !empty( $states ) ) { |
|
| 940 | - echo wpinv_html_select( array( |
|
| 941 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
| 942 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
| 938 | + $states = wpinv_get_country_states( $rate['country'] ); |
|
| 939 | + if( !empty( $states ) ) { |
|
| 940 | + echo wpinv_html_select( array( |
|
| 941 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
| 942 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
| 943 | 943 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
| 944 | - 'selected' => $rate['state'], |
|
| 945 | - 'show_option_all' => false, |
|
| 946 | - 'show_option_none' => false, |
|
| 944 | + 'selected' => $rate['state'], |
|
| 945 | + 'show_option_all' => false, |
|
| 946 | + 'show_option_none' => false, |
|
| 947 | 947 | 'class' => 'wpi_select2', |
| 948 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
| 949 | - ) ); |
|
| 950 | - } else { |
|
| 951 | - echo wpinv_html_text( array( |
|
| 952 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
| 953 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
| 948 | + 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
| 949 | + ) ); |
|
| 950 | + } else { |
|
| 951 | + echo wpinv_html_text( array( |
|
| 952 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
| 953 | + 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
| 954 | 954 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
| 955 | - ) ); |
|
| 956 | - } |
|
| 957 | - ?> |
|
| 955 | + ) ); |
|
| 956 | + } |
|
| 957 | + ?> |
|
| 958 | 958 | </td> |
| 959 | 959 | <td class="wpinv_tax_global"> |
| 960 | 960 | <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
@@ -969,19 +969,19 @@ discard block |
||
| 969 | 969 | <tr> |
| 970 | 970 | <td class="wpinv_tax_country"> |
| 971 | 971 | <?php |
| 972 | - echo wpinv_html_select( array( |
|
| 973 | - 'options' => wpinv_get_country_list( true ), |
|
| 974 | - 'name' => 'tax_rates[0][country]', |
|
| 975 | - 'show_option_all' => false, |
|
| 976 | - 'show_option_none' => false, |
|
| 977 | - 'class' => 'wpinv-tax-country wpi_select2', |
|
| 978 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 979 | - ) ); ?> |
|
| 972 | + echo wpinv_html_select( array( |
|
| 973 | + 'options' => wpinv_get_country_list( true ), |
|
| 974 | + 'name' => 'tax_rates[0][country]', |
|
| 975 | + 'show_option_all' => false, |
|
| 976 | + 'show_option_none' => false, |
|
| 977 | + 'class' => 'wpinv-tax-country wpi_select2', |
|
| 978 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 979 | + ) ); ?> |
|
| 980 | 980 | </td> |
| 981 | 981 | <td class="wpinv_tax_state"> |
| 982 | 982 | <?php echo wpinv_html_text( array( |
| 983 | - 'name' => 'tax_rates[0][state]' |
|
| 984 | - ) ); ?> |
|
| 983 | + 'name' => 'tax_rates[0][state]' |
|
| 984 | + ) ); ?> |
|
| 985 | 985 | </td> |
| 986 | 986 | <td class="wpinv_tax_global"> |
| 987 | 987 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
| 997 | 997 | </table> |
| 998 | 998 | <?php |
| 999 | - echo ob_get_clean(); |
|
| 999 | + echo ob_get_clean(); |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | function wpinv_tools_callback($args) { |
@@ -1024,15 +1024,15 @@ discard block |
||
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | function wpinv_descriptive_text_callback( $args ) { |
| 1027 | - echo wp_kses_post( $args['desc'] ); |
|
| 1027 | + echo wp_kses_post( $args['desc'] ); |
|
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | function wpinv_hook_callback( $args ) { |
| 1031 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1031 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | function wpinv_set_settings_cap() { |
| 1035 | - return wpinv_get_capability(); |
|
| 1035 | + return wpinv_get_capability(); |
|
| 1036 | 1036 | } |
| 1037 | 1037 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
| 1038 | 1038 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,55 +10,55 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Which data store to load. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 13 | + * Which data store to load. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | 17 | protected $data_store_name = 'payment_form'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * This is the name of this object type. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $object_type = 'payment_form'; |
|
| 20 | + * This is the name of this object type. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $object_type = 'payment_form'; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Form Data array. This is the core form data exposed in APIs. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array( |
|
| 33 | - 'status' => 'draft', |
|
| 34 | - 'version' => '', |
|
| 35 | - 'date_created' => null, |
|
| 27 | + * Form Data array. This is the core form data exposed in APIs. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array( |
|
| 33 | + 'status' => 'draft', |
|
| 34 | + 'version' => '', |
|
| 35 | + 'date_created' => null, |
|
| 36 | 36 | 'date_modified' => null, |
| 37 | 37 | 'name' => '', |
| 38 | 38 | 'author' => 1, |
| 39 | 39 | 'elements' => null, |
| 40 | - 'items' => null, |
|
| 41 | - 'earned' => 0, |
|
| 42 | - 'refunded' => 0, |
|
| 43 | - 'cancelled' => 0, |
|
| 44 | - 'failed' => 0, |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Stores meta in cache for future reads. |
|
| 49 | - * |
|
| 50 | - * A group must be set to to enable caching. |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - protected $cache_group = 'getpaid_forms'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
| 58 | - * |
|
| 59 | - * @var WPInv_Invoice |
|
| 60 | - */ |
|
| 61 | - public $invoice = 0; |
|
| 40 | + 'items' => null, |
|
| 41 | + 'earned' => 0, |
|
| 42 | + 'refunded' => 0, |
|
| 43 | + 'cancelled' => 0, |
|
| 44 | + 'failed' => 0, |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Stores meta in cache for future reads. |
|
| 49 | + * |
|
| 50 | + * A group must be set to to enable caching. |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + protected $cache_group = 'getpaid_forms'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
| 58 | + * |
|
| 59 | + * @var WPInv_Invoice |
|
| 60 | + */ |
|
| 61 | + public $invoice = 0; |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
| 68 | 68 | protected $post = null; |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
| 72 | - * |
|
| 73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
| 74 | - */ |
|
| 75 | - public function __construct( $form = 0 ) { |
|
| 76 | - parent::__construct( $form ); |
|
| 71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
| 72 | + * |
|
| 73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
| 74 | + */ |
|
| 75 | + public function __construct( $form = 0 ) { |
|
| 76 | + parent::__construct( $form ); |
|
| 77 | 77 | |
| 78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
| 79 | - $this->set_id( $form ); |
|
| 80 | - } elseif ( $form instanceof self ) { |
|
| 78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
| 79 | + $this->set_id( $form ); |
|
| 80 | + } elseif ( $form instanceof self ) { |
|
| 81 | 81 | |
| 82 | - $this->set_id( $form->get_id() ); |
|
| 83 | - $this->invoice = $form->invoice; |
|
| 82 | + $this->set_id( $form->get_id() ); |
|
| 83 | + $this->invoice = $form->invoice; |
|
| 84 | 84 | |
| 85 | - } elseif ( ! empty( $form->ID ) ) { |
|
| 86 | - $this->set_id( $form->ID ); |
|
| 87 | - } else { |
|
| 88 | - $this->set_object_read( true ); |
|
| 89 | - } |
|
| 85 | + } elseif ( ! empty( $form->ID ) ) { |
|
| 86 | + $this->set_id( $form->ID ); |
|
| 87 | + } else { |
|
| 88 | + $this->set_object_read( true ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | // Load the datastore. |
| 92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 93 | 93 | |
| 94 | - if ( $this->get_id() > 0 ) { |
|
| 94 | + if ( $this->get_id() > 0 ) { |
|
| 95 | 95 | $this->post = get_post( $this->get_id() ); |
| 96 | - $this->data_store->read( $this ); |
|
| 96 | + $this->data_store->read( $this ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | /* |
| 102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,358 +114,358 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | - * Get plugin version when the form was created. |
|
| 118 | - * |
|
| 119 | - * @since 1.0.19 |
|
| 120 | - * @param string $context View or edit context. |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function get_version( $context = 'view' ) { |
|
| 124 | - return $this->get_prop( 'version', $context ); |
|
| 117 | + * Get plugin version when the form was created. |
|
| 118 | + * |
|
| 119 | + * @since 1.0.19 |
|
| 120 | + * @param string $context View or edit context. |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function get_version( $context = 'view' ) { |
|
| 124 | + return $this->get_prop( 'version', $context ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | - * Get date when the form was created. |
|
| 129 | - * |
|
| 130 | - * @since 1.0.19 |
|
| 131 | - * @param string $context View or edit context. |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function get_date_created( $context = 'view' ) { |
|
| 135 | - return $this->get_prop( 'date_created', $context ); |
|
| 128 | + * Get date when the form was created. |
|
| 129 | + * |
|
| 130 | + * @since 1.0.19 |
|
| 131 | + * @param string $context View or edit context. |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function get_date_created( $context = 'view' ) { |
|
| 135 | + return $this->get_prop( 'date_created', $context ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | - * Get GMT date when the form was created. |
|
| 140 | - * |
|
| 141 | - * @since 1.0.19 |
|
| 142 | - * @param string $context View or edit context. |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 139 | + * Get GMT date when the form was created. |
|
| 140 | + * |
|
| 141 | + * @since 1.0.19 |
|
| 142 | + * @param string $context View or edit context. |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 146 | 146 | $date = $this->get_date_created( $context ); |
| 147 | 147 | |
| 148 | 148 | if ( $date ) { |
| 149 | 149 | $date = get_gmt_from_date( $date ); |
| 150 | 150 | } |
| 151 | - return $date; |
|
| 151 | + return $date; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | - * Get date when the form was last modified. |
|
| 156 | - * |
|
| 157 | - * @since 1.0.19 |
|
| 158 | - * @param string $context View or edit context. |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function get_date_modified( $context = 'view' ) { |
|
| 162 | - return $this->get_prop( 'date_modified', $context ); |
|
| 155 | + * Get date when the form was last modified. |
|
| 156 | + * |
|
| 157 | + * @since 1.0.19 |
|
| 158 | + * @param string $context View or edit context. |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function get_date_modified( $context = 'view' ) { |
|
| 162 | + return $this->get_prop( 'date_modified', $context ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * Get GMT date when the form was last modified. |
|
| 167 | - * |
|
| 168 | - * @since 1.0.19 |
|
| 169 | - * @param string $context View or edit context. |
|
| 170 | - * @return string |
|
| 171 | - */ |
|
| 172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 166 | + * Get GMT date when the form was last modified. |
|
| 167 | + * |
|
| 168 | + * @since 1.0.19 |
|
| 169 | + * @param string $context View or edit context. |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 173 | 173 | $date = $this->get_date_modified( $context ); |
| 174 | 174 | |
| 175 | 175 | if ( $date ) { |
| 176 | 176 | $date = get_gmt_from_date( $date ); |
| 177 | 177 | } |
| 178 | - return $date; |
|
| 178 | + return $date; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | - * Get the form name. |
|
| 183 | - * |
|
| 184 | - * @since 1.0.19 |
|
| 185 | - * @param string $context View or edit context. |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - public function get_name( $context = 'view' ) { |
|
| 189 | - return $this->get_prop( 'name', $context ); |
|
| 182 | + * Get the form name. |
|
| 183 | + * |
|
| 184 | + * @since 1.0.19 |
|
| 185 | + * @param string $context View or edit context. |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + public function get_name( $context = 'view' ) { |
|
| 189 | + return $this->get_prop( 'name', $context ); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | - * Alias of self::get_name(). |
|
| 194 | - * |
|
| 195 | - * @since 1.0.19 |
|
| 196 | - * @param string $context View or edit context. |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function get_title( $context = 'view' ) { |
|
| 200 | - return $this->get_name( $context ); |
|
| 201 | - } |
|
| 193 | + * Alias of self::get_name(). |
|
| 194 | + * |
|
| 195 | + * @since 1.0.19 |
|
| 196 | + * @param string $context View or edit context. |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function get_title( $context = 'view' ) { |
|
| 200 | + return $this->get_name( $context ); |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | - * Get the owner of the form. |
|
| 205 | - * |
|
| 206 | - * @since 1.0.19 |
|
| 207 | - * @param string $context View or edit context. |
|
| 208 | - * @return int |
|
| 209 | - */ |
|
| 210 | - public function get_author( $context = 'view' ) { |
|
| 211 | - return (int) $this->get_prop( 'author', $context ); |
|
| 204 | + * Get the owner of the form. |
|
| 205 | + * |
|
| 206 | + * @since 1.0.19 |
|
| 207 | + * @param string $context View or edit context. |
|
| 208 | + * @return int |
|
| 209 | + */ |
|
| 210 | + public function get_author( $context = 'view' ) { |
|
| 211 | + return (int) $this->get_prop( 'author', $context ); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | - * Get the elements that make up the form. |
|
| 216 | - * |
|
| 217 | - * @since 1.0.19 |
|
| 218 | - * @param string $context View or edit context. |
|
| 219 | - * @return array |
|
| 220 | - */ |
|
| 221 | - public function get_elements( $context = 'view' ) { |
|
| 222 | - $elements = $this->get_prop( 'elements', $context ); |
|
| 215 | + * Get the elements that make up the form. |
|
| 216 | + * |
|
| 217 | + * @since 1.0.19 |
|
| 218 | + * @param string $context View or edit context. |
|
| 219 | + * @return array |
|
| 220 | + */ |
|
| 221 | + public function get_elements( $context = 'view' ) { |
|
| 222 | + $elements = $this->get_prop( 'elements', $context ); |
|
| 223 | 223 | |
| 224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
| 224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
| 225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - // Ensure that all required elements exist. |
|
| 229 | - $_elements = array(); |
|
| 230 | - foreach ( $elements as $element ) { |
|
| 228 | + // Ensure that all required elements exist. |
|
| 229 | + $_elements = array(); |
|
| 230 | + foreach ( $elements as $element ) { |
|
| 231 | 231 | |
| 232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
| 232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
| 233 | 233 | |
| 234 | - $_elements[] = array( |
|
| 235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
| 236 | - 'id' => 'gtscicd', |
|
| 237 | - 'name' => 'gtscicd', |
|
| 238 | - 'type' => 'gateway_select', |
|
| 239 | - 'premade' => true |
|
| 234 | + $_elements[] = array( |
|
| 235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
| 236 | + 'id' => 'gtscicd', |
|
| 237 | + 'name' => 'gtscicd', |
|
| 238 | + 'type' => 'gateway_select', |
|
| 239 | + 'premade' => true |
|
| 240 | 240 | |
| 241 | - ); |
|
| 241 | + ); |
|
| 242 | 242 | |
| 243 | - } |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - $_elements[] = $element; |
|
| 245 | + $_elements[] = $element; |
|
| 246 | 246 | |
| 247 | - } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | return $_elements; |
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Get the items sold via the form. |
|
| 254 | - * |
|
| 255 | - * @since 1.0.19 |
|
| 256 | - * @param string $context View or edit context. |
|
| 257 | - * @param string $return objects or arrays. |
|
| 258 | - * @return GetPaid_Form_Item[] |
|
| 259 | - */ |
|
| 260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
| 261 | - $items = $this->get_prop( 'items', $context ); |
|
| 262 | - |
|
| 263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Get the items sold via the form. |
|
| 254 | + * |
|
| 255 | + * @since 1.0.19 |
|
| 256 | + * @param string $context View or edit context. |
|
| 257 | + * @param string $return objects or arrays. |
|
| 258 | + * @return GetPaid_Form_Item[] |
|
| 259 | + */ |
|
| 260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
| 261 | + $items = $this->get_prop( 'items', $context ); |
|
| 262 | + |
|
| 263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
| 264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
| 265 | - } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // Convert the items. |
|
| 268 | + $prepared = array(); |
|
| 266 | 269 | |
| 267 | - // Convert the items. |
|
| 268 | - $prepared = array(); |
|
| 270 | + foreach ( $items as $key => $value ) { |
|
| 269 | 271 | |
| 270 | - foreach ( $items as $key => $value ) { |
|
| 272 | + // Form items. |
|
| 273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
| 271 | 274 | |
| 272 | - // Form items. |
|
| 273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
| 275 | + if ( $value->can_purchase() ) { |
|
| 276 | + $prepared[] = $value; |
|
| 277 | + } |
|
| 274 | 278 | |
| 275 | - if ( $value->can_purchase() ) { |
|
| 276 | - $prepared[] = $value; |
|
| 277 | - } |
|
| 279 | + continue; |
|
| 278 | 280 | |
| 279 | - continue; |
|
| 281 | + } |
|
| 280 | 282 | |
| 281 | - } |
|
| 283 | + // $item_id => $quantity (buy buttons) |
|
| 284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
| 285 | + $item = new GetPaid_Form_Item( $key ); |
|
| 282 | 286 | |
| 283 | - // $item_id => $quantity (buy buttons) |
|
| 284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
| 285 | - $item = new GetPaid_Form_Item( $key ); |
|
| 287 | + if ( $item->can_purchase() ) { |
|
| 286 | 288 | |
| 287 | - if ( $item->can_purchase() ) { |
|
| 289 | + $value = (int) $value; |
|
| 290 | + $item->set_quantity( $value ); |
|
| 291 | + if ( 0 == $value ) { |
|
| 292 | + $item->set_quantity( 1 ); |
|
| 293 | + $item->set_allow_quantities( true ); |
|
| 294 | + } |
|
| 288 | 295 | |
| 289 | - $value = (int) $value; |
|
| 290 | - $item->set_quantity( $value ); |
|
| 291 | - if ( 0 == $value ) { |
|
| 292 | - $item->set_quantity( 1 ); |
|
| 293 | - $item->set_allow_quantities( true ); |
|
| 294 | - } |
|
| 296 | + $prepared[] = $item; |
|
| 297 | + } |
|
| 295 | 298 | |
| 296 | - $prepared[] = $item; |
|
| 297 | - } |
|
| 299 | + continue; |
|
| 300 | + } |
|
| 298 | 301 | |
| 299 | - continue; |
|
| 300 | - } |
|
| 302 | + // Items saved via payment forms editor. |
|
| 303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
| 301 | 304 | |
| 302 | - // Items saved via payment forms editor. |
|
| 303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
| 305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
| 304 | 306 | |
| 305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
| 307 | + if ( ! $item->can_purchase() ) { |
|
| 308 | + continue; |
|
| 309 | + } |
|
| 306 | 310 | |
| 307 | - if ( ! $item->can_purchase() ) { |
|
| 308 | - continue; |
|
| 309 | - } |
|
| 311 | + // Sub-total (Cart items). |
|
| 312 | + if ( isset( $value['subtotal'] ) ) { |
|
| 313 | + $item->set_price( $value['subtotal'] ); |
|
| 314 | + } |
|
| 310 | 315 | |
| 311 | - // Sub-total (Cart items). |
|
| 312 | - if ( isset( $value['subtotal'] ) ) { |
|
| 313 | - $item->set_price( $value['subtotal'] ); |
|
| 314 | - } |
|
| 316 | + if ( isset( $value['quantity'] ) ) { |
|
| 317 | + $item->set_quantity( $value['quantity'] ); |
|
| 318 | + } |
|
| 315 | 319 | |
| 316 | - if ( isset( $value['quantity'] ) ) { |
|
| 317 | - $item->set_quantity( $value['quantity'] ); |
|
| 318 | - } |
|
| 320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
| 321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
| 322 | + } |
|
| 319 | 323 | |
| 320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
| 321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
| 322 | - } |
|
| 324 | + if ( isset( $value['required'] ) ) { |
|
| 325 | + $item->set_is_required( $value['required'] ); |
|
| 326 | + } |
|
| 323 | 327 | |
| 324 | - if ( isset( $value['required'] ) ) { |
|
| 325 | - $item->set_is_required( $value['required'] ); |
|
| 326 | - } |
|
| 328 | + if ( isset( $value['description'] ) ) { |
|
| 329 | + $item->set_custom_description( $value['description'] ); |
|
| 330 | + } |
|
| 327 | 331 | |
| 328 | - if ( isset( $value['description'] ) ) { |
|
| 329 | - $item->set_custom_description( $value['description'] ); |
|
| 330 | - } |
|
| 332 | + $prepared[] = $item; |
|
| 333 | + continue; |
|
| 331 | 334 | |
| 332 | - $prepared[] = $item; |
|
| 333 | - continue; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
| 338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 339 | + $item = new GetPaid_Form_Item( $key ); |
|
| 340 | + |
|
| 341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
| 342 | + $item->set_price( $value['price'] ); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ( $item->can_purchase() ) { |
|
| 346 | + $prepared[] = $item; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + continue; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + if ( 'objects' == $return && 'view' == $context ) { |
|
| 355 | + return $prepared; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $items = array(); |
|
| 359 | + foreach ( $prepared as $item ) { |
|
| 360 | + $items[] = $item->prepare_data_for_use(); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $items; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Get a single item belonging to the form. |
|
| 368 | + * |
|
| 369 | + * @since 1.0.19 |
|
| 370 | + * @param int $item_id The item id to return. |
|
| 371 | + * @return GetPaid_Form_Item|bool |
|
| 372 | + */ |
|
| 373 | + public function get_item( $item_id ) { |
|
| 374 | + |
|
| 375 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + foreach( $this->get_items() as $item ) { |
|
| 380 | + if ( $item->get_id() == (int) $item_id ) { |
|
| 381 | + return $item; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + return false; |
|
| 386 | + |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Gets a single element. |
|
| 391 | + * |
|
| 392 | + * @since 1.0.19 |
|
| 393 | + * @param string $element_type The element type to return. |
|
| 394 | + * @return array|bool |
|
| 395 | + */ |
|
| 396 | + public function get_element_type( $element_type ) { |
|
| 397 | + |
|
| 398 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
| 399 | + return false; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
| 403 | + |
|
| 404 | + if ( $element['type'] == $element_type ) { |
|
| 405 | + return $element; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return false; |
|
| 411 | + |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Get the total amount earned via this form. |
|
| 416 | + * |
|
| 417 | + * @since 1.0.19 |
|
| 418 | + * @param string $context View or edit context. |
|
| 419 | + * @return array |
|
| 420 | + */ |
|
| 421 | + public function get_earned( $context = 'view' ) { |
|
| 422 | + return $this->get_prop( 'earned', $context ); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Get the total amount refunded via this form. |
|
| 427 | + * |
|
| 428 | + * @since 1.0.19 |
|
| 429 | + * @param string $context View or edit context. |
|
| 430 | + * @return array |
|
| 431 | + */ |
|
| 432 | + public function get_refunded( $context = 'view' ) { |
|
| 433 | + return $this->get_prop( 'refunded', $context ); |
|
| 434 | + } |
|
| 334 | 435 | |
| 335 | - } |
|
| 436 | + /** |
|
| 437 | + * Get the total amount cancelled via this form. |
|
| 438 | + * |
|
| 439 | + * @since 1.0.19 |
|
| 440 | + * @param string $context View or edit context. |
|
| 441 | + * @return array |
|
| 442 | + */ |
|
| 443 | + public function get_cancelled( $context = 'view' ) { |
|
| 444 | + return $this->get_prop( 'cancelled', $context ); |
|
| 445 | + } |
|
| 336 | 446 | |
| 337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
| 338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 339 | - $item = new GetPaid_Form_Item( $key ); |
|
| 447 | + /** |
|
| 448 | + * Get the total amount failed via this form. |
|
| 449 | + * |
|
| 450 | + * @since 1.0.19 |
|
| 451 | + * @param string $context View or edit context. |
|
| 452 | + * @return array |
|
| 453 | + */ |
|
| 454 | + public function get_failed( $context = 'view' ) { |
|
| 455 | + return $this->get_prop( 'failed', $context ); |
|
| 456 | + } |
|
| 340 | 457 | |
| 341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
| 342 | - $item->set_price( $value['price'] ); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ( $item->can_purchase() ) { |
|
| 346 | - $prepared[] = $item; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - continue; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
| 355 | - return $prepared; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $items = array(); |
|
| 359 | - foreach ( $prepared as $item ) { |
|
| 360 | - $items[] = $item->prepare_data_for_use(); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $items; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Get a single item belonging to the form. |
|
| 368 | - * |
|
| 369 | - * @since 1.0.19 |
|
| 370 | - * @param int $item_id The item id to return. |
|
| 371 | - * @return GetPaid_Form_Item|bool |
|
| 372 | - */ |
|
| 373 | - public function get_item( $item_id ) { |
|
| 374 | - |
|
| 375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
| 376 | - return false; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - foreach( $this->get_items() as $item ) { |
|
| 380 | - if ( $item->get_id() == (int) $item_id ) { |
|
| 381 | - return $item; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - return false; |
|
| 386 | - |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Gets a single element. |
|
| 391 | - * |
|
| 392 | - * @since 1.0.19 |
|
| 393 | - * @param string $element_type The element type to return. |
|
| 394 | - * @return array|bool |
|
| 395 | - */ |
|
| 396 | - public function get_element_type( $element_type ) { |
|
| 397 | - |
|
| 398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
| 399 | - return false; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
| 403 | - |
|
| 404 | - if ( $element['type'] == $element_type ) { |
|
| 405 | - return $element; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return false; |
|
| 411 | - |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Get the total amount earned via this form. |
|
| 416 | - * |
|
| 417 | - * @since 1.0.19 |
|
| 418 | - * @param string $context View or edit context. |
|
| 419 | - * @return array |
|
| 420 | - */ |
|
| 421 | - public function get_earned( $context = 'view' ) { |
|
| 422 | - return $this->get_prop( 'earned', $context ); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Get the total amount refunded via this form. |
|
| 427 | - * |
|
| 428 | - * @since 1.0.19 |
|
| 429 | - * @param string $context View or edit context. |
|
| 430 | - * @return array |
|
| 431 | - */ |
|
| 432 | - public function get_refunded( $context = 'view' ) { |
|
| 433 | - return $this->get_prop( 'refunded', $context ); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Get the total amount cancelled via this form. |
|
| 438 | - * |
|
| 439 | - * @since 1.0.19 |
|
| 440 | - * @param string $context View or edit context. |
|
| 441 | - * @return array |
|
| 442 | - */ |
|
| 443 | - public function get_cancelled( $context = 'view' ) { |
|
| 444 | - return $this->get_prop( 'cancelled', $context ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Get the total amount failed via this form. |
|
| 449 | - * |
|
| 450 | - * @since 1.0.19 |
|
| 451 | - * @param string $context View or edit context. |
|
| 452 | - * @return array |
|
| 453 | - */ |
|
| 454 | - public function get_failed( $context = 'view' ) { |
|
| 455 | - return $this->get_prop( 'failed', $context ); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Get the currency. |
|
| 460 | - * |
|
| 461 | - * @since 1.0.19 |
|
| 462 | - * @param string $context View or edit context. |
|
| 463 | - * @return string |
|
| 464 | - */ |
|
| 465 | - public function get_currency() { |
|
| 466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
| 467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
| 468 | - } |
|
| 458 | + /** |
|
| 459 | + * Get the currency. |
|
| 460 | + * |
|
| 461 | + * @since 1.0.19 |
|
| 462 | + * @param string $context View or edit context. |
|
| 463 | + * @return string |
|
| 464 | + */ |
|
| 465 | + public function get_currency() { |
|
| 466 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
| 467 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | 470 | /* |
| 471 | 471 | |-------------------------------------------------------------------------- |
@@ -478,22 +478,22 @@ discard block |
||
| 478 | 478 | */ |
| 479 | 479 | |
| 480 | 480 | /** |
| 481 | - * Set plugin version when the item was created. |
|
| 482 | - * |
|
| 483 | - * @since 1.0.19 |
|
| 484 | - */ |
|
| 485 | - public function set_version( $value ) { |
|
| 486 | - $this->set_prop( 'version', $value ); |
|
| 481 | + * Set plugin version when the item was created. |
|
| 482 | + * |
|
| 483 | + * @since 1.0.19 |
|
| 484 | + */ |
|
| 485 | + public function set_version( $value ) { |
|
| 486 | + $this->set_prop( 'version', $value ); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
| 490 | - * Set date when the item was created. |
|
| 491 | - * |
|
| 492 | - * @since 1.0.19 |
|
| 493 | - * @param string $value Value to set. |
|
| 490 | + * Set date when the item was created. |
|
| 491 | + * |
|
| 492 | + * @since 1.0.19 |
|
| 493 | + * @param string $value Value to set. |
|
| 494 | 494 | * @return bool Whether or not the date was set. |
| 495 | - */ |
|
| 496 | - public function set_date_created( $value ) { |
|
| 495 | + */ |
|
| 496 | + public function set_date_created( $value ) { |
|
| 497 | 497 | $date = strtotime( $value ); |
| 498 | 498 | |
| 499 | 499 | if ( $date ) { |
@@ -506,13 +506,13 @@ discard block |
||
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
| 509 | - * Set date when the item was last modified. |
|
| 510 | - * |
|
| 511 | - * @since 1.0.19 |
|
| 512 | - * @param string $value Value to set. |
|
| 509 | + * Set date when the item was last modified. |
|
| 510 | + * |
|
| 511 | + * @since 1.0.19 |
|
| 512 | + * @param string $value Value to set. |
|
| 513 | 513 | * @return bool Whether or not the date was set. |
| 514 | - */ |
|
| 515 | - public function set_date_modified( $value ) { |
|
| 514 | + */ |
|
| 515 | + public function set_date_modified( $value ) { |
|
| 516 | 516 | $date = strtotime( $value ); |
| 517 | 517 | |
| 518 | 518 | if ( $date ) { |
@@ -525,118 +525,118 @@ discard block |
||
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
| 528 | - * Set the item name. |
|
| 529 | - * |
|
| 530 | - * @since 1.0.19 |
|
| 531 | - * @param string $value New name. |
|
| 532 | - */ |
|
| 533 | - public function set_name( $value ) { |
|
| 534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Alias of self::set_name(). |
|
| 539 | - * |
|
| 540 | - * @since 1.0.19 |
|
| 541 | - * @param string $value New name. |
|
| 542 | - */ |
|
| 543 | - public function set_title( $value ) { |
|
| 544 | - $this->set_name( $value ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * Set the owner of the item. |
|
| 549 | - * |
|
| 550 | - * @since 1.0.19 |
|
| 551 | - * @param int $value New author. |
|
| 552 | - */ |
|
| 553 | - public function set_author( $value ) { |
|
| 554 | - $this->set_prop( 'author', (int) $value ); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * Set the form elements. |
|
| 559 | - * |
|
| 560 | - * @since 1.0.19 |
|
| 561 | - * @param array $value Form elements. |
|
| 562 | - */ |
|
| 563 | - public function set_elements( $value ) { |
|
| 564 | - if ( is_array( $value ) ) { |
|
| 565 | - $this->set_prop( 'elements', $value ); |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Set the form items. |
|
| 571 | - * |
|
| 572 | - * @since 1.0.19 |
|
| 573 | - * @param array $value Form elements. |
|
| 574 | - */ |
|
| 575 | - public function set_items( $value ) { |
|
| 576 | - if ( is_array( $value ) ) { |
|
| 577 | - $this->set_prop( 'items', $value ); |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Set the total amount earned via this form. |
|
| 583 | - * |
|
| 584 | - * @since 1.0.19 |
|
| 585 | - * @param float $value Amount earned. |
|
| 586 | - */ |
|
| 587 | - public function set_earned( $value ) { |
|
| 588 | - $value = max( (float) $value, 0 ); |
|
| 589 | - $this->set_prop( 'earned', $value ); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Set the total amount refunded via this form. |
|
| 594 | - * |
|
| 595 | - * @since 1.0.19 |
|
| 596 | - * @param float $value Amount refunded. |
|
| 597 | - */ |
|
| 598 | - public function set_refunded( $value ) { |
|
| 599 | - $value = max( (float) $value, 0 ); |
|
| 600 | - $this->set_prop( 'refunded', $value ); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * Set the total amount cancelled via this form. |
|
| 605 | - * |
|
| 606 | - * @since 1.0.19 |
|
| 607 | - * @param float $value Amount cancelled. |
|
| 608 | - */ |
|
| 609 | - public function set_cancelled( $value ) { |
|
| 610 | - $value = max( (float) $value, 0 ); |
|
| 611 | - $this->set_prop( 'cancelled', $value ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Set the total amount failed via this form. |
|
| 616 | - * |
|
| 617 | - * @since 1.0.19 |
|
| 618 | - * @param float $value Amount cancelled. |
|
| 619 | - */ |
|
| 620 | - public function set_failed( $value ) { |
|
| 621 | - $value = max( (float) $value, 0 ); |
|
| 622 | - $this->set_prop( 'failed', $value ); |
|
| 623 | - } |
|
| 528 | + * Set the item name. |
|
| 529 | + * |
|
| 530 | + * @since 1.0.19 |
|
| 531 | + * @param string $value New name. |
|
| 532 | + */ |
|
| 533 | + public function set_name( $value ) { |
|
| 534 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Alias of self::set_name(). |
|
| 539 | + * |
|
| 540 | + * @since 1.0.19 |
|
| 541 | + * @param string $value New name. |
|
| 542 | + */ |
|
| 543 | + public function set_title( $value ) { |
|
| 544 | + $this->set_name( $value ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * Set the owner of the item. |
|
| 549 | + * |
|
| 550 | + * @since 1.0.19 |
|
| 551 | + * @param int $value New author. |
|
| 552 | + */ |
|
| 553 | + public function set_author( $value ) { |
|
| 554 | + $this->set_prop( 'author', (int) $value ); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * Set the form elements. |
|
| 559 | + * |
|
| 560 | + * @since 1.0.19 |
|
| 561 | + * @param array $value Form elements. |
|
| 562 | + */ |
|
| 563 | + public function set_elements( $value ) { |
|
| 564 | + if ( is_array( $value ) ) { |
|
| 565 | + $this->set_prop( 'elements', $value ); |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Set the form items. |
|
| 571 | + * |
|
| 572 | + * @since 1.0.19 |
|
| 573 | + * @param array $value Form elements. |
|
| 574 | + */ |
|
| 575 | + public function set_items( $value ) { |
|
| 576 | + if ( is_array( $value ) ) { |
|
| 577 | + $this->set_prop( 'items', $value ); |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Set the total amount earned via this form. |
|
| 583 | + * |
|
| 584 | + * @since 1.0.19 |
|
| 585 | + * @param float $value Amount earned. |
|
| 586 | + */ |
|
| 587 | + public function set_earned( $value ) { |
|
| 588 | + $value = max( (float) $value, 0 ); |
|
| 589 | + $this->set_prop( 'earned', $value ); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Set the total amount refunded via this form. |
|
| 594 | + * |
|
| 595 | + * @since 1.0.19 |
|
| 596 | + * @param float $value Amount refunded. |
|
| 597 | + */ |
|
| 598 | + public function set_refunded( $value ) { |
|
| 599 | + $value = max( (float) $value, 0 ); |
|
| 600 | + $this->set_prop( 'refunded', $value ); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * Set the total amount cancelled via this form. |
|
| 605 | + * |
|
| 606 | + * @since 1.0.19 |
|
| 607 | + * @param float $value Amount cancelled. |
|
| 608 | + */ |
|
| 609 | + public function set_cancelled( $value ) { |
|
| 610 | + $value = max( (float) $value, 0 ); |
|
| 611 | + $this->set_prop( 'cancelled', $value ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Set the total amount failed via this form. |
|
| 616 | + * |
|
| 617 | + * @since 1.0.19 |
|
| 618 | + * @param float $value Amount cancelled. |
|
| 619 | + */ |
|
| 620 | + public function set_failed( $value ) { |
|
| 621 | + $value = max( (float) $value, 0 ); |
|
| 622 | + $this->set_prop( 'failed', $value ); |
|
| 623 | + } |
|
| 624 | 624 | |
| 625 | 625 | /** |
| 626 | 626 | * Create an item. For backwards compatibilty. |
| 627 | 627 | * |
| 628 | 628 | * @deprecated |
| 629 | - * @return int item id |
|
| 629 | + * @return int item id |
|
| 630 | 630 | */ |
| 631 | 631 | public function create( $data = array() ) { |
| 632 | 632 | |
| 633 | - // Set the properties. |
|
| 634 | - if ( is_array( $data ) ) { |
|
| 635 | - $this->set_props( $data ); |
|
| 636 | - } |
|
| 633 | + // Set the properties. |
|
| 634 | + if ( is_array( $data ) ) { |
|
| 635 | + $this->set_props( $data ); |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | - // Save the item. |
|
| 639 | - return $this->save(); |
|
| 638 | + // Save the item. |
|
| 639 | + return $this->save(); |
|
| 640 | 640 | |
| 641 | 641 | } |
| 642 | 642 | |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | * Updates an item. For backwards compatibilty. |
| 645 | 645 | * |
| 646 | 646 | * @deprecated |
| 647 | - * @return int item id |
|
| 647 | + * @return int item id |
|
| 648 | 648 | */ |
| 649 | 649 | public function update( $data = array() ) { |
| 650 | 650 | return $this->create( $data ); |
@@ -660,22 +660,22 @@ discard block |
||
| 660 | 660 | */ |
| 661 | 661 | |
| 662 | 662 | /** |
| 663 | - * Checks whether this is the default payment form. |
|
| 664 | - * |
|
| 665 | - * @since 1.0.19 |
|
| 666 | - * @return bool |
|
| 667 | - */ |
|
| 663 | + * Checks whether this is the default payment form. |
|
| 664 | + * |
|
| 665 | + * @since 1.0.19 |
|
| 666 | + * @return bool |
|
| 667 | + */ |
|
| 668 | 668 | public function is_default() { |
| 669 | 669 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
| 670 | 670 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
| 671 | - } |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | 673 | /** |
| 674 | - * Checks whether the form is active. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @return bool |
|
| 678 | - */ |
|
| 674 | + * Checks whether the form is active. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @return bool |
|
| 678 | + */ |
|
| 679 | 679 | public function is_active() { |
| 680 | 680 | $is_active = 0 !== (int) $this->get_id(); |
| 681 | 681 | |
@@ -684,76 +684,76 @@ discard block |
||
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * Checks whether the form has a given item. |
|
| 691 | - * |
|
| 692 | - * @since 1.0.19 |
|
| 693 | - * @return bool |
|
| 694 | - */ |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * Checks whether the form has a given item. |
|
| 691 | + * |
|
| 692 | + * @since 1.0.19 |
|
| 693 | + * @return bool |
|
| 694 | + */ |
|
| 695 | 695 | public function has_item( $item_id ) { |
| 696 | 696 | return false !== $this->get_item( $item_id ); |
| 697 | - } |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Checks whether the form has a given element. |
|
| 701 | - * |
|
| 702 | - * @since 1.0.19 |
|
| 703 | - * @return bool |
|
| 704 | - */ |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Checks whether the form has a given element. |
|
| 701 | + * |
|
| 702 | + * @since 1.0.19 |
|
| 703 | + * @return bool |
|
| 704 | + */ |
|
| 705 | 705 | public function has_element_type( $element_type ) { |
| 706 | 706 | return false !== $this->get_element_type( $element_type ); |
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Checks whether this form is recurring or not. |
|
| 711 | - * |
|
| 712 | - * @since 1.0.19 |
|
| 713 | - * @return bool |
|
| 714 | - */ |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Checks whether this form is recurring or not. |
|
| 711 | + * |
|
| 712 | + * @since 1.0.19 |
|
| 713 | + * @return bool |
|
| 714 | + */ |
|
| 715 | 715 | public function is_recurring() { |
| 716 | 716 | |
| 717 | - if ( ! empty( $this->invoice ) ) { |
|
| 718 | - return $this->invoice->is_recurring(); |
|
| 719 | - } |
|
| 717 | + if ( ! empty( $this->invoice ) ) { |
|
| 718 | + return $this->invoice->is_recurring(); |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | - foreach ( $this->get_items() as $item ) { |
|
| 721 | + foreach ( $this->get_items() as $item ) { |
|
| 722 | 722 | |
| 723 | - if ( $item->is_recurring() ) { |
|
| 724 | - return true; |
|
| 725 | - } |
|
| 723 | + if ( $item->is_recurring() ) { |
|
| 724 | + return true; |
|
| 725 | + } |
|
| 726 | 726 | |
| 727 | - } |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | 729 | return false; |
| 730 | - } |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * Retrieves the form's html. |
|
| 734 | - * |
|
| 735 | - * @since 1.0.19 |
|
| 736 | - */ |
|
| 732 | + /** |
|
| 733 | + * Retrieves the form's html. |
|
| 734 | + * |
|
| 735 | + * @since 1.0.19 |
|
| 736 | + */ |
|
| 737 | 737 | public function get_html( $extra_markup = '' ) { |
| 738 | 738 | |
| 739 | - // Return the HTML. |
|
| 740 | - return wpinv_get_template_html( |
|
| 741 | - 'payment-forms/form.php', |
|
| 742 | - array( |
|
| 743 | - 'form' => $this, |
|
| 744 | - 'extra_markup' => $extra_markup, |
|
| 745 | - ) |
|
| 746 | - ); |
|
| 747 | - |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * Displays the payment form. |
|
| 752 | - * |
|
| 753 | - * @since 1.0.19 |
|
| 754 | - */ |
|
| 739 | + // Return the HTML. |
|
| 740 | + return wpinv_get_template_html( |
|
| 741 | + 'payment-forms/form.php', |
|
| 742 | + array( |
|
| 743 | + 'form' => $this, |
|
| 744 | + 'extra_markup' => $extra_markup, |
|
| 745 | + ) |
|
| 746 | + ); |
|
| 747 | + |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * Displays the payment form. |
|
| 752 | + * |
|
| 753 | + * @since 1.0.19 |
|
| 754 | + */ |
|
| 755 | 755 | public function display( $extra_markup = '' ) { |
| 756 | - echo $this->get_html( $extra_markup ); |
|
| 756 | + echo $this->get_html( $extra_markup ); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | } |