Dashboard — the product's landing/command-center screen.
*
* Deliberately built from ONLY data that already exists elsewhere in the
* product (Form::/Entry::/Form_Start::/Smtp_Connection::/Email_Log:: — the
* exact same classes Forms, Entries, Reports and Settings already read
* from), never a new metric invented for this screen. Every number here is
* something a user could already find by clicking into another screen;
* this page's only job is answering "what's happening right now" without
* making them do that clicking.
*
* Redesign (user feedback: "simple... not showing everything in a clean
* and professional way... user gets benefit from it"). Two real gaps
* closed rather than just re-skinned:
*
* 1. The Key Metrics row only ever showed raw counts with no sense of
* direction — a "12" tells you nothing about whether that's better or
* worse than last week. Reports_Page already solved exactly this
* (Entry::percent_change(), Form_Start::percent_change(), a real
* change-badge component) for its own Key Metrics; this screen adopts
* the identical pattern and the identical CSS classes
* (.chargeforms-stat-tile--metric.is-*, .chargeforms-stat-change) so
* it reads as the same product, not a second, older-looking design.
* 2. Nothing on the old Dashboard told a user what to actually DO — every
* card was a passive report. "Needs Attention" is new: it surfaces
* only the conditions that are true right now (unread backlog, failed
* sends, no SMTP, a form that's never received a submission) with a
* direct link to fix each one, and says so plainly when there's
* nothing to act on rather than always rendering an empty shell.
*
* Not the literal click target of the top-level "ChargeForms" WP-admin
* menu item — that's still Forms_List_Page (registered on the shared
* 'chargeforms' slug, a WP-admin convention changing it would touch
* every existing bookmark/redirect that expects page=chargeforms to be
* the forms list). This screen is reachable from the in-page top nav
* (Page_Header) and its own sidebar entry instead, positioned first.
*/
class Dashboard_Page {
const CAPABILITY = 'chargeforms_manage_forms';
public function __construct() {
add_action( 'admin_menu', [ $this, 'register' ], 8 );
}
public function register() {
add_submenu_page(
'chargeforms',
__( 'Dashboard', 'chargeforms' ),
__( 'Dashboard', 'chargeforms' ),
self::CAPABILITY,
'chargeforms-dashboard',
[ $this, 'render' ]
);
}
public function render() {
if ( ! current_user_can( self::CAPABILITY ) ) {
wp_die( esc_html__( 'You do not have permission to access this page.', 'chargeforms' ) );
}
$form_count = Form::count();
?>