Make WordPress Core


Ignore:
Timestamp:
09/19/2022 09:06:08 PM (19 months ago)
Author:
davidbaumwald
Message:

Administration: Add new get_views_links method to WP_List_Table.

Many WP_List_Table child classes in core use mostly the same code to create their "view" links markup. To DRY-up the code, a new WP_List_Table->get_view_links method is being introduced to consolidate the HTML link generation when provided an array of links.

This change also implements this new method in the relevant WP_List_Table_xxx child classes get_views methods. Finally, unit tests are being added to validate view links markup and test for some "unhappy paths".

Props afercia, costdev, garrett-eclipse, Dharm1025, juhise, peterwilsoncc.
Fixes #42066.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/wpMsSitesListTable.php

    r52010 r54215  
    231231            $this->assertSameSets( $expected, $items );
    232232        }
     233
     234        /**
     235         * @ticket 42066
     236         */
     237        public function test_get_views_should_return_views_by_default() {
     238            $expected = array(
     239                'all'    => '<a href="sites.php" class="current" aria-current="page">All <span class="count">(14)</span></a>',
     240                'public' => '<a href="sites.php?status=public">Public <span class="count">(14)</span></a>',
     241            );
     242
     243            $this->assertSame( $expected, $this->table->get_views() );
     244        }
    233245    }
    234246endif;
Note: See TracChangeset for help on using the changeset viewer.