Skip to content

Commit 608e0da

Browse files
bphadamziel
andauthored
v1 custom post type (#17)
Blueprint - create folder - Add a file to create a plugin that adds a custom post type. - activate plugin Enable the user of playground to create posts with certain custom post type, and create single post and archive templates for this post type. Also props to @ryanwelcher It's v1 --------- Co-authored-by: Adam Zielinski <[email protected]>
1 parent e2962d9 commit 608e0da

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
3+
"meta": {
4+
"title": "Custom Post Type: Books",
5+
"description": "Blueprint that added a custom post type to playground",
6+
"author": "bph",
7+
"categories": ["Content", "CPT"]
8+
},
9+
"landingPage": "/wp-admin/",
10+
"steps":[
11+
{
12+
"step": "login"
13+
},
14+
{
15+
"step": "mkdir",
16+
"path": "/wordpress/wp-content/plugins/books"
17+
},
18+
{
19+
"step": "writeFile",
20+
"path": "/wordpress/wp-content/plugins/books/books.php",
21+
"data": {
22+
"resource": "url",
23+
"url": "https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/custom-post/books.php"
24+
}
25+
},
26+
{
27+
"step": "activatePlugin",
28+
"pluginPath": "books/books.php"
29+
}
30+
]
31+
}

blueprints/custom-post/books.php

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/*
3+
* Plugin Name: Books
4+
* Plugin URI: https://icodeforapurpose.com
5+
* Description: Create the Book Custom post Type
6+
* Version: 0.1.
7+
* Requires at least: 6.0
8+
* Requires PHP: 7.2
9+
* Author: Birgit Pauli-Haack
10+
* Author URI: https://profiles.wordpress.org/bph
11+
* License: GPL v2 or later
12+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
13+
* Update URI: https://example.com/my-plugin/
14+
* Text Domain: gbt
15+
* Domain Path: /languages
16+
*/
17+
18+
19+
// Register Custom Post Type
20+
function register_books() {
21+
22+
$labels = array(
23+
'name' => _x( 'Books', 'Post Type General Name', 'gbt' ),
24+
'singular_name' => _x( 'Book', 'Post Type Singular Name', 'gbt' ),
25+
'menu_name' => __( 'Books', 'gbt' ),
26+
'name_admin_bar' => __( 'Books', 'gbt' ),
27+
'archives' => __( 'Book Archives', 'gbt' ),
28+
'attributes' => __( 'Book Attributes', 'gbt' ),
29+
'parent_item_colon' => __( 'Parent book', 'gbt' ),
30+
'all_items' => __( 'All Books', 'gbt' ),
31+
'add_new_item' => __( 'Add New Book', 'gbt' ),
32+
'add_new' => __( 'Add New Book', 'gbt' ),
33+
'new_item' => __( 'New Book', 'gbt' ),
34+
'edit_item' => __( 'Edit Book', 'gbt' ),
35+
'update_item' => __( 'Update Book', 'gbt' ),
36+
'view_item' => __( 'View Book', 'gbt' ),
37+
'view_items' => __( 'View Books', 'gbt' ),
38+
'search_items' => __( 'Search Books', 'gbt' ),
39+
'not_found' => __( 'Not found', 'gbt' ),
40+
'not_found_in_trash' => __( 'Not found in Trash', 'gbt' ),
41+
'featured_image' => __( 'Featured Image', 'gbt' ),
42+
'set_featured_image' => __( 'Set featured image', 'gbt' ),
43+
'remove_featured_image' => __( 'Remove featured image', 'gbt' ),
44+
'use_featured_image' => __( 'Use as featured image', 'gbt' ),
45+
'insert_into_item' => __( 'Insert into item', 'gbt' ),
46+
'uploaded_to_this_item' => __( 'Uploaded to this item', 'gbt' ),
47+
'items_list' => __( 'Items list', 'gbt' ),
48+
'items_list_navigation' => __( 'Items list navigation', 'gbt' ),
49+
'filter_items_list' => __( 'Filter items list', 'gbt' ),
50+
);
51+
$args = array(
52+
'label' => __( 'Book', 'gbt' ),
53+
'description' => __( 'Books', 'gbt' ),
54+
'labels' => $labels,
55+
'supports' => array( 'title', 'editor'),
56+
'taxonomies' => array( 'genre', ' publisher' ),
57+
'hierarchical' => false,
58+
'public' => true,
59+
'show_ui' => true,
60+
'show_in_menu' => true,
61+
'menu_position' => 5,
62+
'menu_icon' => 'dashicons-book-alt',
63+
'show_in_admin_bar' => true,
64+
'show_in_nav_menus' => true,
65+
'can_export' => true,
66+
'has_archive' => true,
67+
'exclude_from_search' => false,
68+
'publicly_queryable' => true,
69+
'capability_type' => 'post',
70+
'show_in_rest' => true,
71+
);
72+
register_post_type( 'gbtbooks', $args );
73+
74+
}
75+
add_action( 'init', 'register_books', 0 );

0 commit comments

Comments
 (0)