Echo all API Settings sections?
Use the $wp_settings_sections global. It returns an array of settings sections.
Use the $wp_settings_sections global. It returns an array of settings sections.
The Settings API generally expects data in the key => value form. I’m sure it is possible to save array data using the Settings API, but it somewhat circumvents the purpose of the API. If I’m understanding your question correctly, you’re trying to take a Plugin Option, and use the value of that option to … Read more
This a really good question – my suggestion is to use transients. For instance, in your validation callback: wpse51669_validation_cb($settings){ //Perform validation checks if( $valid ){ //If settings validate return $validate_settings; } //Otherwise add settings error add_settings_error(‘my-plug-in-settings’,’error-with-xyz’, ‘I fell over’,’error’); //And add the failed settings to a transient set_transient( ‘my-plug-in-settings-invalid’, $settings, 60); return false; } Then … Read more
This is the way I like to handle collection of form inputs. Detailed explanation is in the comments. if( isset( $_POST ) ) { // Create an empty array. This is the one we’ll eventually store. $arr_store_me = array(); // Create a “whitelist” of posted values (field names) you’d like in your array. // The … Read more
I had the same problem, and here what works for me: function journal_check_cats_callback() { $options = get_option(‘journal_theme_blog_2_col’); $pag = journal_theme_blog_2_col; $_cats = get_terms( ‘category’ ); $html=””; foreach ($_cats as $term) { $checked = in_array($term->term_id, $options) ? ‘checked=”checked”‘ : ”; $html .= sprintf( ‘<input type=”checkbox” id=”%1$s[%2$s]” name=”%1$s[]” value=”%2$s” %3$s />’, $pag, $term->term_id, $checked ); $html .= … Read more
The limit is probably not WordPress specific, but caused by PHP. max_input_vars might be set to 1000, so not all fields might reach WordPress. You can store 4,294,967,295 or 4GB (232 – 1) characters in one option, so I don’t think this is your problem. If it is, you should consider a separate table.
The solution is to merge existing options before saving options in case not all options are presented on the page we are about save. So in the end of $sanitize_callback in register_setting function just before I return the data I call below function where $existing are all existing options saved in database. function merge_options( $existing, … Read more
Very simply put it puts some hidden fields into the form on an option page. Those hidden fields are then used to check if the request made to the browser are valid. For some more in dept information you could read the Codex about WP Nonces
You can call add_settings_section and add_settings_field any time before you do_settings_sections: add_action( ‘my_plugin_add_settings_sections’, function() { wp_remote_get( … ); add_settings_section( … ); add_settings_field( … ); }); // On the plugin settings page output do_action( ‘my_plugin_add_settings_sections’ ); do_settings_sections( … ); You’ll still want to register_setting() earlier though because that custom hook won’t be fired when your settings … Read more
Looks like your validation argument is negative. if ($foo != “”) { //means if foo not equal to empty space // do something when not empty // here you are setting an error } else { // do something when empty // here you are trying to do your normal operation } You are setting … Read more