Last active
December 26, 2015 23:59
-
-
Save purzlbaum/7234936 to your computer and use it in GitHub Desktop.
Custom Post Type Blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists('custom_post_type_blog') ) { | |
// Register Custom Post Type | |
function custom_post_type_blog() { | |
$labels = array( | |
'name' => _x( 'Blogs', 'Post Type General Name', '' ), | |
'singular_name' => _x( 'Blog', 'Post Type Singular Name', '' ), | |
'menu_name' => __( 'Blog', '' ), | |
'parent_item_colon' => __( '', '' ), | |
'all_items' => __( 'Alle Blogeinträge', '' ), | |
'view_item' => __( 'Blogeinträge ansehen', '' ), | |
'add_new_item' => __( 'Neuen Blogeintrag hinzufügen', '' ), | |
'add_new' => __( 'Neuer Blogeintrag', '' ), | |
'edit_item' => __( 'Blogeintrag editieren', '' ), | |
'update_item' => __( 'Blogeintrag updaten', '' ), | |
'search_items' => __( 'Blogeinträge durchsuchen', '' ), | |
'not_found' => __( 'Kein Eintrag gefunden', '' ), | |
'not_found_in_trash' => __( 'Kein Eintrag im Papierkorb.', '' ), | |
); | |
$rewrite = array( | |
'slug' => 'blog', | |
'with_front' => true, | |
'pages' => true, | |
'feeds' => true, | |
); | |
$capabilities = array( | |
'read' => 'read_blogposts', | |
'read_post' => 'read_blog', | |
'delete_posts' => 'delete_blog', | |
'delete_published_post' => 'delete_published_blog', | |
'edit_posts' => 'edit_blog', | |
'edit_others_posts' => 'edit_others_blog', | |
'edit_published_post' => 'edit_published_blog', | |
'upload_files' => 'upload_files_blog', | |
); | |
$args = array( | |
'label' => __( 'blog', '' ), | |
'description' => __( 'Blog Beiträge', '' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', ), | |
'taxonomies' => array( 'category', 'blog_category' ), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'show_in_admin_bar' => true, | |
'menu_position' => 5, | |
'menu_icon' => get_stylesheet_directory_uri() . '/img/custom-post-type/blog.png', | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'query_var' => 'blog', | |
'rewrite' => $rewrite, | |
'capabilities' => $capabilities, | |
'capability_type' => 'blogger', | |
'map_meta_cap' => true, | |
); | |
register_post_type( 'blog', $args ); | |
} | |
// Hook into the 'init' action | |
add_action( 'init', 'custom_post_type_blog', 0 ); | |
} | |
if ( ! function_exists('blog_taxonomy') ) { | |
// Register Custom Taxonomy | |
function blog_taxonomy() { | |
$labels = array( | |
'name' => _x( 'Blog Kategorien', 'Taxonomy General Name', '' ), | |
'singular_name' => _x( 'Blog Kategorie', 'Taxonomy Singular Name', '' ), | |
'menu_name' => __( 'Blog Kategorie', '' ), | |
'all_items' => __( 'Alle Blog Kategorien', '' ), | |
'parent_item' => __( 'Übergeordnete Kategorie', '' ), | |
'parent_item_colon' => __( 'Übergeordnete Kategorie', '' ), | |
'new_item_name' => __( 'Neue Blog Kategorie', '' ), | |
'add_new_item' => __( 'Neue Blog Kategorie hinzufügen', '' ), | |
'edit_item' => __( 'Blog Kategorie editieren', '' ), | |
'update_item' => __( 'Blog Kategorie updaten', '' ), | |
'separate_items_with_commas' => __( 'Kategorien mit Kommas trennen', '' ), | |
'search_items' => __( 'Blog Kategorien durchsuchen', '' ), | |
'add_or_remove_items' => __( 'Blog Kategorien hinzufügen oder entfernen', '' ), | |
'choose_from_most_used' => __( 'Aus den meistbenutzten Kategorien auswählen', '' ), | |
); | |
$rewrite = array( | |
'slug' => 'blogcategory', | |
'with_front' => true, | |
'hierarchical' => true, | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
'query_var' => 'blog_category', | |
'rewrite' => $rewrite, | |
); | |
register_taxonomy( 'blog_category', 'blog', $args ); | |
} | |
// Hook into the 'init' action | |
add_action( 'init', 'blog_taxonomy', 0 ); | |
function blogger_role_setup() { | |
add_role( | |
'blogger', 'Blogger', array( | |
'read_blogposts' => true, | |
'read_blog' => true, | |
'delete_blog' => true, | |
'delete_published_blog' => true, | |
'edit_blog' => true, | |
'edit_others_blog' => false, | |
'edit_published_blog' => true, | |
'upload_files_blog' => true, | |
) | |
); | |
} | |
add_action( 'after_setup_theme', 'blogger_role_setup' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment