validate.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Email validate
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! function_exists( 'csf_validate_email' ) ) {
  11. function csf_validate_email( $value ) {
  12. if ( ! filter_var( $value, FILTER_VALIDATE_EMAIL ) ) {
  13. return esc_html__( 'Please enter a valid email address.', 'sakurairo_csf' );
  14. }
  15. }
  16. }
  17. /**
  18. *
  19. * Numeric validate
  20. *
  21. * @since 1.0.0
  22. * @version 1.0.0
  23. *
  24. */
  25. if ( ! function_exists( 'csf_validate_numeric' ) ) {
  26. function csf_validate_numeric( $value ) {
  27. if ( ! is_numeric( $value ) ) {
  28. return esc_html__( 'Please enter a valid number.', 'sakurairo_csf' );
  29. }
  30. }
  31. }
  32. /**
  33. *
  34. * Required validate
  35. *
  36. * @since 1.0.0
  37. * @version 1.0.0
  38. *
  39. */
  40. if ( ! function_exists( 'csf_validate_required' ) ) {
  41. function csf_validate_required( $value ) {
  42. if ( empty( $value ) ) {
  43. return esc_html__( 'This field is required.', 'sakurairo_csf' );
  44. }
  45. }
  46. }
  47. /**
  48. *
  49. * URL validate
  50. *
  51. * @since 1.0.0
  52. * @version 1.0.0
  53. *
  54. */
  55. if ( ! function_exists( 'csf_validate_url' ) ) {
  56. function csf_validate_url( $value ) {
  57. if ( ! filter_var( $value, FILTER_VALIDATE_URL ) ) {
  58. return esc_html__( 'Please enter a valid URL.', 'sakurairo_csf' );
  59. }
  60. }
  61. }
  62. /**
  63. *
  64. * Email validate for Customizer
  65. *
  66. * @since 1.0.0
  67. * @version 1.0.0
  68. *
  69. */
  70. if ( ! function_exists( 'csf_customize_validate_email' ) ) {
  71. function csf_customize_validate_email( $validity, $value, $wp_customize ) {
  72. if ( ! sanitize_email( $value ) ) {
  73. $validity->add( 'required', esc_html__( 'Please enter a valid email address.', 'sakurairo_csf' ) );
  74. }
  75. return $validity;
  76. }
  77. }
  78. /**
  79. *
  80. * Numeric validate for Customizer
  81. *
  82. * @since 1.0.0
  83. * @version 1.0.0
  84. *
  85. */
  86. if ( ! function_exists( 'csf_customize_validate_numeric' ) ) {
  87. function csf_customize_validate_numeric( $validity, $value, $wp_customize ) {
  88. if ( ! is_numeric( $value ) ) {
  89. $validity->add( 'required', esc_html__( 'Please enter a valid number.', 'sakurairo_csf' ) );
  90. }
  91. return $validity;
  92. }
  93. }
  94. /**
  95. *
  96. * Required validate for Customizer
  97. *
  98. * @since 1.0.0
  99. * @version 1.0.0
  100. *
  101. */
  102. if ( ! function_exists( 'csf_customize_validate_required' ) ) {
  103. function csf_customize_validate_required( $validity, $value, $wp_customize ) {
  104. if ( empty( $value ) ) {
  105. $validity->add( 'required', esc_html__( 'This field is required.', 'sakurairo_csf' ) );
  106. }
  107. return $validity;
  108. }
  109. }
  110. /**
  111. *
  112. * URL validate for Customizer
  113. *
  114. * @since 1.0.0
  115. * @version 1.0.0
  116. *
  117. */
  118. if ( ! function_exists( 'csf_customize_validate_url' ) ) {
  119. function csf_customize_validate_url( $validity, $value, $wp_customize ) {
  120. if ( ! filter_var( $value, FILTER_VALIDATE_URL ) ) {
  121. $validity->add( 'required', esc_html__( 'Please enter a valid URL.', 'sakurairo_csf' ) );
  122. }
  123. return $validity;
  124. }
  125. }