PluginProbe
HTML Forms – Simple WordPress Forms Plugin / 1.3.34
HTML Forms – Simple WordPress Forms Plugin v1.3.34
1.7.0 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 All 67 releases
← All changes | src/admin/class-admin.php +19 -85 1.7.01.3.34 View file →
@@ -22,16 +22,14 @@
22 22 }
23 23
24 24 public function hook() {
25 25 add_action( 'admin_menu', array( $this, 'menu' ) );
26 - add_action( 'admin_enqueue_scripts', array( $this, 'menu_icon' ) );
27 26 add_action( 'init', array( $this, 'register_settings' ) );
28 27 add_action( 'admin_init', array( $this, 'run_migrations' ) );
29 28 add_action( 'admin_init', array( $this, 'listen' ) );
30 29 add_action( 'admin_print_styles', array( $this, 'assets' ) );
31 30 add_action( 'admin_head', array( $this, 'add_screen_options' ) );
32 - add_action( 'hf_admin_action_create_form', array( $this, 'process_create_form' ) );
33 - add_action( 'wp_ajax_hf_dismiss_recaptcha_notice', array( $this, 'dismiss_recaptcha_notice' ) );
31 + add_action( 'hf_admin_action_create_form', array( $this, 'process_create_form' ) );
34 32 add_action( 'hf_admin_action_save_form', array( $this, 'process_save_form' ) );
35 33 add_action( 'hf_admin_action_bulk_delete_submissions', array( $this, 'process_bulk_delete_submissions' ) );
36 34
37 35 add_action( 'hf_admin_output_form_tab_fields', array( $this, 'tab_fields' ) );
@@ -40,11 +38,8 @@
40 38 add_action( 'hf_admin_output_form_tab_actions', array( $this, 'tab_actions' ) );
41 39 add_action( 'hf_admin_output_form_tab_submissions', array( $this, 'tab_submissions_list' ) );
42 40 add_action( 'hf_admin_output_form_tab_submissions', array( $this, 'tab_submissions_detail' ) );
43 41 add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_gutenberg_assets' ) );
44 - add_filter( 'set_screen_option_hf_submissions_per_page', function( $keep, $option, $value ) {
45 - return (int) $value;
46 - }, 10, 3 );
47 42 }
48 43
49 44 public function enqueue_gutenberg_assets() {
50 45 wp_enqueue_script(
@@ -93,32 +88,8 @@
93 88 *
94 89 * @return array
95 90 */
96 91 public function sanitize_settings( $dirty ) {
97 - $int_fields = array( 'enable_nonce', 'load_stylesheet', 'direct_links', 'media_library_uploads', 'maximum_filesize' );
98 - foreach ( $int_fields as $field ) {
99 - if ( isset( $dirty[ $field ] ) ) {
100 - $dirty[ $field ] = absint( $dirty[ $field ] );
101 - }
102 - }
103 -
104 - if ( isset( $dirty['wrapper_tag'] ) ) {
105 - $allowed_tags = array( 'p', 'div', 'span' );
106 - $dirty['wrapper_tag'] = in_array( $dirty['wrapper_tag'], $allowed_tags, true ) ? $dirty['wrapper_tag'] : 'p';
107 - }
108 -
109 - if ( isset( $dirty['submissions_export_delimiter'] ) ) {
110 - $dirty['submissions_export_delimiter'] = sanitize_text_field( $dirty['submissions_export_delimiter'] );
111 - }
112 -
113 - if ( isset( $dirty['google_recaptcha'] ) && is_array( $dirty['google_recaptcha'] ) ) {
114 - foreach ( array( 'site_key', 'secret_key' ) as $key ) {
115 - if ( isset( $dirty['google_recaptcha'][ $key ] ) ) {
116 - $dirty['google_recaptcha'][ $key ] = sanitize_text_field( $dirty['google_recaptcha'][ $key ] );
117 - }
118 - }
119 - }
120 -
121 92 return $dirty;
122 93 }
123 94
124 95 public function listen() {
@@ -163,10 +134,8 @@
163 134 if ( empty( $_GET['page'] ) || strpos( $_GET['page'], 'html-forms' ) !== 0 ) {
164 135 return;
165 136 }
166 137
167 - $settings = hf_get_settings();
168 -
169 138 wp_enqueue_style( 'html-forms-admin', plugins_url( 'assets/css/admin.css', $this->plugin_file ), array(), HTML_FORMS_VERSION );
170 139 wp_enqueue_script( 'html-forms-admin', plugins_url( 'assets/js/admin.js', $this->plugin_file ), array(), HTML_FORMS_VERSION, true );
171 140 wp_localize_script(
172 141 'html-forms-admin',
@@ -174,9 +143,8 @@
174 143 array(
175 144 'page' => $_GET['page'],
176 145 'view' => empty( $_GET['view'] ) ? '' : $_GET['view'],
177 146 'form_id' => empty( $_GET['form_id'] ) ? 0 : (int) $_GET['form_id'],
178 - 'wrapper_tag' => empty( $settings['wrapper_tag'] ) ? 'p' : $settings['wrapper_tag'],
179 147 )
180 148 );
181 149 }
182 150
@@ -181,10 +149,11 @@
181 149 }
182 150
183 151 public function menu() {
184 152 $capability = 'edit_forms';
185 -
186 - add_menu_page(
153 + $svg_icon = '<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="256.000000pt" height="256.000000pt" viewBox="0 0 256.000000 256.000000" preserveAspectRatio="xMidYMid meet"><g transform="translate(0.000000,256.000000) scale(0.100000,-0.100000)"
154 + fill="#000000" stroke="none"><path d="M0 1280 l0 -1280 1280 0 1280 0 0 1280 0 1280 -1280 0 -1280 0 0 -1280z m2031 593 c8 -8 9 -34 4 -78 -6 -56 -9 -65 -23 -60 -43 16 -98 15 -132 -2 -50 -26 -72 -72 -78 -159 l-5 -74 92 0 91 0 0 -70 0 -70 -90 0 -90 0 0 -345 0 -345 -90 0 -90 0 0 345 0 345 -55 0 -55 0 0 70 0 70 55 0 55 0 0 38 c0 63 20 153 45 202 54 105 141 152 273 147 45 -2 87 -8 93 -14z m-1291 -288 l0 -235 230 0 230 0 0 235 0 235 90 0 90 0 0 -575 0 -575 -90 0 -90 0 0 260 0 260 -230 0 -230 0 0 -260 0 -260 -90 0 -90 0 0 575 0 575 90 0 90 0 0 -235z"/></g></svg>';
155 + add_menu_page(
187 156 'HTML Forms',
188 157 'HTML Forms',
189 158 $capability,
190 159 'html-forms',
@@ -191,12 +160,11 @@
191 160 array(
192 161 $this,
193 162 'page_overview',
194 163 ),
195 - 'none',
164 + 'data:image/svg+xml;base64,' . base64_encode( $svg_icon ),
196 165 '99.88491'
197 166 );
198 -
199 167 add_submenu_page(
200 168 'html-forms',
201 169 __( 'Forms', 'html-forms' ),
202 170 __( 'All Forms', 'html-forms' ),
@@ -206,9 +174,8 @@
206 174 $this,
207 175 'page_overview',
208 176 )
209 177 );
210 -
211 178 add_submenu_page(
212 179 'html-forms',
213 180 __( 'Add New Form', 'html-forms' ),
214 181 __( 'Add New', 'html-forms' ),
@@ -218,9 +185,8 @@
218 185 $this,
219 186 'page_new_form',
220 187 )
221 188 );
222 -
223 189 add_submenu_page(
224 190 'html-forms',
225 191 __( 'Settings', 'html-forms' ),
226 192 __( 'Settings', 'html-forms' ),
@@ -246,14 +212,8 @@
246 212 );
247 213 }
248 214 }
249 215
250 - public function menu_icon() {
251 - $html_forms_icon = 'data:image/svg+xml;base64,'.base64_encode('<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 256 256"><path d="M0 0v256h256V0zm203.1 68.7c.8.8.9 3.4.4 7.8-.6 5.6-.9 6.5-2.3 6-4.3-1.6-9.8-1.5-13.2.2-5 2.6-7.2 7.2-7.8 15.9l-.5 7.4H198v14h-18v69h-18v-69h-11v-14h11v-3.8c0-6.3 2-15.3 4.5-20.2 5.4-10.5 14.1-15.2 27.3-14.7 4.5.2 8.7.8 9.3 1.4M74 74v47h46V74h18v115h-18v-52H74v52H56V74z" /></svg>');
252 -
253 - wp_add_inline_style( 'wp-admin', '#toplevel_page_html-forms .wp-menu-image { background-color: currentColor; mask-image: url("'.$html_forms_icon.'"); mask-size: 20px; mask-repeat: no-repeat; mask-position: center; }' );
254 - }
255 -
256 216 public function add_screen_options() {
257 217 // only run on the submissions overview page (not detail)
258 218 if ( empty( $_GET['page'] ) || $_GET['page'] !== 'html-forms' || empty( $_GET['view'] ) || $_GET['view'] !== 'edit' || empty( $_GET['form_id'] ) || ! empty( $_GET['submission_id'] ) ) {
259 219 return;
@@ -274,13 +234,8 @@
274 234 return $columns;
275 235 }
276 236 );
277 237 add_screen_option( 'layout_columns' );
278 - add_screen_option( 'per_page', array(
279 - 'label' => __( 'Submissions per page', 'html-forms' ),
280 - 'default' => 20,
281 - 'option' => 'hf_submissions_per_page',
282 - ) );
283 238 }
284 239
285 240 public function page_overview() {
286 241 if ( ! empty( $_GET['view'] ) && $_GET['view'] === 'edit' ) {
@@ -302,10 +257,8 @@
302 257 }
303 258
304 259 public function page_settings() {
305 260 $settings = hf_get_settings();
306 - $wrapper_tags = array ( 'p', 'div', 'span' );
307 -
308 261 require dirname( $this->plugin_file ) . '/views/page-global-settings.php';
309 262 }
310 263
311 264 public function page_premium() {
@@ -365,19 +318,10 @@
365 318 if ( ! empty( $_GET['submission_id'] ) ) {
366 319 return;
367 320 }
368 321
369 - $items_per_page = (int) get_user_option( 'hf_submissions_per_page' );
370 - if ( $items_per_page < 1 ) {
371 - $items_per_page = 20;
372 - }
373 -
374 - $allowed_orderby = array( 'submitted_at' );
375 - $orderby = isset( $_GET['orderby'] ) && in_array( $_GET['orderby'], $allowed_orderby, true ) ? $_GET['orderby'] : 'submitted_at';
376 - $order = isset( $_GET['order'] ) && strtolower( $_GET['order'] ) === 'asc' ? 'asc' : 'desc';
377 - $search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '';
378 -
379 - $total_items = hf_count_form_submissions( $form->ID, $search );
322 + $items_per_page = 500;
323 + $total_items = hf_count_form_submissions( $form->ID );
380 324 $total_pages = max( 1, ceil( $total_items / $items_per_page ) );
381 325 $current_page = isset( $_GET['paged'] ) ? intval( $_GET['paged'] ) : 1;
382 326 $current_page = max( 1, $current_page );
383 327 $current_page = min( $total_pages, $current_page );
@@ -383,13 +327,10 @@
383 327 $current_page = min( $total_pages, $current_page );
384 328 $submissions = hf_get_form_submissions(
385 329 $form->ID,
386 330 array(
387 - 'limit' => $items_per_page,
388 - 'offset' => ( $current_page - 1 ) * $items_per_page,
389 - 'orderby' => $orderby,
390 - 'order' => $order,
391 - 'search' => $search,
331 + 'limit' => $items_per_page,
332 + 'offset' => ( $current_page - 1 ) * $items_per_page,
392 333 )
393 334 );
394 335 $columns = $this->get_submission_columns( $submissions );
395 336 $hidden_columns = get_hidden_columns( get_current_screen() );
@@ -402,12 +343,12 @@
402 343 return;
403 344 }
404 345
405 346 $submission = hf_get_form_submission( (int) $_GET['submission_id'] );
406 - do_action( 'hf_admin_form_submissions_detail', $submission );
407 347 require dirname( $this->plugin_file ) . '/views/tab-submissions-detail.php';
408 348 }
409 349
350 +
410 351 public function process_create_form() {
411 352 // Fix for MultiSite stripping KSES for roles other than administrator
412 353 remove_all_filters( 'content_save_pre' );
413 354
@@ -453,16 +394,8 @@
453 394 )
454 395 );
455 396
456 397 if ( ! empty( $data['settings'] ) ) {
457 - // Reject redirect URLs with non-http(s) schemes
458 - if ( isset( $data['settings']['redirect_url'] ) && $data['settings']['redirect_url'] !== '' ) {
459 - $scheme = wp_parse_url( $data['settings']['redirect_url'], PHP_URL_SCHEME );
460 - if ( $scheme !== null && ! in_array( strtolower( $scheme ), array( 'http', 'https' ), true ) ) {
461 - $data['settings']['redirect_url'] = '';
462 - }
463 - }
464 -
465 398 update_post_meta( $form_id, '_hf_settings', $data['settings'] );
466 399 }
467 400
468 401 // save form messages in individual meta keys
@@ -542,23 +475,24 @@
542 475 $args = array_map( 'intval', $_POST['id'] );
543 476 $table = $wpdb->prefix . 'hf_submissions';
544 477 $placeholders = rtrim( str_repeat( '%d,', count( $args ) ), ',' );
545 478 $wpdb->query( $wpdb->prepare( "DELETE FROM {$table} WHERE id IN( {$placeholders} );", $args ) );
479 +
480 + $args[] = '_hf_%%';
481 + $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN ( {$placeholders} ) AND meta_key LIKE %s;", $args ) );
546 482 }
547 483
548 484 private function get_default_form_content() {
549 - $settings = hf_get_settings();
550 - $wrapper_tag = ( isset( $settings['wrapper_tag'] ) ) ? $settings['wrapper_tag'] : 'p';
551 -
552 485 $html = '';
553 - $html .= sprintf( "<%1\$s>\n\t<label>%2\$s</label>\n\t<input type=\"text\" name=\"NAME\" placeholder=\"%2\$s\" required />\n</%1\$s>", $wrapper_tag, __( 'Your name', 'html-forms' ) ) . PHP_EOL;
554 - $html .= sprintf( "<%1\$s>\n\t<label>%2\$s</label>\n\t<input type=\"email\" name=\"EMAIL\" placeholder=\"%2\$s\" required />\n</%1\$s>", $wrapper_tag, __( 'Your email', 'html-forms' ) ) . PHP_EOL;
555 - $html .= sprintf( "<%1\$s>\n\t<label>%2\$s</label>\n\t<input type=\"text\" name=\"SUBJECT\" placeholder=\"%2\$s\" required />\n</%1\$s>", $wrapper_tag, __( 'Subject', 'html-forms' ) ) . PHP_EOL;
556 - $html .= sprintf( "<%1\$s>\n\t<label>%2\$s</label>\n\t<textarea name=\"MESSAGE\" placeholder=\"%2\$s\" required></textarea>\n</%1\$s>", $wrapper_tag, __( 'Message', 'html-forms' ) ) . PHP_EOL;
557 - $html .= sprintf( "<%1\$s>\n\t<input type=\"submit\" value=\"%2\$s\" />\n</%1\$s>", $wrapper_tag, __( 'Send', 'html-forms' ) );
486 + $html .= sprintf( "<p>\n\t<label>%1\$s</label>\n\t<input type=\"text\" name=\"NAME\" placeholder=\"%1\$s\" required />\n</p>", __( 'Your name', 'html-forms' ) ) . PHP_EOL;
487 + $html .= sprintf( "<p>\n\t<label>%1\$s</label>\n\t<input type=\"email\" name=\"EMAIL\" placeholder=\"%1\$s\" required />\n</p>", __( 'Your email', 'html-forms' ) ) . PHP_EOL;
488 + $html .= sprintf( "<p>\n\t<label>%1\$s</label>\n\t<input type=\"text\" name=\"SUBJECT\" placeholder=\"%1\$s\" required />\n</p>", __( 'Subject', 'html-forms' ) ) . PHP_EOL;
489 + $html .= sprintf( "<p>\n\t<label>%1\$s</label>\n\t<textarea name=\"MESSAGE\" placeholder=\"%1\$s\" required></textarea>\n</p>", __( 'Message', 'html-forms' ) ) . PHP_EOL;
490 + $html .= sprintf( "<p>\n\t<input type=\"submit\" value=\"%s\" />\n</p>", __( 'Send', 'html-forms' ) );
558 491
559 492 return $html;
560 493 }
494 +
561 495
562 496 /**
563 497 * Filters string and strips out all HTML tags and attributes, except what's in our whitelist.
564 498 *