Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent translations from being loaded too early #47113

Merged
merged 17 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/fix-l10n-too-early
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Removes several side effects in the code bases that caused translations to be loaded too early.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function load() {
add_action( 'pre_set_site_transient_update_themes', array( __CLASS__, 'transient_update_themes' ), 21, 1 );
add_action( 'upgrader_process_complete', array( __CLASS__, 'upgrader_process_complete' ) );
add_action( 'upgrader_pre_download', array( __CLASS__, 'block_expired_updates' ), 10, 2 );
add_action( 'plugins_loaded', array( __CLASS__, 'add_hook_for_modifying_update_notices' ) );
add_action( 'admin_init', array( __CLASS__, 'add_hook_for_modifying_update_notices' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/woocommerce/includes/class-wc-privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct() {
parent::__construct();

// Initialize data exporters and erasers.
add_action( 'plugins_loaded', array( $this, 'register_erasers_exporters' ) );
add_action( 'init', array( $this, 'register_erasers_exporters' ) );

// Cleanup orders daily - this is a callback on a daily cron event.
add_action( 'woocommerce_cleanup_personal_data', array( $this, 'queue_cleanup_personal_data' ) );
Expand Down
4 changes: 3 additions & 1 deletion plugins/woocommerce/includes/class-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ public function init_jetpack_connection_config() {
'connection',
array(
'slug' => 'woocommerce',
'name' => __( 'WooCommerce', 'woocommerce' ),
// Cannot use __() here because it would cause translations to be loaded too early.
// See https://github.com/woocommerce/woocommerce/pull/47113.
'name' => 'WooCommerce',
)
);
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/woocommerce/src/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public static function init() {
*/
protected static function missing_autoloader() {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
// This message is not translated as at this point it's too early to load translations.
error_log( // phpcs:ignore
esc_html__( 'Your installation of WooCommerce is incomplete. If you installed WooCommerce from GitHub, please refer to this document to set up your development environment: https://github.com/woocommerce/woocommerce/wiki/How-to-set-up-WooCommerce-development-environment', 'woocommerce' )
esc_html( 'Your installation of WooCommerce is incomplete. If you installed WooCommerce from GitHub, please refer to this document to set up your development environment: https://github.com/woocommerce/woocommerce/wiki/How-to-set-up-WooCommerce-development-environment' )
);
}
add_action(
Expand Down
299 changes: 156 additions & 143 deletions plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
*/
class CheckoutFields {

/**
* Core checkout fields.
*
* @var array
*/
private $core_fields;

/**
* Additional checkout fields.
*
Expand Down Expand Up @@ -91,144 +84,10 @@ class CheckoutFields {
*/
public function __construct( AssetDataRegistry $asset_data_registry ) {
$this->asset_data_registry = $asset_data_registry;
$this->core_fields = [
'email' => [
'label' => __( 'Email address', 'woocommerce' ),
'optionalLabel' => __(
'Email address (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'email',
'autocapitalize' => 'none',
'index' => 0,
],
'country' => [
'label' => __( 'Country/Region', 'woocommerce' ),
'optionalLabel' => __(
'Country/Region (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'country',
'index' => 1,
],
'first_name' => [
'label' => __( 'First name', 'woocommerce' ),
'optionalLabel' => __(
'First name (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'given-name',
'autocapitalize' => 'sentences',
'index' => 10,
],
'last_name' => [
'label' => __( 'Last name', 'woocommerce' ),
'optionalLabel' => __(
'Last name (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'family-name',
'autocapitalize' => 'sentences',
'index' => 20,
],
'company' => [
'label' => __( 'Company', 'woocommerce' ),
'optionalLabel' => __(
'Company (optional)',
'woocommerce'
),
'required' => false,
'hidden' => false,
'autocomplete' => 'organization',
'autocapitalize' => 'sentences',
'index' => 30,
],
'address_1' => [
'label' => __( 'Address', 'woocommerce' ),
'optionalLabel' => __(
'Address (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'address-line1',
'autocapitalize' => 'sentences',
'index' => 40,
],
'address_2' => [
'label' => __( 'Apartment, suite, etc.', 'woocommerce' ),
'optionalLabel' => __(
'Apartment, suite, etc. (optional)',
'woocommerce'
),
'required' => false,
'hidden' => false,
'autocomplete' => 'address-line2',
'autocapitalize' => 'sentences',
'index' => 50,
],
'city' => [
'label' => __( 'City', 'woocommerce' ),
'optionalLabel' => __(
'City (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'address-level2',
'autocapitalize' => 'sentences',
'index' => 70,
],
'state' => [
'label' => __( 'State/County', 'woocommerce' ),
'optionalLabel' => __(
'State/County (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'address-level1',
'autocapitalize' => 'sentences',
'index' => 80,
],
'postcode' => [
'label' => __( 'Postal code', 'woocommerce' ),
'optionalLabel' => __(
'Postal code (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'postal-code',
'autocapitalize' => 'characters',
'index' => 90,
],
'phone' => [
'label' => __( 'Phone', 'woocommerce' ),
'optionalLabel' => __(
'Phone (optional)',
'woocommerce'
),
'required' => false,
'hidden' => false,
'type' => 'tel',
'autocomplete' => 'tel',
'autocapitalize' => 'characters',
'index' => 100,
],
];

$this->fields_locations = [
// omit email from shipping and billing fields.
'address' => array_merge( \array_diff_key( array_keys( $this->core_fields ), array( 'email' ) ) ),
'address' => array_merge( \array_diff_key( $this->get_core_fields_keys(), array( 'email' ) ) ),
'contact' => array( 'email' ),
'order' => [],
];
Expand Down Expand Up @@ -620,13 +479,167 @@ function ( $value ) {
);
}

/**
* Returns the keys of all core fields.
*
* @return array An array of field keys.
*/
public function get_core_fields_keys() {
return [
'email',
'country',
'first_name',
'last_name',
'company',
'address_1',
'address_2',
'city',
'state',
'postcode',
'phone',
];
}

/**
* Returns an array of all core fields.
*
* @return array An array of fields.
*/
public function get_core_fields() {
return $this->core_fields;
return [
'email' => [
'label' => __( 'Email address', 'woocommerce' ),
'optionalLabel' => __(
'Email address (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'email',
'autocapitalize' => 'none',
'index' => 0,
],
'country' => [
'label' => __( 'Country/Region', 'woocommerce' ),
'optionalLabel' => __(
'Country/Region (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'country',
'index' => 1,
],
'first_name' => [
'label' => __( 'First name', 'woocommerce' ),
'optionalLabel' => __(
'First name (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'given-name',
'autocapitalize' => 'sentences',
'index' => 10,
],
'last_name' => [
'label' => __( 'Last name', 'woocommerce' ),
'optionalLabel' => __(
'Last name (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'family-name',
'autocapitalize' => 'sentences',
'index' => 20,
],
'company' => [
'label' => __( 'Company', 'woocommerce' ),
'optionalLabel' => __(
'Company (optional)',
'woocommerce'
),
'required' => false,
'hidden' => false,
'autocomplete' => 'organization',
'autocapitalize' => 'sentences',
'index' => 30,
],
'address_1' => [
'label' => __( 'Address', 'woocommerce' ),
'optionalLabel' => __(
'Address (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'address-line1',
'autocapitalize' => 'sentences',
'index' => 40,
],
'address_2' => [
'label' => __( 'Apartment, suite, etc.', 'woocommerce' ),
'optionalLabel' => __(
'Apartment, suite, etc. (optional)',
'woocommerce'
),
'required' => false,
'hidden' => false,
'autocomplete' => 'address-line2',
'autocapitalize' => 'sentences',
'index' => 50,
],
'city' => [
'label' => __( 'City', 'woocommerce' ),
'optionalLabel' => __(
'City (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'address-level2',
'autocapitalize' => 'sentences',
'index' => 70,
],
'state' => [
'label' => __( 'State/County', 'woocommerce' ),
'optionalLabel' => __(
'State/County (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'address-level1',
'autocapitalize' => 'sentences',
'index' => 80,
],
'postcode' => [
'label' => __( 'Postal code', 'woocommerce' ),
'optionalLabel' => __(
'Postal code (optional)',
'woocommerce'
),
'required' => true,
'hidden' => false,
'autocomplete' => 'postal-code',
'autocapitalize' => 'characters',
'index' => 90,
],
'phone' => [
'label' => __( 'Phone', 'woocommerce' ),
'optionalLabel' => __(
'Phone (optional)',
'woocommerce'
),
'required' => false,
'hidden' => false,
'type' => 'tel',
'autocomplete' => 'tel',
'autocapitalize' => 'characters',
'index' => 100,
],
];
}

/**
Expand Down
7 changes: 7 additions & 0 deletions plugins/woocommerce/src/Internal/Admin/Marketplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class Marketplace {
* @internal
*/
final public function init() {
add_action( 'init', array( $this, 'on_init' ) );
}

/**
* Hook into WordPress on init.
*/
public function on_init() {
if ( false === FeaturesUtil::feature_is_enabled( 'marketplace' ) ) {
/** Feature controller instance @var FeaturesController $feature_controller */
$feature_controller = wc_get_container()->get( FeaturesController::class );
Expand Down
Loading
Loading