CalderaWP / dismissible_notice

Creates a dismissible--via AJAX--admin nag.
15 stars 1 forks source link

Support for WordPress 4.2 `is-dismissible` class #5

Closed grappler closed 9 years ago

grappler commented 9 years ago

In WordPress 4.2 a new class was introduced to add a dismiss button.

I made some changes to switch to using the class is-dismissible https://github.com/grappler/dismissible_notice/commit/7ca7b9d50dcd306944abadd471749754c0627a9b

I am not sure how you want to support it in this class.

Shelob9 commented 9 years ago

That commit has two things in it:

1) Allowing for skipping the prefixing of the ignore key/ and the sub_str(), which was designed to limit length from getting too long.

2) Adding the is-dismissible class.

grappler commented 9 years ago

Yes, the commit has multiple things in it. I wanted to commit all of my changes in one branch. We can discuss 1. further in https://github.com/CalderaWP/dismissible_notice/pull/4

  1. The best way to provide backwards compatibility would be to add the JS that WordPress uses in 4.2

The two changesets. https://core.trac.wordpress.org/changeset/32068 https://core.trac.wordpress.org/changeset/31973

This is the JS needed

    // Make notices dismissible
    $( '.notice.is-dismissible' ).each( function() {
        var $this = $( this ),
            $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ),
            btnText = caldera_commonL10n.dismiss || '';

        // Ensure plain text
        $button.find( '.screen-reader-text' ).text( btnText );

        $this.append( $button );

        $button.on( 'click.wp-dismiss-notice', function( event ) {
            event.preventDefault();
            $this.fadeTo( 100 , 0, function() {
                $(this).slideUp( 100, function() {
                    $(this).remove();
                });
            });
        });
    });

This PHP then internationalizes the elements

    wp_localize_script( 'caldera-common', 'caldera_commonL10n', array(
        'dismiss'    => __( 'Dismiss this notice.', 'plugin-domain' ),
    ) );

I am not sure what CSS changes need to be made.

Shelob9 commented 9 years ago

As long as it works in pre 4.2 I'm OK with that change.

grappler commented 9 years ago

How many WP versions do you want to support? In the current code dashicons are being used which were only added in 3.8. I have been able to test the code for it to work in 3.7.8 but there are no dashicons before 3.8.

Is support till WP 3.8 enough?