Wordpress wp_options option question? - wordpress

Hello
Can anyone explain me what this mean :
a:2:{s:8:"scSlider";s:8:"featured";s:8:"npSlider";s:1:"4";}
How should I read these values?Tnx

Those are serialized options. When you use add_option() or update_option() with an array or object instead of a scalar value, WordPress serializes the data with serialize() before it puts it in the database. It's incredibly handy when you don't want to have to create a lot of different options in the database to save some values. This way you just put them all into an array and just save the array.
When you retrieve the data with get_option() WordPress will automatically unserialize the data into an array or object as well.

That looks familiar: it looks like a plugin option. As Pekka suggests, they use serialised arrays to pack multiple variables into a single database entry. (Use unserialize.)
I'm guessing you found it whilst doing something like:
SELECT *
FROM `wp_options`
WHERE 1
LIMIT 0 , 30
Unfortunately, without some idea of which plugin you have installed (I'm guessing it's a slider widget of some sort) it's unlikely that anyone will be able to tell you what the values mean.
Could I also suggest making use of the excellent Wordpress Stackexchange site?

Related

Serialized data in Wordpress form is "serialized" again when saved in mysql

I have a challenge with the way data is stored from Wordpress into mysql.
I'm new to Wordpress - but I'm trying to combine different plugins to achieve a specific functionality on a website.
Plugin #1 uses a specific type of post and some metadata - the plugin works great.
Plugin #2 can create posts of custom types and with custom metadata from the frontend. A flexible and great plugin.
My intention is to use plugin #2 to create posts from the frontend for plugin #1, which requires that some specific metadata contains specific values (otherwise the data are interpretted wrong). These values are saved with hidden inputfields in a form.
My challenge is that a value (which is serialized) is kind of serialized again. The value is a:1:{i:0;s:3:"198";}
Plugin #2 handles it well (as the data is shown correct in front- and backend of the plugin) - BUT in myPhpAdmin I can see that the data is saved differently s:20:"a:1:{i:0;s:3:"198";}"; - and hence that value cannot be understood by plugin #1.
I'm thinking of two options:
change something so s:xx: isn't added to the value(-s)
make the frontend form/plugin save the data in a serialized way so the value gets the correct format.
Any recommendations? - can I in anyway achieve my functionality?
Looks like
s:20:"a:1:{i:0;s:3:"198";}";
value is being serialized twice. You can check the plugin source code to see why the plugin serializing same value twice and if can prevent it than both plugin can share same data.

form in wordpress that writes to many tables (with different columns)

Currently, I'm using tablepress to output different info using a table format. I want users to be able to add to existing information. I need a form in wordpress that saves user posts to these different tables. How should I go about this? Sorry if I sound stupid but I'm soft on html.
Thanks.
If you want to insert in posts table using custom form, you can use wp_insert_post().
This function inserts posts (and pages) in the database. It sanitizes variables, does some checks, fills in missing variables like date/time, etc. It takes an object as its argument and returns the post ID of the created post (or 0 if there is an error).
Reference : http://codex.wordpress.org/Function_Reference/wp_insert_post

Wordpress deleted file info "UPDATE wp_options SET option_value"

I am working on a forensics course, with which I have been looking into an attack on a blog server. I have found a number of deleted Wordpress files, and I have managed to figure out which ones contained blog posts.
The one file I cannot figure out contains information beginning with the following:
wordpress#UPDATE wp_options SET option_value = 'O:9:\"MagpieRSS\":19:{s:6:\"parser\";i:0;s:12:\"current_item\";a:0:{}s:5:\"items\";a:10:{i:0;a:9:{s:5:\"title\";s:37:\"India Vs Pakistan: Now Cyber Terror? \";s:6:\"author\";s:8:\"chinchak\";s:4:\"link\";s:59:\"http://feeds09.technorati.com/~r/trarticles/~3/sxlCqi2M9aE/\";s:4:\"guid\";s:74:\"http://technorati.com/politics/article/india-vs-pakistan-now-cyber-terror/\";s:11:\"description\";s:182:\"The India-Pakistan relations could very well be termed the greatest mystery ever of mankind.\";s:7:\"pubdate\";s:31:\"Tue, 21 Aug 2012 00:03:41 +0000\";s:8:\"category\";s:51:\"PoliticsAssam ViolenceCyber TerrorIndia Vs Pakistan\";s:10:\"feedburner\";a:1:{s:8:\"origlink\";s:74:\"http://technorati.com/politics/article/india-vs-pakistan-now-cyber-terror/\";}
It continues in this way for a while, but I haven't had too much luck trying to use Google to tell me what the "wp_options" means. It looks like someone was trying to spam the blog with commments but I can't be sure without a source which can confirm my view is correct. Can anybody help please?
The wp_option table stores key-value information in the columns option_name and option_value. When storing arrays they get serialized, to decode them you can use PHP's unserialize function. It looks like you're dealing with an SQL injection that tries to mess with Wordpress' user options. The purpose is not obvious, because they are rarely displayed. Just used internally. If there's a where clause somewhere in that SQL statement that tells you which option name it's trying to edit you could perhaps match it using this list:
http://codex.wordpress.org/Option_Reference

Wordpress Custom Table Query using Multiple Values

I have been researching the last hour of whether or not I can run a query within wordpress on a custom table that I made using two WHERES. Now I'm new to mysql and php ( 9 months in ) and am just wondering if there is a way to do it besides a AND.
Here is an example of my code
$check_current = $wpdb->get_row("SELECT * FROM $weather_table WHERE status = 'current' AND condition = $current_weather");
status and condition are both fields and I'm trying to find out whether both exist to rewrite the current field. The closest I've come is possibly using the prepare function in Wordpress and php but don't know what that is exactly just know it helps with sql injection and security. Can you run a multiple value query in Wordpress?
Using the AND operator in MySQL is the right way to test for a compound condition.
Be sure to put quotes around any variables (like $current_weather) if the underlying data type is a string.
Also, best practice is to avoid using "*" in the select. Rather, explicitly declare the fields you want to return. This is good for performance.

How can wordpress themes save and retrieve settings?

I'm programming a wordpress theme and need to make it save data, how should I have it do this? Is there a wordpress function or would I have to connect to the database on my own?
Are you just trying to store simple name -> value pairs?
You could check for $_POST data in your theme then use update_option($name,$value) to save the data.
update_option will create the row in the DB if it doesn't exist. And get_option($name) will retrieve it.
Or are you trying to store something more complex?
It depends on what kind of data you're trying to save, how you want it saved, and what you want to do with it later. Can you be more specific?

Resources