*/ const DEFAULTS = array( self::CREDIT => false, self::LOAD_ON_CLICK => false, self::JSON_LD => true, self::THEME_STYLES => true, ); /** * Registers the settings, shown in the REST API to users who can manage options. No * option is written and no request is made. */ public static function register(): void { $labels = array( self::CREDIT => __( 'Show “Powered by show.fm”', 'showfm' ), self::LOAD_ON_CLICK => __( 'Load players only after a visitor clicks', 'showfm' ), self::JSON_LD => __( 'Add episode structured data for search engines', 'showfm' ), self::THEME_STYLES => __( 'Use my theme’s colours and fonts', 'showfm' ), ); foreach ( self::DEFAULTS as $name => $default ) { register_setting( 'showfm', $name, array( 'type' => 'boolean', 'default' => $default, 'sanitize_callback' => 'rest_sanitize_boolean', 'description' => $labels[ $name ], 'show_in_rest' => true, ) ); } } /** * A setting's value, or its default when it was never saved. * * @param string $name One of the setting constants. */ public static function enabled( string $name ): bool { return (bool) get_option( $name, self::DEFAULTS[ $name ] ?? false ); } }