Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 custom post type #17

Merged
merged 10 commits into from
Apr 15, 2024
31 changes: 31 additions & 0 deletions blueprints/custom-post/blueprints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"meta": {
"title": "Custom Post Type: Books",
"description": "Blueprint that added a custom post type to playground",
"author": "bph",
"categories": ["Content", "CPT"]
},
"landingPage": "/wp-admin/",
"steps":[
{
"step": "login"
},
{
"step": "mkdir",
"path": "/wordpress/wp-content/plugins/books"
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/plugins/books/books.php",
"data": {
"resource": "url",
"url": "https://raw.githubusercontent.com/adamziel/blueprints/custom-post/book.txt"
bph marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
"step": "activatePlugin",
"pluginPath": "/wordpress/wp-content/plugins/books/"
bph marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
75 changes: 75 additions & 0 deletions blueprints/custom-post/books.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/*
* Plugin Name: Books
* Plugin URI: https://icodeforapurpose.com
* Description: Create the Book Custom post Type
* Version: 0.1.
* Requires at least: 6.0
* Requires PHP: 7.2
* Author: Birgit Pauli-Haack
* Author URI: https://profiles.wordpress.org/bph
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Update URI: https://example.com/my-plugin/
* Text Domain: gbt
* Domain Path: /languages
*/


// Register Custom Post Type
function register_books() {

$labels = array(
'name' => _x( 'Books', 'Post Type General Name', 'gbt' ),
'singular_name' => _x( 'Book', 'Post Type Singular Name', 'gbt' ),
'menu_name' => __( 'Books', 'gbt' ),
'name_admin_bar' => __( 'Books', 'gbt' ),
'archives' => __( 'Book Archives', 'gbt' ),
'attributes' => __( 'Book Attributes', 'gbt' ),
'parent_item_colon' => __( 'Parent book', 'gbt' ),
'all_items' => __( 'All Books', 'gbt' ),
'add_new_item' => __( 'Add New Book', 'gbt' ),
'add_new' => __( 'Add New Book', 'gbt' ),
'new_item' => __( 'New Book', 'gbt' ),
'edit_item' => __( 'Edit Book', 'gbt' ),
'update_item' => __( 'Update Book', 'gbt' ),
'view_item' => __( 'View Book', 'gbt' ),
'view_items' => __( 'View Books', 'gbt' ),
'search_items' => __( 'Search Books', 'gbt' ),
'not_found' => __( 'Not found', 'gbt' ),
'not_found_in_trash' => __( 'Not found in Trash', 'gbt' ),
'featured_image' => __( 'Featured Image', 'gbt' ),
'set_featured_image' => __( 'Set featured image', 'gbt' ),
'remove_featured_image' => __( 'Remove featured image', 'gbt' ),
'use_featured_image' => __( 'Use as featured image', 'gbt' ),
'insert_into_item' => __( 'Insert into item', 'gbt' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'gbt' ),
'items_list' => __( 'Items list', 'gbt' ),
'items_list_navigation' => __( 'Items list navigation', 'gbt' ),
'filter_items_list' => __( 'Filter items list', 'gbt' ),
);
$args = array(
'label' => __( 'Book', 'gbt' ),
'description' => __( 'Books', 'gbt' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', excerpt, featured_image),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting PHP Fatal error: Uncaught Error: Undefined constant "excerpt" here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I made changes after I tested it myself. 🤦‍♀️ I removed supports excerpt and featured image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should work now.

'taxonomies' => array( 'genre', ' publisher' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-book-alt',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true,
);
register_post_type( 'gbtbooks', $args );

}
add_action( 'init', 'register_books', 0 );