mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Refactor germanized plugin asset loaded
This commit is contained in:
parent
e8118381fa
commit
66f29789fb
3 changed files with 67 additions and 35 deletions
39
modules/ppcp-compat/src/AdminContextTrait.php
Normal file
39
modules/ppcp-compat/src/AdminContextTrait.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* The compatibility module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Compat
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Compat;
|
||||
|
||||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
trait AdminContextTrait {
|
||||
|
||||
/**
|
||||
* Checks if current post id is from a PayPal order.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_paypal_order_edit_page(): bool {
|
||||
$post_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( ! $post_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order( $post_id );
|
||||
if ( ! is_a( $order, WC_Order::class ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $order->get_meta( PayPalGateway::ORDER_ID_META_KEY ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ use WC_Order;
|
|||
use WooCommerce\PayPalCommerce\Compat\Assets\CompatAssets;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WP_Theme;
|
||||
|
||||
|
@ -28,6 +29,8 @@ use WP_Theme;
|
|||
*/
|
||||
class CompatModule implements ModuleInterface {
|
||||
|
||||
use AdminContextTrait;
|
||||
|
||||
/**
|
||||
* Setup the compatibility module.
|
||||
*
|
||||
|
@ -48,14 +51,9 @@ class CompatModule implements ModuleInterface {
|
|||
public function run( ContainerInterface $c ): void {
|
||||
$this->initialize_ppec_compat_layer( $c );
|
||||
$this->fix_site_ground_optimizer_compatibility( $c );
|
||||
|
||||
$this->initialize_gzd_compat_layer( $c );
|
||||
|
||||
$asset_loader = $c->get( 'compat.assets' );
|
||||
assert( $asset_loader instanceof CompatAssets );
|
||||
|
||||
add_action( 'init', array( $asset_loader, 'register' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) );
|
||||
|
||||
$this->migrate_pay_later_settings( $c );
|
||||
$this->migrate_smart_button_settings( $c );
|
||||
|
||||
|
@ -128,6 +126,26 @@ class CompatModule implements ModuleInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
add_action(
|
||||
'admin_enqueue_scripts',
|
||||
/**
|
||||
* Param types removed to avoid third-party issues.
|
||||
*
|
||||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
function( $hook ) use ( $c ): void {
|
||||
if ( $hook !== 'post.php' || ! $this->is_paypal_order_edit_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$asset_loader = $c->get( 'compat.assets' );
|
||||
assert( $asset_loader instanceof CompatAssets );
|
||||
|
||||
$asset_loader->register();
|
||||
$asset_loader->enqueue();
|
||||
}
|
||||
);
|
||||
|
||||
$endpoint = $c->get( 'order-tracking.endpoint.controller' );
|
||||
assert( $endpoint instanceof OrderTrackingEndpoint );
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue