Blueprint - Split settings exporter to multiple to handle each section and remove… (#55216)
Some checks failed
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (1, 10) (push) Failing after 8m16s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (10, 10) (push) Failing after 12m16s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (2, 10) (push) Failing after 12m14s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (3, 10) (push) Failing after 12m12s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (4, 10) (push) Failing after 12m10s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (5, 10) (push) Failing after 12m8s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (6, 10) (push) Failing after 12m7s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (7, 10) (push) Failing after 12m5s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (8, 10) (push) Failing after 12m3s
Blocks Playwright Tests / Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }} (9, 10) (push) Failing after 12m1s
Blocks Playwright Tests / Merge Artifacts (push) Has been cancelled
Blocks Playwright Tests / Create GitHub issues for flaky tests (push) Has been cancelled

* Split settings exporter to multiple to handle each section and remove tasklist options and core profiler.

* Add changefile(s) from automation for the following project(s): woocommerce

* Fix lint issue

* Add strict declaration

* Add back changes reverted by accident

* Add missing period

* Make sure `options` is an object

* Use `replace into` -- insert ignore is not supported in Playground (sqlite)

* Ignore setSiteOptions validation for now

* Remove shipping local pick up settings

* Update copy -- remove list of settings

* Force array when updating option value

* Fix link container spacing

* Re-enable shipping pickup setting

* Refactor - separate out a base class for ExportWCSXettings* classes

* Lint fixes

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Moon 2025-02-14 12:48:27 -08:00 committed by GitHub
parent 284d195cd1
commit b671eb745f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 643 additions and 205 deletions

View File

@ -27,10 +27,7 @@ class ImportSetSiteOptions implements StepProcessor {
public function process( $schema ): StepProcessorResult {
$result = StepProcessorResult::success( SetSiteOptions::get_step_name() );
foreach ( $schema->options as $key => $value ) {
if ( is_object( $value ) ) {
$value = (array) $value;
}
$value = json_decode( json_encode( $value ), true );
$updated = $this->wp_update_option( $key, $value );
if ( $updated ) {

View File

@ -46,12 +46,9 @@ class SetSiteOptions extends Step {
'type' => 'string',
'enum' => array( static::get_step_name() ),
),
'options' => array(
'type' => 'object',
'additionalProperties' => new \stdClass(),
),
),
'required' => array( 'step', 'options' ),
'required' => array( 'step' ),
);
}
@ -63,7 +60,7 @@ class SetSiteOptions extends Step {
public function prepare_json_array(): array {
return array(
'step' => static::get_step_name(),
'options' => $this->options,
'options' => (object) $this->options,
);
}
}

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Refactored ExportWCSettings by splitting it into multiple exporters, each handling a specific section.

View File

@ -28,7 +28,7 @@ export const OverwriteConfirmationModal: React.FC<
>
<p className="woocommerce-blueprint-overwrite-modal__description">
{ __(
'Importing the file will overwrite the current configuration for the following items in WooCommerce Settings:',
'Importing the file will overwrite the current configuration in WooCommerce Settings.',
'woocommerce'
) }
</p>

View File

@ -85,6 +85,7 @@ const Blueprint = () => {
link.setAttribute( 'download', 'woo-blueprint.json' );
}
linkContainer.appendChild( document.createElement( 'br' ) );
linkContainer.appendChild( link );
link.click();

View File

@ -83,6 +83,6 @@ class ExportWCPaymentGateways implements StepExporter {
* @return string
*/
public function get_description() {
return __( 'It includes payment gateways and their settings.', 'woocommerce' );
return __( 'It includes all settings in WooCommerce | Settings | Payments.', 'woocommerce' );
}
}

View File

@ -4,50 +4,28 @@ declare( strict_types = 1);
namespace Automattic\WooCommerce\Admin\Features\Blueprint\Exporters;
use Automattic\WooCommerce\Admin\Features\Blueprint\SettingOptions;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
use Automattic\WooCommerce\Blueprint\Util;
use WC_Admin_Settings;
use WC_Settings_Page;
/**
* Class ExportWCSettings
* Class ExportWCSettingsGeneral
*
* This class exports WooCommerce settings and implements the StepExporter and HasAlias interfaces.
*
* @package Automattic\WooCommerce\Admin\Features\Blueprint\Exporters
*/
class ExportWCSettings implements StepExporter, HasAlias {
abstract class ExportWCSettings implements StepExporter, HasAlias {
use UseWPFunctions;
/**
* Array of WC_Settings_Page objects.
* Return a page I.D to export.
*
* @var WC_Settings_Page[]
* @return string The page ID.
*/
private array $setting_pages;
/**
* Array of page IDs to exclude from export.
*
* @var array
*/
private array $exclude_pages = array( 'integration', 'site-visibility' );
/**
* Constructor.
*
* @param array $setting_pages Optional array of setting pages.
*/
public function __construct( array $setting_pages = array() ) {
if ( empty( $setting_pages ) ) {
$setting_pages = WC_Admin_Settings::get_settings_pages();
}
$this->setting_pages = $setting_pages;
$this->wp_add_filter( 'wooblueprint_export_settings', array( $this, 'add_site_visibility_settings' ), 10, 3 );
}
abstract protected function get_page_id(): string;
/**
* Export WooCommerce settings.
@ -55,144 +33,10 @@ class ExportWCSettings implements StepExporter, HasAlias {
* @return SetSiteOptions
*/
public function export() {
$pages = array();
$options = array();
$option_info = array();
foreach ( $this->setting_pages as $page ) {
$id = $page->get_id();
if ( in_array( $id, $this->exclude_pages, true ) ) {
continue;
}
$pages[ $id ] = $this->get_page_info( $page );
foreach ( $pages[ $id ]['options'] as $option ) {
$options[ $option['id'] ] = $option['value'];
$option_info[ $option['id'] ] = array(
'location' => $option['location'],
'title' => $option['title'],
);
}
unset( $pages[ $id ]['options'] );
}
$filtered = $this->wp_apply_filters( 'wooblueprint_export_settings', $options, $pages, $option_info );
return new SetSiteOptions( $filtered['options'] );
$setting_options = new SettingOptions();
return new SetSiteOptions( $setting_options->get_page_options( $this->get_page_id() ) );
}
/**
* Get information about a settings page.
*
* @param WC_Settings_Page $page The settings page.
* @return array
*/
protected function get_page_info( WC_Settings_Page $page ) {
$info = array(
'label' => $page->get_label(),
'sections' => array(),
);
foreach ( $page->get_sections() as $id => $section ) {
$section_id = Util::camel_to_snake( strtolower( $section ) );
$info['sections'][ $section_id ] = array(
'label' => $section,
'subsections' => array(),
);
$settings = $page->get_settings_for_section( $id );
// Get subsections.
$subsections = array_filter(
$settings,
function ( $setting ) {
return isset( $setting['type'] ) && 'title' === $setting['type'] && isset( $setting['title'] );
}
);
foreach ( $subsections as $subsection ) {
if ( ! isset( $subsection['id'] ) ) {
$subsection['id'] = Util::camel_to_snake( strtolower( $subsection['title'] ) );
}
$info['sections'][ $section_id ]['subsections'][ $subsection['id'] ] = array(
'label' => $subsection['title'],
);
}
// Get options.
$info['options'] = $this->get_page_section_settings( $settings, $page->get_id(), $section_id );
}
return $info;
}
/**
* Get settings for a specific page section.
*
* @param array $settings The settings.
* @param string $page The page ID.
* @param string $section The section ID.
* @return array
*/
private function get_page_section_settings( $settings, $page, $section = '' ) {
$current_title = '';
$data = array();
foreach ( $settings as $setting ) {
if ( 'sectionend' === $setting['type'] || 'slotfill_placeholder' === $setting['type'] || ! isset( $setting['id'] ) ) {
continue;
}
if ( 'title' === $setting['type'] ) {
$current_title = Util::camel_to_snake( strtolower( $setting['title'] ) );
} else {
$location = $page . '.' . $section;
if ( $current_title ) {
$location .= '.' . $current_title;
}
$data[] = array(
'id' => $setting['id'],
'value' => $this->wp_get_option( $setting['id'], $setting['default'] ?? null ),
'title' => $setting['title'] ?? $setting['desc'] ?? '',
'location' => $location,
);
}
}
return $data;
}
/**
* Add site visibility settings.
*
* @param array $options The options array.
* @param array $pages The pages array.
* @param array $option_info The option information array.
* @return array
*/
public function add_site_visibility_settings( array $options, array $pages, array $option_info ) {
$pages['site_visibility'] = array(
'label' => 'Site Visibility',
'sections' => array(
'general' => array(
'label' => 'General',
),
),
);
$options['woocommerce_coming_soon'] = $this->wp_get_option( 'woocommerce_coming_soon' );
$options['woocommerce_store_pages_only'] = $this->wp_get_option( 'woocommerce_store_pages_only' );
$option_info['woocommerce_coming_soon'] = array(
'location' => 'site_visibility.general',
'title' => 'Coming soon',
);
$option_info['woocommerce_store_pages_only'] = array(
'location' => 'site_visibility.general',
'title' => 'Apply to store pages only',
);
return compact( 'options', 'pages', 'option_info' );
}
/**
* Get the name of the step.
@ -209,7 +53,7 @@ class ExportWCSettings implements StepExporter, HasAlias {
* @return string
*/
public function get_alias() {
return 'setWCSettings';
return 'setWCSettingsGeneral';
}
/**
@ -227,6 +71,6 @@ class ExportWCSettings implements StepExporter, HasAlias {
* @return string
*/
public function get_description() {
return __( 'It includes general store options.', 'woocommerce' );
return __( 'It includes all settings in WooCommerce | Settings | General.', 'woocommerce' );
}
}

View File

@ -0,0 +1,58 @@
<?php
declare( strict_types = 1);
namespace Automattic\WooCommerce\Admin\Features\Blueprint\Exporters;
use Automattic\WooCommerce\Admin\Features\Blueprint\SettingOptions;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
/**
* Class ExportWCSettingsProducts
*
* This class exports WooCommerce settings and implements the StepExporter and HasAlias interfaces.
*
* @package Automattic\WooCommerce\Admin\Features\Blueprint\Exporters
*/
class ExportWCSettingsAccount extends ExportWCSettings {
use UseWPFunctions;
/**
* Get the alias for this exporter.
*
* @return string
*/
public function get_alias() {
return 'setWCSettingsAccount';
}
/**
* Return label used in the frontend.
*
* @return string
*/
public function get_label() {
return __( 'Account and Privacy', 'woocommerce' );
}
/**
* Return description used in the frontend.
*
* @return string
*/
public function get_description() {
return __( 'It includes all settings in WooCommerce | Settings | Account and Privacy.', 'woocommerce' );
}
/**
* Get the page ID for the settings page.
*
* @return string
*/
protected function get_page_id(): string {
return 'account';
}
}

View File

@ -0,0 +1,58 @@
<?php
declare( strict_types = 1);
namespace Automattic\WooCommerce\Admin\Features\Blueprint\Exporters;
use Automattic\WooCommerce\Admin\Features\Blueprint\SettingOptions;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
/**
* Class ExportWCSettingsProducts
*
* This class exports WooCommerce settings and implements the StepExporter and HasAlias interfaces.
*
* @package Automattic\WooCommerce\Admin\Features\Blueprint\Exporters
*/
class ExportWCSettingsAdvanced extends ExportWCSettings {
use UseWPFunctions;
/**
* Get the alias for this exporter.
*
* @return string
*/
public function get_alias() {
return 'setWCSettingsAdvanced';
}
/**
* Return label used in the frontend.
*
* @return string
*/
public function get_label() {
return __( 'Advanced', 'woocommerce' );
}
/**
* Return description used in the frontend.
*
* @return string
*/
public function get_description() {
return __( 'It includes all settings in WooCommerce | Settings | Advanced.', 'woocommerce' );
}
/**
* Get the page ID for the settings page.
*
* @return string
*/
protected function get_page_id(): string {
return 'advanced';
}
}

View File

@ -0,0 +1,58 @@
<?php
declare( strict_types = 1);
namespace Automattic\WooCommerce\Admin\Features\Blueprint\Exporters;
use Automattic\WooCommerce\Admin\Features\Blueprint\SettingOptions;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
/**
* Class ExportWCSettingsProducts
*
* This class exports WooCommerce settings and implements the StepExporter and HasAlias interfaces.
*
* @package Automattic\WooCommerce\Admin\Features\Blueprint\Exporters
*/
class ExportWCSettingsEmails extends ExportWCSettings {
use UseWPFunctions;
/**
* Get the alias for this exporter.
*
* @return string
*/
public function get_alias() {
return 'setWCSettingsEmails';
}
/**
* Return label used in the frontend.
*
* @return string
*/
public function get_label() {
return __( 'Emails', 'woocommerce' );
}
/**
* Return description used in the frontend.
*
* @return string
*/
public function get_description() {
return __( 'It includes all settings in WooCommerce | Settings | Emails.', 'woocommerce' );
}
/**
* Get the page ID for the settings page.
*
* @return string
*/
protected function get_page_id(): string {
return 'email';
}
}

View File

@ -0,0 +1,58 @@
<?php
declare( strict_types = 1);
namespace Automattic\WooCommerce\Admin\Features\Blueprint\Exporters;
use Automattic\WooCommerce\Admin\Features\Blueprint\SettingOptions;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
/**
* Class ExportWCSettingsGeneral
*
* This class exports WooCommerce settings and implements the StepExporter and HasAlias interfaces.
*
* @package Automattic\WooCommerce\Admin\Features\Blueprint\Exporters
*/
class ExportWCSettingsGeneral extends ExportWCSettings {
use UseWPFunctions;
/**
* Get the alias for this exporter.
*
* @return string
*/
public function get_alias() {
return 'setWCSettingsGeneral';
}
/**
* Return label used in the frontend.
*
* @return string
*/
public function get_label() {
return __( 'General', 'woocommerce' );
}
/**
* Return description used in the frontend.
*
* @return string
*/
public function get_description() {
return __( 'It includes all settings in WooCommerce | Settings | General.', 'woocommerce' );
}
/**
* Get the page ID for the settings page.
*
* @return string
*/
protected function get_page_id(): string {
return 'general';
}
}

View File

@ -0,0 +1,58 @@
<?php
declare( strict_types = 1);
namespace Automattic\WooCommerce\Admin\Features\Blueprint\Exporters;
use Automattic\WooCommerce\Admin\Features\Blueprint\SettingOptions;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
/**
* Class ExportWCSettingsProducts
*
* This class exports WooCommerce settings and implements the StepExporter and HasAlias interfaces.
*
* @package Automattic\WooCommerce\Admin\Features\Blueprint\Exporters
*/
class ExportWCSettingsIntegrations extends ExportWCSettings {
use UseWPFunctions;
/**
* Get the alias for this exporter.
*
* @return string
*/
public function get_alias() {
return 'setWCSettingsIntegrations';
}
/**
* Return label used in the frontend.
*
* @return string
*/
public function get_label() {
return __( 'Integrations', 'woocommerce' );
}
/**
* Return description used in the frontend.
*
* @return string
*/
public function get_description() {
return __( 'It includes all settings in WooCommerce | Settings | Integrations.', 'woocommerce' );
}
/**
* Get the page ID for the settings page.
*
* @return string
*/
protected function get_page_id(): string {
return 'integration';
}
}

View File

@ -0,0 +1,58 @@
<?php
declare( strict_types = 1);
namespace Automattic\WooCommerce\Admin\Features\Blueprint\Exporters;
use Automattic\WooCommerce\Admin\Features\Blueprint\SettingOptions;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
/**
* Class ExportWCSettingsProducts
*
* This class exports WooCommerce settings and implements the StepExporter and HasAlias interfaces.
*
* @package Automattic\WooCommerce\Admin\Features\Blueprint\Exporters
*/
class ExportWCSettingsProducts extends ExportWCSettings {
use UseWPFunctions;
/**
* Get the alias for this exporter.
*
* @return string
*/
public function get_alias() {
return 'setWCSettingsProducts';
}
/**
* Return label used in the frontend.
*
* @return string
*/
public function get_label() {
return __( 'Products', 'woocommerce' );
}
/**
* Return description used in the frontend.
*
* @return string
*/
public function get_description() {
return __( 'It includes all settings in WooCommerce | Settings | Products.', 'woocommerce' );
}
/**
* Get the page ID for the settings page.
*
* @return string
*/
protected function get_page_id(): string {
return 'products';
}
}

View File

@ -0,0 +1,72 @@
<?php
declare( strict_types = 1);
namespace Automattic\WooCommerce\Admin\Features\Blueprint\Exporters;
use Automattic\WooCommerce\Admin\Features\Blueprint\SettingOptions;
use Automattic\WooCommerce\Blueprint\Exporters\HasAlias;
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\SetSiteOptions;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
/**
* Class ExportWCSettingsProducts
*
* This class exports WooCommerce settings and implements the StepExporter and HasAlias interfaces.
*
* @package Automattic\WooCommerce\Admin\Features\Blueprint\Exporters
*/
class ExportWCSettingsSiteVisibility implements StepExporter, HasAlias {
use UseWPFunctions;
/**
* Export Site Visibility settings.
*
* @return SetSiteOptions
*/
public function export() {
return new SetSiteOptions(
array(
'woocommerce_coming_soon' => $this->wp_get_option( 'woocommerce_coming_soon' ),
'woocommerce_store_pages_only' => $this->wp_get_option( 'woocommerce_store_pages_only' ),
)
);
}
/**
* Get the alias for this exporter.
*
* @return string
*/
public function get_alias() {
return 'setWCSettingsSiteVisibility';
}
/**
* Return label used in the frontend.
*
* @return string
*/
public function get_label() {
return __( 'Site Visibility', 'woocommerce' );
}
/**
* Return description used in the frontend.
*
* @return string
*/
public function get_description() {
return __( 'It includes all settings in WooCommerce | Settings | Visibility.', 'woocommerce' );
}
/**
* Get the name of the step.
*
* @return string
*/
public function get_step_name() {
return 'setSiteOptions';
}
}

View File

@ -71,12 +71,12 @@ class ExportWCShipping implements StepExporter, HasAlias {
);
$classes_steps = array_map(
fn( $class_row ) => new RunSql( Util::array_to_insert_sql( $class_row, $wpdb->prefix . 'term_taxonomy' ) ),
fn( $class_row ) => new RunSql( Util::array_to_insert_sql( $class_row, $wpdb->prefix . 'term_taxonomy', 'replace into' ) ),
$classes
);
$terms = array_map(
fn( $term ) => new RunSql( Util::array_to_insert_sql( $term, $wpdb->prefix . 'terms' ) ),
fn( $term ) => new RunSql( Util::array_to_insert_sql( $term, $wpdb->prefix . 'terms', 'replace into' ) ),
$this->get_terms( $classes )
);
@ -107,7 +107,7 @@ class ExportWCShipping implements StepExporter, HasAlias {
* @return string
*/
public function get_description(): string {
return __( 'It includes shipping settings', 'woocommerce' );
return __( 'It includes all settings in WooCommerce | Settings | Shipping.', 'woocommerce' );
}
/**
@ -128,7 +128,7 @@ class ExportWCShipping implements StepExporter, HasAlias {
global $wpdb;
return array_map(
fn( $zone ) => new RunSql( Util::array_to_insert_sql( $zone, $wpdb->prefix . 'woocommerce_shipping_zones' ) ),
fn( $zone ) => new RunSql( Util::array_to_insert_sql( $zone, $wpdb->prefix . 'woocommerce_shipping_zones', 'replace into' ) ),
$wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_shipping_zones", ARRAY_A )
);
}
@ -142,7 +142,7 @@ class ExportWCShipping implements StepExporter, HasAlias {
global $wpdb;
return array_map(
fn( $location ) => new RunSql( Util::array_to_insert_sql( $location, $wpdb->prefix . 'woocommerce_shipping_zone_locations' ) ),
fn( $location ) => new RunSql( Util::array_to_insert_sql( $location, $wpdb->prefix . 'woocommerce_shipping_zone_locations', 'replace into' ) ),
$wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_shipping_zone_locations", ARRAY_A )
);
}
@ -164,11 +164,11 @@ class ExportWCShipping implements StepExporter, HasAlias {
return array_merge(
array_map(
fn( $method ) => new RunSql( Util::array_to_insert_sql( $method, $wpdb->prefix . 'woocommerce_shipping_zone_methods' ) ),
fn( $method ) => new RunSql( Util::array_to_insert_sql( $method, $wpdb->prefix . 'woocommerce_shipping_zone_methods', 'replace into' ) ),
$methods
),
array_map(
fn( $option ) => new RunSql( Util::array_to_insert_sql( $option, $wpdb->prefix . 'options' ) ),
fn( $option ) => new RunSql( Util::array_to_insert_sql( $option, $wpdb->prefix . 'options', 'replace into' ) ),
$method_options
)
);

View File

@ -40,7 +40,7 @@ class ExportWCTaxRates implements StepExporter, HasAlias {
global $wpdb;
$table = $wpdb->prefix . $table;
return array_map(
fn( $record ) => new RunSql( Util::array_to_insert_sql( $record, $table ) ),
fn( $record ) => new RunSql( Util::array_to_insert_sql( $record, $table, 'replace into' ) ),
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->get_results( "SELECT * FROM {$table}", ARRAY_A )
);
@ -61,7 +61,7 @@ class ExportWCTaxRates implements StepExporter, HasAlias {
* @return string Label text.
*/
public function get_label(): string {
return __( 'Tax Rates', 'woocommerce' );
return __( 'Tax', 'woocommerce' );
}
/**
@ -70,7 +70,7 @@ class ExportWCTaxRates implements StepExporter, HasAlias {
* @return string Description text.
*/
public function get_description(): string {
return __( 'It includes tax rates and locations.', 'woocommerce' );
return __( 'It includes all settings in WooCommerce | Settings | Tax.', 'woocommerce' );
}
/**

View File

@ -6,7 +6,13 @@ namespace Automattic\WooCommerce\Admin\Features\Blueprint;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCCoreProfilerOptions;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCPaymentGateways;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCSettings;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCSettingsAccount;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCSettingsAdvanced;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCSettingsEmails;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCSettingsGeneral;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCSettingsIntegrations;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCSettingsProducts;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCSettingsSiteVisibility;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCShipping;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCTaskOptions;
use Automattic\WooCommerce\Admin\Features\Blueprint\Exporters\ExportWCTaxRates;
@ -67,12 +73,16 @@ class Init {
*/
public function get_woo_exporters() {
$classnames = array(
ExportWCCoreProfilerOptions::class,
ExportWCSettings::class,
ExportWCPaymentGateways::class,
ExportWCShipping::class,
ExportWCTaskOptions::class,
ExportWCSettingsGeneral::class,
ExportWCSettingsProducts::class,
ExportWCTaxRates::class,
ExportWCShipping::class,
ExportWCPaymentGateways::class,
ExportWCSettingsAccount::class,
ExportWCSettingsEmails::class,
ExportWCSettingsIntegrations::class,
ExportWCSettingsSiteVisibility::class,
ExportWCSettingsAdvanced::class,
);
$exporters = array();
@ -106,6 +116,10 @@ class Init {
* @return array
*/
public function get_step_groups_for_js() {
$all_plugins = $this->wp_get_plugins();
$active_plugins = array_intersect_key( $all_plugins, array_flip( get_option( 'active_plugins', array() ) ) );
$active_theme = $this->wp_get_theme();
return array(
array(
'id' => 'settings',
@ -135,8 +149,8 @@ class Init {
'label' => $plugin['Name'],
);
},
array_keys( $this->wp_get_plugins() ),
$this->wp_get_plugins()
array_keys( $active_plugins ),
$active_plugins
),
),
array(
@ -144,15 +158,11 @@ class Init {
'description' => __( 'It includes all the installed themes.', 'woocommerce' ),
'label' => __( 'Themes', 'woocommerce' ),
'icon' => 'brush',
'items' => array_map(
function ( $key, $theme ) {
return array(
'id' => $key,
'label' => $theme['Name'],
);
},
array_keys( $this->wp_get_themes() ),
$this->wp_get_themes()
'items' => array(
array(
'id' => $active_theme->get_stylesheet(),
'label' => $active_theme->get( 'Name' ),
),
),
),
);

View File

@ -0,0 +1,165 @@
<?php
declare( strict_types = 1 );
namespace Automattic\WooCommerce\Admin\Features\Blueprint;
use Automattic\WooCommerce\Blueprint\UseWPFunctions;
use Automattic\WooCommerce\Blueprint\Util;
use WC_Admin_Settings;
use WC_Settings_Page;
/**
* Handles getting options from WooCommerce settings pages.
*
* Class SettingOptions
*/
class SettingOptions {
use UseWPFunctions;
/**
* Array of WC_Settings_Page objects.
*
* @var WC_Settings_Page[]
*/
private array $setting_pages;
/**
* Constructor.
*
* @param array $setting_pages Optional array of setting pages.
*/
public function __construct( array $setting_pages = array() ) {
if ( empty( $setting_pages ) ) {
$setting_pages = WC_Admin_Settings::get_settings_pages();
}
$this->setting_pages = $setting_pages;
}
/**
* Get options for a specific settings page.
*
* @param string $page_id The page ID.
* @return array
*/
public function get_page_options( $page_id ) {
$page = $this->get_page( $page_id );
$page_info = $this->get_page_info( $page );
$options = $this->merge_page_info_options( $page_info );
return array_column( $options, 'value', 'id' );
}
/**
* Get a settings page by ID.
*
* @param string $page_id The page ID.
* @return WC_Settings_Page|null
*/
public function get_page( $page_id ) {
foreach ( $this->setting_pages as $page ) {
$id = $page->get_id();
if ( $id === $page_id ) {
return $page;
}
}
return null;
}
/**
* Get information about a settings page.
*
* @param WC_Settings_Page $page The settings page.
* @return array
*/
protected function get_page_info( WC_Settings_Page $page ) {
$info = array(
'label' => $page->get_label(),
'sections' => array(),
'options' => array(),
);
foreach ( $page->get_sections() as $id => $section ) {
$section_id = Util::camel_to_snake( strtolower( $section ) );
$info['sections'][ $section_id ] = array(
'label' => $section,
'subsections' => array(),
);
$settings = $page->get_settings_for_section( $id );
// Get subsections.
$subsections = array_filter(
$settings,
function ( $setting ) {
return isset( $setting['type'] ) && 'title' === $setting['type'] && isset( $setting['title'] );
}
);
foreach ( $subsections as $subsection ) {
if ( ! isset( $subsection['id'] ) ) {
$subsection['id'] = Util::camel_to_snake( strtolower( $subsection['title'] ) );
}
$info['sections'][ $section_id ]['subsections'][ $subsection['id'] ] = array(
'label' => $subsection['title'],
);
}
// Get options.
$info['sections'][ $section_id ]['options'] = $this->get_page_section_settings( $settings, $page->get_id(), $section_id );
}
return $info;
}
/**
* Get settings for a specific page section.
*
* @param array $settings The settings.
* @param string $page The page ID.
* @param string $section The section ID.
* @return array
*/
private function get_page_section_settings( $settings, $page, $section = '' ) {
$current_title = '';
$data = array();
foreach ( $settings as $setting ) {
if ( 'sectionend' === $setting['type'] || 'slotfill_placeholder' === $setting['type'] || ! isset( $setting['id'] ) ) {
continue;
}
if ( 'title' === $setting['type'] ) {
$current_title = Util::camel_to_snake( strtolower( $setting['title'] ) );
} else {
$location = $page . '.' . $section;
if ( $current_title ) {
$location .= '.' . $current_title;
}
$data[] = array(
'id' => $setting['id'],
'value' => $this->wp_get_option( $setting['id'], $setting['default'] ?? null ),
'title' => $setting['title'] ?? $setting['desc'] ?? '',
'location' => $location,
);
}
}
return $data;
}
/**
* Merge page info options.
*
* @param array $page_info The page info.
*
* @return array|mixed
*/
private function merge_page_info_options( array $page_info ) {
$options = $page_info['options'];
foreach ( $page_info['sections'] as $section ) {
$options = array_merge( $options, $section['options'] );
}
return $options;
}
}