Skip to content

64892 get_submit_button() should support "compact" button shorthand - #11305

Closed
nirav7707 wants to merge 7 commits into
WordPress:trunkfrom
nirav7707:64892-support-button-variation
Closed

64892 get_submit_button() should support "compact" button shorthand#11305
nirav7707 wants to merge 7 commits into
WordPress:trunkfrom
nirav7707:64892-support-button-variation

Conversation

@nirav7707

Copy link
Copy Markdown

Core trac: https://core.trac.wordpress.org/ticket/64892

Test:
Large
Screenshot 2026-03-19 at 5 03 48 PM

Compact
Screenshot 2026-03-19 at 5 04 09 PM

Small
Screenshot 2026-03-19 at 5 04 25 PM

@github-actions

github-actions Bot commented Mar 19, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props niravsherasiya7707, wildworks, motylanogha.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Can you update the following PHPDocs?

* include 'primary', 'small', and 'large'. Default 'primary'.

* include 'primary', 'small', and 'large'. Default 'primary large'.

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@wppoland

Copy link
Copy Markdown

get_submit_button() currently has no test coverage, so here are tests that lock in the new compact shorthand alongside the existing ones. The compact, primary compact, and standalone-compact cases fail on trunk and pass with this PR; the rest document existing behavior.

Goes in tests/phpunit/tests/admin/includesTemplate.php:

	/**
	 * Ensures the 'compact' button variation is recognized as a shorthand and
	 * rendered as the `button-compact` CSS class.
	 *
	 * @ticket 64892
	 *
	 * @covers ::get_submit_button
	 */
	public function test_get_submit_button_supports_compact_shorthand() {
		$button = get_submit_button( 'Save', 'compact', 'submit', false );

		$this->assertStringContainsString(
			'class="button button-compact"',
			$button,
			'The "compact" type was not converted to the "button-compact" shorthand class.'
		);
	}

	/**
	 * Ensures recognized button shorthands are converted to their `button-*`
	 * classes, while non-shorthand values are passed through verbatim.
	 *
	 * @ticket 64892
	 *
	 * @covers ::get_submit_button
	 *
	 * @dataProvider data_get_submit_button_shorthand_classes
	 *
	 * @param string $type           The button type passed to get_submit_button().
	 * @param string $expected_class The expected value of the class attribute.
	 */
	public function test_get_submit_button_shorthand_classes( $type, $expected_class ) {
		$button = get_submit_button( 'Save', $type, 'submit', false );

		$this->assertStringContainsString(
			'class="' . $expected_class . '"',
			$button,
			"The button type \"{$type}\" did not produce the expected class attribute."
		);
	}

	/**
	 * Data provider.
	 *
	 * @return array[]
	 */
	public function data_get_submit_button_shorthand_classes() {
		return array(
			'primary'           => array( 'primary', 'button button-primary' ),
			'small'             => array( 'small', 'button button-small' ),
			'large'             => array( 'large', 'button button-large' ),
			'compact'           => array( 'compact', 'button button-compact' ),
			'primary + compact' => array( 'primary compact', 'button button-primary button-compact' ),
			'secondary skipped' => array( 'secondary', 'button' ),
			'custom passthru'   => array( 'my-custom-class', 'button my-custom-class' ),
		);
	}

Happy to push these as a commit if preferred.

@t-hamano

Copy link
Copy Markdown
Contributor

@wppoland Thanks for the suggestion!

@nirav7707. Could you add some unit tests?

Additionally, all instances where submit_button() is called would benefit from using the shorthand, like so:

diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php
index 71ae2a9eea..d960373dbc 100644
--- a/src/wp-admin/includes/media.php
+++ b/src/wp-admin/includes/media.php
@@ -2905,7 +2905,7 @@ function media_upload_library_form( $errors ) {
                        </select>
                <?php } ?>
 
-               <?php submit_button( __( 'Filter &#187;' ), 'button-compact', 'post-query-submit', false ); ?>
+               <?php submit_button( __( 'Filter &#187;' ), 'compact', 'post-query-submit', false ); ?>
 
        </div>

@t-hamano

Copy link
Copy Markdown
Contributor

Hi @nirav7707, Do you have the bandwidth to address the following feedback? Thank you!

@nirav7707. Could you add some unit tests?

Additionally, all instances where submit_button() is called would benefit from using the shorthand, like so:

t-hamano and others added 2 commits July 15, 2026 17:18
Now that `get_submit_button()` supports the `compact` shorthand, update all
core callers that pass the raw `button-compact` class to use it. This keeps
the callers consistent with the other shorthands (`primary`, `small`, `large`)
and produces identical markup.

Co-Authored-By: Claude <noreply@anthropic.com>
@t-hamano

Copy link
Copy Markdown
Contributor

Additionally, all instances where submit_button() is called would benefit from using the shorthand, like so:

Addressed in be35955

Cover the expansion of the `primary`, `small`, `large`, and `compact` type
shorthands into their `button-*` classes, including combined, array, and
non-shorthand inputs. This guards the newly added `compact` shorthand and
documents the existing expansion behavior.

Co-Authored-By: Claude <noreply@anthropic.com>
@t-hamano

Copy link
Copy Markdown
Contributor

get_submit_button() currently has no test coverage, so here are tests that lock in the new compact shorthand alongside the existing ones. The compact, primary compact, and standalone-compact cases fail on trunk and pass with this PR; the rest document existing behavior.

Thank you for your suggestion! I've pushed the unit tests referring to your code. 24c2790

pento pushed a commit that referenced this pull request Jul 15, 2026
Add `compact` to the type shorthands expanded by `get_submit_button()`, so passing `compact` now yields the `button-compact` class. This matches the existing `primary`, `small`, and `large` shorthands.

Developed in: #11305

Props motylanogha, niravsherasiya7707, wildworks.

Fixes #64892.


git-svn-id: https://develop.svn.wordpress.org/trunk@62756 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62756
GitHub commit: e7f523f

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Jul 15, 2026
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jul 15, 2026
Add `compact` to the type shorthands expanded by `get_submit_button()`, so passing `compact` now yields the `button-compact` class. This matches the existing `primary`, `small`, and `large` shorthands.

Developed in: WordPress/wordpress-develop#11305

Props motylanogha, niravsherasiya7707, wildworks.

Fixes #64892.

Built from https://develop.svn.wordpress.org/trunk@62756


git-svn-id: http://core.svn.wordpress.org/trunk@62040 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@wppoland

Copy link
Copy Markdown

Verified the unit tests locally on the branch, they pass successfully: OK (35 tests, 119 assertions).

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.

3 participants