I have a template page in WordPress that I want the Admin to be able to change the text on that page. I’d love to learn how to make a plugin (I know how to make a plugin so that it shows up in WP, installs when the user sets it to activate, and then create the admin panel) that shows just one text field, and the data the person enters is passed to the template page.
If I could have help finding a tutorial or simple advice on how to do this, it would be greatly appreciated.
An example code for an options-page for a theme. Copy this code in the functions.php of the theme.
if ( !function_exists('localizing_theme_setup') ) {
function localizing_theme_setup() {
localizing_constants();
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain( FB_LT_TEXTDOMAIN, TEMPLATEPATH . '/languages' );
// instance class
$localizing_theme_options = new localizing_theme_options();
}
}
add_action( 'after_setup_theme', 'localizing_theme_setup' );
function localizing_constants() {
define( 'FB_LT_TEXTDOMAIN', 'localizing' );
}
if ( !class_exists( 'localizing_theme_options' ) ) {
class localizing_theme_options {
// constructor
function localizing_theme_options() {
add_action( 'admin_init',
array(&$this, 'localizing_theme_options_init')
);
add_action( 'admin_menu',
array(&$this, 'localizing_theme_options_add_page')
);
}
// Plugin options initialisieren
function localizing_theme_options_init() {
register_setting(
'localizing_theme_options',
'localizing_theme',
array(&$this, 'localizing_theme_options_validate')
);
}
// Menu page Seite hinzufuegen
function localizing_theme_options_add_page() {
add_theme_page(
__( 'Set your Localizing Settings', FB_LT_TEXTDOMAIN ),
__( 'Localizing Settings', FB_LT_TEXTDOMAIN ),
'switch_themes',
'localizing_settings',
array( &$this, 'localizing_theme_options_do_page' )
);
}
// HTML, Simple Options Page
function localizing_theme_options_do_page() {
?>
<div class="wrap">
<h2><?php _e( 'Localizing Settings', FB_LT_TEXTDOMAIN ); ?></h2>
<form method="post" action="options.php">
<?php
settings_fields('localizing_theme_options');
$options = get_option('localizing_theme');
$available_languages_files = get_available_languages();
if ( !empty( $available_languages_files ) ) {
// Translate the list into something that's easier to search
foreach ( $available_languages_files as $available_language ) {
$parts = explode( '_', $available_language );
if ( empty( $parts[0] ) )
continue;
$available_languages[ strtolower( $parts[0] ) ] = $available_language;
$santized = strtolower( $available_language );
$santized = str_replace( '_', '-', $santized );
$available_languages[$santized] = $available_language;
$all_available_languages[] = $available_language;
}
}
?>
<table class="form-table">
<tr>
<th scope="row">
<?php _e( 'Available languages', FB_LT_TEXTDOMAIN ); ?>
</th>
<td>
<input type="text" disabled="disabled" name=""
value="<?php echo implode( ', ', $all_available_languages ); ?>" />
<br />
<p><?php _e( 'This languages was found in the languages folder of this install.', FB_LT_TEXTDOMAIN ); ?></p>
</td>
</tr>
<tr valign="top">
<th scope="row">
<?php _e( 'A example checkbox', FB_LT_TEXTDOMAIN ); ?>
</th>
<td>
<input name="example_name[myoption1]" type="checkbox"
value="1" <?php checked('1',
$options['myoption1']); ?> />
</td>
</tr>
<tr valign="top">
<th scope="row">A example text</th>
<td>
<input type="text" name="example_name[mytext]"
value="<?php echo $options['mytext']; ?>" />
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Save Changes', FB_LT_TEXTDOMAIN ); ?>" />
</p>
</form>
</div>
<?php
}
// Sanitize und validiere input
// (Akzeptiert ein array, return ein sanitized array)
function localizing_theme_options_validate($input) {
// erster Wert muss 0 oder 1 sein
$input['option1'] = ( $input['option1'] == 1 ? 1 : 0 );
// Wert mit text
$input['sometext'] = wp_filter_nohtml_kses($input['sometext']);
return $input;
}
} // end class
} // end if class exists
this is my options from this code:

I hope you understand the code, is also an dummy, works, but is not so fine in the php-codex for classes.