first commit
This commit is contained in:
155
wp-content/plugins/yacht-booking-system/includes/class-yacht.php
Normal file
155
wp-content/plugins/yacht-booking-system/includes/class-yacht.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/**
|
||||
* Yacht Custom Post Type
|
||||
*
|
||||
* @package YachtBooking
|
||||
*/
|
||||
|
||||
namespace YachtBooking;
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Yacht CPT class
|
||||
*/
|
||||
class Yacht {
|
||||
|
||||
/**
|
||||
* Register custom post type
|
||||
*/
|
||||
public static function register() {
|
||||
$labels = array(
|
||||
'name' => __( 'Jachty', 'yacht-booking' ),
|
||||
'singular_name' => __( 'Jacht', 'yacht-booking' ),
|
||||
'menu_name' => __( 'Jachty', 'yacht-booking' ),
|
||||
'name_admin_bar' => __( 'Jacht', 'yacht-booking' ),
|
||||
'add_new' => __( 'Dodaj nowy', 'yacht-booking' ),
|
||||
'add_new_item' => __( 'Dodaj nowy jacht', 'yacht-booking' ),
|
||||
'new_item' => __( 'Nowy jacht', 'yacht-booking' ),
|
||||
'edit_item' => __( 'Edytuj jacht', 'yacht-booking' ),
|
||||
'view_item' => __( 'Zobacz jacht', 'yacht-booking' ),
|
||||
'all_items' => __( 'Wszystkie jachty', 'yacht-booking' ),
|
||||
'search_items' => __( 'Szukaj jachtów', 'yacht-booking' ),
|
||||
'parent_item_colon' => __( 'Nadrzędny jacht:', 'yacht-booking' ),
|
||||
'not_found' => __( 'Nie znaleziono jachtów', 'yacht-booking' ),
|
||||
'not_found_in_trash' => __( 'Nie znaleziono jachtów w koszu', 'yacht-booking' ),
|
||||
'featured_image' => __( 'Zdjęcie jachtu', 'yacht-booking' ),
|
||||
'set_featured_image' => __( 'Ustaw zdjęcie jachtu', 'yacht-booking' ),
|
||||
'remove_featured_image' => __( 'Usuń zdjęcie jachtu', 'yacht-booking' ),
|
||||
'use_featured_image' => __( 'Użyj jako zdjęcie jachtu', 'yacht-booking' ),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'labels' => $labels,
|
||||
'description' => __( 'Jachty dostępne do rezerwacji', 'yacht-booking' ),
|
||||
'public' => false,
|
||||
'publicly_queryable' => false,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => false, // Custom menu będzie w class-admin.php
|
||||
'show_in_rest' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => false,
|
||||
'capability_type' => 'post',
|
||||
'capabilities' => array(
|
||||
'edit_post' => 'yacht_booking_manage_yachts',
|
||||
'read_post' => 'yacht_booking_manage_yachts',
|
||||
'delete_post' => 'yacht_booking_manage_yachts',
|
||||
'edit_posts' => 'yacht_booking_manage_yachts',
|
||||
'edit_others_posts' => 'yacht_booking_manage_yachts',
|
||||
'publish_posts' => 'yacht_booking_manage_yachts',
|
||||
'read_private_posts' => 'yacht_booking_manage_yachts',
|
||||
'delete_posts' => 'yacht_booking_manage_yachts',
|
||||
),
|
||||
'has_archive' => false,
|
||||
'hierarchical' => false,
|
||||
'menu_position' => null,
|
||||
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
|
||||
);
|
||||
|
||||
register_post_type( 'yacht', $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get yacht capacity
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @return int
|
||||
*/
|
||||
public static function get_capacity( $yacht_id ) {
|
||||
return (int) get_post_meta( $yacht_id, '_yacht_capacity', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get yacht price per day
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @return float
|
||||
*/
|
||||
public static function get_price_per_day( $yacht_id ) {
|
||||
return (float) get_post_meta( $yacht_id, '_yacht_price_per_day', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get yacht Google Calendar ID
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_gcal_id( $yacht_id ) {
|
||||
return get_post_meta( $yacht_id, '_yacht_gcal_id', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get yacht features
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_features( $yacht_id ) {
|
||||
$features = get_post_meta( $yacht_id, '_yacht_features', true );
|
||||
return is_array( $features ) ? $features : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update yacht capacity
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @param int $capacity Capacity.
|
||||
*/
|
||||
public static function update_capacity( $yacht_id, $capacity ) {
|
||||
update_post_meta( $yacht_id, '_yacht_capacity', (int) $capacity );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update yacht price per day
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @param float $price Price per day.
|
||||
*/
|
||||
public static function update_price_per_day( $yacht_id, $price ) {
|
||||
update_post_meta( $yacht_id, '_yacht_price_per_day', (float) $price );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update yacht Google Calendar ID
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @param string $gcal_id Google Calendar ID.
|
||||
*/
|
||||
public static function update_gcal_id( $yacht_id, $gcal_id ) {
|
||||
update_post_meta( $yacht_id, '_yacht_gcal_id', sanitize_text_field( $gcal_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update yacht features
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @param array $features Features array.
|
||||
*/
|
||||
public static function update_features( $yacht_id, $features ) {
|
||||
update_post_meta( $yacht_id, '_yacht_features', is_array( $features ) ? $features : array() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user