Populate Dropdwon with DIR files, save value and keep it “selected”

You need to add a ‘selected’ value to the option output, so that the html displays the value that’s saved in the psg_settings. Something like this: function psg_dyn_select_1_render ( ) { $options = get_option( ‘psg_settings’ ); $files = glob( plugin_dir_path( __FILE__ ) . “assets/images/*” ); ?> <select name=”psg_settings[psg_dyn_select_1]”> <?php foreach ($files as $filename){ $filename = … Read more

How to get data from option page [closed]

I echoed out this $google_map_api_key = get_option(‘talimi_mapapi’); and its working fine. try in functions.php add require_once get_template_directory() . ‘/page-templates/theme-settings.php’; or add wp-load.php in your file. if you are using multi-site then try <?php get_site_option( $option, $default , $use_cache ) ?> reference https://codex.wordpress.org/Function_Reference/get_site_option

Multiple checkbox doesn’t work in wordpress settings api

Here is the function I used to solve the problem function username_editor_roles_callback() { global $wp_roles; $roles = $wp_roles->roles; foreach ($roles as $role) { $roleName = $role[‘name’]; $output = sprintf(‘<input type=”checkbox” id=”ue_roles_checkbox” name=”username_editor_settings[ue_roles_confirm][]” value=”%1$s” %2$s><label for=”ue_roles_checkbox”>%1$s</label><br>’, $roleName, checked( in_array($roleName, (array) ue_settings_option()[“ue_roles_confirm”]), 1, false ) ); echo $output; } }

Save Plugin Options as Array

Okey I got it. I was close the whole time 🙂 function weborder_leveranstext_render( ) { $options = get_option( ‘weborder_settings’ ); global $wp_roles; $all_roles = $wp_roles->get_names(); foreach ($all_roles as $role => $value) { echo ‘<br><span style=”width: 180px; display: inline-block;”>’ . $value . ‘</span>’; echo ‘<input type=”text” style=”width: 300px;” name=”weborder_settings[weborder_leveranstext][‘.$role.’]” value=”‘.$options[‘weborder_leveranstext’][$role].'”>’; } }