2015-04-28 27 views
1

所以我有一個內置的日曆WordPress插件。WordPress的插件功能,只有一個工程?

開發人員已經給出了關於如何刪除選項以選擇過去的日期以及您選擇的具體日期的說明。

http://support.themecatcher.net/quform-wordpress/guides/advanced/date-validation

我也跟着指示,但也許我失去了一些東西。由於只有一個功能在同一時間工作,但從未同時工作。

這是代碼。任何幫助將不勝感激。謝謝!


function my_prevent_past_dates($valid, $value, $element) 
{ 
$time = strtotime("{$value['year']}-{$value['month']}-{$value['day']}"); 

if ($time < strtotime('today')) { 
     $element->addError('Please choose a date in the future'); 
    $valid = false; 
} 

return $valid; 
} 

add_filter('iphorm_element_valid_iphorm_1_6', 'my_prevent_past_dates', 10, 3); 

function my_datepicker_prevent_past_dates($options, $dpMinYear, $dpMaxYear, $element) 
{ 
    return "{ 
    minDate: 0, 
    maxDate: new Date({$dpMaxYear}, 12 - 1, 31) 
    }"; 
} 

add_filter('iphorm_datepicker_options_iphorm_1_6', 'my_datepicker_prevent_past_dates', 10, 4); 



function my_get_dates_to_disable() 
{ 
    return array(
     '2015-05-1', 
     '2015-05-2', 
     '2015-05-3', 
     '2015-05-4', 
     '2015-05-5', 
     '2015-05-6', 
); 
} 

function my_prevent_specific_dates($valid, $value, $element) 
{ 
    if ($valid) { 
     $disabledDates = my_get_dates_to_disable(); 
     $submittedDate = "{$value['year']}-{$value['month']}-{$value['day']}"; 

    if (in_array($submittedDate, $disabledDates)) { 
      $element->addError('That date is not available'); 
      $valid = false; 
     } 
    } 

    return $valid; 
} 

add_filter('iphorm_element_valid_iphorm_1_6', 'my_prevent_specific_dates', 10, 3); 

function my_datepicker_prevent_specific_dates($options, $dpMinYear, $dpMaxYear, $element) 
{ 
    return "{ 
     beforeShowDay: function (date) { 
      if (quformDisabledDates) { 
       for (var i = 0; i < quformDisabledDates.length; i++) { 
        var parts = quformDisabledDates[i].split('-'); 
       if (date.getFullYear() == parts[0] && (date.getMonth()+1) == parts[1] && date.getDate() == parts[2]) { 
         return [false]; 
        } 
       } 
      } 
      return [true]; 
     } 
    }"; 
} 

add_filter('iphorm_datepicker_options_iphorm_1_6', 'my_datepicker_prevent_specific_dates', 10, 4); 

function my_print_dates_to_disable() 
{ 
    ?> 
    <script type="text/javascript"> 
    var quformDisabledDates = <?php echo json_encode(my_get_dates_to_disable()); ?>; 
    </script> 
    <?php 
} 
add_action('wp_head', 'my_print_dates_to_disable'); 

回答

0

您可以結合使用my_prevent_specific_dates my_prevent_past_dates,並my_datepicker_prevent_past_dates與my_datepicker_prevent_specific_dates。

function my_get_dates_to_disable() 
{ 
    return array(
     '2015-05-1', 
     '2015-05-2', 
     '2015-05-3', 
     '2015-05-4', 
     '2015-05-5', 
    '2015-05-6', 
); 
} 


function my_prevent_bad_dates($valid, $value, $element) 
{ 
$time = strtotime("{$value['year']}-{$value['month']}-{$value['day']}"); 

if ($time < strtotime('today')) { 
    $element->addError('Please choose a date in the future'); 
    $valid = false; 
} else { 
    $disabledDates = my_get_dates_to_disable(); 
    $submittedDate = "{$value['year']}-{$value['month']}-{$value['day']}"; 

    if (in_array($submittedDate, $disabledDates)) { 
      $element->addError('That date is not available'); 
      $valid = false; 
    }  
} 

return $valid; 
} 

add_filter('iphorm_element_valid_iphorm_1_6', 'my_prevent_bad_dates', 10, 3); 


function my_datepicker_prevent_bad_dates($options, $dpMinYear, $dpMaxYear, $element) 
{ 
    return "{ 
    minDate: 0, 
    maxDate: new Date({$dpMaxYear}, 12 - 1, 31), 
    beforeShowDay: function (date) { 
     if (quformDisabledDates) { 
     for (var i = 0; i < quformDisabledDates.length; i++) { 
      var parts = quformDisabledDates[i].split('-'); 
      if (date.getFullYear() == parts[0] && (date.getMonth()+1) == parts[1] && date.getDate() == parts[2]) { 
      return [false]; 
      } 
     } 
     } 
     return [true]; 
     }  
    }"; 
} 

add_filter('iphorm_datepicker_options_iphorm_1_6', 'my_datepicker_prevent_bad_dates', 10, 4); 

function my_print_dates_to_disable() 
{ 
    ?> 
    <script type="text/javascript"> 
    var quformDisabledDates = <?php echo json_encode(my_get_dates_to_disable()); ?>; 
    </script> 
    <?php 
} 
add_action('wp_head', 'my_print_dates_to_disable');