Public feed #601718

A Nonce Example

public php v1 · immutable
Raw Edit
·published 2007-07-03 17:43 UTC
rendered paste body
<?php/*Plugin Name: A Nonce ExamplePlugin URI: http://blahDescription: Does blahVersion: 1.0Author: OzhAuthor URI: http://planetozh.com/*/function ozh_nex_add_page() {	add_options_page('A Nonce Example', 'Nonce Ex', 8, 'nonceisnotcomplicated', 'ozh_nex_option_page');}function ozh_nex_option_page() {		if (@$_POST) ozh_nex_process_form();		ozh_nex_print_form();}function ozh_nex_process_form() {	global $ozh_nex;	check_admin_referer('noncex-update_value');	$ozh_nex['value'] = $_POST['somefield'];		echo <<<HTML	<div class="updated">	<p>Value entered was: <strong>${ozh_nex['value']}</strong></p>	</div>HTML;}function ozh_nex_print_form() {	global $ozh_nex;		$value = $ozh_nex['value'];		echo <<<HTML	<div class="wrap"><h2>A "nonce" example</h2>	<form method="post" action="">HTML;	if ( function_exists('wp_nonce_field') )		wp_nonce_field('noncex-update_value');	echo <<<HTML	<p>Enter a value: <input type="text" name="somefield" value="$value" /></p>	<p class="submit"><input type="submit" value="Update &raquo;" /></p>	</form>	</div>HTML;}add_action('admin_menu', 'ozh_nex_add_page');