Skip to content

Instantly share code, notes, and snippets.

@technosailor
Created February 26, 2013 14:49
Show Gist options
  • Save technosailor/5038949 to your computer and use it in GitHub Desktop.
Save technosailor/5038949 to your computer and use it in GitHub Desktop.
<?php
class AF_Metaboxes {
public function __construct() {
$this->hooks();
}
public function hooks() {
add_action( 'add_meta_boxes', array( $this, 'metaboxes' ) );
add_action( 'save_post', array( $this, 'save' ) );
}
public function metaboxes() {
add_meta_box( 'extra-fields', 'New Post Meta', array( $this, 'extra_fields_metaboxes' ), 'page', 'side' );
}
public function extra_fields_metaboxes() {
$nonce = wp_create_nonce( 'af_meta_nonce' );
$related = get_post_meta( $post_id, 'af_meta', true );
?>
<input type="hidden" name="_meta_nonce" value="<?php echo $nonce ?>" />
<div class="inside">
<label class="screen-reader-text">My Meta</label>
<p><input type="text" name="af_meta" value="<?php echo esc_attr( $af_meta ) ?>" /></p>
<p class="howto">Some help text</p>
</div>
<?php
}
public function save( $post_id )
{
if( !wp_verify_nonce( $_POST['_meta_nonce'], 'af_meta_nonce' ) )
return false;
update_post_meta( $post_id, 'af_meta_nonce', $_POST['af_meta'] );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment