Add php 8.1 support (WIP)

This commit is contained in:
dinamiko 2022-10-18 15:59:11 +02:00
parent 763e1e287c
commit 68cf4ecda3
14 changed files with 32 additions and 31 deletions

View file

@ -120,8 +120,10 @@ class SubscriptionHelper {
* @return bool Whether page is change subscription or not. * @return bool Whether page is change subscription or not.
*/ */
public function is_subscription_change_payment(): bool { public function is_subscription_change_payment(): bool {
$pay_for_order = filter_input( INPUT_GET, 'pay_for_order', FILTER_SANITIZE_STRING ); if ( ! isset( $_GET['pay_for_order'] ) || ! isset( $_GET['change_payment_method'] ) ) {
$change_payment_method = filter_input( INPUT_GET, 'change_payment_method', FILTER_SANITIZE_STRING ); return false;
return ( isset( $pay_for_order ) && isset( $change_payment_method ) ); }
return true;
} }
} }

View file

@ -100,7 +100,7 @@ class SubscriptionModule implements ModuleInterface {
add_filter( add_filter(
'ppcp_create_order_request_body_data', 'ppcp_create_order_request_body_data',
function( array $data ) use ( $c ) { function( array $data ) use ( $c ) {
$wc_order_action = filter_input( INPUT_POST, 'wc_order_action', FILTER_SANITIZE_STRING ) ?? ''; $wc_order_action = wc_clean( wp_unslash( $_POST['wc_order_action'] ?? '' ) );
if ( if (
$wc_order_action === 'wcs_process_renewal' $wc_order_action === 'wcs_process_renewal'
&& isset( $data['payment_source']['token'] ) && $data['payment_source']['token']['type'] === 'PAYMENT_METHOD_TOKEN' && isset( $data['payment_source']['token'] ) && $data['payment_source']['token']['type'] === 'PAYMENT_METHOD_TOKEN'

View file

@ -53,7 +53,7 @@ class CustomerApprovalListener {
* @return void * @return void
*/ */
public function listen(): void { public function listen(): void {
$token = filter_input( INPUT_GET, 'approval_token_id', FILTER_SANITIZE_STRING ); $token = wc_clean( wp_unslash( $_GET['approval_token_id'] ?? '' ) );
if ( ! is_string( $token ) ) { if ( ! is_string( $token ) ) {
return; return;
} }
@ -94,7 +94,9 @@ class CustomerApprovalListener {
add_action( add_action(
'woocommerce_init', 'woocommerce_init',
function () use ( $message ): void { function () use ( $message ): void {
wc_add_notice( $message, 'error' ); if ( function_exists( 'wc_add_notice' ) ) {
wc_add_notice( $message, 'error' );
}
} }
); );
} }

View file

@ -143,10 +143,8 @@ class VaultedCreditCardHandler {
string $saved_credit_card, string $saved_credit_card,
WC_Order $wc_order WC_Order $wc_order
): WC_Order { ): WC_Order {
$change_payment = filter_input( INPUT_POST, 'woocommerce_change_payment', FILTER_SANITIZE_STRING );
if ( if (
$change_payment isset( $_POST['woocommerce_change_payment'] )
&& $this->subscription_helper->has_subscription( $wc_order->get_id() ) && $this->subscription_helper->has_subscription( $wc_order->get_id() )
&& $this->subscription_helper->is_subscription_change_payment() && $this->subscription_helper->is_subscription_change_payment()
&& $saved_credit_card && $saved_credit_card

View file

@ -83,14 +83,13 @@ class SettingsPageAssets {
} }
$screen = get_current_screen(); $screen = get_current_screen();
if ( $screen->id !== 'woocommerce_page_wc-settings' ) {
$tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING );
$section = filter_input( INPUT_GET, 'section', FILTER_SANITIZE_STRING );
if ( ! 'woocommerce_page_wc-settings' === $screen->id ) {
return false; return false;
} }
$tab = wc_clean( wp_unslash( $_GET['tab'] ?? '' ) );
$section = wc_clean( wp_unslash( $_GET['section'] ?? '' ) );
return 'checkout' === $tab && 'ppcp-gateway' === $section; return 'checkout' === $tab && 'ppcp-gateway' === $section;
} }

View file

@ -275,7 +275,7 @@ class CardButtonGateway extends \WC_Payment_Gateway {
* If customer has chosen change Subscription payment. * If customer has chosen change Subscription payment.
*/ */
if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) { if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) {
$saved_paypal_payment = filter_input( INPUT_POST, 'saved_paypal_payment', FILTER_SANITIZE_STRING ); $saved_paypal_payment = wc_clean( wp_unslash( $_POST['saved_paypal_payment'] ?? '' ) );
if ( $saved_paypal_payment ) { if ( $saved_paypal_payment ) {
update_post_meta( $order_id, 'payment_token_id', $saved_paypal_payment ); update_post_meta( $order_id, 'payment_token_id', $saved_paypal_payment );

View file

@ -360,7 +360,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
/** /**
* If customer has chosen a saved credit card payment. * If customer has chosen a saved credit card payment.
*/ */
$saved_credit_card = filter_input( INPUT_POST, 'saved_credit_card', FILTER_SANITIZE_STRING ); $saved_credit_card = wc_clean( wp_unslash( $_POST['saved_credit_card'] ?? '' ) );
if ( $saved_credit_card ) { if ( $saved_credit_card ) {
try { try {
$wc_order = $this->vaulted_credit_card_handler->handle_payment( $wc_order = $this->vaulted_credit_card_handler->handle_payment(

View file

@ -138,7 +138,7 @@ class OXXO {
'add_meta_boxes', 'add_meta_boxes',
function( string $post_type ) { function( string $post_type ) {
if ( $post_type === 'shop_order' ) { if ( $post_type === 'shop_order' ) {
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_STRING ); $post_id = wc_clean( wp_unslash( $_GET['post'] ?? '' ) );
$order = wc_get_order( $post_id ); $order = wc_get_order( $post_id );
if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === OXXOGateway::ID ) { if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === OXXOGateway::ID ) {
$payer_action = $order->get_meta( 'ppcp_oxxo_payer_action' ); $payer_action = $order->get_meta( 'ppcp_oxxo_payer_action' );
@ -182,7 +182,7 @@ class OXXO {
return false; return false;
} }
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null; $billing_country = wc_clean( wp_unslash( $_POST['country'] ?? '' ) );
if ( $billing_country && 'MX' !== $billing_country ) { if ( $billing_country && 'MX' !== $billing_country ) {
return false; return false;
} }

View file

@ -400,7 +400,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
); );
} }
$funding_source = filter_input( INPUT_POST, 'ppcp-funding-source', FILTER_SANITIZE_STRING ); $funding_source = wc_clean( wp_unslash( $_POST['ppcp-funding-source'] ?? '' ) );
if ( 'card' !== $funding_source && $this->is_free_trial_order( $wc_order ) ) { if ( 'card' !== $funding_source && $this->is_free_trial_order( $wc_order ) ) {
$user_id = (int) $wc_order->get_customer_id(); $user_id = (int) $wc_order->get_customer_id();
@ -423,7 +423,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
* If customer has chosen change Subscription payment. * If customer has chosen change Subscription payment.
*/ */
if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) { if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) {
$saved_paypal_payment = filter_input( INPUT_POST, 'saved_paypal_payment', FILTER_SANITIZE_STRING ); $saved_paypal_payment = wc_clean( wp_unslash( $_POST['saved_paypal_payment'] ?? '' ) );
if ( $saved_paypal_payment ) { if ( $saved_paypal_payment ) {
update_post_meta( $order_id, 'payment_token_id', $saved_paypal_payment ); update_post_meta( $order_id, 'payment_token_id', $saved_paypal_payment );

View file

@ -33,7 +33,7 @@ class FraudNetSessionId {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
$pui_pay_for_order_session_id = filter_input( INPUT_POST, 'pui_pay_for_order_session_id', FILTER_SANITIZE_STRING ); $pui_pay_for_order_session_id = wc_clean( wp_unslash( $_POST['pui_pay_for_order_session_id'] ?? '' ) );
if ( $pui_pay_for_order_session_id && '' !== $pui_pay_for_order_session_id ) { if ( $pui_pay_for_order_session_id && '' !== $pui_pay_for_order_session_id ) {
return $pui_pay_for_order_session_id; return $pui_pay_for_order_session_id;
} }

View file

@ -409,7 +409,7 @@ class PayUponInvoice {
add_action( add_action(
'woocommerce_after_checkout_validation', 'woocommerce_after_checkout_validation',
function( array $fields, WP_Error $errors ) { function( array $fields, WP_Error $errors ) {
$payment_method = filter_input( INPUT_POST, 'payment_method', FILTER_SANITIZE_STRING ); $payment_method = wc_clean( wp_unslash( $_POST['payment_method'] ?? '' ) );
if ( PayUponInvoiceGateway::ID !== $payment_method ) { if ( PayUponInvoiceGateway::ID !== $payment_method ) {
return; return;
} }
@ -418,12 +418,12 @@ class PayUponInvoice {
$errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) ); $errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
} }
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ); $birth_date = wc_clean( wp_unslash( $_POST['billing_birth_date'] ?? '' ) );
if ( ( $birth_date && ! $this->checkout_helper->validate_birth_date( $birth_date ) ) || $birth_date === '' ) { if ( ( $birth_date && ! $this->checkout_helper->validate_birth_date( $birth_date ) ) || $birth_date === '' ) {
$errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) ); $errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) );
} }
$national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ); $national_number = wc_clean( wp_unslash( $_POST['billing_phone'] ?? 0 ) );
if ( ! $national_number ) { if ( ! $national_number ) {
$errors->add( 'validation', __( 'Phone field cannot be empty.', 'woocommerce-paypal-payments' ) ); $errors->add( 'validation', __( 'Phone field cannot be empty.', 'woocommerce-paypal-payments' ) );
} }
@ -484,7 +484,7 @@ class PayUponInvoice {
add_action( add_action(
'woocommerce_update_options_checkout_ppcp-pay-upon-invoice-gateway', 'woocommerce_update_options_checkout_ppcp-pay-upon-invoice-gateway',
function () { function () {
$customer_service_instructions = filter_input( INPUT_POST, 'woocommerce_ppcp-pay-upon-invoice-gateway_customer_service_instructions', FILTER_SANITIZE_STRING ); $customer_service_instructions = wc_clean( wp_unslash( $_POST['woocommerce_ppcp-pay-upon-invoice-gateway_customer_service_instructions'] ?? '' ) );
if ( '' === $customer_service_instructions ) { if ( '' === $customer_service_instructions ) {
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
$gateway_enabled = $gateway_settings['enabled'] ?? ''; $gateway_enabled = $gateway_settings['enabled'] ?? '';
@ -537,7 +537,7 @@ class PayUponInvoice {
'add_meta_boxes', 'add_meta_boxes',
function( string $post_type ) { function( string $post_type ) {
if ( $post_type === 'shop_order' ) { if ( $post_type === 'shop_order' ) {
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_STRING ); $post_id = wc_clean( wp_unslash( $_GET['post'] ?? 0 ) );
$order = wc_get_order( $post_id ); $order = wc_get_order( $post_id );
if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === PayUponInvoiceGateway::ID ) { if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === PayUponInvoiceGateway::ID ) {
$instructions = $order->get_meta( 'ppcp_ratepay_payment_instructions_payment_reference' ); $instructions = $order->get_meta( 'ppcp_ratepay_payment_instructions_payment_reference' );

View file

@ -203,9 +203,9 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
*/ */
public function process_payment( $order_id ) { public function process_payment( $order_id ) {
$wc_order = wc_get_order( $order_id ); $wc_order = wc_get_order( $order_id );
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ) ?? ''; $birth_date = wc_clean( wp_unslash( $_POST['billing_birth_date'] ?? '' ) );
$pay_for_order = filter_input( INPUT_GET, 'pay_for_order', FILTER_SANITIZE_STRING ); $pay_for_order = wc_clean( wp_unslash( $_GET['pay_for_order'] ?? '' ) );
if ( 'true' === $pay_for_order ) { if ( 'true' === $pay_for_order ) {
if ( ! $this->checkout_helper->validate_birth_date( $birth_date ) ) { if ( ! $this->checkout_helper->validate_birth_date( $birth_date ) ) {
wc_add_notice( 'Invalid birth date.', 'error' ); wc_add_notice( 'Invalid birth date.', 'error' );
@ -215,7 +215,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
} }
} }
$phone_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ) ?? ''; $phone_number = wc_clean( wp_unslash( $_POST['billing_phone'] ?? '' ) );
if ( $phone_number ) { if ( $phone_number ) {
$wc_order->set_billing_phone( $phone_number ); $wc_order->set_billing_phone( $phone_number );
$wc_order->save(); $wc_order->save();

View file

@ -25,7 +25,7 @@ class PaymentSourceFactory {
*/ */
public function from_wc_order( WC_Order $order, string $birth_date ) { public function from_wc_order( WC_Order $order, string $birth_date ) {
$address = $order->get_address(); $address = $order->get_address();
$phone = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ) ?? $address['phone'] ?: ''; $phone = wc_clean( wp_unslash( $_POST['billing_phone'] ?? '' ) ) ?? $address['phone'] ?? '';
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] ); $phone_country_code = WC()->countries->get_country_calling_code( $address['country'] );
$phone_country_code = is_array( $phone_country_code ) && ! empty( $phone_country_code ) ? $phone_country_code[0] : $phone_country_code; $phone_country_code = is_array( $phone_country_code ) && ! empty( $phone_country_code ) ? $phone_country_code[0] : $phone_country_code;
if ( is_string( $phone_country_code ) && '' !== $phone_country_code ) { if ( is_string( $phone_country_code ) && '' !== $phone_country_code ) {

View file

@ -54,7 +54,7 @@ class PayUponInvoiceHelper {
return false; return false;
} }
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null; $billing_country = wc_clean( wp_unslash( $_POST['country'] ?? '' ) );
if ( $billing_country && 'DE' !== $billing_country ) { if ( $billing_country && 'DE' !== $billing_country ) {
return false; return false;
} }