PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.3
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
← All changes | includes/_capacity/captcha_simple_text.php +139 -25 10.1.311.8.3 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2
3 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly //FixIn: 9.8.0.4
3 +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // FixIn: 9.8.0.4.
4 4
5 5 // ---------------------------------------------------------------------------------------------------------------------
6 6 // Main function for ajax_ WPBC_AJX_BOOKING__CREATE
7 7 // ---------------------------------------------------------------------------------------------------------------------
@@ -16,32 +16,30 @@
16 16 * @return void wp_send_json() TO front-end or skip and continue
17 17 */
18 18 function wpbc_captcha__in_ajx__check( $request_params, $is_from_admin_panel , $original_ajx_search_params ) {
19 19
20 - if (
21 - ( 'On' === get_bk_option( 'booking_is_use_captcha' ) )
22 - && ( ! $is_from_admin_panel )
23 - && ( ( isset( $original_ajx_search_params['captcha_user_input'] ) ) && ( isset( $original_ajx_search_params['captcha_chalange'] ) ) )
24 - ) {
20 + if ( ( ! $is_from_admin_panel ) && ( ( isset( $original_ajx_search_params['captcha_user_input'] ) ) && ( isset( $original_ajx_search_params['captcha_chalange'] ) ) ) ) {
25 21
26 22 if ( ! wpbc_captcha__simple__is_ansfer_correct( $request_params['captcha_user_input'], $request_params['captcha_chalange'] ) ) {
27 23
28 24 $captcha_arr = wpbc_captcha__simple__generate_new();
29 25
30 - $ajx_data_arr = array();
31 - $ajx_data_arr['status'] = 'error';
32 - $ajx_data_arr['status_error'] = 'captcha_simple_wrong';
33 - $ajx_data_arr['captcha__simple'] = $captcha_arr;
34 - $ajx_data_arr['ajx_after_action_message'] = __( 'The code you entered is incorrect', 'booking' );
26 + $ajx_data_arr = array();
27 + $ajx_data_arr['status'] = 'error';
28 + $ajx_data_arr['status_error'] = 'captcha_simple_wrong';
29 + $ajx_data_arr['captcha__simple'] = $captcha_arr;
30 + $ajx_data_arr['ajx_after_action_message'] = wpbc_frontend_messages__get( 'message_captcha_incorrect', array(), $request_params['resource_id'] );
35 31 $ajx_data_arr['ajx_after_action_message_status'] = 'warning';
36 32
37 - wp_send_json( array(
38 - 'ajx_data' => $ajx_data_arr,
39 - 'ajx_search_params' => $original_ajx_search_params,
40 - 'ajx_cleaned_params' => $request_params,
41 - 'resource_id' => $request_params['resource_id']
42 - ) );
43 - // After this page will die;
33 + wp_send_json(
34 + array(
35 + 'ajx_data' => $ajx_data_arr,
36 + 'ajx_search_params' => $original_ajx_search_params,
37 + 'ajx_cleaned_params' => $request_params,
38 + 'resource_id' => $request_params['resource_id'],
39 + )
40 + );
41 + // After this page will die;.
44 42 }
45 43 }
46 44 }
47 45
@@ -84,9 +82,9 @@
84 82
85 83 $captcha_instance = new wpdevReallySimpleCaptcha();
86 84
87 85 // Clean up dead files older than 2 minutes
88 - $captcha_instance->cleanup( 2 ); //FixIn: 7.0.1.67
86 + $captcha_instance->cleanup( 2 ); // FixIn: 7.0.1.67.
89 87
90 88 //$captcha_instance->img_size = array( 72, 24 );
91 89 /* Background color of CAPTCHA image. RGB color 0-255 */
92 90 //$captcha_instance->bg = array( 0, 0, 0 );//array( 255, 255, 255 );
@@ -102,9 +100,9 @@
102 100 //$captcha_instance->img_type = 'png';
103 101
104 102
105 103 $word = $captcha_instance->generate_random_word();
106 - $prefix = mt_rand();
104 + $prefix = wp_rand();
107 105
108 106 $captcha_instance->generate_image( $prefix, $word );
109 107
110 108 $filename = $prefix . '.png';
@@ -135,12 +133,13 @@
135 133 $captcha_arr = wpbc_captcha__simple__generate_new();
136 134
137 135 $captcha_url = $captcha_arr['url'];
138 136 $captcha_challenge = $captcha_arr['challenge'];
139 - $html = '<span class="wpbc_text_captcha_container">';
137 + $html = '<span class="wpbc_text_captcha_container wpdev-form-control-wrap ">';
140 138 $html .= '<input autocomplete="off" type="hidden" name="wpdev_captcha_challenge_' . $resource_id . '" id="wpdev_captcha_challenge_' . $resource_id . '" value="' . $captcha_challenge . '" />';
141 139 $html .= '<input autocomplete="off" type="text" class="captachinput" value="" name="captcha_input' . $resource_id . '" id="captcha_input' . $resource_id . '" />';
142 - $html .= '<img class="captcha_img" id="captcha_img' . $resource_id . '" alt="To show CAPTCHA, please deactivate cache plugin or exclude this page from caching or disable CAPTCHA at WP Booking Calendar > Settings General page in Form Options section." src="' . $captcha_url . '" />';
140 + // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage
141 + $html .= '<img class="captcha_img" id="captcha_img' . $resource_id . '" alt="To show CAPTCHA, please deactivate cache plugin or exclude this page from caching or disable CAPTCHA at WP Booking Calendar - Settings General page in Form Options section." src="' . $captcha_url . '" />';
143 142 $html .= '</span>';
144 143
145 144 return $html;
146 145 }
@@ -152,9 +151,9 @@
152 151 * @return string|true if true then can work, Otherwise return error message
153 152 */
154 153 function wpbc_captcha__simple__is_installed() {
155 154
156 - //FixIn: 8.8.3.5
155 + // FixIn: 8.8.3.5.
157 156 if ( function_exists( 'gd_info' ) ) {
158 157
159 158 return true;
160 159 /*
@@ -161,9 +160,9 @@
161 160 $gd_info = gd_info();
162 161 if ( isset( $gd_info['GD Version'] ) ) {
163 162 $gd_info = $gd_info['GD Version'];
164 163 } else {
165 - $gd_info = json_encode( $gd_info );
164 + $gd_info = wp_json_encode( $gd_info );
166 165 }
167 166 */
168 167 } else {
169 168 return '<strong>Error!</strong> CAPTCHA requires the GD library activated in your PHP configuration.'
@@ -170,5 +169,120 @@
170 169 .'Please check more <a href="https://wpbookingcalendar.com/faq/captcha-showing-problems/">here</a>.';
171 170 }
172 171
173 172
174 -}
173 +}
174 +
175 +
176 +/**
177 + * Decide if CAPTCHA can be shown for current request/context.
178 + *
179 + * Rules:
180 + * - Must be enabled in settings (booking_is_use_captcha = On)
181 + * - Must not be a WP Admin page, except plugin settings form page
182 + *
183 + * @return bool
184 + */
185 +function wpbc_booking_form_is_captcha_allowed_here() {
186 +
187 + // In admin area we usually do not show CAPTCHA, except booking form builder preview pages.
188 + // if ( is_admin() && ( ! wpbc_is_settings_form_page() ) ) { return false; } //.
189 +
190 + // old URI-based logic for edge cases, keep it as extra guard:.
191 + $server_request_uri = ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
192 +
193 + // Optional legacy-style admin URI check.
194 + $admin_uri = ltrim( str_replace( get_site_url( null, '', 'admin' ), '', admin_url( 'admin.php?' ) ), '/' );
195 +
196 + if (
197 + ( '' !== $server_request_uri )
198 + && ( false !== strpos( $server_request_uri, $admin_uri ) )
199 + && ( ! wpbc_is_settings_form_page() )
200 + && ( ! wpbc_is_builder_booking_form_page() )
201 + ) {
202 + return false;
203 + }
204 +
205 + return true;
206 +}
207 +
208 +
209 +/**
210 + * Default CAPTCHA placeholder replacement for booking form HTML.
211 + *
212 + * Replaces [captcha] token with generated CAPTCHA markup (if enabled),
213 + * or removes the token when CAPTCHA is disabled/not allowed in current context.
214 + *
215 + * Add-ons can:
216 + * - Replace HTML entirely by filtering 'wpbc_booking_form_captcha_html'
217 + * - Or override this whole replacement by using a lower priority on
218 + * 'wpbc_booking_form_html__create_captha' / '__create_captcha'
219 + *
220 + * @param string $form_html Booking form HTML.
221 + * @param int $resource_id Booking resource ID.
222 + *
223 + * @return string
224 + */
225 +function wpbc_booking_form_html__create_captcha_default( $form_html, $resource_id ) {
226 +
227 + if ( false === strpos( $form_html, '[captcha]' ) ) {
228 + return $form_html;
229 + }
230 +
231 + $resource_id = (int) $resource_id;
232 +
233 + // If CAPTCHA is not allowed here, remove placeholder.
234 + if ( ! wpbc_booking_form_is_captcha_allowed_here() ) {
235 + return str_replace( '[captcha]', '', $form_html );
236 + }
237 +
238 + /**
239 + * Filter: Provide CAPTCHA HTML for booking form.
240 + *
241 + * Return non-empty string to supply your own CAPTCHA markup (addons).
242 + * Return empty string to let WPBC fallback to the built-in simple CAPTCHA.
243 + *
244 + * @param string $captcha_html CAPTCHA HTML (empty by default).
245 + * @param int $resource_id Booking resource ID.
246 + * @param array $args Context args.
247 + */
248 + $captcha_html = apply_filters( 'wpbc_booking_form_captcha_html', '', $resource_id,
249 + array(
250 + 'context' => 'booking_form',
251 + 'placeholder' => '[captcha]',
252 + )
253 + );
254 +
255 + if ( '' === $captcha_html ) {
256 + // Core fallback (your existing generator).
257 + $captcha_html = wpbc_captcha__simple__generate_html_content( $resource_id );
258 + }
259 +
260 + return str_replace( '[captcha]', $captcha_html, $form_html );
261 +}
262 +add_filter( 'wpbc_booking_form_html__create_captcha', 'wpbc_booking_form_html__create_captcha_default', 10, 2 );
263 +
264 +
265 +/**
266 + * How an add-on supplies a different CAPTCHA (example).
267 + * add_filter( 'wpbc_booking_form_captcha_html', 'my_addon_wpbc_captcha_html', 20, 3 );
268 + *
269 + *
270 + * Provide custom CAPTCHA HTML (e.g., reCAPTCHA/hCaptcha).
271 + *
272 + * @param string $captcha_html Current HTML (empty by default).
273 + * @param int $resource_id Booking resource ID.
274 + * @param array $args Context args.
275 + *
276 + * @return string
277 + *
278 + * function my_addon_wpbc_captcha_html( $captcha_html, $resource_id, $args ) {
279 + *
280 + * // Only replace on booking form rendering context.
281 + * if ( empty( $args['context'] ) || ( 'booking_form' !== $args['context'] ) ) {
282 + * return $captcha_html;
283 + * }
284 + *
285 + * // Return your custom markup here.
286 + * return '<div class="my-addon-captcha">...</div>';
287 + * }
288 + */