Last active
September 11, 2021 12:11
-
-
Save wpmudev-sls/c98857e560c2c2dc3b8df808cc55a54e to your computer and use it in GitHub Desktop.
[Forminator] - Limit the birthday date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator] - Limit the date of birth | |
* Description: [Forminator] - Limit the date of birth | |
* Task: 0/11289012348292/1172860968808076 | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; } | |
add_action( 'after_setup_theme', 'wpmudev_forminator_limit_birthday_date_func', 101 ); | |
function wpmudev_forminator_limit_birthday_date_func() { | |
if ( defined('FORMINATOR_PRO') && class_exists( 'Forminator' ) ) { | |
add_action( 'wp_footer', 'wpmudev_forminator_limit_birthday_date', 21 ); | |
function wpmudev_forminator_limit_birthday_date(){ | |
ob_start(); | |
?> | |
<script> | |
(function($){ | |
$(function(){ | |
if (typeof ($.fn.forminatorLoader) === 'undefined') { | |
// nothing to do here | |
} else { | |
$(document).on('after.load.forminator', function(e, form_id){ | |
let _form = $('#forminator-module-'+ form_id), | |
_disableMessage = 'This age is restrict!'; | |
if( _form.length && _form.hasClass('forminator-custom-form') ){ | |
let _birthday = _form.find('.birthday-date-picker .forminator-datepicker'); | |
if( _birthday.length ){ | |
_birthday.datepicker( "option", "maxDate", "-216m" ); | |
var _old = _birthday.datepicker("option", "beforeShowDay"); | |
var _max_time = new Date(); | |
_max_time.setFullYear( _max_time.getFullYear() - 18 ); | |
_birthday.datepicker( "option", "beforeShowDay", function( current_date ){ | |
if( current_date > _max_time ){ | |
return [false, "enabledDate", _disableMessage]; | |
}else{ | |
return [true, "enabledDate"]; | |
} | |
}); | |
} | |
} | |
}); | |
} | |
}); | |
})(window.jQuery) | |
</script> | |
<?php | |
echo ob_get_clean(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi is it possible to give some instructions on how to make this work? Does this works only with Forminator pro ?