'form',
'plural' => 'forms',
'ajax' => false,
]
);
add_filter( 'default_hidden_columns', [ $this, 'default_hidden_columns' ], 10, 2 );
// Determine the current view.
$this->view = wpforms()->get( 'forms_views' )->get_current_view();
// Default number of forms to show per page.
$this->per_page = (int) apply_filters( 'wpforms_overview_per_page', 20 );
}
/**
* Get the instance of a class and store it in itself.
*
* @since 1.7.5
*/
public static function get_instance() {
static $instance;
if ( ! $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Retrieve the table columns.
*
* @since 1.0.0
*
* @return array $columns Array of all the list table columns.
*/
public function get_columns() {
$columns = [
'cb' => '',
'name' => esc_html__( 'Name', 'wpforms-lite' ),
'tags' => esc_html__( 'Tags', 'wpforms-lite' ),
'author' => esc_html__( 'Author', 'wpforms-lite' ),
'shortcode' => esc_html__( 'Shortcode', 'wpforms-lite' ),
'created' => esc_html__( 'Date', 'wpforms-lite' ),
];
if ( LiteConnect::is_allowed() && LiteConnect::is_enabled() ) {
$columns['entries'] = esc_html__( 'Entries', 'wpforms-lite' );
}
return apply_filters( 'wpforms_overview_table_columns', $columns );
}
/**
* Render the checkbox column.
*
* @since 1.0.0
*
* @param WP_Post $form Form.
*
* @return string
*/
public function column_cb( $form ) {
return '';
}
/**
* Render the columns.
*
* @since 1.0.0
*
* @param WP_Post $form CPT object as a form representation.
* @param string $column_name Column Name.
*
* @return string
*/
public function column_default( $form, $column_name ) {
switch ( $column_name ) {
case 'id':
$value = $form->ID;
break;
case 'shortcode':
$value = '[wpforms id="' . $form->ID . '"]';
break;
// This slug is not changed to 'date' for backward compatibility.
case 'created':
if ( gmdate( 'Ymd', strtotime( $form->post_date ) ) === gmdate( 'Ymd', strtotime( $form->post_modified ) ) ) {
$value = wp_kses(
sprintf( /* translators: %1$s - Post created date. */
__( 'Created
%1$s', 'wpforms-lite' ),
esc_html( wpforms_datetime_format( $form->post_date ) )
),
[ 'br' => [] ]
);
} else {
$value = wp_kses(
sprintf( /* translators: %1$s - Post modified date. */
__( 'Last Modified
%1$s', 'wpforms-lite' ),
esc_html( wpforms_datetime_format( $form->post_modified ) )
),
[ 'br' => [] ]
);
}
break;
case 'entries':
$value = sprintf(
'%s%d',
esc_url( admin_url( 'admin.php?page=wpforms-entries' ) ),
esc_attr__( 'Entries are securely backed up in the cloud. Upgrade to restore.', 'wpforms-lite' ),
'',
LiteConnectIntegration::get_form_entries_count( $form->ID )
);
break;
case 'modified':
$value = get_post_modified_time( get_option( 'date_format' ), false, $form );
break;
case 'author':
$value = '';
$author = get_userdata( $form->post_author );
if ( ! $author ) {
break;
}
$value = $author->display_name;
$user_edit_url = get_edit_user_link( $author->ID );
if ( ! empty( $user_edit_url ) ) {
$value = '' . esc_html( $value ) . '';
}
break;
case 'php':
$value = 'if( function_exists( \'wpforms_get\' ) ){ wpforms_get( ' . $form->ID . ' ); }
';
break;
default:
$value = '';
}
return apply_filters( 'wpforms_overview_table_column_value', $value, $form, $column_name );
}
/**
* Filter the default list of hidden columns.
*
* @since 1.7.2
*
* @param string[] $hidden Array of IDs of columns hidden by default.
* @param WP_Screen $screen WP_Screen object of the current screen.
*
* @return string[]
*/
public function default_hidden_columns( $hidden, $screen ) {
if ( $screen->id !== 'toplevel_page_wpforms-overview' ) {
return $hidden;
}
return [
'tags',
'author',
Locator::COLUMN_NAME,
];
}
/**
* Render the form name column with action links.
*
* @since 1.0.0
*
* @param WP_Post $form Form.
*
* @return string
*/
public function column_name( $form ) {
// Build the row action links and return the value.
return $this->get_column_name_title( $form ) . $this->get_column_name_row_actions( $form );
}
/**
* Render the form tags column.
*
* @since 1.7.5
*
* @param WP_Post $form Form.
*
* @return string
*/
public function column_tags( $form ) {
return wpforms()->get( 'forms_tags' )->column_tags( $form );
}
/**
* Get the form name HTML for the form name column.
*
* @since 1.5.8
*
* @param WP_Post $form Form object.
*
* @return string
*/
protected function get_column_name_title( $form ) {
$title = ! empty( $form->post_title ) ? $form->post_title : $form->post_name;
$name = sprintf(
'%s',
esc_html( $title )
);
if ( $this->view === 'trash' ) {
return $name;
}
if ( wpforms_current_user_can( 'view_form_single', $form->ID ) ) {
$name = sprintf(
'%s',
esc_url( wpforms_get_form_preview_url( $form->ID ) ),
esc_attr__( 'View preview', 'wpforms-lite' ),
esc_html( $title )
);
}
if ( wpforms_current_user_can( 'view_entries_form_single', $form->ID ) ) {
$name = sprintf(
'%s',
esc_url(
add_query_arg(
[
'view' => 'list',
'form_id' => $form->ID,
],
admin_url( 'admin.php?page=wpforms-entries' )
)
),
esc_attr__( 'View entries', 'wpforms-lite' ),
esc_html( $title )
);
}
if ( wpforms_current_user_can( 'edit_form_single', $form->ID ) ) {
$name = sprintf(
'%s',
esc_url(
add_query_arg(
[
'view' => 'fields',
'form_id' => $form->ID,
],
admin_url( 'admin.php?page=wpforms-builder' )
)
),
esc_attr__( 'Edit This Form', 'wpforms-lite' ),
esc_html( $title )
);
}
return $name;
}
/**
* Get the row actions HTML for the form name column.
*
* @since 1.5.8
*
* @param WP_Post $form Form object.
*
* @return string
*/
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.
*
* @since 1.0.0
*
* @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
}
/**
* Define bulk actions available for our table listing.
*
* @since 1.0.0
*
* @return array
*/
public function get_bulk_actions() {
return wpforms()->get( 'forms_bulk_actions' )->get_dropdown_items();
}
/**
* Generate the table navigation above or below the table.
*
* @since 1.7.2
*
* @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 );
return;
}
// Otherwise, display bulk actions menu and "0 items" on the right (pagination).
?>