PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Form_Builder / helpers / Form_Builder_Security.php

Form_Builder_Security.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.78, at includes/widgets/Form_Builder/helpers/Form_Builder_Security.php

82 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace King_Addons;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 /**
10 * Shared Form Builder checks for public AJAX requests.
11 */
12 class Form_Builder_Security
13 {
14 /**
15 * Checks whether a published document contains the Form Builder widget.
16 *
17 * @param mixed $page_id Page or post ID from the request.
18 * @return bool True when the document is published and includes Form Builder.
19 */
20 public static function page_has_form_builder($page_id): bool
21 {
22 $page_id = absint($page_id);
23 if ($page_id <= 0) {
24 return false;
25 }
26
27 $post = get_post($page_id);
28 if (!$post || 'publish' !== $post->post_status) {
29 return false;
30 }
31
32 $elementor_data = get_post_meta($page_id, '_elementor_data', true);
33 if (empty($elementor_data)) {
34 return false;
35 }
36
37 if (!is_string($elementor_data)) {
38 $elementor_data = wp_json_encode($elementor_data);
39 }
40
41 return false !== strpos($elementor_data, 'king-addons-form-builder');
42 }
43
44 /**
45 * Validates a page ID for public form submissions.
46 *
47 * Accepts a published page that contains Form Builder. Also accepts a
48 * published source page or template when the widget is injected by Theme
49 * Builder, Header/Footer, or a popup and is therefore not stored on the
50 * queried page.
51 *
52 * @param mixed $page_id Page or post ID from the request.
53 * @return bool True when the page ID is safe to store with a submission.
54 */
55 public static function is_valid_submission_page($page_id): bool
56 {
57 if (self::page_has_form_builder($page_id)) {
58 return true;
59 }
60
61 $page_id = absint($page_id);
62 if ($page_id <= 0) {
63 return false;
64 }
65
66 $post = get_post($page_id);
67 if (!$post || 'publish' !== $post->post_status) {
68 return false;
69 }
70
71 if (is_post_publicly_viewable($post)) {
72 return true;
73 }
74
75 return in_array(
76 $post->post_type,
77 ['elementor_library', 'king-addons-el-hf', 'king_addons_popup'],
78 true
79 );
80 }
81 }
82