WordPress.org

Ready to get started?Download WordPress

Forums

Trying to save options page (1 post)

  1. user256
    Member
    Posted 9 months ago #

    I'm trying to create a plugin to save inputs from a select menu, i can find a thousand tutorials doing it the old way. Can anyone point me in the direction of something new / offer some advice?

    cheers

    <?php
    /*
     * Plugin Name: opengraph
     * Description: Enabling your site with Open Graph metabox on posts
     * Version: 10.1
     * Author: user256
     */
    
        define('SSD_NAME', plugin_basename( __FILE__ ));
        define('SSD_PLUGIN_URL', plugin_dir_url( __FILE__ ));
        define('SSD_PLUGIN_PATH', plugin_dir_path( __FILE__ ));
        define('SSD_VERSION', '0.1');
    
    /** register css & js **/
    wp_register_style( 'ssd-style', plugins_url( 'css/style.css', __FILE__ ), array(), '20130510', 'all' );
    wp_register_script( 'ssd-script', plugins_url( '/js/ssd.js', __FILE__ ), array( 'jquery' ) );
    /** end register css & js **/
    
    get_template_part( 'unknownpleasures ');
    
    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_global_options(){
    	register_setting('ssd_options_group', 'ssd_global_settings', 'ssd_validate');
    }
    
    /** enque css & js **/
    wp_enqueue_style( 'ssd-style' );
    wp_enqueue_script( 'ssd-script' );
    
    function register_form_settings() { // whitelist options
    	register_setting( 'ssd_global_options', 'twitterid' );
    	register_setting( 'ssd_global_options', 'fb_link' );
    	register_setting( 'ssd_global_options', 'ssd-card' ); 
    
    }
    
    function ssd_display_settings()
    {
    ?>
    <div class="wrap">
    	<div class="icon32" id="icon-options-general"><br></div>
    		<h2>Socially Structured Data</h2>
    <div class="dev-banner">
    				    <div class="dev-banner-left">Banner Area Left</div>
    				    <div class="dev-banner-right">Banner Area Right</div>
    			</div>
    			<div class="dev-clear"></div>
    <form method="post" action="options.php">
    <?php	settings_fields( 'ssd_global_options' );  ?>
    <?php	do_settings_fields( 'ssd_global_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>
    
    <select name="ssd-card-type" id="ssd-card-type">
        <option value="summary">Select Card Type</option>
         	<option value="summary" <?php if($card_type=="summary") echo 'selected="selected"';?>>Summary Card</option>
        	<option value="summary_large_image" <?php if($card_type=="summary_large_image") echo 'selected="selected"';?> >Summary Large Image Card</option>
        	<option value="photo" <?php if($card_type=="photo") echo 'selected="selected"';?>>Photo Card</option>
        	<option value="gallery" <?php if($card_type=="gallery") echo 'selected="selected"';?>>Gallery Card</option>
        	<option value="app" <?php if($card_type=="app") echo 'selected="selected"';?>>App Card</option>
        	<option value="player" <?php if($card_type=="player") echo 'selected="selected"';?>>Player Card</option>
        	<option value="product" <?php if($card_type=="product") echo 'selected="selected"';?>>Product Card</option>
    </select>
    <!--summary card -->
    			<tr id="summary" ><td colspan="2" class="head"><label>Summary Card Details</label></td></tr>
    		    <tr id="summary" ><td class="dev-left">
    			<label>Title</label></td>
         		<td class="dev-right">
    			    <input type="text" name="summary[title]" value="<?php echo $summary['title'];?>" size="50" placeholder="Left blank to use Post title by default." />
    			</td></tr>
    		    <tr id="summary" ><td class="dev-left">
    			<label>Description</label></td>
         		<td class="dev-right">
    			    <textarea name="summary[description]" cols="47" rows="4" placeholder="Left blank to use Post excerpt by default."><?php echo $summary['description'];?></textarea>
    			</td></tr>
    			<tr id="summary" ><td class="dev-left">
    			<label>Image</label></td>
         		<td class="dev-right">
    			    <input type="text" name="summary[image]" value="<?php echo $summary['image'];?>" size="50" placeholder="No image selected then Post feature image or plugin default image will be used." />
    			</td></tr>
    
    <?php submit_button(); ?>
    </form>
    </div>
    <?php
    }
    ?>

Reply

You must log in to post.

About this Topic