PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/smartbox-theme-1.01/inc/core/options/validation/date.php

https://github.com/bfay/maniacal-kitten
PHP | 47 lines | 18 code | 1 blank | 28 comment | 4 complexity | 2de8be28e03a47e4ff435b77ee9369fa MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Checks for valid date
  4. *
  5. * @package Smartbox
  6. * @subpackage Core
  7. * @since 1.0
  8. *
  9. * @copyright (c) 2013 Oxygenna.com
  10. * @license http://wiki.envato.com/support/legal-terms/licensing-terms/
  11. * @version 1.01
  12. */
  13. /**
  14. * Validates a date
  15. *
  16. * @package Smartbox
  17. * @since 1.0
  18. **/
  19. class OxyDate {
  20. /**
  21. * Validates the option data
  22. *
  23. * @return validated options array
  24. * @since 1.0
  25. **/
  26. function validate( $field, $options, $new_options ) {
  27. $valid_date = false;
  28. // get new date value
  29. $date = $new_options[$field['id']];
  30. // split up the date into m / d / y
  31. $parts = explode( '/', $date );
  32. // do we have m d y ?
  33. if( count( $parts ) == 3 ) {
  34. // check if m d y is valid date
  35. $valid_date = checkdate( $parts[0], $parts[1], $parts[2] );
  36. }
  37. // if we have a valid date return new value otherwise report error
  38. if( $valid_date ) {
  39. $options[$field['id']] = $date;
  40. }
  41. else {
  42. add_settings_error( $field['name'], $field['id'], $field['name'] . ' - ' . __('Invalid date supplied', THEME_ADMIN_TD), 'error' );
  43. }
  44. return $options;
  45. }
  46. }