get_gmt_from_date example

$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 );
            }
        }

        $lock_user_id = null;
        $autosave     = ! empty( $_POST['customize_changeset_autosave'] );
        
if ( empty( $date ) ) {
        return null;
    }

    /* * At this point $date could either be a local date (if we were passed * a *local* date without a timezone offset) or a UTC date (otherwise). * Timezone conversion needs to be handled differently between these two cases. */
    if ( ! $is_utc && ! $has_timezone ) {
        $local = gmdate( 'Y-m-d H:i:s', $date );
        $utc   = get_gmt_from_date( $local );
    } else {
        $utc   = gmdate( 'Y-m-d H:i:s', $date );
        $local = get_date_from_gmt( $utc );
    }

    return array( $local$utc );
}

/** * Returns a contextual HTTP error code for authorization failure. * * @since 4.7.0 * * @return int 401 if the user is not logged in, 403 if the user is logged in. */
$data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date );
        }

        if ( rest_is_field_included( 'date_gmt', $fields ) ) {
            /* * For drafts, `post_date_gmt` may not be set, indicating that the date * of the draft should be updated each time it is saved (see #38883). * In this case, shim the value based on the `post_date` field * with the site's timezone offset applied. */
            if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
                $post_date_gmt = get_gmt_from_date( $post->post_date );
            } else {
                $post_date_gmt = $post->post_date_gmt;
            }
            $data['date_gmt'] = $this->prepare_date_response( $post_date_gmt );
        }

        if ( rest_is_field_included( 'guid', $fields ) ) {
            $data['guid'] = array(
                /** This filter is documented in wp-includes/post-template.php */
                'rendered' => apply_filters( 'get_the_guid', $post->guid, $post->ID ),
                'raw'      => $post->guid,
            );


    /** * Converts a WordPress GMT date string to an IXR_Date object. * * @param string $date_gmt WordPress GMT date string. * @param string $date Date string. * @return IXR_Date IXR_Date object. */
    protected function _convert_date_gmt( $date_gmt$date ) {
        if ( '0000-00-00 00:00:00' !== $date && '0000-00-00 00:00:00' === $date_gmt ) {
            return new IXR_Date( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $date, false ), 'Ymd\TH:i:s' ) );
        }
        return $this->_convert_date( $date_gmt );
    }

    /** * Prepares post data for return in an XML-RPC object. * * @param array $post The unprepared post data. * @param array $fields The subset of post type fields to return. * @return array The prepared post data. */
    
if ( ! $post_date ) {
        if ( $wp_error ) {
            return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
        } else {
            return 0;
        }
    }

    if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) {
        if ( ! in_array( $post_statusget_post_stati( array( 'date_floating' => true ) ), true ) ) {
            $post_date_gmt = get_gmt_from_date( $post_date );
        } else {
            $post_date_gmt = '0000-00-00 00:00:00';
        }
    } else {
        $post_date_gmt = $postarr['post_date_gmt'];
    }

    if ( $update || '0000-00-00 00:00:00' === $post_date ) {
        $post_modified     = current_time( 'mysql' );
        $post_modified_gmt = current_time( 'mysql', 1 );
    } else {
        
$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 $post_data;
}

function wp_insert_comment( $commentdata ) {
    global $wpdb;

    $data = wp_unslash( $commentdata );

    $comment_author       = ! isset( $data['comment_author'] ) ? '' : $data['comment_author'];
    $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email'];
    $comment_author_url   = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url'];
    $comment_author_ip    = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP'];

    $comment_date     = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date'];
    $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt'];

    $comment_post_id  = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID'];
    $comment_content  = ! isset( $data['comment_content'] ) ? '' : $data['comment_content'];
    $comment_karma    = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
    $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
    $comment_agent    = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
    $comment_type     = empty( $data['comment_type'] ) ? 'comment' : $data['comment_type'];
    $comment_parent   = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];

    $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];

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