';
return vsprintf( $label_format, $args );
}
/* When the post is saved, saves our custom data */
function sp_save_postdata($post_id, $post) {
global $sp_boxes;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ! wp_verify_nonce( $_POST['sp_nonce_name'], plugin_basename(__FILE__) ) ) {
return $post->ID;
}
// Is the user allowed to edit the post or page?
if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post->ID ))
return $post->ID;
} else {
if ( ! current_user_can( 'edit_post', $post->ID ))
return $post->ID;
}
// OK, we're authenticated: we need to find and save the data
// We'll put it into an array to make it easier to loop though.
// The data is already in $sp_boxes, but we need to flatten it out.
foreach ( $sp_boxes as $sp_box ) {
foreach ( $sp_box as $sp_fields ) {
$my_data[$sp_fields[0]] = $_POST[$sp_fields[0]];
}
}
// Add values of $my_data as custom fields
// Let's cycle through the $my_data array!
foreach ($my_data as $key => $value) {
if ( 'revision' == $post->post_type ) {
// don't store custom data twice
return;
}
// if $value is an array, make it a CSV (unlikely)
$value = implode(',', (array)$value);
if ( get_post_meta($post->ID, $key, FALSE) ) {
// Custom field has a value.
update_post_meta($post->ID, $key, $value);
} else {
// Custom field does not have a value.
add_post_meta($post->ID, $key, $value);
}
if (!$value) {
// delete blanks
delete_post_meta($post->ID, $key);
}
}
}
function echo_sp_nonce () {
// Use nonce for verification ... ONLY USE ONCE!
echo sprintf(
'',
'sp_nonce_name',
wp_create_nonce( plugin_basename(__FILE__) )
);
}
// A simple function to get data stored in a custom field
if ( !function_exists('get_custom_field') ) {
function get_custom_field($field) {
global $post;
$custom_field = get_post_meta($post->ID, $field, true);
echo $custom_field;
}
}
?>