_x( 'Rooms', 'post type general name', 'wp-bnb' ), 'singular_name' => _x( 'Room', 'post type singular name', 'wp-bnb' ), 'menu_name' => _x( 'Rooms', 'admin menu', 'wp-bnb' ), 'name_admin_bar' => _x( 'Room', 'add new on admin bar', 'wp-bnb' ), 'add_new' => _x( 'Add New', 'room', 'wp-bnb' ), 'add_new_item' => __( 'Add New Room', 'wp-bnb' ), 'new_item' => __( 'New Room', 'wp-bnb' ), 'edit_item' => __( 'Edit Room', 'wp-bnb' ), 'view_item' => __( 'View Room', 'wp-bnb' ), 'all_items' => __( 'Rooms', 'wp-bnb' ), 'search_items' => __( 'Search Rooms', 'wp-bnb' ), 'parent_item_colon' => __( 'Parent Rooms:', 'wp-bnb' ), 'not_found' => __( 'No rooms found.', 'wp-bnb' ), 'not_found_in_trash' => __( 'No rooms found in Trash.', 'wp-bnb' ), 'featured_image' => __( 'Room Image', 'wp-bnb' ), 'set_featured_image' => __( 'Set room image', 'wp-bnb' ), 'remove_featured_image' => __( 'Remove room image', 'wp-bnb' ), 'use_featured_image' => __( 'Use as room image', 'wp-bnb' ), 'archives' => __( 'Room archives', 'wp-bnb' ), 'insert_into_item' => __( 'Insert into room', 'wp-bnb' ), 'uploaded_to_this_item' => __( 'Uploaded to this room', 'wp-bnb' ), 'filter_items_list' => __( 'Filter rooms list', 'wp-bnb' ), 'items_list_navigation' => __( 'Rooms list navigation', 'wp-bnb' ), 'items_list' => __( 'Rooms list', 'wp-bnb' ), ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => 'wp-bnb', 'query_var' => true, 'rewrite' => array( 'slug' => 'room', 'with_front' => false, ), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'menu_icon' => 'dashicons-admin-home', 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', ), 'show_in_rest' => true, 'rest_base' => 'rooms', 'rest_controller_class' => 'WP_REST_Posts_Controller', 'taxonomies' => array( RoomType::TAXONOMY, Amenity::TAXONOMY ), ); register_post_type( self::POST_TYPE, $args ); } /** * Add meta boxes. * * @return void */ public static function add_meta_boxes(): void { add_meta_box( 'bnb_room_building', __( 'Building', 'wp-bnb' ), array( self::class, 'render_building_meta_box' ), self::POST_TYPE, 'side', 'high' ); add_meta_box( 'bnb_room_details', __( 'Room Details', 'wp-bnb' ), array( self::class, 'render_details_meta_box' ), self::POST_TYPE, 'normal', 'high' ); add_meta_box( 'bnb_room_gallery', __( 'Room Gallery', 'wp-bnb' ), array( self::class, 'render_gallery_meta_box' ), self::POST_TYPE, 'normal', 'default' ); add_meta_box( 'bnb_room_pricing', __( 'Room Pricing', 'wp-bnb' ), array( self::class, 'render_pricing_meta_box' ), self::POST_TYPE, 'normal', 'high' ); } /** * Render building selection meta box. * * @param \WP_Post $post Current post object. * @return void */ public static function render_building_meta_box( \WP_Post $post ): void { wp_nonce_field( 'bnb_room_meta', 'bnb_room_meta_nonce' ); $building_id = get_post_meta( $post->ID, self::META_PREFIX . 'building_id', true ); $buildings = get_posts( array( 'post_type' => Building::POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ) ); ?>
' . esc_html__( 'Add a building', 'wp-bnb' ) . '' ); ?>
ID, self::META_PREFIX . 'room_number', true ); $floor = get_post_meta( $post->ID, self::META_PREFIX . 'floor', true ); $capacity = get_post_meta( $post->ID, self::META_PREFIX . 'capacity', true ); $max_adults = get_post_meta( $post->ID, self::META_PREFIX . 'max_adults', true ); $max_children = get_post_meta( $post->ID, self::META_PREFIX . 'max_children', true ); $size = get_post_meta( $post->ID, self::META_PREFIX . 'size', true ); $beds = get_post_meta( $post->ID, self::META_PREFIX . 'beds', true ); $bathrooms = get_post_meta( $post->ID, self::META_PREFIX . 'bathrooms', true ); $status = get_post_meta( $post->ID, self::META_PREFIX . 'status', true ); ?>|
|
|
|
unit() ); ?>
|
|
|
|
|
' . esc_html__( 'Pricing Settings', 'wp-bnb' ) . '' ); ?>
value; if ( isset( $_POST[ $key ] ) && '' !== $_POST[ $key ] ) { $pricing_data[ $tier->value ] = floatval( $_POST[ $key ] ); } } if ( isset( $_POST['bnb_room_price_weekend_surcharge'] ) ) { $pricing_data['weekend_surcharge'] = floatval( $_POST['bnb_room_price_weekend_surcharge'] ); } if ( ! empty( $pricing_data ) ) { Calculator::saveRoomPricing( $post_id, $pricing_data ); } } /** * Add custom columns to the post list. * * @param array $columns Existing columns. * @return array */ public static function add_columns( array $columns ): array { $new_columns = array(); foreach ( $columns as $key => $value ) { if ( 'taxonomy-bnb_room_type' === $key ) { continue; // Will add after title. } if ( 'taxonomy-bnb_amenity' === $key ) { continue; // Will add after room type. } $new_columns[ $key ] = $value; if ( 'title' === $key ) { $new_columns['building'] = __( 'Building', 'wp-bnb' ); $new_columns['room_number'] = __( 'Room #', 'wp-bnb' ); $new_columns['taxonomy-bnb_room_type'] = __( 'Room Type', 'wp-bnb' ); $new_columns['capacity'] = __( 'Capacity', 'wp-bnb' ); $new_columns['price'] = __( 'Price/Night', 'wp-bnb' ); $new_columns['status'] = __( 'Status', 'wp-bnb' ); } } return $new_columns; } /** * Render custom column content. * * @param string $column Column name. * @param int $post_id Post ID. * @return void */ public static function render_column( string $column, int $post_id ): void { switch ( $column ) { case 'building': $building_id = get_post_meta( $post_id, self::META_PREFIX . 'building_id', true ); if ( $building_id ) { $building = get_post( $building_id ); if ( $building ) { printf( '%s', esc_url( get_edit_post_link( $building_id ) ), esc_html( $building->post_title ) ); } else { echo '—'; } } else { echo '—'; } break; case 'room_number': $room_number = get_post_meta( $post_id, self::META_PREFIX . 'room_number', true ); echo esc_html( $room_number ?: '—' ); break; case 'capacity': $capacity = get_post_meta( $post_id, self::META_PREFIX . 'capacity', true ); if ( $capacity ) { printf( ' %s', esc_html( $capacity ) ); } else { echo '—'; } break; case 'price': $pricing = Calculator::getRoomPricing( $post_id ); $nightly = $pricing[ PricingTier::SHORT_TERM->value ]['price'] ?? null; if ( $nightly ) { echo esc_html( Calculator::formatPrice( $nightly ) ); } else { echo '' . esc_html__( 'Not set', 'wp-bnb' ) . ''; } break; case 'status': $status = get_post_meta( $post_id, self::META_PREFIX . 'status', true ) ?: 'available'; $statuses = self::get_room_statuses(); $colors = self::get_status_colors(); ?> Building::POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ) ); if ( empty( $buildings ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Filter display only. $selected = isset( $_GET['building_id'] ) ? absint( $_GET['building_id'] ) : 0; ?> is_main_query() ) { return; } if ( self::POST_TYPE !== $query->get( 'post_type' ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Filter query only. if ( ! empty( $_GET['building_id'] ) ) { $query->set( 'meta_query', array( array( 'key' => self::META_PREFIX . 'building_id', 'value' => absint( $_GET['building_id'] ), ), ) ); } } /** * Change title placeholder. * * @param string $placeholder Default placeholder. * @param \WP_Post $post Current post. * @return string */ public static function change_title_placeholder( string $placeholder, \WP_Post $post ): string { if ( self::POST_TYPE === $post->post_type ) { return __( 'Enter room name', 'wp-bnb' ); } return $placeholder; } /** * Get room status options. * * @return array