/** * @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)); }
/** * 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); } }
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; }
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']); }
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; }
/** * 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; }
/** * 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; }
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; }
/** * 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; }
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'); }
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; }
/** * 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; }
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; }
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()); }
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); }
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); } }
/** * 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); } }
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; }
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)); }
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()); } }
function test_date() { $this->make_user_by_role('author'); $this->factory->post->create(); $results = $this->myxmlrpcserver->mt_getRecentPostTitles(array(1, 'author', 'author')); $this->assertNotInstanceOf('IXR_Error', $results); foreach ($results as $result) { $post = get_post($result['postid']); $date_gmt = strtotime(get_gmt_from_date(mysql2date('Y-m-d H:i:s', $post->post_date, false), 'Ymd\\TH:i:s')); $this->assertInstanceOf('IXR_Date', $result['dateCreated']); $this->assertInstanceOf('IXR_Date', $result['date_created_gmt']); $this->assertEquals(strtotime($post->post_date), $result['dateCreated']->getTimestamp()); $this->assertEquals($date_gmt, $result['date_created_gmt']->getTimestamp()); } }
public function test_local_time() { update_option('timezone_string', 'America/New_York'); $gmt_base = new Fieldmanager_Datepicker(array('name' => 'test_gmt_time', 'use_time' => true)); $local_base = new Fieldmanager_Datepicker(array('name' => 'test_local_time', 'use_time' => true, 'store_local_time' => true)); $test_data = array('date' => '13 Mar 2014', 'hour' => '2', 'minute' => '37', 'ampm' => 'am'); $gmt_base->add_meta_box('test meta box', $this->post)->save_to_post_meta($this->post_id, $test_data); $gmt_stamp = get_post_meta($this->post_id, 'test_gmt_time', true); $this->assertEquals(strtotime('2014-03-13 02:37:00'), intval($gmt_stamp)); $local_base->add_meta_box('test meta box', $this->post)->save_to_post_meta($this->post_id, $test_data); $local_stamp = get_post_meta($this->post_id, 'test_local_time', true); $this->assertEquals(get_gmt_from_date('2014-03-13 02:37:00', 'U'), intval($local_stamp)); $this->assertEquals(strtotime('2014-03-13 02:37:00 America/New_York'), intval($local_stamp)); $this->assertEquals($gmt_stamp - $local_stamp, -4 * HOUR_IN_SECONDS); }
public function get_google_calendar_time_format($start_date = '', $end_date = '') { if (!$start_date) { return ''; } $start_date = get_gmt_from_date($start_date); $start_date = strtotime($start_date); if (!$end_date) { $end_date = $start_date * 3600; // Add 1 hour to the start time and be done with } else { $end_date = get_gmt_from_date($end_date); $end_date = strtotime($end_date); } return date('Ymd\\THis\\Z', $start_date) . '/' . date('Ymd\\THis\\Z', $end_date); }
/** * Compile the schema.org event data into an array */ protected function build_data() { global $post; $id = $post->ID; $event_data = parent::build_data(); $event_data[$id]->{'@type'} = 'Event'; $event_data[$id]->startDate = get_gmt_from_date(tribe_get_start_date($post, true, Tribe__Events__Date_Utils::DBDATETIMEFORMAT), 'c'); $event_data[$id]->endDate = get_gmt_from_date(tribe_get_end_date($post, true, Tribe__Events__Date_Utils::DBDATETIMEFORMAT), 'c'); if (tribe_has_venue($id)) { $event_data[$id]->location = new stdClass(); $event_data[$id]->location->{'@type'} = 'Place'; $event_data[$id]->location->name = tribe_get_venue($post->ID); $event_data[$id]->location->address = strip_tags(str_replace("\n", '', tribe_get_full_address($post->ID))); } return $event_data; }
/** * Create a new product. * * @since 2.7.0 * @param WC_Product */ public function create(&$product) { $product->set_date_created(current_time('timestamp')); $id = wp_insert_post(apply_filters('woocommerce_new_product_variation_data', array('post_type' => 'product_variation', 'post_status' => $product->get_status() ? $product->get_status() : 'publish', 'post_author' => get_current_user_id(), 'post_title' => get_the_title($product->get_parent_id()) . ' – ' . wc_get_formatted_variation($product, true, false), 'post_content' => '', 'post_parent' => $product->get_parent_id(), 'comment_status' => 'closed', 'ping_status' => 'closed', 'menu_order' => $product->get_menu_order(), 'post_date' => date('Y-m-d H:i:s', $product->get_date_created()), 'post_date_gmt' => get_gmt_from_date(date('Y-m-d H:i:s', $product->get_date_created())))), true); if ($id && !is_wp_error($id)) { $product->set_id($id); $this->update_post_meta($product); $this->update_terms($product); $this->update_attributes($product); $product->save_meta_data(); do_action('woocommerce_create_product_variation', $id); $product->apply_changes(); $this->update_version_and_type($product); $this->update_term_counts($product); $this->clear_caches($product); } }
/** * Method to create a new product in the database. * @param WC_Product */ public function create(&$product) { $product->set_date_created(current_time('timestamp')); $id = wp_insert_post(apply_filters('woocommerce_new_product_data', array('post_type' => 'product', 'post_status' => $product->get_status() ? $product->get_status() : 'publish', 'post_author' => get_current_user_id(), 'post_title' => $product->get_name() ? $product->get_name() : __('Product', 'woocommerce'), 'post_content' => $product->get_description(), 'post_excerpt' => $product->get_short_description(), 'post_parent' => $product->get_parent_id(), 'comment_status' => $product->get_reviews_allowed() ? 'open' : 'closed', 'ping_status' => 'closed', 'menu_order' => $product->get_menu_order(), 'post_date' => date('Y-m-d H:i:s', $product->get_date_created()), 'post_date_gmt' => get_gmt_from_date(date('Y-m-d H:i:s', $product->get_date_created())))), true); if ($id && !is_wp_error($id)) { $product->set_id($id); $this->update_post_meta($product); $this->update_terms($product); $this->update_attributes($product); $this->update_downloads($product); $product->save_meta_data(); do_action('woocommerce_new_product', $id); $product->apply_changes(); $this->update_version_and_type($product); $this->update_term_counts($product); $this->clear_caches($product); } }
public function update_rc_reserved_content($post_id) { $component = new Class_Rucy_Component(); $post_metas = $component->get_post_rc_meta((int) $post_id); if ($post_metas->accept != "1") { return; } // rollback $rollback_data = array(); if ($post_metas->accept_rollback == "1") { $rollback_data = $this->get_rollback_post((int) $post_id, $post_metas->accept_rollback_date, $post_metas->accept_rollback_feature_img); } // set update content $updates = array('ID' => (int) $post_id, 'post_content' => $post_metas->content); // set update post date if ($post_metas->accept_update == "1") { $updates['post_date'] = $post_metas->date; $updates['post_date_gmt'] = get_gmt_from_date($post_metas->date); } // update post remove_filter('content_save_pre', 'wp_filter_post_kses'); remove_filter('content_filtered_save_pre', 'wp_filter_post_kses'); add_filter('content_save_pre', array($this, 'rc_content_allow_iframe')); wp_update_post($updates, true); remove_filter('content_save_pre', array($this, 'rc_content_allow_iframe')); add_filter('content_save_pre', 'wp_filter_post_kses'); add_filter('content_filtered_save_pre', 'wp_filter_post_kses'); // update feature image if ($post_metas->accept_feature_img == "1" && $post_metas->feature_img != "") { $this->update_post_thumbnail($post_id, $post_metas->feature_img); } // delete post metas $post_meta_keys = $component->get_post_meta_keys(); foreach ($post_meta_keys as $key => $value) { delete_post_meta($post_id, $value); } // clear schedule on wp_cron wp_clear_scheduled_hook(RC_CRON_HOOK, array($post_id)); // save post meta for rollback if ($post_metas->accept_rollback == "1") { $reserve_date = strtotime(get_gmt_from_date($post_metas->rollback_date) . "GMT"); $this->set_rollback_setting($post_id, $reserve_date, $rollback_data); } }
/** * Function to create the duplicate of the event. * * @access public * @param mixed $post * @param int $parent (default: 0) * @param string $post_status (default: '') * @return void */ 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'); } $new_post_type = $post->post_type; $post_content = str_replace("'", "''", $post->post_content); $post_content_filtered = str_replace("'", "''", $post->post_content_filtered); $post_excerpt = str_replace("'", "''", $post->post_excerpt); $post_title = str_replace("'", "''", $post->post_title) . $suffix; $post_name = str_replace("'", "''", $post->post_name); $comment_status = str_replace("'", "''", $post->comment_status); $ping_status = str_replace("'", "''", $post->ping_status); // Insert the new template in the post table $wpdb->query("INSERT INTO {$wpdb->posts}\r\n\t\t\t(post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt, post_status, post_type, comment_status, ping_status, post_password, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type)\r\n\t\t\tVALUES\r\n\t\t\t('{$new_post_author->ID}', '{$new_post_date}', '{$new_post_date_gmt}', '{$post_content}', '{$post_content_filtered}', '{$post_title}', '{$post_excerpt}', '{$post_status}', '{$new_post_type}', '{$comment_status}', '{$ping_status}', '{$post->post_password}', '{$post->to_ping}', '{$post->pinged}', '{$new_post_date}', '{$new_post_date_gmt}', '{$post_parent}', '{$post->menu_order}', '{$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); // for event tickets addon using WC if ($new_post_type == 'product') { $children_products = get_children('post_parent=' . $post->ID . '&post_type=product_variation'); if ($children_products) { if ($children_products) { 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; }
private function compute($whichtime) { // Returned value should be in UNIX time. $unixtime_now = time(); // Convert to date $now_timestring_gmt = gmdate('Y-m-d H:i:s', $unixtime_now); // Convert to blog's timezone $now_timestring_blogzone = get_date_from_gmt($now_timestring_gmt, 'Y-m-d H:i:s'); $int_key = 'db' == $whichtime ? '_database' : ''; $sched = isset($_POST['updraft_interval' . $int_key]) ? $_POST['updraft_interval' . $int_key] : 'manual'; // Was a particular week-day specified? if (isset($_POST['updraft_startday_' . $whichtime]) && ('weekly' == $sched || 'monthly' == $sched || 'fortnightly' == $sched)) { // Get specified day of week in range 0-6 $startday = min(absint($_POST['updraft_startday_' . $whichtime]), 6); // Get today's day of week in range 0-6 $day_today_blogzone = get_date_from_gmt($now_timestring_gmt, 'w'); if ($day_today_blogzone != $startday) { if ($startday < $day_today_blogzone) { $startday += 7; } $new_startdate_unix = $unixtime_now + ($startday - $day_today_blogzone) * 86400; $now_timestring_blogzone = get_date_from_gmt(gmdate('Y-m-d H:i:s', $new_startdate_unix), 'Y-m-d H:i:s'); } } // HH:MM, in blog time zone // This function is only called from the options validator, so we don't read the current option //$start_time = UpdraftPlus_Options::get_updraft_option('updraft_starttime_'.$whichtime); $start_time = isset($_POST['updraft_starttime_' . $whichtime]) ? $_POST['updraft_starttime_' . $whichtime] : '00:00'; list($start_hour, $start_minute) = $this->parse($start_time); // Now, convert the start time HH:MM from blog time to UNIX time $start_time_unix = get_gmt_from_date(substr($now_timestring_blogzone, 0, 11) . sprintf('%02d', $start_hour) . ':' . sprintf('%02d', $start_minute) . ':00', 'U'); // That may have already passed for today if ($start_time_unix < time()) { if ('weekly' == $sched || 'monthly' == $sched || 'fortnightly' == $sched) { $start_time_unix = $start_time_unix + 86400 * 7; } else { $start_time_unix = $start_time_unix + 86400; } } return $start_time_unix; }
/** * Method to update an order in the database. * @param WC_Order $order */ public function update(&$order) { $order->set_version(WC_VERSION); wp_update_post(array('ID' => $order->get_id(), 'post_date' => date('Y-m-d H:i:s', $order->get_date_created('edit')), 'post_date_gmt' => get_gmt_from_date(date('Y-m-d H:i:s', $order->get_date_created('edit'))), 'post_status' => 'wc-' . ($order->get_status('edit') ? $order->get_status('edit') : apply_filters('woocommerce_default_order_status', 'pending')), 'post_parent' => $order->get_parent_id(), 'post_excerpt' => $this->get_post_excerpt($order))); $this->update_post_meta($order); $order->save_meta_data(); $order->apply_changes(); $this->clear_caches($order); }