Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Custom_Post_Type {
- public function __construct() {
- add_action('init', array($this, 'my_custom_post_types'));
- add_filter('post_updated_messages',
- array($this, 'my_custom_post_type_messages'));
- add_action('admin_head', array($this, 'my_custom_post_type_help'));
- }
- public function my_custom_post_types() {
- $labels = array(
- 'name' => 'Recipes',
- 'singular_name' => 'Recipe',
- 'menu_name' => 'Recipe',
- 'name_admin_bar' => 'Recipe',
- 'add_new' => 'Add New',
- 'add_new_item' => 'Add New Recipe',
- 'new_item' => 'New Recipe',
- 'edit_item' => 'Edit Recipe',
- 'view_item' => 'View Recipe',
- 'all_items' => 'All Recipes',
- 'search_items' => 'Search Recipes',
- 'parent_item_colon' => 'Parent Recipes:',
- 'not_found' => 'No recipes found.',
- 'not_found_in_trash' => 'No recipes found in Trash.'
- );
- $args = array(
- 'public' => TRUE,
- 'show_ui' => TRUE,
- 'show_in_admin_bar' => TRUE,
- 'labels' => $labels,
- 'description' => 'My yummy recipes will be published using this post type',
- 'menu_icon' => 'dashicons-carrot',
- 'menu_position' => 20,
- 'hierarchical' => TRUE,
- 'taxonomies' => array('post_tag'),
- 'supports' => array('title', 'editor', 'author', 'thumbnail',
- 'excerpt', 'trackbacks', 'custom-fields', 'comments',
- 'revisions', 'page-attributes', 'post-formats'),
- 'rewrite' => array('slug' => 'my_recipe', 'with_front' => false),
- 'has_archive' => TRUE,
- );
- register_post_type('recipe', $args);
- flush_rewrite_rules();
- }
- public function my_custom_post_type_messages($messages) {
- $post = get_post();
- $messages['recipe'] = array(
- 0 => '',
- 1 => 'Recipe updated.',
- 2 => 'Custom field updated.',
- 3 => 'Custom field deleted.',
- 4 => 'Recipe updated.',
- 5 => isset($_GET['revision']) ? sprintf('Recipe restored to revision from %s',
- wp_post_revision_title((int) $_GET['revision'], FALSE)) : FALSE,
- 6 => 'Recipe published.',
- 7 => 'Recipe saved.',
- 8 => 'Recipe submitted.',
- 9 => sprintf('Recipe scheduled for <strong>%1$s</strong>.',
- date_i18n('M j, Y @ G:i', strtotime($post->post_date))),
- 10 => 'Recipe draft updated.'
- );
- return $messages;
- }
- public function my_custom_post_type_help() {
- $screen = get_current_screen();
- if ('recipe' != $screen->post_type) {
- return;
- }
- $basics = array(
- 'id' => 'recipe_basics',
- 'title' => 'Recipe Basics',
- 'content' => 'Content for help tab here - basics',
- );
- $advanced = array(
- 'id' => 'recipe_advanced',
- 'title' => 'Recipe Advanced',
- 'content' => '<strong style="color:red;">Content for help tab here - advanced.</strong>',
- );
- $screen->add_help_tab($basics);
- $screen->add_help_tab($advanced);
- }
- }
- new Custom_Post_Type();
- # BEGIN WordPress
- <IfModule mod_rewrite.c>
- RewriteEngine On
- RewriteBase /wordpress_learn/
- RewriteRule ^index.php$ - [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /wordpress_learn/index.php [L]
- </IfModule>
- # END WordPress
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement