Here is the fixed and modified code which was having the nonce action issue.
<?php
/*
Plugin Name: Test Plugin
Plugin URI: Test
Description: Test
Author: Test
Version: 007
Author URI:
*/
// add all post types
$clinical_post_types = array();
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
$clinical_post_types[] = $post_type;
}
// Meta box
// Add the language metabox on every registered custom post type
function clinical_add_language_metaboxe() {
global $clinical_post_types;
foreach ( $clinical_post_types as $post_type ) {
add_meta_box( 'clinical_meta_box', __( 'Search Engine Optimization', 'clinical' ), 'clinical_meta_custom_box', $post_type, 'normal', 'default' );
}
}
// The Post's meta fields Metabox
function clinical_meta_custom_box() {
global $post;
// Get the meta fields data if its already been entered
$meta_title = get_post_meta( $post->ID, '_clinical_meta_title', true );
$meta_description = get_post_meta( $post->ID, '_clinical_meta_description', true );
echo '<input type="hidden" name="clinicalmeta_noncename" id="clinicalmeta_noncename" value="' . wp_create_nonce( "clinicalmeta_nonce_action" ) . '" />';
// Echo out the field
$html="<p><label for="clinical_meta_title"><strong>" . __( 'Title', 'clinical' ) . '</strong></label></p>';
$html .= '<p><input type="text" class="regular-text" name="_clinical_meta_title" id="clinical_meta_title" value="' . $meta_title . '" /></p>';
$html .= '<p><label for="clinical_meta_description"><strong>' . __( 'Description', 'clinical' ) . '</strong></label></p>';
$html .= '<p><textarea class="large-text" name="_clinical_meta_description" id="clinical_meta_description">' . $meta_description . '</textarea></p>';
echo $html;
}
// Save the metabox data
function clinical_save_post_meta( $post_id, $post ) {
global $clinical_post_types;
$key_title="_clinical_meta_title";
$key_description = '_clinical_meta_description';
// if we're not in a clinical-enabled post type, skip.
if ( in_array( $post->post_type, $clinical_post_types ) ) {
// return $post;
}
// verify this came from our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( empty( $_POST[ $key_title ] ) && empty( $_POST[ $key_description ] ) ) || empty( $_POST['clinicalmeta_noncename'] ) || ( ! wp_verify_nonce( $_POST['clinicalmeta_noncename'], "clinicalmeta_nonce_action" ) ) || ( ! current_user_can( 'edit_post', $post->ID ) ) ) {
return $post->ID;
}
// OK, we're authenticated: we need to find and save the data
$title = $_POST[ $key_title ];
$description = $_POST[ $key_description ];
// set the post's meta title:
$updated_title = update_post_meta( $post->ID, $key_title, $title );
$updated_description = update_post_meta( $post->ID, $key_description, $description );
// Delete if blank:
if ( empty( $title ) ) {
delete_post_meta( $post->ID, $key_title );
}
if ( empty( $description ) ) {
delete_post_meta( $post->ID, $key_description );
}
}
// Filters
function clinical_wp_title_filter( $title ) {
global $post;
$seo_title = get_post_meta( $post->ID, '_clinical_meta_title', true );
if ( ! empty( $seo_title ) ) {
return $seo_title;
}
return $title;
}
function clinical_wp_head_action() {
global $post;
$seo_description = get_post_meta( $post->ID, '_clinical_meta_description', true );
if ( ! empty( $seo_description ) ) {
echo '<!-- Clinical CMS SEO --> <meta name="description" content="' . esc_attr( $seo_description ) . '" /> <!-- END Clinical CMS SEO -->';
}
}
// Helpers
// Filters and Hooks
add_action( 'admin_init', 'clinical_add_language_metaboxe' );
add_action( 'save_post', 'clinical_save_post_meta', 1, 2 );
add_filter( 'wp_title', 'clinical_wp_title_filter' );
add_action( 'wp_head', 'clinical_wp_head_action' );