Answer the question
In order to leave comments, you need to log in
I can not understand why the parameters are not saved?
Why are the settings not saved?
The specific code where the fields are created and saved:
public function function_settings_fields() {
register_setting('export_google_sheets_settings','id_document', 'absint');
add_settings_section('export_settings_section_id', '', '', 'export_google_sheets' );
add_settings_field('id_document','ID документа (Гугл таблицы)',array( $this, 'function_get_settings' ),'export_google_sheets', 'export_settings_section_id',
array(
'label_for' => 'id_document',
'class' => 'id_document-class',
'name' => 'id_document',
)
);
/*********************************************************** */
register_setting('export_google_sheets_settings', 'id_document','absint');
add_settings_section('export_settings_id_list_section_id','', '', 'export_google_sheets' );
add_settings_field('id_list','ID листа (Гугл таблицы)',array( $this, 'function_get_settings' ), 'export_google_sheets', 'export_settings_id_list_section_id',
array(
'label_for' => 'id_list',
'class' => 'id_list-class',
'name' => 'id_list',
)
);
}
public function function_get_settings($args) {
$value = get_option( $args[ 'name' ] );
printf(
'<input type="text" min="1" id="%s" name="%s" value="'.$value.'" />',
esc_attr( $args[ 'name' ] ),
esc_attr( $args[ 'name' ] ),
absint( $value )
);
}
class export_sheets {
public function __construct() {
add_action('admin_menu', array( $this, 'function_settings' ) );
add_action('admin_init', array( $this, 'function_settings_fields' ) );
add_action( 'admin_notices', array( $this, 'settings_update_notice' ) );
}
public function function_settings() {
add_menu_page('Настройка экспорта информации','Экспорт Google Sheets', 'manage_options', 'export_google_sheets', array( $this, 'export_sheets_menu_callback' ), 'dashicons-admin-generic', 150 );
}
public function export_sheets_menu_callback() {
echo '<div class="wrap">
<h1>' . get_admin_page_title() . '</h1>
<form method="post" action="options.php">';
settings_fields( 'export_google_sheets_settings' );
do_settings_sections( 'export_google_sheets' );
submit_button();
echo '</form>
</div>';
}
public function function_settings_fields() {
register_setting('export_google_sheets_settings','id_document', 'absint');
add_settings_section('export_settings_section_id', '', '', 'export_google_sheets' );
add_settings_field('id_document','ID документа (Гугл таблицы)',array( $this, 'function_get_settings' ),'export_google_sheets', 'export_settings_section_id',
array(
'label_for' => 'id_document',
'class' => 'id_document-class',
'name' => 'id_document',
)
);
/*********************************************************** */
register_setting('export_google_sheets_settings', 'id_document','absint');
add_settings_section('export_settings_id_list_section_id','', '', 'export_google_sheets' );
add_settings_field('id_list','ID листа (Гугл таблицы)',array( $this, 'function_get_settings' ), 'export_google_sheets', 'export_settings_id_list_section_id',
array(
'label_for' => 'id_list',
'class' => 'id_list-class',
'name' => 'id_list',
)
);
}
public function function_get_settings($args) {
$value = get_option( $args[ 'name' ] );
printf(
'<input type="text" min="1" id="%s" name="%s" value="'.$value.'" />',
esc_attr( $args[ 'name' ] ),
esc_attr( $args[ 'name' ] ),
absint( $value )
);
}
function settings_update_notice() {
if(isset($_GET[ 'page' ]) && 'export_google_sheets' == $_GET['page'] && isset($_GET[ 'settings-updated' ]) && true == $_GET[ 'settings-updated' ]) {
echo '<div class="notice notice-success is-dismissible"><p>Настройки экспорта обновлены!</p></div>';
}
}
}
$export_sheets = new export_sheets();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question