我一直在尝试将设置保存到我正在创建的插件的Wordpress数据库中,但我一直被抛出
“警告:非法字符串偏移'iconomysignup_amount'中 /home/tomatocr/public_html/wp-content/plugins/iconomysignup/iconomy-signup.php 在第52行“
以下是我使用的插件代码:
<?php
/**
* Plugin Name: Tomatocraft iConomy Signup
* Description: A simple plugin that gives a user-defined amount of coins to the user who just signed up.
* Version: 1.0
* Author: minejames1
* Author URI: http://twitter.com/jaycraft_
*/
// add the admin options page
add_action('admin_menu', 'plugin_admin_add_page');
function plugin_admin_add_page() {
add_options_page('Tomatocraft iConomy Signup', 'iConomy Signup', 'manage_options', 'iconomysignup', 'plugin_options_page');
}
// display the admin options page
function plugin_options_page() {
?>
<div class="wrap">
<?php screen_icon();?>
<h2>Set signup iConomy reward</h2>
<form action="options.php" method="post">
<?php settings_fields('plugin_options'); ?>
<?php do_settings_sections('iconomysignup'); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
} // end of page
// add the admin settings and such
add_action('admin_init', 'plugin_admin_init');
function plugin_admin_init(){
register_setting( 'plugin_options', 'plugin_options', 'plugin_options_validate' );
add_settings_section('plugin_main', 'Main Settings', 'plugin_section_text', 'iconomysignup');
add_settings_field('plugin_iconomysignup_amount', 'Amount of Tomatoes', 'plugin_setting_string', 'iconomysignup', 'plugin_main');
}
function plugin_options_validate($input) {
$options = get_option('plugin_options');
$options['iconomysignup_amount'] = trim($input['iconomysignup_amount']);
if(!is_numeric($options['iconomysignup_amount'])) {
$options['iconomysignup_amount'] = '';
}
return $options;
}
function plugin_section_text() {
echo '<p>Enter in the amount of Tomatoes the user should receive when signing up.</p>';
}
function plugin_setting_string() {
$options = get_option('plugin_options');
echo "<input id='plugin_iconomysignup_amount' name='plugin_options[iconomysignup_amount]' size='40' type='text' value='{$options['iconomysignup_amount']}' />";
}
?>
如果有人能指出我正在犯的错误会很棒 - 他们可能很愚蠢而且显而易见,但作为Wordpress CMS的初学者,这一切都让人很困惑。感谢。
答案 0 :(得分:1)
在第52行更改此内容
value='{$options['iconomysignup_amount']}'
用这个
value='{$options[iconomysignup_amount]}'
或
value=\"{$options['iconomysignup_amount']}\"
答案 1 :(得分:0)
您可以尝试:
echo '<input id="plugin_iconomysignup_amount" name="plugin_options[iconomysignup_amount]" size="40" type="text" value="'.$options['iconomysignup_amount'].'" />';