I have been asked to create a dial on a wordpress website. The customer wants to be able to update the value of the gauge.
I have two options – I can either create something that sits alongside wordpress where they can update the value, or I can have it as part of wordpress, but I am not sure how to do that or how easy it would be.
Basically I just need a screen where an authenticated user can update a value. I then need to be able to read that value from one of the theme files (specifically the static front page theme file) and display it.
I am comfortable with PHP, but not familiar with wordpress – is there any easy way to do this, or will it make more sense to just do it separately?
It should be pretty easy actually – WordPress provides the core of what you need to interact with the database.
Here’s some sample code of a theme I built a few years back. There’s more to it than this, obviously you have to create the table at some point. But once that is in place, the global $wpdb is your gateway.
Alternatively for just a one field, you could use the “options”. e.g.
update_option()
is/was in /wp-includes/function.php (I presume it’s still there… it’s been a while) and you would need to call anadd_option
before hand –get_option()
will return the current value.I’ve faced some similar scenarios before, and what I’ve found to best in terms of UX for the admin it’s to use a “Dashboard widget” where they can update the values. You can check the documentation on http://codex.wordpress.org/Dashboard_Widgets_API
Then, you can use the Options API to update and retrieve the given value.
The article in the Codex is outdated, Creating Options Page, but has two links to articles written by two great developers:
Handling plugins options in WordPress 2.8 with register setting, by Ozh
WordPress Settings API Tutorial, by Otto
Note that you are not limited only to “Options Page”, there are many more. Then, it’s a matter of retriving the values in the frontend with the Options API.
You could also use the Advanced Custom Fields Plugin Drop-In “Options Page”.
It provides you with the ability to edit the options Pages without needing to code.
Plus, after finishing developement, you can still export all the fields to php.
Plugin Link
This is the best answer to this problem. To create a form that is accessible on Admin. A link with functional code here:
The variables can be accessed as a WordPress Setting.