• I am using wp version 3.0.3. I have a question about creating plugin.

    I followed wordpress instructon (https://codex.www.ads-software.com/Creating_Options_Pages#See_It_All_Together_2) and got it to working so that the options are saved into the database.

    Now my other file in plugin folder is options.php

    <?php
    require_once ($_SERVER["DOCUMENT_ROOT"] . '/file2.php');
    
    // *** Add your API Key, Secret Key here ***
    $appapikey = '[<?php echo get_option('option_etc'); ?>]';
    $appsecret = '[000000000000000000000000000000]';
    $facebook = new Facebook($appapikey, $appsecret);
    // $user_id = $facebook->require_login();
    
    echo '<div id="iframeLinkDiv"><a clicktohide="iframeLinkDiv" onClick="outside_location.setInnerFBML(link_1);" style="cursor: pointer;"><img src="<?php echo get_option('new_option_name'); ?>" border="0" alt="" /></a></div>';
    echo '<div id="outside_location"></div>';
    echo '<fb:js-string var="link_1">';
    echo '<iframe height="500px" allowTransparency="true" frameborder="0" scrolling="yes" style="width:520px; src="<?php echo get_option('some_other_option'); ?>">';
    echo '</iframe>';
    echo '</fb:js-string>';
    echo '<script type="text/javascript" charset="utf-8">
    var outside_location = document.getElementById("outside_location");
    </script>';
    
    ?>

    What am i doing wrong? Why can’t i get the inserted data directly inside the other php file?

    It says:
    Parse error: syntax error, unexpected T_STRING in /home/…/plugins/pluginname/options.php on line 5

    Am i even in the right direction? I am running a multisite with subdomains and i can activate this plugin in network mode, but i want that the users can edit this file and the database will remember every users inserted data.

    Thanks for reading ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • I looked at the linked post, and it looks nothing like what you posted.

    Did you get the code from a Facebook php example for a sample Facebook app? It doesn’t make a whole lot of sense. Normally, for FBML iframes, Facebook provides examples using FBML which looks like a normal HTML page. They then grab the HTML/FBML page and parse the FBML for display on their server. You’re nesting WP php functions inside of FBML & FB php code. You’re not closing open PHP tags before you open another one.

    I don’t see any functions that define your WordPress plug-in’s options, nor do I see any hooks into WordPress. There’s no way it can understand “get_option” if you don’t init WP with valid WP code first. There’s no way WP can know your WP options & variables if you haven’t defined them or registered them with WP first. Not sure how you saved any data into WP’s database with the posted script. It appears to be an iframe that’s located on facebook’s server. Are you trying to frame a page within Facebook? I’m sorry but I don’t even understand what you’re trying to do. If you’re trying to frame your blog to appear on FB’s site, then you probably don’t need a WP plugin for that.

    Thread Starter ak47marx

    (@ak47marx)

    Hi Mandy,
    thank you for your answer.
    After reading my text again i can see how it can be confusing.

    Lets say that i have a plugin folder named “fbplugin”

    – Inside the fbplugin folder, there is a “inst.php” and “index.php”

    “inst.php” is the plugin installation file for admin with the following code:

    <?php
    require_once ($_SERVER["DOCUMENT_ROOT"] . '/wp-content/plugins/fbplugin/filename.php');
    
    /*
    Plugin Name: Name
    Plugin URI: https://www.company.com
    Description: Description
    Author: Author
    Author URI: https://www.company.com
    */
    // create custom plugin settings menu
    add_action('admin_menu', 'baw_create_menu');
    
    function baw_create_menu() {
    
    	//create new top-level menu
    	add_menu_page('Menu Title', 'Test', 'administrator', __FILE__, 'baw_settings_page',plugins_url('/images/fileimage.png', __FILE__));
    
    	//call register settings function
    	add_action( 'admin_init', 'register_mysettings' );
    }
    
    function register_mysettings() {
    	//register our settings
    	register_setting( 'baw-settings-group', '01selection' );
    	register_setting( 'baw-settings-group', '02selection' );
    	register_setting( 'baw-settings-group', '03selection' );
    	register_setting( 'baw-settings-group', '04selection' );
    	register_setting( 'baw-settings-group', '05selection' );
    	register_setting( 'baw-settings-group', '06selection' );
    }
    
    function baw_settings_page() {
    
    if ($_GET['updated']==true) { ?>
        <div id="message" class="updated">
            <p>
            Updated.
            </p>
        </div>
    
    <?php
    // *** Add your API Key, Secret Key here ***
    $appapikey = '[HERE I WANT DATA FROM 01SELECTION]';
    $appsecret = '[HERE I WANT DATA FROM 02SELECTION]';
    $facebook = new Facebook($appapikey, $appsecret);
    // $user_id = $facebook->require_login();
    ?>
    
    <?php } ?>
    
    <div class="wrap">
    <h2>Integrate with your facebook page</h2>
    
    <form method="post" action="options.php">
        <?php settings_fields( 'baw-settings-group' ); ?>
        <table class="form-table">
            <tr valign="top">
            <th scope="row">01 selection</th>
            <td><input type="text" name="01selection" size="40" value="<?php echo get_option('01selection'); ?>" /></td>
            </tr>
    
            <tr valign="top">
            <th scope="row">02 selection</th>
            <td><input type="text" name="02selection" size="40" value="<?php echo get_option('02selection'); ?>" /></td>
            </tr>
    
            <tr valign="top">
            <th scope="row">03 selection</th>
            <td><input type="text" name="03selection" size="55" value="<?php echo get_option('03selection'); ?>" /></td>
            </tr>
    
     	<tr valign="top">
            <th scope="row">04 selection</th>
            <td><input type="text" name="04selection" size="8" value="<?php echo get_option('04selection'); ?>" /></td>
            </tr>
    
    	<tr valign="top">
            <th scope="row">05 selection</th>
            <td><input type="text" name="05selection" size="8" value="<?php echo get_option('05selection'); ?>" /></td>
            </tr>
    
    	<tr valign="top">
            <th scope="row">06 selection</th>
            <td><input type="text" name="06selection" size="55" value="<?php echo get_option('06selection'); ?>" /></td>
            </tr>
    
        </table>
    
        <p class="submit">
        <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
        </p>
    
    </form>
    </div>
    
    <div id="iframeLinkDiv"><a clicktohide="iframeLinkDiv" onClick="outside_location.setInnerFBML(link_1);" style="cursor: pointer;"><img src="<?php echo get_option('03selection'); ?>" border="0" alt="" /></a></div>
    <div id="outside_location"></div>
    <fb:js-string var="link_1">
    <iframe src="<?php echo get_option('04selection'); ?>" height="<?php echo get_option('05selection'); ?>px" allowTransparency="true" frameborder="0" scrolling="<?php echo get_option('06selection'); ?>" style="width:520px; >
    </iframe>
    </fb:js-string>
    <script type="text/javascript" charset="utf-8">
    var outside_location = document.getElementById("outside_location");
    </script>
    
    </iframe>
    
    <?php } ?>

    My question for the first (inst.php) file: how do i get the data from the db for “01selection” and “02 selection” ? They are inside [ ] tags.

    – Now for the second file “index.php” in plugins folder

    File contains the code:

    <?php
    require_once ($_SERVER["DOCUMENT_ROOT"] . '/wp-content/plugins/fbplugin/filename.php');
    
    // *** Add your API Key, Secret Key here ***
    $appapikey = '[<?php echo get_option('01selection'); ?>]';
    $appsecret = '[<?php echo get_option('02selection'); ?>]';
    $facebook = new Facebook($appapikey, $appsecret);
    // $user_id = $facebook->require_login();
    
    //
    
    echo '<div id="iframeLinkDiv"><a clicktohide="iframeLinkDiv" onClick="outside_location.setInnerFBML(link_1);" style="cursor: pointer;"><img src="<?php echo get_option('03selection'); ?>" border="0" alt="" /></a></div>';
    echo '<div id="outside_location"></div>';
    echo '<fb:js-string var="link_1">';
    echo '<iframe height="<?php echo get_option('04selection'); ?>px" allowTransparency="true" frameborder="0" scrolling="<?php echo get_option('05selection'); ?>" style="width:520px; border:none" src="<?php echo get_option('06selection'); ?>">';
    echo '</iframe>';
    echo '</fb:js-string>';
    echo '<script type="text/javascript" charset="utf-8">
    var outside_location = document.getElementById("outside_location");
    </script>';
    ?>

    What i would like to do is to get the data from the db and insert it to selections 01 to 06 so that when i type a direct link to /wp-content/plugins/fbplugin/ i can see the index page with results of changes made previously for images and links..

    Really hope you can help ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't get data from db into php file.’ is closed to new replies.