WordPress Settings API Overrides My Previous Value
WordPress Settings API Overrides My Previous Value
WordPress Settings API Overrides My Previous Value
$options = get_option( ‘textdomain_settings’ ); ?> <input type=”checkbox” name=”textdomain_settings[textdomain_checkbox_field_0]” <?php checked( $options[‘textdomain_checkbox_field_0’], 1 ); ?> value=”1″> <?php Use this settings under Callback Field Function or you can generate code form here for settings api directly.
Help to create the best plugin settings!
With the code that you’ve added to your question, you’re adding the HTML ‘checked’ attribute twice, which is probably why things are getting confused. You have it hard-coded as checked=”checked”, but then checked( 1, get_option( ‘theme_custom_option’ ), false ) will write another checked attribute corresponding to the actual value of the option. You should be … Read more
All the out-of-the-box API endpoints are documented quite well here: https://developer.wordpress.org/rest-api/reference/ A quick look in the relevant places didn’t turn up a way to get theme elements (although I might have missed it). It’s trivially easy to setup new API endpoints; here’s a quick example you could pop into your funcitons.php to ‘hard-wire’ into that … Read more
Warning: This page allows direct access to your site settings. You can break things here. Please be cautious!
Sanitization and validation input fields – Settings API
Nevermind, I figured it out. Here’s what I did in case anybody else wants to know. In my main php file in the plugin directory, I just added the following: if (get_option(‘new_option_name’) == ‘true’) { require_once plugin_dir_path(__FILE__) . ‘includes/theme/functions/add_id_user_admin.php’; }
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; } }
Is it possible to have a global parameter page which allows to configure other plugins in the same place?