namespace WPForms\Admin\Forms;
use WPForms\Admin\Forms\Table\Facades\Columns;
use WPForms\Forms\Locator;
use WPForms\Integrations\LiteConnect\LiteConnect;
use WPForms\Integrations\LiteConnect\Integration as LiteConnectIntegration;
// This line is needed to prevent fatal errors in the third-party plugins.
// We know about Jetpack (probably others also) can load WP classes during cron jobs or something similar.
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
* Generate the table on the plugin overview page.
class ListTable extends WP_List_Table {
* Number of forms to show per page.
* Number of forms in different views.
* Primary class constructor.
public function __construct() {
// Utilize the parent constructor to build the main class properties.
// Determine the current view.
$this->view = wpforms()->obj( 'forms_views' )->get_current_view();
* Filters the default number of forms to show per page.
* @param int $forms_per_page Number of forms to show per page.
$this->per_page = (int) apply_filters( 'wpforms_overview_per_page', 20 ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
private function hooks() {
add_filter( 'default_hidden_columns', [ $this, 'default_hidden_columns' ], 10, 2 );
* Get the instance of a class and store it in itself.
public static function get_instance() {
* Retrieve the table columns.
* @return array $columns Array of all the list table columns.
public function get_columns() {
return Columns::get_list_table_columns();
* Render the checkbox column.
* @param WP_Post $form Form.
public function column_cb( $form ) {
return '<input type="checkbox" name="form_id[]" value="' . absint( $form->ID ) . '" />';
* @param WP_Post $form CPT object as a form representation.
* @param string $column_name Column Name.
public function column_default( $form, $column_name ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity
switch ( $column_name ) {
$value = '[wpforms id="' . $form->ID . '"]';
if ( wpforms_is_form_template( $form->ID ) ) {
$value = __( 'N/A', 'wpforms-lite' );
// This slug is not changed to 'date' for backward compatibility.
if ( gmdate( 'Ymd', strtotime( $form->post_date ) ) === gmdate( 'Ymd', strtotime( $form->post_modified ) ) ) {
sprintf( /* translators: %1$s - Post created date. */
__( 'Created<br/>%1$s', 'wpforms-lite' ),
esc_html( wpforms_datetime_format( $form->post_date ) )
sprintf( /* translators: %1$s - Post modified date. */
__( 'Last Modified<br/>%1$s', 'wpforms-lite' ),
esc_html( wpforms_datetime_format( $form->post_modified ) )
'<span class="wpforms-lite-connect-entries-count"><a href="%s" data-title="%s">%s%d</a></span>',
esc_url( admin_url( 'admin.php?page=wpforms-entries' ) ),
esc_attr__( 'Entries are securely backed up in the cloud. Upgrade to restore.', 'wpforms-lite' ),
'<svg viewBox="0 0 16 12"><path d="M10.8 2c1.475 0 2.675 1.175 2.775 2.625C15 5.125 16 6.475 16 8a3.6 3.6 0 0 1-3.6 3.6H4a3.98 3.98 0 0 1-4-4 4.001 4.001 0 0 1 2.475-3.7A4.424 4.424 0 0 1 6.8.4c1.4 0 2.625.675 3.425 1.675C10.4 2.025 10.6 2 10.8 2ZM4 10.4h8.4a2.4 2.4 0 0 0 0-4.8.632.632 0 0 0-.113.013.678.678 0 0 1-.112.012c.125-.25.225-.525.225-.825 0-.875-.725-1.6-1.6-1.6a1.566 1.566 0 0 0-1.05.4 3.192 3.192 0 0 0-2.95-2 3.206 3.206 0 0 0-3.2 3.2v.05A2.757 2.757 0 0 0 1.2 7.6 2.795 2.795 0 0 0 4 10.4Zm6.752-4.624a.64.64 0 1 0-.905-.905L6.857 7.86 5.38 6.352a.64.64 0 1 0-.914.896l1.93 1.97a.64.64 0 0 0 .91.004l3.446-3.446Z"/></svg>',
LiteConnectIntegration::get_form_entries_count( $form->ID )
$value = get_post_modified_time( get_option( 'date_format' ), false, $form );
$author = get_userdata( $form->post_author );
$value = $author->display_name;
$user_edit_url = get_edit_user_link( $author->ID );
if ( ! empty( $user_edit_url ) ) {
$value = '<a href="' . esc_url( $user_edit_url ) . '">' . esc_html( $value ) . '</a>';
$value = '<code style="display:block;font-size:11px;">if( function_exists( \'wpforms_get\' ) ){ wpforms_get( ' . $form->ID . ' ); }</code>';
* Filters the Forms Overview list table culumn value.
* @param string $value Column value.
* @param WP_Post $form CPT object as a form representation.
* @param string $column_name Column Name.
return apply_filters( 'wpforms_overview_table_column_value', $value, $form, $column_name ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
* Filter the default list of hidden columns.
* @param string[] $hidden Array of IDs of columns hidden by default.
* @param WP_Screen $screen WP_Screen object of the current screen.
public function default_hidden_columns( $hidden, $screen ) {
if ( $screen->id !== 'toplevel_page_wpforms-overview' ) {
if ( Columns::has_selected_columns() ) {
* Render the form name column with action links.
* @param WP_Post $form Form.
public function column_name( $form ) {
$title = $this->get_column_name_title( $form );
$states = _post_states( $form, false );
$actions = $this->get_column_name_row_actions( $form );
// Build the row action links and return the value.
return $title . $states . $actions;
* Render the form tags column.
* @param WP_Post $form Form.
public function column_tags( $form ) {
return wpforms()->obj( 'forms_tags' )->column_tags( $form );
* Get the form name HTML for the form name column.
* @param WP_Post $form Form object.
protected function get_column_name_title( $form ) {
$title = ! empty( $form->post_title ) ? $form->post_title : $form->post_name;
'<span><strong>%s</strong></span>',
if ( $this->view === 'trash' ) {
if ( wpforms_current_user_can( 'view_form_single', $form->ID ) ) {
'<a href="%s" title="%s" class="row-title" target="_blank" rel="noopener noreferrer"><strong>%s</strong></a>',
esc_url( wpforms_get_form_preview_url( $form->ID ) ),
esc_attr__( 'View preview', 'wpforms-lite' ),
if ( wpforms_current_user_can( 'view_entries_form_single', $form->ID ) ) {
'<a href="%s" title="%s"><strong>%s</strong></a>',
admin_url( 'admin.php?page=wpforms-entries' )
esc_attr__( 'View entries', 'wpforms-lite' ),
if ( wpforms_current_user_can( 'edit_form_single', $form->ID ) ) {
'<a href="%s" title="%s"><strong>%s</strong></a>',
admin_url( 'admin.php?page=wpforms-builder' )
esc_attr__( 'Edit This Form', 'wpforms-lite' ),
* Get the row actions HTML for the form name column.
* @param WP_Post $form Form object.
protected function get_column_name_row_actions( $form ) {
// phpcs:disable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
* Filters row action links on the 'All Forms' admin page.
* @param array $row_actions An array of action links for a given form.
* @param WP_Post $form Form object.
return $this->row_actions( apply_filters( 'wpforms_overview_row_actions', [], $form ) );
// phpcs:enable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
* Define bulk actions available for our table listing.
public function get_bulk_actions() {
return wpforms()->obj( 'forms_bulk_actions' )->get_dropdown_items();
* Generate the table navigation above or below the table.
* @param string $which The location of the table navigation: 'top' or 'bottom'.
protected function display_tablenav( $which ) {
// If there are some forms just call the parent method.
if ( $this->has_items() ) {
parent::display_tablenav( $which );
// Otherwise, display bulk actions menu and "0 items" on the right (pagination).
<div class="tablenav <?php echo esc_attr( $which ); ?>">
<div class="alignleft actions bulkactions">
<?php $this->bulk_actions( $which ); ?>
$this->extra_tablenav( $which );
if ( $which === 'top' ) {
$this->pagination( $which );
* Extra controls to be displayed between bulk actions and pagination.
* @param string $which The location of the table navigation: 'top' or 'bottom'.
protected function extra_tablenav( $which ) {
wpforms()->obj( 'forms_tags' )->extra_tablenav( $which, $this );
wpforms()->obj( 'forms_views' )->extra_tablenav( $which );
* Message to be displayed when there are no forms.
public function no_items() {
wpforms()->obj( 'forms_views' )->get_current_view() === 'templates' ?
esc_html_e( 'No form templates found.', 'wpforms-lite' ) :
esc_html_e( 'No forms found.', 'wpforms-lite' );
* Fetch and set up the final data for the table.
public function prepare_items() {
$columns = $this->get_columns();
// Hidden columns (none).
$hidden = get_hidden_columns( $this->screen );
// Define which columns can be sorted - form name, author, date.
'name' => [ 'title', false ],
'author' => [ 'author', false ],
'created' => [ 'date', false ],
$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
if ( $orderby === 'date' ) {
'posts_per_page' => $per_page,
'no_found_rows' => false,
'post_status' => 'publish',