PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.2.2
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.2.2
4.17.2 4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Admin / SettingsPages / FormList.php
wp-user-avatar / src / Admin / SettingsPages Last commit date
DragDropBuilder 4 years ago EmailSettings 4 years ago AbstractSettingsPage.php 4 years ago AddNewForm.php 4 years ago AdminFooter.php 5 years ago ExtensionsSettingsPage.php 4 years ago FormList.php 5 years ago Forms.php 4 years ago GeneralSettings.php 4 years ago IDUserColumn.php 5 years ago MailOptin.php 4 years ago MemberDirectories.php 4 years ago MembersDirectoryList.php 5 years ago ToolsSettingsPage.php 4 years ago index.php 5 years ago
FormList.php
429 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages;
4
5 use ProfilePress\Core\Base;
6 use ProfilePress\Core\Classes\ExtensionManager;
7 use ProfilePress\Core\Classes\FormRepository as FR;
8 use ProfilePress\Core\Themes\Shortcode\ThemesRepository as ShortcodeThemesRepository;
9 use ProfilePress\Core\Themes\DragDrop\ThemesRepository as DragDropThemesRepository;
10
11 if ( ! class_exists('WP_List_Table')) {
12 require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
13 }
14
15 class FormList extends \WP_List_Table
16 {
17 private $table;
18
19 /** @var \wpdb */
20 private $wpdb;
21
22 public function __construct($wpdb)
23 {
24 $this->wpdb = $wpdb;
25 $this->table = Base::form_db_table();
26 parent::__construct(array(
27 'singular' => esc_html__('form', 'wp-user-avatar'), //singular name of the listed records
28 'plural' => esc_html__('forms', 'wp-user-avatar'), //plural name of the listed records
29 'ajax' => false //does this table support ajax?
30 )
31 );
32 }
33
34 public function get_forms($per_page, $current_page = 1, $form_type = '')
35 {
36 $per_page = absint($per_page);
37 $current_page = absint($current_page);
38 $form_type = ! empty($form_type) ? sanitize_text_field($form_type) : FR::LOGIN_TYPE;
39
40 $offset = ($current_page - 1) * $per_page;
41 $sql = "SELECT * FROM $this->table";
42 $args = [];
43
44 $sql .= " WHERE form_type = %s";
45 $args[] = $form_type;
46
47 $sql .= " ORDER BY date DESC";
48
49 $args[] = $per_page;
50
51 $sql .= " LIMIT %d";
52 if ($current_page > 1) {
53 $args[] = $offset;
54 $sql .= " OFFSET %d";
55 }
56
57 $result = $this->wpdb->get_results(
58 $this->wpdb->prepare($sql, $args),
59 'ARRAY_A'
60 );
61
62 if ( ! ExtensionManager::is_premium()) {
63 $shortcode_premium_theme_classes = wp_list_pluck(ShortcodeThemesRepository::premiumThemes(), 'theme_class');
64 $dnd_premium_theme_classes = wp_list_pluck(DragDropThemesRepository::premiumThemes(), 'theme_class');
65
66 $filtered = [];
67 foreach ($result as $form) {
68
69 $builder_type = $form['builder_type'];
70 $form_type = $form['form_type'];
71 $form_id = $form['form_id'];
72
73 $form_class = FR::get_form_class($form_id, $form_type);
74
75 if ($builder_type == FR::SHORTCODE_BUILDER_TYPE &&
76 ! in_array($form_class, $shortcode_premium_theme_classes)
77 ) {
78 $filtered[] = $form;
79 }
80
81 if ($builder_type == FR::DRAG_DROP_BUILDER_TYPE &&
82 ! in_array($form_class, $dnd_premium_theme_classes)
83 ) {
84 $filtered[] = $form;
85 }
86
87 }
88
89 $result = $filtered;
90 }
91
92 return $result;
93 }
94
95 /**
96 * Returns the count of records in the database.
97 *
98 * @param string $form_type
99 *
100 * @return null|string
101 */
102 public function record_count($form_type = '')
103 {
104 $form_type = ! empty($form_type) ? sanitize_text_field($form_type) : FR::LOGIN_TYPE;
105
106 $sql = "SELECT COUNT(*) FROM $this->table";
107 if ( ! empty($form_type)) {
108 $form_type = esc_sql($form_type);
109 $sql .= " WHERE form_type = '$form_type'";
110 }
111
112 return $this->wpdb->get_var($sql);
113 }
114
115 public static function customize_url($form_id, $form_type, $builder_type = FR::SHORTCODE_BUILDER_TYPE)
116 {
117 $slug = $form_type == FR::MEMBERS_DIRECTORY_TYPE ? PPRESS_MEMBER_DIRECTORIES_SLUG : PPRESS_FORMS_SETTINGS_SLUG;
118
119 $url = admin_url(
120 sprintf(
121 'admin.php?page=%s&view=edit-shortcode-%s&id=%d',
122 $slug,
123 sanitize_text_field($form_type),
124 absint($form_id)
125 )
126 );
127
128 if ($builder_type == FR::DRAG_DROP_BUILDER_TYPE) {
129
130 $url = admin_url(
131 sprintf(
132 'admin.php?page=%s&view=drag-drop-builder&form-type=%s&id=%d',
133 $slug,
134 sanitize_text_field($form_type),
135 absint($form_id)
136 )
137 );
138 }
139
140 return esc_url_raw($url);
141 }
142
143 public static function delete_url($form_id, $form_type)
144 {
145 return esc_url_raw(admin_url(
146 sprintf(
147 'admin.php?page=pp-forms&action=delete&form_type=%s&id=%d&_wpnonce=%s',
148 sanitize_text_field($form_type),
149 absint($form_id),
150 ppress_create_nonce()
151 )
152 ));
153 }
154
155 public static function clone_url($form_id, $form_type)
156 {
157 return esc_url_raw(admin_url(
158 sprintf(
159 'admin.php?page=pp-forms&action=clone&form_type=%s&id=%d&_wpnonce=%s',
160 sanitize_text_field($form_type),
161 absint($form_id),
162 ppress_create_nonce()
163 )
164 ));
165 }
166
167 public static function preview_url($form_id, $form_type)
168 {
169 return esc_url_raw(add_query_arg(['pp_preview_form' => $form_id, 'type' => $form_type], home_url()));
170 }
171
172 /**
173 * Text displayed when no email optin form is available
174 */
175 public function no_items()
176 {
177 printf(
178 esc_html__('No form is currently available. %sConsider creating one%s', 'wp-user-avatar'),
179 '<a href="' . add_query_arg('view', 'add-new-form', PPRESS_FORMS_SETTINGS_PAGE) . '">',
180 '</a>'
181 );
182 }
183
184 /**
185 * Associative array of columns
186 *
187 * @return array
188 */
189 public function get_columns()
190 {
191 $columns = array(
192 'cb' => '<input type="checkbox" />',
193 'title' => esc_html__('Title', 'wp-user-avatar'),
194 'shortcode' => esc_html__('Shortcode', 'wp-user-avatar'),
195 'builder' => esc_html__('Builder Type', 'wp-user-avatar'),
196 'date' => esc_html__('Date', 'wp-user-avatar')
197 );
198
199 if ( ! class_exists('ProfilePress\Libsodium\Libsodium')) {
200 unset($columns['builder']);
201 }
202
203 return $columns;
204 }
205
206 /**
207 * Render the bulk edit checkbox
208 *
209 * @param array $item
210 *
211 * @return string
212 */
213 function column_cb($item)
214 {
215 return sprintf(
216 '<input type="checkbox" name="form_id[]" value="%s" />', $item['form_id']
217 );
218 }
219
220 /**
221 * Method for Title column
222 *
223 * @param array $item an array of DB data
224 *
225 * @return string
226 */
227 public function column_title($item)
228 {
229 $form_id = absint($item['form_id']);
230 $form_type = sanitize_text_field($item['form_type']);
231 $builder_type = sanitize_text_field($item['builder_type']);
232 $customize_url = esc_url(self::customize_url($form_id, $form_type, $builder_type));
233 $delete_url = esc_url(self::delete_url($form_id, $form_type));
234 $clone_url = esc_url(self::clone_url($form_id, $form_type));
235 $preview_url = esc_url(self::preview_url($form_id, $form_type));
236
237 $actions = array(
238 'edit' => sprintf("<a href='%s'>%s</a>", $customize_url, esc_attr__('Edit', 'wp-user-avatar')),
239 'delete' => sprintf("<a class='pp-form-delete' href='%s'>%s</a>", $delete_url, esc_attr__('Delete', 'wp-user-avatar')),
240 'clone' => sprintf("<a href='%s'>%s</a>", $clone_url, esc_attr__('Duplicate', 'wp-user-avatar')),
241 // using form prefix cos there is a preview admin class that floats element to the right
242 'form-preview' => sprintf("<a target='_blank' href='%s'>%s</a>", $preview_url, esc_attr__('Preview', 'wp-user-avatar'))
243 );
244
245 $name = '<strong><a href="' . $customize_url . '">' . $item['name'] . '</a></strong>';
246
247
248 return $name . $this->row_actions($actions);
249 }
250
251 /**
252 * Method for Shortcode column
253 *
254 * @param array $item an array of DB data
255 *
256 * @return string
257 */
258 public function column_shortcode($item)
259 {
260 $form_type = sanitize_text_field($item['form_type']);
261
262 $shortcode = sprintf('[profilepress-%s id="%s"]', $form_type, absint($item['form_id']));
263
264 $output = '<input type="text" onfocus="this.select();" readonly="readonly" value="' . esc_attr($shortcode) . '" class="shortcode-in-list-table" />';
265
266 return $output;
267 }
268
269 public function column_builder($item)
270 {
271 $builder_type = esc_html__('Shortcode', 'wp-user-avatar');
272 if ($item['builder_type'] == FR::DRAG_DROP_BUILDER_TYPE) {
273 $builder_type = esc_html__('Drag & Drop', 'wp-user-avatar');
274 }
275
276 return $builder_type;
277 }
278
279 public function column_default($item, $column_name)
280 {
281 switch ($column_name) {
282 case 'date' :
283 $value = mysql2date('F j, Y', $item['date']);
284 break;
285 default:
286 $value = $item[$column_name];
287 break;
288 }
289
290 return apply_filters('ppress_forms_table_column', $value, $item, $column_name);
291 }
292
293 /**
294 * Columns to make sortable.
295 *
296 * @return array
297 */
298 public function get_sortable_columns()
299 {
300 $sortable_columns = array(
301 'name' => array('name', true),
302 );
303
304 return $sortable_columns;
305 }
306
307 /**
308 * Returns an associative array containing the bulk action
309 *
310 * @return array
311 */
312 public function get_bulk_actions()
313 {
314 $actions = array(
315 'bulk-delete' => esc_html__('Delete', 'wp-user-avatar'),
316 );
317
318 return $actions;
319 }
320
321 /**
322 * Handles data query and filter, sorting, and pagination.
323 *
324 * @param string $form_type
325 */
326 public function prepare_items($form_type = '')
327 {
328 if (isset($_GET['page']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG && ! empty($_GET['form-type'])) {
329 $form_type = sanitize_text_field($_GET['form-type']);
330 }
331
332 $this->_column_headers = $this->get_column_info();
333 /** Process bulk action */
334 $this->process_actions();
335 $per_page = $this->get_items_per_page('forms_per_page', 10);
336 $current_page = $this->get_pagenum();
337 $total_items = self::record_count($form_type);
338 $this->set_pagination_args([
339 'total_items' => $total_items, //WE have to calculate the total number of items
340 'per_page' => $per_page //WE have to determine how many items to show on a page
341 ]);
342
343 $this->items = $this->get_forms($per_page, $current_page, $form_type);
344 }
345
346 public function process_actions()
347 {
348 // Bail if user is not an admin or without admin privileges.
349 if ( ! current_user_can('manage_options')) return;
350
351 if ('delete' === $this->current_action()) {
352
353 if ( ! ppress_verify_nonce()) wp_nonce_ays(ppress_nonce_action_string());
354
355 $form_id = absint($_GET['id']);
356 $form_type = sanitize_text_field($_GET['form_type']);
357
358 FR::delete_form($form_id, $form_type);
359
360 $url = PPRESS_FORMS_SETTINGS_PAGE;
361
362 if (isset($_GET['form_type'])) {
363
364 $url = add_query_arg('form-type', sanitize_text_field($_GET['form_type']), $url);
365
366 if (FR::MEMBERS_DIRECTORY_TYPE == $_GET['form_type']) {
367 $url = PPRESS_MEMBER_DIRECTORIES_SETTINGS_PAGE;
368 }
369 }
370
371
372 wp_safe_redirect($url);
373 exit;
374
375 }
376
377 if ('clone' === $this->current_action()) {
378
379 if ( ! ppress_verify_nonce()) wp_nonce_ays(ppress_nonce_action_string());
380
381 $form_id = absint($_GET['id']);
382 $form_type = sanitize_text_field($_GET['form_type']);
383
384 FR::clone_form($form_id, $form_type);
385
386 $url = PPRESS_FORMS_SETTINGS_PAGE;
387
388 if (isset($_GET['form_type'])) {
389 $url = add_query_arg('form-type', sanitize_text_field($_GET['form_type']), $url);
390
391 if (FR::MEMBERS_DIRECTORY_TYPE == $_GET['form_type']) {
392 $url = PPRESS_MEMBER_DIRECTORIES_SETTINGS_PAGE;
393 }
394 }
395
396 wp_safe_redirect($url);
397 exit;
398 }
399
400 // Detect when a bulk action is being triggered...
401 if ('bulk-delete' == $this->current_action()) {
402 check_admin_referer('bulk-' . $this->_args['plural']);
403 $form_ids = array_map('absint', $_POST['form_id']);
404
405 foreach ($form_ids as $form_id) {
406 $form_type = ! empty($_GET['form-type']) ? sanitize_text_field($_GET['form-type']) : FR::LOGIN_TYPE;
407 if (isset($_GET['page']) && $_GET['page'] == PPRESS_MEMBER_DIRECTORIES_SLUG) {
408 $form_type = FR::MEMBERS_DIRECTORY_TYPE;
409 }
410
411 FR::delete_form($form_id, $form_type);
412 }
413 }
414 }
415
416 /**
417 * @return FormList
418 */
419 public static function get_instance()
420 {
421 static $instance = null;
422
423 if (is_null($instance)) {
424 $instance = new static($GLOBALS['wpdb']);
425 }
426
427 return $instance;
428 }
429 }