update
This commit is contained in:
@@ -218,6 +218,16 @@ class Yacht_Booking {
|
||||
YACHT_BOOKING_VERSION
|
||||
);
|
||||
|
||||
// WP color picker on yacht edit form.
|
||||
if ( isset( $_GET['page'] ) && 'yacht-bookings-add-yacht' === $_GET['page'] ) {
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
wp_enqueue_script( 'wp-color-picker' );
|
||||
wp_add_inline_script(
|
||||
'wp-color-picker',
|
||||
'jQuery(function($){ $(".yacht-color-picker").wpColorPicker(); });'
|
||||
);
|
||||
}
|
||||
|
||||
wp_enqueue_script(
|
||||
'yacht-booking-admin',
|
||||
YACHT_BOOKING_PLUGIN_URL . 'admin/assets/js/admin.js',
|
||||
|
||||
@@ -152,4 +152,37 @@ class Yacht {
|
||||
public static function update_features( $yacht_id, $features ) {
|
||||
update_post_meta( $yacht_id, '_yacht_features', is_array( $features ) ? $features : array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get admin-selected yacht color for the aggregated calendar.
|
||||
*
|
||||
* Returns sanitized hex (#rrggbb, lowercase) or '' when not set.
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_color( $yacht_id ) {
|
||||
$value = (string) get_post_meta( $yacht_id, '_yacht_color', true );
|
||||
if ( '' === $value ) {
|
||||
return '';
|
||||
}
|
||||
return preg_match( '/^#[0-9a-f]{6}$/i', $value ) ? strtolower( $value ) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Update yacht color. Empty value removes the meta (fallback to palette).
|
||||
*
|
||||
* @param int $yacht_id Yacht post ID.
|
||||
* @param string $color Hex color (#rrggbb) or empty string.
|
||||
*/
|
||||
public static function update_color( $yacht_id, $color ) {
|
||||
$color = trim( (string) $color );
|
||||
if ( '' === $color ) {
|
||||
delete_post_meta( $yacht_id, '_yacht_color' );
|
||||
return;
|
||||
}
|
||||
if ( preg_match( '/^#[0-9a-f]{6}$/i', $color ) ) {
|
||||
update_post_meta( $yacht_id, '_yacht_color', strtolower( $color ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user