| 1 |
<?php |
| 2 |
|
| 3 |
namespace WeDevs\Wpuf; |
| 4 |
|
| 5 |
use Invisible_Recaptcha; |
| 6 |
use WeDevs\Wpuf\Ajax\Upload_Ajax; |
| 7 |
use WeDevs\Wpuf\Traits\FieldableTrait; |
| 8 |
use WPUF_ReCaptcha; |
| 9 |
|
| 10 |
/** |
| 11 |
* Handles form generaton and posting for add/edit post in frontend |
| 12 |
*/ |
| 13 |
class Render_Form { |
| 14 |
use FieldableTrait; |
| 15 |
|
| 16 |
public static $meta_key = 'wpuf_form'; |
| 17 |
|
| 18 |
public static $separator = ' | '; |
| 19 |
|
| 20 |
public static $config_id = '_wpuf_form_id'; |
| 21 |
|
| 22 |
private $form_condition_key = 'wpuf_cond'; |
| 23 |
|
| 24 |
private static $_instance; |
| 25 |
|
| 26 |
private $field_count = 0; |
| 27 |
|
| 28 |
public $multiform_start = 0; |
| 29 |
|
| 30 |
public static function init() { |
| 31 |
if ( !self::$_instance ) { |
| 32 |
self::$_instance = new self(); |
| 33 |
} |
| 34 |
|
| 35 |
return self::$_instance; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Send json error message |
| 40 |
* |
| 41 |
* @param string $error |
| 42 |
*/ |
| 43 |
public function send_error( $error ) { |
| 44 |
echo wp_json_encode( [ |
| 45 |
'success' => false, |
| 46 |
'error' => $error, |
| 47 |
] ); |
| 48 |
|
| 49 |
die(); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Really simple captcha validation |
| 54 |
* |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function validate_rs_captcha() { |
| 58 |
$nonce = isset( $_REQUEST['wpuf-login-nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpuf-login-nonce'] ) ) : ''; |
| 59 |
|
| 60 |
if ( isset( $nonce) && ! wp_verify_nonce( $nonce, 'wpuf_login_action' ) ) { |
| 61 |
return ; |
| 62 |
} |
| 63 |
|
| 64 |
$rs_captcha_input = isset( $_POST['rs_captcha'] ) ? sanitize_text_field( wp_unslash( $_POST['rs_captcha'] ) ) : ''; |
| 65 |
$rs_captcha_file = isset( $_POST['rs_captcha_val'] ) ? sanitize_text_field( wp_unslash( $_POST['rs_captcha_val'] ) ) : ''; |
| 66 |
|
| 67 |
if ( class_exists( 'ReallySimpleCaptcha' ) ) { |
| 68 |
$captcha_instance = new ReallySimpleCaptcha(); |
| 69 |
|
| 70 |
if ( !$captcha_instance->check( $rs_captcha_file, $rs_captcha_input ) ) { |
| 71 |
$this->send_error( __( 'Really Simple Captcha validation failed', 'wp-user-frontend' ) ); |
| 72 |
} else { |
| 73 |
// validation success, remove the files |
| 74 |
$captcha_instance->remove( $rs_captcha_file ); |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* reCaptcha Validation |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public function validate_re_captcha( $no_captcha = '', $invisible = '' ) { |
| 85 |
$nonce = isset( $_REQUEST['wpuf-login-nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['wpuf-login-nonce'] ) ) : ''; |
| 86 |
|
| 87 |
if ( isset( $nonce ) && ! wp_verify_nonce( $nonce, 'wpuf_login_action' ) ) { |
| 88 |
return ; |
| 89 |
} |
| 90 |
// need to check if invisible reCaptcha need library or we can do it here. |
| 91 |
// ref: https://shareurcodes.com/blog/google%20invisible%20recaptcha%20integration%20with%20php |
| 92 |
$site_key = wpuf_get_option( 'recaptcha_public', 'wpuf_general' ); |
| 93 |
$private_key = wpuf_get_option( 'recaptcha_private', 'wpuf_general' ); |
| 94 |
$rremote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; |
| 95 |
$g_recaptcha_response = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : ''; |
| 96 |
|
| 97 |
if ( $no_captcha == 1 && 0 == $invisible ) { |
| 98 |
if ( !class_exists( 'WPUF_ReCaptcha' ) ) { |
| 99 |
require_once WPUF_ROOT . '/Lib/recaptchalib_noCaptcha.php'; |
| 100 |
} |
| 101 |
|
| 102 |
$response = null; |
| 103 |
$reCaptcha = new WPUF_ReCaptcha( $private_key ); |
| 104 |
|
| 105 |
$resp = $reCaptcha->verifyResponse( |
| 106 |
$rremote_addr, |
| 107 |
$g_recaptcha_response |
| 108 |
); |
| 109 |
|
| 110 |
if ( !$resp->success ) { |
| 111 |
$this->send_error( __( 'noCaptcha reCAPTCHA validation failed', 'wp-user-frontend' ) ); |
| 112 |
} |
| 113 |
} elseif ( $no_captcha == 0 && 0 == $invisible ) { |
| 114 |
$recap_challenge = isset( $_POST['recaptcha_challenge_field'] ) ? sanitize_text_field( wp_unslash( $_POST['recaptcha_challenge_field'] ) ) : ''; |
| 115 |
$recap_response = isset( $_POST['recaptcha_response_field'] ) ? sanitize_text_field( wp_unslash( $_POST['recaptcha_response_field'] ) ) : ''; |
| 116 |
|
| 117 |
$resp = recaptcha_check_answer( $private_key, $rremote_addr, $recap_challenge, $recap_response ); |
| 118 |
|
| 119 |
if ( !$resp->is_valid ) { |
| 120 |
$this->send_error( __( 'reCAPTCHA validation failed', 'wp-user-frontend' ) ); |
| 121 |
} |
| 122 |
} elseif ( $no_captcha == 0 && 1 == $invisible ) { |
| 123 |
$response = null; |
| 124 |
$recaptcha = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : ''; |
| 125 |
$object = new Invisible_Recaptcha( $site_key, $private_key ); |
| 126 |
|
| 127 |
$response = $object->verifyResponse( $recaptcha ); |
| 128 |
|
| 129 |
if ( isset( $response['success'] ) and $response['success'] != true ) { |
| 130 |
$this->send_error( __( 'Invisible reCAPTCHA validation failed', 'wp-user-frontend' ) ); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Guess a suitable username for registration based on email address |
| 137 |
* |
| 138 |
* @param string $email email address |
| 139 |
* |
| 140 |
* @return string username |
| 141 |
*/ |
| 142 |
public function guess_username( $email ) { |
| 143 |
// username from email address |
| 144 |
$username = sanitize_user( substr( $email, 0, strpos( $email, '@' ) ) ); |
| 145 |
|
| 146 |
if ( !username_exists( $username ) ) { |
| 147 |
return $username; |
| 148 |
} |
| 149 |
|
| 150 |
// try to add some random number in username |
| 151 |
// and may be we got our username |
| 152 |
$username .= wp_rand( 1, 199 ); |
| 153 |
|
| 154 |
if ( !username_exists( $username ) ) { |
| 155 |
return $username; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Get input meta fields separated as post vars, taxonomy and meta vars |
| 161 |
* |
| 162 |
* @param int $form_id form id |
| 163 |
* |
| 164 |
* @return array |
| 165 |
*/ |
| 166 |
public static function get_input_fields_by_form_id( $form_id ) { |
| 167 |
$form_vars = wpuf_get_form_fields( $form_id ); |
| 168 |
|
| 169 |
$ignore_lists = ['section_break', 'html']; |
| 170 |
$post_vars = $meta_vars = $taxonomy_vars = []; |
| 171 |
|
| 172 |
foreach ( $form_vars as $key => $value ) { |
| 173 |
|
| 174 |
// ignore section break and HTML input type |
| 175 |
if ( in_array( $value['input_type'], $ignore_lists ) ) { |
| 176 |
continue; |
| 177 |
} |
| 178 |
|
| 179 |
//separate the post and custom fields |
| 180 |
if ( isset( $value['is_meta'] ) && $value['is_meta'] == 'yes' ) { |
| 181 |
$meta_vars[] = $value; |
| 182 |
continue; |
| 183 |
} |
| 184 |
|
| 185 |
if ( $value['input_type'] == 'taxonomy' ) { |
| 186 |
|
| 187 |
// don't add "category" |
| 188 |
if ( $value['name'] == 'category' ) { |
| 189 |
continue; |
| 190 |
} |
| 191 |
|
| 192 |
$taxonomy_vars[] = $value; |
| 193 |
} else { |
| 194 |
$post_vars[] = $value; |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
return [$post_vars, $taxonomy_vars, $meta_vars]; |
| 199 |
} |
| 200 |
|
| 201 |
public function guest_fields( $form_settings ) { |
| 202 |
?> |
| 203 |
<li class="el-name"> |
| 204 |
<div class="wpuf-label"> |
| 205 |
<label><?php echo esc_attr( $form_settings['name_label'] ); ?> <span class="required">*</span></label> |
| 206 |
</div> |
| 207 |
|
| 208 |
<div class="wpuf-fields"> |
| 209 |
<input type="text" required="required" data-required="yes" data-type="text" name="guest_name" value="" size="40"> |
| 210 |
</div> |
| 211 |
</li> |
| 212 |
|
| 213 |
<li class="el-email"> |
| 214 |
<div class="wpuf-label"> |
| 215 |
<label><?php echo esc_attr( $form_settings['email_label'] ); ?> <span class="required">*</span></label> |
| 216 |
</div> |
| 217 |
|
| 218 |
<div class="wpuf-fields"> |
| 219 |
<input type="email" required="required" data-required="yes" data-type="email" name="guest_email" value="" size="40"> |
| 220 |
</div> |
| 221 |
</li> |
| 222 |
<?php |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Handles the add post shortcode |
| 227 |
* |
| 228 |
* @param int $form_id |
| 229 |
* @param int $post_id |
| 230 |
*/ |
| 231 |
public function render_form( $form_id, $post_id = null ) { |
| 232 |
$form_status = get_post_status( $form_id ); |
| 233 |
|
| 234 |
if ( !$form_status ) { |
| 235 |
echo wp_kses_post( '<div class="wpuf-message">' . __( 'Your selected form is no longer available.', 'wp-user-frontend' ) . '</div>' ); |
| 236 |
|
| 237 |
return; |
| 238 |
} |
| 239 |
|
| 240 |
if ( $form_status != 'publish' ) { |
| 241 |
echo wp_kses_post( '<div class="wpuf-message">' . __( "Please make sure you've published your form.", 'wp-user-frontend' ) . '</div>' ); |
| 242 |
|
| 243 |
return; |
| 244 |
} |
| 245 |
|
| 246 |
$form_vars = wpuf_get_form_fields( $form_id ); |
| 247 |
$form_settings = wpuf_get_form_settings( $form_id ); |
| 248 |
$label_position = isset( $form_settings['label_position'] ) ? $form_settings['label_position'] : 'left'; |
| 249 |
$layout = isset( $form_settings['form_layout'] ) ? $form_settings['form_layout'] : 'layout1'; |
| 250 |
$theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use_theme_css'] : 'wpuf-style'; |
| 251 |
|
| 252 |
do_action( 'wpuf_before_form_render', $form_id ); |
| 253 |
|
| 254 |
if ( ! empty( $layout ) && 'on' !== $theme_css ) { |
| 255 |
wp_enqueue_style( 'wpuf-' . $layout ); |
| 256 |
} |
| 257 |
|
| 258 |
if ( !is_user_logged_in() && isset( $form_settings['post_permission'] ) && 'guest_post' === $form_settings['post_permission'] ) { |
| 259 |
echo wp_kses_post( '<div class="wpuf-message">' . $form_settings['message_restrict'] . '</div>' ); |
| 260 |
|
| 261 |
return; |
| 262 |
} |
| 263 |
|
| 264 |
if ( $form_vars ) { |
| 265 |
?> |
| 266 |
<form class="wpuf-form-add wpuf-form-<?php echo esc_attr( $layout ); ?> <?php echo ( $layout == 'layout1' ) ? esc_attr( $theme_css ) : 'wpuf-style'; ?>" action="" method="post"> |
| 267 |
|
| 268 |
<?php |
| 269 |
// Display form title if enabled |
| 270 |
if ( isset( $form_settings['show_form_title'] ) && wpuf_is_checkbox_or_toggle_on( $form_settings['show_form_title'] ) ) { |
| 271 |
$form_title = get_the_title( $form_id ); |
| 272 |
if ( ! empty( $form_title ) ) { |
| 273 |
echo '<h2 class="wpuf-form-title">' . esc_html( $form_title ) . '</h2>'; |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
// Display form description if set |
| 278 |
if ( isset( $form_settings['form_description'] ) && ! empty( $form_settings['form_description'] ) ) { |
| 279 |
echo '<div class="wpuf-form-description">' . wp_kses_post( $form_settings['form_description'] ) . '</div>'; |
| 280 |
} |
| 281 |
?> |
| 282 |
|
| 283 |
<ul class="wpuf-form form-label-<?php echo esc_attr( $label_position ); ?>"> |
| 284 |
|
| 285 |
<?php |
| 286 |
if ( !$post_id ) { |
| 287 |
do_action( 'wpuf_add_post_form_top', $form_id, $form_settings ); |
| 288 |
} else { |
| 289 |
do_action( 'wpuf_edit_post_form_top', $form_id, $post_id, $form_settings ); |
| 290 |
} |
| 291 |
|
| 292 |
if ( !is_user_logged_in() && isset( $form_settings['post_permission'] ) && 'guest_post' === $form_settings['post_permission'] && wpuf_is_checkbox_or_toggle_on( $form_settings['guest_details'] ) ) { |
| 293 |
$this->guest_fields( $form_settings ); |
| 294 |
} |
| 295 |
|
| 296 |
$this->render_items( $form_vars, $post_id, 'post', $form_id, $form_settings ); |
| 297 |
$this->submit_button( $form_id, $form_settings, $post_id ); |
| 298 |
|
| 299 |
if ( !$post_id ) { |
| 300 |
do_action( 'wpuf_add_post_form_bottom', $form_id, $form_settings ); |
| 301 |
} else { |
| 302 |
do_action( 'wpuf_edit_post_form_bottom', $form_id, $post_id, $form_settings ); |
| 303 |
} ?> |
| 304 |
|
| 305 |
</ul> |
| 306 |
|
| 307 |
</form> |
| 308 |
|
| 309 |
<?php |
| 310 |
} //endif |
| 311 |
do_action( 'wpuf_after_form_render', $form_id ); |
| 312 |
} |
| 313 |
|
| 314 |
public function render_item_before( $form_field, $post_id ) { |
| 315 |
$label_exclude = ['section_break', 'html', 'action_hook', 'toc', 'shortcode']; |
| 316 |
$el_name = !empty( $form_field['name'] ) ? $form_field['name'] : ''; |
| 317 |
$class_name = !empty( $form_field['css'] ) ? ' ' . $form_field['css'] : ''; |
| 318 |
$field_size = !empty( $form_field['width'] ) ? ' field-size-' . $form_field['width'] : ''; |
| 319 |
|
| 320 |
printf( '<li class="wpuf-el %s%s%s" data-label="%s">', esc_attr( $el_name ), esc_attr( $class_name ), esc_attr( $field_size ),esc_attr( $form_field['label'] ) ); |
| 321 |
|
| 322 |
if ( isset( $form_field['input_type'] ) && !in_array( $form_field['input_type'], $label_exclude ) ) { |
| 323 |
$this->label( $form_field, $post_id ); |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
public function render_item_after( $form_field ) { |
| 328 |
echo wp_kses_post( '</li>' ); |
| 329 |
} |
| 330 |
|
| 331 |
public function conditional_logic( $form_field, $form_id ) { |
| 332 |
$cond_inputs = $form_field['wpuf_cond']; |
| 333 |
$cond_inputs['condition_status'] = isset( $cond_inputs['condition_status'] ) ? $cond_inputs['condition_status'] : ''; |
| 334 |
|
| 335 |
if ( $cond_inputs['condition_status'] == 'yes' ) { |
| 336 |
$cond_inputs['type'] = $form_field['input_type']; |
| 337 |
$cond_inputs['name'] = $form_field['name']; |
| 338 |
$cond_inputs['form_id'] = $form_id; |
| 339 |
$condition = wp_json_encode( $cond_inputs ); |
| 340 |
} else { |
| 341 |
$condition = ''; |
| 342 |
} |
| 343 |
|
| 344 |
//taxnomy name create unique |
| 345 |
if ( $form_field['input_type'] == 'taxonomy' ) { |
| 346 |
$cond_inputs['name'] = $form_field['name'] . '_' . $form_field['type'] . '_' . $form_field['id']; |
| 347 |
$condition = wp_json_encode( $cond_inputs ); |
| 348 |
} |
| 349 |
|
| 350 |
//for section break |
| 351 |
if ( $form_field['input_type'] == 'section_break' ) { |
| 352 |
$cond_inputs['name'] = $form_field['name'] . '_' . $form_field['id']; |
| 353 |
$condition = wp_json_encode( $cond_inputs ); |
| 354 |
} ?> |
| 355 |
<script type="text/javascript"> |
| 356 |
wpuf_conditional_items.push(<?php echo esc_html( $condition ); ?>); |
| 357 |
</script> |
| 358 |
<?php |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* Render form items |
| 363 |
* |
| 364 |
* @param array $form_vars |
| 365 |
* @param int|null $post_id |
| 366 |
* @param string $type type of the form. post or user |
| 367 |
*/ |
| 368 |
public function render_items( $form_vars, $post_id, $type, $form_id, $form_settings, $cond_inputs = [] ) { |
| 369 |
if ( ! $type ) { |
| 370 |
$type = 'post'; |
| 371 |
} |
| 372 |
$edit_ignore = [ 'really_simple_captcha' ]; |
| 373 |
$hidden_fields = []; ?> |
| 374 |
<script type="text/javascript"> |
| 375 |
if ( typeof wpuf_conditional_items === 'undefined' ) { |
| 376 |
wpuf_conditional_items = []; |
| 377 |
} |
| 378 |
|
| 379 |
if ( typeof wpuf_plupload_items === 'undefined' ) { |
| 380 |
wpuf_plupload_items = []; |
| 381 |
} |
| 382 |
|
| 383 |
if ( typeof wpuf_map_items === 'undefined' ) { |
| 384 |
wpuf_map_items = []; |
| 385 |
} |
| 386 |
</script> |
| 387 |
<?php |
| 388 |
|
| 389 |
foreach ( $form_vars as $key => $form_field ) { |
| 390 |
|
| 391 |
// check field visibility options |
| 392 |
if ( array_key_exists( 'wpuf_visibility', $form_field ) ) { |
| 393 |
$visibility_selected = $form_field['wpuf_visibility']['selected']; |
| 394 |
$visibility_choices = $form_field['wpuf_visibility']['choices']; |
| 395 |
$show_field = false; |
| 396 |
|
| 397 |
if ( $visibility_selected == 'everyone' ) { |
| 398 |
$show_field = true; |
| 399 |
} |
| 400 |
|
| 401 |
if ( $visibility_selected == 'hidden' ) { |
| 402 |
$form_field['css'] .= ' wpuf_hidden_field'; |
| 403 |
$show_field = true; |
| 404 |
} |
| 405 |
|
| 406 |
if ( $visibility_selected == 'logged_in' && is_user_logged_in() ) { |
| 407 |
if ( empty( $visibility_choices ) ) { |
| 408 |
$show_field = true; |
| 409 |
} else { |
| 410 |
foreach ( $visibility_choices as $key => $choice ) { |
| 411 |
if ( current_user_can( $choice ) ) { |
| 412 |
$show_field = true; |
| 413 |
break; |
| 414 |
} |
| 415 |
continue; |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
if ( $visibility_selected == 'subscribed_users' && is_user_logged_in() ) { |
| 421 |
$user_pack = wpuf()->subscription->get_user_pack( get_current_user_id() ); |
| 422 |
|
| 423 |
if ( empty( $visibility_choices ) && !empty( $user_pack ) ) { |
| 424 |
$show_field = true; |
| 425 |
} elseif ( !empty( $user_pack ) && !empty( $visibility_choices ) ) { |
| 426 |
foreach ( $visibility_choices as $pack => $id ) { |
| 427 |
if ( $user_pack['pack_id'] == $id ) { |
| 428 |
$show_field = true; |
| 429 |
break; |
| 430 |
} |
| 431 |
continue; |
| 432 |
} |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
if ( !$show_field ) { |
| 437 |
continue; |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
// don't show captcha in edit page |
| 442 |
if ( $post_id && in_array( $form_field['input_type'], $edit_ignore ) ) { |
| 443 |
continue; |
| 444 |
} |
| 445 |
|
| 446 |
// igonre the hidden fields |
| 447 |
if ( $form_field['input_type'] == 'hidden' ) { |
| 448 |
$hidden_fields[] = $form_field; |
| 449 |
continue; |
| 450 |
} |
| 451 |
|
| 452 |
// Skip gated taxonomy fields to prevent empty list items and orphaned labels |
| 453 |
if ( $this->is_taxonomy_field_gated( $form_field ) ) { |
| 454 |
continue; |
| 455 |
} |
| 456 |
|
| 457 |
if ( $form_field['input_type'] != 'step_start' && $form_field['input_type'] != 'step_end' ) { |
| 458 |
$this->render_item_before( $form_field, $post_id ); |
| 459 |
} |
| 460 |
|
| 461 |
$this->field_count++; |
| 462 |
|
| 463 |
switch ( $form_field['input_type'] ) { |
| 464 |
case 'text': |
| 465 |
$this->text( $form_field, $post_id, $type, $form_id ); |
| 466 |
$this->conditional_logic( $form_field, $form_id ); |
| 467 |
break; |
| 468 |
|
| 469 |
case 'textarea': |
| 470 |
$this->textarea( $form_field, $post_id, $type, $form_id ); |
| 471 |
$this->conditional_logic( $form_field, $form_id ); |
| 472 |
break; |
| 473 |
|
| 474 |
case 'select': |
| 475 |
$this->select( $form_field, false, $post_id, $type, $form_id ); |
| 476 |
$this->conditional_logic( $form_field, $form_id ); |
| 477 |
break; |
| 478 |
|
| 479 |
case 'multiselect': |
| 480 |
$this->select( $form_field, true, $post_id, $type, $form_id ); |
| 481 |
$this->conditional_logic( $form_field, $form_id ); |
| 482 |
break; |
| 483 |
|
| 484 |
case 'radio': |
| 485 |
$this->radio( $form_field, $post_id, $type, $form_id ); |
| 486 |
$this->conditional_logic( $form_field, $form_id ); |
| 487 |
break; |
| 488 |
|
| 489 |
case 'checkbox': |
| 490 |
$this->checkbox( $form_field, $post_id, $type, $form_id ); |
| 491 |
$this->conditional_logic( $form_field, $form_id ); |
| 492 |
break; |
| 493 |
|
| 494 |
case 'url': |
| 495 |
$this->url( $form_field, $post_id, $type, $form_id ); |
| 496 |
$this->conditional_logic( $form_field, $form_id ); |
| 497 |
break; |
| 498 |
|
| 499 |
case 'email': |
| 500 |
$this->email( $form_field, $post_id, $type, $form_id ); |
| 501 |
$this->conditional_logic( $form_field, $form_id ); |
| 502 |
break; |
| 503 |
|
| 504 |
case 'password': |
| 505 |
$this->password( $form_field, $post_id, $type, $form_id ); |
| 506 |
$this->conditional_logic( $form_field, $form_id ); |
| 507 |
break; |
| 508 |
|
| 509 |
case 'taxonomy': |
| 510 |
|
| 511 |
$this->taxonomy( $form_field, $post_id, $form_id ); |
| 512 |
$this->conditional_logic( $form_field, $form_id ); |
| 513 |
break; |
| 514 |
|
| 515 |
case 'section_break': |
| 516 |
$form_field['name'] = 'section_break'; |
| 517 |
$this->section_break( $form_field, $post_id, $form_id ); |
| 518 |
$this->conditional_logic( $form_field, $form_id ); |
| 519 |
break; |
| 520 |
|
| 521 |
case 'html': |
| 522 |
$form_field['name'] = 'custom_html_' . str_replace( ' ', '_', $form_field['label'] ); |
| 523 |
|
| 524 |
$this->html( $form_field, $form_id ); |
| 525 |
$this->conditional_logic( $form_field, $form_id ); |
| 526 |
break; |
| 527 |
|
| 528 |
case 'image_upload': |
| 529 |
$this->image_upload( $form_field, $post_id, $type, $form_id ); |
| 530 |
$this->conditional_logic( $form_field, $form_id ); |
| 531 |
break; |
| 532 |
|
| 533 |
case 'recaptcha': |
| 534 |
$this->recaptcha( $form_field, $post_id, $form_id ); |
| 535 |
$this->conditional_logic( $form_field, $form_id ); |
| 536 |
break; |
| 537 |
|
| 538 |
default: |
| 539 |
|
| 540 |
// fallback for a dynamic method of this class if exists |
| 541 |
$dynamic_method = 'field_' . $form_field['input_type']; |
| 542 |
|
| 543 |
if ( method_exists( $this, $dynamic_method ) ) { |
| 544 |
$this->{$dynamic_method}( $form_field, $post_id, $type, $form_id ); |
| 545 |
} |
| 546 |
|
| 547 |
do_action( 'wpuf_render_form_' . $form_field['input_type'], $form_field, $form_id, $post_id, $form_settings ); |
| 548 |
do_action( 'wpuf_render_pro_' . $form_field['input_type'], $form_field, $post_id, $type, $form_id, $form_settings, 'WPUF_Render_Form', $this, $this->multiform_start, isset( $form_settings['enable_multistep'] ) ? $form_settings['enable_multistep'] : '' ); |
| 549 |
break; |
| 550 |
} |
| 551 |
|
| 552 |
$this->render_item_after( $form_field ); |
| 553 |
} //end foreach |
| 554 |
|
| 555 |
if ( $hidden_fields ) { |
| 556 |
foreach ( $hidden_fields as $field ) { |
| 557 |
printf( '<input type="hidden" name="%s" value="%s">', esc_attr( $field['name'] ), esc_attr( $field['meta_value'] ) ); |
| 558 |
echo "\r\n"; |
| 559 |
} |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
public function submit_button( $form_id, $form_settings, $post_id ) { |
| 564 |
?> |
| 565 |
<li class="wpuf-submit"> |
| 566 |
<div class="wpuf-label"> |
| 567 |
|
| 568 |
</div> |
| 569 |
|
| 570 |
<?php wp_nonce_field( 'wpuf_form_add' ); ?> |
| 571 |
<input type="hidden" name="form_id" value="<?php echo esc_attr( $form_id ); ?>"> |
| 572 |
<input type="hidden" name="page_id" value="<?php echo get_post() ? esc_attr( get_the_ID() ) : '0'; ?>"> |
| 573 |
<input type="hidden" id="del_attach" name="delete_attachments[]"> |
| 574 |
<input type="hidden" name="action" value="wpuf_submit_post"> |
| 575 |
|
| 576 |
<?php |
| 577 |
if ( $post_id ) { |
| 578 |
$cur_post = get_post( $post_id ); ?> |
| 579 |
<input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ); ?>"> |
| 580 |
<input type="hidden" name="post_date" value="<?php echo esc_attr( $cur_post->post_date ); ?>"> |
| 581 |
<input type="hidden" name="comment_status" value="<?php echo esc_attr( $cur_post->comment_status ); ?>"> |
| 582 |
<input type="hidden" name="post_author" value="<?php echo esc_attr( $cur_post->post_author ); ?>"> |
| 583 |
<input type="submit" class="wpuf-submit-button" name="submit" value="<?php echo esc_attr( $form_settings['update_text'] ); ?>" /> |
| 584 |
<?php |
| 585 |
} else { ?> |
| 586 |
<input type="submit" class="wpuf-submit-button" name="submit" value="<?php echo esc_attr( $form_settings['submit_text'] ); ?>" /> |
| 587 |
<input type="hidden" name="wpuf_form_status" value="new"> |
| 588 |
<?php } ?> |
| 589 |
|
| 590 |
<?php if ( isset( $form_settings['draft_post'] ) && $form_settings['draft_post'] == 'true' ) { ?> |
| 591 |
<a href="#" class="btn" id="wpuf-post-draft"><?php esc_html_e( 'Save Draft', 'wp-user-frontend' ); ?></a> |
| 592 |
<?php } ?> |
| 593 |
</li> |
| 594 |
<?php |
| 595 |
} |
| 596 |
|
| 597 |
/** |
| 598 |
* Form preview handler |
| 599 |
* |
| 600 |
* @return void |
| 601 |
*/ |
| 602 |
public function preview_form() { |
| 603 |
$form_id = isset( $_GET['form_id'] ) ? intval( wp_unslash( $_GET['form_id'] ) ) : 0; |
| 604 |
|
| 605 |
if ( $form_id ) { |
| 606 |
wp_enqueue_script( 'jquery' ); |
| 607 |
wp_enqueue_style( 'wpuf-frontend-forms' ); |
| 608 |
?> |
| 609 |
|
| 610 |
<!doctype html> |
| 611 |
<html lang="en"> |
| 612 |
<head> |
| 613 |
<meta charset="UTF-8"> |
| 614 |
<title>Form Preview</title> |
| 615 |
|
| 616 |
<style type="text/css"> |
| 617 |
body { |
| 618 |
margin: 0; |
| 619 |
padding: 0; |
| 620 |
background: #eee; |
| 621 |
} |
| 622 |
|
| 623 |
.container { |
| 624 |
width: 700px; |
| 625 |
margin: 0 auto; |
| 626 |
margin-top: 20px; |
| 627 |
padding: 20px; |
| 628 |
background: #fff; |
| 629 |
border: 1px solid #DFDFDF; |
| 630 |
-webkit-box-shadow: 1px 1px 2px rgba(0,0,0,0.1); |
| 631 |
box-shadow: 1px 1px 2px rgba(0,0,0,0.1); |
| 632 |
} |
| 633 |
</style> |
| 634 |
|
| 635 |
</head> |
| 636 |
<body> |
| 637 |
<div class="container"> |
| 638 |
<?php $this->render_form( $form_id, null ); ?> |
| 639 |
</div> |
| 640 |
</body> |
| 641 |
</html> |
| 642 |
|
| 643 |
<?php |
| 644 |
} else { |
| 645 |
wp_die( 'Error generating the form preview' ); |
| 646 |
} |
| 647 |
|
| 648 |
exit; |
| 649 |
} |
| 650 |
|
| 651 |
/** |
| 652 |
* Prints required field asterisk |
| 653 |
* |
| 654 |
* @param array $attr |
| 655 |
* |
| 656 |
* @return string |
| 657 |
*/ |
| 658 |
public function required_mark( $attr ) { |
| 659 |
if ( isset( $attr['required'] ) && $attr['required'] == 'yes' ) { |
| 660 |
return ' <span class="required">*</span>'; |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
/** |
| 665 |
* Prints HTML5 required attribute |
| 666 |
* |
| 667 |
* @param array $attr |
| 668 |
* |
| 669 |
* @return string |
| 670 |
*/ |
| 671 |
public function required_html5( $attr ) { |
| 672 |
if ( $attr['required'] == 'yes' ) { |
| 673 |
// echo ' required="required"'; |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
/** |
| 678 |
* Print required class name |
| 679 |
* |
| 680 |
* @param array $attr |
| 681 |
* |
| 682 |
* @return string |
| 683 |
*/ |
| 684 |
public function required_class( $attr ) { |
| 685 |
if ( $attr['required'] == 'yes' ) { |
| 686 |
echo ' required'; |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
/** |
| 691 |
* Prints form input label |
| 692 |
* |
| 693 |
* @param array $attr |
| 694 |
*/ |
| 695 |
public function label( $attr, $post_id = 0 ) { |
| 696 |
if ( $post_id && $attr['input_type'] == 'password' ) { |
| 697 |
$attr['required'] = 'no'; |
| 698 |
} |
| 699 |
|
| 700 |
if ( isset( $attr['input_type'] ) && $attr['input_type'] == 'recaptcha' && $attr['recaptcha_type'] == 'invisible_recaptcha' ) { |
| 701 |
return; |
| 702 |
} ?> |
| 703 |
<div class="wpuf-label"> |
| 704 |
<label for="<?php echo isset( $attr['name'] ) ? esc_attr( $attr['name'] ) : 'cls'; ?>"><?php echo esc_attr( $attr['label'] ) . esc_attr( $this->required_mark( $attr ) ); ?></label> |
| 705 |
</div> |
| 706 |
<?php |
| 707 |
} |
| 708 |
|
| 709 |
/** |
| 710 |
* Prints help text for a field |
| 711 |
* |
| 712 |
* @param array $attr |
| 713 |
*/ |
| 714 |
public function help_text( $attr ) { |
| 715 |
if ( empty( $attr['help'] ) ) { |
| 716 |
return; |
| 717 |
} ?> |
| 718 |
<span class="wpuf-help"><?php echo esc_html( stripslashes( $attr['help'] ) ); ?></span> |
| 719 |
<?php |
| 720 |
} |
| 721 |
|
| 722 |
/** |
| 723 |
* Check if its a meta field |
| 724 |
* |
| 725 |
* @param array $attr |
| 726 |
* |
| 727 |
* @return bool |
| 728 |
*/ |
| 729 |
public function is_meta( $attr ) { |
| 730 |
if ( isset( $attr['is_meta'] ) && $attr['is_meta'] == 'yes' ) { |
| 731 |
return true; |
| 732 |
} |
| 733 |
|
| 734 |
return false; |
| 735 |
} |
| 736 |
|
| 737 |
/** |
| 738 |
* Get a meta value |
| 739 |
* |
| 740 |
* @param int $object_id user_ID or post_ID |
| 741 |
* @param string $meta_key |
| 742 |
* @param string $type post or user |
| 743 |
* @param bool $single |
| 744 |
* |
| 745 |
* @return string |
| 746 |
*/ |
| 747 |
public function get_meta( $object_id, $meta_key, $type = 'post', $single = true ) { |
| 748 |
if ( !$object_id ) { |
| 749 |
return ''; |
| 750 |
} |
| 751 |
|
| 752 |
if ( $type == 'post' ) { |
| 753 |
return get_post_meta( $object_id, $meta_key, $single ); |
| 754 |
} |
| 755 |
|
| 756 |
return get_user_meta( $object_id, $meta_key, $single ); |
| 757 |
} |
| 758 |
|
| 759 |
public function get_user_data( $user_id, $field ) { |
| 760 |
return get_user_by( 'id', $user_id )->$field; |
| 761 |
} |
| 762 |
|
| 763 |
/** |
| 764 |
* Prints a text field |
| 765 |
* |
| 766 |
* @param array $attr |
| 767 |
* @param int|null $post_id |
| 768 |
*/ |
| 769 |
public function text( $attr, $post_id, $type = 'post', $form_id = null ) { |
| 770 |
// checking for user profile username |
| 771 |
$username = false; |
| 772 |
$taxonomy = false; |
| 773 |
|
| 774 |
if ( $post_id ) { |
| 775 |
if ( $this->is_meta( $attr ) ) { |
| 776 |
$value = $this->get_meta( $post_id, $attr['name'], $type ); |
| 777 |
} else { |
| 778 |
|
| 779 |
// applicable for post tags |
| 780 |
if ( $type == 'post' && $attr['name'] == 'tags' ) { |
| 781 |
$post_tags = wp_get_post_tags( $post_id ); |
| 782 |
$tagsarray = []; |
| 783 |
|
| 784 |
foreach ( $post_tags as $tag ) { |
| 785 |
$tagsarray[] = $tag->name; |
| 786 |
} |
| 787 |
|
| 788 |
$value = implode( ', ', $tagsarray ); |
| 789 |
$taxonomy = true; |
| 790 |
} elseif ( $type == 'post' ) { |
| 791 |
$value = get_post_field( $attr['name'], $post_id ); |
| 792 |
} elseif ( $type == 'user' ) { |
| 793 |
$name = $attr['name']; |
| 794 |
$value = get_user_by( 'id', $post_id )->$name; |
| 795 |
|
| 796 |
if ( $attr['name'] == 'user_login' ) { |
| 797 |
$username = true; |
| 798 |
} |
| 799 |
} |
| 800 |
} |
| 801 |
} else { |
| 802 |
$value = $attr['default']; |
| 803 |
|
| 804 |
if ( $type == 'post' && $attr['name'] == 'tags' ) { |
| 805 |
$taxonomy = true; |
| 806 |
} |
| 807 |
} ?> |
| 808 |
|
| 809 |
<div class="wpuf-fields"> |
| 810 |
<input class="textfield<?php echo esc_attr( $this->required_class( $attr ) ); |
| 811 |
echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" type="text" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="text"<?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ); ?>" size="<?php echo esc_attr( $attr['size'] ); ?>" <?php echo esc_attr( $username ) ? 'disabled' : ''; ?> /> |
| 812 |
<span class="wpuf-wordlimit-message wpuf-help"></span> |
| 813 |
<?php $this->help_text( $attr ); ?> |
| 814 |
|
| 815 |
<?php if ( $taxonomy ) { |
| 816 |
$query_string = '?action=wpuf_ajax_tag_search&tax=post_tag'; |
| 817 |
$query_string .= '&nonce=' . wp_create_nonce( 'wpuf_ajax_tag_search' ); |
| 818 |
?> |
| 819 |
<script type="text/javascript"> |
| 820 |
;(function($) { |
| 821 |
$(document).ready( function(){ |
| 822 |
$('li.tags input[name=tags]').suggest( wpuf_frontend.ajaxurl + '<?php echo esc_js( $query_string ); ?>', { delay: 500, minchars: 2, multiple: true, multipleSep: ', ' } ); |
| 823 |
}); |
| 824 |
})(jQuery); |
| 825 |
</script> |
| 826 |
<?php } ?> |
| 827 |
</div> |
| 828 |
|
| 829 |
<?php |
| 830 |
if ( isset( $attr['word_restriction'] ) && $attr['word_restriction'] ) { |
| 831 |
$this->check_word_restriction_func( $attr['word_restriction'], 'no', $attr['name'] . '_' . $form_id ); |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
/** |
| 836 |
* Function to check word restriction |
| 837 |
* |
| 838 |
* @param $word_nums number of words allowed |
| 839 |
*/ |
| 840 |
public function check_word_restriction_func( $word_nums, $rich_text, $field_name ) { |
| 841 |
// bail out if it is dashboard |
| 842 |
if ( is_admin() ) { |
| 843 |
return; |
| 844 |
} ?> |
| 845 |
<script type="text/javascript"> |
| 846 |
;(function($) { |
| 847 |
$(document).ready( function(){ |
| 848 |
WP_User_Frontend.editorLimit.bind(<?php printf( '%d, "%s", "%s"', esc_attr( $word_nums ), esc_attr( $field_name ), esc_attr( $rich_text ) ); ?>); |
| 849 |
}); |
| 850 |
})(jQuery); |
| 851 |
</script> |
| 852 |
<?php |
| 853 |
} |
| 854 |
|
| 855 |
/** |
| 856 |
* Prints a textarea field |
| 857 |
* |
| 858 |
* @param array $attr |
| 859 |
* @param int|null $post_id |
| 860 |
*/ |
| 861 |
public function textarea( $attr, $post_id, $type, $form_id ) { |
| 862 |
$req_class = ( $attr['required'] == 'yes' ) ? 'required' : 'rich-editor'; |
| 863 |
|
| 864 |
if ( $post_id ) { |
| 865 |
if ( $this->is_meta( $attr ) ) { |
| 866 |
$value = $this->get_meta( $post_id, $attr['name'], $type, true ); |
| 867 |
} else { |
| 868 |
if ( $type == 'post' ) { |
| 869 |
$value = get_post_field( $attr['name'], $post_id ); |
| 870 |
} else { |
| 871 |
$value = $this->get_user_data( $post_id, $attr['name'] ); |
| 872 |
} |
| 873 |
} |
| 874 |
} else { |
| 875 |
$value = $attr['default']; |
| 876 |
} ?> |
| 877 |
|
| 878 |
<?php if ( in_array( $attr['rich'], [ 'yes', 'teeny' ] ) ) { ?> |
| 879 |
<div class="wpuf-fields wpuf-rich-validation <?php printf( 'wpuf_%s_%s', esc_attr( $attr['name'] ), esc_attr( $form_id ) ); ?>" data-type="rich" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-name="<?php echo esc_attr( $attr['name'] ); ?>"> |
| 880 |
<?php } else { ?> |
| 881 |
<div class="wpuf-fields"> |
| 882 |
<?php } ?> |
| 883 |
|
| 884 |
<?php if ( isset( $attr['insert_image'] ) && $attr['insert_image'] == 'yes' ) { ?> |
| 885 |
<div id="wpuf-insert-image-container"> |
| 886 |
<a class="wpuf-button wpuf-insert-image" id="wpuf-insert-image_<?php echo esc_attr( $form_id ); ?>" href="#" data-form_id="<?php echo esc_attr( $form_id ); ?>"> |
| 887 |
<span class="wpuf-media-icon"></span> |
| 888 |
<?php esc_html_e( 'Insert Photo', 'wp-user-frontend' ); ?> |
| 889 |
</a> |
| 890 |
</div> |
| 891 |
|
| 892 |
<script type="text/javascript"> |
| 893 |
;(function($) { |
| 894 |
$(document).ready( function(){ |
| 895 |
WP_User_Frontend.insertImage('wpuf-insert-image_<?php echo esc_attr( $form_id ); ?>', '<?php echo esc_attr( $form_id ); ?>'); |
| 896 |
}); |
| 897 |
})(jQuery); |
| 898 |
</script> |
| 899 |
<?php } ?> |
| 900 |
|
| 901 |
<?php |
| 902 |
$form_settings = wpuf_get_form_settings( $form_id ); |
| 903 |
$layout = isset( $form_settings['form_layout'] ) ? $form_settings['form_layout'] : 'layout1'; |
| 904 |
$textarea_id = $attr['name'] ? $attr['name'] . '_' . $form_id : 'textarea_' . $this->field_count; |
| 905 |
$content_css = includes_url() . 'js/tinymce/skins/wordpress/wp-content.css'; |
| 906 |
|
| 907 |
if ( $attr['rich'] == 'yes' ) { |
| 908 |
$editor_settings = [ |
| 909 |
'textarea_rows' => $attr['rows'], |
| 910 |
'quicktags' => false, |
| 911 |
'media_buttons' => false, |
| 912 |
'editor_class' => $req_class, |
| 913 |
'textarea_name' => $attr['name'], |
| 914 |
'tinymce' => [ |
| 915 |
'content_css' => $content_css . ', ' . WPUF_ASSET_URI . '/css/frontend-form/' . $layout . '.css', |
| 916 |
], |
| 917 |
]; |
| 918 |
|
| 919 |
$editor_settings = apply_filters( 'wpuf_textarea_editor_args', $editor_settings ); |
| 920 |
wp_editor( $value, $textarea_id, $editor_settings ); |
| 921 |
} elseif ( $attr['rich'] == 'teeny' ) { |
| 922 |
$editor_settings = [ |
| 923 |
'textarea_rows' => $attr['rows'], |
| 924 |
'quicktags' => false, |
| 925 |
'media_buttons' => false, |
| 926 |
'teeny' => true, |
| 927 |
'editor_class' => $req_class, |
| 928 |
'textarea_name' => $attr['name'], |
| 929 |
'tinymce' => [ |
| 930 |
'content_css' => $content_css . ', ' . WPUF_ASSET_URI . '/css/frontend-form/' . $layout . '.css', |
| 931 |
], |
| 932 |
]; |
| 933 |
|
| 934 |
$editor_settings = apply_filters( 'wpuf_textarea_editor_args', $editor_settings ); |
| 935 |
wp_editor( $value, $textarea_id, $editor_settings ); |
| 936 |
} else { |
| 937 |
?> |
| 938 |
<textarea class="textareafield<?php echo esc_attr( $this->required_class( $attr ) ); ?> <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" name="<?php echo esc_attr( $attr['name'] ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="textarea"<?php $this->required_html5( $attr ); ?> placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" rows="<?php echo esc_attr( $attr['rows'] ); ?>" cols="<?php echo esc_attr( $attr['cols'] ); ?>"><?php echo esc_textarea( $value ); ?></textarea> |
| 939 |
<span class="wpuf-wordlimit-message wpuf-help"></span> |
| 940 |
<?php |
| 941 |
} ?> |
| 942 |
<?php $this->help_text( $attr ); ?> |
| 943 |
</div> |
| 944 |
<?php |
| 945 |
|
| 946 |
if ( isset( $attr['word_restriction'] ) && $attr['word_restriction'] ) { |
| 947 |
$this->check_word_restriction_func( $attr['word_restriction'], $attr['rich'], $attr['name'] . '_' . $form_id ); |
| 948 |
} |
| 949 |
} |
| 950 |
|
| 951 |
/** |
| 952 |
* Prints a select or multiselect field |
| 953 |
* |
| 954 |
* @param array $attr |
| 955 |
* @param bool $multiselect |
| 956 |
* @param int|null $post_id |
| 957 |
*/ |
| 958 |
public function select( $attr, $multiselect, $post_id, $type, $form_id = null ) { |
| 959 |
if ( ! $multiselect ) { |
| 960 |
$multiselect = false; |
| 961 |
} |
| 962 |
if ( $post_id ) { |
| 963 |
$selected = $this->get_meta( $post_id, $attr['name'], $type ); |
| 964 |
|
| 965 |
if ( $multiselect ) { |
| 966 |
if ( is_serialized( $selected ) ) { |
| 967 |
$selected = wpuf_safe_unserialize( $selected ); |
| 968 |
} elseif ( is_array( $selected ) ) { |
| 969 |
$selected = $selected; |
| 970 |
} else { |
| 971 |
$selected = explode( self::$separator, $selected ); |
| 972 |
} |
| 973 |
} |
| 974 |
} else { |
| 975 |
$selected = isset( $attr['selected'] ) ? $attr['selected'] : ''; |
| 976 |
$selected = $multiselect ? ( is_array( $selected ) ? $selected : [] ) : $selected; |
| 977 |
} |
| 978 |
|
| 979 |
$name = $multiselect ? $attr['name'] . '[]' : $attr['name']; |
| 980 |
$multi = $multiselect ? ' multiple="multiple"' : ''; |
| 981 |
$data_type = $multiselect ? 'multiselect' : 'select'; |
| 982 |
$css = $multiselect ? ' class="multiselect wpuf_' . $attr['name'] . '_' . $form_id . '"' : ''; ?> |
| 983 |
|
| 984 |
<div class="wpuf-fields"> |
| 985 |
<select <?php echo esc_attr( $css ); ?> class="<?php echo 'wpuf_' . esc_attr( $attr['name'] ) . '_' .esc_attr( $form_id ); ?>" name="<?php echo esc_attr( $name ); ?>"<?php echo esc_attr( $multi ); ?> data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="<?php echo esc_attr($data_type ); ?>"<?php esc_attr( $this->required_html5( $attr ) ); ?>> |
| 986 |
|
| 987 |
<?php if ( !empty( $attr['first'] ) ) { ?> |
| 988 |
<option value=""><?php echo esc_attr( $attr['first'] ); ?></option> |
| 989 |
<?php } ?> |
| 990 |
|
| 991 |
<?php |
| 992 |
if ( $attr['options'] && count( $attr['options'] ) > 0 ) { |
| 993 |
foreach ( $attr['options'] as $value => $option ) { |
| 994 |
$current_select = $multiselect ? selected( in_array( $value, $selected ), true, false ) : selected( $selected, $value, false ); ?> |
| 995 |
<option value="<?php echo esc_attr( $value ); ?>"<?php echo esc_attr( $current_select ); ?>><?php echo esc_html( $option ); ?></option> |
| 996 |
<?php |
| 997 |
} |
| 998 |
} ?> |
| 999 |
</select> |
| 1000 |
<?php $this->help_text( $attr ); ?> |
| 1001 |
</div> |
| 1002 |
<?php |
| 1003 |
} |
| 1004 |
|
| 1005 |
/** |
| 1006 |
* Prints a radio field |
| 1007 |
* |
| 1008 |
* @param array $attr |
| 1009 |
* @param int|null $post_id |
| 1010 |
*/ |
| 1011 |
public function radio( $attr, $post_id, $type, $form_id ) { |
| 1012 |
$selected = isset( $attr['selected'] ) ? $attr['selected'] : ''; |
| 1013 |
|
| 1014 |
if ( $post_id ) { |
| 1015 |
$selected = $this->get_meta( $post_id, $attr['name'], $type, true ); |
| 1016 |
} ?> |
| 1017 |
|
| 1018 |
<div class="wpuf-fields" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="radio"> |
| 1019 |
|
| 1020 |
<?php |
| 1021 |
if ( $attr['options'] && count( $attr['options'] ) > 0 ) { |
| 1022 |
foreach ( $attr['options'] as $value => $option ) { |
| 1023 |
?> |
| 1024 |
|
| 1025 |
<label <?php echo $attr['inline'] == 'yes' ? 'class="wpuf-radio-inline"' : 'class="wpuf-radio-block"'; ?>> |
| 1026 |
<input name="<?php echo esc_attr( $attr['name'] ); ?>" class="<?php echo 'wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $selected, $value ); ?> /> |
| 1027 |
<?php echo esc_html( $option ); ?> |
| 1028 |
</label> |
| 1029 |
<?php |
| 1030 |
} |
| 1031 |
} ?> |
| 1032 |
|
| 1033 |
<?php $this->help_text( $attr ); ?> |
| 1034 |
</div> |
| 1035 |
|
| 1036 |
<?php |
| 1037 |
} |
| 1038 |
|
| 1039 |
/** |
| 1040 |
* Prints a checkbox field |
| 1041 |
* |
| 1042 |
* @param array $attr |
| 1043 |
* @param int|null $post_id |
| 1044 |
*/ |
| 1045 |
public function checkbox( $attr, $post_id, $type, $form_id ) { |
| 1046 |
$selected = isset( $attr['selected'] ) ? $attr['selected'] : []; |
| 1047 |
|
| 1048 |
if ( $post_id ) { |
| 1049 |
if ( $value = $this->get_meta( $post_id, $attr['name'], $type, true ) ) { |
| 1050 |
if ( is_serialized( $value ) ) { |
| 1051 |
$selected = wpuf_safe_unserialize( $value ); |
| 1052 |
} elseif ( is_array( $value ) ) { |
| 1053 |
$selected = $value; |
| 1054 |
} else { |
| 1055 |
$selected = explode( self::$separator, $value ); |
| 1056 |
} |
| 1057 |
} |
| 1058 |
} ?> |
| 1059 |
|
| 1060 |
<div class="wpuf-fields" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="radio"> |
| 1061 |
|
| 1062 |
<?php |
| 1063 |
if ( $attr['options'] && count( $attr['options'] ) > 0 ) { |
| 1064 |
foreach ( $attr['options'] as $value => $option ) { |
| 1065 |
?> |
| 1066 |
<label <?php echo $attr['inline'] == 'yes' ? 'class="wpuf-checkbox-inline"' : 'class="wpuf-checkbox-block"'; ?>> |
| 1067 |
<input type="checkbox" class="<?php echo 'wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" name="<?php echo esc_attr( $attr['name'] ); ?>[]" value="<?php echo esc_attr( $value ); ?>"<?php echo in_array( $value, $selected ) ? ' checked="checked"' : ''; ?> /> |
| 1068 |
<?php echo esc_html( $option ); ?> |
| 1069 |
</label> |
| 1070 |
<?php |
| 1071 |
} |
| 1072 |
} ?> |
| 1073 |
|
| 1074 |
<?php $this->help_text( $attr ); ?> |
| 1075 |
|
| 1076 |
</div> |
| 1077 |
|
| 1078 |
<?php |
| 1079 |
} |
| 1080 |
|
| 1081 |
/** |
| 1082 |
* Prints a url field |
| 1083 |
* |
| 1084 |
* @param array $attr |
| 1085 |
* @param int|null $post_id |
| 1086 |
*/ |
| 1087 |
public function url( $attr, $post_id, $type, $form_id ) { |
| 1088 |
if ( $post_id ) { |
| 1089 |
if ( $this->is_meta( $attr ) ) { |
| 1090 |
$value = $this->get_meta( $post_id, $attr['name'], $type, true ); |
| 1091 |
} else { |
| 1092 |
//must be user profile url |
| 1093 |
$value = $this->get_user_data( $post_id, $attr['name'] ); |
| 1094 |
} |
| 1095 |
} else { |
| 1096 |
$value = $attr['default']; |
| 1097 |
} ?> |
| 1098 |
|
| 1099 |
<div class="wpuf-fields"> |
| 1100 |
<input id="wpuf-<?php echo esc_attr( $attr['name'] ); ?>" type="url" class="url <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="text"<?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ); ?>" size="<?php echo esc_attr( $attr['size'] ); ?>" /> |
| 1101 |
<?php $this->help_text( $attr ); ?> |
| 1102 |
</div> |
| 1103 |
|
| 1104 |
<?php |
| 1105 |
} |
| 1106 |
|
| 1107 |
/** |
| 1108 |
* Prints a email field |
| 1109 |
* |
| 1110 |
* @param array $attr |
| 1111 |
* @param int|null $post_id |
| 1112 |
*/ |
| 1113 |
public function email( $attr, $post_id, $type, $form_id ) { |
| 1114 |
if ( ! $type ) { |
| 1115 |
$type = 'post'; |
| 1116 |
} |
| 1117 |
if ( $post_id ) { |
| 1118 |
if ( $this->is_meta( $attr ) ) { |
| 1119 |
$value = $this->get_meta( $post_id, $attr['name'], $type, true ); |
| 1120 |
} else { |
| 1121 |
//must be user email |
| 1122 |
$value = $this->get_user_data( $post_id, $attr['name'] ); |
| 1123 |
} |
| 1124 |
} else { |
| 1125 |
$value = $attr['default']; |
| 1126 |
} ?> |
| 1127 |
|
| 1128 |
<div class="wpuf-fields"> |
| 1129 |
<input id="wpuf-<?php echo esc_attr( $attr['name'] ); ?>" type="email" class="email <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="email" <?php $this->required_html5( $attr ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="<?php echo esc_attr( $value ); ?>" size="<?php echo esc_attr( $attr['size'] ); ?>" /> |
| 1130 |
<?php $this->help_text( $attr ); ?> |
| 1131 |
</div> |
| 1132 |
|
| 1133 |
<?php |
| 1134 |
} |
| 1135 |
|
| 1136 |
/** |
| 1137 |
* Prints a email field |
| 1138 |
* |
| 1139 |
* @param array $attr |
| 1140 |
*/ |
| 1141 |
public function password( $attr, $post_id, $type, $form_id ) { |
| 1142 |
if ( $post_id ) { |
| 1143 |
$attr['required'] = 'no'; |
| 1144 |
} |
| 1145 |
|
| 1146 |
$repeat_pass = ( $attr['repeat_pass'] == 'yes' ) ? true : false; |
| 1147 |
$pass_strength = ( $attr['pass_strength'] == 'yes' ) ? true : false; ?> |
| 1148 |
|
| 1149 |
<div class="wpuf-fields"> |
| 1150 |
<input id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_1'; ?>" type="password" class="password <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="password"<?php $this->required_html5( $attr ); ?> data-repeat="<?php echo esc_attr( $repeat_pass ) ? 'true' : 'false'; ?>" name="pass1" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" value="" size="<?php echo esc_attr( $attr['size'] ); ?>" /> |
| 1151 |
<?php $this->help_text( $attr ); ?> |
| 1152 |
</div> |
| 1153 |
|
| 1154 |
<?php |
| 1155 |
if ( $repeat_pass ) { |
| 1156 |
$field_size = !empty( $attr['width'] ) ? ' field-size-' . $attr['width'] : ''; |
| 1157 |
|
| 1158 |
echo wp_kses_post( '</li>' ); |
| 1159 |
echo wp_kses_post( '<li class="wpuf-el password-repeat ' . $field_size . '" data-label="' . esc_attr( __( 'Confirm Password', 'wp-user-frontend' ) ) . '">' ); |
| 1160 |
|
| 1161 |
$this->label( ['name' => 'pass2', 'label' => $attr['re_pass_label'], 'required' => $post_id ? 'no' : 'yes'] ); ?> |
| 1162 |
|
| 1163 |
<div class="wpuf-fields"> |
| 1164 |
<input id="<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_2'; ?>" type="password" class="password <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="confirm_password"<?php $this->required_html5( $attr ); ?> name="pass2" value="" placeholder="<?php echo esc_attr( $attr['placeholder'] ); ?>" size="<?php echo esc_attr( $attr['size'] ); ?>" /> |
| 1165 |
</div> |
| 1166 |
|
| 1167 |
<?php |
| 1168 |
} |
| 1169 |
|
| 1170 |
if ( $pass_strength ) { |
| 1171 |
echo wp_kses_post( '</li>' ); |
| 1172 |
echo wp_kses_post( '<li>' ); |
| 1173 |
|
| 1174 |
wp_enqueue_script( 'wpuf-zxcvbn' ); |
| 1175 |
wp_enqueue_script( 'wpuf-password-strength-meter' ); ?> |
| 1176 |
<div class="wpuf-label"> |
| 1177 |
|
| 1178 |
</div> |
| 1179 |
|
| 1180 |
<div class="wpuf-fields"> |
| 1181 |
<div class="pass-strength-result" id="pass-strength-result_<?php echo esc_attr( $form_id ); ?>" style="display: block"><?php esc_html_e( 'Strength indicator', 'wp-user-frontend' ); ?></div> |
| 1182 |
</div> |
| 1183 |
|
| 1184 |
<script type="text/javascript"> |
| 1185 |
jQuery(function($) { |
| 1186 |
function check_pass_strength() { |
| 1187 |
var pass1 = $("#<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_1'; ?>").val(), |
| 1188 |
pass2 = $("#<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_2'; ?>").val(), |
| 1189 |
strength; |
| 1190 |
|
| 1191 |
if ( typeof pass2 === undefined ) { |
| 1192 |
pass2 = pass1; |
| 1193 |
} |
| 1194 |
|
| 1195 |
$("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").removeClass('short bad good strong'); |
| 1196 |
if (!pass1) { |
| 1197 |
$("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").html(pwsL10n.empty); |
| 1198 |
return; |
| 1199 |
} |
| 1200 |
|
| 1201 |
strength = wp.passwordStrength.meter(pass1, wp.passwordStrength.userInputBlacklist(), pass2); |
| 1202 |
|
| 1203 |
switch (strength) { |
| 1204 |
case 2: |
| 1205 |
$("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('bad').html(pwsL10n.bad); |
| 1206 |
break; |
| 1207 |
case 3: |
| 1208 |
$("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('good').html(pwsL10n.good); |
| 1209 |
break; |
| 1210 |
case 4: |
| 1211 |
$("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('strong').html(pwsL10n.strong); |
| 1212 |
break; |
| 1213 |
case 5: |
| 1214 |
$("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('short').html(pwsL10n.mismatch); |
| 1215 |
break; |
| 1216 |
default: |
| 1217 |
$("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").addClass('short').html(pwsL10n['short']); |
| 1218 |
} |
| 1219 |
} |
| 1220 |
|
| 1221 |
$("#<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_1'; ?>").val('').keyup(check_pass_strength); |
| 1222 |
$("#<?php echo esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ) . '_2'; ?>").val('').keyup(check_pass_strength); |
| 1223 |
$("#pass-strength-result_<?php echo esc_attr( $form_id ); ?>").show(); |
| 1224 |
}); |
| 1225 |
</script> |
| 1226 |
<?php |
| 1227 |
} |
| 1228 |
} |
| 1229 |
|
| 1230 |
public function taxnomy_select( $terms, $attr ) { |
| 1231 |
$selected = $terms ? $terms : ''; |
| 1232 |
$required = sprintf( 'data-required="%s" data-type="select"', $attr['required'] ); |
| 1233 |
$taxonomy = $attr['name']; |
| 1234 |
$class = ' wpuf_' . $attr['name'] . '_' . $selected; |
| 1235 |
$exclude_type = isset( $attr['exclude_type'] ) ? $attr['exclude_type'] : 'exclude'; |
| 1236 |
$exclude = isset( $attr['exclude'] ) ? $attr['exclude'] : ''; |
| 1237 |
|
| 1238 |
if ( $exclude_type == 'child_of' && !empty( $exclude ) ) { |
| 1239 |
$exclude = $exclude[0]; |
| 1240 |
} |
| 1241 |
|
| 1242 |
$tax_args = [ |
| 1243 |
'show_option_none' => __( '-- Select --', 'wp-user-frontend' ), |
| 1244 |
'hierarchical' => 1, |
| 1245 |
'hide_empty' => 0, |
| 1246 |
'orderby' => isset( $attr['orderby'] ) ? $attr['orderby'] : 'name', |
| 1247 |
'order' => isset( $attr['order'] ) ? $attr['order'] : 'ASC', |
| 1248 |
'name' => $taxonomy . '[]', |
| 1249 |
'taxonomy' => $taxonomy, |
| 1250 |
'echo' => 0, |
| 1251 |
'title_li' => '', |
| 1252 |
'class' => 'cat-ajax ' . $taxonomy . $class, |
| 1253 |
$exclude_type => $exclude, |
| 1254 |
'selected' => $selected, |
| 1255 |
'depth' => 1, |
| 1256 |
'child_of' => isset( $attr['parent_cat'] ) ? $attr['parent_cat'] : '', |
| 1257 |
]; |
| 1258 |
|
| 1259 |
$tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args ); |
| 1260 |
|
| 1261 |
$select = wp_dropdown_categories( $tax_args ); |
| 1262 |
|
| 1263 |
echo wp_kses_post( str_replace( '<select', '<select ' . $required, $select ) ); |
| 1264 |
$attr = [ |
| 1265 |
'required' => $attr['required'], |
| 1266 |
'name' => $attr['name'], |
| 1267 |
'exclude_type' => $attr['exclude_type'], |
| 1268 |
'exclude' => isset( $attr['exclude'] ) ? $attr['exclude'] : '', |
| 1269 |
'orderby' => $attr['orderby'], |
| 1270 |
'order' => $attr['order'], |
| 1271 |
//'last_term_id' => isset( $attr['parent_cat'] ) ? $attr['parent_cat'] : '', |
| 1272 |
//'term_id' => $selected |
| 1273 |
]; |
| 1274 |
$attr = apply_filters( 'wpuf_taxonomy_checklist_args', $attr ); ?> |
| 1275 |
<span data-taxonomy=<?php echo esc_attr( wp_json_encode( $attr ) ); ?>></span> |
| 1276 |
<?php |
| 1277 |
} |
| 1278 |
|
| 1279 |
/** |
| 1280 |
* Check if a taxonomy field is gated (custom taxonomy when pro is not active) |
| 1281 |
* |
| 1282 |
* @param array $form_field Field configuration |
| 1283 |
* @return bool True if field is gated and should be skipped |
| 1284 |
*/ |
| 1285 |
private function is_taxonomy_field_gated( $form_field ) { |
| 1286 |
// Only check taxonomy fields |
| 1287 |
if ( $form_field['input_type'] !== 'taxonomy' ) { |
| 1288 |
return false; |
| 1289 |
} |
| 1290 |
|
| 1291 |
// If pro is active, no fields are gated |
| 1292 |
if ( wpuf_is_pro_active() ) { |
| 1293 |
return false; |
| 1294 |
} |
| 1295 |
|
| 1296 |
// Get free taxonomies (built-in + taxonomies for post/page) |
| 1297 |
$free_taxonomies = wpuf_get_free_taxonomies(); |
| 1298 |
return ! in_array( $form_field['name'], $free_taxonomies, true ); |
| 1299 |
} |
| 1300 |
|
| 1301 |
/** |
| 1302 |
* Prints a taxonomy field |
| 1303 |
* |
| 1304 |
* @param array $attr |
| 1305 |
* @param int|null $post_id |
| 1306 |
*/ |
| 1307 |
public function taxonomy( $attr, $post_id, $form_id ) { |
| 1308 |
// Check if this is a custom taxonomy and pro is not active |
| 1309 |
$free_taxonomies = wpuf_get_free_taxonomies(); |
| 1310 |
if ( ! in_array( $attr['name'], $free_taxonomies, true ) && ! wpuf_is_pro_active() ) { |
| 1311 |
// Don't render custom taxonomies when pro is not active |
| 1312 |
return; |
| 1313 |
} |
| 1314 |
|
| 1315 |
$exclude_type = isset( $attr['exclude_type'] ) ? esc_attr( $attr['exclude_type'] ) : 'exclude'; |
| 1316 |
// $exclude = $attr['exclude']; |
| 1317 |
$exclude = isset( $attr['exclude'] ) ? esc_attr( $attr['exclude'] ) : ''; |
| 1318 |
|
| 1319 |
if ( $exclude_type == 'child_of' ) { |
| 1320 |
$exclude = $exclude[0]; |
| 1321 |
} |
| 1322 |
|
| 1323 |
$taxonomy = $attr['name']; |
| 1324 |
$class = ' wpuf_' . $attr['name'] . '_' . $form_id; |
| 1325 |
$current_user = get_current_user_id(); |
| 1326 |
|
| 1327 |
$terms = []; |
| 1328 |
|
| 1329 |
if ( $post_id && $attr['type'] == 'text' ) { |
| 1330 |
$terms = wp_get_post_terms( $post_id, $taxonomy, ['fields' => 'names'] ); |
| 1331 |
} elseif ( $post_id ) { |
| 1332 |
$terms = wp_get_post_terms( $post_id, $taxonomy, ['fields' => 'ids'] ); |
| 1333 |
} |
| 1334 |
|
| 1335 |
if ( !taxonomy_exists( $taxonomy ) ) { |
| 1336 |
echo wp_kses_post( '<br><div class="wpuf-message">' . __( 'This field is no longer available.', 'wp-user-frontend' ) . '</div>' ); |
| 1337 |
|
| 1338 |
return; |
| 1339 |
} |
| 1340 |
|
| 1341 |
$div_class = 'wpuf_' . $attr['name'] . '_' . $attr['type'] . '_' . $attr['id'] . '_' . $form_id; ?> |
| 1342 |
|
| 1343 |
|
| 1344 |
<?php if ( $attr['type'] == 'checkbox' ) { ?> |
| 1345 |
<div class="wpuf-fields <?php echo esc_attr( $div_class ); ?>" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="tax-checkbox"> |
| 1346 |
<?php } else { ?> |
| 1347 |
<div class="wpuf-fields <?php echo esc_attr( $div_class ); ?>"> |
| 1348 |
<?php } ?> |
| 1349 |
|
| 1350 |
<?php |
| 1351 |
switch ( $attr['type'] ) { |
| 1352 |
case 'ajax': |
| 1353 |
$class = ' wpuf_' . $attr['name'] . '_' . $form_id; |
| 1354 |
?> |
| 1355 |
<div class="category-wrap <?php echo esc_attr( $class ); ?>"> |
| 1356 |
<?php |
| 1357 |
|
| 1358 |
if ( !count( $terms ) ) { |
| 1359 |
?> |
| 1360 |
<div id="lvl0" level="0"> |
| 1361 |
<?php $this->taxnomy_select( null, $attr, $form_id ); ?> |
| 1362 |
</div> |
| 1363 |
<?php |
| 1364 |
} else { |
| 1365 |
$level = 0; |
| 1366 |
asort( $terms ); |
| 1367 |
$last_term_id = end( $terms ); |
| 1368 |
|
| 1369 |
foreach ( $terms as $term_id ) { |
| 1370 |
$class = ( $last_term_id != $term_id ) ? 'hasChild' : ''; ?> |
| 1371 |
<div id="lvl<?php echo esc_attr( $level ); ?>" level="<?php echo esc_attr( $level ); ?>" > |
| 1372 |
<?php $this->taxnomy_select( $term_id, $attr ); ?> |
| 1373 |
</div> |
| 1374 |
<?php |
| 1375 |
$attr['parent_cat'] = $term_id; |
| 1376 |
$level++; |
| 1377 |
} |
| 1378 |
} |
| 1379 |
|
| 1380 |
?> |
| 1381 |
</div> |
| 1382 |
<span class="loading"></span> |
| 1383 |
<?php |
| 1384 |
break; |
| 1385 |
|
| 1386 |
case 'select': |
| 1387 |
$selected = $terms ? $terms[0] : ''; |
| 1388 |
$required = sprintf( 'data-required="%s" data-type="select"', $attr['required'] ); |
| 1389 |
$tax_args = [ |
| 1390 |
'show_option_none' => isset( $attr['first'] ) ? $attr['first'] : '--select--', |
| 1391 |
'hierarchical' => 1, |
| 1392 |
'hide_empty' => 0, |
| 1393 |
'orderby' => isset( $attr['orderby'] ) ? $attr['orderby'] : 'name', |
| 1394 |
'order' => isset( $attr['order'] ) ? $attr['order'] : 'ASC', |
| 1395 |
'name' => $taxonomy . '[]', |
| 1396 |
'taxonomy' => $taxonomy, |
| 1397 |
'echo' => 0, |
| 1398 |
'title_li' => '', |
| 1399 |
'class' => $taxonomy . $class, |
| 1400 |
$exclude_type => $exclude, |
| 1401 |
'selected' => $selected, |
| 1402 |
]; |
| 1403 |
|
| 1404 |
$tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args ); |
| 1405 |
|
| 1406 |
$select = wp_dropdown_categories( $tax_args ); |
| 1407 |
|
| 1408 |
echo wp_kses_post( str_replace( '<select', '<select ' . $required, $select ) ); |
| 1409 |
break; |
| 1410 |
|
| 1411 |
case 'multiselect': |
| 1412 |
$selected = $terms ? $terms : []; |
| 1413 |
$required = sprintf( 'data-required="%s" data-type="multiselect"', $attr['required'] ); |
| 1414 |
$walker = new WPUF_Walker_Category_Multi(); |
| 1415 |
$tax_args = [ |
| 1416 |
// 'show_option_none' => __( '-- Select --', 'wpuf' ), |
| 1417 |
'hierarchical' => 1, |
| 1418 |
'hide_empty' => 0, |
| 1419 |
'orderby' => isset( $attr['orderby'] ) ? $attr['orderby'] : 'name', |
| 1420 |
'order' => isset( $attr['order'] ) ? $attr['order'] : 'ASC', |
| 1421 |
'name' => $taxonomy . '[]', |
| 1422 |
'id' => 'cat-ajax', |
| 1423 |
'taxonomy' => $taxonomy, |
| 1424 |
'echo' => 0, |
| 1425 |
'title_li' => '', |
| 1426 |
'class' => $taxonomy . ' multiselect' . $class, |
| 1427 |
$exclude_type => $exclude, |
| 1428 |
'selected' => $selected, |
| 1429 |
'walker' => $walker, |
| 1430 |
]; |
| 1431 |
|
| 1432 |
$tax_args = apply_filters( 'wpuf_taxonomy_checklist_args', $tax_args ); |
| 1433 |
|
| 1434 |
$select = wp_dropdown_categories( $tax_args ); |
| 1435 |
|
| 1436 |
echo wp_kses_post( str_replace( '<select', '<select multiple="multiple" ' . $required, $select ) ); |
| 1437 |
break; |
| 1438 |
|
| 1439 |
case 'checkbox': |
| 1440 |
wpuf_category_checklist( $post_id, false, $attr, $class ); |
| 1441 |
break; |
| 1442 |
|
| 1443 |
case 'text': |
| 1444 |
$query_string = '?action=wpuf_ajax_tag_search&tax=' . esc_attr( $attr['name'] ); |
| 1445 |
$query_string .= '&nonce=' . wp_create_nonce( 'wpuf_ajax_tag_search' ); |
| 1446 |
|
| 1447 |
?> |
| 1448 |
|
| 1449 |
<input class="textfield<?php echo esc_attr( $this->required_class( $attr ) ); ?>" id="<?php echo esc_attr( $attr['name'] ); ?>" type="text" data-required="<?php echo esc_attr( $attr['required'] ); ?>" data-type="text"<?php esc_attr( $this->required_html5( $attr ) ); ?> name="<?php echo esc_attr( $attr['name'] ); ?>" value="<?php echo esc_attr( implode( ', ', $terms ) ); ?>" size="40" /> |
| 1450 |
|
| 1451 |
<script type="text/javascript"> |
| 1452 |
;(function($) { |
| 1453 |
$(document).ready( function(){ |
| 1454 |
$('#<?php echo esc_attr( $attr['name'] ); ?>').suggest( wpuf_frontend.ajaxurl + '<?php echo esc_js( $query_string ); ?>', { delay: 500, minchars: 2, multiple: true, multipleSep: ', ' } ); |
| 1455 |
}); |
| 1456 |
})(jQuery); |
| 1457 |
</script> |
| 1458 |
|
| 1459 |
<?php |
| 1460 |
break; |
| 1461 |
|
| 1462 |
default: |
| 1463 |
// code... |
| 1464 |
break; |
| 1465 |
} ?> |
| 1466 |
<?php $this->help_text( $attr ); ?> |
| 1467 |
</div> |
| 1468 |
|
| 1469 |
|
| 1470 |
<?php |
| 1471 |
} |
| 1472 |
|
| 1473 |
/** |
| 1474 |
* Prints a HTML field |
| 1475 |
* |
| 1476 |
* @param array $attr |
| 1477 |
*/ |
| 1478 |
public function html( $attr, $form_id ) { |
| 1479 |
?> |
| 1480 |
<div class="wpuf-fields <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>"> |
| 1481 |
<?php echo esc_html( $attr['html'] ); ?> |
| 1482 |
</div> |
| 1483 |
<?php |
| 1484 |
} |
| 1485 |
|
| 1486 |
/** |
| 1487 |
* Prints a image upload field |
| 1488 |
* |
| 1489 |
* @param array $attr |
| 1490 |
* @param int|null $post_id |
| 1491 |
*/ |
| 1492 |
public function image_upload( $attr, $post_id, $type, $form_id ) { |
| 1493 |
$has_featured_image = false; |
| 1494 |
$has_images = false; |
| 1495 |
$has_avatar = false; |
| 1496 |
$unique_id = sprintf( '%s-%d', $attr['name'], $form_id ); |
| 1497 |
|
| 1498 |
if ( $post_id ) { |
| 1499 |
if ( $this->is_meta( $attr ) ) { |
| 1500 |
$images = $this->get_meta( $post_id, $attr['name'], $type, false ); |
| 1501 |
|
| 1502 |
if ( $images ) { |
| 1503 |
if ( is_serialized( $images[0] ) ) { |
| 1504 |
$images = wpuf_safe_unserialize( $images[0] ); |
| 1505 |
} |
| 1506 |
|
| 1507 |
if ( is_array( $images[0] ) ) { |
| 1508 |
$images = $images[0]; |
| 1509 |
} |
| 1510 |
} |
| 1511 |
|
| 1512 |
$has_images = true; |
| 1513 |
} else { |
| 1514 |
if ( $type == 'post' ) { |
| 1515 |
// it's a featured image then |
| 1516 |
$thumb_id = get_post_thumbnail_id( $post_id ); |
| 1517 |
|
| 1518 |
if ( $thumb_id ) { |
| 1519 |
$has_featured_image = true; |
| 1520 |
$featured_image = Upload_Ajax::attach_html( $thumb_id, 'featured_image' ); |
| 1521 |
} |
| 1522 |
} else { |
| 1523 |
// it must be a user avatar |
| 1524 |
$has_avatar = true; |
| 1525 |
$featured_image = get_avatar( $post_id ); |
| 1526 |
} |
| 1527 |
} |
| 1528 |
} |
| 1529 |
$button_label = empty( $attr['button_label'] ) ? __( 'Select Image', 'wp-user-frontend' ) : $attr['button_label']; ?> |
| 1530 |
|
| 1531 |
<div class="wpuf-fields"> |
| 1532 |
<div id="wpuf-<?php echo esc_attr( $unique_id ); ?>-upload-container"> |
| 1533 |
<div class="wpuf-attachment-upload-filelist" data-type="file" data-required="<?php echo esc_attr( $attr['required'] ); ?>"> |
| 1534 |
<a id="wpuf-<?php echo esc_attr( $unique_id ); ?>-pickfiles" data-form_id="<?php echo esc_attr( $form_id ); ?>" class="button file-selector <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>" href="#"><?php echo esc_attr( $button_label ); ?></a> |
| 1535 |
|
| 1536 |
<ul class="wpuf-attachment-list thumbnails"> |
| 1537 |
<?php |
| 1538 |
if ( $has_featured_image ) { |
| 1539 |
echo esc_attr( $featured_image ); |
| 1540 |
} |
| 1541 |
|
| 1542 |
if ( $has_avatar ) { |
| 1543 |
$avatar = get_user_meta( $post_id, 'user_avatar', true ); |
| 1544 |
|
| 1545 |
if ( $avatar ) { |
| 1546 |
echo wp_kses_post( '<li>' . $featured_image ); |
| 1547 |
printf( '<br><a href="#" data-confirm="%s" class="btn btn-danger btn-small wpuf-button button wpuf-delete-avatar">%s</a>', esc_html( __( 'Are you sure?', 'wp-user-frontend' ) ),esc_html( __( 'Delete', 'wp-user-frontend' ) ) ); |
| 1548 |
echo wp_kses_post( '</li>' ); |
| 1549 |
} |
| 1550 |
} |
| 1551 |
|
| 1552 |
if ( $has_images ) { |
| 1553 |
foreach ( $images as $attach_id ) { |
| 1554 |
echo esc_attr( Upload_Ajax::attach_html( $attach_id, $attr['name'] ) ); |
| 1555 |
} |
| 1556 |
} ?> |
| 1557 |
</ul> |
| 1558 |
</div> |
| 1559 |
</div><!-- .container --> |
| 1560 |
|
| 1561 |
<?php $this->help_text( $attr ); ?> |
| 1562 |
|
| 1563 |
</div> <!-- .wpuf-fields --> |
| 1564 |
|
| 1565 |
<script type="text/javascript"> |
| 1566 |
;(function($) { |
| 1567 |
$(document).ready( function(){ |
| 1568 |
var uploader = new WPUF_Uploader('wpuf-<?php echo esc_attr( $unique_id ); ?>-pickfiles', 'wpuf-<?php echo esc_attr( $unique_id ); ?>-upload-container', <?php echo esc_attr( $attr['count'] ); ?>, '<?php echo esc_attr( $attr['name'] ); ?>', 'jpg,jpeg,jfif,gif,png,bmp', <?php echo esc_attr( $attr['max_size'] ); ?>); |
| 1569 |
wpuf_plupload_items.push(uploader); |
| 1570 |
}); |
| 1571 |
})(jQuery); |
| 1572 |
</script> |
| 1573 |
<?php |
| 1574 |
} |
| 1575 |
|
| 1576 |
/** |
| 1577 |
* Prints a section break |
| 1578 |
* |
| 1579 |
* @param array $attr |
| 1580 |
* @param int|null $post_id |
| 1581 |
*/ |
| 1582 |
public function section_break( $attr, $post_id, $form_id ) { |
| 1583 |
?> |
| 1584 |
<div class="wpuf-section-wrap <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $attr['id'] ) . '_' . esc_attr( $form_id ); ?>"> |
| 1585 |
<h2 class="wpuf-section-title"><?php echo esc_attr( $attr['label'] ); ?></h2> |
| 1586 |
<div class="wpuf-section-details"><?php echo esc_attr( $attr['description'] ); ?></div> |
| 1587 |
</div> |
| 1588 |
<?php |
| 1589 |
} |
| 1590 |
|
| 1591 |
/** |
| 1592 |
* Prints recaptcha field |
| 1593 |
* |
| 1594 |
* @param array $attr |
| 1595 |
*/ |
| 1596 |
public static function recaptcha( $attr, $post_id, $form_id ) { |
| 1597 |
if ( $post_id ) { |
| 1598 |
return; |
| 1599 |
} |
| 1600 |
$enable_no_captcha = $enable_invisible_recaptcha = ''; |
| 1601 |
|
| 1602 |
if ( isset( $attr['recaptcha_type'] ) ) { |
| 1603 |
$enable_invisible_recaptcha = $attr['recaptcha_type'] == 'invisible_recaptcha' ? true : false; |
| 1604 |
$enable_no_captcha = $attr['recaptcha_type'] == 'enable_no_captcha' ? true : false; |
| 1605 |
} |
| 1606 |
|
| 1607 |
if ( $enable_invisible_recaptcha ) { |
| 1608 |
wp_enqueue_script( 'wpuf-recaptcha-invisible', 'https://www.google.com/recaptcha/api.js?onload=wpufreCaptchaLoaded&render=explicit&hl=en', array(), null, true ); |
| 1609 |
|
| 1610 |
$inline_script = sprintf( |
| 1611 |
"jQuery(document).ready(function($) { |
| 1612 |
jQuery('[name=\"submit\"]').removeClass('wpuf-submit-button').addClass('g-recaptcha').attr('data-sitekey', '%s'); |
| 1613 |
|
| 1614 |
$(document).on('click','.g-recaptcha', function(e){ |
| 1615 |
e.preventDefault(); |
| 1616 |
e.stopPropagation(); |
| 1617 |
if (typeof grecaptcha !== 'undefined') { |
| 1618 |
grecaptcha.execute(); |
| 1619 |
} |
| 1620 |
}) |
| 1621 |
}); |
| 1622 |
|
| 1623 |
var wpufreCaptchaLoaded = function() { |
| 1624 |
if (typeof grecaptcha !== 'undefined') { |
| 1625 |
grecaptcha.render('recaptcha', { |
| 1626 |
'size' : 'invisible', |
| 1627 |
'callback' : wpufRecaptchaCallback |
| 1628 |
}); |
| 1629 |
grecaptcha.execute(); |
| 1630 |
} |
| 1631 |
}; |
| 1632 |
|
| 1633 |
function wpufRecaptchaCallback(token) { |
| 1634 |
jQuery('[name=\"g-recaptcha-response\"]').val(token); |
| 1635 |
jQuery('[name=\"submit\"]').removeClass('g-recaptcha').addClass('wpuf-submit-button'); |
| 1636 |
}", |
| 1637 |
esc_js( wpuf_get_option( 'recaptcha_public', 'wpuf_general' ) ) |
| 1638 |
); |
| 1639 |
|
| 1640 |
wp_add_inline_script( 'wpuf-recaptcha-invisible', $inline_script, 'after' ); |
| 1641 |
?> |
| 1642 |
|
| 1643 |
<div type="submit" id='recaptcha' class="g-recaptcha" data-sitekey=<?php echo esc_attr( wpuf_get_option( 'recaptcha_public', 'wpuf_general' ) ); ?> data-callback="onSubmit" data-size="invisible"></div> |
| 1644 |
<?php } else { ?> |
| 1645 |
<div class="wpuf-fields <?php echo ' wpuf_' . esc_attr( $attr['name'] ) . '_' . esc_attr( $form_id ); ?>"> |
| 1646 |
<?php echo esc_html( recaptcha_get_html( wpuf_get_option( 'recaptcha_public', 'wpuf_general' ), $enable_no_captcha, null, is_ssl() ) ); ?> |
| 1647 |
</div> |
| 1648 |
<?php } |
| 1649 |
} |
| 1650 |
} |
| 1651 |
|