WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 4 months ago

#30942 new defect (bug)

In quicktags settings, setting buttons to zero-length string doesn't give empty toolbar.

Reported by: gitlost Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.1
Component: Editor Keywords: has-patch
Focuses: Cc:
PR Number:

Description

This issue was raised on Wordpress stackexchange http://wordpress.stackexchange.com/a/174086/57034.

If you set the buttons of the quicktags settings to a zero-length string, eg by using the 'quicktags_settings' filter

	add_filter( 'quicktags_settings', function ( $qtInit ) {
		$qtInit['buttons'] = '';
		return $qtInit;
	} );

which typically results in the following setting in tinyMCEPreInit

qtInit: {'content': id:"content",buttons:""},'replycontent': id:"replycontent",buttons:""}}

then quicktags just ignores it and uses the default buttons, due to this falsey test on line 263 of "wp-includes/js/quicktags.js"

			if ( settings.buttons ) {
				use = ','+settings.buttons+',';
			}

This can be worked around by using any non-falsey value in setting $qtInit['buttons'] but that's somewhat non-intuitive. The proposed simple patch tests for string type so you can use '' (and also tests for boolean false which is nice to have as well).

			if ( typeof settings.buttons === 'string' ) {
				use = ','+settings.buttons+',';
			} else if ( settings.buttons === false ) {
				use = ' '; // Any old truthy string.
			}

Attachments (5)

30942_quicktags.diff (510 bytes) - added by gitlost 5 years ago.
Proposed patch.
30942_unittests.diff (3.8 KB) - added by gitlost 5 years ago.
Unit tests for patch.
30942_quicktags2.diff (510 bytes) - added by gitlost 4 years ago.
Refresh for 4.4.
30942_unittests2.diff (4.2 KB) - added by gitlost 4 years ago.
Refresh for 4.4.
30942.patch (2.8 KB) - added by azaozz 4 years ago.
This seems to work here.

Download all attachments as: .zip

Change History (9)

@gitlost
5 years ago

Proposed patch.

@gitlost
5 years ago

Unit tests for patch.

This ticket was mentioned in Slack in #core by jorbin. View the logs.


4 years ago

@gitlost
4 years ago

Refresh for 4.4.

@gitlost
4 years ago

Refresh for 4.4.

#2 @gitlost
4 years ago

  • Keywords has-patch added

Refreshes for gardening drive.

#3 @azaozz
4 years ago

30942_quicktags2.diff won't work well any more. Now the Quicktags toolbar is added from PHP. If no buttons it remains visible and empty, so needs to be hidden.

I'm still not sure how useful this is. Also, kind of easier to do with a little CSS :)

@azaozz
4 years ago

This seems to work here.

#4 @gitlost
4 years ago

Thanks for responding.

That's better, more understandable code, but personally would leave out the ed.toolbar.style.display = 'none'; bit as it leaves a blank gap instead of an empty toolbar (due to the margin-top on the textarea) and a) is ignored with the workaround version and b) I find the later more aesthetically pleasing :)

(It's useful in the sense that the filter will do what one expects.)

Note: See TracTickets for help on using tickets.