Make WordPress Core

Changeset 62756


Ignore:
Timestamp:
07/15/2026 09:42:49 AM (4 months ago)
Author:
wildworks
Message:

Administration: Support compact button shorthand.

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: ​https://github.com/WordPress/wordpress-develop/pull/11305

Props motylanogha, niravsherasiya7707, wildworks.

Fixes #64892.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/customize.php

    r62745 r62756  
    199199                                <?php $save_text = $wp_customize->is_theme_active() ? __( 'Publish' ) : __( 'Activate &amp; Publish' ); ?>
    200200                                <div id="customize-save-button-wrapper" class="customize-save-button-wrapper" >
    201                                         <?php submit_button( $save_text, 'primary button-compact save', 'save', false ); ?>
     201                                        <?php submit_button( $save_text, 'primary compact save', 'save', false ); ?>
    202202                                        <button id="publish-settings" class="publish-settings button-primary button-compact button dashicons dashicons-admin-generic" aria-label="<?php esc_attr_e( 'Publish Settings' ); ?>" aria-expanded="false" disabled></button>
    203203                                </div>
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r62400 r62756  
    443443                        if ( ! empty( $output ) && $this->has_items() ) {
    444444                                echo $output;
    445                                 submit_button( __( 'Filter' ), 'button-compact', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
     445                                submit_button( __( 'Filter' ), 'compact', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    446446                        }
    447447                }
  • trunk/src/wp-admin/includes/class-wp-links-list-table.php

    r62400 r62756  
    124124                        wp_dropdown_categories( $dropdown_options );
    125125
    126                         submit_button( __( 'Filter' ), 'button-compact', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
     126                        submit_button( __( 'Filter' ), 'compact', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    127127                        ?>
    128128                </div>
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r62704 r62756  
    417417        <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
    418418        <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" />
    419                 <?php submit_button( $text, 'button-compact', '', false, array( 'id' => 'search-submit' ) ); ?>
     419                <?php submit_button( $text, 'compact', '', false, array( 'id' => 'search-submit' ) ); ?>
    420420</p>
    421421                <?php
    … …  
    633633                echo "</select>\n";
    634634
    635                 submit_button( __( 'Apply' ), 'action button-compact', 'bulk_action', false, array( 'id' => "doaction$two" ) );
     635                submit_button( __( 'Apply' ), 'action compact', 'bulk_action', false, array( 'id' => "doaction$two" ) );
    636636                echo "\n";
    637637        }
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r62516 r62756  
    243243                        do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
    244244
    245                         submit_button( __( 'Filter' ), 'button-compact', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
     245                        submit_button( __( 'Filter' ), 'compact', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    246246
    247247                        if ( $this->is_trash && $this->has_items()
    248248                                && current_user_can( 'edit_others_posts' )
    249249                        ) {
    250                                 submit_button( __( 'Empty Trash' ), 'apply button-compact', 'delete_all', false );
     250                                submit_button( __( 'Empty Trash' ), 'apply compact', 'delete_all', false );
    251251                        }
    252252                        ?>
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r62685 r62756  
    597597                        if ( ! empty( $output ) ) {
    598598                                echo $output;
    599                                 submit_button( __( 'Filter' ), 'button-compact', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
     599                                submit_button( __( 'Filter' ), 'compact', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    600600                        }
    601601                }
  • trunk/src/wp-admin/includes/media.php

    r62683 r62756  
    29062906                <?php } ?>
    29072907
    2908                 <?php submit_button( __( 'Filter &#187;' ), 'button-compact', 'post-query-submit', false ); ?>
     2908                <?php submit_button( __( 'Filter &#187;' ), 'compact', 'post-query-submit', false ); ?>
    29092909
    29102910        </div>
  • trunk/src/wp-admin/includes/template.php

    r62710 r62756  
    25632563 * @param string       $text             Optional. The text of the button. Defaults to 'Save Changes'.
    25642564 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
    2565  *                                       include 'primary', 'small', and 'large'. Default 'primary'.
     2565 *                                       include 'primary', 'small', 'compact' and 'large'. Default 'primary'.
    25662566 * @param string       $name             Optional. The HTML name of the submit button. If no `id` attribute
    25672567 *                                       is given in the `$other_attributes` parameter, `$name` will be used
    … …  
    25872587 * @param string       $text             Optional. The text of the button. Defaults to 'Save Changes'.
    25882588 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
    2589  *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
     2589 *                                       include 'primary', 'small', 'compact' and 'large'. Default 'primary large'.
    25902590 * @param string       $name             Optional. The HTML name of the submit button. If no `id` attribute
    25912591 *                                       is given in the `$other_attributes` parameter, `$name` will be used
    … …  
    26062606        }
    26072607
    2608         $button_shorthand = array( 'primary', 'small', 'large' );
     2608        $button_shorthand = array( 'primary', 'small', 'large', 'compact' );
    26092609        $classes          = array( 'button' );
    26102610
  • trunk/tests/phpunit/tests/admin/includesTemplate.php

    r61465 r62756  
    511511                $this->assertSame( array(), $result, 'get_post_states() should return an empty array when WP_Post is not supplied.' );
    512512        }
     513
     514        /**
     515         * Tests that get_submit_button() expands the type shorthands into their
     516         * `button-*` classes.
     517         *
     518         * @ticket 64892
     519         *
     520         * @covers ::get_submit_button
     521         *
     522         * @dataProvider data_get_submit_button_shorthand
     523         *
     524         * @param string|array $type     The type argument passed to get_submit_button().
     525         * @param string       $expected The expected class attribute value.
     526         */
     527        public function test_get_submit_button_expands_type_shorthands( $type, $expected ) {
     528                $button = get_submit_button( 'Save', $type, 'submit', false );
     529
     530                $this->assertStringContainsString( 'class="' . $expected . '"', $button );
     531        }
     532
     533        /**
     534         * Data provider.
     535         *
     536         * @return array[]
     537         */
     538        public function data_get_submit_button_shorthand() {
     539                return array(
     540                        'primary shorthand'            => array( 'primary', 'button button-primary' ),
     541                        'small shorthand'              => array( 'small', 'button button-small' ),
     542                        'large shorthand'              => array( 'large', 'button button-large' ),
     543                        'compact shorthand'            => array( 'compact', 'button button-compact' ),
     544                        'multiple shorthands'          => array( 'primary compact', 'button button-primary button-compact' ),
     545                        'non-shorthand with compact'   => array( 'action compact', 'button action button-compact' ),
     546                        'array type with compact'      => array( array( 'primary', 'compact' ), 'button button-primary button-compact' ),
     547                        'raw button-compact unchanged' => array( 'button-compact', 'button button-compact' ),
     548                );
     549        }
    513550}
Note: See TracChangeset for help on using the changeset viewer.