Skip to content

Dashboard Widget visible even when disabled #391

Closed

Description

@EusebiuOprinoiu

Describe the bug

Hello, Ben!

After the last update, the Zero Spam widget is shown on the admin dashboard even when it is disabled for all user roles.

Steps to Reproduce

  1. Disable the widget for all user roles in the plugin settings
  2. Check the admin dashboard

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. EusebiuOprinoiu commented on Jan 28, 2026

    @EusebiuOprinoiu
    ContributorAuthor

    In addition, when the widget is displayed, it generates multiple database errors:
    Table 'dbname.prefix_zerospam_log' doesn't exist

    The correct table name is prefix_wpzerospam_log, not prefix_zerospam_log.

  2. bmarshall511 commented on Mar 16, 2026

    @bmarshall511
    Collaborator

    Both issues have been addressed in branch fix/391-dashboard-widget-visibility-and-db-errors:

    1. Widget visible when disabled for all roles

    The root cause was twofold: HTML multi-select elements don't submit a value when nothing is selected, and the widget code treated "nothing submitted" the same as "never configured" — both fell back to showing the widget for administrators.

    Fixes:

    Added a new "Dashboard Widget" enable/disable toggle (widget_enabled) that provides an unambiguous on/off control, separate from the role-based visibility setting.
    Fixed the settings save handler to explicitly store an empty array when no roles are selected in the multi-select, so the code can distinguish "never configured" from "explicitly disabled for all."
    Extracted the duplicated visibility logic into a single has_widget_access() method.
    Added a zerospam_dashboard_widget_visible filter so developers can override visibility programmatically.
    2. Database errors (Table 'prefix_zerospam_log' doesn't exist)

    The widget now checks for table existence before running queries. When the log table is missing, it shows a clean notice with a link to the settings page instead of triggering raw SQL errors.

    Additional improvements in this fix:

    Widget transient cache clears immediately when settings are saved (no more 5-minute delay).
    Refresh button now updates stats and charts in-place via AJAX (no page reload).
    Chart.js is bundled locally instead of loaded from CDN.
    AJAX refresh correctly returns network-level data on multisite network admin dashboards.

  3. added 2 commits that reference this issue on Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions