diff --git a/jest.config.js b/jest.config.js index 77751a3b34..7606dd2eab 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,7 +13,6 @@ module.exports = { '.*\\.svg$': '/src/test/svgr-mock.js', '\\.(mp4|webm|png|jpg|jpeg|gif)$': '/src/test/file-stub.js', '^stackable$': '/src/test/stackable-mock.js', - '@wordpress/api$': '/src/test/wp-api-stub.js', '@wordpress/ajax$': '/src/test/wp-admin-stub.js', '@wordpress/codeEditor$': '/src/test/wp-admin-stub.js', '@wordpress/plugins$': '/src/test/wp-admin-stub.js', diff --git a/src/components/base-control2/label-tooltip.js b/src/components/base-control2/label-tooltip.js index 939bbba4ef..1b1b7fe19c 100644 --- a/src/components/base-control2/label-tooltip.js +++ b/src/components/base-control2/label-tooltip.js @@ -15,7 +15,7 @@ import { fetchSettings } from '~stackable/util' import { useRef, useState, useEffect, } from '@wordpress/element' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' import domReady from '@wordpress/dom-ready' const LabelTooltip = props => { @@ -138,10 +138,13 @@ function useHelpTooltipEnabled() { const updateHelpTooltipEnabled = newValue => { helpTooltipEnabled = newValue - const model = new models.Settings( { - stackable_help_tooltip_disabled: newValue ? '' : '1', // eslint-disable-line + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { + stackable_help_tooltip_disabled: newValue ? '' : '1', // eslint-disable-line + }, } ) - model.save() // Let the other components know that the value has changed. window.dispatchEvent( new CustomEvent( '_stkHelpTooltipEnabledChanged', { detail: newValue } ) ) diff --git a/src/components/guided-modal-tour/index.js b/src/components/guided-modal-tour/index.js index b410dd676e..ed086b8061 100644 --- a/src/components/guided-modal-tour/index.js +++ b/src/components/guided-modal-tour/index.js @@ -18,7 +18,7 @@ import { guidedTourStates } from 'stackable' /** * WordPress dependencies */ -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' import { useEffect, useState, lazy, Suspense, memo, } from '@wordpress/element' @@ -92,9 +92,12 @@ const GuidedModalTour = memo( props => { // Update the stackable_guided_tour_states setting if ( ! guidedTourStates.includes( tourId ) ) { - // eslint-disable-next-line camelcase - const settings = new models.Settings( { stackable_guided_tour_states: [ ...guidedTourStates, tourId ] } ) - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + // eslint-disable-next-line camelcase + data: { stackable_guided_tour_states: [ ...guidedTourStates, tourId ] }, + } ) } // Soft update the global variable to prevent the tour from being shown again. diff --git a/src/deprecated/v2/init.php b/src/deprecated/v2/init.php index 8ede3bd3da..2b1e74dee7 100644 --- a/src/deprecated/v2/init.php +++ b/src/deprecated/v2/init.php @@ -232,7 +232,7 @@ function stackable_block_editor_assets_v2() { } // Backend editor scripts: blocks. - $dependencies = array( 'ugb-block-js', 'code-editor', 'wp-blocks', 'wp-element', 'wp-components', 'wp-util', 'wp-plugins', 'wp-i18n', 'wp-api' ); + $dependencies = array( 'ugb-block-js', 'code-editor', 'wp-blocks', 'wp-element', 'wp-components', 'wp-util', 'wp-plugins', 'wp-i18n', 'wp-api-fetch' ); wp_register_script( 'ugb-block-js-v2', plugins_url( 'dist/deprecated/editor_blocks_deprecated_v2.js', STACKABLE_FILE ), diff --git a/src/deprecated/v2/welcome/admin.js b/src/deprecated/v2/welcome/admin.js index 495efef943..f075c1f446 100644 --- a/src/deprecated/v2/welcome/admin.js +++ b/src/deprecated/v2/welcome/admin.js @@ -7,7 +7,7 @@ import { } from '@wordpress/element' import { send as ajaxSend } from '@wordpress/ajax' import { Spinner } from '@wordpress/components' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' /** * External dependencies @@ -123,8 +123,11 @@ export const OptimizationSettings = ( { searchSettings } ) => { }, [] ) const updateOptimizeScriptLoad = value => { - const model = new models.Settings( { stackable_optimize_script_load: value } ) // eslint-disable-line camelcase - model.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { stackable_optimize_script_load: value }, // eslint-disable-line camelcase + } ) setOptimizeScriptLoad( value ) } diff --git a/src/init.php b/src/init.php index 3b7613b37a..1dfd880c25 100644 --- a/src/init.php +++ b/src/init.php @@ -337,7 +337,7 @@ public function register_block_editor_assets() { plugins_url( 'dist/stk.js', STACKABLE_FILE ), // wp-util for wp.ajax. // wp-plugins & wp-edit-post for Gutenberg plugins. - array( 'code-editor', 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-api-fetch', 'wp-util', 'wp-plugins', 'wp-i18n', 'wp-api', 'lodash' ), + array( 'code-editor', 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-api-fetch', 'wp-util', 'wp-plugins', 'wp-i18n', 'lodash' ), STACKABLE_VERSION ); diff --git a/src/lazy-components/cimo/index.js b/src/lazy-components/cimo/index.js index b0ef01f3a0..582250d1e2 100644 --- a/src/lazy-components/cimo/index.js +++ b/src/lazy-components/cimo/index.js @@ -9,7 +9,7 @@ import domReady from '@wordpress/dom-ready' import { useState, useRef, useEffect, } from '@wordpress/element' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' let isPolling = false let cimoData = { status: cimo?.status, action: cimo?.action } @@ -20,8 +20,11 @@ const CimoDownloadNotice = props => { const pollCountRef = useRef( 0 ) const onDismiss = () => { - const settings = new models.Settings( { stackable_hide_cimo_notice: true } ) // eslint-disable-line camelcase - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { stackable_hide_cimo_notice: true }, // eslint-disable-line camelcase + } ) if ( cimo ) { cimo.hideNotice = true diff --git a/src/plugins/global-settings/block-styles/store.js b/src/plugins/global-settings/block-styles/store.js index 51de7dba9c..d879f8663b 100644 --- a/src/plugins/global-settings/block-styles/store.js +++ b/src/plugins/global-settings/block-styles/store.js @@ -11,7 +11,7 @@ import { } from '@wordpress/data' import domReady from '@wordpress/dom-ready' import { __ } from '@wordpress/i18n' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' import { cloneDeep } from 'lodash' // Include all the stored state. @@ -45,9 +45,12 @@ const STORE_REDUCER = ( state = DEFAULT_STATE, action ) => { delete newBlockStyles[ action.blockName ] } - // eslint-disable-next-line camelcase - const settings = new models.Settings( { stackable_global_block_styles: newBlockStyles } ) - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + // eslint-disable-next-line camelcase + data: { stackable_global_block_styles: newBlockStyles }, + } ) return newBlockStyles } diff --git a/src/plugins/global-settings/color-schemes/color-scheme-picker.js b/src/plugins/global-settings/color-schemes/color-scheme-picker.js index 453f94f35a..505e6ddd46 100644 --- a/src/plugins/global-settings/color-schemes/color-scheme-picker.js +++ b/src/plugins/global-settings/color-schemes/color-scheme-picker.js @@ -31,7 +31,7 @@ import { useRef, useState, useEffect, } from '@wordpress/element' import { useSelect, dispatch } from '@wordpress/data' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' import { __, sprintf } from '@wordpress/i18n' import { applyFilters, doAction } from '@wordpress/hooks' @@ -146,15 +146,18 @@ const ColorSchemePicker = props => { const saveColorSchemeSettings = updatedColorSchemes => { clearTimeout( saveTimeout ) saveTimeout = setTimeout( () => { - const settings = new models.Settings( { - // Store an empty array if all color schemes have no values, - // which optimizes the frontend by skipping unnecessary color scheme calculations. - // Otherwise, save the provided updatedColorSchemes array. - stackable_global_color_schemes: hasNoColorSchemes( updatedColorSchemes ) ? [] : updatedColorSchemes, // eslint-disable-line camelcase - // Clear the cached CSS when the color scheme is updated - stackable_global_color_scheme_generated_css: '', // eslint-disable-line camelcase + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { + // Store an empty array if all color schemes have no values, + // which optimizes the frontend by skipping unnecessary color scheme calculations. + // Otherwise, save the provided updatedColorSchemes array. + stackable_global_color_schemes: hasNoColorSchemes( updatedColorSchemes ) ? [] : updatedColorSchemes, // eslint-disable-line camelcase + // Clear the cached CSS when the color scheme is updated + stackable_global_color_scheme_generated_css: '', // eslint-disable-line camelcase + }, } ) - settings.save() }, 300 ) // Update our store. diff --git a/src/plugins/global-settings/color-schemes/index.js b/src/plugins/global-settings/color-schemes/index.js index 10a1165f5f..faf7e6d4d1 100644 --- a/src/plugins/global-settings/color-schemes/index.js +++ b/src/plugins/global-settings/color-schemes/index.js @@ -26,7 +26,7 @@ import { addFilter } from '@wordpress/hooks' import { Fragment, useState } from '@wordpress/element' import { __ } from '@wordpress/i18n' import { useSelect, dispatch } from '@wordpress/data' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' export { GlobalColorSchemeStyles } from './editor-loader' @@ -53,11 +53,14 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-color-scheme const onChangeDefaultColorScheme = ( mode, colorSchemeKey ) => { clearTimeout( saveTimeout ) saveTimeout = setTimeout( () => { - const settings = new models.Settings( { - [ COLOR_SCHEME_OPTION_NAMES[ mode ] ]: colorSchemeKey, // eslint-disable-line camelcase - stackable_global_color_scheme_generated_css: '', // eslint-disable-line camelcase + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { + [ COLOR_SCHEME_OPTION_NAMES[ mode ] ]: colorSchemeKey, // eslint-disable-line camelcase + stackable_global_color_scheme_generated_css: '', // eslint-disable-line camelcase + }, } ) - settings.save() }, 300 ) // Update our store. @@ -141,8 +144,11 @@ addFilter( 'stackable.global-settings.inspector.global-colors.toggle-controls', hideColorSchemeColors: value, } ) - const settings = new models.Settings( { stackable_global_hide_color_scheme_colors: value } ) // eslint-disable-line camelcase - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { stackable_global_hide_color_scheme_colors: value }, // eslint-disable-line camelcase + } ) } return <> diff --git a/src/plugins/global-settings/colors/color-picker.js b/src/plugins/global-settings/colors/color-picker.js index 2f7dbfc075..f71cab8755 100644 --- a/src/plugins/global-settings/colors/color-picker.js +++ b/src/plugins/global-settings/colors/color-picker.js @@ -18,7 +18,7 @@ import { useRef } from '@wordpress/element' import { select, dispatch, useSelect, } from '@wordpress/data' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' import { __, sprintf } from '@wordpress/i18n' import { ColorIndicator, ColorPicker } from '@wordpress/components' @@ -61,8 +61,11 @@ const ColorPickers = props => { // Save settings. clearTimeout( saveTimeout ) saveTimeout = setTimeout( () => { - const settings = new models.Settings( { stackable_global_colors: [ newColors ] } ) // eslint-disable-line camelcase - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { stackable_global_colors: [ newColors ] }, // eslint-disable-line camelcase + } ) }, 300 ) // Update our store. diff --git a/src/plugins/global-settings/colors/index.js b/src/plugins/global-settings/colors/index.js index 05a1c603d8..dfb7245921 100644 --- a/src/plugins/global-settings/colors/index.js +++ b/src/plugins/global-settings/colors/index.js @@ -20,7 +20,7 @@ import { addFilter, applyFilters } from '@wordpress/hooks' import { Fragment } from '@wordpress/element' import { __ } from '@wordpress/i18n' import { dispatch, useSelect } from '@wordpress/data' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' export { GlobalColorStyles } @@ -80,8 +80,11 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-colors', out hideThemeColors: value, } ) - const settings = new models.Settings( { stackable_global_hide_theme_colors: value } ) // eslint-disable-line camelcase - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { stackable_global_hide_theme_colors: value }, // eslint-disable-line camelcase + } ) } const onChangeHideDefaultColors = value => { @@ -89,8 +92,11 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-colors', out hideDefaultColors: value, } ) - const settings = new models.Settings( { stackable_global_hide_default_colors: value } ) // eslint-disable-line camelcase - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { stackable_global_hide_default_colors: value }, // eslint-disable-line camelcase + } ) } const onChangeHideSiteEditorColors = value => { @@ -98,8 +104,11 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-colors', out hideSiteEditorColors: value, } ) - const settings = new models.Settings( { stackable_global_hide_site_editor_colors: value } ) // eslint-disable-line camelcase - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { stackable_global_hide_site_editor_colors: value }, // eslint-disable-line camelcase + } ) } const ColorToggleControls = applyFilters( 'stackable.global-settings.inspector.global-colors.toggle-controls', Fragment ) diff --git a/src/plugins/global-settings/typography/editor-loader.js b/src/plugins/global-settings/typography/editor-loader.js index 934a2a1c29..20256dedb1 100644 --- a/src/plugins/global-settings/typography/editor-loader.js +++ b/src/plugins/global-settings/typography/editor-loader.js @@ -29,7 +29,7 @@ import { addAction, removeAction, applyFilters, doAction, addFilter, } from '@wordpress/hooks' import { useSelect, dispatch } from '@wordpress/data' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' let saveTypographyAsPresetsThrottle = null @@ -101,8 +101,11 @@ export const GlobalTypographyStyles = () => { clearTimeout( saveTypographyAsPresetsThrottle ) saveTypographyAsPresetsThrottle = setTimeout( () => { - const settings = new models.Settings( { stackable_global_custom_preset_controls: newSettings } ) // eslint-disable-line camelcase - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { stackable_global_custom_preset_controls: newSettings }, // eslint-disable-line camelcase + } ) }, 300 ) dispatch( 'stackable/global-preset-controls.custom' ).updateCustomPresetControls( newSettings ) diff --git a/src/plugins/global-settings/typography/index.js b/src/plugins/global-settings/typography/index.js index 26afdfc055..c5e338ba83 100644 --- a/src/plugins/global-settings/typography/index.js +++ b/src/plugins/global-settings/typography/index.js @@ -39,7 +39,7 @@ import { import { Fragment, useEffect, useRef, useState, } from '@wordpress/element' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' import { addFilter, applyFilters, doAction, } from '@wordpress/hooks' @@ -240,10 +240,13 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography', clearTimeout( saveTypographyThrottle ) saveTypographyThrottle = setTimeout( () => { - const model = new models.Settings( { - stackable_global_typography: [ newSettings ], // eslint-disable-line + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { + stackable_global_typography: [ newSettings ], // eslint-disable-line + }, } ) - model.save() }, 500 ) dispatch( 'stackable/global-typography' ).updateSettings( newSettings ) @@ -254,10 +257,13 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography', clearTimeout( saveSelectedFontPairThrottle ) saveSelectedFontPairThrottle = setTimeout( () => { - const model = new models.Settings( { - stackable_selected_font_pair: name, // eslint-disable-line + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { + stackable_selected_font_pair: name, // eslint-disable-line + }, } ) - model.save() }, 500 ) } @@ -266,27 +272,36 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography', clearTimeout( saveCustomFontPairsThrottle ) saveCustomFontPairsThrottle = setTimeout( () => { - const model = new models.Settings( { - stackable_custom_font_pairs: [ ...fontPairs ] , // eslint-disable-line + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { + stackable_custom_font_pairs: [ ...fontPairs ] , // eslint-disable-line + }, } ) - model.save() }, 500 ) } const changeApplySettingsTo = value => { setApplySettingsTo( value ) - const model = new models.Settings( { - stackable_global_typography_apply_to: value, // eslint-disable-line + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { + stackable_global_typography_apply_to: value, // eslint-disable-line + }, } ) - model.save() } const changeIsApplyBodyToHTML = value => { setIsApplyBodyToHTML( value ) - const model = new models.Settings( { - stackable_is_apply_body_to_html: value, // eslint-disable-line + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { + stackable_is_apply_body_to_html: value, // eslint-disable-line + }, } ) - model.save() } const updateTypeScale = value => { diff --git a/src/plugins/global-settings/utils/use-block-layout-inspector-utils.js b/src/plugins/global-settings/utils/use-block-layout-inspector-utils.js index 17adaa9033..aa556f2d1b 100644 --- a/src/plugins/global-settings/utils/use-block-layout-inspector-utils.js +++ b/src/plugins/global-settings/utils/use-block-layout-inspector-utils.js @@ -14,7 +14,7 @@ import { useDeviceType, useBlockHoverState } from '~stackable/hooks' * WordPress dependencies */ import { __ } from '@wordpress/i18n' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' import { useSelect, dispatch } from '@wordpress/data' export const useBlockLayoutInspectorUtils = ( storeName, optionName, setDisplayHoverNotice, saveTimeout ) => { @@ -52,8 +52,11 @@ export const useBlockLayoutInspectorUtils = ( storeName, optionName, setDisplayH const saveSettings = newSettings => { clearTimeout( saveTimeout ) saveTimeout = setTimeout( () => { - const settings = new models.Settings( { [ optionName ]: newSettings } ) // eslint-disable-line camelcase - settings.save() + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: { [ optionName ]: newSettings }, + } ) }, 300 ) // Update our store. diff --git a/src/plugins/v2-migration-popup/index.js b/src/plugins/v2-migration-popup/index.js index dc9cef361b..6617caada6 100644 --- a/src/plugins/v2-migration-popup/index.js +++ b/src/plugins/v2-migration-popup/index.js @@ -4,27 +4,28 @@ import detectV2Blocks from './detect-v2-blocks' import MigrationModal from './migration-popover' +/** + * External dependencies + */ +import { fetchSettings } from '~stackable/util' + /** * WordPress dependencies */ import { registerPlugin } from '@wordpress/plugins' -import { loadPromise, models } from '@wordpress/api' -loadPromise.then( () => { - const settings = new models.Settings() - settings.fetch().then( response => { - // If the detector is already dismissed, don't show it any more. - if ( response.stackable_v2_block_detector_disabled ) { - return - } +fetchSettings().then( response => { + // If the detector is already dismissed, don't show it any more. + if ( response.stackable_v2_block_detector_disabled ) { + return + } - // Only do this when the v2 compatibility is not enabled at all. - if ( ! response.stackable_v2_editor_compatibility && ! response.stackable_v2_editor_compatibility_usage ) { - detectV2Blocks().then( hasV2Blocks => { - if ( hasV2Blocks ) { - registerPlugin( 'stackable-v2-migration-popup', { render: MigrationModal } ) - } - } ) - } - } ) + // Only do this when the v2 compatibility is not enabled at all. + if ( ! response.stackable_v2_editor_compatibility && ! response.stackable_v2_editor_compatibility_usage ) { + detectV2Blocks().then( hasV2Blocks => { + if ( hasV2Blocks ) { + registerPlugin( 'stackable-v2-migration-popup', { render: MigrationModal } ) + } + } ) + } } ) diff --git a/src/plugins/v2-migration-popup/migration-popover.js b/src/plugins/v2-migration-popup/migration-popover.js index d7a668671e..c13a3d29cf 100644 --- a/src/plugins/v2-migration-popup/migration-popover.js +++ b/src/plugins/v2-migration-popup/migration-popover.js @@ -11,7 +11,7 @@ import { } from '@wordpress/components' import { useState } from '@wordpress/element' import { __ } from '@wordpress/i18n' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' const MigrationModal = () => { const [ isOpen, setIsOpen ] = useState( true ) @@ -23,8 +23,11 @@ const MigrationModal = () => { const save = ( settings, refresh = false ) => { setIsBusy( true ) - const model = new models.Settings( settings ) - model.save().then( () => { + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: settings, + } ).then( () => { setIsBusy( false ) setIsOpen( false ) // Reload the page. diff --git a/src/test/wp-api-stub.js b/src/test/wp-api-stub.js deleted file mode 100644 index 1f5ea94f12..0000000000 --- a/src/test/wp-api-stub.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * This stub is needed for wp.api calls. - */ -module.exports = { - loadPromise: Promise.resolve(), - models: { - Settings: () => { - return { - save: () => {}, - fetch: () => Promise.resolve( {} ), - } - }, - }, -} diff --git a/src/util/admin.js b/src/util/admin.js index f10afd2a9a..8df103eb49 100644 --- a/src/util/admin.js +++ b/src/util/admin.js @@ -6,7 +6,6 @@ import { sortBy } from 'lodash' /** * WordPress dependencies */ -import { loadPromise } from '@wordpress/api' import apiFetch from '@wordpress/api-fetch' // Collect all the blocks and their variations for enabling/disabling and sort @@ -59,11 +58,12 @@ let fetchingPromise = null */ export const fetchSettings = () => { if ( ! fetchingPromise ) { - fetchingPromise = loadPromise.then( async () => { - const response = await apiFetch( { - path: '/stackable/v3/settings/', - method: 'GET', - } ) + // apiFetch can call a known REST path directly, so it does not need + // @wordpress/api's loadPromise. + fetchingPromise = apiFetch( { + path: '/stackable/v3/settings/', + method: 'GET', + } ).then( response => { fetchingPromise = null return response } ) diff --git a/src/welcome/admin.js b/src/welcome/admin.js index b621d886b6..5e13f2e5c4 100644 --- a/src/welcome/admin.js +++ b/src/welcome/admin.js @@ -18,7 +18,7 @@ import domReady from '@wordpress/dom-ready' import { Button, Flex, FlexItem, Spinner, CheckboxControl, Modal, } from '@wordpress/components' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' import { applyFilters } from '@wordpress/hooks' /** @@ -546,8 +546,11 @@ const Settings = () => { } setIsSaving( true ) setIsRecentlySaved( true ) - const model = new models.Settings( unsavedChanges ) - model.save().then( () => { + apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: unsavedChanges, + } ).then( () => { // Add a little more time for the spinner for better feedback setTimeout( () => { setIsSaving( false ) diff --git a/src/welcome/import-export/index.js b/src/welcome/import-export/index.js index fcea5c2352..bae3d02e98 100644 --- a/src/welcome/import-export/index.js +++ b/src/welcome/import-export/index.js @@ -11,7 +11,7 @@ import { import { useState, useMemo, Fragment, } from '@wordpress/element' -import { models } from '@wordpress/api' +import apiFetch from '@wordpress/api-fetch' /** * External dependencies @@ -90,8 +90,11 @@ const ImportSettings = ( { } if ( Object.keys( settingsToSave ).length > 0 ) { - const model = new models.Settings( settingsToSave ) - await model.save() + await apiFetch( { + path: '/wp/v2/settings', + method: 'POST', + data: settingsToSave, + } ) } setNotice( __( 'Settings imported successfully.', i18n ) ) diff --git a/src/welcome/index.php b/src/welcome/index.php index dda4588a6f..12040ecfc3 100644 --- a/src/welcome/index.php +++ b/src/welcome/index.php @@ -112,7 +112,7 @@ public function enqueue_dashboard_script( $hook ) { do_action( 'stackable_settings_admin_enqueue_scripts' ); - wp_enqueue_script( 'stackable-welcome', plugins_url( 'dist/admin_welcome.js', STACKABLE_FILE ), array( 'wp-i18n', 'wp-element', 'wp-hooks', 'wp-util', 'wp-components', 'wp-api', 'wp-editor', 'lodash' ), STACKABLE_VERSION ); + wp_enqueue_script( 'stackable-welcome', plugins_url( 'dist/admin_welcome.js', STACKABLE_FILE ), array( 'wp-i18n', 'wp-element', 'wp-hooks', 'wp-util', 'wp-components', 'wp-api-fetch', 'wp-editor', 'lodash' ), STACKABLE_VERSION ); // Add translations. wp_set_script_translations( 'stackable-welcome', STACKABLE_I18N );