Wordpress插件没有提交选项

时间:2016-08-21 13:30:14

标签: php wordpress

我的Wordpress插件应该从选项页面中获取2个参数并将它们添加到网站的标签中 参数由插件在插件设置页面

中安装插件的用户插入

错误描述 -
名为 - " sitefuel_accountId"的第一个参数未提交到数据库, 而第二个参数名为 - " sitefuel_domainName"已成功提交

这是我的php文件 -

    <?PHP
/*
Plugin name: SiteFuel Solutions
Plugin URI: http://www.codefuel.com/products/sitefuel
Description: A beautiful search experience, that engages your visitors, improves conversion and adds monetization to your site
Author: ElramVashdi is Cool Guy
Author URI: http://www.codefuel.com/products/sitefuel
License: GPLv2 or later
Version: 1.0
*/

session_start();

add_action('wp_head', 'add_sitefuel_plugin');
function add_sitefuel_plugin() {
    $accountId  = get_option('sitefuel_accountId');
    $domainName  = get_option('sitefuel_domainName');

    if( $accountId && $domainName ) {
        ?>
        <!-- START SiteFuel -->
        <script src="//sf.mmccint.com/bootstrap?pubid=<?php echo $accountId ?>&url=<?php echo $domainName ?>" data-owner="sitefuel"></script>

        <!-- END SiteFuel -->
    <?php
    }
 }

function sitefuel_plugin_admin_scripts() {
    if ( is_admin() ){
        if ( isset($_GET['page']) && $_GET['page'] == 'sitefuel_settings' ) {
            wp_enqueue_script('jquery');
        }
    }
}
add_action( 'admin_init', 'sitefuel_plugin_admin_scripts' );

function sitefuel_plugin_deactivation() {
    delete_option('sitefuel_siteurl');
    delete_option('sitefuel_accountId');
    delete_option('sitefuel_domainName');    
    delete_option('sitefuel_email');
    delete_option('sitefuel_password');
    delete_option('sitefuel_sphereup_admin_url');
    delete_option('sitefuel_deferred_admin_notices');
}

register_deactivation_hook(__FILE__, 'sitefuel_plugin_deactivation');

function sitefuel_plugin_settings() {

    add_options_page( __( "SiteFuel Plugin settings", BSEARCH_LOCAL_NAME ), __( "SiteFuel Search", BSEARCH_LOCAL_NAME ), 'manage_options', 'sitefuel_settings', 'sitefuel_display_settings');
}
add_action( 'admin_menu', 'sitefuel_plugin_settings' );

function sitefuel_action_links( $links ) {
    $newField = array();
    $newField[] = '<a href="'. get_admin_url(null, 'options-general.php?page=sitefuel_settings') .'">Settings</a>';
    $newField = array_merge($newField, $links);
    return $newField;
}
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'sitefuel_action_links' );

add_action('admin_notices', 'sitefuel_admin_notices');
function sitefuel_admin_notices() {
    if ($notices= get_option('sitefuel_deferred_admin_notices')) {
        echo "<script>
            var $ = jQuery;
            $(document).ready(function() {
                $('#setting-error-settings_updated').hide();
            });

        </script>";
        foreach ($notices as $notice) {
            echo "<div class='error'><p>$notice</p></div>";
        }
        delete_option('sitefuel_deferred_admin_notices');
    }
}

function sitefuel_display_settings() {
    $accountId  = get_option('sitefuel_accountId');
    $domainName  = get_option('sitefuel_domainName');

    $updateAdminLink = false;

    if ( (get_option('sitefuel_accountId') != $accountId || !$accountId) && (get_option('sitefuel_domainName') != $domainName || !$domainName) ) {
        $updateAdminLink = true;
    }

    if($updateAdminLink) {
        update_option('sitefuel_accountId', $accountId);
        update_option('sitefuel_domainName', $domainName);        
        $adminUrl = '';
    }

    $additionalData = 'style="width: 250px;"';
    if($adminUrl) {
        $additionalData .= ' disabled="disabled"';
    }

    $html = '<div class="wrap">

            <form method="post" name="options" action="options.php">

            <h2>SiteFuel Account</h2>' . wp_nonce_field('update-options') . '
            <table width="25%" cellpadding="10" class="form-table">';

    if(!$accountId ) {
        $html .= '<tr>
                    <td align="left" scope="row" style="color: red;" colspan="2">
                        Your plugin is currently not set up.<br/><br/>Please enter the Account Id below and click Save.
                    </td>
                </tr>';
    }

    if(!$domainName ) {
        $html .= '<tr>
                    <td align="left" scope="row" style="color: red;" colspan="2">
                        Your plugin is currently not set up.<br/><br/>Please enter the Domain Name below and click Save.
                    </td>
                </tr>';
    }

    $html .= '<tr>
                    <td align="left">
                        <label>Your AccountID: </label>
                    </td>
                    <td align="left" scope="row">
                        <input name="sitefuel_accountId" value="' . $accountId . '" '.$additionalData.' title="3 characters minimum" />
                    </td>                   
                </tr>
                <tr>
                    <td align="left">
                        <label>Your DomainName: </label>
                    </td>
                    <td align="left" scope="row">
                        <input name="sitefuel_domainName" value="' . $domainName . '" '.$additionalData.' title="3 characters minimum" />
                    </td>                   
                </tr>';

    if( $adminUrl ) {
        $html .= '<tr><td align="left" scope="row" colspan="2">Thanks you for creating a SiteFuel Search account!</td></tr>';
    }
    $html .= '</table>';

    if ( !$adminUrl ) {
        $html .= '<p class="submit">
                <input type="hidden" name="action" value="update" />
                <input type="hidden" name="page_options" value="sitefuel_accountId" />
                <input type="hidden" name="page_options" value="sitefuel_domainName" />                
                <input type="submit" name="Submit" value="Save" />
            </p>';

    }
    $html .= '</form></div>';
    echo $html;
}

0 个答案:

没有答案