本文整理汇总了PHP中unstick_post函数的典型用法代码示例。如果您正苦于以下问题:PHP unstick_post函数的具体用法?PHP unstick_post怎么用?PHP unstick_post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unstick_post函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toggle_sticky_state
public function toggle_sticky_state($sticky)
{
if (!$this->validate_request()) {
exit;
}
$success = false;
$res = array();
if (isset($_GET['note_id'])) {
$note_id = (int) $_GET['note_id'];
$note_post = get_post($note_id);
if ($note_post && $note_post->post_type == $this->note_post_type) {
if ($sticky) {
stick_post($note_id);
} else {
unstick_post($note_id);
}
$success = true;
$note_obj = new USIN_Note($note_id);
$user_id = $note_obj->get_note_user();
$all_notes = USIN_Note::get_all($user_id);
$res['notes'] = $all_notes;
}
}
$res['success'] = $success;
echo json_encode($res);
exit;
}
示例2: pw_esp_unstick
/**
* Unstick Posts
*
* @access public
* @since 1.0
* @return void
*/
function pw_esp_unstick($title = '', $post_id = 0)
{
if (pw_esp_is_expired($post_id)) {
// Post is expired so unstick
unstick_post($post_id);
}
return $title;
}
示例3: unsticky_unstick
function unsticky_unstick()
{
$args = array('post__in' => get_option('sticky_posts'));
$stickyQuery = get_posts($args);
error_log($stickyQuery);
foreach ($stickyQuery as $id) {
$timeToUnstick = get_post_meta($id, '_unsticky_time', true);
error_log(print_r($timeToUnstick));
if ($timeToUnstick < time()) {
unstick_post($id);
}
}
}
示例4: wp_delete_post
/**
* Trashes or deletes a post or page.
*
* When the post and page is permanently deleted, everything that is tied to it is deleted also.
* This includes comments, post meta fields, and terms associated with the post.
*
* The post or page is moved to trash instead of permanently deleted unless trash is
* disabled, item is already in the trash, or $force_delete is true.
*
* @since 1.0.0
* @uses do_action() on 'delete_post' before deletion unless post type is 'attachment'.
* @uses do_action() on 'deleted_post' after deletion unless post type is 'attachment'.
* @uses wp_delete_attachment() if post type is 'attachment'.
* @uses wp_trash_post() if item should be trashed.
*
* @param int $postid Post ID.
* @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false.
* @return mixed False on failure
*/
function wp_delete_post($postid = 0, $force_delete = false)
{
global $wpdb, $wp_rewrite;
if (!($post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", $postid)))) {
return $post;
}
if (!$force_delete && ($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS) {
return wp_trash_post($postid);
}
if ($post->post_type == 'attachment') {
return wp_delete_attachment($postid, $force_delete);
}
do_action('delete_post', $postid);
delete_post_meta($postid, '_wp_trash_meta_status');
delete_post_meta($postid, '_wp_trash_meta_time');
wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type));
$parent_data = array('post_parent' => $post->post_parent);
$parent_where = array('post_parent' => $postid);
if ('page' == $post->post_type) {
// if the page is defined in option page_on_front or post_for_posts,
// adjust the corresponding options
if (get_option('page_on_front') == $postid) {
update_option('show_on_front', 'posts');
delete_option('page_on_front');
}
if (get_option('page_for_posts') == $postid) {
delete_option('page_for_posts');
}
// Point children of this page to its parent, also clean the cache of affected children
$children_query = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_parent = %d AND post_type='page'", $postid);
$children = $wpdb->get_results($children_query);
$wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => 'page'));
} else {
unstick_post($postid);
}
// Do raw query. wp_get_post_revisions() is filtered
$revision_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = 'revision'", $postid));
// Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
foreach ($revision_ids as $revision_id) {
wp_delete_post_revision($revision_id);
}
// Point all attachments to this post up one level
$wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => 'attachment'));
$comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = %d", $postid));
if (!empty($comment_ids)) {
do_action('delete_comment', $comment_ids);
foreach ($comment_ids as $comment_id) {
wp_delete_comment($comment_id, true);
}
do_action('deleted_comment', $comment_ids);
}
$post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d ", $postid));
if (!empty($post_meta_ids)) {
do_action('delete_postmeta', $post_meta_ids);
$in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_id IN({$in_post_meta_ids})");
do_action('deleted_postmeta', $post_meta_ids);
}
do_action('delete_post', $postid);
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->posts} WHERE ID = %d", $postid));
do_action('deleted_post', $postid);
if ('page' == $post->post_type) {
clean_page_cache($postid);
foreach ((array) $children as $child) {
clean_page_cache($child->ID);
}
$wp_rewrite->flush_rules(false);
} else {
clean_post_cache($postid);
}
wp_clear_scheduled_hook('publish_future_post', array($postid));
do_action('deleted_post', $postid);
return $post;
}
示例5: callback
/**
* Main AJAX callback
*
* @param object The post fragment object
*/
function callback($post_data)
{
if (!property_exists($post_data, 'postID') || !property_exists($post_data, 'isSticky')) {
self::die_failure('invalid_message', __('Insufficient information provided.', 'o2'));
}
$post = get_post(absint($post_data->postID));
if (!$post) {
self::die_failure('post_not_found', __('Post not found.', 'o2'));
}
if (!current_user_can('edit_post', $post->ID)) {
self::die_failure('cannot_edit_post_sticky', __('You are not allowed to edit this post sticky.', 'o2'));
}
if ($post_data->isSticky) {
stick_post($post->ID);
} else {
unstick_post($post->ID);
}
// Bump the post to make it update in polling
o2_Fragment::bump_post($post->ID);
$retval = array('isSticky' => is_sticky($post->ID));
self::die_success($retval);
}
示例6: bulk_edit_posts
//.........这里部分代码省略.........
if (is_array($post_data['post_category']) && !empty($post_data['post_category'])) {
$new_cats = array_map('absint', $post_data['post_category']);
} else {
unset($post_data['post_category']);
}
}
$tax_input = array();
if (isset($post_data['tax_input'])) {
foreach ($post_data['tax_input'] as $tax_name => $terms) {
if (empty($terms)) {
continue;
}
if (is_taxonomy_hierarchical($tax_name)) {
$tax_input[$tax_name] = array_map('absint', $terms);
} else {
$comma = _x(',', 'tag delimiter');
if (',' !== $comma) {
$terms = str_replace($comma, ',', $terms);
}
$tax_input[$tax_name] = explode(',', trim($terms, " \n\t\r\v,"));
}
}
}
if (isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent'])) {
$pages = $wpdb->get_results("SELECT ID, post_parent FROM {$wpdb->posts} WHERE post_type = 'page'");
$children = array();
for ($i = 0; $i < 50 && $parent > 0; $i++) {
$children[] = $parent;
foreach ($pages as $page) {
if ($page->ID == $parent) {
$parent = $page->post_parent;
break;
}
}
}
}
$updated = $skipped = $locked = array();
$shared_post_data = $post_data;
foreach ($post_IDs as $post_ID) {
// Start with fresh post data with each iteration.
$post_data = $shared_post_data;
$post_type_object = get_post_type_object(get_post_type($post_ID));
if (!isset($post_type_object) || isset($children) && in_array($post_ID, $children) || !current_user_can('edit_post', $post_ID)) {
$skipped[] = $post_ID;
continue;
}
if (wp_check_post_lock($post_ID)) {
$locked[] = $post_ID;
continue;
}
$post = get_post($post_ID);
$tax_names = get_object_taxonomies($post);
foreach ($tax_names as $tax_name) {
$taxonomy_obj = get_taxonomy($tax_name);
if (isset($tax_input[$tax_name]) && current_user_can($taxonomy_obj->cap->assign_terms)) {
$new_terms = $tax_input[$tax_name];
} else {
$new_terms = array();
}
if ($taxonomy_obj->hierarchical) {
$current_terms = (array) wp_get_object_terms($post_ID, $tax_name, array('fields' => 'ids'));
} else {
$current_terms = (array) wp_get_object_terms($post_ID, $tax_name, array('fields' => 'names'));
}
$post_data['tax_input'][$tax_name] = array_merge($current_terms, $new_terms);
}
if (isset($new_cats) && in_array('category', $tax_names)) {
$cats = (array) wp_get_post_categories($post_ID);
$post_data['post_category'] = array_unique(array_merge($cats, $new_cats));
unset($post_data['tax_input']['category']);
}
$post_data['post_type'] = $post->post_type;
$post_data['post_mime_type'] = $post->post_mime_type;
$post_data['guid'] = $post->guid;
foreach (array('comment_status', 'ping_status', 'post_author') as $field) {
if (!isset($post_data[$field])) {
$post_data[$field] = $post->{$field};
}
}
$post_data['ID'] = $post_ID;
$post_data['post_ID'] = $post_ID;
$post_data = _wp_translate_postdata(true, $post_data);
if (is_wp_error($post_data)) {
$skipped[] = $post_ID;
continue;
}
$updated[] = wp_update_post($post_data);
if (isset($post_data['sticky']) && current_user_can($ptype->cap->edit_others_posts)) {
if ('sticky' == $post_data['sticky']) {
stick_post($post_ID);
} else {
unstick_post($post_ID);
}
}
if (isset($post_data['post_format'])) {
set_post_format($post_ID, $post_data['post_format']);
}
}
return array('updated' => $updated, 'skipped' => $skipped, 'locked' => $locked);
}
示例7: _toggle_sticky
/**
* Encapsulate the logic for sticking a post
* and determining if the user has permission to do so
*
* @since 4.3.0
* @access private
*
* @param array $post_data
* @param bool $update
* @return void|IXR_Error
*/
private function _toggle_sticky($post_data, $update = false)
{
$post_type = get_post_type_object($post_data['post_type']);
// Private and password-protected posts cannot be stickied.
if ('private' === $post_data['post_status'] || !empty($post_data['post_password'])) {
// Error if the client tried to stick the post, otherwise, silently unstick.
if (!empty($post_data['sticky'])) {
return new IXR_Error(401, __('Sorry, you cannot stick a private post.'));
}
if ($update) {
unstick_post($post_data['ID']);
}
} elseif (isset($post_data['sticky'])) {
if (!current_user_can($post_type->cap->edit_others_posts)) {
return new IXR_Error(401, __('Sorry, you are not allowed to stick this post.'));
}
$sticky = wp_validate_boolean($post_data['sticky']);
if ($sticky) {
stick_post($post_data['ID']);
} else {
unstick_post($post_data['ID']);
}
}
}
示例8: wpsc_insert_product
/**
* wpsc_insert_product function
*
* @param unknown
* @return unknown
*/
function wpsc_insert_product($post_data, $wpsc_error = false)
{
global $wpdb, $user_ID;
$adding = false;
$update = false;
$product_columns = array('name' => '', 'description' => '', 'additional_description' => '', 'price' => null, 'weight' => null, 'weight_unit' => '', 'pnp' => null, 'international_pnp' => null, 'file' => null, 'image' => '0', 'quantity_limited' => '', 'quantity' => null, 'special' => null, 'special_price' => null, 'display_frontpage' => null, 'notax' => null, 'publish' => null, 'active' => null, 'donation' => null, 'no_shipping' => null, 'thumbnail_image' => null, 'thumbnail_state' => null);
foreach ($product_columns as $column => $default) {
if (!isset($post_data[$column])) {
$post_data[$column] = '';
}
if ($post_data[$column] !== null) {
$update_values[$column] = stripslashes($post_data[$column]);
} else {
if ($update != true && $default !== null) {
$update_values[$column] = stripslashes($default);
}
}
}
$product_post_values = array('post_author' => $user_ID, 'post_content' => $post_data['description'], 'post_excerpt' => $post_data['additional_description'], 'post_title' => $post_data['name'], 'post_status' => $post_data['post_status'], 'post_type' => "wpsc-product", 'post_name' => sanitize_title($post_data['name']));
$product_post_values["comment_status"] = "open";
if (isset($sku) && $sku != '') {
$product_post_array['guid'] = $sku;
}
$product_id = wp_insert_post($product_post_values);
if (isset($post_data["sticky"])) {
stick_post($product_id);
} else {
unstick_post($product_id);
}
if ($product_id == 0) {
if ($wp_error) {
return new WP_Error('db_insert_error', __('Could not insert product into the database', 'wpsc'), $wpdb->last_error);
} else {
return 0;
}
}
$adding = true;
// if we succeed, we can do further editing
// and the meta
wpsc_update_product_meta($product_id, $post_data['meta']);
do_action('wpsc_edit_product', $product_id);
return $product_id;
}
示例9: cp_add_new_listing
function cp_add_new_listing($advals, $renew_id = false)
{
global $wpdb, $cp_options;
$new_tags = '';
$ad_length = '';
$attach_id = '';
$the_attachment = '';
// check to see if html is allowed
if (!$cp_options->allow_html) {
$post_content = appthemes_filter($advals['post_content']);
} else {
$post_content = wp_kses_post($advals['post_content']);
}
// tags are tricky and need to be put into an array before saving the ad
if (!empty($advals['tags_input'])) {
$new_tags = explode(',', $advals['tags_input']);
}
// put all the new ad elements into an array
// these are the minimum required fields for WP (except tags)
$new_ad = array();
$new_ad['post_title'] = appthemes_filter($advals['post_title']);
$new_ad['post_content'] = trim($post_content);
$new_ad['post_status'] = 'pending';
// no longer setting final status until after images are set
$new_ad['post_author'] = $advals['user_id'];
$new_ad['post_type'] = APP_POST_TYPE;
if ($renew_id) {
$new_ad['ID'] = $renew_id;
$new_ad['post_date'] = current_time('mysql');
$new_ad['post_date_gmt'] = current_time('mysql', 1);
$post_id = wp_update_post($new_ad);
} else {
// insert the new ad
$post_id = wp_insert_post($new_ad);
}
//set the custom post type categories
wp_set_post_terms($post_id, appthemes_filter($advals['cat']), APP_TAX_CAT, false);
//set the custom post type tags
wp_set_post_terms($post_id, $new_tags, APP_TAX_TAG, false);
// the unique order ID we created becomes the ad confirmation ID
// we will use this for payment systems and for activating the ad
// later if need be. it needs to start with cp_ otherwise it won't
// be loaded in with the ad so let's give it a new name
$advals['cp_sys_ad_conf_id'] = $advals['oid'];
// get the ad duration and first see if ad packs are being used
// if so, get the length of time in days otherwise use the default
// prune period defined on the CP settings page
if (isset($advals['pack_duration'])) {
$ad_length = $advals['pack_duration'];
} else {
$ad_length = $cp_options->prun_period;
}
// set the ad listing expiration date and put into a session
$ad_expire_date = appthemes_mysql_date(current_time('mysql'), $ad_length);
$advals['cp_sys_expire_date'] = $ad_expire_date;
$advals['cp_sys_ad_duration'] = $ad_length;
// if renew ad - delete all old post meta and unmark ad as featured
if ($renew_id) {
unstick_post($renew_id);
$custom_field_keys = get_post_custom_keys($renew_id);
foreach ($custom_field_keys as $custom_key) {
delete_post_meta($renew_id, $custom_key);
}
}
// now add all the custom fields into WP post meta fields
foreach ($advals as $meta_key => $meta_value) {
if (appthemes_str_starts_with($meta_key, 'cp_') && !is_array($advals[$meta_key])) {
add_post_meta($post_id, $meta_key, wp_kses_post($meta_value), true);
}
if (appthemes_str_starts_with($meta_key, 'cp_') && is_array($advals[$meta_key])) {
foreach ($advals[$meta_key] as $checkbox_value) {
add_post_meta($post_id, $meta_key, wp_kses_post($checkbox_value));
}
}
}
// if they checked the box for a featured ad, then make the post sticky
if (isset($advals['featured_ad'])) {
stick_post($post_id);
}
if (isset($advals['attachment'])) {
$the_attachment = $advals['attachment'];
// associate the already uploaded images to the new ad and create multiple image sizes
$attach_id = cp_associate_images($post_id, $the_attachment, true);
}
if (isset($advals['app_attach_id'])) {
$attachments = $advals['app_attach_id'];
$titles = isset($advals['app_attach_title']) ? $advals['app_attach_title'] : array();
// associate the already uploaded images to the new ad and update titles
$attach_id = appthemes_plupload_associate_images($post_id, $attachments, $titles, true);
}
// set the thumbnail pic on the WP post
//cp_set_ad_thumbnail($post_id, $attach_id);
//last step is to publish the ad when its appropriate to publish immediately
$final_status = cp_set_post_status($advals);
if ($final_status == 'publish') {
$final_post = array();
$final_post['ID'] = $post_id;
$final_post['post_status'] = $final_status;
$update_result = wp_update_post($final_post);
}
//.........这里部分代码省略.........
示例10: update_item
/**
* Update a single post.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function update_item($request)
{
$id = (int) $request['id'];
$post = get_post($id);
if (empty($id) || empty($post->ID) || $this->post_type !== $post->post_type) {
return new WP_Error('rest_post_invalid_id', __('Post id is invalid.'), array('status' => 400));
}
$post = $this->prepare_item_for_database($request);
if (is_wp_error($post)) {
return $post;
}
// convert the post object to an array, otherwise wp_update_post will expect non-escaped input
$post_id = wp_update_post((array) $post, true);
if (is_wp_error($post_id)) {
if (in_array($post_id->get_error_code(), array('db_update_error'))) {
$post_id->add_data(array('status' => 500));
} else {
$post_id->add_data(array('status' => 400));
}
return $post_id;
}
$schema = $this->get_item_schema();
if (!empty($schema['properties']['format']) && !empty($request['format'])) {
set_post_format($post, $request['format']);
}
if (!empty($schema['properties']['featured_image']) && isset($request['featured_image'])) {
$this->handle_featured_image($request['featured_image'], $post_id);
}
if (!empty($schema['properties']['sticky']) && isset($request['sticky'])) {
if (!empty($request['sticky'])) {
stick_post($post_id);
} else {
unstick_post($post_id);
}
}
if (!empty($schema['properties']['template']) && isset($request['template'])) {
$this->handle_template($request['template'], $post->ID);
}
$this->update_additional_fields_for_object(get_post($post_id), $request);
/**
* @TODO: Enable rest_insert_post() action after.
* Media Controller has been migrated to new style.
*
* do_action( 'rest_insert_post', $post, $request );
*/
/* This action is documented in lib/endpoints/class-wp-rest-controller.php */
do_action('rest_insert_post', $post, $request, false);
return $this->get_item(array('id' => $post_id, 'context' => 'edit'));
}
示例11: save_post
//.........这里部分代码省略.........
wp_set_object_terms($new_post_id, array(), $source_post_taxonomy);
}
}
// Get a list of cats that the target blog has.
$target_blog_terms = $this->get_current_blog_taxonomy_terms($source_post_taxonomy);
// Go through the original post's terms and compare each slug with the slug of the target terms.
$taxonomies_to_add_to = array();
$have_created_taxonomies = false;
foreach ($source_post_terms as $source_post_term) {
$found = false;
$source_slug = $source_post_term->slug;
foreach ($target_blog_terms as $target_blog_term) {
if ($target_blog_term['slug'] == $source_slug) {
$found = true;
$taxonomies_to_add_to[$target_blog_term['term_id']] = intval($target_blog_term['term_id']);
break;
}
}
// Should we create the taxonomy if it doesn't exist?
if (!$found && $taxonomies_create) {
$new_taxonomy = wp_insert_term($source_post_term->name, $source_post_taxonomy, array('slug' => $source_post_term->slug, 'description' => $source_post_term->description));
$taxonomies_to_add_to[] = $source_post_term->slug;
$have_created_taxonomies = true;
}
}
if ($taxonomies_create) {
$this->sync_terms($source_post_taxonomy, $original_blog, $blogID);
}
if (count($taxonomies_to_add_to) > 0) {
wp_set_object_terms($new_post_id, $taxonomies_to_add_to, $source_post_taxonomy);
}
}
}
/**
Remove the current attachments.
*/
$attachments_to_remove =& get_children('post_parent=' . $new_post_id . '&post_type=attachment');
foreach ($attachments_to_remove as $attachment_to_remove) {
wp_delete_attachment($attachment_to_remove->ID);
}
foreach ($attachment_data as $key => $attached_file) {
if ($key != 'thumbnail') {
$this->copy_attachment($attached_file, $new_post_id);
}
}
if ($custom_fields) {
// Remove all old custom fields.
$old_custom_fields = get_post_custom($new_post_id);
foreach ($old_custom_fields as $key => $value) {
// This post has a featured image! Remove it from disk!
if ($key == '_thumbnail_id') {
$thumbnail_post = $value[0];
wp_delete_post($thumbnail_post);
}
delete_post_meta($new_post_id, $key);
}
foreach ($post_custom_fields as $meta_key => $meta_value) {
if (is_array($meta_value)) {
foreach ($meta_value as $single_meta_value) {
$single_meta_value = maybe_unserialize($single_meta_value);
add_post_meta($new_post_id, $meta_key, $single_meta_value);
}
} else {
$meta_value = maybe_unserialize($meta_value);
add_post_meta($new_post_id, $meta_key, $meta_value);
}
}
// Attached files are custom fields... but special custom fields. Therefore they need special treatment. Like retards. Retarded files.
if ($has_thumbnail) {
$new_attachment_id = $this->copy_attachment($attachment_data['thumbnail'], $new_post_id);
if ($new_attachment_id !== false) {
update_post_meta($new_post_id, '_thumbnail_id', $new_attachment_id);
}
}
}
// Sticky behaviour
$child_post_is_sticky = is_sticky($new_post_id);
if ($post_is_sticky && !$child_post_is_sticky) {
stick_post($new_post_id);
}
if (!$post_is_sticky && $child_post_is_sticky) {
unstick_post($new_post_id);
}
if ($link) {
$new_post_broadcast_data = $this->get_post_broadcast_data($blog_id, $new_post_id);
$new_post_broadcast_data->set_linked_parent($original_blog, $post_id);
$this->set_post_broadcast_data($blogID, $new_post_id, $new_post_broadcast_data);
}
$to_broadcasted_blogs[] = '<a href="' . get_permalink($new_post_id) . '">' . get_bloginfo('name') . '</a>';
restore_current_blog();
}
// Finished broadcasting.
$this->broadcasting = false;
$post_url_and_name = '<a href="' . get_permalink($post_id) . '">' . $post['post_title'] . '</a>';
do_action('threewp_activity_monitor_new_activity', array('activity_id' => '3broadcast_broadcasted', 'activity_strings' => array('' => '%user_display_name_with_link% has broadcasted ' . $post_url_and_name . ' to: ' . implode(', ', $to_broadcasted_blogs))));
// Save the post broadcast data.
if ($link) {
$this->set_post_broadcast_data($blog_id, $post_id, $broadcast_data);
}
}
示例12: save_post_translation
function save_post_translation($translation_id, $translation)
{
global $wpdb, $sitepress_settings, $sitepress, $icl_adjust_id_url_filter_off;
$icl_adjust_id_url_filter_off = true;
$translation_info = $wpdb->get_row($wpdb->prepare("\n SELECT * FROM {$wpdb->prefix}icl_translations tr\n JOIN {$wpdb->prefix}icl_translation_status ts ON ts.translation_id = tr.translation_id\n WHERE tr.translation_id=%d", $translation_id));
$lang_code = $translation_info->language_code;
$trid = $translation_info->trid;
$original_post_details = $wpdb->get_row("\n SELECT p.post_author, p.post_type, p.post_status, p.comment_status, p.ping_status, p.post_parent, p.menu_order, p.post_date, t.language_code\n FROM {$wpdb->prefix}icl_translations t \n JOIN {$wpdb->posts} p ON t.element_id = p.ID AND CONCAT('post_',p.post_type) = t.element_type\n WHERE trid='{$trid}' AND p.ID = '{$translation['original_id']}'\n ");
//is the original post a sticky post?
$sticky_posts = get_option('sticky_posts');
$is_original_sticky = $original_post_details->post_type == 'post' && in_array($translation['original_id'], $sticky_posts);
$this->_content_fix_image_paths_in_body($translation);
$this->_content_fix_relative_link_paths_in_body($translation);
$this->_content_decode_shortcodes($translation);
// handle the page parent and set it to the translated parent if we have one.
if ($original_post_details->post_parent) {
$post_parent_trid = $wpdb->get_var($wpdb->prepare("\tSELECT trid\n\t\t\t\t\t\tFROM {$wpdb->prefix}icl_translations\n\t\t\t\t\t\tWHERE element_type= %s AND element_id = %d ", 'post_' . $original_post_details->post_type, $original_post_details->post_parent));
if ($post_parent_trid) {
$parent_id = $wpdb->get_var($wpdb->prepare("SELECT element_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM {$wpdb->prefix}icl_translations\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE element_type = %s\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND trid = %d\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND language_code = %s ", 'post_' . $original_post_details->post_type, $post_parent_trid, $lang_code));
}
}
// determine post id based on trid
$post_id = $translation_info->element_id;
if ($post_id) {
// see if the post really exists - make sure it wasn't deleted while the plugin was
if (!$wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE ID = %d ", $post_id))) {
$is_update = false;
$q = "DELETE FROM {$wpdb->prefix}icl_translations WHERE element_type=%s AND element_id=%d";
$q_prepared = $wpdb->prepare($q, array('post_' . $original_post_details->post_type, $post_id));
$wpdb->query($q_prepared);
} else {
$is_update = true;
$postarr['ID'] = $_POST['post_ID'] = $post_id;
}
} else {
$is_update = false;
}
$postarr['post_title'] = $translation['title'];
if ($sitepress_settings['translated_document_page_url'] == 'translate' && isset($translation['URL'])) {
$postarr['post_name'] = $translation['URL'];
}
$postarr['post_content'] = $translation['body'];
if (isset($translation['excerpt']) && $translation['excerpt'] != "") {
$postarr['post_excerpt'] = $translation['excerpt'];
}
if (isset($translated_taxonomies) && is_array($translated_taxonomies)) {
foreach ($translated_taxonomies as $taxonomy => $values) {
$postarr['tax_input'][$taxonomy] = join(',', (array) $values);
}
}
$postarr['post_author'] = $original_post_details->post_author;
$postarr['post_type'] = $original_post_details->post_type;
if ($sitepress_settings['sync_comment_status']) {
$postarr['comment_status'] = $original_post_details->comment_status;
}
if ($sitepress_settings['sync_ping_status']) {
$postarr['ping_status'] = $original_post_details->ping_status;
}
if ($sitepress_settings['sync_page_ordering']) {
$postarr['menu_order'] = $original_post_details->menu_order;
}
if ($sitepress_settings['sync_private_flag'] && $original_post_details->post_status == 'private') {
$postarr['post_status'] = 'private';
}
if (!$is_update) {
$postarr['post_status'] = !$sitepress_settings['translated_document_status'] ? 'draft' : $original_post_details->post_status;
} else {
// set post_status to the current post status.
$postarr['post_status'] = $wpdb->get_var($wpdb->prepare("SELECT post_status\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM {$wpdb->prefix}posts\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE ID = %d ", $post_id));
}
if ($sitepress_settings['sync_post_date']) {
$postarr['post_date'] = $original_post_details->post_date;
}
if (isset($parent_id) && $sitepress_settings['sync_page_parent']) {
$_POST['post_parent'] = $postarr['post_parent'] = $parent_id;
$_POST['parent_id'] = $postarr['parent_id'] = $parent_id;
}
if ($is_update) {
$postarr['post_name'] = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} WHERE ID=%d", $post_id));
}
$_POST['trid'] = $trid;
$_POST['lang'] = $lang_code;
$_POST['skip_sitepress_actions'] = true;
global $wp_rewrite;
if (!isset($wp_rewrite)) {
$wp_rewrite = new WP_Rewrite();
}
kses_remove_filters();
$postarr = apply_filters('icl_pre_save_pro_translation', $postarr);
$new_post_id = wp_insert_post($postarr);
do_action('icl_pro_translation_saved', $new_post_id);
// set stickiness
if ($is_original_sticky && $sitepress_settings['sync_sticky_flag']) {
stick_post($new_post_id);
} else {
if ($original_post_details->post_type == 'post' && $is_update) {
unstick_post($new_post_id);
//just in case - if this is an update and the original post stckiness has changed since the post was sent to translation
}
}
//.........这里部分代码省略.........
示例13: write_post
//.........这里部分代码省略.........
// Set Google+ authorship status for the post
if ($new) {
$gplus_enabled = isset($gplus) ? (bool) $gplus : true;
if (false === $gplus_enabled) {
update_post_meta($post_id, 'gplus_authorship_disabled', 1);
}
} else {
if (isset($gplus) && true === $gplus) {
delete_post_meta($post_id, 'gplus_authorship_disabled');
} else {
if (isset($gplus) && false == $gplus) {
update_post_meta($post_id, 'gplus_authorship_disabled', 1);
}
}
}
// Set sharing status of the post
if ($new) {
$sharing_enabled = isset($sharing) ? (bool) $sharing : true;
if (false === $sharing_enabled) {
update_post_meta($post_id, 'sharing_disabled', 1);
}
} else {
if (isset($sharing) && true === $sharing) {
delete_post_meta($post_id, 'sharing_disabled');
} else {
if (isset($sharing) && false == $sharing) {
update_post_meta($post_id, 'sharing_disabled', 1);
}
}
}
if (true === $sticky) {
stick_post($post_id);
} else {
unstick_post($post_id);
}
// WPCOM Specific (Jetpack's will get bumped elsewhere
// Tracks how many posts are published and sets meta so we can track some other cool stats (like likes & comments on posts published)
if ($new && 'publish' == $input['status'] || !$new && isset($last_status) && 'publish' != $last_status && isset($new_status) && 'publish' == $new_status) {
if (function_exists('bump_stats_extras')) {
bump_stats_extras('api-insights-posts', $this->api->token_details['client_id']);
update_post_meta($post_id, '_rest_api_published', 1);
update_post_meta($post_id, '_rest_api_client_id', $this->api->token_details['client_id']);
}
}
// We ask the user/dev to pass Publicize services he/she wants activated for the post, but Publicize expects us
// to instead flag the ones we don't want to be skipped. proceed with said logic.
// any posts coming from Path (client ID 25952) should also not publicize
if ($publicize === false || 25952 == $this->api->token_details['client_id']) {
// No publicize at all, skipp all by full service
foreach ($GLOBALS['publicize_ui']->publicize->get_services('all') as $name => $service) {
update_post_meta($post_id, $GLOBALS['publicize_ui']->publicize->POST_SKIP . $name, 1);
}
} else {
if (is_array($publicize) && count($publicize) > 0) {
foreach ($GLOBALS['publicize_ui']->publicize->get_services('all') as $name => $service) {
/*
* We support both indexed and associative arrays:
* * indexed are to pass entire services
* * associative are to pass specific connections per service
*
* We do support mixed arrays: mixed integer and string keys (see 3rd example below).
*
* EG: array( 'twitter', 'facebook') will only publicize to those, ignoring the other available services
* Form data: publicize[]=twitter&publicize[]=facebook
* EG: array( 'twitter' => '(int) $pub_conn_id_0, (int) $pub_conn_id_3', 'facebook' => (int) $pub_conn_id_7 ) will publicize to two Twitter accounts, and one Facebook connection, of potentially many.
* Form data: publicize[twitter]=$pub_conn_id_0,$pub_conn_id_3&publicize[facebook]=$pub_conn_id_7
示例14: save_translation
//.........这里部分代码省略.........
if ($post_name != $post_name_rewritten) {
$incr = 1;
do {
$exists = $wpdb->get_var($wpdb->prepare("\n SELECT p.ID FROM {$wpdb->posts} p\n JOIN {$wpdb->prefix}icl_translations t ON t.element_id = p.ID AND t.element_type=%s\n WHERE p.ID <> %d AND t.language_code = %s AND p.post_name=%s\n ", 'post_' . $postarr['post_type'], $new_post_id, $job->language_code, $post_name));
if ($exists) {
$incr++;
} else {
break;
}
$post_name = $post_name_base . '-' . $incr;
} while ($exists);
$wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $new_post_id));
}
$ICL_Pro_Translation->_content_fix_links_to_translated_content($new_post_id, $job->language_code);
// update body translation with the links fixed
$new_post_content = $wpdb->get_var($wpdb->prepare("SELECT post_content FROM {$wpdb->posts} WHERE ID=%d", $new_post_id));
foreach ($job->elements as $jel) {
if ($jel->field_type == 'body') {
$fields_data_translated = $this->encode_field_data($new_post_content, $jel->field_format);
break;
}
}
$wpdb->update($wpdb->prefix . 'icl_translate', array('field_data_translated' => $fields_data_translated), array('job_id' => $data['job_id'], 'field_type' => 'body'));
// set stickiness
//is the original post a sticky post?
remove_filter('option_sticky_posts', array($sitepress, 'option_sticky_posts'));
// remove filter used to get language relevant stickies. get them all
$sticky_posts = get_option('sticky_posts');
$is_original_sticky = $original_post->post_type == 'post' && in_array($original_post->ID, $sticky_posts);
if ($is_original_sticky && $sitepress_settings['sync_sticky_flag']) {
stick_post($new_post_id);
} else {
if ($original_post->post_type == 'post' && !is_null($element_id)) {
unstick_post($new_post_id);
//just in case - if this is an update and the original post stckiness has changed since the post was sent to translation
}
}
//sync plugins texts
foreach ((array) $this->settings['custom_fields_translation'] as $cf => $op) {
if ($op == 1) {
update_post_meta($new_post_id, $cf, get_post_meta($original_post->ID, $cf, true));
}
}
// set specific custom fields
$copied_custom_fields = array('_top_nav_excluded', '_cms_nav_minihome');
foreach ($copied_custom_fields as $ccf) {
$val = get_post_meta($original_post->ID, $ccf, true);
update_post_meta($new_post_id, $ccf, $val);
}
// sync _wp_page_template
if ($sitepress_settings['sync_page_template']) {
$_wp_page_template = get_post_meta($original_post->ID, '_wp_page_template', true);
if (!empty($_wp_page_template)) {
update_post_meta($new_post_id, '_wp_page_template', $_wp_page_template);
}
}
// sync post format
if ($sitepress_settings['sync_post_format']) {
$_wp_post_format = get_post_format($original_post->ID);
set_post_format($new_post_id, $_wp_post_format);
}
// set the translated custom fields if we have any.
foreach ((array) $this->settings['custom_fields_translation'] as $field_name => $val) {
if ($val == 2) {
// should be translated
// find it in the translation
示例15: save_translation
//.........这里部分代码省略.........
icl_cache_clear($postarr['post_type'] . 's_per_language');
// clear post counter per language in cache
// set taxonomies for users with limited caps
if (!current_user_can('manage-categories') && !empty($postarr['tax_input'])) {
foreach ($postarr['tax_input'] as $taxonomy => $terms) {
wp_set_post_terms($new_post_id, $terms, $taxonomy, false);
// true to append to existing tags | false to replace existing tags
}
}
do_action('icl_pro_translation_saved', $new_post_id, $data['fields']);
if ($ICL_Pro_Translation) {
/** @var WPML_Pro_Translation $ICL_Pro_Translation */
$ICL_Pro_Translation->_content_fix_links_to_translated_content($new_post_id, $job->language_code);
}
// update body translation with the links fixed
$new_post_content = $wpdb->get_var($wpdb->prepare("SELECT post_content FROM {$wpdb->posts} WHERE ID=%d", $new_post_id));
foreach ($job->elements as $jel) {
if ($jel->field_type == 'body') {
$fields_data_translated = $this->encode_field_data($new_post_content, $jel->field_format);
break;
}
}
if (isset($fields_data_translated)) {
$wpdb->update($wpdb->prefix . 'icl_translate', array('field_data_translated' => $fields_data_translated), array('job_id' => $data['job_id'], 'field_type' => 'body'));
}
// set stickiness
//is the original post a sticky post?
$sticky_posts = get_option('sticky_posts');
$is_original_sticky = $original_post->post_type == 'post' && in_array($original_post->ID, $sticky_posts);
if ($is_original_sticky && $sitepress->get_setting('sync_sticky_flag')) {
stick_post($new_post_id);
} else {
if ($original_post->post_type == 'post' && !is_null($element_id)) {
unstick_post($new_post_id);
//just in case - if this is an update and the original post stckiness has changed since the post was sent to translation
}
}
//sync plugins texts
foreach ((array) $this->settings['custom_fields_translation'] as $cf => $op) {
if ($op == 1) {
update_post_meta($new_post_id, $cf, get_post_meta($original_post->ID, $cf, true));
}
}
// set specific custom fields
$copied_custom_fields = array('_top_nav_excluded', '_cms_nav_minihome');
foreach ($copied_custom_fields as $ccf) {
$val = get_post_meta($original_post->ID, $ccf, true);
update_post_meta($new_post_id, $ccf, $val);
}
// sync _wp_page_template
if ($sitepress->get_setting('sync_page_template')) {
$_wp_page_template = get_post_meta($original_post->ID, '_wp_page_template', true);
if (!empty($_wp_page_template)) {
update_post_meta($new_post_id, '_wp_page_template', $_wp_page_template);
}
}
// sync post format
if ($sitepress->get_setting('sync_post_format')) {
$_wp_post_format = get_post_format($original_post->ID);
set_post_format($new_post_id, $_wp_post_format);
}
$package_helper = new WPML_Element_Translation_Package();
$package_helper->save_job_custom_fields($job, $new_post_id, (array) $this->settings['custom_fields_translation']);
$link = get_edit_post_link($new_post_id);
if ($link == '') {
// the current user can't edit so just include permalink