• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_checkdate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_checkdate函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_checkdate函数的具体用法?PHP wp_checkdate怎么用?PHP wp_checkdate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_checkdate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: validateDate

 /**
  * Validate Date Input
  */
 public function validateDate($data)
 {
     // First validate that it is an actual date
     if (!wp_checkdate(intval($data['mm']), intval($data['jj']), intval($data['aa']), $data['aa'] . '-' . $data['mm'] . '-' . $data['jj'])) {
         return wp_send_json(array('status' => 'error', 'message' => __('Please provide a valid date.', 'nestedpages')));
         die;
     }
     // Validate all the fields are there
     if ($data['aa'] !== "" && $data['mm'] !== "" && $data['jj'] !== "" && $data['hh'] !== "" && $data['mm'] !== "" && $data['ss'] !== "") {
         $date = strtotime($data['aa'] . '-' . $data['mm'] . '-' . $data['jj'] . ' ' . $data['hh'] . ':' . $data['mm'] . ':' . $data['ss']);
         return date('Y-m-d H:i:s', $date);
     } else {
         return wp_send_json(array('status' => 'error', 'message' => __('Please provide a valid date.', 'nestedpages')));
         die;
     }
 }
开发者ID:erkmen,项目名称:wpstartersetup,代码行数:19,代码来源:class-np-validation.php


示例2: checkValidDate

 /**
  * Check valid date
  */
 private function checkValidDate($month, $day, $year)
 {
     if (!wp_checkdate(intval($month), intval($day), intval($year), $year . '-' . $month . '-' . $day)) {
         return $this->sendDateError();
     }
 }
开发者ID:dtwist,项目名称:wp-nested-pages,代码行数:9,代码来源:Validation.php


示例3: get_new_expiration_date

 function get_new_expiration_date($post_data = false)
 {
     $new_expiration_date = false;
     if ($post_data === false) {
         $post_data =& $_POST;
     }
     // see if the expiration date has been changed, and thus must be updated
     foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) {
         if (!empty($post_data['cbp-expiration-hidden_' . $timeunit]) && $post_data['cbp-expiration-hidden_' . $timeunit] != $post_data['cbp-expiration-' . $timeunit]) {
             $post_data['edit_expiration_date'] = '1';
             break;
         }
     }
     // if the expiration date has changed, validate it now
     if (!empty($post_data['edit_expiration_date'])) {
         // collect data
         $aa = $post_data['cbp-expiration-aa'];
         $mm = $post_data['cbp-expiration-mm'];
         $jj = $post_data['cbp-expiration-jj'];
         $hh = $post_data['cbp-expiration-hh'];
         $mn = $post_data['cbp-expiration-mn'];
         $ss = $post_data['cbp-expiration-ss'];
         // validate / normalize collected data
         $aa = $aa <= 0 ? date('Y') : $aa;
         $mm = $mm <= 0 ? date('n') : $mm;
         $jj = $jj > 31 ? 31 : $jj;
         $jj = $jj <= 0 ? date('j') : $jj;
         $hh = $hh > 23 ? $hh - 24 : $hh;
         $mn = $mn > 59 ? $mn - 60 : $mn;
         $ss = $ss > 59 ? $ss - 60 : $ss;
         $new_expiration_date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss);
         $valid_date = wp_checkdate($mm, $jj, $aa, $new_expiration_date);
         if (!$valid_date) {
             return new WP_Error('invalid_date', __('Whoops, the provided expiration date is invalid.'));
         }
         $post_data['expiration_date_gmt'] = get_gmt_from_date($new_expiration_date);
     }
     // $new_expiration_date is now either false or a valid date
     return $new_expiration_date;
 }
开发者ID:gasbriones,项目名称:bacare,代码行数:40,代码来源:cbp_expiration_date.class.php


示例4: dequeue_movie

 /**
  * Remove a movie from the queue list.
  * 
  * Simply change the movie's post_status to 'import-draft',
  * update the dates and delete the movie metadata.
  *
  * @since    1.0
  * 
  * @param    string     $post_id Movie Post ID.
  * 
  * @return   int|WP_Error    Post ID if everything worked, WP_Error instance if update of meta delete failed
  */
 public static function dequeue_movie($post_id)
 {
     $post_date = current_time('mysql');
     $post_date = wp_checkdate(substr($post_date, 5, 2), substr($post_date, 8, 2), substr($post_date, 0, 4), $post_date);
     $post_date_gmt = get_gmt_from_date($post_date);
     $_post = array('ID' => $post_id, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_status' => 'import-draft');
     $update = wp_update_post($_post, $wp_error = true);
     if (is_wp_error($update)) {
         return new WP_Error('error', sprintf(__('An error occured when trying to remove "%s" from the queue: %s', 'wpmovielibrary'), get_the_title($post_id), $update->get_error_message()));
     }
     $update = delete_post_meta($post_id, '_wpmoly_movie_data');
     if (false === $update) {
         return new WP_Error('error', sprintf(__('An error occured when trying to delete "%s" metadata.', 'wpmovielibrary'), get_the_title($post_id)));
     }
     return $post_id;
 }
开发者ID:masterdoed,项目名称:wpmovielibrary,代码行数:28,代码来源:class-wpmoly-import-queue.php


示例5: wp_insert_post


//.........这里部分代码省略.........
    if (empty($post_author)) {
        $post_author = $user_id;
    }
    // Don't allow contributors to set the post slug for pending review posts
    if ('pending' == $post_status && !current_user_can('publish_posts')) {
        $post_name = '';
    }
    // Create a valid post name. Drafts and pending posts are allowed to have an empty
    // post name.
    if (empty($post_name)) {
        if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
            $post_name = sanitize_title($post_title);
        } else {
            $post_name = '';
        }
    } else {
        // On updates, we need to check to see if it's using the old, fixed sanitization context.
        $check_name = sanitize_title($post_name, '', 'old-save');
        if ($update && strtolower(urlencode($post_name)) == $check_name && get_post_field('post_name', $ID) == $check_name) {
            $post_name = $check_name;
        } else {
            // new post, or slug has changed.
            $post_name = sanitize_title($post_name);
        }
    }
    // If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now
    if (empty($post_date) || '0000-00-00 00:00:00' == $post_date) {
        $post_date = current_time('mysql');
    }
    // validate the date
    $mm = substr($post_date, 5, 2);
    $jj = substr($post_date, 8, 2);
    $aa = substr($post_date, 0, 4);
    $valid_date = wp_checkdate($mm, $jj, $aa, $post_date);
    if (!$valid_date) {
        if ($wp_error) {
            return new WP_Error('invalid_date', __('Whoops, the provided date is invalid.'));
        } else {
            return 0;
        }
    }
    if (empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt) {
        if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
            $post_date_gmt = get_gmt_from_date($post_date);
        } else {
            $post_date_gmt = '0000-00-00 00:00:00';
        }
    }
    if ($update || '0000-00-00 00:00:00' == $post_date) {
        $post_modified = current_time('mysql');
        $post_modified_gmt = current_time('mysql', 1);
    } else {
        $post_modified = $post_date;
        $post_modified_gmt = $post_date_gmt;
    }
    if ('publish' == $post_status) {
        $now = gmdate('Y-m-d H:i:59');
        if (mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false)) {
            $post_status = 'future';
        }
    } elseif ('future' == $post_status) {
        $now = gmdate('Y-m-d H:i:59');
        if (mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false)) {
            $post_status = 'publish';
        }
    }
开发者ID:palimadra,项目名称:bubblegraphics-wpsite,代码行数:67,代码来源:post.php


示例6: _wp_translate_postdata


//.........这里部分代码省略.........
	}

	if ( isset( $post_data['content'] ) )
		$post_data['post_content'] = $post_data['content'];

	if ( isset( $post_data['excerpt'] ) )
		$post_data['post_excerpt'] = $post_data['excerpt'];

	if ( isset( $post_data['parent_id'] ) )
		$post_data['post_parent'] = (int) $post_data['parent_id'];

	if ( isset($post_data['trackback_url']) )
		$post_data['to_ping'] = $post_data['trackback_url'];

	if ( !isset($post_data['user_ID']) )
		$post_data['user_ID'] = $GLOBALS['user_ID'];

	if (!empty ( $post_data['post_author_override'] ) ) {
		$post_data['post_author'] = (int) $post_data['post_author_override'];
	} else {
		if (!empty ( $post_data['post_author'] ) ) {
			$post_data['post_author'] = (int) $post_data['post_author'];
		} else {
			$post_data['post_author'] = (int) $post_data['user_ID'];
		}
	}

	if ( ! $update && isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] )
		 && ! current_user_can( $ptype->cap->edit_others_posts ) ) {

		if ( 'page' == $post_data['post_type'] )
			return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );
		else
			return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) );
	}

	// What to do based on which button they pressed
	if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] )
		$post_data['post_status'] = 'draft';
	if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] )
		$post_data['post_status'] = 'private';
	if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( !isset($post_data['post_status']) || $post_data['post_status'] != 'private' ) )
		$post_data['post_status'] = 'publish';
	if ( isset($post_data['advanced']) && '' != $post_data['advanced'] )
		$post_data['post_status'] = 'draft';
	if ( isset($post_data['pending']) && '' != $post_data['pending'] )
		$post_data['post_status'] = 'pending';

	if ( isset( $post_data['ID'] ) )
		$post_id = $post_data['ID'];
	else
		$post_id = false;
	$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;

	// Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
	// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
	if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->cap->publish_posts )) )
		if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) )
			$post_data['post_status'] = 'pending';

	if ( ! isset($post_data['post_status']) )
		$post_data['post_status'] = $previous_status;

	if (!isset( $post_data['comment_status'] ))
		$post_data['comment_status'] = 'closed';

	if (!isset( $post_data['ping_status'] ))
		$post_data['ping_status'] = 'closed';

	foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
		if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) {
			$post_data['edit_date'] = '1';
			break;
		}
	}

	if ( !empty( $post_data['edit_date'] ) ) {
		$aa = $post_data['aa'];
		$mm = $post_data['mm'];
		$jj = $post_data['jj'];
		$hh = $post_data['hh'];
		$mn = $post_data['mn'];
		$ss = $post_data['ss'];
		$aa = ($aa <= 0 ) ? date('Y') : $aa;
		$mm = ($mm <= 0 ) ? date('n') : $mm;
		$jj = ($jj > 31 ) ? 31 : $jj;
		$jj = ($jj <= 0 ) ? date('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', __( 'Whoops, the provided date is invalid.' ) );
		}
		$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
	}

	return $post_data;
}
开发者ID:pauEscarcia,项目名称:AIMM,代码行数:101,代码来源:POST.PHP


示例7: parse_query


//.........这里部分代码省略.........
         $this->is_single = true;
         $this->is_attachment = true;
     } elseif ('' != $qv['name']) {
         $this->is_single = true;
     } elseif ($qv['p']) {
         $this->is_single = true;
     } elseif ('' !== $qv['hour'] && '' !== $qv['minute'] && '' !== $qv['second'] && '' != $qv['year'] && '' != $qv['monthnum'] && '' != $qv['day']) {
         // If year, month, day, hour, minute, and second are set, a single
         // post is being queried.
         $this->is_single = true;
     } elseif ('' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id'])) {
         $this->is_page = true;
         $this->is_single = false;
     } else {
         // Look for archive queries. Dates, categories, authors, search, post type archives.
         if (isset($this->query['s'])) {
             $this->is_search = true;
         }
         if ('' !== $qv['second']) {
             $this->is_time = true;
             $this->is_date = true;
         }
         if ('' !== $qv['minute']) {
             $this->is_time = true;
             $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']) {
                     $qv['error'] = '404';
                 } else {
                     $this->is_month = true;
                     $this->is_date = true;
                 }
             }
         }
         if ($qv['year']) {
             if (!$this->is_date) {
                 $this->is_year = true;
                 $this->is_date = true;
             }
         }
         if ($qv['m']) {
             $this->is_date = true;
             if (strlen($qv['m']) > 9) {
                 $this->is_time = true;
             } elseif (strlen($qv['m']) > 7) {
                 $this->is_day = true;
             } elseif (strlen($qv['m']) > 5) {
                 $this->is_month = true;
             } else {
开发者ID:inpsyde,项目名称:wordpress-dev,代码行数:67,代码来源:class-wp-query.php


示例8: validate_date_values


//.........这里部分代码省略.........
      * validation routine continue to be sure that all invalid
      * values generate errors too.
      */
     if (array_key_exists('before', $date_query) && is_array($date_query['before'])) {
         $valid = $this->validate_date_values($date_query['before']);
     }
     if (array_key_exists('after', $date_query) && is_array($date_query['after'])) {
         $valid = $this->validate_date_values($date_query['after']);
     }
     // Array containing all min-max checks.
     $min_max_checks = array();
     // Days per year.
     if (array_key_exists('year', $date_query)) {
         /*
          * If a year exists in the date query, we can use it to get the days.
          * If multiple years are provided (as in a BETWEEN), use the first one.
          */
         if (is_array($date_query['year'])) {
             $_year = reset($date_query['year']);
         } else {
             $_year = $date_query['year'];
         }
         $max_days_of_year = date('z', mktime(0, 0, 0, 12, 31, $_year)) + 1;
     } else {
         // otherwise we use the max of 366 (leap-year)
         $max_days_of_year = 366;
     }
     $min_max_checks['dayofyear'] = array('min' => 1, 'max' => $max_days_of_year);
     // Days per week.
     $min_max_checks['dayofweek'] = array('min' => 1, 'max' => 7);
     // Days per week.
     $min_max_checks['dayofweek_iso'] = array('min' => 1, 'max' => 7);
     // Months per year.
     $min_max_checks['month'] = array('min' => 1, 'max' => 12);
     // Weeks per year.
     if (isset($_year)) {
         /*
          * If we have a specific year, use it to calculate number of weeks.
          * Note: the number of weeks in a year is the date in which Dec 28 appears.
          */
         $week_count = date('W', mktime(0, 0, 0, 12, 28, $_year));
     } else {
         // Otherwise set the week-count to a maximum of 53.
         $week_count = 53;
     }
     $min_max_checks['week'] = array('min' => 1, 'max' => $week_count);
     // Days per month.
     $min_max_checks['day'] = array('min' => 1, 'max' => 31);
     // Hours per day.
     $min_max_checks['hour'] = array('min' => 0, 'max' => 23);
     // Minutes per hour.
     $min_max_checks['minute'] = array('min' => 0, 'max' => 59);
     // Seconds per minute.
     $min_max_checks['second'] = array('min' => 0, 'max' => 59);
     // Concatenate and throw a notice for each invalid value.
     foreach ($min_max_checks as $key => $check) {
         if (!array_key_exists($key, $date_query)) {
             continue;
         }
         // Throw a notice for each failing value.
         foreach ((array) $date_query[$key] as $_value) {
             $is_between = $_value >= $check['min'] && $_value <= $check['max'];
             if (!is_numeric($_value) || !$is_between) {
                 $error = sprintf(__('Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.'), '<code>' . esc_html($_value) . '</code>', '<code>' . esc_html($key) . '</code>', '<code>' . esc_html($check['min']) . '</code>', '<code>' . esc_html($check['max']) . '</code>');
                 _doing_it_wrong(__CLASS__, $error, '4.1.0');
                 $valid = false;
             }
         }
     }
     // If we already have invalid date messages, don't bother running through checkdate().
     if (!$valid) {
         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']))) {
             /* translators: 1: year, 2: month, 3: day of month */
             $day_month_year_error_msg = sprintf(__('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) {
         /*
          * 2. checking day, month combination
          * We use 2012 because, as a leap year, it's the most permissive.
          */
         if (!wp_checkdate($date_query['month'], $date_query['day'], 2012, sprintf('2012-%s-%s', $date_query['month'], $date_query['day']))) {
             /* translators: 1: month, 2: day of month */
             $day_month_year_error_msg = sprintf(__('The following values do not describe a valid date: month %1$s, day %2$s.'), '<code>' . esc_html($date_query['month']) . '</code>', '<code>' . esc_html($date_query['day']) . '</code>');
             $valid = false;
         }
     }
     if (!empty($day_month_year_error_msg)) {
         _doing_it_wrong(__CLASS__, $day_month_year_error_msg, '4.1.0');
     }
     return $valid;
 }
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:101,代码来源:date.php


示例9: pmxi_insert_post

function pmxi_insert_post($postarr, $wp_error = false)
{
    global $wpdb;
    $user_id = get_current_user_id();
    $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_id, 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'post_content' => '', 'post_title' => '');
    $postarr = wp_parse_args($postarr, $defaults);
    $postarr = sanitize_post($postarr, 'db');
    // export array as variables
    extract($postarr, EXTR_SKIP);
    // Are we updating or creating?
    $post_ID = 0;
    $update = false;
    if (!empty($ID)) {
        $update = true;
        // Get the post ID and GUID
        $post_ID = $ID;
        $post_before = get_post($post_ID);
        if (is_null($post_before)) {
            if ($wp_error) {
                return new WP_Error('invalid_post', __('Invalid post ID.'));
            }
            return 0;
        }
        $guid = get_post_field('guid', $post_ID);
        $previous_status = get_post_field('post_status', $ID);
    } else {
        $previous_status = 'new';
    }
    if (empty($post_type)) {
        $post_type = 'post';
    }
    if (empty($post_status)) {
        $post_status = 'draft';
    }
    // Make sure we set a valid category.
    if (empty($post_category) || 0 == count($post_category) || !is_array($post_category)) {
        // 'post' requires at least one category.
        if ('post' == $post_type && 'auto-draft' != $post_status) {
            $post_category = array(get_option('default_category'));
        } else {
            $post_category = array();
        }
    }
    if (empty($post_author)) {
        $post_author = $user_id;
    }
    // Create a valid post name. Drafts and pending posts are allowed to have an empty
    // post name.
    if (empty($post_name)) {
        if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
            $post_name = sanitize_title($post_title);
        } else {
            $post_name = '';
        }
    } else {
        // On updates, we need to check to see if it's using the old, fixed sanitization context.
        $check_name = sanitize_title($post_name, '', 'old-save');
        if ($update && strtolower(urlencode($post_name)) == $check_name && get_post_field('post_name', $ID) == $check_name) {
            $post_name = $check_name;
        } else {
            // new post, or slug has changed.
            $post_name = sanitize_title($post_name);
        }
    }
    // If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now
    if (empty($post_date) || '0000-00-00 00:00:00' == $post_date) {
        $post_date = current_time('mysql');
    }
    // validate the date
    $mm = substr($post_date, 5, 2);
    $jj = substr($post_date, 8, 2);
    $aa = substr($post_date, 0, 4);
    $valid_date = wp_checkdate($mm, $jj, $aa, $post_date);
    if (!$valid_date) {
        if ($wp_error) {
            return new WP_Error('invalid_date', __('Whoops, the provided date is invalid.'));
        } else {
            return 0;
        }
    }
    if (empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt) {
        if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
            $post_date_gmt = get_gmt_from_date($post_date);
        } else {
            $post_date_gmt = '0000-00-00 00:00:00';
        }
    }
    if ($update || '0000-00-00 00:00:00' == $post_date) {
        $post_modified = current_time('mysql');
        $post_modified_gmt = current_time('mysql', 1);
    } else {
        $post_modified = $post_date;
        $post_modified_gmt = $post_date_gmt;
    }
    if ('publish' == $post_status) {
        $now = gmdate('Y-m-d H:i:59');
        if (mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false)) {
            $post_status = 'future';
        }
    } elseif ('future' == $post_status) {
//.........这里部分代码省略.........
开发者ID:thabofletcher,项目名称:tc-site,代码行数:101,代码来源:pmxi_insert_post.php


示例10: adverts_save_post

/**
 * Save additional data for adverts custom post type
 * 
 * @uses Adverts_Form 
 * 
 * @param int $ID Post ID
 * @param WP_Post $post
 * @since 0.1
 * @return null
 */
function adverts_save_post($ID = false, $post = false)
{
    global $pagenow;
    if (!in_array($pagenow, array("post.php", "post-new.php"))) {
        return $ID;
    }
    $nonce = 'product_price_box_content_nonce';
    if (!isset($_POST[$nonce]) || !wp_verify_nonce($_POST[$nonce], basename(__FILE__))) {
        //return $ID;
    }
    /* Get the post type object. */
    $post_type = get_post_type_object($post->post_type);
    /* Check if the current user has permission to edit the post. */
    if (!current_user_can($post_type->cap->edit_post, $ID)) {
        return $ID;
    }
    if (!$post->post_type == 'advert') {
        return $ID;
    }
    if (defined("DOING_AJAX") && DOING_AJAX) {
        return $ID;
    }
    /* Save expiration date in DB */
    if (!empty($_POST)) {
        $current_exp_date = get_post_meta($ID, "_expiration_date", true);
        $edit_date = empty($current_exp_date);
    } else {
        $edit_date = false;
    }
    foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) {
        if (!empty($_POST['adverts_hidden_' . $timeunit]) && $_POST['adverts_hidden_' . $timeunit] != $_POST['adverts_' . $timeunit]) {
            $edit_date = 1;
            break;
        }
    }
    if (isset($_POST["never_expires"]) && $_POST["never_expires"] == "1") {
        // Advert does not expire, unset expiration date
        delete_post_meta($ID, "_expiration_date");
    } else {
        if ($edit_date) {
            // Build expiration date, based on submitted $_POST data
            $aa = isset($_POST['adverts_aa']) ? $_POST['adverts_aa'] : null;
            $mm = isset($_POST['adverts_mm']) ? $_POST['adverts_mm'] : null;
            $jj = isset($_POST['adverts_jj']) ? $_POST['adverts_jj'] : null;
            $hh = isset($_POST['adverts_hh']) ? $_POST['adverts_hh'] : null;
            $mn = isset($_POST['adverts_mn']) ? $_POST['adverts_mn'] : null;
            $ss = isset($_POST['adverts_ss']) ? $_POST['adverts_ss'] : null;
            $aa = $aa <= 0 ? date('Y') : $aa;
            $mm = $mm <= 0 ? date('n') : $mm;
            $jj = $jj > 31 ? 31 : $jj;
            $jj = $jj <= 0 ? date('j') : $jj;
            $hh = $hh > 23 ? $hh - 24 : $hh;
            $mn = $mn > 59 ? $mn - 60 : $mn;
            $ss = $ss > 59 ? $ss - 60 : $ss;
            $exp_date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss);
            $valid_date = wp_checkdate($mm, $jj, $aa, $exp_date);
            if (!$valid_date) {
                return new WP_Error('invalid_date', __('Whoops, the provided date is invalid.'));
            }
            //$exp_date_gmt = get_gmt_from_date( $exp_date );
            //
            // Save expiration date in DB
            update_post_meta($ID, "_expiration_date", strtotime($exp_date));
        }
    }
    $form = new Adverts_Form();
    $form->load(Adverts::instance()->get("form"));
    $form->bind(stripslashes_deep($_POST));
    foreach ($form->get_fields() as $field) {
        if (isset($field["value"])) {
            $meta_old = get_post_meta($ID, $field["name"]);
            if ($field["value"] == '') {
                delete_post_meta($ID, $field["name"]);
            } else {
                update_post_meta($ID, $field["name"], $field["value"]);
            }
        }
    }
}
开发者ID:hemangsk,项目名称:TCB,代码行数:89,代码来源:admin-post-type.php


