Astra_Admin_Ajax::astra_update_admin_setting()
Save settings.
Description
Return
(void)
Source
File: admin/includes/class-astra-admin-ajax.php
public function astra_update_admin_setting() {
$response_data = array( 'message' => $this->get_error_msg( 'permission' ) );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( $response_data );
}
if ( empty( $_POST ) ) {
$response_data = array( 'message' => $this->get_error_msg( 'invalid' ) );
wp_send_json_error( $response_data );
}
/**
* Nonce verification.
*/
if ( ! check_ajax_referer( 'astra_update_admin_setting', 'security', false ) ) {
$response_data = array( 'message' => $this->get_error_msg( 'nonce' ) );
wp_send_json_error( $response_data );
}
$get_bool_settings = $this->astra_admin_settings_typewise();
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$sub_option_key = isset( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : '';
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$sub_option_value = '';
// @codingStandardsIgnoreStart
if ( isset( $get_bool_settings[ $sub_option_key ] ) ) {
if ( 'bool' === $get_bool_settings[ $sub_option_key ] ) {
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$val = isset( $_POST['value'] ) && 'true' === sanitize_text_field( $_POST['value'] ) ? true : false;
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$sub_option_value = $val;
} else {
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$sub_option_value = $val;
}
}
// @codingStandardsIgnoreEnd
Astra_API_Init::update_admin_settings_option( $sub_option_key, $sub_option_value );
$response_data = array(
'message' => __( 'Successfully saved data!', 'astra' ),
);
wp_send_json_success( $response_data );
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 4.0.0 | Introduced. |