Skip to content

Newfold Features Settings API

Evan Mullins edited this page Feb 8, 2024 · 2 revisions

Features API

newfold-labs/wp-module-features

  • Do NOT use the module loader
  • This is a straight-up Composer package
  • Expose a register_feature method to add features
  • Will give
  • Feature interactions
    • Some features might be more high-level (e.g. enable/disable caching)
    • Some features are more fine-tuned (e.g. page vs browser caching)
    • High-level features are often going to be in a "simplified" view for basic users
    • Fine-grained features are going to be displayed in an "advanced" view for professionals
    • When checking internally if a feature is enabled, always check the fine-grained option
    • This is essentially "bundling" for features
  • Fetching a registered feature will return an object with methods for authorization, validation, save, edit, delete, get, etc.
  • Callback/filter for
    • Authorization
    • Sanitization/Validation
      • Always return WP_Error if something goes wrong (or throw an exception)
    • Save/Fetch/Delete

Site Capabilities API

  • Move into this features module?

  • We should add a filter to the capabilities for environmental toggling

    • A brand plugin may need to override a capability
      • Example: Plugin disables a feature based on environment (e.g., WP Cloud)
  • Settings should work similarly to the same function in WP (https://developer.wordpress.org/plugins/settings/settings-api/)

    • Settings should be auto-loaded in the data store (for UI purposes only)
    • Register UI type
      • Input field (email, number, etc)
      • Select Field (single vs multi-select)
        • Need a way to provide options
      • Toggle
        • We should always enforce boolean values
      • How do we want to render the name, description/helper text, context (e.g., sub-settings), placeholder text
        • How are error and success messages handled?
      • REST API
        • Uses registered callbacks for a feature
      • WP-CLI
        • Can surface commands based on registered callbacks

Settings we have/might need:

Settings Page

Coming soon toggle

Automatic updates

  • Everything
    • WP Core
    • Plugins
    • Theme

Number of revisions

Number of weeks to empty trash

Disable comments for older posts

  • Close comments after x days

Comments to display per page

Performance page

Enable/disable types of caching

  • Caching level
    • Disabled
    • Assets Only
    • Assets & Web pages
    • Assets & Web page - extended