Tag Info

Hot answers tagged

23

They now are Starting with WordPress 3.7 expired transients are deleted on database upgrades, see #20316 Old answer If someone can't show me otherwise it seems that transients are not garbage collected after all. What makes it worse is that unlike options they are not guaranteed to be stored in database. So there is no reliable way to fetch list of all ...


21

OK so found some more: JeffreyWay / WordPress-Theme-Options-Page - open source class the project is hosted on github aimed at theme developers, looks nice, haven't used it. . devinsays / Options-Framework - open source Framework the project is hosted on github aimed at theme developers , i later learned that is has evolved in to Thematic-options very ...


18

Moving some of the comments from the discussion into an answer, with re-wording and re-formatting.. Basically, what it comes down to is that unless you have a super extreme case, they don't really need to be "garbage collected". If you never fetch them, then it doesn't matter if they're there or not. See, transients are stored in the options table by ...


16

Use wp_register_style and wp_enqueue_style to add the stylesheet. DO NOT simply add a stylesheet link to wp_head. Queuing styles allows other plugins or themes to modify the stylesheet if necessary. Your stylesheet can be a .php file: wp_register_style('myStyleSheet', 'my-stylesheet.php'); wp_enqueue_style( 'myStyleSheet'); my-stylesheet.php would look ...


15

Yes, sort of. When the get_option call is made, WordPress runs a function called wp_load_alloptions, which either grabs a cached copy of all autoloaded options or loads all those options into the cache. Then wp_load_alloptions returns an array of all the autoloaded options. If your option is autoloaded (specified when you use the add_option function), it ...


13

Otto - I couldn't disagree with you more. The issue is that eventually with all those transients, the size of the table becomes ridiculous. It doesn't take millions of rows to bog down. I'm currently dealing with an options table that has over 130k rows, and hangs regularly. Because the value field is a large text type, even looking for only the "autoload" ...


10

WordPress Tabs are non-standard, static html markup. You can only add the markup within your functions.php theme file or inside your plugin. <h2 class="nav-tab-wrapper"> <a href="#" class="nav-tab">Tab #1</a> <a href="#" class="nav-tab nav-tab-active">Tab #2</a> <a href="#" class="nav-tab">Tab #2</a> ...


9

serialize representation can be stored in text and reversed JSON representation can be stored in text but cannot always be precisely reversed Run this example: $query = new WP_Query(); var_dump( $query ); var_dump( unserialize( serialize( $query ) ) ); var_dump( json_decode( json_encode( $query ) ) ); After going through serialize accurate WP_Query ...


8

You don't get an error because WordPress does not check for the length, and MySQL silently truncates it (giving a warning, not an error), unless you enable the STRICT_ALL_TABLES option (which will change the warning into an error). Even more confusing, when you enable multisite the options are saved in the sitemeta table with a maximum key length of 255, ...


8

scbFramework has related classes, I used it for one plugin and it saved me plenty of time; WPAlchemy MetaBox I see a lot of mentions for this around, hadn't used it myself yet; Hybrid Core has set of functions for pages/metaboxes/settings, but it probably won't make sense to use it just for that.


8

Dynamically building a CSS file and then loading it adds a HUGE performance burden to what should be a very low bandwidth deal of adding a CSS file, especially if there are variables in the CSS that are going to be processed through WP. Because it is two different files being created for one page load, WP starts up twice and runs all the DB queries twice, ...


8

