Dismissible Admin Notice Box

Overview

Starting with Enfold 6.0 we add the possibility for developers to add and manage custom admin notice boxes.

Features

  • Dismiss notice on single user base or for all users
  • Time limit or endless time to show notice to users before dismissed
  • Show notices to users depending on capability
  • WP default admin box styling classes supported or custom styling
  • Content of notice box can be:
    • Plain text
    • Simple HTML
    • Complete custom HTML template
Special features for developers:

When loading a backend page append an argument to url, e.g.

../wp-admin/admin.php?page=avia&avia-admin-notices=clear-all

  • avia-admin-notices=clear-all

Removes all notices and clears all internal markers which notices a user has dismissed. Good for testing if you want to show notices again after downgrading the theme version (to downgrade the theme version in the database – necessary to be recognized later –  set WP_DEBUG = true and upload an older version of the theme or change version in style.css)

  • avia-admin-notices=clear-current-user

Clears all internal markers which notices the current user has dismissed. This brings back all notices (if not expired by the time limit)

  • avia-admin-notices=clear-all-users

Clears all internal markers which notices all users have dismissed.

Implementation

  • Base class is implemented in enfold\framework\php\class-admin-notices.php
  • See enfold\framework\php\admin-notices\admin-notices-def.php for default boxes
  • See enfold\includes\admin\admin-notices\admin-notices-def-enfold.php for Enfold specific box content, allows to override default box content
  • Templates are placed in subfolder ..\admin-notices\templates but can be changed. We highly recommend to use full paths to template files because of include of php files

Important Methods

  • add_notice( $notice_keys, $expire = false, $save = true )
  • delete_notice( $notice_keys = null, $save = true )
  • get_current_notices()
  • get_all_notices()
  • get_default_expire_time( $context = ” )

Filters

  • ‘avf_admin_notices_definition_files’ – add paths to custom box definition files, this allows to override previous defined boxes
  • ‘avf_init_admin_notices’ – allows to alter the admin notice box array with definitions
  • ‘avf_admin_notices_filtered’ – for current user filtered notice boxes to display
  • ‘avf_skip_output_single_notice’ – skip output of notice box
  • ‘avf_admin_notices_activate_cron’ – enable/disable cron job to clean up database for notice box show data and user meta
  • ‘avf_admin_notice_default_expire_time’ – change the default expire time (in a context)