_x('Articles', 'post type name', 'anno'),
'singular_name' => _x('Article', 'post type singular name', 'anno'),
'add_new_item' => _x('Add New Article', 'post type plural name', 'anno'),
'edit_item' => _x('Edit Article', 'post type label', 'anno'),
'new_item' => _x('New Article', 'post type label', 'anno'),
'view_item' => _x('View Article', 'post type label', 'anno'),
'search_items' => _x('Search Articles', 'post type label', 'anno'),
'not_found' => _x('No Articles found', 'post type label', 'anno'),
'not_found_in_trash' => _x('No Articles found in Trash', 'post type label', 'anno'),
'menu_name' => _x('Articles', 'post type label, noun', 'anno'),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'has_archive' => true,
'hierarchical' => false,
'rewrite' => true,
'query_var' => 'articles',
'supports' => array('title', 'thumbnail', 'comments', 'revisions', 'author'),
'taxonomies' => array(),
'menu_position' => 5,
'capability_type' => $capability_type,
'menu_icon' => get_bloginfo('template_url').'/assets/main/img/admin-menu-icon.png',
);
register_post_type('article', $args);
}
add_action('after_setup_theme', 'anno_register_post_types');
/**
* Request handler for post types (article)
*/
function anno_post_type_requst_handler() {
// Converts Article to Post post type
if (isset($_POST['anno_convert'])) {
wp_verify_nonce($_POST['anno_convert_nonce'], 'anno_convert');
if(!current_user_can('editor') && !current_user_can('administrator')) {
wp_die(_x('Unable to perform that ability', 'wp_die error message', 'anno'));
}
$post_id = absint($_POST['post_ID']);
anno_article_to_post($post_id);
wp_redirect(get_edit_post_link($post_id, 'redirect'));
die();
}
}
add_action('admin_init', 'anno_post_type_requst_handler', 0);
/**
* Display custom messages for articles. Based on WP high 3.1.2
*/
function anno_post_updated_messages($messages) {
global $post;
// Based on message code in WP high 3.2
$messages['article'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf(_x('Article updated. View article', 'Article updated message', 'anno'), esc_url(get_permalink($post->ID))),
2 => _x('Custom field updated.', 'Article updated message', 'anno'),
3 => _x('Custom field deleted.', 'Article updated message', 'anno'),
4 => _x('Article updated.', 'Article updated message', 'anno'),
5 => isset($_GET['revision']) ? sprintf( _x('Article restored to revision from %s', 'Article updated message', 'anno'), wp_post_revision_title((int) $_GET['revision'], false )) : false,
6 => sprintf(_x('Article published. View article', 'Article updated message', 'anno'), esc_url(get_permalink($post->ID))),
7 => _x('Article saved.', 'Article updated message', 'anno'),
8 => sprintf( _x('Article submitted. Preview article', 'Article updated message', 'anno'), esc_url(add_query_arg('preview', 'true', get_permalink($post->ID)))),
9 => sprintf( _x('Article scheduled for: %1$s. Preview article', 'Article updated message', 'anno'), date_i18n( _x( 'M j, Y @ G:i', 'Article updated future time format', 'anno' ), strtotime( $post->post_date )), esc_url( get_permalink($post->ID))),
10 => sprintf( _x('Article draft updated. Preview article', 'Article updated message', 'anno'), esc_url( add_query_arg('preview', 'true', get_permalink($post->ID)))),
11 => _x('Article successfully cloned.', 'Article updated message', 'anno'),
12 => _x('Unable to clone article.', 'Article updated message', 'anno'),
);
return $messages;
}
add_filter('post_updated_messages', 'anno_post_updated_messages');
/**
* Add DTD Meta Boxes
*/
function anno_article_meta_boxes() {
add_meta_box('subtitle', _x('Subtitle', 'Meta box title', 'anno'), 'anno_subtitle_meta_box', 'article', 'normal', 'high');
add_meta_box('body', _x('Body', 'Meta box title', 'anno'), 'anno_body_meta_box', 'article', 'normal', 'high');
add_meta_box('references', _x('References', 'Meta box title', 'anno'), 'anno_references_meta_box', 'article', 'normal', 'high');
add_meta_box('abstract', _x('Abstract', 'Meta box title', 'anno'), 'anno_abstract_meta_box', 'article', 'normal', 'high');
add_meta_box('funding', _x('Funding Statement', 'Meta box title', 'anno'), 'anno_funding_meta_box', 'article', 'normal', 'high');
add_meta_box('acknowledgements', _x('Acknowledgements', 'Meta box title', 'anno'), 'anno_acknowledgements_meta_box', 'article', 'normal', 'high');
add_meta_box('appendices', _x('Appendices', 'Meta box title', 'anno'), 'anno_appendices_meta_box', 'article', 'normal', 'high');
add_meta_box('featured', _x('Featured', 'Meta box title', 'anno'), 'anno_featured_meta_box', 'article', 'side', 'default');
if (current_user_can('editor') || current_user_can('administrator')) {
add_meta_box('convert', _x('Convert To Post', 'Meta box title', 'anno'), 'anno_convert_meta_box', 'article', 'side', 'low');
}
}
add_action('add_meta_boxes_article', 'anno_article_meta_boxes');
function anno_subtitle_meta_box($post) {
$html = get_post_meta($post->ID, '_anno_subtitle', true);
?>
post_content) || $hook_suffix == 'post-new.php') {
$content = '
'.sprintf(_x('The Annotum editor requires at least WordPress 3.3. It appears you are using WordPress %s. ', 'WordPress version error message', 'anno'), get_bloginfo('version')).'
'; } ?> ID, '_anno_references', true); if (!empty($references) && is_array($references)) { foreach ($references as $ref_key => $reference) { $ref_key_display = $ref_key + 1; ?> ID, '_anno_funding', true); ?> ID, '_anno_acknowledgements', true); ?> ID, '_anno_featured', true); ?> /> post_type == 'article') { $anno_meta = array( 'anno_subtitle', 'anno_funding', 'anno_acknowledgements', 'anno_featured' ); foreach ($anno_meta as $key) { if (isset($_POST[$key])) { switch ($key) { case 'anno_featured': if (isset($_POST['anno_featured']) && $_POST['anno_featured'] == 'on') { $value = 'on'; } else { $value = 'off'; } // Reset the transient if this is a published article if ($post->post_status == 'publish') { delete_transient('anno_featured'); } break; case 'anno_subtitle': case 'anno_funding': case 'anno_acknowledgements': default: if (isset($_POST[$key])) { $value = force_balance_tags($_POST[$key]); } else { $value = ''; } break; } update_post_meta($post_id, '_'.$key, $value); } else if ( 'anno_featured' == $key ) { $value = 'off'; // anno_featured is a checkbox, will no be in $_POST when unchecked update_post_meta($post_id, '_'.$key, $value); } } $appendices = array(); if (isset($_POST['anno_appendix']) && is_array($_POST['anno_appendix'])) { foreach ($_POST['anno_appendix'] as $appendix) { if (!anno_is_appendix_empty($appendix)) { $appendices[] = addslashes(anno_validate_xml_content_on_save(stripslashes($appendix))); } } update_post_meta($post_id, '_anno_appendices', $appendices); } } } add_action('wp_insert_post', 'anno_article_save_post', 10, 2); /** * Checks to see if a content block is empty or contains the default markup * * @param string $appendix_content Content sent from the editor * @return bool true if there exists content other than the default, false otherwise. */ function anno_is_appendix_empty($appendix_content) { // Account for variations in how different browsers handle empty tags in tinyMCE $appendix_content = str_replace(array(' ', ' ', ' ', '\n', 'Article to a Post. This will also convert any terms in article taxonomies to post taxonomies. You will not be able to revert this Article back once it has been converted to a Post.', 'conversion instructions', 'anno'); ?>
ID); $deposit_id = 'doi-deposit-submit'; } ?> /> />