Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. <?php
  2.  
  3. class Custom_Post_Type {
  4.  
  5. public function __construct() {
  6. add_action('init', array($this, 'my_custom_post_types'));
  7. add_filter('post_updated_messages',
  8. array($this, 'my_custom_post_type_messages'));
  9. add_action('admin_head', array($this, 'my_custom_post_type_help'));
  10. }
  11.  
  12. public function my_custom_post_types() {
  13. $labels = array(
  14. 'name' => 'Recipes',
  15. 'singular_name' => 'Recipe',
  16. 'menu_name' => 'Recipe',
  17. 'name_admin_bar' => 'Recipe',
  18. 'add_new' => 'Add New',
  19. 'add_new_item' => 'Add New Recipe',
  20. 'new_item' => 'New Recipe',
  21. 'edit_item' => 'Edit Recipe',
  22. 'view_item' => 'View Recipe',
  23. 'all_items' => 'All Recipes',
  24. 'search_items' => 'Search Recipes',
  25. 'parent_item_colon' => 'Parent Recipes:',
  26. 'not_found' => 'No recipes found.',
  27. 'not_found_in_trash' => 'No recipes found in Trash.'
  28. );
  29. $args = array(
  30. 'public' => TRUE,
  31. 'show_ui' => TRUE,
  32. 'show_in_admin_bar' => TRUE,
  33. 'labels' => $labels,
  34. 'description' => 'My yummy recipes will be published using this post type',
  35. 'menu_icon' => 'dashicons-carrot',
  36. 'menu_position' => 20,
  37. 'hierarchical' => TRUE,
  38. 'taxonomies' => array('post_tag'),
  39. 'supports' => array('title', 'editor', 'author', 'thumbnail',
  40. 'excerpt', 'trackbacks', 'custom-fields', 'comments',
  41. 'revisions', 'page-attributes', 'post-formats'),
  42. 'rewrite' => array('slug' => 'my_recipe', 'with_front' => false),
  43. 'has_archive' => TRUE,
  44. );
  45. register_post_type('recipe', $args);
  46. flush_rewrite_rules();
  47. }
  48.  
  49. public function my_custom_post_type_messages($messages) {
  50. $post = get_post();
  51.  
  52. $messages['recipe'] = array(
  53. 0 => '',
  54. 1 => 'Recipe updated.',
  55. 2 => 'Custom field updated.',
  56. 3 => 'Custom field deleted.',
  57. 4 => 'Recipe updated.',
  58. 5 => isset($_GET['revision']) ? sprintf('Recipe restored to revision from %s',
  59. wp_post_revision_title((int) $_GET['revision'], FALSE)) : FALSE,
  60. 6 => 'Recipe published.',
  61. 7 => 'Recipe saved.',
  62. 8 => 'Recipe submitted.',
  63. 9 => sprintf('Recipe scheduled for <strong>%1$s</strong>.',
  64. date_i18n('M j, Y @ G:i', strtotime($post->post_date))),
  65. 10 => 'Recipe draft updated.'
  66. );
  67.  
  68. return $messages;
  69. }
  70.  
  71. public function my_custom_post_type_help() {
  72. $screen = get_current_screen();
  73.  
  74. if ('recipe' != $screen->post_type) {
  75. return;
  76. }
  77.  
  78. $basics = array(
  79. 'id' => 'recipe_basics',
  80. 'title' => 'Recipe Basics',
  81. 'content' => 'Content for help tab here - basics',
  82. );
  83.  
  84. $advanced = array(
  85. 'id' => 'recipe_advanced',
  86. 'title' => 'Recipe Advanced',
  87. 'content' => '<strong style="color:red;">Content for help tab here - advanced.</strong>',
  88. );
  89.  
  90. $screen->add_help_tab($basics);
  91. $screen->add_help_tab($advanced);
  92. }
  93.  
  94. }
  95.  
  96. new Custom_Post_Type();
  97.  
  98. # BEGIN WordPress
  99. <IfModule mod_rewrite.c>
  100. RewriteEngine On
  101. RewriteBase /wordpress_learn/
  102. RewriteRule ^index.php$ - [L]
  103. RewriteCond %{REQUEST_FILENAME} !-f
  104. RewriteCond %{REQUEST_FILENAME} !-d
  105. RewriteRule . /wordpress_learn/index.php [L]
  106. </IfModule>
  107.  
  108. # END WordPress
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement