WC_Admin_Permalink_Settings::settings_save │ public │ WC 1.0

Save the settings.

Method of the class: WC_Admin_Permalink_Settings{}

No Hooks.

Returns

null. Nothing (null).

Usage

$WC_Admin_Permalink_Settings = new WC_Admin_Permalink_Settings();
$WC_Admin_Permalink_Settings->settings_save();

WC_Admin_Permalink_Settings::settings_save() code WC 11.2.1

public function settings_save() {
	if ( ! is_admin() ) {
		return;
	}

	// We need to save the options ourselves; settings api does not trigger save for the permalinks page.
	if ( isset( $_POST['permalink_structure'], $_POST['wc-permalinks-nonce'], $_POST['woocommerce_product_category_slug'], $_POST['woocommerce_product_tag_slug'], $_POST['woocommerce_product_attribute_slug'] ) && wp_verify_nonce( wp_unslash( $_POST['wc-permalinks-nonce'] ), 'wc-permalinks' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce is verified; permalink tokens require domain-specific cleaning.
		wc_switch_to_site_locale();

		$permalinks                   = (array) get_option( 'woocommerce_permalinks', array() );
		$permalinks['category_base']  = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_category_slug'] ) );
		$permalinks['tag_base']       = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_tag_slug'] ) );
		$permalinks['attribute_base'] = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_attribute_slug'] ) );

		/*
		 * The form only ever posts strings for these two fields, but nothing enforces that,
		 * and the resolver requires one. A non-string radio value resolves to the default
		 * product base; a non-string structure is passed as null, which resolves to the
		 * default base only when the radio selects the custom branch that reads it.
		 */
		// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by sanitize_text_field().
		$product_base = sanitize_text_field( isset( $_POST['product_permalink'] ) && is_string( $_POST['product_permalink'] ) ? wp_unslash( $_POST['product_permalink'] ) : '' );
		// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by wc_sanitize_permalink() inside the resolver.
		$posted_structure = isset( $_POST['product_permalink_structure'] ) && is_string( $_POST['product_permalink_structure'] ) ? wp_unslash( $_POST['product_permalink_structure'] ) : null;

		// Resolved inside the wc_switch_to_site_locale() window opened above, so the stored
		// value is the same site-locale form settings() compares against.
		$permalinks['product_base'] = $this->get_stored_product_base( $product_base, $posted_structure );

		update_option( 'woocommerce_permalinks', $permalinks );
		wc_restore_locale();
	}
}