From f9588dd2c7fe3b23d63467474c7c4fe0a41be934 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 27 Nov 2018 13:08:01 -0500 Subject: [PATCH] initial commit --- glm-rooms.php | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 glm-rooms.php diff --git a/glm-rooms.php b/glm-rooms.php new file mode 100644 index 0000000..9f44b40 --- /dev/null +++ b/glm-rooms.php @@ -0,0 +1,241 @@ + _x( GLM_ROOM_PLURAL, 'Post Type General Name' ), + 'singular_name' => _x( GLM_ROOM_SINGLE, 'Post Type Singular Name' ), + 'menu_name' => __( GLM_ROOM_PLURAL ), + 'name_admin_bar' => __( GLM_ROOM_PLURAL ), + 'archives' => __( GLM_ROOM_SINGLE . ' Archives' ), + 'parent_item_colon' => __( 'Parent Room:' ), + 'all_items' => __( 'All Rooms' ), + 'add_new_item' => __( 'Add New Room' ), + 'add_new' => __( 'Add New Room' ), + 'new_item' => __( 'New Room' ), + 'edit_item' => __( 'Edit Room' ), + 'update_item' => __( 'Update Room' ), + 'view_item' => __( 'View Room' ), + 'search_items' => __( 'Search Room' ), + 'not_found' => __( 'Not found' ), + 'not_found_in_trash' => __( 'Not found in Trash' ), + 'featured_image' => __( 'Featured Image' ), + 'set_featured_image' => __( 'Set featured image' ), + 'remove_featured_image' => __( 'Remove featured image' ), + 'use_featured_image' => __( 'Use as featured image' ), + 'insert_into_item' => __( 'Insert into item' ), + 'uploaded_to_this_item' => __( 'Uploaded to this item' ), + 'items_list' => __( 'Rooms list' ), + 'items_list_navigation' => __( 'Rooms list navigation' ), + 'filter_items_list' => __( 'Filter items list' ), + ); + + $rewrite = array( + 'slug' => GLM_ROOM_POST_TYPE , + 'with_front' => false, + 'pages' => false, + 'feeds' => false, + ); + + $args = array( + 'label' => __( GLM_ROOM_SINGLE ), + 'description' => __( 'Custom ' . GLM_ROOM_PLURAL ), + 'labels' => $labels, + 'supports' => array( 'title', 'thumbnail', 'revisions', 'editor', 'page-attributes'), + 'hierarchical' => true, + 'public' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_position' => 5, + 'menu_icon' => 'dashicons-building', + 'show_in_admin_bar' => true, + 'show_in_nav_menus' => true, + 'can_export' => true, + 'has_archive' => true, + 'exclude_from_search' => false, + 'publicly_queryable' => true, + 'rewrite' => $rewrite, + 'capability_type' => 'page' + ); + + register_post_type( GLM_ROOM_POST_TYPE , $args ); + register_taxonomy_for_object_type( GLM_ROOM_CATEGORY_NAME, GLM_ROOM_POST_TYPE ); +} + + +/** + * rooms_taxonomies + * + * Setup of the Taxonomies for the post type + * + * @access public + * @return void + */ +function rooms_taxonomies() { + + // Experiences + $labels = array( + 'name' => _x( GLM_ROOM_CATEGORY_NAME, 'taxonomy general name' ), + 'singular_name' => _x( GLM_ROOM_CATEGORY_NAME, 'taxonomy singular name' ), + 'search_items' => __( 'Search ' . GLM_ROOM_CATEGORY_PLURAL ), + 'all_items' => __( 'All ' . GLM_ROOM_CATEGORY_PLURAL ), + 'parent_item' => __( 'Parent ' . GLM_ROOM_CATEGORY_SINGLE ), + 'parent_item_colon' => __( 'Parent ' . GLM_ROOM_CATEGORY_SINGLE ), + 'edit_item' => __( 'Edit ' . GLM_ROOM_CATEGORY_SINGLE ), + 'update_item' => __( 'Update ' . GLM_ROOM_CATEGORY_SINGLE ), + 'add_new_item' => __( 'Add New ' . GLM_ROOM_CATEGORY_SINGLE ), + 'new_item_name' => __( 'New ' . GLM_ROOM_CATEGORY_SINGLE . ' Name' ), + 'menu_name' => __( 'Site ' . GLM_ROOM_CATEGORY_SINGLE ), + ); + + $capabilities = array( + 'manage_terms' => 'manage_categories', + 'edit_terms' => 'manage_categories', + 'delete_terms' => 'manage_categories', + 'assign_terms' => 'edit_posts', + ); + + $args = array( + 'label' => __( GLM_ROOM_CATEGORY_PLURAL ), + 'rewrite' => array( 'slug' => GLM_ROOM_CATEGORY_SLUG ), + 'capabilities' => $capabilities, + 'public ' => true, + 'show_in_quick_edit' => true, + 'show_in_admin_column' => true, + 'hierarchical' => true + ); + + register_taxonomy( + GLM_ROOM_CATEGORY_NAME, + GLM_ROOM_POST_TYPE , + $args + ); +} + +/** + * rooms_taxonomy_filter_restrict_manage_posts + * + * This will setup the Filter for the Custom taxonomies. + * + * @access public + * @return void + */ +function rooms_taxonomy_filter_restrict_manage_posts() { + global $typenow; + + $post_types = get_post_types( array( '_builtin' => false ) ); + + if ( in_array( $typenow, $post_types ) ) { + $filters = get_object_taxonomies( $typenow ); + + foreach ( $filters as $tax_slug ) { + $tax_obj = get_taxonomy( $tax_slug ); + wp_dropdown_categories( array( + 'show_option_all' => __( 'Show All ' . $tax_obj->label ), + 'taxonomy' => $tax_slug, + 'name' => $tax_obj->name, + 'orderby' => 'menu_order', + 'selected' => ( isset( $_GET[$tax_slug] ) ), + 'hierarchical' => $tax_obj->hierarchical, + 'show_count' => false, + 'hide_empty' => true, + ) ); + } + } +} + +add_action( 'restrict_manage_posts', 'rooms_taxonomy_filter_restrict_manage_posts' ); + +/** + * Rooms_taxonomy_filter_post_type_request + * + * Filter the post request for the Taxonomy Filter + * + * @param mixed $query + * @access public + * @return void + */ +function rooms_taxonomy_filter_post_type_request( $query ) { + global $pagenow, $typenow; + + if ( 'edit.php' === $pagenow ) { + $filters = get_object_taxonomies( $typenow ); + foreach ( $filters as $tax_slug ) { + $var = &$query->query_vars[ $tax_slug ]; + + if ( isset( $var ) ) { + $term = get_term_by( 'id', $var, $tax_slug ); + + $var = $term->slug; + } + } + } +} +add_filter( 'parse_query', 'rooms_taxonomy_filter_post_type_request' ); +add_action( 'init', 'rooms_custom_post_type' ); +add_action( 'init', 'rooms_taxonomies' ); + + +/** + * Rooms_set_admin_columns + * + * Setup of the list columns + * + * @access public + * @return void + */ +function rooms_set_admin_columns() { + add_filter( 'manage_edit-rooms_columns', 'rooms_admin_edit_columns' ); + add_action( 'manage_rooms_posts_custom_column', 'rooms_admin_custom_columns' ); +} + +add_action( 'admin_init', 'rooms_set_admin_columns' ); + +/** + * Rooms_admin_edit_columns + * + * Setup of the edit columns. This will create the headers for each column. + * + * @param mixed $columns + * @access public + * @return void + */ +function rooms_admin_edit_columns( $columns ) { + $columns = array( + 'cb' => '', + 'title' => GLM_ROOM_SINGLE . ' Title', + 'rooms_col_cat' => GLM_ROOM_CATEGORY_SINGLE, + ); + return $columns; +} \ No newline at end of file -- 2.17.1