• I have the following code, but I need to add a line of code from the WP admin to this, but can’t figure out how to do that.

    I started off with this:

    <?php
    $app_id = "echo get_option('appid');";
    ?>

    Then I tried to add the line of code from admin using:

    $app_id = "echo get_option('appid');";

    A bit too literal maybe, so I removed the semi-colon within the quotes:

    $app_id = "echo get_option('appid')";

    I’m running out of hair to pull out, so if anybody can help, that would be great.

    Thanks.

Viewing 15 replies - 1 through 15 (of 23 total)
  • Try:

    <?php
    $app_id = get_option('appid');
    echo $app_id;
    ?>
    Thread Starter HorrorUK

    (@horroruk)

    Thanks, I’ll give that a go ??

    Thread Starter HorrorUK

    (@horroruk)

    I wrote that slightly wrong in the first box.

    It should be reading something like (it’s Facebook):

    <?php
    $app_id = "76543768778578";
    ?>

    I tried:

    <?php
    $app_id = get_option('appid');
    echo $app_id;
    ?>

    But it still doesn’t seem to be accepting it.

    Did you store that app_id as an option first?

    Thread Starter HorrorUK

    (@horroruk)

    Bit of a blonde moment going on today, sorry.

    How do you store the app_id option?

    Thread Starter HorrorUK

    (@horroruk)

    I’m starting to think I’ve totally messed up here. Looking at the page, I’ve not actually called in any page that holds the info or the db.

    I’m wondering if I need to add a line calling the database into the page?

    Thread Starter HorrorUK

    (@horroruk)

    I don’t know if this will help make sense of it:

    https://pastebin.com/qQe8kfVY

    This is the page I have, and it is the second block of PHP I’m trying to work on to bring in the two bits of info I added to admin.

    Please note, I changed the two bits of info names, to make it simpler.
    They are now:

    tabsappid
    tabsappsecret

    This is the error I receive:

    Parse error: syntax error, unexpected T_STRING in /var/www/vhosts/writers-site.com/httpdocs/wp-content/plugins/facebook-tabs-for-wordpress/fbindex.php on line 7

    Why not just use:

    $facebook = new Facebook(array(
            'appId' => '76543768778578',
            'secret' => $app_secret,
            'cookie' => true
    ));
    Thread Starter HorrorUK

    (@horroruk)

    I was thinking about something like that, so I tried:

    <?php
    $app_id = get_option('tabsappid');
    echo $app_id;
    $app_id = get_option('tabsappsecret');
    echo $app_id;
    
    $facebook = new Facebook(array(
            'appId' => $app_id,
            'secret' => $app_secret,
            'cookie' => true
    ));
    ?>

    However, that causes the following error:

    Fatal error: Call to undefined function get_option() in /var/www/vhosts/writers-site.com/httpdocs/wp-content/plugins/facebook-tabs-for-wordpress/fbindex.php on line 6

    It looks like it doesn’t realise it’s part of WordPress.

    It makes it worse feeling so close to the answer.

    Why are you trying to use get_option() when this hasn’t been stored in the database as an option?

    Thread Starter HorrorUK

    (@horroruk)

    In my WordPress admin I’ve set up a page to take two values which are stored as tabsappid and tabsappsecret, and then I’m trying to get those values to to show in the correct sections on this page.

    Have you confirmed that these values are being stored in the database correctly?

    Thread Starter HorrorUK

    (@horroruk)

    Hi Esmi, thanks for sticking with me on this one.

    I just checked the database, and it is storing the values ok.

    Thread Starter HorrorUK

    (@horroruk)

    I think I must be missing calling wordpress in somehow, because of the part of the error message that says:

    Fatal error: Call to undefined function get_option()

    In my WordPress admin I’ve set up a page to take two values which are stored as tabsappid and tabsappsecret

    Is this a theme options page? If so, have you seen https://www.chipbennett.net/2011/02/17/incorporating-the-settings-api-in-wordpress-themes/ Or https://ottodestruct.com/blog/2009/wordpress-settings-api-tutorial/

    Can you see these options in clear text when you view https://your_domain/wp-admin/options.php? Or are they serialized arrays?

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘adding echo get_option correctly’ is closed to new replies.