WordPress tried to save the custom field, but did not have the necessary permissions to do so.
Please copy the below into /wp-document-revisions-slug; ?>-custom-field.php
/*
Plugin Name: name; ?> Custom Document Field
Plugin URI: plugin_uri; ?>
Description: Creates name ); ?> custom taxonomy for use with WP Document Revisions
Version: version; ?>
Author: author; ?>
Author URI: author_uri; ?>
License: GPL2
*/
type ) {
case 'text':
$this->text();
break;
case 'user':
$this->user();
break;
case 'exclusive':
$this->ct();
$this->exclusive();
break;
default:
$this->ct();
break;
}
//append signature
$this->signature();
//close tag and clear buffer to string
echo "?>";
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/**
* CB to process submission of UI
* @since 0.1
*/
function ui_submit() {
//verify POSTing
if ( !$_POST )
return;
//check referer
check_admin_referer('document_revisions_custom_taxonomy');
//set up defaults and parse args
$defaults = array(
'name' => $this->name,
'name_plural' => $this->name_plural,
'slug' => $this->slug,
'type' => 'hierarchical',
);
$args = wp_parse_args( $_POST, $defaults );
//filter data and store
$this->name = ucwords( trim( $args['name'] ) );
$this->name_plural = ucwords( trim( $args['name_plural'] ) );
$this->slug = preg_replace('/[^a-z0-9_]/', '', strtolower( str_replace( ' ', '_', trim( $args['slug'] ) ) ) );
$this->type = $args['type'];
//generate plugin
$this->plugin = $this->generate_plugin();
}
/**
* Pulls signature from file
* @since 0.1
* @param string $file the plugin content
* @returns string the parsed plugin
*/
function parse_plugin_file( $file ) {
$pattern = '#/[\*]{35}.*?[A-Za-z0-9 \r]{34}(.*)[\*]{36}/#sm';
$result = preg_match( $pattern, $file, $matches );
if ( !$result )
return false;
return trim( $matches[1] );
}
/**
* Attempts to write plugin file to disk
* @since 0.1
* @returns bool success/fail
*/
function save_plugin() {
return file_put_contents( WP_PLUGIN_DIR . '/wp-document-revisions-' . $this->slug . '-custom-field.php', $this->plugin );
}
/**
* Generates Custom Taxonomy plugins
* @since 0.1
*/
function ct() { ?>
/**
* Callback to register name; ?> custom document taxonomy
*/
function wp_document_revisions_register_slug; ?>_ct() {
$labels = array(
'name' => _x( 'name_plural; ?>', 'taxonomy general name' ),
'singular_name' => _x( 'name; ?>', 'taxonomy singular name' ),
'search_items' => __( 'Search name_plural; ?>' ),
'all_items' => __( 'All name_plural; ?>' ),
'parent_item' => __( 'Parent name; ?>' ),
'parent_item_colon' => __( 'Parent name; ?>:' ),
'edit_item' => __( 'Edit name; ?>' ),
'update_item' => __( 'Update name; ?>' ),
'add_new_item' => __( 'Add New name; ?>' ),
'new_item_name' => __( 'New name; ?> Name' ),
'menu_name' => __( 'name; ?>' ),
);
register_taxonomy('document_slug; ?>',array('document'), array(
'hierarchical' => type == 'freeform') ? 'false' : 'true' ?>,
'labels' => $labels,
'show_ui' => true,
'public' => false,
'rewrite' =>false,
));
}
//add action hook
add_action( 'init', 'wp_document_revisions_register_slug; ?>_ct');
/**
* Callback to register name; ?> metabox
*/
function wp_document_revisions_register_slug; ?>_metabox() {
add_meta_box( 'document_slug; ?>', 'name; ?>', 'wp_document_revisions_slug; ?>_cb', 'document');
}
//add action hook
add_action( 'add_meta_boxes', 'wp_document_revisions_register_slug; ?>_metabox' );
/**
* Callback to store name; ?> field
*/
function wp_document_revisions_save_slug; ?>( $post_id ) {
//verify this is not an autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
//verify nonce
if ( !wp_verify_nonce( $_POST['document_slug; ?>_nonce'], plugin_basename( __FILE__ ) ) )
return;
//verify permissions
if ( !current_user_can( 'edit_post', $post_id ) )
return;
//store the data
update_post_meta( $post_id, 'document_slug; ?>', $_POST['document_slug; ?>'], true);
}
add_action( 'save_post', 'wp_document_revisions_save_slug; ?>', 10, 1 );
/**
* Callback to display name; ?> metabox
*/
function wp_document_revisions_slug; ?>_cb( $post) {
global $wpdb;
//output nonce field
wp_nonce_field( plugin_basename( __FILE__ ), 'document_slug; ?>_nonce' );
//get list of authors
$authors = $wpdb->get_results("SELECT display_name, user_nicename from $wpdb->users ORDER BY display_name");
//output label
echo ':';
//output name; ?> dropdown
echo '';
}
/**
* Callback to register name; ?> metabox
*/
function wp_document_revisions_register_slug; ?>_metabox() {
add_meta_box( 'document_slug; ?>', 'name; ?>', 'wp_document_revisions_slug; ?>_cb', 'document');
}
//add action hook
add_action( 'add_meta_boxes', 'wp_document_revisions_register_slug; ?>_metabox' );
/**
* Callback to store name; ?> field
*/
function wp_document_revisions_save_slug; ?>( $post_id ) {
//verify this is not an autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
//verify nonce
if ( !wp_verify_nonce( $_POST['document_slug; ?>_nonce'], plugin_basename( __FILE__ ) ) )
return;
//verify permissions
if ( !current_user_can( 'edit_post', $post_id ) )
return;
//store the data
update_post_meta( $post_id, 'document_slug; ?>', $_POST['document_slug; ?>'], true);
}
add_action( 'save_post', 'wp_document_revisions_save_slug; ?>', 10, 1 );
/**
* Callback to display name; ?> metabox
*/
function wp_document_revisions_slug; ?>_cb( ) {
global $post;
//create nonce field
wp_nonce_field( plugin_basename( __FILE__ ), 'document_slug; ?>_nonce' );
//output label
echo ':';
//output name; ?> field
echo '';
}
/**
* Callback to register name; ?> metabox
*/
function wp_document_revisions_register_slug; ?>_metabox() {
//remove default metabox
remove_meta_box( 'document_slug; ?>div', 'document', 'side');
//add custom metabox
add_meta_box( 'document_slug; ?>', 'name; ?>', 'wp_document_revisions_slug; ?>_cb', 'document', 'side');
}
//add action hook
add_action( 'add_meta_boxes', 'wp_document_revisions_register_slug; ?>_metabox' );
/**
* Generates the name; ?> taxonomy radio inputs
* @params object $post the post object WP passes
* @params object $box the meta box object WP passes (with our arg stuffed in there)
*/
function wp_document_revisions_slug; ?>_cb( $post ) {
//get the taxonomy and labels
$taxonomy = get_taxonomy( 'document_slug; ?>' );
//grab an array of all terms within our custom taxonomy, including empty terms
$terms = get_terms( 'document_slug; ?>', array( 'hide_empty' => false ) );
//garb the current selected term where applicable so we can select it
$current = wp_get_object_terms( $post->ID, 'document_slug; ?>' );
//loop through the terms
foreach ($terms as $term) {
//build the radio box with the term_id as its value
echo 'term_id ) )
checked( $term->term_id, $current[0]->term_id );
//build the label
echo '> '. "\r\n";
}
echo 'term_id) );
echo '/> '. "\r\n";
'; ?>
+ echo $taxonomy->labels->add_new_item; ?>
//nonce is a funny word
wp_nonce_field( 'add_document_slug; ?>', '_ajax_nonce-add-document_slug; ?>' );
wp_nonce_field( 'document_slug; ?>', 'document_slug; ?>_nonce');
}
/**
* Processes AJAX request to add new name; ?> terms
* @since 1.2
*/
function wp_document_revisions_slug; ?>_ajax_add() {
//pull the taxonomy from the action query var
$type = substr($_GET['action'],4);
//pull up the taxonomy details
$taxonomy = get_taxonomy($type);
//check the nonce
check_ajax_referer( $_GET['action'] , '_ajax_nonce-add-document_slug; ?>' );
//check user capabilities
if ( !current_user_can( $taxonomy->cap->edit_terms ) )
die('-1');
//insert term
$term = wp_insert_term( $_POST['new_document_slug; ?>'], 'document_slug; ?>' );
//get updated post to send to taxonomy box
$post = get_post( $_POST['post_ID'] );
//return the HTML of the updated metabox back to the user so they can use the new term
wp_document_revisions_slug; ?>_cb( $post );
exit();
}
add_action('wp_ajax_add_document_slug; ?>', 'wp_document_revisions_slug; ?>_ajax_add');
/**
* Callback to store name; ?> custom taxonomy
*/
function wp_document_revisions_save_slug; ?>( $post_id ) {
//verify this is not an autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
//verify nonce
if ( !wp_verify_nonce( $_POST['document_slug; ?>_nonce'], 'document_slug; ?>' ) )
return;
//verify permissions
if ( !current_user_can( 'edit_post', $post_id ) )
return;
//associate taxonomy with parent, not revision
if ( wp_is_post_revision( $post_id ) )
$post_id = wp_is_post_revision( $post_id );
//store the data
wp_set_post_terms( $post_id, $_POST['document_slug; ?>'], 'document_slug; ?>', false);
}
add_action( 'save_post', 'wp_document_revisions_save_slug; ?>', 10, 1 );
/***********************************
WP Document Revisions Custom Field
$this->name, 'name_plural' => $this->name_plural, 'slug' => $this->slug, 'type' => $this->type ) ); ?>
************************************/