This commit is contained in:
David Remer 2020-09-02 10:56:26 +03:00
parent cb37119a99
commit 4daca6dde0
4 changed files with 65 additions and 47 deletions

View file

@ -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&section=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;
}
}

View file

@ -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&section=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" />';
}
}

View file

@ -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

View file

@ -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;