试图编写一个简单的插件,无限循环?

时间:2014-07-12 作者:fsiaj0as98dsadas

我处于停滞状态。我已经检查过我的代码很多次了。该代码仅在设置-->插件页面上显示了大约4到5次,然后中断了浏览器。

我只是想制作一个文本框,可以根据需要进行修改,并在字体页面上显示出来。php。

我将此函数包括在内。我的主插件文件中的php文件:

<?php

// Add admin page to WP Settings menu
function grizzly_quotes_add_options() {
    add_options_page( \'Site Quotes\', \'Site Quotes\', \'manage_options\', \'site_quotes\', \'site_quotes_output_settings\' );
}

// Add Javascript
function add_grizzly_scripts() { 
    wp_enqueue_script( \'responsiveslidesjs\',  plugins_url( \'assets/js/responsiveslides.min.js\' , __FILE__ ) );
    wp_enqueue_script( \'themejs\',  plugins_url( \'assets/js/theme.js\' , __FILE__ ) );
}

// Add stylesheets
function add_grizzly_stylesheets() {
    wp_enqueue_style( \'responsiveslidescss\', plugins_url( \'assets/css/responsiveslides.css\' , __FILE__ ) );
}


// Add section for settings section to admin panel plugin page
function site_quotes_api_init() {
    // Add settings section to WP admin plugin page
    add_settings_section(
        \'site_quotes_settings_section\',
        \'Main Settings\',
        \'site_quotes_main_create_description\',
        \'site_quotes_plugin\'
    );
    add_settings_field(
        \'sometext\',
        \'Some text!\',
        \'site_quotes_output_settings\',
        \'site_quotes_plugin\',
        \'site_quotes_settings_section\'
    );
    register_setting( \'settings-group\', \'site_quotes_plugin_settings_arraykey\', \'site_quotes_validate\' );
}

// Sanitize and validate data
function site_quotes_validate($input) {
    $options = get_option(\'site_quotes_plugin_settings_arraykey\');
    $options[\'sometext\'] = trim($input[\'sometext\']);
    return $options;
}

// Output section description
function site_quotes_main_create_description() { 
    echo \'<p>This is where you add your quote!</p>\';
}


// Output the actual form
function site_quotes_output_settings() {
    ?>
    <div class="wrap">
    <form method="post" action="options.php">
        <?php
        // Makes the $options_group
        settings_fields( \'settings-group\' );
        // Make the $page
        do_settings_sections( \'site_quotes_plugin\' );
        ?>
        <?php submit_button(\'Save Changes\'); ?>
    </form>
    </div>
    <?php
}

function site_quotes_main_create_input() {
    $options = get_option(\'site_quotes_plugin_settings_arraykey\');
    ?><input type="text" name="site_quotes_plugin_settings_arraykey[sometext]" value="<?php echo $options[\'sometext\']; ?>" /><?php
}

// 

// Add to hook
add_action( \'admin_menu\', \'grizzly_quotes_add_options\' );
add_action( \'admin_init\', \'site_quotes_api_init\' );
add_action( \'init\', \'add_grizzly_scripts\' );
add_action( \'init\', \'add_grizzly_stylesheets\' );

1 个回复
最合适的回答,由SO网友:Sven 整理而成

仔细看看add_settings_field(); 您的回拨与的相同add_options_page().

您已经设置了输入函数。只要换一下site_quotes_output_settingssite_quotes_main_create_input 一切都应该很好:

add_settings_field(
  \'sometext\',
  \'Some text!\',
  \'site_quotes_main_create_input\',
  \'site_quotes_plugin\',
  \'site_quotes_settings_section\'
);

结束

相关推荐