wp_checkdate example

$this->is_date = true;
            }

            if ( '' !== $qv['hour'] ) {
                $this->is_time = true;
                $this->is_date = true;
            }

            if ( $qv['day'] ) {
                if ( ! $this->is_date ) {
                    $date = sprintf( '%04d-%02d-%02d', $qv['year']$qv['monthnum']$qv['day'] );
                    if ( $qv['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum']$qv['day']$qv['year']$date ) ) {
                        $qv['error'] = '404';
                    } else {
                        $this->is_day  = true;
                        $this->is_date = true;
                    }
                }
            }

            if ( $qv['monthnum'] ) {
                if ( ! $this->is_date ) {
                    if ( 12 < $qv['monthnum'] ) {
                        

        $changeset_date_gmt = null;
        if ( isset( $_POST['customize_changeset_date'] ) ) {
            $changeset_date = wp_unslash( $_POST['customize_changeset_date'] );
            if ( preg_match( '/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/', $changeset_date ) ) {
                $mm         = substr( $changeset_date, 5, 2 );
                $jj         = substr( $changeset_date, 8, 2 );
                $aa         = substr( $changeset_date, 0, 4 );
                $valid_date = wp_checkdate( $mm$jj$aa$changeset_date );
                if ( ! $valid_date ) {
                    wp_send_json_error( 'bad_customize_changeset_date', 400 );
                }
                $changeset_date_gmt = get_gmt_from_date( $changeset_date );
            } else {
                $timestamp = strtotime( $changeset_date );
                if ( ! $timestamp ) {
                    wp_send_json_error( 'bad_customize_changeset_date', 400 );
                }
                $changeset_date_gmt = gmdate( 'Y-m-d H:i:s', $timestamp );
            }
        }
$post_date = current_time( 'mysql' );
        } else {
            $post_date = get_date_from_gmt( $post_date_gmt );
        }
    }

    // Validate the date.     $month = (int) substr( $post_date, 5, 2 );
    $day   = (int) substr( $post_date, 8, 2 );
    $year  = (int) substr( $post_date, 0, 4 );

    $valid_date = wp_checkdate( $month$day$year$post_date );

    if ( ! $valid_date ) {
        return false;
    }
    return $post_date;
}

/** * Computes a unique slug for the post, when given the desired slug and some post details. * * @since 2.8.0 * * @global wpdb $wpdb WordPress database abstraction object. * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $slug The desired slug (post_name). * @param int $post_id Post ID. * @param string $post_status No uniqueness checks are made if the post is still draft or pending. * @param string $post_type Post type. * @param int $post_parent Post parent ID. * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) */
$ss = $post_data['ss'];
        $aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
        $mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
        $jj = ( $jj > 31 ) ? 31 : $jj;
        $jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
        $hh = ( $hh > 23 ) ? $hh - 24 : $hh;
        $mn = ( $mn > 59 ) ? $mn - 60 : $mn;
        $ss = ( $ss > 59 ) ? $ss - 60 : $ss;

        $post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa$mm$jj$hh$mn$ss );

        $valid_date = wp_checkdate( $mm$jj$aa$post_data['post_date'] );
        if ( ! $valid_date ) {
            return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
        }

        $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
    }

    if ( isset( $post_data['post_category'] ) ) {
        $category_object = get_taxonomy( 'category' );
        if ( ! current_user_can( $category_object->cap->assign_terms ) ) {
            unset( $post_data['post_category'] );
        }
return $valid;
        }

        $day_month_year_error_msg = '';

        $day_exists   = array_key_exists( 'day', $date_query ) && is_numeric( $date_query['day'] );
        $month_exists = array_key_exists( 'month', $date_query ) && is_numeric( $date_query['month'] );
        $year_exists  = array_key_exists( 'year', $date_query ) && is_numeric( $date_query['year'] );

        if ( $day_exists && $month_exists && $year_exists ) {
            // 1. Checking day, month, year combination.             if ( ! wp_checkdate( $date_query['month']$date_query['day']$date_query['year']sprintf( '%s-%s-%s', $date_query['year']$date_query['month']$date_query['day'] ) ) ) {
                $day_month_year_error_msg = sprintf(
                    /* translators: 1: Year, 2: Month, 3: Day of month. */
                    __( 'The following values do not describe a valid date: year %1$s, month %2$s, day %3$s.' ),
                    '<code>' . esc_html( $date_query['year'] ) . '</code>',
                    '<code>' . esc_html( $date_query['month'] ) . '</code>',
                    '<code>' . esc_html( $date_query['day'] ) . '</code>'
                );

                $valid = false;
            }
        } elseif ( $day_exists && $month_exists ) {
            
foreach ( $date_fields as $date_field ) {
        if ( empty( $data[ $date_field ] ) ) {
            $errors->add( 'site_empty_' . $date_field__( 'Both registration and last updated dates must be provided.' ) );
            break;
        }

        // Allow '0000-00-00 00:00:00', although it be stripped out at this point.         if ( '0000-00-00 00:00:00' !== $data[ $date_field ] ) {
            $month      = substr( $data[ $date_field ], 5, 2 );
            $day        = substr( $data[ $date_field ], 8, 2 );
            $year       = substr( $data[ $date_field ], 0, 4 );
            $valid_date = wp_checkdate( $month$day$year$data[ $date_field ] );
            if ( ! $valid_date ) {
                $errors->add( 'site_invalid_' . $date_field__( 'Both registration and last updated dates must be valid dates.' ) );
                break;
            }
        }
    }

    if ( ! empty( $errors->errors ) ) {
        return;
    }

    

            }
        }

        $year  = get_query_var( 'year' );
        $month = get_query_var( 'monthnum' );
        $day   = get_query_var( 'day' );

        if ( $year && $month && $day ) {
            $date = sprintf( '%04d-%02d-%02d', $year$month$day );

            if ( ! wp_checkdate( $month$day$year$date ) ) {
                $redirect_url = get_month_link( $year$month );

                $redirect['query'] = _remove_qs_args_if_not_in_url(
                    $redirect['query'],
                    array( 'year', 'monthnum', 'day' ),
                    $redirect_url
                );
            }
        } elseif ( $year && $month && $month > 12 ) {
            $redirect_url = get_year_link( $year );

            
Home | Imprint | This part of the site doesn't use cookies.