1

I am at a standstill. I have checked over my code so many times. The code just shows up about 4 or 5 times on the Settings --> Plugin page and then breaks the browser.

I am just trying to make a text box that can be modified as needed and echoed out on the font-page.php.

I am including this functions.php file from my main plugin file:

<?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' );
  • Did the answer solve your problem? Do you need further help? :) – Sven Jul 15 '14 at 11:59
0

Take a closer look at add_settings_field(); your callback is the same as of add_options_page().

You've already set up your input function. Just change site_quotes_output_settings to site_quotes_main_create_input and everything should be fine:

add_settings_field(
  'sometext',
  'Some text!',
  'site_quotes_main_create_input',
  'site_quotes_plugin',
  'site_quotes_settings_section'
);
| improve this answer | |
  • 1
    Thanks Sven! This worked perfectly. I think the problem is I don't really understand what I am doing besides just filling in the fields, this goes there, this goes there, blah blah. What is the best way to go about fixing this? Start reading through the WP Codex? I am working on my PHP as I speak but I am still rather beginner. – fsiaj0as98dsadas Jul 20 '14 at 21:11
  • @TheCarlJay This is totally fine and you'll get used to this after some time. Make sure to use an IDE with code hinting and learn to interpret the error messages. Of course reading through the Codex definitely helps, too. However this is kinda out of scope of this question, but feel free to join us in Chat if you're further interested in any of these :) – Sven Jul 20 '14 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.