Submenu pages delete settings from options array when saved

Yep you are missing something, On your validate_options function you need to: get an array of all existing options. update only the options your Submenu page handles. return that array. So something like: function validate_options($input){ //do regular validation stuff //… //… //get all options $options = get_option(THEMENAME . ‘_settings’); //update only the neede options foreach … Read more

Fallback when Transient API fails

Mark Jaquith made a “TLC Transients” method that you might find useful. Essentially, it implements a transient interface that does soft expiration and background updating. https://github.com/markjaquith/WP-TLC-Transients The idea is that you define a function to do the call that gets the data, then define the transient and pass it that function as a callback. When … Read more

How to change option recently_edited?

The function is update_recently_edited in wp-admin/includes/misc.php. unfortunately it is fixed at 5: function update_recently_edited( $file ) { $oldfiles = (array) get_option( ‘recently_edited’ ); if ( $oldfiles ) { $oldfiles = array_reverse( $oldfiles ); $oldfiles[] = $file; $oldfiles = array_reverse( $oldfiles ); $oldfiles = array_unique( $oldfiles ); if ( 5 < count( $oldfiles )) array_pop( $oldfiles … Read more

delete_option() and update_option() returning false

The delete_option() function will return false if the option does not exist. The update_option() function will return false if the option already has the same value as what you’re trying to update it to. Both will also return false if the SQL query itself fails for whatever reason.

How to add a new plugin page under desired Options page?

Use add_submenu_page instead. <?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); ?> $parent_slug should be one of the following For Dashboard: add_submenu_page( ‘index.php’, … ); Also see add_dashboard_page() For Posts: add_submenu_page( ‘edit.php’, … ); Also see Also see add_posts_page() For Media: add_submenu_page( ‘upload.php’, … ); Also see add_media_page() For Links: add_submenu_page( ‘link-manager.php’, … ); … Read more

How to display an admin notice after updating plugin settings?

After digging in the setting API I found the answer. Method 1 was correct, but the notification should not be done by hooking to admin_notices, rather by the function add_settings_error add_action (‘pre_update_option_my_var’, function( $new_value, $old_value) { //Do my validation $valid = ( ‘correct_value’ == $new_value ); if ( !$valid ) { //This fixes the issue … Read more

WordPress Admin back-end – advanced options page?

// Adds ‘ALL’ options page – only accessible for admins and custom roles that have the ‘manage_options’ capability. function wpse31956_all_settings_page() { add_options_page( __(‘All’), __(‘All’), ‘manage_options’, ‘options.php’ ); } add_action( ‘admin_menu’, ‘wpse31956_all_settings_page’ ); Note: As I just saw that me an @ChipBennet posted at nearly the same time: The answer is the same.

bloginfo() vs get_option?

The two functions output exactly the same thing. From the Codex entry for get_bloginfo(): ‘name’ – Returns the “Site Title” set in Settings > General. This data is retrieved from the “blogname” record in the wp_options table. From source: case ‘name’: default: $output = get_option(‘blogname’); Neither get_bloginfo() nor bloginfo() do any sort of sanitization or … Read more

get_option() filtering and getting out of recursion

Usually I remove the filter, then add it back on afterwards; function _my_custom_option( $option ) { remove_filter( ‘pre_option_name’, ‘_my_custom_option’ ); // do what you like with $option add_filter( ‘pre_option_name’, ‘_my_custom_option’ ); return $option; } add_filter( ‘pre_option_name’, ‘_my_custom_option’ );