So what is WPlize and what is it for?
WPlize is a class, which access the options
table of WordPress and makes it easier to create, edit, get and delete preferences of a Plugin or theme in the options
table of WordPress. Using this class improves the performances and create a clean code in Plugins and themes. Only one entry will be created for each Plugin or theme, an array creates and manages the entries.
Many Plugins creating quite a lot data, for example the popular contact Plugin cforms creates 60 entries, which worsen the performance.
But that’s not necessary, WordPress supports the use of arrays. Also single entries having a better performance by using an internal caching, even though it’s not as good as using an array for many entries instead many entries in the database.
I use this solution for quite a long time already and created for this new functions in my Plugins. I didn’t implement this in older Plugins yet, but if I have time I will make the changes in older Plugins too.
In collaboration with Sergej Müller (known for his Plugin wpSEO), after I recommend this variant, Sergej created an own class, which makes it even easier with less code to integrate.
First we thought to create a Plugin, which has access to other Plugins. But since we didn’t think it is worth it because of lack of popularity, we just thought to offer the class here.
This class enables a simplyfied and better performed access for Plugin and theme authors. Functions like add_option
, delete_option
, get_option
and update_option
are also getting used in the functions of this class.
Which possibilities has the class to offer and how can you implement them?
Save the file in a sub folder of your theme or Plugin and integrate via PHP.
if ( !class_exists('WPlize') ) {
require_once('inc/WPlize.php');
}
The following Syntax explains more in detail.
The download file includes also a readme-file with some examples.
- Initializing Multi-Option
$WPlize = new WPlize( 'my_plugin', array( 'my_key' => 'my_value', 'your_key' => 'your_value' ) );
- Updating option [Variant 1]
$WPlize->update_option('my_key', 'simple_value');
- Updating option [Variant 2]
$WPlize->update_option( array( 'my_key' => 'my_value', 'your_key' => 'simple_value' ) );
- Get option
$WPlize->get_option('your_key');
- Delete Multi-Option
$WPlize->delete_option();
Download:
Please read the updatenotice an the download-site.
Download as zip-file, incl. readme: class_WPlize.zip – 3 kByte
Comments
8 responses to “WPlize – A Class For Options In WordPress”
Is there any way to delete only one option?
Yes, this is possible. I think, for only delete one option it is the simple way
delete_option('option_name');
Interesting. Very interesting. Kinda like an OOP spin on my theme options page tutorial…
I’ve been struggling with options for a few days now. Finally have them working. Now I found this post and I thank you, although a bit late to save me all that time. I’ll be testing this class when I have a chance to include it into my present plugin project. Thanx for all your articles and good luck with the wpwebhost competition.
Thanks for the wishes Twincascos, the decision if we made it under the best 20 Blogs talking about WordPress is coming closer. Will be interesting if we make it 🙂
Thank you Doug for your link to your tutorial, hope you find more coming posts interesting too. 😉
I’m trying to implement this in my own plugin, but I’m at a loss as to how to use it on a settings page, without bypassing the built in update/save function. Is that what you’re recommending we do?
@Malcalevak, you can intercept every save, for example via $-POST and then start the save/update function of the class.
I take it you mean overriding the built in save feature with your own?