Automattic\WooCommerce\Internal\Admin\Agentic
AgenticSettingsPage::save_settings
Save settings to registry structure.
Method of the class: AgenticSettingsPage{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$AgenticSettingsPage = new AgenticSettingsPage(); $AgenticSettingsPage->save_settings();
AgenticSettingsPage::save_settings() AgenticSettingsPage::save settings code WC 10.5.0
public function save_settings() {
check_admin_referer( 'woocommerce-settings' );
$registry = $this->get_registry();
// Update general settings.
$registry['general'] = array(
'enable_products_default' => isset( $_POST['woocommerce_agentic_enable_products_default'] ) && '1' === $_POST['woocommerce_agentic_enable_products_default']
? 'yes'
: 'no',
);
// Update OpenAI settings.
$new_token = isset( $_POST['woocommerce_agentic_openai_bearer_token'] )
? sanitize_text_field( wp_unslash( $_POST['woocommerce_agentic_openai_bearer_token'] ) )
: '';
// Only update if a new token was provided; otherwise keep existing.
if ( ! empty( $new_token ) ) {
$registry['openai']['bearer_token'] = wp_hash_password( $new_token );
} elseif ( ! isset( $registry['openai']['bearer_token'] ) ) {
$registry['openai']['bearer_token'] = '';
}
/**
* Filter registry before saving.
*
* Allows extensions to save their own agent provider settings.
* Extensions can access $_POST directly for their settings but MUST sanitize all input
* using appropriate WordPress sanitization functions (sanitize_text_field, esc_url_raw, etc.)
* and call wp_unslash() on POST data.
*
* @since 10.4.0
*
* @internal This filter is experimental and behind a non-visible feature flag. Backwards compatibility not guaranted.
*
* @param array $registry Registry data to save. Extensions should add their provider settings to this array.
*/
$registry = apply_filters( 'woocommerce_agentic_commerce_save_settings', $registry );
// Save registry (don't autoload to prevent performance issues).
update_option( self::REGISTRY_OPTION, $registry, false );
}