Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login and Registration: Add expiration support for dismissing notices. #95

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

costdev
Copy link
Owner

@costdev costdev commented Oct 26, 2023

This adds support for an array dismissible value in wp_get_admin_notice().

The array:

array(
    // (string) Required. Cannot be empty.
    'slug'       => 'mynotice',
    // (int) Optional. Seconds to dismiss for. Must be >= 0. Default 0 (permanently dismissed).
    'expiration' => 60,
)

Examples

Make a notice permanently dismissible

wp_get_admin_notice(
    __( 'A notice that will be dismissed permanently.' ),
   array(
       'type'        => 'info',
       'dismissible' => array( 'slug' => 'mynotice' ),
   )
);

Make a notice dismissible for 30 days

wp_get_admin_notice(
    __( 'A notice that will be dismissed for 30 days.' ),
    array(
        'type'        => 'info',
        'dismissible' => array(
            'slug'       => 'mynotice',
            'expiration' => 30 * DAY_IN_SECONDS,
        ),
    )
);

Make all notices permanently dismissible

add_filter( 'wp_admin_notice_args', 'dismiss_each_admin_notice_permanently', 10, 2 );
function dismiss_each_admin_notice_permanently( $args, $message ) {
    $args['dismissible'] = array(
        'slug'       => md5( $message ), // So its transient is unique to that message.
    );
    return $args;
}

Make all notices dismissible for 30 days

add_filter( 'wp_admin_notice_args', 'dismiss_each_admin_notice_for_30_days', 10, 2 );
function dismiss_each_admin_notice_for_30_days( $args, $message ) {
    $args['dismissible'] = array(
        'slug'       => md5( $message ), // So its transient is unique to that message.
        'expiration' => 30 * DAY_IN_SECONDS,
    );
    return $args;
}

Trac ticket:

@costdev costdev force-pushed the save_dismissal_duration_for_admin_notices branch 10 times, most recently from 4b025e5 to 95fd8ec Compare October 29, 2023 11:27
@costdev costdev force-pushed the save_dismissal_duration_for_admin_notices branch from 95fd8ec to b3f6072 Compare October 29, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant