Created
April 18, 2022 17:21
-
-
Save dariabloodworth/f3e129daccd8d154fd1ff4d8f67a5886 to your computer and use it in GitHub Desktop.
The original book post type for Get Noticed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getnoticed_types_book_init() { | |
# BOOKS | |
register_post_type( | |
'book', | |
array( | |
'labels' => array( | |
'name' => _x('Books', 'post type general name'), | |
'singular_name' => _x('Book', 'post type singular name'), | |
'add_new' => _x('Add New', 'book'), | |
'add_new_item' => __('Add New Book'), | |
'edit_item' => __('Edit Book'), | |
'new_item' => __('New Book'), | |
'view_item' => __('View Book'), | |
'search_items' => __('Search Books'), | |
'not_found' => __('No books found'), | |
'not_found_in_trash' => __('No books found in Trash'), | |
'parent_item_colon' => '', | |
'menu_name' => 'Books' | |
), | |
'public' => true, | |
'show_ui' => true, | |
'supports' => array( | |
'title', | |
'editor', | |
'thumbnail', | |
'comments', | |
'publicize', 'wpcom-markdown' # optional Jetpack features | |
), | |
'taxonomies' => array('category'), | |
'menu_position' => 9999, | |
'menu_icon' => '', | |
'has_archive' => true, | |
'rewrite' => array( | |
'slug' => apply_filters( 'getnoticed_types_slug', 'books' ), | |
'with_front' => false | |
) | |
) | |
); | |
} | |
add_action( 'init', 'getnoticed_types_book_init' ); | |
/* Modify admin columns */ | |
function getnoticed_types_book_columns( $default_cols ) { | |
$cols['cb'] = '<input type="checkbox" />'; | |
$cols['thumbnail'] = __('Thumbnail'); | |
$cols['title'] = __('Book Title'); | |
$cols['bookauthor'] = __('Author(s)'); | |
$cols['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>'; | |
$cols['date'] = _x('Date', 'column name'); | |
return $cols; | |
} | |
add_filter( 'manage_edit-book_columns', 'getnoticed_types_book_columns' ); | |
/* Output functions for custom admin columns */ | |
function getnoticed_types_book_columns_data( $col, $id ) { | |
global $post; | |
switch( $col ) { | |
case 'bookauthor': | |
$meta = get_post_meta( $id, 'getnoticed_meta_book', true ); | |
echo $meta['bookauthor']; | |
break; | |
case 'thumbnail': | |
echo the_post_thumbnail( 'custom_book' ); | |
break; | |
default: | |
break; | |
} | |
} | |
add_action( 'manage_book_posts_custom_column', 'getnoticed_types_book_columns_data', 10, 2 ); | |
/* Set up metaboxes */ | |
function getnoticed_types_book_call() { | |
$types_book = new getnoticedPostTypes( 'Books', 'book', array( | |
"bookauthor" => array( | |
'name' => 'bookauthor', | |
'title' => 'Author(s)' | |
), | |
"asin" => array( | |
'name' => 'asin', | |
'title' => 'ASIN or ISBN-10', | |
'description' => "We'll use this to generate a link to the product on Amazon with your affiliate code if it's been set up." | |
#'description' => 'We will use this to pull a thumbnail of the book from Amazon.' | |
), | |
'link' => array( | |
'name' => 'link', | |
'title' => 'Purchase link', | |
'description' => "Provide a link to help people purchase this book (this will override the automatic link generation from above)." | |
), | |
'publisher' => array( | |
'name' => 'publisher', | |
'title' => 'Publisher' | |
), | |
'city' => array( | |
'name' => 'city', | |
'title' => 'Publisher\'s city' | |
), | |
'year' => array( | |
'name' => 'year', | |
'title' => 'Year of publication' | |
) | |
) ); | |
} | |
if ( is_admin() ) add_action( 'load-post.php', 'getnoticed_types_book_call' ); | |
if ( is_admin() ) add_action( 'load-post-new.php', 'getnoticed_types_book_call' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment