Create Index.php, init .php and activate page
Quote from admin on April 3, 2020, 12:59 pm
ACTIVATE.PHP
<?php
function r_activate_plugin(){
// 4.7 < 4.5 = false
if( version_compare( get_bloginfo( 'version' ), '5.3', '>' ) ){
wp_die( __( 'You must update WordPress to use this plugin', 'recipe' ) );
}
}
INIT.PHP
<?php
function recipe_init(){
$labels = array(
'name' => __( 'Recipes', 'recipe' ),
'singular_name' => __( 'Recipe', 'recipe' ),
'menu_name' => __( 'Recipes', 'recipe' ),
'name_admin_bar' => __( 'Recipe', 'recipe' ),
'add_new' => __( 'Add New', 'recipe' ),
'add_new_item' => __( 'Add New Recipe', 'recipe' ),
'new_item' => __( 'New Recipe', 'recipe' ),
'edit_item' => __( 'Edit Recipe', 'recipe' ),
'view_item' => __( 'View Recipe', 'recipe' ),
'all_items' => __( 'All Recipes', 'recipe' ),
'search_items' => __( 'Search Recipes', 'recipe' ),
'parent_item_colon' => __( 'Parent Recipes:', 'recipe' ),
'not_found' => __( 'No recipes found.', 'recipe' ),
'not_found_in_trash' => __( 'No recipes found in Trash.', 'recipe' )
);$args = array(
'labels' => $labels,
'description' => __( 'A custom post type for recipes.', 'recipe' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'recipe' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 20,
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
'taxonomies' => array( 'category', 'post_tag' )
);register_post_type( 'recipe', $args );
}
INDEX.PHP
<?php
/*
* Plugin Name: Recipe
* Description: A simple WordPress plugin that allows users to create recipes and rate those recipes
* Version: 1.0
* Author: Thava
* Author URI: http://otripanai.com
* Text Domain: recipe
*/if( !function_exists( 'add_action' ) ){
die( "Hi there! I'm just a plugin, not much I can do when called directly." );
}// Setup
// Includes
include( 'includes/activate.php' );
include( 'includes/init.php' );//Hooks
register_activation_hook( __FILE__, 'r_activate_plugin' );
add_action( 'init', 'recipe_init' );//Shortcodes
?>
https://developer.wordpress.org/reference/functions/register_post_type/#uses
/**
* Register a custom post type called "book".
*
* @see get_post_type_labels() for label keys.
*/
function wpdocs_codex_book_init() {
$labels = array(
'name' => _x( 'Books', 'Post type general name', 'textdomain' ),
'singular_name' => _x( 'Book', 'Post type singular name', 'textdomain' ),
'menu_name' => _x( 'Books', 'Admin Menu text', 'textdomain' ),
'name_admin_bar' => _x( 'Book', 'Add New on Toolbar', 'textdomain' ),
'add_new' => __( 'Add New', 'textdomain' ),
'add_new_item' => __( 'Add New Book', 'textdomain' ),
'new_item' => __( 'New Book', 'textdomain' ),
'edit_item' => __( 'Edit Book', 'textdomain' ),
'view_item' => __( 'View Book', 'textdomain' ),
'all_items' => __( 'All Books', 'textdomain' ),
'search_items' => __( 'Search Books', 'textdomain' ),
'parent_item_colon' => __( 'Parent Books:', 'textdomain' ),
'not_found' => __( 'No books found.', 'textdomain' ),
'not_found_in_trash' => __( 'No books found in Trash.', 'textdomain' ),
'featured_image' => _x( 'Book Cover Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'textdomain' ),
'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'textdomain' ),
'remove_featured_image' => _x( 'Remove cover image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'textdomain' ),
'use_featured_image' => _x( 'Use as cover image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'textdomain' ),
'archives' => _x( 'Book archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'textdomain' ),
'insert_into_item' => _x( 'Insert into book', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'textdomain' ),
'uploaded_to_this_item' => _x( 'Uploaded to this book', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'textdomain' ),
'filter_items_list' => _x( 'Filter books list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'textdomain' ),
'items_list_navigation' => _x( 'Books list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'textdomain' ),
'items_list' => _x( 'Books list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'textdomain' ),
);$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'book' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
);register_post_type( 'book', $args );
}add_action( 'init', 'wpdocs_codex_book_init' );
ACTIVATE.PHP
<?php
function r_activate_plugin(){
// 4.7 < 4.5 = false
if( version_compare( get_bloginfo( 'version' ), '5.3', '>' ) ){
wp_die( __( 'You must update WordPress to use this plugin', 'recipe' ) );
}
}
INIT.PHP
<?php
function recipe_init(){
$labels = array(
'name' => __( 'Recipes', 'recipe' ),
'singular_name' => __( 'Recipe', 'recipe' ),
'menu_name' => __( 'Recipes', 'recipe' ),
'name_admin_bar' => __( 'Recipe', 'recipe' ),
'add_new' => __( 'Add New', 'recipe' ),
'add_new_item' => __( 'Add New Recipe', 'recipe' ),
'new_item' => __( 'New Recipe', 'recipe' ),
'edit_item' => __( 'Edit Recipe', 'recipe' ),
'view_item' => __( 'View Recipe', 'recipe' ),
'all_items' => __( 'All Recipes', 'recipe' ),
'search_items' => __( 'Search Recipes', 'recipe' ),
'parent_item_colon' => __( 'Parent Recipes:', 'recipe' ),
'not_found' => __( 'No recipes found.', 'recipe' ),
'not_found_in_trash' => __( 'No recipes found in Trash.', 'recipe' )
);
$args = array(
'labels' => $labels,
'description' => __( 'A custom post type for recipes.', 'recipe' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'recipe' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 20,
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
'taxonomies' => array( 'category', 'post_tag' )
);
register_post_type( 'recipe', $args );
}
INDEX.PHP
<?php
/*
* Plugin Name: Recipe
* Description: A simple WordPress plugin that allows users to create recipes and rate those recipes
* Version: 1.0
* Author: Thava
* Author URI: http://otripanai.com
* Text Domain: recipe
*/
if( !function_exists( 'add_action' ) ){
die( "Hi there! I'm just a plugin, not much I can do when called directly." );
}
// Setup
// Includes
include( 'includes/activate.php' );
include( 'includes/init.php' );
//Hooks
register_activation_hook( __FILE__, 'r_activate_plugin' );
add_action( 'init', 'recipe_init' );
//Shortcodes
?>
https://developer.wordpress.org/reference/functions/register_post_type/#uses
* Register a custom post type called "book".
*
* @see get_post_type_labels() for label keys.
*/
function wpdocs_codex_book_init() {
$labels = array(
'name' => _x( 'Books', 'Post type general name', 'textdomain' ),
'singular_name' => _x( 'Book', 'Post type singular name', 'textdomain' ),
'menu_name' => _x( 'Books', 'Admin Menu text', 'textdomain' ),
'name_admin_bar' => _x( 'Book', 'Add New on Toolbar', 'textdomain' ),
'add_new' => __( 'Add New', 'textdomain' ),
'add_new_item' => __( 'Add New Book', 'textdomain' ),
'new_item' => __( 'New Book', 'textdomain' ),
'edit_item' => __( 'Edit Book', 'textdomain' ),
'view_item' => __( 'View Book', 'textdomain' ),
'all_items' => __( 'All Books', 'textdomain' ),
'search_items' => __( 'Search Books', 'textdomain' ),
'parent_item_colon' => __( 'Parent Books:', 'textdomain' ),
'not_found' => __( 'No books found.', 'textdomain' ),
'not_found_in_trash' => __( 'No books found in Trash.', 'textdomain' ),
'featured_image' => _x( 'Book Cover Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'textdomain' ),
'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'textdomain' ),
'remove_featured_image' => _x( 'Remove cover image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'textdomain' ),
'use_featured_image' => _x( 'Use as cover image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'textdomain' ),
'archives' => _x( 'Book archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'textdomain' ),
'insert_into_item' => _x( 'Insert into book', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'textdomain' ),
'uploaded_to_this_item' => _x( 'Uploaded to this book', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'textdomain' ),
'filter_items_list' => _x( 'Filter books list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'textdomain' ),
'items_list_navigation' => _x( 'Books list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'textdomain' ),
'items_list' => _x( 'Books list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'textdomain' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'book' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
);
register_post_type( 'book', $args );
}
add_action( 'init', 'wpdocs_codex_book_init' );