Returns the available views for the list table.
Description
See also
Parameters
- $current
-
(string) (Required) Slug of the current view, passed by reference. Should be set properly in the method.
- $list_url
-
(string) (Optional) The URL to the list page.
Default value: ''
Return
(array) Views as <code>$slug => $data</code> pairs. The $data array must have keys 'url' and 'label' and may additionally have 'class' and 'aria_label'.
Source
File: src/db-objects/submissions/submissions-list-table.php
protected function build_views( &$current, $list_url = '' ) { $capabilities = $this->manager->capabilities(); $current = 'all'; $total = 0; $views = array(); $user_id = 0; if ( ! $capabilities || ! $capabilities->current_user_can( 'edit_others_items' ) || ! $capabilities->current_user_can( 'read_others_items' ) ) { $user_id = get_current_user_id(); } else { $user_counts = $this->manager->count( get_current_user_id() ); if ( isset( $_REQUEST['user_id'] ) && get_current_user_id() === absint( $_REQUEST['user_id'] ) ) { $current = 'mine'; } $views['mine'] = array( 'url' => add_query_arg( 'user_id', get_current_user_id(), $list_url ), 'label' => sprintf( translate_nooped_plural( $this->manager->get_message( 'list_table_view_mine', true ), $user_counts['_total'] ), number_format_i18n( $user_counts['_total'] ) ), ); } $form_id = 0; if ( ! empty( $_GET['form_id'] ) ) { $form_id = (int) $_GET['form_id']; } $counts = $this->manager->count( $user_id, $form_id ); foreach ( $counts as $status => $number ) { if ( '_total' === $status ) { continue; } $views[ $status ] = array( 'url' => add_query_arg( 'status', $status, $list_url ), 'label' => sprintf( translate_nooped_plural( $this->manager->get_message( 'list_table_view_status_' . $status, true ), $number ), number_format_i18n( $number ) ), ); $total += $number; } if ( isset( $_REQUEST['status'] ) ) { $current = $_REQUEST['status']; } if ( isset( $user_counts ) && absint( $user_counts['_total'] ) === absint( $total ) ) { unset( $views['mine'] ); } if ( ! empty( $views ) ) { $views = array_merge( array( 'all' => array( 'url' => $list_url, 'label' => sprintf( translate_nooped_plural( $this->manager->get_message( 'list_table_view_all', true ), $total ), number_format_i18n( $total ) ), ), ), $views ); } if ( $form_id > 0 ) { foreach ( $views as $slug => $data ) { $views[ $slug ]['url'] = add_query_arg( 'form_id', $form_id, $data['url'] ); } } /** * Filters the submission views. * * @since 1.0.0 * * @param array $views Associative array of `$view_slug => $view_data` pairs. */ return apply_filters( "{$this->manager->get_prefix()}submission_admin_views", $views ); }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |