Skip to content

Commit bb2ccd9

Browse files
committed
Add post_type_supports helper to check feature support
Add a `supports` method to `PostTypeSupportsMap` for Rust usage and a `post_type_supports` free function for FFI clients to check if a post type supports a specific feature by key presence. Includes documentation explaining the assumption that key presence implies support, regardless of the associated value.
1 parent d30f9c7 commit bb2ccd9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

wp_api/src/post_types.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ pub struct PostTypeSupportsMap {
101101
pub map: HashMap<PostTypeSupports, Arc<PostTypeSupportsValue>>,
102102
}
103103

104+
impl PostTypeSupportsMap {
105+
/// Check if the post type supports a specific feature by checking if the key is present.
106+
///
107+
/// Note: This only checks for key presence, not the associated value. WordPress typically
108+
/// includes a feature in the map with a `true` value when supported, and omits it entirely
109+
/// when not supported. The value can also be an object with additional configuration (e.g.,
110+
/// `editor` may have nested settings). We assume that if a key is present, the feature is
111+
/// supported, regardless of the actual value.
112+
pub fn supports(&self, feature: &PostTypeSupports) -> bool {
113+
self.map.contains_key(feature)
114+
}
115+
}
116+
117+
/// Check if a post type supports a specific feature by checking if the key is present.
118+
///
119+
/// Note: This only checks for key presence, not the associated value. See
120+
/// `PostTypeSupportsMap::supports` for details on this assumption.
121+
#[uniffi::export]
122+
fn post_type_supports(supports_map: &PostTypeSupportsMap, feature: PostTypeSupports) -> bool {
123+
supports_map.supports(&feature)
124+
}
125+
104126
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, uniffi::Object)]
105127
#[serde(transparent)]
106128
pub struct PostTypeSupportsValue {

0 commit comments

Comments
 (0)