Skip to content

Instantly share code, notes, and snippets.

@exts
Created August 11, 2023 01:50
Show Gist options
  • Save exts/5d07acabc359dc11096064fc149146a9 to your computer and use it in GitHub Desktop.
Save exts/5d07acabc359dc11096064fc149146a9 to your computer and use it in GitHub Desktop.
Custom Wordpress Post Types Plugin Free
<?php
/*
Plugin Name: Beginner Grower: Custom Post Types
Plugin URI: https://beginnergrower.com
Description: Add's a 'articles' post type
Author: Lamonte Harris
Version: 1.0.0
Author URI: https://lamonte.dev
*/
class BeginnerGrowerDotComCustomPostTypes
{
public function createPostTypes()
{
$default_support = [
'title',
'editor',
'author',
'thumbnail',
'excerpt',
'comments',
'custom-fields',
'revisions',
'post-formats',
];
$labels = [
'articles' => [
'name' => _x('Articles', 'plural'),
'singular_name' => _x('Article', 'singular'),
'menu_name' => _x('Articles', 'admin menu'),
'name_admin_bar' => _x('articles', 'admin bar'),
'edit_item' => __('Edit Article'),
'new_item' => __('New Article'),
'view_item' => __('View Article'),
'view_items' => __('View Articles'),
'search_items' => __('Search Articles'),
'add_new_item' => __('Add New Article'),
'not_found' => __('No articles found'),
'all_items' => __('All articles'),
'items_list' => __('Articles list'),
'item_published' => __('Article published'),
]
];
$list = [
'articles' => [
'skip' => ['comments'],
'slug' => 'articles',
],
];
foreach($list as $key => $val) {
$supports = [];
$_skip = $val['skip'] ?? [];
foreach($default_support as $support) {
if(in_array($support, $_skip)) {
continue;
}
$supports[] = $support;
}
register_post_type($val['slug'], [
'supports' => $supports,
'labels' => $labels[$key],
'public' => true,
'query_var' => true,
'rewrite' => ['slug' => $val['slug']],
'has_archive' => true,
'hierarchical' => false,
]);
}
}
}
add_action('init', [new BeginnerGrowerDotComCustomPostTypes(), 'createPostTypes']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment