Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. function my_acf_validate_save_post() {
  2.  
  3. if ( empty( $_POST ) ) {
  4. return;
  5. }
  6.  
  7. if ( empty( $_POST['post_ID'] ) ) {
  8. return;
  9. }
  10.  
  11. if ( empty( $_POST['acf']['field_5dc15b87cac79'] ) || empty( $_POST['acf']['field_5dc15ca6a59c3'] ) ) {
  12. return;
  13. }
  14.  
  15. $fxl_new_start_date = sanitize_text_field( wp_unslash( $_POST['acf']['field_5dc15b87cac79'] ) );
  16.  
  17. $fxl_new_end_date = sanitize_text_field( wp_unslash( $_POST['acf']['field_5dc15ca6a59c3'] ) );
  18.  
  19. // Check if user is an administrator.
  20. if ( current_user_can( 'manage_options' ) ) {
  21. // Clear all errors.
  22. acf_reset_validation_errors();
  23. }
  24. $fxl_pricing_page = get_page_by_title( 'Plans & Pricing' );
  25.  
  26. if ( $fxl_pricing_page ) {
  27.  
  28. if ( (int) $_POST['post_ID'] === $fxl_pricing_page->ID ) {// I have to use $_POST['post_ID'] here, instead of get_the_id(), because when the hook fires, $post is not defined, so get_the_id() returns false, instead of the post ID.
  29.  
  30. if ( $fxl_new_start_date > $fxl_new_end_date ) {
  31. acf_add_validation_error( 'acf[field_5dc15ca6a59c3]', 'Sale end date must occur after sale start date.' );
  32. }
  33. }
  34. }
  35. }
  36. add_action( 'acf/validate_save_post', 'my_acf_validate_save_post', 10, 0 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement