Skip to content

Commit

Permalink
Merge pull request #269 from woocommerce/fix/258
Browse files Browse the repository at this point in the history
Fix "Translation loading for the woocommerce-square domain was triggered too early" error on WP 6.7
  • Loading branch information
vikrampm1 authored Jan 24, 2025
2 parents 755bb62 + efd8158 commit 2b80ff6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
18 changes: 12 additions & 6 deletions includes/Admin/Privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,27 @@ class Privacy extends \WC_Abstract_Privacy {
*/
public function __construct() {

parent::__construct( __( 'Square', 'woocommerce-square' ) );
parent::__construct();

$this->add_eraser( 'woocommerce-square-customer-data', __( 'WooCommerce Square Customer Data', 'woocommerce-square' ), array( $this, 'customer_data_eraser' ) );
// Initialize data exporters and erasers.
add_action( 'init', array( $this, 'register_erasers_exporters' ) );
}

/**
* Initial registration of privacy erasers and exporters.
*/
public function register_erasers_exporters() {
$this->name = __( 'Square', 'woocommerce-square' );

$this->add_eraser( 'woocommerce-square-customer-data', __( 'WooCommerce Square Customer Data', 'woocommerce-square' ), array( $this, 'customer_data_eraser' ) );
}

/**
* Gets the message to display.
*
* @since 2.0.0
*/
public function get_message() {
public function get_privacy_message() {

return wpautop(
sprintf(
Expand Down Expand Up @@ -98,7 +107,4 @@ public function customer_data_eraser( $email_address, $page ) {
'done' => true,
);
}


}

26 changes: 17 additions & 9 deletions includes/Framework/PaymentGateway/Payment_Gateway_Privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,20 @@ public function __construct( Payment_Gateway_Plugin $plugin ) {

$this->plugin = $plugin;

parent::__construct( $plugin->get_plugin_name() );
parent::__construct();

// add the action & filter hooks
$this->add_hooks();

// add the token exporters & erasers
// translators: Placeholder %s - Plugin name
$this->add_exporter( "wc-{$plugin->get_id_dasherized()}-customer-tokens", sprintf( esc_html__( '%s Payment Tokens', 'woocommerce-square' ), $plugin->get_plugin_name() ), array( $this, 'customer_tokens_exporter' ) );

// translators: Placeholder %s - Plugin name
$this->add_eraser( "wc-{$plugin->get_id_dasherized()}-customer-tokens", sprintf( esc_html__( '%s Payment Tokens', 'woocommerce-square' ), $plugin->get_plugin_name() ), array( $this, 'customer_tokens_eraser' ) );
}


/**
* Adds the action & filter hooks.
*
* @since 3.0.0
*/
protected function add_hooks() {
// Initialize data exporters and erasers.
add_action( 'init', array( $this, 'register_erasers_exporters' ) );

// add the gateway data to customer data exports
add_filter( 'woocommerce_privacy_export_customer_personal_data', array( $this, 'add_export_customer_data' ), 10, 2 );
Expand All @@ -80,6 +74,20 @@ protected function add_hooks() {
add_action( 'woocommerce_privacy_remove_order_personal_data', array( $this, 'remove_order_personal_data' ) );
}

/**
* Initial registration of privacy erasers and exporters.
*/
public function register_erasers_exporters() {
$this->name = $this->plugin->get_plugin_name();

// add the token exporters & erasers
// translators: Placeholder %s - Plugin name
$this->add_exporter( "wc-{$this->plugin->get_id_dasherized()}-customer-tokens", sprintf( esc_html__( '%s Payment Tokens', 'woocommerce-square' ), $this->plugin->get_plugin_name() ), array( $this, 'customer_tokens_exporter' ) );

// translators: Placeholder %s - Plugin name
$this->add_eraser( "wc-{$this->plugin->get_id_dasherized()}-customer-tokens", sprintf( esc_html__( '%s Payment Tokens', 'woocommerce-square' ), $this->plugin->get_plugin_name() ), array( $this, 'customer_tokens_eraser' ) );
}


/** Customer methods ******************************************************/

Expand Down
24 changes: 16 additions & 8 deletions includes/Handlers/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,11 @@ public function __construct( Square\Plugin $plugin ) {

$this->plugin = $plugin;

// add common errors
$this->product_errors = array(
/* translators: Placeholder: %s - product name */
'missing_sku' => __( "Please add an SKU to sync %s with Square. The SKU must match the item's SKU in your Square account.", 'woocommerce-square' ),
/* translators: Placeholder: %s - product name */
'missing_variation_sku' => __( "Please add an SKU to every variation of %s for syncing with Square. Each SKU must be unique and match the corresponding item's SKU in your Square account.", 'woocommerce-square' ),
);

// Get gift card features status.
$gift_card_settings = get_option( Gift_Card::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, array() );
$this->gift_card_enabled = $gift_card_settings['enabled'] ?? 'no';

add_action( 'init', array( $this, 'register_common_errors' ) );
add_action( 'current_screen', array( $this, 'add_tabs' ), 99 );

// add hooks
Expand All @@ -91,6 +84,21 @@ public function __construct( Square\Plugin $plugin ) {
$this->add_product_sync_hooks();
}

/**
* Loads register common errors.
*
* @since x.x.x
*/
public function register_common_errors() {
// Add common errors.
$this->product_errors = array(
/* translators: Placeholder: %s - product name */
'missing_sku' => __( "Please add an SKU to sync %s with Square. The SKU must match the item's SKU in your Square account.", 'woocommerce-square' ),
/* translators: Placeholder: %s - product name */
'missing_variation_sku' => __( "Please add an SKU to every variation of %s for syncing with Square. Each SKU must be unique and match the corresponding item's SKU in your Square account.", 'woocommerce-square' ),
);
}

/**
* Adds hooks to the admin products edit screen.
*
Expand Down

0 comments on commit 2b80ff6

Please sign in to comment.