C:\xampp\htdocs\landing\wp-content\plugins\wpforms-lite\includes\admin\overview\class-overview.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php

/**
 * Primary overview page inside the admin which lists all forms.
 *
 * @since 1.0.0
 */
class WPForms_Overview {

    
/**
     * Primary class constructor.
     *
     * @since 1.0.0
     */
    
public function __construct() {

        
// Maybe load overview page.
        
add_action'admin_init', array( $this'init' ) );

        
// Setup screen options. Needs to be here as admin_init hook it too late.
        
add_action'load-toplevel_page_wpforms-overview', array( $this'screen_options' ) );
        
add_filter'set-screen-option', array( $this'screen_options_set' ), 10);
        
add_filter'set_screen_option_wpforms_forms_per_page', [ $this'screen_options_set' ], 10);
    }

    
/**
     * Determine if the user is viewing the overview page, if so, party on.
     *
     * @since 1.0.0
     */
    
public function init() {

        
// Only load if we are actually on the overview page.
        
if ( ! wpforms_is_admin_page'overview' ) ) {
            return;
        }

        
// Bulk actions.
        
add_action'load-toplevel_page_wpforms-overview', array( $this'notices' ) );
        
add_action'load-toplevel_page_wpforms-overview', array( $this'process_bulk_actions' ) );
        
add_filter'removable_query_args', array( $this'removable_query_args' ) );

        
// The overview page leverages WP_List_Table so we must load it.
        
if ( ! class_exists'WP_List_Table'false ) ) {
            require_once 
ABSPATH 'wp-admin/includes/class-wp-list-table.php';
        }

        
// Load the class that builds the overview table.
        
require_once WPFORMS_PLUGIN_DIR 'includes/admin/overview/class-overview-table.php';

        
add_action'admin_enqueue_scripts', array( $this'enqueues' ) );
        
add_action'wpforms_admin_page', array( $this'output' ) );

        
// Provide hook for addons.
        
do_action'wpforms_overview_init' );
    }

    
/**
     * Add per-page screen option to the Forms table.
     *
     * @since 1.0.0
     */
    
public function screen_options() {

        
$screen get_current_screen();

        if ( 
null === $screen || 'toplevel_page_wpforms-overview' !== $screen->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() {

        
?>
        <div id="wpforms-overview" class="wrap wpforms-admin-wrap">

            <h1 class="page-title">
                <?php esc_html_e'Forms Overview''wpforms-lite' ); ?>
                <?php if ( wpforms_current_user_can'create_forms' ) ) : ?>
                    <a href="<?php echo esc_urladmin_url'admin.php?page=wpforms-builder&view=setup' ) ); ?>" class="add-new-h2 wpforms-btn-orange">
                        <?php esc_html_e'Add New''wpforms-lite' ); ?>
                    </a>
                <?php endif; ?>
            </h1>

            <?php
            $overview_table 
= new WPForms_Overview_Table();
            
$overview_table->prepare_items();
            
?>

            <div class="wpforms-admin-content">

                <?php

                do_action
'wpforms_admin_overview_before_table' );

                if ( empty( 
$overview_table->items ) ) {

                    
// Output no forms screen.
                    
echo wpforms_render'admin/empty-states/no-forms' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

                
} else {
                
?>
                    <form id="wpforms-overview-table" method="get" action="<?php echo esc_urladmin_url'admin.php?page=wpforms-overview' ) ); ?>">

                        <input type="hidden" name="post_type" value="wpforms" />
                        <input type="hidden" name="page" value="wpforms-overview" />

                        <?php $overview_table->views(); ?>
                        <?php $overview_table->display(); ?>

                    </form>
                <?php ?>

            </div>

        </div>
        <?php
    
}

    
/**
     * Add admin action notices and process bulk actions.
     *
     * @since 1.5.7
     */
    
public function notices() {

        
$deleted    = ! empty( $_REQUEST['deleted'] ) ? sanitize_key$_REQUEST['deleted'] ) : false// phpcs:ignore WordPress.Security.NonceVerification
        
$duplicated = ! empty( $_REQUEST['duplicated'] ) ? sanitize_key$_REQUEST['duplicated'] ) : false// phpcs:ignore WordPress.Security.NonceVerification
        
$notice     = array();

        if ( 
$deleted && 'error' !== $deleted ) {
            
$notice = array(
                
'type' => '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_noncesanitize_key$_GET['_wpnonce'] ), 'bulk-forms' ) &&
            ! 
wp_verify_noncesanitize_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_keysarray_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_keysarray_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();
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586