How to use value from form data to add option to WP database
-
How do I save the value of some form input into an option in WordPress?
I developed a simple plugin that embeds a URL into any WordPress site. I have also created a plugin settings page following the model provided at Otto’s tutorial. I have only one setting that user’s can edit – the URL of the website they’d like to embed. It seems simple enough, but I cannot find where in Otto’s tutorial an option is created. There is no call to add_option. So I’m not clear how to make my function work to retrieve the URL the admin has typed in from my plugin settings page:
function get_url_to_embed() { $options = get_option('plugin_options'); if ($options == FALSE) { return "https://www.google.com/"; } return $options['text_string']; // What goes inside the brackets?? }
If you didn’t already understand, the default embedded URL is Google. If the admin has typed in a URL on the plugin settings page, I’d like THAT website to be embedded. How do I do this?
- The topic ‘How to use value from form data to add option to WP database’ is closed to new replies.