PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.0.3
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.0.3
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 Membership 4 years ago AbstractSettingsPage.php 4 years ago AddNewForm.php 4 years ago AdminFooter.php 4 years ago ExtensionsSettingsPage.php 4 years ago FormList.php 4 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
431 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=%s&action=delete&form_type=%s&id=%d&_wpnonce=%s',
148 PPRESS_FORMS_SETTINGS_SLUG,
149 sanitize_text_field($form_type),
150 absint($form_id),
151 ppress_create_nonce()
152 )
153 ));
154 }
155
156 public static function clone_url($form_id, $form_type)
157 {
158 return esc_url_raw(admin_url(
159 sprintf(
160 'admin.php?page=%s&action=clone&form_type=%s&id=%d&_wpnonce=%s',
161 PPRESS_FORMS_SETTINGS_SLUG,
162 sanitize_text_field($form_type),
163 absint($form_id),
164 ppress_create_nonce()
165 )
166 ));
167 }
168
169 public static function preview_url($form_id, $form_type)
170 {
171 return esc_url_raw(add_query_arg(['pp_preview_form' => $form_id, 'type' => $form_type], home_url()));
172 }
173
174 /**
175 * Text displayed when no email optin form is available
176 */
177 public function no_items()
178 {
179 printf(
180 esc_html__('No form is currently available. %sConsider creating one%s', 'wp-user-avatar'),
181 '<a href="' . add_query_arg('view', 'add-new-form', PPRESS_FORMS_SETTINGS_PAGE) . '">',
182 '</a>'
183 );
184 }
185
186 /**
187 * Associative array of columns
188 *
189 * @return array
190 */
191 public function get_columns()
192 {
193 $columns = array(
194 'cb' => '<input type="checkbox" />',
195 'title' => esc_html__('Title', 'wp-user-avatar'),
196 'shortcode' => esc_html__('Shortcode', 'wp-user-avatar'),
197 'builder' => esc_html__('Builder Type', 'wp-user-avatar'),
198 'date' => esc_html__('Date', 'wp-user-avatar')
199 );
200
201 if ( ! class_exists('ProfilePress\Libsodium\Libsodium')) {
202 unset($columns['builder']);
203 }
204
205 return $columns;
206 }
207
208 /**
209 * Render the bulk edit checkbox
210 *
211 * @param array $item
212 *
213 * @return string
214 */
215 function column_cb($item)
216 {
217 return sprintf(
218 '<input type="checkbox" name="form_id[]" value="%s" />', $item['form_id']
219 );
220 }
221
222 /**
223 * Method for Title column
224 *
225 * @param array $item an array of DB data
226 *
227 * @return string
228 */
229 public function column_title($item)
230 {
231 $form_id = absint($item['form_id']);
232 $form_type = sanitize_text_field($item['form_type']);
233 $builder_type = sanitize_text_field($item['builder_type']);
234 $customize_url = esc_url(self::customize_url($form_id, $form_type, $builder_type));
235 $delete_url = esc_url(self::delete_url($form_id, $form_type));
236 $clone_url = esc_url(self::clone_url($form_id, $form_type));
237 $preview_url = esc_url(self::preview_url($form_id, $form_type));
238
239 $actions = array(
240 'edit' => sprintf("<a href='%s'>%s</a>", $customize_url, esc_attr__('Edit', 'wp-user-avatar')),
241 'delete' => sprintf("<a class='pp-form-delete' href='%s'>%s</a>", $delete_url, esc_attr__('Delete', 'wp-user-avatar')),
242 'clone' => sprintf("<a href='%s'>%s</a>", $clone_url, esc_attr__('Duplicate', 'wp-user-avatar')),
243 // using form prefix cos there is a preview admin class that floats element to the right
244 'form-preview' => sprintf("<a target='_blank' href='%s'>%s</a>", $preview_url, esc_attr__('Preview', 'wp-user-avatar'))
245 );
246
247 $name = '<strong><a href="' . $customize_url . '">' . $item['name'] . '</a></strong>';
248
249
250 return $name . $this->row_actions($actions);
251 }
252
253 /**
254 * Method for Shortcode column
255 *
256 * @param array $item an array of DB data
257 *
258 * @return string
259 */
260 public function column_shortcode($item)
261 {
262 $form_type = sanitize_text_field($item['form_type']);
263
264 $shortcode = sprintf('[profilepress-%s id="%s"]', $form_type, absint($item['form_id']));
265
266 $output = '<input type="text" onfocus="this.select();" readonly="readonly" value="' . esc_attr($shortcode) . '" class="shortcode-in-list-table" />';
267
268 return $output;
269 }
270
271 public function column_builder($item)
272 {
273 $builder_type = esc_html__('Shortcode', 'wp-user-avatar');
274 if ($item['builder_type'] == FR::DRAG_DROP_BUILDER_TYPE) {
275 $builder_type = esc_html__('Drag & Drop', 'wp-user-avatar');
276 }
277
278 return $builder_type;
279 }
280
281 public function column_default($item, $column_name)
282 {
283 switch ($column_name) {
284 case 'date' :
285 $value = mysql2date('F j, Y', $item['date']);
286 break;
287 default:
288 $value = $item[$column_name];
289 break;
290 }
291
292 return apply_filters('ppress_forms_table_column', $value, $item, $column_name);
293 }
294
295 /**
296 * Columns to make sortable.
297 *
298 * @return array
299 */
300 public function get_sortable_columns()
301 {
302 $sortable_columns = array(
303 'name' => array('name', true),
304 );
305
306 return $sortable_columns;
307 }
308
309 /**
310 * Returns an associative array containing the bulk action
311 *
312 * @return array
313 */
314 public function get_bulk_actions()
315 {
316 $actions = array(
317 'bulk-delete' => esc_html__('Delete', 'wp-user-avatar'),
318 );
319
320 return $actions;
321 }
322
323 /**
324 * Handles data query and filter, sorting, and pagination.
325 *
326 * @param string $form_type
327 */
328 public function prepare_items($form_type = '')
329 {
330 if (isset($_GET['page']) && $_GET['page'] == PPRESS_FORMS_SETTINGS_SLUG && ! empty($_GET['form-type'])) {
331 $form_type = sanitize_text_field($_GET['form-type']);
332 }
333
334 $this->_column_headers = $this->get_column_info();
335 /** Process bulk action */
336 $this->process_actions();
337 $per_page = $this->get_items_per_page('forms_per_page', 10);
338 $current_page = $this->get_pagenum();
339 $total_items = self::record_count($form_type);
340 $this->set_pagination_args([
341 'total_items' => $total_items, //WE have to calculate the total number of items
342 'per_page' => $per_page //WE have to determine how many items to show on a page
343 ]);
344
345 $this->items = $this->get_forms($per_page, $current_page, $form_type);
346 }
347
348 public function process_actions()
349 {
350 // Bail if user is not an admin or without admin privileges.
351 if ( ! current_user_can('manage_options')) return;
352
353 if ('delete' === $this->current_action()) {
354
355 if ( ! ppress_verify_nonce()) wp_nonce_ays(ppress_nonce_action_string());
356
357 $form_id = absint($_GET['id']);
358 $form_type = sanitize_text_field($_GET['form_type']);
359
360 FR::delete_form($form_id, $form_type);
361
362 $url = PPRESS_FORMS_SETTINGS_PAGE;
363
364 if (isset($_GET['form_type'])) {
365
366 $url = add_query_arg('form-type', sanitize_text_field($_GET['form_type']), $url);
367
368 if (FR::MEMBERS_DIRECTORY_TYPE == $_GET['form_type']) {
369 $url = PPRESS_MEMBER_DIRECTORIES_SETTINGS_PAGE;
370 }
371 }
372
373
374 wp_safe_redirect($url);
375 exit;
376
377 }
378
379 if ('clone' === $this->current_action()) {
380
381 if ( ! ppress_verify_nonce()) wp_nonce_ays(ppress_nonce_action_string());
382
383 $form_id = absint($_GET['id']);
384 $form_type = sanitize_text_field($_GET['form_type']);
385
386 FR::clone_form($form_id, $form_type);
387
388 $url = PPRESS_FORMS_SETTINGS_PAGE;
389
390 if (isset($_GET['form_type'])) {
391 $url = add_query_arg('form-type', sanitize_text_field($_GET['form_type']), $url);
392
393 if (FR::MEMBERS_DIRECTORY_TYPE == $_GET['form_type']) {
394 $url = PPRESS_MEMBER_DIRECTORIES_SETTINGS_PAGE;
395 }
396 }
397
398 wp_safe_redirect($url);
399 exit;
400 }
401
402 // Detect when a bulk action is being triggered...
403 if ('bulk-delete' == $this->current_action()) {
404 check_admin_referer('bulk-' . $this->_args['plural']);
405 $form_ids = array_map('absint', $_POST['form_id']);
406
407 foreach ($form_ids as $form_id) {
408 $form_type = ! empty($_GET['form-type']) ? sanitize_text_field($_GET['form-type']) : FR::LOGIN_TYPE;
409 if (isset($_GET['page']) && $_GET['page'] == PPRESS_MEMBER_DIRECTORIES_SLUG) {
410 $form_type = FR::MEMBERS_DIRECTORY_TYPE;
411 }
412
413 FR::delete_form($form_id, $form_type);
414 }
415 }
416 }
417
418 /**
419 * @return FormList
420 */
421 public static function get_instance()
422 {
423 static $instance = null;
424
425 if (is_null($instance)) {
426 $instance = new static($GLOBALS['wpdb']);
427 }
428
429 return $instance;
430 }
431 }