WordPress Snippet

ワードプレスをカスタマイズしよう

新しい、プラグイン管理パネルの作り方

code check WordPress 3.4

<?php
/*
Plugin Name: My Test
Plugin URI: 
Description: coding test
Version: 0.1
Author: Nobita
Author URI: http://www.tenman.info/
License: GPL2
 */
?>< ?php

// create custom plugin settings menu
	add_action( 'admin_menu', 'baw_create_menu' );

/**
 * Menu Create
 *
 *
 *
 *
 */

	function baw_create_menu() {
	
		//create new top-level menu
		add_menu_page( 'BAW Plugin Settings', 'BAW Settings', 'administrator', basename( __FILE__ ), 'baw_settings_page',plugins_url( '/images/icon.png', __FILE__) );
	
		//call register settings function
		add_action( 'admin_init', 'register_mysettings' );
	}

/**
 * HTML
 *
 *
 *
 *
 */

	function register_mysettings() {
		//register our settings
		register_setting( 'baw-settings-group', 'new_option_name' );
		register_setting( 'baw-settings-group', 'some_other_option' );
		register_setting( 'baw-settings-group', 'option_etc' );
	}
	
	function baw_settings_page() {
		$mytest_plugin_data= get_plugin_data( __FILE__ );
	?><div class="wrap">
	<h2>Plugin Name: < ?php echo $mytest_plugin_data['Name'];?></h2>
	
	<form method="post" action="options.php">
		< ?php settings_fields( 'baw-settings-group' ); ?>
		< ?php do_settings_sections( 'baw-settings-group' ); ?>
		<table class="form-table">
			<tr valign="top">
			<th scope="row">New Option Name</th>
			<td><input type="text" name="new_option_name" value="<?php echo get_option( 'new_option_name','fallback value' ); ?/>" /></td>
			</tr>
			<tr valign="top">
			<th scope="row">Some Other Option</th>
			<td><input type="text" name="some_other_option" value="<?php echo get_option( 'some_other_option','fallback value' ); ?/>" /></td>
			</tr>
			
			<tr valign="top">
			<th scope="row">Options, Etc.</th>
			<td><input type="text" name="option_etc" value="<?php echo get_option( 'option_etc','fallback value' ); ?/>" /></td>
			</tr>
		</table>
		<p class="submit">
		<input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'PluginPrefix' ) ?/>" />
		</p>
	</form>
	</div>
	< ?php //template using like bellow
	echo 'get_option( \'new_option_name\',\'fallback value\' ); Result: <span style="color:red">'. get_option( 'new_option_name','fallback value' ).'';
	?>
	
<h3>link</h3>
<ul>
<li><a href="http://www.presscoders.com/2010/05/wordpress-settings-api-explained/">tutorial</a></li>
<li><a href="http://codex.wordpress.org/Creating_Options_Pages">Codex:Creating_Options_Pages</a></li>
<li><a href="http://pastebin.com/DSWq8aYY">Another snippet</a></li>

</ul>	
	< ?php } ?>

[emulsion_relate_posts]