Prevent action running for non-instance screens
Co-Authored-By: grola <grola@users.noreply.github.com>
This commit is contained in:
parent
187eff6e95
commit
974d33eb85
|
@ -524,31 +524,47 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes and saves options.
|
* Processes and saves global shipping method options in the admin area.
|
||||||
* If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out.
|
*
|
||||||
|
* This method is usually attached to woocommerce_update_options_x hooks.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @return bool was anything saved?
|
* @return bool was anything saved?
|
||||||
*/
|
*/
|
||||||
public function process_admin_options() {
|
public function process_admin_options() {
|
||||||
if ( $this->instance_id ) {
|
if ( $this->instance_id ) {
|
||||||
$this->init_instance_settings();
|
return $this->process_instance_options();
|
||||||
|
}
|
||||||
|
|
||||||
$post_data = $this->get_post_data();
|
return parent::process_admin_options();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ( $this->get_instance_form_fields() as $key => $field ) {
|
/**
|
||||||
if ( 'title' !== $this->get_field_type( $field ) ) {
|
* Processes and saves options for a shipping method instance.
|
||||||
try {
|
*
|
||||||
$this->instance_settings[ $key ] = $this->get_field_value( $key, $field, $post_data );
|
* @since 3.4.1
|
||||||
} catch ( Exception $e ) {
|
* @return bool was anything saved?
|
||||||
$this->add_error( $e->getMessage() );
|
*/
|
||||||
}
|
public function process_instance_options() {
|
||||||
|
// Check we are processing the correct form for this instance.
|
||||||
|
if ( ! $this->instance_id || ! isset( $_REQUEST['instance_id'] ) || absint( $_REQUEST['instance_id'] ) !== $this->instance_id ) { // WPCS: input var ok, CSRF ok.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->init_instance_settings();
|
||||||
|
|
||||||
|
$post_data = $this->get_post_data();
|
||||||
|
|
||||||
|
foreach ( $this->get_instance_form_fields() as $key => $field ) {
|
||||||
|
if ( 'title' !== $this->get_field_type( $field ) ) {
|
||||||
|
try {
|
||||||
|
$this->instance_settings[ $key ] = $this->get_field_value( $key, $field, $post_data );
|
||||||
|
} catch ( Exception $e ) {
|
||||||
|
$this->add_error( $e->getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return update_option( $this->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $this->id . '_instance_settings_values', $this->instance_settings, $this ) );
|
|
||||||
} else {
|
|
||||||
return parent::process_admin_options();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return update_option( $this->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $this->id . '_instance_settings_values', $this->instance_settings, $this ), 'yes' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue