Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Custom Post Type
- //==========================================================================================
- // Community Posts =============================================================================
- //==========================================================================================
- function cws_register_community_post() {
- $labels = array(
- 'name' => _x( 'Community Posts', 'post type general name', 'cws' ),
- 'singular_name' => _x( 'Community Post', 'post type singular name', 'cws' ),
- 'add_new' => _x( 'Add New', 'community_post', 'cws' ),
- 'add_new_item' => __( 'Add New Community Post', 'cws' ),
- 'edit_item' => __( 'Edit Community Post', 'cws' ),
- 'new_item' => __( 'New Community Post', 'cws' ),
- 'all_items' => __( 'Community Posts', 'cws' ),
- 'view_item' => __( 'View Community Post', 'cws' ),
- 'search_items' => __( 'Search Community Posts', 'cws' ),
- 'not_found' => __( 'No Community Posts found', 'cws' ),
- 'not_found_in_trash' => __( 'No Community Posts found in the trash', 'cws' ),
- 'parent_item_colon' => '',
- 'menu_name' => 'Community Posts'
- );
- $args = array(
- 'labels' => $labels,
- 'description' => __( 'All Community Posts.', 'cws' ),
- 'public' => true,
- 'menu_position' => 25,
- // here
- 'show_in_menu' => true,
- //'show_in_menu' => 'community-menu',
- // 'hierarchical' => true,
- 'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' ),
- 'has_archive' => false,
- // here
- 'taxonomies' => array( 'community-menu' ),
- 'rewrite' => array(
- 'slug' => 'community/%community_post_domain%',
- // here
- 'with_front' => true
- ),
- 'capability_type' => 'community_post',
- 'capabilities' => array(
- 'read_post' => 'read_community_posts',
- 'edit_post' => 'edit_community_posts',
- 'delete_post' => 'delete_community_posts',
- ),
- );
- register_post_type( 'community_post', $args );
- }
- add_action( 'init', 'cws_register_community_post' );
- // Taxonomies
- //==========================================================================================
- // Community Post Type & Domain =============================================================
- //==========================================================================================
- function create_community_post_taxonomies() {
- $domainArgs = array(
- 'show_ui' => true,
- 'hierarchical' => true,
- 'show_in_menu' => 'community-menu',
- 'show_admin_column' => true,
- 'labels' => array(
- 'name' => _x( 'Community Post Domains', 'taxonomy general name', 'cws' ),
- 'singular_name' => _x( 'Community Post Domain', 'taxonomy singular name', 'cws' ),
- 'add_new_item' => __( 'Add New Community Post Domain', 'cws' ),
- 'new_item_name' => __( 'New Community Post Domain', 'cws' ),
- ),
- // here: Remove capabilities
- //'capabilities' => array(
- // 'manage_terms' => 'edit_community_posts',
- // 'edit_terms' => 'edit_community_posts',
- // 'delete_terms' => 'edit_community_posts',
- // 'assign_terms' => 'edit_community_posts',
- //),
- );
- $typeArgs = array(
- 'show_ui' => true,
- 'hierarchical' => true,
- 'show_in_menu' => 'community-menu',
- 'show_admin_column' => true,
- 'labels' => array(
- 'name' => _x( 'Community Post Types', 'taxonomy general name', 'cws' ),
- 'singular_name' => _x( 'Community Post Type', 'taxonomy singular name', 'cws' ),
- 'add_new_item' => __( 'Add New Community Post Type', 'cws' ),
- 'new_item_name' => __( 'New Community Post Type', 'cws' ),
- ),
- // here: Remove capabilities
- //'capabilities' => array(
- // 'manage_terms' => 'edit_community_posts',
- // 'edit_terms' => 'edit_community_posts',
- // 'delete_terms' => 'edit_community_posts',
- // 'assign_terms' => 'edit_community_posts',
- //),
- 'rewrite' => array(
- 'slug' => 'community',
- // here
- 'with_front' => true,
- 'hierarchical' => false,
- ),
- );
- register_taxonomy( 'community_post_type', 'community_post', $typeArgs );
- register_taxonomy( 'community_post_domain', 'community_post', $domainArgs );
- }
- add_action( 'init', 'create_community_post_taxonomies' );
- /**
- * here
- * Fix permalinks structure with post_type_link
- */
- add_filter('post_type_link', 'so_update_permalink_structure', 10, 2);
- function so_update_permalink_structure( $post_link, $post )
- {
- if ( false !== strpos( $post_link, '%community_post_domain%' ) ) {
- $taxonomy_terms = get_the_terms( $post->ID, 'community_post_domain' );
- foreach ( $taxonomy_terms as $term ) {
- if ( ! $term->parent ) {
- $post_link = str_replace( '%community_post_domain%', $term->slug, $post_link );
- }
- }
- }
- return $post_link;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement