'boolean', 'label' => __( 'Enable Analytics', 'agentmonitor' ), 'description' => __( 'Whether visit tracking is enabled.', 'agentmonitor' ), 'sanitize_callback' => 'rest_sanitize_boolean', 'show_in_rest' => false, 'default' => true, ) ); register_setting( AGENT_MONITOR_OPTION_GROUP, AGENT_MONITOR_TOKEN, array( 'type' => 'string', 'label' => __( 'Site Token', 'agentmonitor' ), 'description' => __( 'The access token linking this site to your Agent Monitor site.', 'agentmonitor' ), 'sanitize_callback' => 'sanitize_text_field', 'show_in_rest' => false, 'default' => '', ) ); register_setting( AGENT_MONITOR_OPTION_GROUP, AGENT_MONITOR_LOG_MAX_SIZE, array( 'type' => 'integer', 'label' => __( 'Maximum Log Size', 'agentmonitor' ), 'description' => __( 'Maximum size of the visit log file in megabytes before new visits are dropped.', 'agentmonitor' ), 'sanitize_callback' => 'agent_monitor_sanitize_log_max_size', 'show_in_rest' => false, 'default' => 16, ) ); } function agent_monitor_sanitize_log_max_size( $value ) { $min = (int) ( AGENT_MONITOR_EVENT_LOG_SIZE_MIN / MB_IN_BYTES ); $max = (int) ( AGENT_MONITOR_EVENT_LOG_SIZE_MAX / MB_IN_BYTES ); $value = max( $min, min( $max, (int) $value ) ); return (int) ( round( $value / 8 ) * 8 ); } add_action('admin_init', 'agent_monitor_register_settings'); // Register menu item function agent_monitor_menu() { add_menu_page( 'Agent Monitor', 'Agent Monitor', 'manage_options', 'agentmonitor', 'agent_monitor_page' ); } add_action('admin_menu', 'agent_monitor_menu'); function agent_monitor_enqueue_settings_styles( $hook ) { if ( $hook !== 'toplevel_page_agentmonitor' ) { return; } wp_register_style( 'agentmonitor-settings', plugin_dir_url( __FILE__ ) . '../assets/css/main.css', [], AGENT_MONITOR_PLUGIN_VERSION ); wp_enqueue_style( 'agentmonitor-settings' ); } add_action( 'admin_enqueue_scripts', 'agent_monitor_enqueue_settings_styles' ); function agent_monitor_page() { // Prevent unauthorized access if ( ! current_user_can( 'manage_options' ) ) { return; } // Detect updates if ( isset( $_GET['settings-updated'] ) ) { add_settings_error( 'agent_monitor_messages', 'agent_monitor_message', __( 'Settings Saved', 'agentmonitor' ), 'updated' ); } // show error/update messages settings_errors( 'agent_monitor_messages' ); ?>