WordPress Theme Options insert in custom database table with $wpdb-insert - mysql

I've been working out with this quite a long time and I can't find a way how to make it work.
I'm creating a simple theme option with my theme but putting all the options to a custom database table.
I want to know how $wpdb->insert() inserts all options like add_option().
This is my code - http://pastebin.com/5xHBs6r2
If you look at line 209 *function stheme_initialize_theme_options()* you'll see what I mean. I also created a function (*function stheme_default_options()*) that holds the default options and return it with apply_filters().
I hope someone can help me with this as I'm really struggling with it for a week now.
Thank you!
Best regards.

Consider using the Options API. It's a lot simpler than writing your own queries, and it's built in already.
http://codex.wordpress.org/Options_API
Setting, resetting and retrieving options you store can be done with 3 or 4 commands altogether, so it's a pretty nifty system. For instance, this:
add_option('my_option', 'foo');
Will instantiate an option in the DB, this will update it:
update_option('my_option', 'foo2');
and finally, this will retrieve it:
$s = get_option('my_option');
If you do use the Options APi, it's a good idea to stick to a naming convention, have your own prefix for your options. Too easy to cross over to other plugins etc if you use anything too obvious.

This is a classic XY Problem.
Don't create a table to do something that WordPress already does. You're even putting yourself into a trap, as you won't be able to query your data with WP default tools and will have to re-invent the wheel to achieve it.
What you're looking for is register_activation_hook, register_deactivation_hook and register_uninstall_hook.
Aside the uninstall hook, we can use the file uninstall.php with our plugins to clean up our stuff after the plugin is deleted. See this related posts at WordPress Answers.
PS: in your code, this is totally uncalled for:
add_action( 'init', 'st_register_table', 1 );
You address custom tables simply with $wpdb->prefix.'your_table'.

Related

Magento theme mysteriously stops loading upon disabling (and then renabling) store view

I've been banging my head over the last day or so over a VERY WIERD issue I'm encountering with my Magento 1.9 site. All was working fine until I decided to add another language to the store (while disabling one of the languages already present). What I did was follow the same process I used to set up the language i.e. go to store view, and simply "disable" the language I did not want in the language selector drop down.
However, immediately after I did this, the theme I'm using stopped loading correctly. And no matter what I do (renable etc), it simply won't load any more. This is ALL I did BTW - I did NOT modify any other settings, code etc. . .
Is there something I'm missing here? Any input would be greatly appreciated!!
Did you tried to clean the cache? Any external cache?
Please check the other scopes. Perhaps you changed it.

With open source software like OpenCart, how much can I alter the core code?

I'm new to working with open source projects and I'm currently looking into OpenCart specifically. Sorry if this question is a bit dumb but how much can I change the code to customize my needs?
Lets say I want to make the telephone field not required. Can I simply remove the if statement in the controller?
Or if I would like to add a new field house_nr to the checkout; can I just create the database field and alter the code to make it work?
The reason I ask: Wont that break the code again when I update to a new version? What is best practice here? Should I keep a document of every file I altered so I can do it again in a big update?
Modifying the core will 100% break when upgrading, but you are free to do so. As always backup often, cos a reinstall will destroy anything else you did.
Use vqmod and custom templates instead. TRicky to work out at first, but you will be very thankfull down the line. Google them to resarch both.

namespace conflict in C

I have defined list_t in my project that got list module API like list_pop(). But now I have to use MySQL lib to communicate with DB, but the MySQL lib still got its list implements, and also defined a list_pop() API. In my other modules, I have to link both of them, and comes the conflict.
One of my solution is, separately include header file for different list API calling, this works well, but while some function need to call both of MySQL::list_pop() and local::list_pop(), how to notify the compiler the correct link point? Is there some GCC trick that can do these without any changes to local::list_pop()?
For most practical purposes, you are going to have to rename one or the other set of functions. It is probably easier to rename your own than those of MySQL.
The simplest approach is to simply add a prefix that has a higher probability of being unique (enough), such as your initials, or the codename of your project, or something. Or you can rename everything to avoid collisions, being aware that MySQL might add a new function in the future.
This is exactly why namespaces were invented for C++, and why C projects usually have systematic prefixes on sets of functions.
There is a way to solve this. Refactor your list_pop() to, say, my_list_pop().
There is one other way to solve this,
Looking at the header of the MySQL my_list.h here, https://github.com/lgsonic/mysql-trigger/blob/master/mysql/my_list.h you can see that list_pop is just a macro, and its binded at compile time, not at runtime(hence not a real library function). Changing list_pop of MySQL to list_pop_my(just in the #define) can make it do what you want it to do.

Is it possible to user-wide replace default gtk2 widgets with compatible custom ones derived from the original

(This is an in-theory question, to scratch a personal itch, so I am not interested in "IMHO thats-not-advisable" answers, because this is just something to fix some little things, not to be installed on your machine etc... ;-)
I have made a couple of custom Gtk widgets that extend the base widgets such as GtkFileChooser and GtkNotebook.
(not much, but its something, as of yesterday I knew nothing about gtk or c, so this is more of an in-theory question - however if its not possible there is not much point in me learning any more gtk2)
However I would like to use these widgets in all my gtk2 apps.
Is it possible to over ride the default widgets system-wise without rebuilding the gtk2 libs from source?
It looks like gtk-modules would be the way to go, but the documentation seems sparse, unless my googling is missing something.
The purpose of this, is that the GtkNotebook does not support multiple rows of tabs, however it is used in Geany, Anjuta, Bluefish and numerous other gtk2 based editors. I can recompile geany and Anjuta, and bluefish to use my widget instead, but I'd prefer to swap it out across the board.
Normally the right solution to reusing widgets between different applications is to create a dynamic library that adds the widgets.
Remember that it's advisable to create real GObject subclasses with a separate GType. Then it's also trivial to add support for say introspection so your widgets can also be used in language bindings etc.

Is "include file" in shtml the best method to keep non-database changing data

We have a website that uses #include file command to roll info into some web pages. The authors can access the text files to update things like the occasional class or contact information for the department.
My question is this, I don't see anyone using this method and wonder if it is a good idea to keep using it. If not, what method should I transition to instead?
I don't think there is anything wrong with it, and I've done some similar things with PHP. If the people that make the changes are comfortable with how they do it and they can do what they need to, I think you should stick with it. There could be some retraining involved and/or a fair amount of work involved for changing the system.
If you are using ASP.NET then you could bundle that code into a nice little UserControl that will display all of the important information.
Other platforms should allow you to bundle the logic into a class object, and display it using that.
It really depends on the platform that you are using to deploy the application in. The include file could be your best solution if you are deploying in a more limited platform.