id ) { return; } add_screen_option( 'per_page', array( 'label' => esc_html__( 'Number of forms per page:', 'wpforms-lite' ), 'option' => 'wpforms_forms_per_page', 'default' => apply_filters( 'wpforms_overview_per_page', 20 ), ) ); } /** * Form table per-page screen option value. * * @since 1.0.0 * * @param bool $keep Whether to save or skip saving the screen option value. Default false. * @param string $option The option name. * @param int $value The number of rows to use. * * @return mixed */ public function screen_options_set( $keep, $option, $value ) { if ( 'wpforms_forms_per_page' === $option ) { return $value; } return $keep; } /** * Enqueue assets for the overview page. * * @since 1.0.0 */ public function enqueues() { // Hook for addons. do_action( 'wpforms_overview_enqueue' ); } /** * Build the output for the overview page. * * @since 1.0.0 */ public function output() { ?>

prepare_items(); ?>
items ) ) { // Output no forms screen. echo wpforms_render( 'admin/empty-states/no-forms' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } else { ?>
views(); ?> display(); ?>
'info', /* translators: %s - Deleted forms count. */ 'msg' => sprintf( _n( '%s form was successfully deleted.', '%s forms were successfully deleted.', $deleted, 'wpforms-lite' ), $deleted ), ); } if ( $duplicated && 'error' !== $duplicated ) { $notice = array( 'type' => 'info', /* translators: %s - Duplicated forms count. */ 'msg' => sprintf( _n( '%s form was successfully duplicated.', '%s forms were successfully duplicated.', $duplicated, 'wpforms-lite' ), $duplicated ), ); } if ( 'error' === $deleted || 'error' === $duplicated ) { $notice = array( 'type' => 'error', 'msg' => esc_html__( 'Security check failed. Please try again.', 'wpforms-lite' ), ); } if ( ! empty( $notice ) ) { \WPForms\Admin\Notice::add( $notice['msg'], $notice['type'] ); } } /** * Process the bulk table actions. * * @since 1.5.7 */ public function process_bulk_actions() { $ids = isset( $_GET['form_id'] ) ? array_map( 'absint', (array) $_GET['form_id'] ) : array(); // phpcs:ignore WordPress.Security.NonceVerification $action = ! empty( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification if ( $action === '-1' ) { $action = ! empty( $_REQUEST['action2'] ) ? sanitize_key( $_REQUEST['action2'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification } // Checking the sortable column link. $is_orderby_link = ! empty( $_REQUEST['orderby'] ) && ! empty( $_REQUEST['order'] ); if ( empty( $ids ) || empty( $action ) || $is_orderby_link ) { return; } // Check exact action values. if ( ! in_array( $action, [ 'delete', 'duplicate' ], true ) ) { return; } if ( empty( $_GET['_wpnonce'] ) ) { return; } // Check the nonce. if ( ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'bulk-forms' ) && ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'wpforms_' . $action . '_form_nonce' ) ) { return; } // Check that we have a method for this action. if ( ! method_exists( $this, 'bulk_action_' . $action . '_forms' ) ) { return; } $processed_forms = count( $this->{'bulk_action_' . $action . '_forms'}( $ids ) ); // Unset get vars and perform redirect to avoid action reuse. wp_safe_redirect( add_query_arg( $action . 'd', $processed_forms, remove_query_arg( array( 'action', 'action2', '_wpnonce', 'form_id', 'paged', '_wp_http_referer' ) ) ) ); exit; } /** * Delete forms. * * @since 1.5.7 * * @param array $ids Form ids to delete. * * @return array List of deleted forms. */ private function bulk_action_delete_forms( $ids ) { if ( ! is_array( $ids ) ) { return []; } $deleted = []; foreach ( $ids as $id ) { $deleted[ $id ] = wpforms()->form->delete( $id ); } return array_keys( array_filter( $deleted ) ); } /** * Duplicate forms. * * @since 1.5.7 * * @param array $ids Form ids to duplicate. * * @return array List of duplicated forms. */ private function bulk_action_duplicate_forms( $ids ) { if ( ! is_array( $ids ) ) { return []; } if ( ! wpforms_current_user_can( 'create_forms' ) ) { return []; } $duplicated = []; foreach ( $ids as $id ) { if ( wpforms_current_user_can( 'view_form_single', $id ) ) { $duplicated[ $id ] = wpforms()->form->duplicate( $id ); } } return array_keys( array_filter( $duplicated ) ); } /** * Remove certain arguments from a query string that WordPress should always hide for users. * * @since 1.5.7 * * @param array $removable_query_args An array of parameters to remove from the URL. * * @return array Extended/filtered array of parameters to remove from the URL. */ public function removable_query_args( $removable_query_args ) { if ( wpforms_is_admin_page( 'overview' ) ) { $removable_query_args[] = 'duplicated'; } return $removable_query_args; } } new WPForms_Overview();