WP_List_Table::print_column_headers() – Prints column headers, accounting for hidden and sortable columns.

You appear to be a bot. Output may be restricted

Description

Prints column headers, accounting for hidden and sortable columns.

Usage

WP_List_Table::print_column_headers( $with_id );

Parameters

$with_id
( bool ) optional default: 1 – Whether to set the ID attribute or not

Returns

void

Source

File name: wordpress/wp-admin/includes/class-wp-list-table.php


Lines:

1 to 100 of 140
  public function print_column_headers( $with_id = true ) {
    list( $columns, $hidden, $sortable, $primary ) = $this->WP_List_Table::get_column_info();

    $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
    $current_url = remove_query_arg( 'paged', $current_url );

    // When users click on a column header to sort by other columns.
    if ( isset( $_GET['orderby'] ) ) {
      $current_orderby = $_GET['orderby'];
      // In the initial view there's no orderby parameter.
    } else {
      $current_orderby = '';
    }

    // Not in the initial view and descending order.
    if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
      $current_order = 'desc';
    } else {
      // The initial view is not always 'asc', we'll take care of this below.
      $current_order = 'asc';
    }

    if ( ! empty( $columns['cb'] ) ) {
      static $cb_counter = 1;
      $columns['cb']     = '<label class="label-covers-full-cell" for="cb-select-all-' . $cb_counter . '">' .
        '<span class="screen-reader-text">' .
          /* translators: Hidden accessibility text. */
          __( 'Select All' ) .
        '</span>' .
        '</label>' .
        '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
      $cb_counter++;
    }

    foreach ( $columns as $column_key => $column_display_name ) {
      $class          = array( 'manage-column', "column-$column_key" );
      $aria_sort_attr = '';
      $abbr_attr      = '';
      $order_text     = '';

      if ( in_array( $column_key, $hidden, true ) ) {
        $class[] = 'hidden';
      }

      if ( 'cb' === $column_key ) {
        $class[] = 'check-column';
      } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
        $class[] = 'num';
      }

      if ( $column_key === $primary ) {
        $class[] = 'column-primary';
      }

      if ( isset( $sortable[ $column_key ] ) ) {
        $orderby       = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
        $desc_first    = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
        $abbr          = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
        $orderby_text  = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
        $initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';

        /*
				 * We're in the initial view and there's no $_GET['orderby'] then check if the
				 * initial sorting information is set in the sortable columns and use that.
				 */
        if ( '' === $current_orderby && $initial_order ) {
          // Use the initially sorted column $orderby as current orderby.
          $current_orderby = $orderby;
          // Use the initially sorted column asc/desc order as initial order.
          $current_order = $initial_order;
        }

        /*
				 * True in the initial view when an initial orderby is set via get_sortable_columns()
				 * and true in the sorted views when the actual $_GET['orderby'] is equal to $orderby.
				 */
        if ( $current_orderby === $orderby ) {
          // The sorted column. The `aria-sort` attribute must be set only on the sorted column.
          if ( 'asc' === $current_order ) {
            $order          = 'desc';
            $aria_sort_attr = ' aria-sort="ascending"';
          } else {
            $order          = 'asc';
            $aria_sort_attr = ' aria-sort="descending"';
          }

          $class[] = 'sorted';
          $class[] = $current_order;
        } else {
          // The other sortable columns.
          $order = strtolower( $desc_first );

          if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) {
            $order = $desc_first ? 'desc' : 'asc';
          }

          $class[] = 'sortable';
          $class[] = 'desc' === $order ? 'asc' : 'desc';

          /* translators: Hidden accessibility text. */

 View on GitHub View on Trac