本文整理汇总了PHP中delete_post_thumbnail函数的典型用法代码示例。如果您正苦于以下问题:PHP delete_post_thumbnail函数的具体用法?PHP delete_post_thumbnail怎么用?PHP delete_post_thumbnail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delete_post_thumbnail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_nav_fields
/**
* Save the new field data for the nav menu.
*
* @param $menu_id
* @param $menu_item_db_id
* @param $args
*/
public function update_nav_fields($menu_id, $menu_item_db_id, $args)
{
// Hide on mobile.
if (isset($_POST['hide-menu-on-mobile'][$menu_item_db_id])) {
update_post_meta($menu_item_db_id, 'hide_menu_on_mobile', empty($_POST['hide-menu-on-mobile'][$menu_item_db_id]) ? false : 'on');
} else {
delete_post_meta($menu_item_db_id, 'hide_menu_on_mobile');
}
// Image.
if (isset($_POST['menu-item-image']) && is_array($_POST['menu-item-image'])) {
if (!isset($_POST['menu-item-image'][$menu_item_db_id]) || !$_POST['menu-item-image'][$menu_item_db_id]) {
delete_post_thumbnail($menu_item_db_id);
}
if (isset($_POST['menu-item-image'][$menu_item_db_id])) {
set_post_thumbnail($menu_item_db_id, absint($_POST['menu-item-image'][$menu_item_db_id]));
}
}
if (isset($_POST['menu-item-icon']) && is_array($_POST['menu-item-icon'])) {
if (isset($_POST['menu-item-icon'][$menu_item_db_id])) {
update_post_meta($menu_item_db_id, '_menu_item_icon', sanitize_text_field($_POST['menu-item-icon'][$menu_item_db_id]));
}
}
if (isset($_POST['menu-item-widget-area']) && isset($_POST['menu-item-widget-area'][$menu_item_db_id]) && is_array($_POST['menu-item-widget-area'])) {
update_post_meta($menu_item_db_id, '_menu_item_widget_area', sanitize_text_field($_POST['menu-item-widget-area'][$menu_item_db_id]));
}
}
示例2: wp_delete_attachments
/**
* Delete attachments linked to a specified post
* @param int $parent_id Parent id of post to delete attachments for
*/
function wp_delete_attachments($parent_id, $unlink = true, $type = 'images')
{
if ($type == 'images' and has_post_thumbnail($parent_id)) {
delete_post_thumbnail($parent_id);
}
$ids = array();
$attachments = get_posts(array('post_parent' => $parent_id, 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null));
foreach ($attachments as $attach) {
if ($type == 'files' and !wp_attachment_is_image($attach->ID)) {
if ($unlink) {
wp_delete_attachment($attach->ID, true);
} else {
$ids[] = $attach->ID;
}
} elseif ($type == 'images' and wp_attachment_is_image($attach->ID)) {
if ($unlink) {
wp_delete_attachment($attach->ID, true);
} else {
$ids[] = $attach->ID;
}
}
}
global $wpdb;
if (!empty($ids)) {
$ids_string = implode(',', $ids);
// unattach
$result = $wpdb->query("UPDATE {$wpdb->posts} SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( {$ids_string} )");
foreach ($ids as $att_id) {
clean_attachment_cache($att_id);
}
}
return $ids;
}
示例3: delete
/**
* Delete the post thumbnail when deleted from front end
*
* @since 0.1
*
* @param array $data Sanitized data to use for saving.
*
* @return bool Always returns true.
*/
public function delete($data)
{
$postid = isset($data['postid']) ? $data['postid'] : false;
delete_post_thumbnail($postid);
do_action('lasso_featured_image_deleted', $postid, get_current_user_ID());
return true;
}
示例4: mc_event_post
function mc_event_post($action, $data, $event_id)
{
// if the event save was successful.
if ($action == 'add' || $action == 'copy') {
$post_id = mc_create_event_post($data, $event_id);
} else {
if ($action == 'edit') {
if (isset($_POST['event_post']) && ($_POST['event_post'] == 0 || $_POST['event_post'] == '')) {
$post_id = mc_create_event_post($data, $event_id);
} else {
$post_id = $_POST['event_post'];
}
// If, after all that, the post doesn't exist, create it.
if (!get_post_status($post_id)) {
mc_create_event_post($data, $event_id);
}
$term = mc_get_category_detail($data['event_category'], 'category_term');
if (!$term) {
$term = wp_insert_term('General', 'mc-event-category');
$term = !is_wp_error($term) ? $term['term_id'] : false;
if ($term) {
$update = mc_update_category('category_term', $term, $data['event_category']);
}
}
$privacy = mc_get_category_detail($data['event_category'], 'category_private') == 1 ? 'private' : 'publish';
$title = $data['event_title'];
$template = apply_filters('mc_post_template', 'details', $term);
$data['shortcode'] = "[my_calendar_event event='{$event_id}' template='{$template}' list='']";
$description = $data['event_desc'];
$excerpt = $data['event_short'];
$post_status = $privacy;
$auth = $data['event_author'];
$type = 'mc-events';
$my_post = array('ID' => $post_id, 'post_title' => $title, 'post_content' => $description, 'post_status' => $post_status, 'post_author' => $auth, 'post_name' => sanitize_title($title), 'post_date' => date('Y-m-d H:i:s', current_time('timestamp')), 'post_type' => $type, 'post_excerpt' => $excerpt);
if (mc_switch_sites() && defined(BLOG_ID_CURRENT_SITE)) {
switch_to_blog(BLOG_ID_CURRENT_SITE);
}
$post_id = wp_update_post($my_post);
wp_set_object_terms($post_id, (int) $term, 'mc-event-category');
if ($data['event_image'] == '') {
delete_post_thumbnail($post_id);
} else {
$attachment_id = isset($_POST['event_image_id']) && is_numeric($_POST['event_image_id']) ? $_POST['event_image_id'] : false;
if ($attachment_id) {
set_post_thumbnail($post_id, $attachment_id);
}
}
$access = isset($_POST['events_access']) ? $_POST['events_access'] : array();
$access_terms = implode(',', array_values($access));
mc_update_event('event_access', $access_terms, $event_id, '%s');
do_action('mc_update_event_post', $post_id, $_POST, $data, $event_id);
if (mc_switch_sites()) {
restore_current_blog();
}
}
}
return $post_id;
}
示例5: delete_menu_item_image_action
/**
* When menu item removed remove menu image metadata.
*/
public function delete_menu_item_image_action()
{
$menu_item_id = (int) $_REQUEST['menu-item'];
check_admin_referer('delete-menu_item_image_' . $menu_item_id);
if (is_nav_menu_item($menu_item_id) && has_post_thumbnail($menu_item_id)) {
delete_post_thumbnail($menu_item_id);
delete_post_meta($menu_item_id, 'menu_item_icon');
delete_post_meta($menu_item_id, 'menu-item-bg-img');
}
}
示例6: erm_update_menu_item
/**
*
*/
function erm_update_menu_item()
{
//echo '<pre>'; print_r( $_POST ); echo '</pre>'; exit();
if (isset($_POST['post_id'])) {
$post_id = absint($_POST['post_id']);
wp_update_post(array('ID' => $post_id, 'post_title' => $_POST['title'], 'post_name' => $_POST['title'], 'post_content' => $_POST['content']));
update_post_meta($post_id, '_erm_visible', $_POST['visible'] == 'true' ? true : false);
update_post_meta($post_id, '_erm_prices', $_POST['prices']);
$image_id = absint($_POST['image_id']);
if ($image_id != 0) {
set_post_thumbnail($post_id, $image_id);
} else {
delete_post_thumbnail($post_id);
}
wp_send_json_success();
}
exit;
}
示例7: wp_delete_attachments
/**
* Delete attachments linked to a specified post
* @param int $parent_id Parent id of post to delete attachments for
*/
function wp_delete_attachments($parent_id, $unlink = true, $type = '')
{
if ($type == 'images' and has_post_thumbnail($parent_id)) {
delete_post_thumbnail($parent_id);
}
foreach (get_posts(array('post_parent' => $parent_id, 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null)) as $attach) {
if ($type == 'files' and !wp_attachment_is_image($attach->ID)) {
wp_delete_attachment($attach->ID, true);
} elseif ($type == 'images' and wp_attachment_is_image($attach->ID) or "" == $type) {
if ($unlink or !wp_attachment_is_image($attach->ID)) {
wp_delete_attachment($attach->ID, true);
} else {
global $wpdb;
$sql = "delete a,b,c\n\t\t\t\t\tFROM " . $wpdb->posts . " a\n\t\t\t\t\tLEFT JOIN " . $wpdb->term_relationships . " b ON ( a.ID = b.object_id )\n\t\t\t\t\tLEFT JOIN " . $wpdb->postmeta . " c ON ( a.ID = c.post_id )\n\t\t\t\t\tLEFT JOIN " . $wpdb->posts . " d ON ( a.ID = d.post_parent )\n\t\t\t\t\tWHERE a.ID = " . $attach->ID . ";";
$wpdb->query($wpdb->prepare($sql, ''));
}
}
}
}
示例8: set_banner_image
public final function set_banner_image()
{
$post_ID = intval($_POST['post_id']);
if (!current_user_can('edit_post', $post_ID)) {
wp_die(-1);
}
$banner_id = intval($_POST['banner_id']);
check_ajax_referer("update-post_{$post_ID}");
if ($banner_id == '-1') {
if (delete_post_thumbnail($post_ID)) {
wp_send_json_success('');
} else {
wp_die(0);
}
}
$course = \Ekko\Core\CoursePostType::singleton()->get_course($post_ID);
if (set_post_thumbnail($course->ID, $banner_id)) {
wp_send_json_success($this->banner_thumbnail_html($course));
}
wp_die(0);
}
示例9: update_post_thumbnail
private function update_post_thumbnail($post_id, $reserved_post_thumb_path)
{
include_once ABSPATH . 'wp-admin/includes/image.php';
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($reserved_post_thumb_path);
$file_name = basename($reserved_post_thumb_path);
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $file_name;
} else {
$file = $upload_dir['basedir'] . '/' . $file_name;
}
file_put_contents($file, $image_data);
$wp_file_type = wp_check_filetype($file_name, null);
$attachment = array('post_mime_type' => $wp_file_type['type'], 'post_title' => sanitize_file_name($file_name), 'post_content' => '', 'post_status' => 'inherit');
delete_post_thumbnail($post_id);
$attachment_id = wp_insert_attachment($attachment, $file, $post_id);
$attach_data = wp_generate_attachment_metadata($attachment_id, $file);
if (!empty($attach_data) && !is_wp_error($attach_data)) {
$res = wp_update_attachment_metadata($attachment_id, $attach_data);
set_post_thumbnail($post_id, $attachment_id);
return $res;
}
}
示例10: deletePostPicture
public static function deletePostPicture($postId)
{
delete_post_thumbnail($postId);
}
示例11: wp_ajax_set_menu_item_thumbnail
/**
* Update item thumbnail via ajax action.
*
* @since 2.0
*/
public function wp_ajax_set_menu_item_thumbnail()
{
$json = !empty($_REQUEST['json']);
$post_ID = intval($_POST['post_id']);
if (!current_user_can('edit_post', $post_ID)) {
wp_die(-1);
}
$thumbnail_id = intval($_POST['thumbnail_id']);
$is_hovered = (bool) $_POST['is_hover'];
check_ajax_referer("update-menu-item");
if ($thumbnail_id == '-1') {
if ($is_hovered) {
$success = delete_post_meta($post_ID, '_thumbnail_hover_id');
} else {
$success = delete_post_thumbnail($post_ID);
}
} else {
if ($is_hovered) {
$success = update_post_meta($post_ID, '_thumbnail_hover_id', $thumbnail_id);
} else {
$success = set_post_thumbnail($post_ID, $thumbnail_id);
}
}
if ($success) {
$return = $this->wp_post_thumbnail_only_html($post_ID);
$json ? wp_send_json_success($return) : wp_die($return);
}
wp_die(0);
}
示例12: update_post_meta
public static function update_post_meta($meta_vars, $post_id)
{
// prepare the meta vars
list($meta_key_value, $multi_repeated, $files) = self::prepare_meta_fields($meta_vars);
// set featured image if there's any
// if not in admin or if in admin (but doing an ajax call)
if (is_admin() && defined('DOING_AJAX') && DOING_AJAX || !is_admin()) {
if (isset($_POST['feat-image-id']) && $_POST['feat-image-id'] != 0) {
$attachment_id = $_POST['feat-image-id'];
fes_associate_attachment($attachment_id, $post_id);
set_post_thumbnail($post_id, $attachment_id);
}
if (!isset($_POST['feat-image-id']) || $_POST['feat-image-id'] == 0) {
delete_post_thumbnail($post_id);
}
}
// save all custom fields
foreach ($meta_key_value as $meta_key => $meta_value) {
update_post_meta($post_id, $meta_key, $meta_value);
}
// save any multicolumn repeatable fields
foreach ($multi_repeated as $repeat_key => $repeat_value) {
// first, delete any previous repeatable fields
delete_post_meta($post_id, $repeat_key);
// now add them
foreach ($repeat_value as $repeat_field) {
update_post_meta($post_id, $repeat_key, $repeat_field);
}
}
// save any files attached
foreach ($files as $file_input) {
if (!isset($_POST[$file_input['name']])) {
continue;
}
$ids = array();
// We need to detach all previously attached files for this field. See #559
$old_files = get_post_meta($post_id, $file_input['name'], true);
if (!empty($old_files) && is_array($old_files)) {
foreach ($old_files as $file_id) {
global $wpdb;
$wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $file_id), array('%d'), array('%d'));
}
}
foreach ($_POST[$file_input['name']] as $file => $url) {
if (empty($url)) {
continue;
}
$author_id = 0;
if (!current_user_can('manage_shop_settings')) {
$author_id = get_post_field('post_author', $post_id);
}
$attachment_id = fes_get_attachment_id_from_url($url, $author_id);
fes_associate_attachment($attachment_id, $post_id);
$ids[] = $attachment_id;
}
update_post_meta($post_id, $file_input['name'], $ids);
}
}
示例13: wp_idea_stream_ideas_update_idea
/**
* Handles updating an idea
*
* @package WP Idea Stream
* @subpackage ideas/functions
*
* @since 2.0.0
*
* @uses check_admin_referer() to check the request has been done from current site
* @uses wp_idea_stream_get_redirect_url() to get default redirect url
* @uses get_query_var() to get the value of a specific query var
* @uses wp_idea_stream_get_post_type() to get the ideas post type identifier
* @uses get_queried_object() to try to get the idea object WordPress built
* @uses wp_idea_stream_ideas_get_idea_by_name() to get an idea object out of its post name
* @uses wp_idea_stream_user_can() to check user's capability
* @uses wp_idea_stream_add_message() to add a feddback message to user
* @uses wp_safe_redirect() to safely redirect the user and avoid duplicates
* @uses wp_idea_stream_ideas_save_idea() to save the idea
* @uses wp_idea_stream_get_form_url() to get the add new form url
* @uses wp_idea_stream_ideas_get_idea_permalink() to get the idea link
*/
function wp_idea_stream_ideas_update_idea()
{
global $wp_query;
// Bail if not a post request
if ('POST' != strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
// Bail if not a post idea request
if (empty($_POST['wp_idea_stream']) || !is_array($_POST['wp_idea_stream'])) {
return;
}
// Bail if it's not an update
if (empty($_POST['wp_idea_stream']['_the_id'])) {
return;
}
// Check nonce
check_admin_referer('wp_idea_stream_save');
$redirect = wp_idea_stream_get_redirect_url();
// Get idea name
$idea_name = get_query_var(wp_idea_stream_get_post_type());
// Get Idea Object
$idea = get_queried_object();
// If queried object doesn't match or wasn't helpfull, try to get the idea using core function
if (empty($idea->post_name) || empty($idea_name) || $idea_name != $idea->post_name) {
$idea = wp_idea_stream_ideas_get_idea_by_name($idea_name);
}
// Found no idea, redirect and inform the user
if (empty($idea->ID)) {
wp_idea_stream_add_message(array('type' => 'error', 'content' => __('The idea you are trying to edit does not seem to exist.', 'wp-idea-stream')));
// Redirect to main archive page
wp_safe_redirect($redirect);
exit;
}
// Checks if the user can edit the idea
if (!wp_idea_stream_ideas_can_edit($idea)) {
// Add feedback to the user
wp_idea_stream_add_message(array('type' => 'error', 'content' => __('You are not allowed to edit this idea.', 'wp-idea-stream')));
// Redirect to main archive page
wp_safe_redirect($redirect);
exit;
}
$updated = array_diff_key($_POST['wp_idea_stream'], array('save' => 'submit'));
// Title & content are required
if (empty($updated['_the_title']) || empty($updated['_the_content'])) {
// Add feedback to the user
wp_idea_stream_add_message(array('type' => 'error', 'content' => __('Title and description are required fields.', 'wp-idea-stream')));
// Simply stop, so that the user keeps the posted values.
return;
}
// Reset '_the_id' param to the ID of the idea found
$updated['_the_id'] = $idea->ID;
$feedback_message = array();
$featured_error = __('There was a problem saving the featured image, sorry.', 'wp-idea-stream');
$featured_type = 'info';
// Take care of the featured image
$thumbnail_id = (int) get_post_thumbnail_id($idea);
if (!empty($updated['_the_thumbnail'])) {
$thumbnail_src = key($updated['_the_thumbnail']);
$thumbnail = reset($updated['_the_thumbnail']);
// Update the Featured image
if (!is_numeric($thumbnail) || $thumbnail_id !== (int) $thumbnail) {
if (is_numeric($thumbnail)) {
// validate the attachment
if (!get_post($thumbnail)) {
$feedback_message[] = $featured_error;
// Set the new Featured image
} else {
set_post_thumbnail($idea->ID, $thumbnail);
}
} else {
$sideload = WP_Idea_Stream_Ideas_Thumbnail::start($thumbnail_src, $idea->ID);
if (is_wp_error($sideload->result)) {
$feedback_message[] = $featured_error;
}
}
}
// Delete the featured image
} elseif (!empty($thumbnail_id)) {
delete_post_thumbnail($idea);
//.........这里部分代码省略.........
示例14: mla_list_table_custom_bulk_action
/**
* Process an MLA_List_Table custom bulk action
*
* Creates new items from the "Bulk Translate" list.
*
* @since 2.13
*
* @param array $item_content NULL, to indicate no handler.
* @param string $bulk_action the requested action.
* @param integer $post_id the affected attachment.
*
* @return object updated $item_content. NULL if no handler, otherwise
* ( 'message' => error or status message(s), 'body' => '' )
*/
public static function mla_list_table_custom_bulk_action($item_content, $bulk_action, $post_id)
{
if (self::MLA_GFI_ACTION != $bulk_action) {
return $item_content;
}
/* translators: 1: post ID */
$item_prefix = sprintf(__('Item %1$d', 'media-library-assistant'), $post_id) . ', ';
/*
* If there is a real thumbnail image, no generation is required or allowed
*/
$thumbnail = wp_get_attachment_image($post_id);
if (!empty($thumbnail)) {
return array('message' => $item_prefix . __('has native thumbnail.', 'media-library-assistant'));
}
/*
* Look for the "Featured Image" as an alternate thumbnail for PDFs, etc.
*/
$thumbnail = get_post_thumbnail_id($post_id);
if (!empty($thumbnail)) {
switch (self::$bulk_action_options['existing_thumbnails']) {
case 'ignore':
break;
case 'trash':
delete_post_thumbnail($post_id);
wp_delete_post(absint($thumbnail), false);
break;
case 'delete':
delete_post_thumbnail($post_id);
wp_delete_post(absint($thumbnail), true);
break;
case 'keep':
default:
return array('message' => $item_prefix . __('Featured Image retained.', 'media-library-assistant'));
}
}
/*
* Validate the file existance and type
*/
$file = get_attached_file($post_id);
if (empty($file)) {
/* translators: 1: ERROR tag 2: Item post ID */
return array('message' => sprintf(__('%1$s: %2$sno attached file.', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $item_prefix));
}
if (!in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), array('ai', 'eps', 'pdf', 'ps'))) {
return array('message' => $item_prefix . __('unsupported file type.', 'media-library-assistant'));
}
/*
* Generate a thumbnail
*/
require_once MLA_PLUGIN_PATH . 'includes/class-mla-image-processor.php';
$results = MLAImageProcessor::mla_handle_thumbnail_sideload($file, self::$bulk_action_options);
if (!empty($results['error'])) {
/* translators: 1: ERROR tag 2: Item post ID */
return array('message' => sprintf(__('%1$s: %2$sthumbnail generation failed', 'media-library-assistant'), __('ERROR', 'media-library-assistant'), $item_prefix) . ' - ' . $results['error']);
}
/*
* Adjust the file name for the new item
*/
$pathinfo = pathinfo($results['name']);
if (isset(self::$bulk_action_options['suffix'])) {
$pathinfo['filename'] = sanitize_file_name($pathinfo['filename'] . strtolower(self::$bulk_action_options['suffix']));
}
$pathinfo['extension'] = 'image/jpeg' == $results['type'] ? 'jpg' : 'png';
$results['name'] = $pathinfo['filename'] . '.' . $pathinfo['extension'];
$overrides = array('test_form' => false, 'test_size' => true, 'test_upload' => true);
// move the temporary file into the uploads directory
$results = wp_handle_sideload($results, $overrides);
$item_data = get_post($post_id, ARRAY_A);
unset($item_data['ID']);
unset($item_data['post_author']);
unset($item_data['post_date']);
unset($item_data['post_date_gmt']);
if (isset(self::$bulk_action_options['suffix'])) {
$item_data['post_title'] .= self::$bulk_action_options['suffix'];
}
unset($item_data['post_name']);
unset($item_data['post_modified']);
unset($item_data['post_modified_gmt']);
$item_parent = $item_data['post_parent'];
unset($item_data['post_parent']);
$item_data['guid'] = $results['url'];
$item_data['post_mime_type'] = $results['type'];
unset($item_data['comment_count']);
unset($item_data['ancestors']);
unset($item_data['post_category']);
unset($item_data['tags_input']);
//.........这里部分代码省略.........
示例15: wp_ajax_set_post_thumbnail
function wp_ajax_set_post_thumbnail()
{
$post_ID = intval($_POST['post_id']);
if (!current_user_can('edit_post', $post_ID)) {
wp_die(-1);
}
$thumbnail_id = intval($_POST['thumbnail_id']);
check_ajax_referer("set_post_thumbnail-{$post_ID}");
if ($thumbnail_id == '-1') {
if (delete_post_thumbnail($post_ID)) {
wp_die(_wp_post_thumbnail_html(null, $post_ID));
} else {
wp_die(0);
}
}
if (set_post_thumbnail($post_ID, $thumbnail_id)) {
wp_die(_wp_post_thumbnail_html($thumbnail_id, $post_ID));
}
wp_die(0);
}