Automattic\WooCommerce\Admin\Features
LaunchYourStore::save_site_visibility_options()
Save values submitted from WooCommerce -> Settings -> General.
Method of the class: LaunchYourStore{}
No Hooks.
Return
null
. Nothing (null).
Usage
$LaunchYourStore = new LaunchYourStore(); $LaunchYourStore->save_site_visibility_options();
LaunchYourStore::save_site_visibility_options() LaunchYourStore::save site visibility options code WC 9.8.2
public function save_site_visibility_options() { $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // New Settings API uses wp_rest nonce. $nonce_string = Features::is_enabled( 'settings' ) ? 'wp_rest' : 'woocommerce-settings'; if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, $nonce_string ) ) { return; } // options to allowed update and their allowed values. $options = array( 'woocommerce_coming_soon' => array( 'yes', 'no' ), 'woocommerce_store_pages_only' => array( 'yes', 'no' ), 'woocommerce_private_link' => array( 'yes', 'no' ), ); $event_data = array(); foreach ( $options as $name => $allowed_values ) { $current_value = get_option( $name, 'not set' ); $new_value = $current_value; if ( isset( $_POST[ $name ] ) ) { $input_value = sanitize_text_field( wp_unslash( $_POST[ $name ] ) ); // no-op if input value is invalid. if ( in_array( $input_value, $allowed_values, true ) ) { update_option( $name, $input_value ); $new_value = $input_value; // log the transition if there is one. if ( $current_value !== $new_value ) { $enabled_or_disabled = 'yes' === $new_value ? 'enabled' : 'disabled'; $event_data[ $name . '_toggled' ] = $enabled_or_disabled; } } } $event_data[ $name ] = $new_value; } wc_admin_record_tracks_event( 'site_visibility_saved', $event_data ); }