update
This commit is contained in:
@@ -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