rest workgin
This commit is contained in:
parent
2a6750ca31
commit
6f43506e51
|
@ -67,32 +67,31 @@ export const Content = ( { data, nonce } ) => {
|
|||
// body: JSON.stringify( gatherFormInputs() ),
|
||||
// } );
|
||||
|
||||
// const { page } = useSettingsLocation();
|
||||
// const formData = new FormData();
|
||||
// const formInputs = gatherFormInputs();
|
||||
// for ( const [ key, value ] of Object.entries( formInputs ) ) {
|
||||
// formData.append( key, value );
|
||||
// }
|
||||
// // Add _wpnonce to form data
|
||||
const { page } = useSettingsLocation();
|
||||
const formData = new FormData();
|
||||
const formInputs = gatherFormInputs();
|
||||
for ( const [ key, value ] of Object.entries( formInputs ) ) {
|
||||
formData.append( key, value );
|
||||
}
|
||||
// Add _wpnonce to form data
|
||||
// formData.append( '_wpnonce', nonce );
|
||||
// formData.append( 'save', 'Save changes' );
|
||||
// formData.append( 'save_type', 'modern_settings' );
|
||||
formData.append( 'save', 'Save changes' );
|
||||
|
||||
// const response = await fetch(
|
||||
// // `/wp-admin/admin.php?page=wc-settings&tab=${ page }`,
|
||||
// // `/wp-json/wc/v3/modern-settings`,
|
||||
// `/wp-json/wc-admin/settings`,
|
||||
// {
|
||||
// method: 'POST',
|
||||
// body: formData,
|
||||
// }
|
||||
// );
|
||||
const response = await fetch(
|
||||
// `/wp-admin/admin.php?page=wc-settings&tab=${ page }`,
|
||||
// `/wp-json/wc/v3/modern-settings`,
|
||||
'/wp-json/wc-admin/settings',
|
||||
{
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
}
|
||||
);
|
||||
|
||||
const response = await fetch( '/wp-json/wc-admin/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify( gatherFormInputs() ),
|
||||
} );
|
||||
// const response = await fetch( '/wp-json/wc-admin/settings', {
|
||||
// method: 'POST',
|
||||
// headers: { 'content-type': 'application/json' },
|
||||
// body: JSON.stringify( gatherFormInputs() ),
|
||||
// } );
|
||||
|
||||
console.log( response );
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
"build:project:copy-assets:admin": "wireit",
|
||||
"build:project:copy-assets:blocks": "wireit",
|
||||
"build:project:actualize-translation-domains": "wireit",
|
||||
"build:zip": "./bin/build-zip.sh",
|
||||
"changelog": "XDEBUG_MODE=off composer install --quiet && composer exec -- changelogger",
|
||||
"docker:down": "pnpm exec wc-e2e docker:down",
|
||||
"docker:ssh": "pnpm exec wc-e2e docker:ssh",
|
||||
|
@ -721,6 +720,7 @@
|
|||
"node_modules/@woocommerce/e2e-core-tests/CHANGELOG.md",
|
||||
"node_modules/@woocommerce/api/dist/",
|
||||
"node_modules/@woocommerce/admin-e2e-tests/build",
|
||||
"node_modules/@woocommerce/classic-assets/build",
|
||||
"node_modules/@woocommerce/block-library/build",
|
||||
"node_modules/@woocommerce/block-library/blocks.ini",
|
||||
"node_modules/@woocommerce/admin-library/build",
|
||||
|
|
|
@ -73,6 +73,7 @@ class Init {
|
|||
'Automattic\WooCommerce\Admin\API\MarketingCampaigns',
|
||||
'Automattic\WooCommerce\Admin\API\MarketingCampaignTypes',
|
||||
'Automattic\WooCommerce\Admin\API\Options',
|
||||
'Automattic\WooCommerce\Admin\API\Settings',
|
||||
'Automattic\WooCommerce\Admin\API\PaymentGatewaySuggestions',
|
||||
'Automattic\WooCommerce\Admin\API\Themes',
|
||||
'Automattic\WooCommerce\Admin\API\Plugins',
|
||||
|
|
|
@ -33,7 +33,6 @@ class Settings extends \WC_REST_Data_Controller {
|
|||
* Register routes.
|
||||
*/
|
||||
public function register_routes() {
|
||||
error_log( 'register_routes for settings' );
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
|
@ -43,6 +42,7 @@ class Settings extends \WC_REST_Data_Controller {
|
|||
'callback' => array( $this, 'save_settings' ),
|
||||
'permission_callback' => array( $this, 'permissions_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ class Settings extends \WC_REST_Data_Controller {
|
|||
*/
|
||||
public function permissions_check( $request ) {
|
||||
return true;
|
||||
// return current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,6 +64,25 @@ class Settings extends \WC_REST_Data_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function save_settings( $request ) {
|
||||
error_log('this is workign');
|
||||
return new \WP_REST_Response( array( 'status' => 'success' ) );
|
||||
}
|
||||
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'options',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'options' => array(
|
||||
'type' => 'array',
|
||||
'description' => __( 'Array of options with associated values.', 'woocommerce' ),
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue