• Resolved user256

    (@user256)


    Hey, trying to get my head around the form functionality. Can’t work out why this wont save. Any hints?

    [ Moderator note: please wrap code in backticks or use the code button. Do not use blockquote. ]

    <?php
    /*
     * Plugin Name: opengraph
     * Description: Enabling your site with Open Graph metabox on posts
     * Version: 0.1
     * Author: user256
     */
    
    add_action('admin_menu', 'ssd_settings'); // register admin menu
    add_action('admin_init', 'ssd_form_options');  // register form
    
    function register_mysettings() { // whitelist options
    	register_setting( 'ssd_form_options', 'twitterid' );
    	register_setting( 'ssd_form_options', 'fb_link' );
    }
    
    /** register form fields **/
    function ssd_form_options(){
    	register_setting('ssd_options_group', 'ssd_global_settings', 'ssd_validate');
        }
    
    /** register menu page **/
    function ssd_settings() {
    	add_menu_page('Structured Social Settings', 'Structured Social', 'administrator', 'ssd_settings_page', 'ssd_display_settings');
    } 
    
    function ssd_display_settings()
    {
    ?>
    <div class="wrap">
    	<div class="icon32" id="icon-options-general"></div>
    		<h2>Socially Structured Data</h2>
    <form method="post" action="options.php">
    <?php	settings_fields( 'ssd_options_group' );
    	do_settings_fields( 'ssd_options_group' ); ?>
    
    <p><strong>Twitter ID:</strong>
                    <input type="text" name="twitterid" size="45" value="<?php echo get_option('twitterid'); ?>" />
                </p>
    <p><strong>Facebook Page Links:</strong>
        <input type="text" name="fb_link" size="45" value="<?php echo get_option('fb_link'); ?>" />
    </p>
    
          <?php submit_button(); ?>
            </form>
    </div>
    <?php
    }
    ?>

Viewing 1 replies (of 1 total)
  • Thread Starter user256

    (@user256)

    urgh finally figured it out…. The issue seemed to be the order i was calling. Found a more detailed guide at thinkcode

    Working example

    <?php
    /*
     * Plugin Name: opengraph
     * Description: Enabling your site with Open Graph metabox on posts
     * Version: 0.1
     * Author: user256
     */
    
    add_action('admin_menu', 'ssd_settings'); // register admin menu
    add_action('admin_init', 'register_form_settings');  // register form
    
    /** register menu page **/
    function ssd_settings() {
    	add_menu_page('Structured Social Settings', 'Structured Social', 'administrator', 'ssd_settings_page', 'ssd_display_settings');
    } 
    
    /** register form fields **/
    function ssd_form_options(){
    	register_setting('ssd_options_group', 'ssd_global_settings', 'ssd_validate');
        }
    
    function register_form_settings() { // whitelist options
    	register_setting( 'ssd_form_options', 'twitterid' );
    	register_setting( 'ssd_form_options', 'fb_link' );
    }
    
    function ssd_display_settings()
    {
    ?>
    <div class="wrap">
    	<div class="icon32" id="icon-options-general"><br></div>
    		<h2>Socially Structured Data</h2>
    <form method="post" action="options.php">
    <?php	settings_fields( 'ssd_form_options' );  ?>
    <?php	do_settings_fields( 'ssd_form_options' ); ?>
    
    <p><strong>Twitter ID:</strong><br />
                    <input type="text" name="twitterid" size="45" value="<?php echo get_option('twitterid'); ?>" />
                </p>
    <p><strong>Facebook Page Links:</strong><br />
        <input type="text" name="fb_link" size="45" value="<?php echo get_option('fb_link'); ?>" />
    </p>
    
    <?php submit_button(); ?>
    </form>
    </div>
    <?php
    }
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘WordPress options page help’ is closed to new replies.