checkbox: <input name="option_name" type="checkbox" value="1" <?php checked( '1', get_option( 'option_name' ) ); ?> /> radio: <input name="option_name" type="radio" value="0" <?php checked( '0', get_option( 'option_name' ) ); ?> /> <input name="option_name" type="radio" value="1" <?php checked( '1', get_option( 'option_name' ...


7

@JonathonByrd's answer is probably 'best' - certainly you should using get_option if at all possible, since there's no guarantee the option name will stay the same between WordPress versions. Similarly - @JonathonByrd also relies on using a global variable which may be removed/renamed (though perhaps very unlikely). Unfortunately there are no public ...


7

Joining two answers(*), I've done a plugin to add a custom meta option when registering a new site (front and back end) and display its value in a column in the Sites screen. Multisite Categories ... (*) code references 1 - WordPress + Multisite: How to add custom blog options to Add New Site form in Network Admin?, by @dennisg 2 - Multisite: How to ...


6

That's because your options are stored as a serialised array, in one row with name XX_theme_settings. To update one option, you would still need to retrieve the existing settings, ammend the appropriate value and update all options in your array together. For example: $my_options= get_option('XX_theme_settings');//retrieve all options ...


6

The Options API is primarily a database API, allowing you to get and store values in the options table of the database easily. The Settings API is an interface API. It allows you to build settings screens in a manner that will adapt with future changes to the WordPress interface, as well as to handle security (nonces and whitelisting and validation and ...


6

The Multisite signup process is not an easy thing to tweak. It does have many hooks to play with, unlike other processes, but they don't seem to come together too well for heavy customization, so I understand your frustration. If I understand correctly, it's not that complicated to achieve what you want, although it cannot be a one-step solution without ...


6

You should (if available) submit the code you are working with, even if just a snippet, so we can assess your process in relation to your question. The short answer however is YES, it is safe, so long as you, prevent input fields being displayed on user profile page for certain user roles prevent unauthorized users from saving user meta to the database ...


6

WordPress, by default, does a form of "Object Caching" but its lifetime is only a single page load. Options are actually a really good example of this. Check out this answer for more info. The summary: A page starts All options are loaded with a simple SELECT option_name, option_value from $wpdb->options statement Subsequent requests for those options ...


6

I tend to store multiple options as an array, so i'd have something like this.. <?php $options = get_option( 'myoption' ); ?> <input type="checkbox" name="myoption[option_one]" value="1"<?php checked( 1 == $options['option_one'] ); ?> /> <input type="checkbox" name="myoption[option_two]" value="1"<?php checked( 1 == ...


6

Basically to distinguish between false boolean value and '' empty string you must use more strict comparison operator. var_dump( '' == false ); // this is 'true', treated like two 'empty()' values var_dump( '' === false ); // this is 'false', because values are both 'empty()' BUT of different type But there is more. Since what you want is very typical - ...


6

When the installer runs it calls wp_install(), that in turn calls populate_options() defined in wp-admin/includes/schema.php, which runs the following.. if ( !__get_option('home') ) update_option('home', $guessurl); Prior to that $guessurl is defined by.. $guessurl = wp_guess_url(); The guess URL function is defined in wp-includes/functions.php and ...


6

If you wrote your code correctly, then delete_option would be the correct way. The question isn't how to clear the option; the question is how to structure your code such that the "option does not exist" case is a valid case. Think about it. The first time you start this code, that option isn't going to exist at all, right? Your code should be perfectly ...


5

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 . ...


5

The problem is they are getting saved... it's just you're always saving the defaults! $ev_options = ev_theme_settings_defaults(); if ( false === $ev_options ) { $ev_options = ev_theme_settings_defaults(); } update_option( 'theme_evolutionary_options', $ev_options ); And that's running on every page load (it's hooked to the action after_theme_setup). ...


5

There's a wpmu_options action that lets you append more HTML on the Network Settings page. If you want to add your own sub-menu/page to the Settings parent menu: add_action('network_admin_menu', 'add_my_netw_settings_page'); function add_my_netw_settings_page() { add_submenu_page( 'settings.php', 'Co za asy', 'Co za asy', ...


5

You should do defaults at the time of pulling the data out. Never insert default values into the database. Defaults are default. Options in the DB override defaults. How to do defaults for a serialized options array: $defaults = array( 'default1' => '1', 'default2' => '2', ); $options = wp_parse_args(get_option('plugin_options'), $defaults);


5

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 ...


4

Assuming this array for example usage: $options = array( "name" => __('Font','mytheme'), "desc" => __('Change the font face)','mytheme'), "id" => "mytheme_font", "std" => array('size' => '10px', 'face' => 'Arial', 'color' => '#000000'), "type" => "text", ); For question 1, to reference nested arrays, just ...


4

The reason is that if you are on page 1, the data that is posted to be saved is an array of the form: XX_theme_settings=array('XX_Option1' =>'input1','XX_Option2'=>'input2',...) and contains no data from page 2. This is because the input from page 2 is not posted with it (since it wasn't in the same <form> - it's not on the page). Thus when ...



Only top voted, non community-wiki answers of a minimum length are eligible