'array', 'sanitize_callback' => 'tellpin_sanitize_options', 'default' => tellpin_default_options(), 'show_in_rest' => false, ) ); add_settings_section( 'tellpin_widget', '', 'tellpin_render_service_description', 'tellpin' ); add_settings_field( 'tellpin_project_key', esc_html__( 'Project key', 'tellpin' ), 'tellpin_render_project_key_field', 'tellpin', 'tellpin_widget', array( 'label_for' => 'tellpin_project_key' ) ); add_settings_field( 'tellpin_enabled', esc_html__( 'Widget', 'tellpin' ), 'tellpin_render_enabled_field', 'tellpin', 'tellpin_widget' ); } add_action( 'admin_init', 'tellpin_register_settings' ); /** * Sanitise settings submitted through options.php. * * The Settings API verifies the nonce and manage_options capability before * updating this option. Project keys are checked locally without any requests. * * @param mixed $input Submitted option value. * @return array Validated options. */ function tellpin_sanitize_options( $input ) { if ( ! is_array( $input ) || ! isset( $input['project_key'] ) || ! is_string( $input['project_key'] ) ) { add_settings_error( 'tellpin_options', 'tellpin_invalid_settings', esc_html__( 'The settings could not be saved. Paste your Tellpin project key and try again.', 'tellpin' ) ); return tellpin_get_options(); } $project_key = trim( sanitize_text_field( $input['project_key'] ) ); if ( strlen( $project_key ) > 255 ) { add_settings_error( 'tellpin_options', 'tellpin_project_key_too_long', esc_html__( 'The project key is too long. Paste the project key from your Tellpin dashboard. Your settings have not been changed.', 'tellpin' ) ); return tellpin_get_options(); } $enabled = isset( $input['enabled'] ) && in_array( $input['enabled'], array( 1, '1' ), true ); if ( $enabled && '' === $project_key ) { add_settings_error( 'tellpin_options', 'tellpin_project_key_required', esc_html__( 'Enter a project key before enabling the Tellpin widget. The widget remains disabled.', 'tellpin' ) ); $enabled = false; } return array( 'project_key' => $project_key, 'enabled' => $enabled ? 1 : 0, ); } /** * Add Settings > Tellpin for site administrators. * * @return void */ function tellpin_add_settings_page() { add_options_page( esc_html__( 'Tellpin settings', 'tellpin' ), esc_html__( 'Tellpin', 'tellpin' ), 'manage_options', 'tellpin', 'tellpin_render_settings_page' ); } add_action( 'admin_menu', 'tellpin_add_settings_page' ); /** * Explain the external service before the owner enables it. * * @return void */ function tellpin_render_service_description() { ?>

·

403 ) ); } $options = tellpin_get_options(); ?>