本文整理汇总了PHP中get_gmt_from_date函数的典型用法代码示例。如果您正苦于以下问题:PHP get_gmt_from_date函数的具体用法?PHP get_gmt_from_date怎么用?PHP get_gmt_from_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_gmt_from_date函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: test_get_gmt_from_date_during_dst
/**
* @ticket 20328
*/
function test_get_gmt_from_date_during_dst()
{
update_option('timezone_string', 'Europe/London');
$local = '2012-06-01 12:34:56';
$gmt = '2012-06-01 11:34:56';
$this->assertEquals($gmt, get_gmt_from_date($local));
}
开发者ID:boonebgorges,项目名称:wp,代码行数:10,代码来源:date.php
示例2: update_orbis_task_meta
/**
* Update Orbis task meta data
*
* @param array $data
*/
function update_orbis_task_meta($post_id, array $data = null)
{
if (is_array($data)) {
// Due At
if (isset($data['_orbis_task_due_at_string'])) {
$date_string = $data['_orbis_task_due_at_string'];
$timestamp = strtotime($date_string);
if ($timestamp !== false) {
$date = date('Y-m-d H:i:s', $timestamp);
$date_gmt = get_gmt_from_date($date);
$data['_orbis_task_due_at'] = $date;
$data['_orbis_task_due_at_gmt'] = $date_gmt;
}
}
// Seconds
if (isset($data['_orbis_task_seconds_string'])) {
$data['_orbis_task_seconds'] = orbis_parse_time($data['_orbis_task_seconds_string']);
}
// Meta
foreach ($data as $key => $value) {
if ($value === '' || $value === null) {
delete_post_meta($post_id, $key);
} else {
update_post_meta($post_id, $key, $value);
}
}
// Sync
orbis_save_task_sync($post_id);
}
}
开发者ID:joffcrabtree,项目名称:wp-orbis-tasks,代码行数:35,代码来源:post.php
示例3: open
public function open($email_id, $subscriber_id, $status = 1)
{
global $wpdb;
// Initialise column format array
$column_formats = $this->get_columns();
$data = array('status' => $status, 'opened_count' => 1, 'opened_at' => get_gmt_from_date(date('Y-m-d H:i:s')));
// Force fields to lower case
$data = array_change_key_case($data);
// White list columns
$data = array_intersect_key($data, $column_formats);
// Reorder $column_formats to match the order of columns given in $data
$data_keys = array_keys($data);
$column_formats = array_merge(array_flip($data_keys), $column_formats);
if (false === ($rows = $wpdb->update($this->table_name, $data, array('email_id' => $email_id, 'subscriber_id' => $subscriber_id, 'status' => 0, 'opened_at' => '0000-00-00 00:00:00'), $column_formats))) {
return false;
}
if ($rows === 0 && $status === 1) {
$wpdb->query($wpdb->prepare(" Update " . $this->table_name . " set opened_count = opened_count+1 where email_id = %s and subscriber_id = %s ", $email_id, $subscriber_id));
}
if ($rows === 0 && $status > 1) {
if (false === $wpdb->update($this->table_name, array('status' => $status), array('email_id' => $email_id, 'subscriber_id' => $subscriber_id))) {
return false;
}
}
return true;
}
开发者ID:richardsweeney,项目名称:sendpress,代码行数:26,代码来源:class-sendpress-db-subscribers-tracker.php
示例4: upsert_post
public function upsert_post($post, $silent = false)
{
global $wpdb;
// reject the post if it's not a WP_Post
if (!$post instanceof WP_Post) {
return;
}
$post = $post->to_array();
// reject posts without an ID
if (!isset($post['ID'])) {
return;
}
$now = current_time('mysql');
$now_gmt = get_gmt_from_date($now);
$defaults = array('ID' => 0, 'post_author' => '0', 'post_content' => '', 'post_content_filtered' => '', 'post_title' => '', 'post_name' => '', 'post_excerpt' => '', 'post_status' => 'draft', 'post_type' => 'post', 'comment_status' => 'closed', 'comment_count' => '0', 'ping_status' => '', 'post_password' => '', 'to_ping' => '', 'pinged' => '', 'post_parent' => 0, 'menu_order' => 0, 'guid' => '', 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_modified' => $now, 'post_modified_gmt' => $now_gmt);
$post = array_intersect_key($post, $defaults);
$post = sanitize_post($post, 'db');
unset($post['filter']);
$exists = $wpdb->get_var($wpdb->prepare("SELECT EXISTS( SELECT 1 FROM {$wpdb->posts} WHERE ID = %d )", $post['ID']));
if ($exists) {
$wpdb->update($wpdb->posts, $post, array('ID' => $post['ID']));
} else {
$wpdb->insert($wpdb->posts, $post);
}
clean_post_cache($post['ID']);
}
开发者ID:kanei,项目名称:vantuch.cz,代码行数:26,代码来源:class.jetpack-sync-wp-replicastore.php
示例5: eventon_create_duplicate_from_event
function eventon_create_duplicate_from_event($post, $parent = 0, $post_status = '')
{
global $wpdb;
$new_post_author = wp_get_current_user();
$new_post_date = current_time('mysql');
$new_post_date_gmt = get_gmt_from_date($new_post_date);
if ($parent > 0) {
$post_parent = $parent;
$post_status = $post_status ? $post_status : 'publish';
$suffix = '';
} else {
$post_parent = $post->post_parent;
$post_status = $post_status ? $post_status : 'draft';
$suffix = ' ' . __('(Copy)', 'eventon');
}
// Insert the new template in the post table
$wpdb->insert($wpdb->posts, array('post_author' => $new_post_author->ID, 'post_date' => $new_post_date, 'post_date_gmt' => $new_post_date_gmt, 'post_content' => $post->post_content, 'post_content_filtered' => $post->post_content_filtered, 'post_title' => $post->post_title . $suffix, 'post_excerpt' => $post->post_excerpt, 'post_status' => $post_status, 'post_type' => $post->post_type, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_password' => $post->post_password, 'to_ping' => $post->to_ping, 'pinged' => $post->pinged, 'post_modified' => $new_post_date, 'post_modified_gmt' => $new_post_date_gmt, 'post_parent' => $post_parent, 'menu_order' => $post->menu_order, 'post_mime_type' => $post->post_mime_type));
$new_post_id = $wpdb->insert_id;
// Copy the taxonomies
eventon_duplicate_post_taxonomies($post->ID, $new_post_id, $post->post_type);
// Copy the meta information
eventon_duplicate_post_meta($post->ID, $new_post_id);
// ONLY for ticket addon event duplication
if ($post->post_type == 'product') {
$exclude = apply_filters('woocommerce_duplicate_product_exclude_children', false);
if (!$exclude && ($children_products = get_children('post_parent=' . $post->ID . '&post_type=product_variation'))) {
foreach ($children_products as $child) {
eventon_create_duplicate_from_event(eventon_get_event_to_duplicate($child->ID), $new_post_id, $child->post_status);
}
}
}
return $new_post_id;
}
开发者ID:pab44,项目名称:pab44,代码行数:33,代码来源:duplicate_event.php
示例6: build_data
/**
* Compile the schema.org event data into an array
*/
private function build_data()
{
global $post;
$id = $post->ID;
$events_data = array();
// Index by ID: this will allow filter code to identify the actual event being referred to
// without injecting an additional property
$events_data[$id] = new stdClass();
$events_data[$id]->{'@context'} = 'http://schema.org';
$events_data[$id]->{'@type'} = 'Event';
$events_data[$id]->name = get_the_title();
if (has_post_thumbnail()) {
$events_data[$id]->image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
}
$events_data[$id]->url = get_the_permalink($post->ID);
$events_data[$id]->startDate = get_gmt_from_date(tribe_get_start_date($post, true, TribeDateUtils::DBDATETIMEFORMAT), 'c');
$events_data[$id]->endDate = get_gmt_from_date(tribe_get_end_date($post, true, TribeDateUtils::DBDATETIMEFORMAT), 'c');
if (tribe_has_venue($id)) {
$events_data[$id]->location = new stdClass();
$events_data[$id]->location->{'@type'} = 'Place';
$events_data[$id]->location->name = tribe_get_venue($post->ID);
$events_data[$id]->location->address = strip_tags(str_replace("\n", '', tribe_get_full_address($post->ID)));
}
/**
* Allows the event data to be modifed by themes and other plugins.
*
* @param array $events_data objects representing the Google Markup for each event.
*/
$events_data = apply_filters('tribe_google_event_data', $events_data);
// Strip the post ID indexing before returning
$events_data = array_values($events_data);
return $events_data;
}
开发者ID:chicosilva,项目名称:olharambiental,代码行数:36,代码来源:Google_Data_Markup.php
示例7: clone_landing_page
/**
* Creates cloned landing page and opens it for user
* @param string $status
*/
public static function clone_landing_page($status = 'pending')
{
/* Get the original post */
$id = isset($_GET['post']) ? $_GET['post'] : $_POST['post'];
$post = get_post($id);
/* Copy the post and insert it */
if (!isset($post) || !$post) {
$post_type_obj = get_post_type_object($post->post_type);
wp_die(esc_attr(__('Copy creation failed, could not find original:', 'landing-pages')) . ' ' . $id);
}
if (!is_object($post) && is_numeric($post)) {
$post = get_post($post);
}
$status = $post->post_status;
/* We don't want to clone revisions */
if ($post->post_type == 'revision') {
return;
}
$prefix = "Copy of ";
$suffix = "";
$status = 'pending';
$new_post_author = self::get_current_user();
$new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_mime_type' => $post->post_mime_type, 'post_parent' => $new_post_parent = empty($parent_id) ? $post->post_parent : $parent_id, 'post_password' => $post->post_password, 'post_status' => $status, 'post_title' => $prefix . $post->post_title . $suffix, 'post_type' => $post->post_type);
$new_post['post_date'] = $new_post_date = $post->post_date;
$new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
$new_post_id = wp_insert_post($new_post);
$meta_data = self::get_meta($post->ID);
foreach ($meta_data as $key => $value) {
update_post_meta($new_post_id, $key, $value);
}
wp_redirect(admin_url('edit.php?post_type=' . $post->post_type));
exit;
}
开发者ID:gbaladi,项目名称:landing-pages,代码行数:37,代码来源:class.cloning.php
示例8: lp_duplicate_post_create_duplicate
function lp_duplicate_post_create_duplicate($post, $status = '', $parent_id = '', $blank = false)
{
$prefix = "";
$suffix = "";
if (!is_object($post) && is_numeric($post)) {
$post = get_post($post);
}
$status = $post->post_status;
/* We don't want to clone revisions */
if ($post->post_type == 'revision') {
return;
}
if ($post->post_type != 'attachment') {
$prefix = "Copy of ";
$suffix = "";
$status = 'pending';
}
$new_post_author = lp_duplicate_post_get_current_user();
if ($blank == false) {
$new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_mime_type' => $post->post_mime_type, 'post_parent' => $new_post_parent = empty($parent_id) ? $post->post_parent : $parent_id, 'post_password' => $post->post_password, 'post_status' => $status, 'post_title' => $prefix . $post->post_title . $suffix, 'post_type' => $post->post_type);
$new_post['post_date'] = $new_post_date = $post->post_date;
$new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
} else {
$new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => "", 'post_excerpt' => "", 'post_mime_type' => $post->post_mime_type, 'post_status' => $status, 'post_title' => __("New Blank Landing Page", 'landing-pages'), 'post_type' => $post->post_type, 'post_date' => date('Y-m-d H:i:s'));
}
$new_post_id = wp_insert_post($new_post);
$meta_data = lp_get_post_meta_all($post->ID);
foreach ($meta_data as $key => $value) {
update_post_meta($new_post_id, $key, $value);
}
return $new_post_id;
}
开发者ID:devilcranx,项目名称:landing-pages,代码行数:32,代码来源:module.clone.php
示例9: clonePage
/**
* Clones provided page ID
* @param int $pageId
* @return int
*/
public function clonePage($pageId)
{
$oldPost = get_post($pageId);
if (null === $oldPost) {
return 0;
}
if ('revision' === $oldPost->post_type) {
return 0;
}
$currentUser = wp_get_current_user();
$newPost = array('menu_order' => $oldPost->menu_order, 'comment_status' => $oldPost->comment_status, 'ping_status' => $oldPost->ping_status, 'post_author' => $currentUser->ID, 'post_content' => $oldPost->post_content, 'post_excerpt' => $oldPost->post_excerpt, 'post_mime_type' => $oldPost->post_mime_type, 'post_parent' => $oldPost->post_parent, 'post_password' => $oldPost->post_password, 'post_status' => $oldPost->post_status, 'post_title' => '(dup) ' . $oldPost->post_title, 'post_type' => $oldPost->post_type, 'post_date' => $oldPost->post_date, 'post_date_gmt' => get_gmt_from_date($oldPost->post_date));
$newId = wp_insert_post($newPost);
/*
* Generating unique slug
*/
if ($newPost['post_status'] == 'publish' || $newPost['post_status'] == 'future') {
$postName = wp_unique_post_slug($oldPost->post_name, $newId, $newPost['post_status'], $oldPost->post_type, $newPost['post_parent']);
$newPost = array();
$newPost['ID'] = $newId;
$newPost['post_name'] = $postName;
wp_update_post($newPost);
}
$this->cloneMeta($pageId, $newId);
$this->cloneOpData($pageId, $newId);
return $newId;
}
开发者ID:kyscastellanos,项目名称:arepa,代码行数:31,代码来源:clone_page.php
示例10: wowslider_add
function wowslider_add($folder = false, $update = 0, $delete = true)
{
global $wp_filesystem, $wpdb, $user_ID;
static $id = 0;
if (!$folder) {
return $id;
}
if (!$wp_filesystem || !is_object($wp_filesystem)) {
WP_Filesystem();
}
if ($wp_filesystem->is_file($folder) && strtolower(substr($folder, -4)) == '.zip') {
return wowslider_import($folder, $update, $delete);
}
$folder = rtrim(str_replace('\\', '/', $folder), '/') . '/';
if ($wp_filesystem->is_file($folder . 'slider.html') && $wp_filesystem->is_dir($folder . 'images/')) {
$images = array();
$list = $wp_filesystem->dirlist($folder . ($wp_filesystem->is_dir($folder . 'tooltips/') ? 'tooltips/' : 'images/'));
foreach ($list as $name => $v) {
if ($v['type'] == 'f' && strtolower(substr($name, -4)) == '.jpg') {
$images[] = $name;
}
if (count($images) == 10) {
break;
}
}
if (count($images)) {
$name = '';
if (preg_match('/<!--\\s*Name:(.+?)\\s*-->/ui', file_get_contents($folder . 'slider.html'), $match)) {
$name = trim($match[1]);
}
$date = current_time('mysql');
$insert = array('slider_name' => mb_substr($name, 0, 200), 'slider_author' => $user_ID, 'slider_date' => $date, 'slider_date_gmt' => get_gmt_from_date($date), 'slider_public' => 1, 'slider_images' => serialize($images));
if ($update) {
$insert['ID'] = $update;
}
foreach ($insert as $k => $v) {
$insert[$k] = '"' . $wpdb->escape($v) . '"';
}
$wpdb->query('INSERT INTO ' . $wpdb->prefix . 'wowslider (' . implode(',', array_keys($insert)) . ') VALUES (' . implode(',', array_values($insert)) . ');');
$id = $update ? (int) $update : (int) $wpdb->get_var('SELECT LAST_INSERT_ID();');
if ($id) {
$dest = WOWSLIDER_PLUGIN_PATH . 'sliders/' . $id . '/';
if ($wp_filesystem->is_dir($dest)) {
$wp_filesystem->delete($dest, true);
}
$wp_filesystem->move($folder, $dest);
if ($name == '') {
$wpdb->query('UPDATE ' . $wpdb->prefix . 'wowslider SET slider_name = "' . $wpdb->escape('Slider ' . $id) . '" WHERE ID = ' . $id . ';');
}
file_put_contents($dest . 'slider.html', str_replace('%ID%', $id, file_get_contents($dest . 'slider.html')));
file_put_contents($dest . 'style.css', str_replace('%ID%', $id, file_get_contents($dest . 'style.css')));
return true;
} else {
return __('Failure when added to the table.', 'wowslider');
}
}
}
return __('Wrong slider.', 'wowslider');
}
开发者ID:rmaloney,项目名称:simplewp_restaurant,代码行数:59,代码来源:api.php
示例11: duplicate_post
function duplicate_post($old_id)
{
global $wpdb, $table_prefix;
$sql = sprintf("select * from %sposts where ID = %s", $table_prefix, $old_id);
$old_post = $wpdb->get_row($sql);
$sql = sprintf("select * from %spostmeta where post_id = %s", $table_prefix, $old_id);
$old_meta = $wpdb->get_results($sql);
$sql = sprintf("select * from %sterm_relationships where object_id = %s", $table_prefix, $old_id);
$old_term = $wpdb->get_results($sql);
if (defined('STARRATING_INSTALLED')) {
$sql = sprintf("select * from %sgdsr_data_article where post_id = %s", $table_prefix, $old_id);
$old_gdsr = $wpdb->get_row($sql);
}
$post_date = current_time('mysql');
$post_date_gmt = get_gmt_from_date($post_date);
unset($old_post->ID);
unset($old_post->filter);
unset($old_post->guid);
unset($old_post->post_date_gmt);
$old_post->post_date = $post_date;
$old_post->post_status = "draft";
$old_post->post_title .= " (1)";
$old_post->post_name .= "-1";
$old_post->post_modified = $post_date;
$old_post->post_modified_gmt = $post_date_gmt;
$old_post->comment_count = "0";
if (false === $wpdb->insert($wpdb->posts, get_object_vars($old_post))) {
return 0;
}
$post_ID = (int) $wpdb->insert_id;
$wpdb->update($wpdb->posts, array('guid' => get_permalink($post_ID)), array('ID' => $post_ID));
foreach ($old_meta as $m) {
unset($m->meta_id);
$m->post_id = $post_ID;
$wpdb->insert($wpdb->postmeta, get_object_vars($m));
}
foreach ($old_term as $m) {
unset($m->meta_id);
$m->object_id = $post_ID;
$wpdb->insert($wpdb->term_relationships, get_object_vars($m));
}
if (is_object($old_gdsr)) {
$old_gdsr->post_id = $post_ID;
unset($old_gdsr->user_voters);
unset($old_gdsr->user_votes);
unset($old_gdsr->visitor_voters);
unset($old_gdsr->visitor_votes);
unset($old_gdsr->review);
unset($old_gdsr->views);
unset($old_gdsr->user_recc_plus);
unset($old_gdsr->user_recc_minus);
unset($old_gdsr->visitor_recc_plus);
unset($old_gdsr->visitor_recc_minus);
unset($old_gdsr->last_voted);
unset($old_gdsr->last_voted_recc);
$wpdb->insert($table_prefix . "gdsr_data_article", get_object_vars($old_gdsr));
}
return $post_ID;
}
开发者ID:hewu,项目名称:blogwp,代码行数:59,代码来源:db.php
示例12: fyd_create_results_page
/**
* Create a new page to display the search results.
* This page will essentially be the home of the app,
* and the one to which we inject all the information
* the app displays.
*
*/
private static function fyd_create_results_page()
{
$date = get_the_date('Y-m-d H:i:s');
$page_template_path = plugins_url('/templates/page-find-your-do-results.php', __FILE__);
$args = array('post_content' => '', 'post_title' => 'Find Your DO Results', 'post_status' => 'publish', 'post_type' => 'page', 'ping_status' => 'closed', 'post_date' => $date, 'post_date_gmt' => get_gmt_from_date($date), 'comment_status' => 'closed');
$post_id = wp_insert_post($args);
return $post_id;
}
开发者ID:pjsinco,项目名称:find-your-do-play,代码行数:15,代码来源:class-find-your-do-activator.php
示例13: pronamic_events_get_end_date_meta
function pronamic_events_get_end_date_meta($timestamp, array &$meta = array())
{
$date = date('Y-m-d H:i:s', $timestamp);
$date_gmt = get_gmt_from_date($date);
$meta['_pronamic_end_date'] = $timestamp;
$meta['_pronamic_event_end_date'] = $date;
$meta['_pronamic_event_end_date_gmt'] = $date_gmt;
return $meta;
}
开发者ID:joffcrabtree,项目名称:wp-pronamic-events,代码行数:9,代码来源:functions.php
示例14: test_date
function test_date()
{
$this->make_user_by_role('editor');
$result = $this->myxmlrpcserver->wp_getPage(array(1, $this->post_id, 'editor', 'editor'));
$this->assertNotInstanceOf('IXR_Error', $result);
$this->assertInstanceOf('IXR_Date', $result['dateCreated']);
$this->assertInstanceOf('IXR_Date', $result['date_created_gmt']);
$date_gmt = strtotime(get_gmt_from_date(mysql2date('Y-m-d H:i:s', $this->post_data['post_date'], false), 'Ymd\\TH:i:s'));
$this->assertEquals($this->post_date_ts, $result['dateCreated']->getTimestamp());
$this->assertEquals($date_gmt, $result['date_created_gmt']->getTimestamp());
}
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:11,代码来源:getPage.php
示例15: comment
function comment($id, $post_id, $props = array())
{
global $wp_version;
$now = current_time('mysql');
$now_gmt = get_gmt_from_date($now);
$comment = (object) array_merge(self::$default_comment_props, $props, array('comment_ID' => $id, 'comment_post_ID' => $post_id, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt));
if (version_compare($wp_version, '4.4', '<')) {
return $comment;
}
return new WP_Comment($comment);
}
开发者ID:iamtakashi,项目名称:jetpack,代码行数:11,代码来源:class.jetpack-sync-test-object-factory.php
示例16: set_due_at
public function set_due_at($date_string)
{
update_post_meta($this->post->ID, '_orbis_task_due_at_string', $date_string);
$timestamp = strtotime($date_string);
if ($timestamp !== false) {
$date = date('Y-m-d H:i:s', $timestamp);
$date_gmt = get_gmt_from_date($date);
update_post_meta($this->post->ID, '_orbis_task_due_at', $date);
update_post_meta($this->post->ID, '_orbis_task_due_at_gmt', $date_gmt);
}
}
开发者ID:joffcrabtree,项目名称:wp-orbis-tasks,代码行数:11,代码来源:orbis-task.php
示例17: create
/**
* Method to create a new coupon in the database.
*
* @since 2.7.0
* @param WC_Coupon
*/
public function create(&$coupon)
{
$coupon->set_date_created(current_time('timestamp'));
$coupon_id = wp_insert_post(apply_filters('woocommerce_new_coupon_data', array('post_type' => 'shop_coupon', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_title' => $coupon->get_code(), 'post_content' => '', 'post_excerpt' => $coupon->get_description(), 'post_date' => date('Y-m-d H:i:s', $coupon->get_date_created()), 'post_date_gmt' => get_gmt_from_date(date('Y-m-d H:i:s', $coupon->get_date_created())))), true);
if ($coupon_id) {
$coupon->set_id($coupon_id);
$this->update_post_meta($coupon, true);
$coupon->save_meta_data();
$coupon->apply_changes();
do_action('woocommerce_new_coupon', $coupon_id);
}
}
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:18,代码来源:class-wc-coupon-data-store-cpt.php
示例18: wp_insert_post
function wp_insert_post($postarr = array())
{
global $wpdb, $allowedtags;
// export array as variables
extract($postarr);
$post_name = sanitize_title($post_title);
$post_author = (int) $post_author;
// Make sure we set a valid category
if (0 == count($post_category) || !is_array($post_category)) {
$post_category = array(get_option('default_category'));
}
$post_cat = $post_category[0];
if (empty($post_date)) {
$post_date = current_time('mysql');
}
// Make sure we have a good gmt date:
if (empty($post_date_gmt)) {
$post_date_gmt = get_gmt_from_date($post_date);
}
if (empty($comment_status)) {
$comment_status = get_settings('default_comment_status');
}
if (empty($ping_status)) {
$ping_status = get_settings('default_ping_status');
}
if (empty($post_parent)) {
$post_parent = 0;
}
if ('publish' == $post_status) {
$post_name_check = $wpdb->get_var("SELECT post_name FROM {$wpdb->posts} WHERE post_name = '{$post_name}' AND post_status = 'publish' AND ID != '{$post_ID}' LIMIT 1");
if ($post_name_check) {
$suffix = 2;
while ($post_name_check) {
$alt_post_name = $post_name . "-{$suffix}";
$post_name_check = $wpdb->get_var("SELECT post_name FROM {$wpdb->posts} WHERE post_name = '{$alt_post_name}' AND post_status = 'publish' AND ID != '{$post_ID}' LIMIT 1");
$suffix++;
}
$post_name = $alt_post_name;
}
}
$sql = "INSERT INTO {$wpdb->posts}\n\t\t(post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_category, post_status, post_name, comment_status, ping_status, post_parent)\n\t\tVALUES ('{$post_author}', '{$post_date}', '{$post_date_gmt}', '{$post_date}', '{$post_date_gmt}', '{$post_content}', '{$post_title}', '{$post_excerpt}', '{$post_cat}', '{$post_status}', '{$post_name}', '{$comment_status}', '{$ping_status}', '{$post_parent}')";
$result = $wpdb->query($sql);
$post_ID = $wpdb->insert_id;
// Set GUID
$wpdb->query("UPDATE {$wpdb->posts} SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '{$post_ID}'");
wp_set_post_cats('', $post_ID, $post_category);
if ($post_status == 'publish') {
do_action('publish_post', $post_ID);
}
pingback($content, $post_ID);
// Return insert_id if we got a good result, otherwise return zero.
return $result ? $post_ID : 0;
}
开发者ID:BackupTheBerlios,项目名称:steampress-svn,代码行数:53,代码来源:functions-post.php
示例19: test_future_post_transition
public function test_future_post_transition()
{
// Create a future post and add the archiveless post meta value
$post_id = $this->factory->post->create(array('post_title' => 'future archiveless post', 'post_date' => gmdate('Y-m-d H:i:s', time() + DAY_IN_SECONDS), 'post_status' => 'future'));
add_post_meta($post_id, 'archiveless', '1');
// Verify that the post correctly inserted with the 'future' status
$this->assertEquals('future', get_post_status($post_id));
// Set a new date in the past
$new_date = gmdate('Y-m-d H:i:s', time() - DAY_IN_SECONDS);
wp_update_post(array('ID' => $post_id, 'post_date' => $new_date, 'post_date_gmt' => get_gmt_from_date($new_date)));
// Verify that the post transitioned to 'archiveless' (due to the post meta)
$this->assertEquals('archiveless', get_post_status($post_id));
}
开发者ID:TheBillPleaseZA,项目名称:archiveless,代码行数:13,代码来源:test-general.php
示例20: test_date
function test_date()
{
$this->make_user_by_role('editor');
$results = $this->myxmlrpcserver->wp_getPageList(array(1, 'editor', 'editor'));
$this->assertNotInstanceOf('IXR_Error', $results);
foreach ($results as $result) {
$page = get_post($result->page_id);
$date_gmt = strtotime(get_gmt_from_date(mysql2date('Y-m-d H:i:s', $page->post_date, false), 'Ymd\\TH:i:s'));
$this->assertInstanceOf('IXR_Date', $result->dateCreated);
$this->assertInstanceOf('IXR_Date', $result->date_created_gmt);
$this->assertEquals(strtotime($page->post_date), $result->dateCreated->getTimestamp());
$this->assertEquals($date_gmt, $result->date_created_gmt->getTimestamp());
}
}
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:14,代码来源:getPageList.php
注:本文中的get_gmt_from_date函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论