mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- fixed saving empty value to multi texts fields;
This commit is contained in:
@@ -44,6 +44,7 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
|
||||
add_action( 'um_settings_before_save', array( $this, 'before_licenses_save' ) );
|
||||
add_action( 'um_settings_save', array( $this, 'licenses_save' ) );
|
||||
|
||||
add_filter( 'um_change_settings_before_save', array( $this, 'remove_empty_values' ), 10, 1 );
|
||||
|
||||
//invalid licenses notice
|
||||
add_action( 'admin_notices', array( $this, 'check_wrong_licenses' ) );
|
||||
@@ -1303,13 +1304,14 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
|
||||
if ( isset( $_POST['um-settings-action'] ) && 'save' == $_POST['um-settings-action'] && ! empty( $_POST['um_options'] ) ) {
|
||||
do_action( "um_settings_before_save" );
|
||||
|
||||
foreach ( $_POST['um_options'] as $key=>$value ) {
|
||||
$settings = apply_filters( 'um_change_settings_before_save', $_POST['um_options'] );
|
||||
|
||||
foreach ( $settings as $key=>$value ) {
|
||||
um_update_option( $key, $value );
|
||||
}
|
||||
|
||||
do_action( "um_settings_save" );
|
||||
|
||||
|
||||
//redirect after save settings
|
||||
$arg = array(
|
||||
'page' => 'um_options',
|
||||
@@ -1326,6 +1328,46 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove empty values from multi text fields
|
||||
*
|
||||
* @param $settings
|
||||
* @return array
|
||||
*/
|
||||
function remove_empty_values( $settings ) {
|
||||
$tab = '';
|
||||
if ( ! empty( $_GET['tab'] ) )
|
||||
$tab = $_GET['tab'];
|
||||
|
||||
$section = '';
|
||||
if ( ! empty( $_GET['section'] ) )
|
||||
$section = $_GET['section'];
|
||||
|
||||
if ( isset( $this->settings_structure[$tab]['sections'][$section]['fields'] ) )
|
||||
$fields = $this->settings_structure[$tab]['sections'][$section]['fields'];
|
||||
else
|
||||
$fields = $this->settings_structure[$tab]['fields'];
|
||||
|
||||
if ( empty( $fields ) )
|
||||
return $settings;
|
||||
|
||||
|
||||
$filtered_settings = array();
|
||||
foreach ( $settings as $key=>$value ) {
|
||||
|
||||
$filtered_settings[$key] = $value;
|
||||
|
||||
foreach( $fields as $field ) {
|
||||
if ( $field['id'] == $key && $field['type'] == 'multi_text' ) {
|
||||
$filtered_settings[$key] = array_filter( $settings[$key] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered_settings;
|
||||
}
|
||||
|
||||
|
||||
function on_settings_save() {
|
||||
if ( ! empty( $_POST['um_options'] ) ) {
|
||||
if ( ! empty( $_POST['pages_settings'] ) ) {
|
||||
|
||||
Reference in New Issue
Block a user