Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function my_acf_validate_save_post() {
- if ( empty( $_POST ) ) {
- return;
- }
- if ( empty( $_POST['post_ID'] ) ) {
- return;
- }
- if ( empty( $_POST['acf']['field_5dc15b87cac79'] ) || empty( $_POST['acf']['field_5dc15ca6a59c3'] ) ) {
- return;
- }
- $fxl_new_start_date = sanitize_text_field( wp_unslash( $_POST['acf']['field_5dc15b87cac79'] ) );
- $fxl_new_end_date = sanitize_text_field( wp_unslash( $_POST['acf']['field_5dc15ca6a59c3'] ) );
- // Check if user is an administrator.
- if ( current_user_can( 'manage_options' ) ) {
- // Clear all errors.
- acf_reset_validation_errors();
- }
- $fxl_pricing_page = get_page_by_title( 'Plans & Pricing' );
- if ( $fxl_pricing_page ) {
- 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.
- if ( $fxl_new_start_date > $fxl_new_end_date ) {
- acf_add_validation_error( 'acf[field_5dc15ca6a59c3]', 'Sale end date must occur after sale start date.' );
- }
- }
- }
- }
- add_action( 'acf/validate_save_post', 'my_acf_validate_save_post', 10, 0 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement