本文整理汇总了PHP中wp_unique_post_slug函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_unique_post_slug函数的具体用法?PHP wp_unique_post_slug怎么用?PHP wp_unique_post_slug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_unique_post_slug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: mcs_generate_submit_page
function mcs_generate_submit_page($slug)
{
$current_user = wp_get_current_user();
if (!is_page($slug)) {
$page = array('post_title' => __('Submit Events', 'my-calendar'), 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => $current_user->ID, 'ping_status' => 'closed', 'post_content' => '[submit_event]');
$post_ID = wp_insert_post($page);
$post_slug = wp_unique_post_slug($slug, $post_ID, 'publish', 'page', 0);
wp_update_post(array('ID' => $post_ID, 'post_name' => $post_slug));
} else {
$post = get_page_by_path($slug);
$post_ID = $post->ID;
}
update_option('mcs_submit_id', $post_ID);
return $post_ID;
}
示例3: duplicate
/**
* Perfomr duplicating post/page
* @param object $post
* @param string $status
* @param string $parent_id
* @return int
*/
function duplicate($post, $status = '', $parent_id = '')
{
$prefix = '';
$suffix = '';
$this->old_post_content = $post->post_content;
$this->new_post_content = tf_generate_new_shortcode_ids($post->post_content);
// We don't want to clone revisions
if ($post->post_type == 'revision') {
return;
}
if ($post->post_type != 'attachment') {
$prefix = '';
//$suffix = ' Copy';
$suffix = '';
}
$new_post_author = $this->duplicate_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' => $this->new_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' => $new_post_status = empty($status) ? $post->post_status : $status, 'post_title' => $prefix . $post->post_title . $suffix, 'post_type' => $post->post_type);
$new_post_id = wp_insert_post($new_post);
// apply hook to duplicate action
if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) {
do_action('tf_duplicate_page', $new_post_id, $post);
} else {
do_action('tf_duplicate_post', $new_post_id, $post);
}
// If the copy is published or scheduled, we have to set a proper slug.
if ($new_post_status == 'publish' || $new_post_status == 'future') {
$post_name = wp_unique_post_slug($post->post_name, $new_post_id, $new_post_status, $post->post_type, $new_post_parent);
$new_post = array();
$new_post['ID'] = $new_post_id;
$new_post['post_name'] = $post_name;
// Update the post into the database
wp_update_post($new_post);
}
// set new url
if ($post->post_type == 'page') {
$this->new_url = get_page_link($new_post_id);
} else {
$this->new_url = get_permalink($new_post_id);
}
// check if admin
if ($this->edit_link) {
$this->new_url = get_edit_post_link($new_post_id);
}
return $new_post_id;
}
示例4: create_duplicate
/**
* Create a duplicate from a post
*/
private function create_duplicate($post, $status = '')
{
$prefix = __('Copy', 'newsplus') . ': ';
$suffix = "";
if (!empty($prefix)) {
$prefix .= " ";
}
if (!empty($suffix)) {
$suffix = " " . $suffix;
}
$new_post_author = wp_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_password' => $post->post_password, 'post_status' => $new_post_status = empty($status) ? $post->post_status : $status, 'post_title' => $prefix . $post->post_title . $suffix, 'post_type' => $post->post_type);
$new_post_id = wp_insert_post($new_post);
//copy metas
global $wpdb;
$metas = $wpdb->get_results('SELECT meta_key,meta_value FROM ' . $wpdb->postmeta . ' WHERE post_id=' . $post->ID, ARRAY_A);
if (!empty($metas)) {
foreach ($metas as $value) {
$wpdb->insert($wpdb->postmeta, array('post_id' => $new_post_id, 'meta_key' => $value['meta_key'], 'meta_value' => $value['meta_value']));
}
}
//copy categories
$cats = $wpdb->get_results('SELECT term_taxonomy_id FROM ' . $wpdb->term_relationships . ' WHERE object_id=' . $post->ID, ARRAY_A);
if (!empty($cats)) {
foreach ($cats as $value) {
$wpdb->insert($wpdb->term_relationships, array('object_id' => $new_post_id, 'term_taxonomy_id' => $value['term_taxonomy_id']));
}
}
// If the copy is published or scheduled, we have to set a proper slug.
$post_name = wp_unique_post_slug($post->post_name, $new_post_id, $new_post_status, $post->post_type);
$new_post = array();
$new_post['ID'] = $new_post_id;
$new_post['post_name'] = $post_name;
// Update the post into the database
wp_update_post($new_post);
//reset stat
update_post_meta($new_post_id, 'mail_stat_data', '');
return $new_post_id;
}
示例5: raindrops_unique_entry_title
function raindrops_unique_entry_title($postid = '', $echo = false)
{
global $post;
if (isset($post) && empty($postid)) {
$postid = $post->ID;
} elseif (empty($post)) {
return;
}
$post_object = get_post($postid);
$post_name = $post_object->post_name;
$unique_title = urldecode(wp_unique_post_slug($post_name, $post->ID, 'publish', 'post', 0));
preg_match('!(.+)(-[0-9]+)$!', $unique_title, $regs);
if (isset($regs[2])) {
if (true == $echo) {
echo esc_html($regs[2]);
} else {
return esc_html($regs[2]);
}
}
}
示例6: process_posts
//.........这里部分代码省略.........
} else {
$datetime = explode(' ', $this->values[COL_POST_MODIFIED]);
$date_str = $this->dates_interconv($datetime[0]) . ' ' . $datetime[1];
$time_data = strtotime($date_str);
}
$post['post_date'] = date('Y-m-d H:i:s', $time_data);
$post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $time_data);
$post['post_modified'] = date('Y-m-d H:i:s', $time_data);
$post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $time_data);
}
if ('publish' == $this->values[COL_POST_STATUS]) {
$now = current_time('mysql');
if (mysql2date('U', $post['post_modified'], false) > mysql2date('U', $now, false)) {
$this->values[COL_POST_STATUS] = 'future';
}
} elseif ('future' == $this->values[COL_POST_STATUS]) {
$now = current_time('mysql');
if (mysql2date('U', $post['post_modified'], false) <= mysql2date('U', $now, false)) {
$this->values[COL_POST_STATUS] = 'publish';
}
}
$post['ID'] = $post_id;
$post['post_author'] = !WC2_Utils::is_blank($this->values[COL_POST_AUTHOR]) ? $this->values[COL_POST_AUTHOR] : 1;
$post['post_content'] = $this->convert_encoding($this->values[COL_POST_CONTENT]);
$post['post_title'] = $this->convert_encoding($this->values[COL_POST_TITLE]);
$post['post_excerpt'] = $this->convert_encoding($this->values[COL_POST_EXCERPT]);
$post['post_status'] = $this->values[COL_POST_STATUS];
$post['comment_status'] = !WC2_Utils::is_blank($this->values[COL_POST_COMMENT_STATUS]) ? $this->values[COL_POST_COMMENT_STATUS] : 'close';
$post['ping_status'] = 'close';
$post['post_password'] = 'private' == $post['post_status'] ? '' : $this->values[COL_POST_PASSWORD];
$post['post_type'] = ITEM_POST_TYPE;
$post['post_parent'] = 0;
$post_name = sanitize_title($this->convert_encoding($this->values[COL_POST_NAME]));
$post['post_name'] = wp_unique_post_slug($post_name, $post_id, $post['post_status'], $post['post_type'], $post['post_parent']);
$post['to_ping'] = '';
$post['pinged'] = '';
$post['menu_order'] = 0;
$post['post_content_filtered'] = '';
if (empty($post['post_name']) && !in_array($post['post_status'], array('draft', 'pending', 'auto-draft'))) {
$post['post_name'] = sanitize_title($post['post_title'], $post_id);
}
if ($mode == 'add') {
$post['guid'] = '';
if (false === $wpdb->insert($wpdb->posts, $post)) {
$this->error_log($row, __('This data was not registered in the database.', 'wc2'));
$pre_item_code = $this->values[COL_ITEM_CODE];
$this->create_log();
$this->progress_add();
continue;
}
$post_id = $wpdb->insert_id;
$wc2_item->set_the_post_id($post_id);
$where = array('ID' => $post_id);
$wpdb->update($wpdb->posts, array('guid' => get_permalink($post_id)), $where);
} elseif ($mode == 'upd') {
$where = array('ID' => $post_id);
if (false === $wpdb->update($wpdb->posts, $post, $where)) {
$this->error_log($row, __('The data were not registered with a database.', 'wc2'));
$pre_item_code = $this->values[COL_ITEM_CODE];
$this->create_log();
$this->progress_add();
continue;
}
//delete all metas of Item
$meta_key_table = array();
$cfrows = explode(';', trim($this->values[COL_POST_CUSTOM_FIELD]));
示例7: save
/**
* Saves a doc.
*
* This method handles saving for both new and existing docs. It detects the difference by
* looking for the presence of $this->doc_slug
*
* @since 1.0-beta
*/
function save($args = false)
{
global $bp, $wp_rewrite;
// bbPress plays naughty with revision saving
add_action('pre_post_update', 'wp_save_post_revision');
// Get the required taxonomy items associated with the group. We only run this
// on a save because it requires extra database hits.
$this->setup_terms();
// Set up the default value for the result message
$results = array('message' => __('Unknown error. Please try again.', 'bp-docs'), 'redirect' => 'create');
// Backward compatibility. Had to change to doc_content to work with wp_editor
$doc_content = '';
if (isset($_POST['doc_content'])) {
$doc_content = $_POST['doc_content'];
} else {
if (isset($_POST['doc']['content'])) {
$doc_content = $_POST['doc']['content'];
}
}
// Check group associations
// @todo Move into group integration piece
// This group id is only used to check whether the user can associate the doc with the group.
$associated_group_id = isset($_POST['associated_group_id']) ? intval($_POST['associated_group_id']) : null;
if (bp_is_active('groups')) {
if (!empty($associated_group_id) && !current_user_can('bp_docs_associate_with_group', $associated_group_id)) {
$retval = array('message_type' => 'error', 'message' => __('You are not allowed to associate a Doc with that group.', 'bp-docs'), 'redirect_url' => bp_docs_get_create_link());
return $retval;
}
}
if (empty($_POST['doc']['title'])) {
// The title field is required
$result['message'] = __('The title field is required.', 'bp-docs');
$result['redirect'] = !empty($this->doc_slug) ? 'edit' : 'create';
} else {
$defaults = array('post_type' => $this->post_type_name, 'post_title' => $_POST['doc']['title'], 'post_name' => isset($_POST['doc']['permalink']) ? sanitize_title($_POST['doc']['permalink']) : sanitize_title($_POST['doc']['title']), 'post_content' => sanitize_post_field('post_content', $doc_content, 0, 'db'), 'post_status' => 'publish');
$r = wp_parse_args($args, $defaults);
if (empty($this->doc_slug)) {
$this->is_new_doc = true;
$r['post_author'] = bp_loggedin_user_id();
// If there's a 'doc_id' value in the POST, use
// the autodraft as a starting point
if (isset($_POST['doc_id']) && 0 != $_POST['doc_id']) {
$post_id = (int) $_POST['doc_id'];
$r['ID'] = $post_id;
wp_update_post($r);
} else {
$post_id = wp_insert_post($r);
}
if (!$post_id) {
$result['message'] = __('There was an error when creating the doc.', 'bp-docs');
$result['redirect'] = 'create';
} else {
$this->doc_id = $post_id;
$the_doc = get_post($this->doc_id);
$this->doc_slug = $the_doc->post_name;
// A normal, successful save
$result['message'] = __('Doc successfully created!', 'bp-docs');
$result['redirect'] = 'single';
}
} else {
$this->is_new_doc = false;
$doc = bp_docs_get_current_doc();
$this->doc_id = $doc->ID;
$r['ID'] = $this->doc_id;
// Make sure the post_name is set
if (empty($r['post_name'])) {
$r['post_name'] = sanitize_title($r['post_title']);
}
// Make sure the post_name is unique
$r['post_name'] = wp_unique_post_slug($r['post_name'], $this->doc_id, $r['post_status'], $this->post_type_name, $doc->post_parent);
$this->doc_slug = $r['post_name'];
// Save pre-update post data, for comparison by callbacks.
$this->previous_revision = clone $doc;
if (!wp_update_post($r)) {
$result['message'] = __('There was an error when saving the doc.', 'bp-docs');
$result['redirect'] = 'edit';
} else {
// Remove the edit lock
delete_post_meta($this->doc_id, '_edit_lock');
delete_post_meta($this->doc_id, '_bp_docs_last_pinged');
// When the post has been autosaved, we need to leave a
// special success message
if (!empty($_POST['is_auto']) && $_POST['is_auto']) {
$result['message'] = __('You idled a bit too long while in Edit mode. In order to allow others to edit the doc you were working on, your changes have been autosaved. Click the Edit button to return to Edit mode.', 'bp-docs');
} else {
// A normal, successful save
$result['message'] = __('Doc successfully edited!', 'bp-docs');
}
$result['redirect'] = 'single';
}
$post_id = $this->doc_id;
}
//.........这里部分代码省略.........
示例8: wp_ajax_inline_save
/**
* Ajax handler for Quick Edit saving a post from a list table.
*
* @since 3.1.0
*
* @global WP_List_Table $wp_list_table
*/
function wp_ajax_inline_save()
{
global $wp_list_table, $mode;
check_ajax_referer('inlineeditnonce', '_inline_edit');
if (!isset($_POST['post_ID']) || !($post_ID = (int) $_POST['post_ID'])) {
wp_die();
}
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_ID)) {
wp_die(__('You are not allowed to edit this page.'));
}
} else {
if (!current_user_can('edit_post', $post_ID)) {
wp_die(__('You are not allowed to edit this post.'));
}
}
if ($last = wp_check_post_lock($post_ID)) {
$last_user = get_userdata($last);
$last_user_name = $last_user ? $last_user->display_name : __('Someone');
printf($_POST['post_type'] == 'page' ? __('Saving is disabled: %s is currently editing this page.') : __('Saving is disabled: %s is currently editing this post.'), esc_html($last_user_name));
wp_die();
}
$data =& $_POST;
$post = get_post($post_ID, ARRAY_A);
// Since it's coming from the database.
$post = wp_slash($post);
$data['content'] = $post['post_content'];
$data['excerpt'] = $post['post_excerpt'];
// Rename.
$data['user_ID'] = get_current_user_id();
if (isset($data['post_parent'])) {
$data['parent_id'] = $data['post_parent'];
}
// Status.
if (isset($data['keep_private']) && 'private' == $data['keep_private']) {
$data['visibility'] = 'private';
$data['post_status'] = 'private';
} else {
$data['post_status'] = $data['_status'];
}
if (empty($data['comment_status'])) {
$data['comment_status'] = 'closed';
}
if (empty($data['ping_status'])) {
$data['ping_status'] = 'closed';
}
// Exclude terms from taxonomies that are not supposed to appear in Quick Edit.
if (!empty($data['tax_input'])) {
foreach ($data['tax_input'] as $taxonomy => $terms) {
$tax_object = get_taxonomy($taxonomy);
/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
if (!apply_filters('quick_edit_show_taxonomy', $tax_object->show_in_quick_edit, $taxonomy, $post['post_type'])) {
unset($data['tax_input'][$taxonomy]);
}
}
}
// Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
if (!empty($data['post_name']) && in_array($post['post_status'], array('draft', 'pending'))) {
$post['post_status'] = 'publish';
$data['post_name'] = wp_unique_post_slug($data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent']);
}
// Update the post.
edit_post();
$wp_list_table = _get_list_table('WP_Posts_List_Table', array('screen' => $_POST['screen']));
$mode = $_POST['post_view'] === 'excerpt' ? 'excerpt' : 'list';
$level = 0;
$request_post = array(get_post($_POST['post_ID']));
$parent = $request_post[0]->post_parent;
while ($parent > 0) {
$parent_post = get_post($parent);
$parent = $parent_post->post_parent;
$level++;
}
$wp_list_table->display_rows(array(get_post($_POST['post_ID'])), $level);
wp_die();
}
示例9: duplicate_post_create_duplicate
/**
* Create a duplicate from a posts' instance
*/
function duplicate_post_create_duplicate($post, $status = '')
{
$new_post_author = $this->duplicate_post_get_current_user();
$new_post_status = $status;
if (empty($new_post_status)) {
$new_post_status = $post->post_status;
}
$new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'pinged' => $post->pinged, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_date' => $post->post_date, 'post_date_gmt' => get_gmt_from_date($post->post_date), 'post_excerpt' => $post->post_excerpt, 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => $new_post_status, 'post_title' => $post->post_title, 'post_type' => $post->post_type, 'to_ping' => $post->to_ping);
$new_post_id = wp_insert_post($new_post);
$edit_event_url = esc_attr(admin_url("post.php?post={$new_post_id}&action=edit"));
$message = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf(__('<p>The event <strong>%s</strong> was cloned succesfully. <a href="%s">Edit cloned event</a></p>', AI1EC_PLUGIN_NAME), $post->post_title, $edit_event_url));
$message->set_message_type('updated');
$this->admin_notice_helper->add_renderable_children($message);
// If you have written a plugin which uses non-WP database tables to save
// information about a post you can hook this action to dupe that data.
if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) {
do_action('dp_duplicate_page', $new_post_id, $post);
} else {
do_action('dp_duplicate_post', $new_post_id, $post);
}
delete_post_meta($new_post_id, '_dp_original');
add_post_meta($new_post_id, '_dp_original', $post->ID);
// If the copy gets immediately published, we have to set a proper slug.
if ($new_post_status == 'publish' || $new_post_status == 'future') {
$post_name = wp_unique_post_slug($post->post_name, $new_post_id, $new_post_status, $post->post_type, $post->post_parent);
$new_post = array();
$new_post['ID'] = $new_post_id;
$new_post['post_name'] = $post_name;
// Update the post into the database
wp_update_post($new_post);
}
return $new_post_id;
}
开发者ID:hamid-kamalpour,项目名称:all-in-one-event-calendar,代码行数:36,代码来源:class-ai1ec-duplicate-controller.php
示例10: duplicate
/**
* Create a duplicate from a post
* @see https://wordpress.org/plugins/duplicate-post/
*/
function duplicate($post, $status = 'draft', $parent_id = '')
{
// We don't want to clone revisions
if ($post->post_type == 'revision') {
return;
}
$new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $post->ID, 'post_content' => $post->post_content, 'post_excerpt' => get_option('duplicate_post_copyexcerpt') == '1' ? $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' => $new_post_status = empty($status) ? $post->post_status : $status, 'post_title' => $post->post_title, 'post_type' => $post->post_type);
$new_post_id = wp_insert_post($new_post);
// If the copy is published or scheduled, we have to set a proper slug.
if ($new_post_status == 'publish' || $new_post_status == 'future') {
$post_name = wp_unique_post_slug($post->post_name, $new_post_id, $new_post_status, $post->post_type, $new_post_parent);
$new_post = array('ID' => $new_post_id, 'post_name' => $post_name);
// Update the post into the database
wp_update_post($new_post);
}
// If you have written a plugin which uses non-WP database tables to save
// information about a post you can hook this action to dupe that data.
if ($post->post_type == 'page' || is_post_type_hierarchical($post->post_type)) {
do_action('dp_duplicate_page', $new_post_id, $post);
} else {
do_action('dp_duplicate_post', $new_post_id, $post);
}
delete_post_meta($new_post_id, '_dp_original');
add_post_meta($new_post_id, '_dp_original', $post->ID);
return $new_post_id;
}
示例11: get_sample_permalink
/**
* {@internal Missing Short Description}}
*
* @since 2.5.0
*
* @param int|object $id Post ID or post object.
* @param string $title (optional) Title
* @param string $name (optional) Name
* @return array With two entries of type string
*/
function get_sample_permalink($id, $title = null, $name = null)
{
$post = get_post($id);
if (!$post) {
return array('', '');
}
$ptype = get_post_type_object($post->post_type);
$original_status = $post->post_status;
$original_date = $post->post_date;
$original_name = $post->post_name;
// Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
if (in_array($post->post_status, array('draft', 'pending'))) {
$post->post_status = 'publish';
$post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
}
// If the user wants to set a new name -- override the current one
// Note: if empty name is supplied -- use the title instead, see #6072
if (!is_null($name)) {
$post->post_name = sanitize_title($name ? $name : $title, $post->ID);
}
$post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
$post->filter = 'sample';
$permalink = get_permalink($post, true);
// Replace custom post_type Token with generic pagename token for ease of use.
$permalink = str_replace("%{$post->post_type}%", '%pagename%', $permalink);
// Handle page hierarchy
if ($ptype->hierarchical) {
$uri = get_page_uri($post);
$uri = untrailingslashit($uri);
$uri = strrev(stristr(strrev($uri), '/'));
$uri = untrailingslashit($uri);
$uri = apply_filters('editable_slug', $uri);
if (!empty($uri)) {
$uri .= '/';
}
$permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
}
$permalink = array($permalink, apply_filters('editable_slug', $post->post_name));
$post->post_status = $original_status;
$post->post_date = $original_date;
$post->post_name = $original_name;
unset($post->filter);
return $permalink;
}
示例12: duplicate_post_create_duplicate
/**
* Create a duplicate from a post
*/
function duplicate_post_create_duplicate($post, $status = '', $parent_id = '')
{
if (!duplicate_post_is_post_type_enabled($post->post_type) && $post->post_type != 'attachment') {
wp_die(__('Copy features for this post type are not enabled in options page', 'duplicate-post'));
}
if ($post->post_type != 'attachment') {
$prefix = sanitize_text_field(get_option('duplicate_post_title_prefix'));
$suffix = sanitize_text_field(get_option('duplicate_post_title_suffix'));
$title = ' ';
if (get_option('duplicate_post_copytitle') == 1) {
$title = $post->post_title;
if (!empty($prefix)) {
$prefix .= " ";
}
if (!empty($suffix)) {
$suffix = " " . $suffix;
}
} else {
$title = ' ';
}
$title = trim($prefix . $title . $suffix);
if ($title == '') {
// empty title
$title = __('Untitled');
}
if (get_option('duplicate_post_copystatus') == 0) {
$status = 'draft';
}
}
$new_post_author = wp_get_current_user();
$menu_order = $post->menu_order;
$increase_menu_order_by = get_option('duplicate_post_increase_menu_order_by');
if (!empty($increase_menu_order_by) && is_numeric($increase_menu_order_by)) {
$menu_order += intval($increase_menu_order_by);
}
$new_post = array('menu_order' => $menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => get_option('duplicate_post_copycontent') == '1' ? addslashes($post->post_content) : "", 'post_content_filtered' => get_option('duplicate_post_copycontent') == '1' ? addslashes($post->post_content_filtered) : "", 'post_excerpt' => get_option('duplicate_post_copyexcerpt') == '1' ? addslashes($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' => get_option('duplicate_post_copypassword') == '1' ? $post->post_password : "", 'post_status' => $new_post_status = empty($status) ? $post->post_status : $status, 'post_title' => addslashes($title), 'post_type' => $post->post_type);
if (get_option('duplicate_post_copydate') == 1) {
$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);
// If the copy is published or scheduled, we have to set a proper slug.
if ($new_post_status == 'publish' || $new_post_status == 'future') {
$post_name = $post->post_name;
if (get_option('duplicate_post_copyslug') != 1) {
$post_name = '';
}
$post_name = wp_unique_post_slug($post_name, $new_post_id, $new_post_status, $post->post_type, $new_post_parent);
$new_post = array();
$new_post['ID'] = $new_post_id;
$new_post['post_name'] = $post_name;
// Update the post into the database
wp_update_post($new_post);
}
// If you have written a plugin which uses non-WP database tables to save
// information about a post you can hook this action to dupe that data.
if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) {
do_action('dp_duplicate_page', $new_post_id, $post);
} else {
do_action('dp_duplicate_post', $new_post_id, $post);
}
delete_post_meta($new_post_id, '_dp_original');
add_post_meta($new_post_id, '_dp_original', $post->ID);
return $new_post_id;
}
示例13: update_product_actions
function update_product_actions()
{
$nonce = filter_input(INPUT_POST, 'wcml_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (!$nonce || !wp_verify_nonce($nonce, 'update_product_actions')) {
echo json_encode(array('error' => __('Invalid nonce', 'wpml-wcml')));
die;
}
global $woocommerce_wpml, $sitepress, $wpdb, $sitepress_settings, $iclTranslationManagement;
//get post values
$data = array();
$records = $_POST['records'];
parse_str($records, $data);
$original_product_id = filter_input(INPUT_POST, 'product_id', FILTER_SANITIZE_NUMBER_INT);
$job_id = filter_input(INPUT_POST, 'job_id', FILTER_SANITIZE_NUMBER_INT);
$language = filter_input(INPUT_POST, 'language', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$orig_product = get_post($original_product_id);
if (!$data['title_' . $language]) {
echo json_encode(array('error' => __('Title missing', 'wpml-wcml')));
die;
}
$languages = $sitepress->get_active_languages();
$product_trid = $sitepress->get_element_trid($original_product_id, 'post_' . $orig_product->post_type);
$tr_product_id = apply_filters('translate_object_id', $original_product_id, 'product', false, $language);
if (get_magic_quotes_gpc()) {
foreach ($data as $key => $data_item) {
if (!is_array($data_item)) {
$data[$key] = stripslashes($data_item);
}
}
}
if (is_null($tr_product_id)) {
//insert new post
$args = array();
$args['post_title'] = $data['title_' . $language];
$args['post_type'] = $orig_product->post_type;
$args['post_content'] = $data['content_' . $language];
$args['post_excerpt'] = $data['excerpt_' . $language];
$args['post_status'] = $orig_product->post_status;
$args['menu_order'] = $orig_product->menu_order;
$args['ping_status'] = $orig_product->ping_status;
$args['comment_status'] = $orig_product->comment_status;
$product_parent = apply_filters('translate_object_id', $orig_product->post_parent, 'product', false, $language);
$args['post_parent'] = is_null($product_parent) ? 0 : $product_parent;
$_POST['to_lang'] = $language;
if ($woocommerce_wpml->settings['products_sync_date']) {
$args['post_date'] = $orig_product->post_date;
}
$tr_product_id = wp_insert_post($args);
$translation_id = $wpdb->get_var($wpdb->prepare("SELECT translation_id\r\n FROM {$wpdb->prefix}icl_translations\r\n WHERE element_type=%s AND trid=%d AND language_code=%s AND element_id IS NULL ", "post_product", $product_trid, $language));
if ($translation_id) {
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_translations WHERE element_id=%d AND trid=%d", $tr_product_id, $product_trid));
$wpdb->update($wpdb->prefix . 'icl_translations', array('element_id' => $tr_product_id), array('translation_id' => $translation_id));
$iclTranslationManagement->update_translation_status(array('status' => ICL_TM_COMPLETE, 'needs_update' => 0, 'translation_id' => $translation_id, 'translator_id' => get_current_user_id()));
} else {
$sitepress->set_element_language_details($tr_product_id, 'post_' . $orig_product->post_type, $product_trid, $language);
}
$this->duplicate_product_post_meta($original_product_id, $tr_product_id, $data, true);
} else {
//update post
$args = array();
$args['ID'] = $tr_product_id;
$args['post_title'] = $data['title_' . $language];
$args['post_content'] = $data['content_' . $language];
$args['post_excerpt'] = $data['excerpt_' . $language];
$args['post_status'] = $orig_product->post_status;
$args['ping_status'] = $orig_product->ping_status;
$args['comment_status'] = $orig_product->comment_status;
$product_parent = apply_filters('translate_object_id', $orig_product->post_parent, 'product', false, $language);
$args['post_parent'] = is_null($product_parent) ? 0 : $product_parent;
$_POST['to_lang'] = $language;
wp_update_post($args);
$post_name = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} WHERE ID=%d", $tr_product_id));
if (isset($data['post_name_' . $language]) && $post_name != $data['post_name_' . $language]) {
// update post_name
// need set POST variable ( WPML used them when filtered this function)
$new_post_name = sanitize_title($data['post_name_' . $language] ? $data['post_name_' . $language] : $data['title_' . $language]);
$_POST['new_title'] = $data['title_' . $language];
$_POST['new_slug'] = $new_post_name;
$new_slug = wp_unique_post_slug($new_post_name, $tr_product_id, $orig_product->post_status, $orig_product->post_type, $args['post_parent']);
$wpdb->update($wpdb->posts, array('post_name' => $new_slug), array('ID' => $tr_product_id));
}
$sitepress->set_element_language_details($tr_product_id, 'post_' . $orig_product->post_type, $product_trid, $language);
$this->duplicate_product_post_meta($original_product_id, $tr_product_id, $data);
}
do_action('wcml_update_extra_fields', $tr_product_id, $data, $language);
do_action('wcml_before_sync_product_data', $original_product_id, $tr_product_id, $language);
$this->sync_product_attr($original_product_id, $tr_product_id, $language, $data);
$this->sync_default_product_attr($original_product_id, $tr_product_id, $language);
$wpml_media_options = maybe_unserialize(get_option('_wpml_media'));
//sync media
if ($wpml_media_options['new_content_settings']['duplicate_featured']) {
//sync feature image
$this->sync_thumbnail_id($original_product_id, $tr_product_id, $language);
}
if ($wpml_media_options['new_content_settings']['duplicate_media']) {
//sync product gallery
$this->sync_product_gallery($original_product_id);
}
//sync taxonomies
$this->sync_product_taxonomies($original_product_id, $tr_product_id, $language);
//.........这里部分代码省略.........
示例14: mc_generate_calendar_page
function mc_generate_calendar_page($slug)
{
global $current_user;
get_currentuserinfo();
if (!is_page($slug)) {
$page = array('post_title' => __('My Calendar', 'my-calendar'), 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => $current_user->ID, 'ping_status' => 'closed', 'post_content' => '[my_calendar]');
$post_ID = wp_insert_post($page);
$post_slug = wp_unique_post_slug($slug, $post_ID, 'publish', 'page', 0);
wp_update_post(array('ID' => $post_ID, 'post_name' => $post_slug));
} else {
$post = get_page_by_path($slug);
$post_ID = $post->ID;
}
update_option('mc_uri', get_permalink($post_ID));
update_option('mc_uri_id', $post_ID);
return $post_ID;
}
示例15: _duplicate_post_copy_attachments
/**
* Copy the attachments
* It simply copies the table entries, actual file won't be duplicated
*/
protected function _duplicate_post_copy_attachments($new_id, $post)
{
//if (get_option('duplicate_post_copyattachments') == 0) return;
// get old attachments
$attachments = get_posts(array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID));
// clone old attachments
foreach ($attachments as $att) {
$new_att_author = $this->_duplicate_post_get_current_user();
$new_att = array('menu_order' => $att->menu_order, 'comment_status' => $att->comment_status, 'guid' => $att->guid, 'ping_status' => $att->ping_status, 'pinged' => $att->pinged, 'post_author' => $new_att_author->ID, 'post_content' => $att->post_content, 'post_date' => $att->post_date, 'post_date_gmt' => get_gmt_from_date($att->post_date), 'post_excerpt' => $att->post_excerpt, 'post_mime_type' => $att->post_mime_type, 'post_parent' => $new_id, 'post_password' => $att->post_password, 'post_status' => $this->_get_new_post_status($att->post_status), 'post_title' => $att->post_title, 'post_type' => $att->post_type, 'to_ping' => $att->to_ping);
$new_att_id = wp_insert_post($new_att);
// get and apply a unique slug
$att_name = wp_unique_post_slug($att->post_name, $new_att_id, $att->post_status, $att->post_type, $new_id);
$new_att = array();
$new_att['ID'] = $new_att_id;
$new_att['post_name'] = $att_name;
wp_update_post($new_att);
}
}