mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
phpcs
This commit is contained in:
parent
cb37119a99
commit
4daca6dde0
4 changed files with 65 additions and 47 deletions
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
|
||||
|
||||
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
class SectionsRenderer {
|
||||
|
||||
public const KEY = 'ppcp-tab';
|
||||
|
||||
public function should_render() : bool {
|
||||
|
||||
global $current_section;
|
||||
return $current_section === PayPalGateway::ID;
|
||||
}
|
||||
public function render() {
|
||||
if (! $this->should_render()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current = ! isset($_GET[self::KEY]) ? 'paypal' : sanitize_text_field(wp_unslash($_GET[self::KEY]));
|
||||
$sections = [
|
||||
'paypal' => __( 'PayPal', 'paypal-for-woocommerce' ),
|
||||
'dcc' => __( 'Credit Card', 'paypal-for-woocommerce' ),
|
||||
];
|
||||
|
||||
echo '<ul class="subsubsub">';
|
||||
|
||||
$array_keys = array_keys( $sections );
|
||||
|
||||
foreach ( $sections as $id => $label ) {
|
||||
$url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&' . self::KEY . '=' . $id );
|
||||
echo '<li><a href="' . $url . '" class="' . ( $current == $id ? 'current' : '' ) . '">' . esc_html($label) . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
|
||||
}
|
||||
|
||||
echo '</ul><br class="clear" />';
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* Renders the Sections Tab.
|
||||
*
|
||||
* @package Inpsyde\PayPalCommerce\WcGateway\Settings
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
|
||||
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
/**
|
||||
* Class SectionsRenderer
|
||||
*/
|
||||
class SectionsRenderer {
|
||||
|
||||
public const KEY = 'ppcp-tab';
|
||||
|
||||
/**
|
||||
* Whether the sections tab should be rendered.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() : bool {
|
||||
|
||||
global $current_section;
|
||||
return PayPalGateway::ID === $current_section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Sections tab.
|
||||
*/
|
||||
public function render() {
|
||||
if ( ! $this->should_render() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
//phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$current = ! isset( $_GET[ self::KEY ] ) ? 'paypal' : sanitize_text_field( wp_unslash( $_GET[ self::KEY ] ) );
|
||||
$sections = array(
|
||||
'paypal' => __( 'PayPal', 'paypal-for-woocommerce' ),
|
||||
'dcc' => __( 'Credit Card', 'paypal-for-woocommerce' ),
|
||||
);
|
||||
|
||||
echo '<ul class="subsubsub">';
|
||||
|
||||
$array_keys = array_keys( $sections );
|
||||
|
||||
foreach ( $sections as $id => $label ) {
|
||||
$url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&' . self::KEY . '=' . $id );
|
||||
echo '<li><a href="' . esc_url( $url ) . '" class="' . ( $current === $id ? 'current' : '' ) . '">' . esc_html( $label ) . '</a> ' . ( end( $array_keys ) === $id ? '' : '|' ) . ' </li>';
|
||||
}
|
||||
|
||||
echo '</ul><br class="clear" />';
|
||||
}
|
||||
}
|
|
@ -212,8 +212,9 @@ class SettingsRenderer {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
$is_dcc = isset($_GET[SectionsRenderer::KEY]) && 'dcc' === sanitize_text_field(wp_unslash($_GET[SectionsRenderer::KEY]));
|
||||
$nonce = wp_create_nonce( SettingsListener::NONCE );
|
||||
//phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$is_dcc = isset( $_GET[ SectionsRenderer::KEY ] ) && 'dcc' === sanitize_text_field( wp_unslash( $_GET[ SectionsRenderer::KEY ] ) );
|
||||
$nonce = wp_create_nonce( SettingsListener::NONCE );
|
||||
?>
|
||||
<input type="hidden" name="ppcp-nonce" value="<?php echo esc_attr( $nonce ); ?>">
|
||||
<?php
|
||||
|
|
|
@ -59,8 +59,8 @@ class WcGatewayModule implements ModuleInterface {
|
|||
|
||||
add_action(
|
||||
'woocommerce_sections_checkout',
|
||||
function() use ($container) {
|
||||
$section_renderer = $container->get('wcgateway.settings.sections-renderer');
|
||||
function() use ( $container ) {
|
||||
$section_renderer = $container->get( 'wcgateway.settings.sections-renderer' );
|
||||
/**
|
||||
* The Section Renderer.
|
||||
*
|
||||
|
@ -173,13 +173,13 @@ class WcGatewayModule implements ModuleInterface {
|
|||
$methods[] = $container->get( 'wcgateway.paypal-gateway' );
|
||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
|
||||
$screen = ! function_exists('get_current_screen') ? (object) ['id' => 'front'] : get_current_screen();
|
||||
$screen = ! function_exists( 'get_current_screen' ) ? (object) array( 'id' => 'front' ) : get_current_screen();
|
||||
/**
|
||||
* The DCC Applies object.
|
||||
*
|
||||
* @var DccApplies $dcc_applies
|
||||
*/
|
||||
if ( $screen->id !== 'woocommerce_page_wc-settings' && $dcc_applies->for_country_currency() ) {
|
||||
if ( 'woocommerce_page_wc-settings' !== $screen->id && $dcc_applies->for_country_currency() ) {
|
||||
$methods[] = $container->get( 'wcgateway.credit-card-gateway' );
|
||||
}
|
||||
return (array) $methods;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue