Strabber), plugin action link and setup notice. */ class Strabber_Admin { const PAGE = 'strabber'; const GROUP = 'strabber'; public static function init() { add_action('admin_menu', [__CLASS__, 'add_menu']); add_action('admin_init', [__CLASS__, 'register_settings']); add_action('admin_notices', [__CLASS__, 'setup_notice']); add_filter('plugin_action_links_' . plugin_basename(STRABBER_PLUGIN_FILE), [__CLASS__, 'action_links']); } public static function add_menu() { add_options_page( __('Strabber', 'strabber'), __('Strabber', 'strabber'), 'manage_options', self::PAGE, [__CLASS__, 'render_page'] ); } public static function register_settings() { register_setting(self::GROUP, Strabber_Options::SITE_ID, [ 'type' => 'string', 'default' => '', 'sanitize_callback' => [__CLASS__, 'sanitize_site_id'], ]); register_setting(self::GROUP, Strabber_Options::EXCLUDE_ROLES, [ 'type' => 'array', 'default' => [], 'sanitize_callback' => ['Strabber_Options', 'sanitize_roles'], ]); add_settings_section('strabber_main', '', '__return_false', self::PAGE); add_settings_field( Strabber_Options::SITE_ID, __('Site ID', 'strabber'), [__CLASS__, 'render_site_id_field'], self::PAGE, 'strabber_main', ['label_for' => Strabber_Options::SITE_ID] ); add_settings_field( Strabber_Options::EXCLUDE_ROLES, __('Do not record', 'strabber'), [__CLASS__, 'render_exclude_roles_field'], self::PAGE, 'strabber_main' ); } public static function sanitize_site_id($value) { $raw = is_string($value) ? trim($value) : ''; $site_id = Strabber_Options::sanitize_site_id($raw); if ($raw !== '' && $site_id === '') { // WordPress runs this callback twice when the option is first created; report the error once. if (!get_settings_errors(Strabber_Options::SITE_ID)) { add_settings_error( Strabber_Options::SITE_ID, 'strabber_invalid_site_id', __('The Site ID may only contain letters, digits, dashes and underscores. The previous value was kept.', 'strabber') ); } return Strabber_Options::site_id(); } return $site_id; } public static function render_page() { if (!current_user_can('manage_options')) { return; } ?>

' . esc_html__('Strabber dashboard', 'strabber') . '' ); ?>

get_names() as $role => $name) : ?>

id === 'settings_page_' . self::PAGE) { return; } printf( '

%s %s

', esc_html__('Strabber is not recording yet: no Site ID is set.', 'strabber'), esc_url(self::settings_url()), esc_html__('Configure Strabber', 'strabber') ); } public static function action_links($links) { array_unshift( $links, sprintf('%s', esc_url(self::settings_url()), esc_html__('Settings', 'strabber')) ); return $links; } private static function settings_url() { return admin_url('options-general.php?page=' . self::PAGE); } }