'form',
'plural' => 'forms',
'ajax' => false,
)
);
// Default number of forms to show per page
$this->per_page = apply_filters( 'wpforms_overview_per_page', 20 );
}
/**
* Retrieve the table columns.
*
* @since 1.0.0
* @return array $columns Array of all the list table columns.
*/
public function get_columns() {
$columns = array(
'cb' => '',
'form_name' => esc_html__( 'Name', 'wpforms-lite' ),
'shortcode' => esc_html__( 'Shortcode', 'wpforms-lite' ),
'created' => esc_html__( 'Created', 'wpforms-lite' ),
);
return apply_filters( 'wpforms_overview_table_columns', $columns );
}
/**
* Render the checkbox column.
*
* @since 1.0.0
*
* @param WP_Post $form
*
* @return string
*/
public function column_cb( $form ) {
return '';
}
/**
* Renders the columns.
*
* @since 1.0.0
*
* @param WP_Post $form
* @param string $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;
case 'created':
$value = get_the_date( get_option( 'date_format' ), $form );
break;
case 'modified':
$value = get_post_modified_time( get_option( 'date_format' ), false, $form );
break;
case 'author':
$author = get_userdata( $form->post_author );
$value = $author->display_name;
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 );
}
/**
* Render the form name column with action links.
*
* @since 1.0.0
*
* @param WP_Post $form
*
* @return string
*/
public function column_form_name( $form ) {
// Prepare variables.
$name = ! empty( $form->post_title ) ? $form->post_title : $form->post_name;
$name = sprintf(
'%s',
add_query_arg(
array(
'view' => 'fields',
'form_id' => $form->ID,
),
admin_url( 'admin.php?page=wpforms-builder' )
),
esc_html__( 'Edit This Form', 'wpforms-lite' ),
$name
);
// Build all of the row action links.
$row_actions = array();
// Edit.
$row_actions['edit'] = sprintf(
'%s',
add_query_arg(
array(
'view' => 'fields',
'form_id' => $form->ID,
),
admin_url( 'admin.php?page=wpforms-builder' )
),
esc_html__( 'Edit This Form', 'wpforms-lite' ),
esc_html__( 'Edit', 'wpforms-lite' )
);
// Entries.
$row_actions['entries'] = sprintf(
'%s',
add_query_arg(
array(
'view' => 'list',
'form_id' => $form->ID,
),
admin_url( 'admin.php?page=wpforms-entries' )
),
esc_html__( 'View entries', 'wpforms-lite' ),
esc_html__( 'Entries', 'wpforms-lite' )
);
// Preview.
$row_actions['preview_'] = sprintf(
'%s',
esc_url( wpforms_get_form_preview_url( $form->ID ) ),
esc_html__( 'View preview', 'wpforms-lite' ),
esc_html__( 'Preview', 'wpforms-lite' )
);
// Duplicate.
$row_actions['duplicate'] = sprintf(
'%s',
wp_nonce_url(
add_query_arg(
array(
'action' => 'duplicate',
'form_id' => $form->ID,
),
admin_url( 'admin.php?page=wpforms-overview' )
),
'wpforms_duplicate_form_nonce'
),
esc_html__( 'Duplicate this form', 'wpforms-lite' ),
esc_html__( 'Duplicate', 'wpforms-lite' )
);
// Delete.
$row_actions['delete'] = sprintf(
'%s',
wp_nonce_url(
add_query_arg(
array(
'action' => 'delete',
'form_id' => $form->ID,
),
admin_url( 'admin.php?page=wpforms-overview' )
),
'wpforms_delete_form_nonce'
),
esc_html__( 'Delete this form', 'wpforms-lite' ),
esc_html__( 'Delete', 'wpforms-lite' )
);
// Build the row action links and return the value.
return $name . $this->row_actions( apply_filters( 'wpforms_overview_row_actions', $row_actions, $form ) );
}
/**
* Define bulk actions available for our table listing.
*
* @since 1.0.0
*
* @return array
*/
public function get_bulk_actions() {
$actions = array(
'delete' => esc_html__( 'Delete', 'wpforms-lite' ),
);
return $actions;
}
/**
* Process the bulk actions.
*
* @since 1.0.0
*/
public function process_bulk_actions() {
$ids = isset( $_GET['form_id'] ) ? $_GET['form_id'] : array();
if ( ! is_array( $ids ) ) {
$ids = array( $ids );
}
$ids = array_map( 'absint', $ids );
$action = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : false; // phpcs:ignore
// Checking the sortable column link.
$is_orderby_link = ! empty( $_REQUEST['orderby'] ) && ! empty( $_REQUEST['order'] );
if ( empty( $ids ) || empty( $action ) || $is_orderby_link ) {
return;
}
// Delete one or multiple forms - both delete links and bulk actions.
if ( 'delete' === $this->current_action() ) {
if (
wp_verify_nonce( $_GET['_wpnonce'], 'bulk-forms' ) ||
wp_verify_nonce( $_GET['_wpnonce'], 'wpforms_delete_form_nonce' )
) {
foreach ( $ids as $id ) {
wpforms()->form->delete( $id );
}
?>