示例11: save_slider

 /**
  * Save slider details. Callback function for action save_post_{post_type}
  * @param int $post_id
  * @param object $post
  * @param bool $update
  */
 public function save_slider($post_id, $post, $update)
 {
     if (!current_user_can('edit_fa_items', $post_id)) {
         wp_die(-1);
     }
     // check for the nonce presence
     if (!isset($_POST['fa-slider-settings-nonce'])) {
         return;
     }
     check_admin_referer('fa-slider-options-save', 'fa-slider-settings-nonce');
     // process expiration date
     $process_date = false;
     foreach (array('exp_mm', 'exp_dd', 'exp_yy', 'exp_hh', 'exp_ii') as $timeunit) {
         if ($_POST[$timeunit] != $_POST['curr_' . $timeunit]) {
             $process_date = true;
             break;
         }
     }
     // if date should be processed
     if ($process_date) {
         $date = $_POST['exp_yy'] . '-' . $_POST['exp_mm'] . '-' . $_POST['exp_dd'];
         if (wp_checkdate($_POST['exp_mm'], $_POST['exp_dd'], $_POST['exp_yy'], $date)) {
             $expiration_date = $date . ' ' . $_POST['exp_hh'] . ':' . $_POST['exp_ii'] . ':' . $_POST['exp_ss'];
             $_POST['slider']['expires'] = $expiration_date;
             // check if currently set up date is less than post date
             if (strtotime($expiration_date) < time() && parent::get_status_expired() != $post->post_status) {
                 $args = array('ID' => $post_id, 'post_status' => parent::get_status_expired());
                 // remove the action to avoid a loop
                 remove_action('save_post_' . parent::get_type_slider(), array($this, 'save_slider'));
                 wp_update_post($args);
             }
         }
     }
     // remove the expiration date if set
     if (isset($_POST['exp_ignore'])) {
         $_POST['slider']['expires'] = '0000-00-00 00:00:00';
     }
     // do not allow no post type specified for posts
     if (!isset($_POST['slides']['post_type'])) {
         $_POST['slides']['post_type'][] = 'post';
     }
     // allow no categories specified (allow all categories if none specified)
     if (!isset($_POST['slides']['tags'])) {
         $_POST['slides']['tags'] = array();
     }
     // allow empty content on mixed posts
     if (!isset($_POST['slides']['posts'])) {
         $_POST['slides']['posts'] = array();
     }
     // allow empty content on images
     if (!isset($_POST['slides']['images'])) {
         $_POST['slides']['images'] = array();
     }
     // set the slider color
     if (isset($_POST['theme']['active'])) {
         $theme = $_POST['theme']['active'];
         // process the layout variation if available
         if (isset($_POST['layout']['class'][$theme])) {
             $_POST['layout']['class'] = $_POST['layout']['class'][$theme];
         } else {
             $_POST['layout']['class'] = '';
         }
         // set the color
         if (isset($_POST['theme_color'][$theme])) {
             $_POST['theme']['color'] = $_POST['theme_color'][$theme];
         } else {
             $_POST['theme']['color'] = '';
         }
     }
     // allow empty on display categories
     if (!isset($_POST['display']['tax'])) {
         $_POST['display']['tax'] = array();
     }
     // allow empty on display posts
     if (!isset($_POST['display']['posts'])) {
         $_POST['display']['posts'] = array();
     }
     // process the publish areas
     $areas = fa_get_options('hooks');
     $set = isset($_POST['slider_area']) ? $_POST['slider_area'] : array();
     foreach ($areas as $area_id => $area) {
         if (in_array($area_id, $set)) {
             if (!in_array($post_id, $area['sliders'])) {
                 $areas[$area_id]['sliders'][] = $post_id;
             }
         } else {
             if (in_array($post_id, $area['sliders'])) {
                 $key = array_search($post_id, $area['sliders']);
                 if (false !== $key) {
                     unset($areas[$area_id]['sliders'][$key]);
                 }
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:proudchild,项目名称:sdmblog,代码行数:101,代码来源:class-fa-admin.php


示例12: current_time

 * is not 'draft' or 'pending', set date to now.
 */
if (empty($postarr['post_date']) || '0000-00-00 00:00:00' == $postarr['post_date']) {
    if (empty($postarr['post_date_gmt']) || '0000-00-00 00:00:00' == $postarr['post_date_gmt']) {
        $post_date = current_time('mysql');
    } else {
        $post_date = get_date_from_gmt($postarr['post_date_gmt']);
    }
} else {
    $post_date = $postarr['post_date'];
}
// Validate the date.
$mm = substr($post_date, 5, 2);
$jj = substr($post_date, 8, 2);
$aa = substr($post_date, 0, 4);
$valid_date = wp_checkdate($mm, $jj, $aa, $post_date);
if (!$valid_date) {
    if ($wp_error) {
        $result['status_msg'] .= 'Whoops, the provided date is invalid.';
        echo json_encode($result);
        exit(-1);
    } else {
        $result['status_msg'] .= '时间出错';
        echo json_encode($result);
        exit(-1);
    }
}
if (empty($postarr['post_date_gmt']) || '0000-00-00 00:00:00' == $postarr['post_date_gmt']) {
    if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
        $post_date_gmt = get_gmt_from_date($post_date);
    } else {
开发者ID:supermt,项目名称:WordPressAPI,代码行数:31,代码来源:postin.php


示例13: import_movie

 /**
  * Save a temporary movie for submitted title.
  * 
  * This is used to save movies submitted from a list before any
  * alteration is made by user. Posts will be kept as 'import-draft'
  * for 24 hours and then destroyed on the next plugin init.
  *
  * @since    1.0
  * 
  * @param    string    $title Movie title.
  * 
  * @return   int       Newly created post ID if everything worked, 0 if no post created.
  */
 public static function import_movie($movie)
 {
     $post_date = current_time('mysql');
     $post_date = wp_checkdate(substr($post_date, 5, 2), substr($post_date, 8, 2), substr($post_date, 0, 4), $post_date);
     $post_date_gmt = get_gmt_from_date($post_date);
     $post_author = get_current_user_id();
     $post_content = '';
     $post_excerpt = '';
     $post_title = $movie['movietitle'];
     $page = get_page_by_title($post_title, OBJECT, 'movie');
     if (!is_null($page)) {
         $message = sprintf('%s − <span class="edit"><a href="%s">%s</a> |</span> <span class="view"><a href="%s">%s</a></span>', sprintf(__('Movie "%s" already imported.', 'wpmovielibrary'), "<em>" . get_the_title($page->ID) . "</em>"), get_edit_post_link($page->ID), __('Edit', 'wpmovielibrary'), get_permalink($page->ID), __('View', 'wpmovielibrary'));
         return new WP_Error('existing_movie', $message);
     }
     $posts = array('ID' => '', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $post_author, 'post_content' => $post_content, 'post_excerpt' => $post_excerpt, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_name' => sanitize_title($post_title), 'post_status' => 'import-draft', 'post_title' => $post_title, 'post_type' => 'movie');
     $import = wp_insert_post($posts);
     return $import;
 }
开发者ID:masterdoed,项目名称:wpmovielibrary,代码行数:31,代码来源:class-wpmoly-import.php


示例14: save_ad

 /**
  * prepare the ad post type to be saved
  *
  * @since 1.0.0
  * @param int $post_id id of the post
  * @todo handling this more dynamic based on ad type
  */
 public function save_ad($post_id)
 {
     // only use for ads, no other post type
     if (!isset($_POST['post_type']) || $this->post_type != $_POST['post_type'] || !isset($_POST['advanced_ad']['type'])) {
         return;
     }
     // don’t do this on revisions
     if (wp_is_post_revision($post_id)) {
         return;
     }
     // get ad object
     $ad = new Advanced_Ads_Ad($post_id);
     if (!$ad instanceof Advanced_Ads_Ad) {
         return;
     }
     // filter to allow change of submitted ad settings
     $_POST['advanced_ad'] = apply_filters('advanced-ads-ad-settings-pre-save', $_POST['advanced_ad']);
     $ad->type = $_POST['advanced_ad']['type'];
     if (isset($_POST['advanced_ad']['output'])) {
         $ad->set_option('output', $_POST['advanced_ad']['output']);
     } else {
         $ad->set_option('output', array());
     }
     /**
      * deprecated since introduction of "visitors" in 1.5.4
      */
     if (isset($_POST['advanced_ad']['visitor'])) {
         $ad->set_option('visitor', $_POST['advanced_ad']['visitor']);
     } else {
         $ad->set_option('visitor', array());
     }
     // visitor conditions
     if (isset($_POST['advanced_ad']['visitors'])) {
         $ad->set_option('visitors', $_POST['advanced_ad']['visitors']);
     } else {
         $ad->set_option('visitors', array());
     }
     // save size
     $ad->width = 0;
     if (isset($_POST['advanced_ad']['width'])) {
         $ad->width = absint($_POST['advanced_ad']['width']);
     }
     $ad->height = 0;
     if (isset($_POST['advanced_ad']['height'])) {
         $ad->height = absint($_POST['advanced_ad']['height']);
     }
     if (!empty($_POST['advanced_ad']['description'])) {
         $ad->description = esc_textarea($_POST['advanced_ad']['description']);
     } else {
         $ad->description = '';
     }
     if (!empty($_POST['advanced_ad']['content'])) {
         $ad->content = $_POST['advanced_ad']['content'];
     } else {
         $ad->content = '';
     }
     if (!empty($_POST['advanced_ad']['conditions'])) {
         $ad->conditions = $_POST['advanced_ad']['conditions'];
     } else {
         $ad->conditions = array();
     }
     // prepare expiry date
     if (isset($_POST['advanced_ad']['expiry_date']['enabled'])) {
         $year = absint($_POST['advanced_ad']['expiry_date']['year']);
         $month = absint($_POST['advanced_ad']['expiry_date']['month']);
         $day = absint($_POST['advanced_ad']['expiry_date']['day']);
         $hour = absint($_POST['advanced_ad']['expiry_date']['hour']);
         $minute = absint($_POST['advanced_ad']['expiry_date']['minute']);
         $expiration_date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year, $month, $day, $hour, $minute, '00');
         $valid_date = wp_checkdate($month, $day, $year, $expiration_date);
         if (!$valid_date) {
             $ad->expiry_date = 0;
         } else {
             // as PHP 5.2 has not reliable 'u' option need to calculate timestamps this way
             $gmDate = get_gmt_from_date($expiration_date, 'Y-m-d-H-i');
             list($year, $month, $day, $hour, $minute) = explode('-', $gmDate);
             $ad->expiry_date = gmmktime($hour, $minute, 0, $month, $day, $year);
         }
     } else {
         $ad->expiry_date = 0;
     }
     $ad->save();
 }
开发者ID:Tymvie,项目名称:advanced_ads_mod,代码行数:90,代码来源:class-advanced-ads-admin.php


示例15: check_date

 /**
  * Check Gregorian date.
  * 
  * @param  string $time  Date to check
  * @return boolean       True if date is valid
  * @see /wp-includes/post.php
  */
 public function check_date($time)
 {
     /**
      * Validate the date
      * 
      * @see /wp-includes/post.php
      */
     $mm = substr($time, 5, 2);
     $jj = substr($time, 8, 2);
     $aa = substr($time, 0, 4);
     $valid_date = wp_checkdate($mm, $jj, $aa, $time);
     return $valid_date;
 }
开发者ID:radscheit,项目名称:unicorn,代码行数:20,代码来源:class-analytics.php


示例16: redirect_canonical


//.........这里部分代码省略.........
    if (is_feed() && ($id = get_query_var('p'))) {
        if ($redirect_url = get_post_comments_feed_link($id, get_query_var('feed'))) {
            $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed'), $redirect_url);
            $redirect['path'] = parse_url($redirect_url, PHP_URL_PATH);
        }
    }
    if (is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p'))) {
        $vars = $wpdb->get_results($wpdb->prepare("SELECT post_type, post_parent FROM {$wpdb->posts} WHERE ID = %d", $id));
        if (isset($vars[0]) && ($vars = $vars[0])) {
            if ('revision' == $vars->post_type && $vars->post_parent > 0) {
                $id = $vars->post_parent;
            }
            if ($redirect_url = get_permalink($id)) {
                $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url);
            }
        }
    }
    // These tests give us a WP-generated permalink
    if (is_404()) {
        // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's
        $id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id'));
        if ($id && ($redirect_post = get_post($id))) {
            $post_type_obj = get_post_type_object($redirect_post->post_type);
            if ($post_type_obj->public) {
                $redirect_url = get_permalink($redirect_post);
                $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url);
            }
        }
        if (get_query_var('day') && get_query_var('monthnum') && get_query_var('year')) {
            $year = get_query_var('year');
            $month = get_query_var('monthnum');
            $day = get_query_var('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 (get_query_var('monthnum') && get_query_var('year') && 12 < get_query_var('monthnum')) {
            $redirect_url = get_year_link(get_query_var('year'));
            $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('year', 'monthnum'), $redirect_url);
        }
        if (!$redirect_url) {
            if ($redirect_url = redirect_guess_404_permalink()) {
                $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url);
            }
        }
        if (get_query_var('page') && $wp_query->post && false !== strpos($wp_query->post->post_content, '<!--nextpage-->')) {
            $redirect['path'] = rtrim($redirect['path'], (int) get_query_var('page 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_clean_plugins_cache函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_check_post_lock函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap