bulk_actions( $which ); ?>
extra_tablenav( $which );
if ( $which === 'top' ) {
$this->pagination( $which );
}
?>
get( 'forms_tags' )->extra_tablenav( $which, $this );
wpforms()->get( 'forms_views' )->extra_tablenav( $which );
}
/**
* Message to be displayed when there are no forms.
*
* @since 1.0.0
*/
public function no_items() {
esc_html_e( 'No forms found.', 'wpforms-lite' );
}
/**
* Fetch and set up the final data for the table.
*
* @since 1.0.0
*/
public function prepare_items() {
// Set up the columns.
$columns = $this->get_columns();
// Hidden columns (none).
$hidden = get_hidden_columns( $this->screen );
// Define which columns can be sorted - form name, author, date.
$sortable = [
'name' => [ 'title', false ],
'author' => [ 'author', false ],
'created' => [ 'date', false ],
];
// Set column headers.
$this->_column_headers = [ $columns, $hidden, $sortable ];
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$page = $this->get_pagenum();
$order = isset( $_GET['order'] ) && $_GET['order'] === 'asc' ? 'ASC' : 'DESC';
$orderby = isset( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'ID';
$per_page = $this->get_items_per_page( 'wpforms_forms_per_page', $this->per_page );
// phpcs:enable WordPress.Security.NonceVerification.Recommended
$args = [
'orderby' => $orderby,
'order' => $order,
'nopaging' => false,
'posts_per_page' => $per_page,
'paged' => $page,
'no_found_rows' => false,
'post_status' => 'publish',
];
/**
* Filters the `get_posts()` arguments while preparing items for the forms overview table.
*
* @since 1.7.3
*
* @param array $args Arguments array.
*/
$args = (array) apply_filters( 'wpforms_overview_table_prepare_items_args', $args );
// Giddy up.
$this->items = wpforms()->get( 'form' )->get( '', $args );
$per_page = isset( $args['posts_per_page'] ) ? $args['posts_per_page'] : $this->get_items_per_page( 'wpforms_forms_per_page', $this->per_page );
$this->update_count( $args );
$count_current_view = empty( $this->count[ $this->view ] ) ? 0 : $this->count[ $this->view ];
// Finalize pagination.
$this->set_pagination_args(
[
'total_items' => $count_current_view,
'per_page' => $per_page,
'total_pages' => ceil( $count_current_view / $per_page ),
]
);
}
/**
* Calculate and update form counts.
*
* @since 1.7.2
*
* @param array $args Get forms arguments.
*/
private function update_count( $args ) {
/**
* Allow counting forms filtered by a given search criteria.
*
* If result will not contain `all` key, count All Forms without filtering will be performed.
*
* @since 1.7.2
*
* @param array $count Contains counts of forms in different views.
* @param array $args Arguments of the `get_posts`.
*/
$this->count = (array) apply_filters( 'wpforms_overview_table_update_count', [], $args );
// We do not need to perform all forms count if we have the result already.
if ( isset( $this->count['all'] ) ) {
return;
}
// Count all forms.
$this->count['all'] = wpforms_current_user_can( 'wpforms_view_others_forms' )
? (int) wp_count_posts( 'wpforms' )->publish
: (int) count_user_posts( get_current_user_id(), 'wpforms', true );
/**
* Filters forms count data after counting all forms.
*
* This filter executes only if the result of `wpforms_overview_table_update_count` filter
* doesn't contain `all` key.
*
* @since 1.7.3
*
* @param array $count Contains counts of forms in different views.
* @param array $args Arguments of the `get_posts`.
*/
$this->count = (array) apply_filters( 'wpforms_overview_table_update_count_all', $this->count, $args );
}
/**
* Display the pagination.
*
* @since 1.7.2
*
* @param string $which The location of the table pagination: 'top' or 'bottom'.
*/
protected function pagination( $which ) {
if ( $this->has_items() ) {
parent::pagination( $which );
return;
}
printf(
'