Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active September 11, 2021 12:11
Show Gist options
  • Save wpmudev-sls/c98857e560c2c2dc3b8df808cc55a54e to your computer and use it in GitHub Desktop.
Save wpmudev-sls/c98857e560c2c2dc3b8df808cc55a54e to your computer and use it in GitHub Desktop.
[Forminator] - Limit the birthday date
<?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();
}
}
}
@d12ilham
Copy link

Hi is it possible to give some instructions on how to make this work? Does this works only with Forminator pro ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment