WC_Admin_Permalink_Settings::settings_save()publicWC 1.0

Save the settings.

Метод класса: WC_Admin_Permalink_Settings{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

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

Код WC_Admin_Permalink_Settings::settings_save() WC 9.4.2

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' ) ) { // WPCS: input var ok, sanitization ok.
		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'] ) ); // WPCS: input var ok, sanitization ok.
		$permalinks['tag_base']       = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_tag_slug'] ) ); // WPCS: input var ok, sanitization ok.
		$permalinks['attribute_base'] = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_attribute_slug'] ) ); // WPCS: input var ok, sanitization ok.

		// Generate product base.
		$product_base = isset( $_POST['product_permalink'] ) ? wc_clean( wp_unslash( $_POST['product_permalink'] ) ) : ''; // WPCS: input var ok, sanitization ok.

		if ( 'custom' === $product_base ) {
			if ( isset( $_POST['product_permalink_structure'] ) ) { // WPCS: input var ok.
				$product_base = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', trim( wp_unslash( $_POST['product_permalink_structure'] ) ) ) ); // WPCS: input var ok, sanitization ok.
			} else {
				$product_base = '/';
			}

			// This is an invalid base structure and breaks pages.
			if ( '/%product_cat%/' === trailingslashit( $product_base ) ) {
				$product_base = '/' . _x( 'product', 'slug', 'woocommerce' ) . $product_base;
			}
		} elseif ( empty( $product_base ) ) {
			$product_base = _x( 'product', 'slug', 'woocommerce' );
		}

		$permalinks['product_base'] = wc_sanitize_permalink( $product_base );

		// Shop base may require verbose page rules if nesting pages.
		$shop_page_id   = wc_get_page_id( 'shop' );
		$shop_permalink = ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' );

		if ( $shop_page_id && stristr( trim( $permalinks['product_base'], '/' ), $shop_permalink ) ) {
			$permalinks['use_verbose_page_rules'] = true;
		}

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