• Resolved lbeckerpointio

    (@lbeckerpointio)


    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m not sure if I understand you correctly, but have a look yourself:

    function get_url_to_embed() {
      $url = get_option("OPTION_NAME");
    	if(empty($url)) {
        $url = "https://www.google.com/";
    	}
    	return $url;
    }

    That makes get_url_to_embed() return either google.com or – if the option has been set – with the set option value. Or did I misunderstand your problem?

    Thread Starter lbeckerpointio

    (@lbeckerpointio)

    Thanks for the response – actually, my issue wasn’t due to my code at all. Google doesn’t allow you to embed their main page – their X-Frame-Options header doesn’t allow it. I thought the page wasn’t embedding because the option value wasn’t set…but that wasn’t the case.

    So the issue has been cleared?

    Thread Starter lbeckerpointio

    (@lbeckerpointio)

    Yeah, I figured this issue out about 20 minutes ago, just as your were replying.

    Good to hear ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to use value from form data to add option to WP database’ is closed to new replies.