'string', 'default' => '', 'sanitize_callback' => [ self::class, 'sanitize_api_key' ], ] ); register_setting( Tabs::SETTINGS_GROUP_AUTHENTICATION, self::OPTION_PROJECT_ID, [ 'type' => 'string', 'default' => '', 'sanitize_callback' => [ self::class, 'sanitize_project_id' ], ] ); add_settings_field( 'beyondwords-api-key', __( 'API key', 'speechkit' ), [ self::class, 'render_api_key' ], Tabs::PAGE_AUTHENTICATION, Tabs::SECTION_AUTHENTICATION ); add_settings_field( 'beyondwords-project-id', __( 'Project ID', 'speechkit' ), [ self::class, 'render_project_id' ], Tabs::PAGE_AUTHENTICATION, Tabs::SECTION_AUTHENTICATION ); } /** * Register the integration method field for the Integration tab. */ public static function register_integration_fields(): void { register_setting( Tabs::SETTINGS_GROUP_INTEGRATION, self::OPTION_INTEGRATION_METHOD, [ 'type' => 'string', 'default' => self::INTEGRATION_REST_API, 'sanitize_callback' => [ self::class, 'sanitize_integration_method' ], ] ); add_settings_field( 'beyondwords-integration-method', __( 'Integration method', 'speechkit' ), [ self::class, 'render_integration_method' ], Tabs::PAGE_INTEGRATION, Tabs::SECTION_INTEGRATION ); } /** * Register the per-site preferences (excerpt, player UI). * * Preselect lives in its own class: post-type-aware logic plus a JS asset. */ public static function register_preferences_fields(): void { register_setting( Tabs::SETTINGS_GROUP_PREFERENCES, self::OPTION_PREPEND_EXCERPT, [ 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean', ] ); add_filter( 'option_' . self::OPTION_PREPEND_EXCERPT, 'rest_sanitize_boolean' ); register_setting( Tabs::SETTINGS_GROUP_PREFERENCES, self::OPTION_PLAYER_UI, [ 'type' => 'string', 'default' => self::PLAYER_UI_ENABLED, 'sanitize_callback' => [ self::class, 'sanitize_player_ui' ], ] ); add_settings_field( 'beyondwords-include-excerpt', __( 'Excerpt', 'speechkit' ), [ self::class, 'render_prepend_excerpt' ], Tabs::PAGE_PREFERENCES, Tabs::SECTION_PREFERENCES ); add_settings_field( 'beyondwords-player-ui', __( 'Player UI', 'speechkit' ), [ self::class, 'render_player_ui' ], Tabs::PAGE_PREFERENCES, Tabs::SECTION_PREFERENCES ); } /** * Sanitisers * ------------------------------------------------------------------ */ public static function sanitize_api_key( $value ) { $value = sanitize_text_field( (string) $value ); if ( '' === $value ) { Utils::add_settings_error_message( __( 'Please enter the BeyondWords API key. This can be found in your project settings.', 'speechkit' ), 'Settings/ApiKey' ); } return $value; } public static function sanitize_project_id( $value ) { $value = sanitize_text_field( (string) $value ); if ( '' === $value ) { Utils::add_settings_error_message( __( 'Please enter your BeyondWords project ID. This can be found in your project settings.', 'speechkit' ), 'Settings/ProjectId' ); } return $value; } public static function sanitize_integration_method( $value ): string { $value = is_string( $value ) ? $value : ''; return in_array( $value, [ self::INTEGRATION_REST_API, self::INTEGRATION_CLIENT_SIDE ], true ) ? $value : self::INTEGRATION_REST_API; } public static function sanitize_player_ui( $value ): string { $value = is_string( $value ) ? $value : ''; return in_array( $value, [ self::PLAYER_UI_ENABLED, self::PLAYER_UI_HEADLESS, self::PLAYER_UI_DISABLED ], true ) ? $value : self::PLAYER_UI_ENABLED; } /** * Renderers * ------------------------------------------------------------------ */ public static function render_api_key(): void { $value = (string) get_option( self::OPTION_API_KEY, '' ); ?>

%s', esc_html__( 'Magic Embed', 'speechkit' ) ) ); ?>

%s', esc_html__( 'headless mode', 'speechkit' ) ) ); ?>

ID, self::OPTION_INTEGRATION_METHOD, true ); } if ( '' === $method ) { $method = (string) get_option( self::OPTION_INTEGRATION_METHOD, self::INTEGRATION_REST_API ); } return self::sanitize_integration_method( $method ); } /** * Available integration method choices. * * @return array */ public static function get_integration_method_options(): array { return [ self::INTEGRATION_REST_API => __( 'REST API', 'speechkit' ), self::INTEGRATION_CLIENT_SIDE => __( 'Magic Embed', 'speechkit' ), ]; } /** * Available player UI choices. * * @return array */ public static function get_player_ui_options(): array { return [ self::PLAYER_UI_ENABLED => __( 'Enabled', 'speechkit' ), self::PLAYER_UI_HEADLESS => __( 'Headless', 'speechkit' ), self::PLAYER_UI_DISABLED => __( 'Disabled', 'speechkit' ), ]; } }