本文整理汇总了PHP中wp_delete_attachment函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_delete_attachment函数的具体用法?PHP wp_delete_attachment怎么用?PHP wp_delete_attachment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_delete_attachment函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: removeAttachments
private function removeAttachments($post)
{
$attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $post->ID));
foreach ($attachments as $attachment) {
wp_delete_attachment($attachment->ID, true);
}
}
开发者ID:johnleesw,项目名称:mustardseedwp,代码行数:7,代码来源:Sweeper.php
示例2: deleteImage
public function deleteImage($image_id, $post_id, $meta_key = false)
{
wp_delete_attachment($image_id, false);
if ($meta_key) {
delete_post_meta($post_id, $meta_key, $image_id);
}
}
开发者ID:fregu,项目名称:orkanlia,代码行数:7,代码来源:images.php
示例3: prepare_form
/**
* Main edit post form
*
* @global type $wpdb
* @global type $userdata
*/
function prepare_form()
{
global $wpdb, $userdata;
$post_id = isset($_GET['pid']) ? intval($_GET['pid']) : 0;
//is editing enabled?
if (wpuf_get_option('enable_post_edit', 'yes') != 'yes') {
return __('Post Editing is disabled', 'wpuf');
}
$curpost = get_post($post_id);
if (!$curpost) {
return __('Invalid post', 'wpuf');
}
//has permission?
if (!current_user_can('delete_others_posts') && $userdata->ID != $curpost->post_author) {
return __('You are not allowed to edit', 'wpuf');
}
//perform delete attachment action
if (isset($_REQUEST['action']) && $_REQUEST['action'] == "del") {
check_admin_referer('wpuf_attach_del');
$attach_id = intval($_REQUEST['attach_id']);
if ($attach_id) {
wp_delete_attachment($attach_id);
}
}
//process post
if (isset($_POST['wpuf_edit_post_submit']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'wpuf-edit-post')) {
$this->submit_post();
}
//show post form
$this->edit_form($curpost);
}
开发者ID:alphaomegahost,项目名称:FIN,代码行数:37,代码来源:wpuf-edit-post.php
示例4: wp_rp_upload_attachment
/**
* Cron - Thumbnail extraction
*/
function wp_rp_upload_attachment($url, $post_id)
{
/* Parts copied from wp-admin/includes/media.php:media_sideload_image */
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/media.php';
include_once ABSPATH . 'wp-admin/includes/image.php';
$tmp = download_url($url);
preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $url, $matches);
$file_array['name'] = sanitize_file_name(urldecode(basename($matches[0])));
$file_array['tmp_name'] = $tmp;
if (is_wp_error($tmp)) {
@unlink($file_array['tmp_name']);
return false;
}
$post_data = array('guid' => $url, 'post_title' => 'rp_' . $file_array['name']);
$attachment_id = media_handle_sideload($file_array, $post_id, null, $post_data);
if (is_wp_error($attachment_id)) {
@unlink($file_array['tmp_name']);
return false;
}
$attach_data = wp_get_attachment_metadata($attachment_id);
$platform_options = wp_rp_get_platform_options();
$min_width = $platform_options['custom_size_thumbnail_enabled'] ? WP_RP_CUSTOM_THUMBNAILS_WIDTH : WP_RP_THUMBNAILS_WIDTH;
$min_height = $platform_options['custom_size_thumbnail_enabled'] ? WP_RP_CUSTOM_THUMBNAILS_HEIGHT : WP_RP_THUMBNAILS_HEIGHT;
if (!$attach_data || $attach_data['width'] < $min_width || $attach_data['height'] < $min_height) {
wp_delete_attachment($attachment_id);
return false;
}
return $attachment_id;
}
开发者ID:johnreytepacia,项目名称:etarticles,代码行数:33,代码来源:thumbnailer.php
示例5: delete_images_permanently
function delete_images_permanently($entries)
{
$meta_key = WPPG_ATTACHMENT_META_TAG;
$errors = '';
if (is_array($entries)) {
//Remove multiple images from gallery
foreach ($entries as $entry) {
$result = wp_delete_attachment($entry, true);
if ($result == NULL) {
$errors .= '<p><strong>' . sprintf(__('The deletion of attachment with image ID %s failed!', 'spgallery'), $entry) . '</strong></p>';
}
}
} elseif ($entries != NULL) {
//Remove a single image from the gallery
$result = wp_delete_attachment($entries, true);
if ($result == NULL) {
$errors .= '<p><strong>' . sprintf(__('The deletion of attachment with image ID %s failed!', 'spgallery'), $entries) . '</strong></p>';
}
}
if ($errors == '') {
$success_msg = '<div id="message" class="updated fade"><p><strong>';
$success_msg .= __('The selected images were successfully deleted from the system permanently!', 'spgallery');
$success_msg .= '</strong></p></div>';
_e($success_msg);
} else {
$error_msg = '<div id="message" class="error">';
$error_msg .= $errors;
$error_msg .= '</div>';
}
}
开发者ID:stvnfrancisco,项目名称:art_portfolio_wordpress,代码行数:30,代码来源:wppg-list-gallery-images.php
示例6: delete_attachment
public function delete_attachment()
{
global $json_api;
if (!current_user_can('upload_files') && !current_user_can('delete_posts')) {
$json_api->error("You do not have permission to delete files.");
}
//$json_api->error("Test 1 You do not have permission to delete files.");
//return null;
$nonce_id = $json_api->get_nonce_id('attachments', 'update_attachment');
if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) {
//$json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method.");
}
$id = $json_api->query->id !== null;
if ($json_api->query->id !== null) {
$id = (int) $json_api->query->id;
} else {
$json_api->error("Include 'id' or 'slug' var in your request.");
}
$force_delete = true;
if ($json_api->query->force_delete !== null) {
$force_delete = (bool) $json_api->query->force_delete;
}
$result = wp_delete_attachment($id, $force_delete);
if ($result) {
$successful = true;
} else {
$successful = false;
}
$result = array('post' => $result, 'deleted' => (bool) $successful);
return $result;
}
开发者ID:andreiRS,项目名称:Radii8,代码行数:31,代码来源:attachments.php
示例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 = '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;
}
开发者ID:lizbur10,项目名称:js_finalproject,代码行数:37,代码来源:wp_delete_attachments.php
示例8: expirator_callback
function expirator_callback()
{
//get_post_meta( $attachment_id, '_time_to_left', true );
global $post;
$args = array('post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => -1);
$loop = new WP_Query($args);
$output = "";
while ($loop->have_posts()) {
$loop->the_post();
$today = date("Y-m-d");
$today = strtotime($today);
$picker = get_post_meta($post->ID, '_time_to_left', true);
$picker = strtotime($picker);
if ($picker != '') {
$output .= 'process ' . $post->ID . ' >> ' . $today . ':' . $picker . '</br>';
if ($today >= $picker) {
$output .= 'this true - remove it</br>';
wp_delete_attachment($post->ID, true);
}
$output .= '</br></br>';
}
}
//send mail about expiration status
//wp_mail( '[email protected]', 'expirator', $output );
}
开发者ID:WordPress-UiGEN-resources,项目名称:wp-media-duplicator-class,代码行数:25,代码来源:plugin_init.php
示例9: deleteAttachments
/**
* Delete all wordpress attachments
* for a particular post.
*
* @param null $postId
*
* @return array
*/
public function deleteAttachments($postId = NULL)
{
// Data must be sent
if (is_null($postId)) {
return 'Must provide post ID to delete attachments.';
}
// Init a results array
$results = array();
// Get attachments
$attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'any', 'post_parent' => $postId));
// Loop through attachments
foreach ($attachments as $attachment) {
// Delete this attachment.
$result = wp_delete_attachment($attachment->ID, true);
// If deletion was successful...
if ($result) {
// Add id to success array.
$results[] = $attachment->ID;
} else {
// Warn the user...
echo "Warning! : Attachment could not be deleted: " . $attachment->ID;
}
}
// Return results.
return $results;
}
开发者ID:jakop345,项目名称:RETS-To-Wordpress,代码行数:34,代码来源:wp-manager.php
示例10: threewp_broadcast_apply_existing_attachment_action
/**
@brief threewp_broadcast_apply_existing_attachment_action
@since 2015-11-16 14:10:32
**/
public function threewp_broadcast_apply_existing_attachment_action($action)
{
if ($action->is_finished()) {
return;
}
$bcd = $action->broadcasting_data;
switch ($action->action) {
case 'overwrite':
// Delete the existing attachment
$this->debug('Maybe copy attachment: Deleting current attachment %s', $action->target_attachment->ID);
wp_delete_attachment($action->target_attachment->ID, true);
// true = Don't go to trash
// Tell BC to copy the attachment.
$action->use = false;
break;
case 'randomize':
$filename = $bcd->attachment_data->filename_base;
$filename = preg_replace('/(.*)\\./', '\\1_' . rand(1000000, 9999999) . '.', $filename);
$bcd->attachment_data->filename_base = $filename;
$this->debug('Maybe copy attachment: Randomizing new attachment filename to %s.', $bcd->attachment_data->filename_base);
// Tell BC to copy the attachment.
$action->use = false;
break;
}
}
开发者ID:Garth619,项目名称:wines-by-jennifer,代码行数:29,代码来源:attachments.php
示例11: tearDown
/**
* Tear down the test fixture.
*/
public function tearDown()
{
// Cleanup
foreach ($this->_ids as $id) {
wp_delete_attachment($id, true);
}
parent::tearDown();
}
开发者ID:boonebgorges,项目名称:wp,代码行数:11,代码来源:MediaEdit.php
示例12: delete_attachment
/**
* [delet_attachment write data from wordpress to CSV]
* @param [type] $post_id [description]
* @return [type] [description]
*/
public function delete_attachment( $post ) {
global $wpdb;
//$ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_parent = $post_id AND post_type = 'attachment'");
$ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment'");
foreach ( $ids as $id )
wp_delete_attachment($id);
}
开发者ID:nvminhtu,项目名称:Wordpress_plugin,代码行数:13,代码来源:delete-attachment.php
示例13: import_roles
public function import_roles()
{
if (!$this->can_import()) {
$this->main->permission_denied();
return;
}
if (!extension_loaded('simplexml')) {
echo '<div class="error"><p>' . $this->__('This functionality requires SimpleXML extension, which is not loaded.') . '</p></div>';
return;
}
if (!empty($_POST['submit'])) {
check_admin_referer('import-upload');
set_time_limit(0);
if ($this->handle_upload()) {
$this->roles_data = array();
global $wp_roles;
foreach ($this->import_data->roles as $role) {
$this->roles_data[$role->name] = (object) array('display_name' => $role->display_name, 'override' => FALSE);
if (get_role($role->name) !== NULL) {
$this->roles_data[$role->name]->override = TRUE;
}
}
}
}
if (!empty($_POST['importroles'])) {
$this->main->verify_nonce();
set_time_limit(0);
if (!empty($_POST['file-id'])) {
$this->file_id = $_POST['file-id'];
$this->parse_contents(get_attached_file($this->file_id));
if (is_wp_error($this->import_data)) {
$this->result = (object) array('success' => FALSE, 'message' => $this->import_data->get_error_message());
$this->import_data = NULL;
} else {
$this->roles_data = array();
if (!empty($_POST['import-roles'])) {
$this->roles_data = $_POST['import-roles'];
if (!is_array($this->roles_data)) {
$this->roles_data = array();
}
}
foreach ($this->import_data->roles as $role) {
if (array_key_exists($role->name, $this->roles_data)) {
if (get_role($role->name) === NULL) {
add_role($role->name, $role->display_name, $role->capabilities);
} else {
WPFront_User_Role_Editor_Add_Edit::update_role($role->name, $role->display_name, $role->capabilities);
}
}
}
$this->result = (object) array('success' => TRUE, 'message' => sprintf($this->__('%d role(s) imported.'), count($this->roles_data)));
$this->import_data = NULL;
}
wp_delete_attachment($this->file_id);
}
}
include $this->main->pluginDIR() . 'templates/personal-pro/import-roles.php';
}
开发者ID:JulieKuehl,项目名称:auburn-agency,代码行数:58,代码来源:class-wpfront-user-role-editor-import.php
示例14: tzs_delete_auction_callback
function tzs_delete_auction_callback()
{
$id = isset($_POST['id']) && is_numeric($_POST['id']) ? intval($_POST['id']) : 0;
$is_delete = isset($_POST['is_delete']) && is_numeric($_POST['is_delete']) ? intval($_POST['is_delete']) : 0;
$user_id = get_current_user_id();
$errors = array();
if ($id <= 0) {
echo "Номер не найден";
} else {
if ($user_id == 0) {
echo "Вход в систему обязателен";
} else {
global $wpdb;
// Добавить проверку наличия ставок - если есть ставки, то удаление невозможно
$sql = "SELECT COUNT(*) as cnt FROM " . TZS_AUCTION_RATES_TABLE . " WHERE auction_id = {$id}";
$row = $wpdb->get_row($sql);
if (count($row) === 0 && $wpdb->last_error != null) {
echo 'Не удалось отобразить информацию о ставках по тендеру. Свяжитесь, пожалуйста, с администрацией сайта.';
echo $wpdb->last_error;
} else {
if ($row === null) {
echo 'Ставки по тендеру не найдены.';
} else {
if ($row->cnt > 0) {
echo 'Обнаружены ставки по тендеру, удаление записи невозможно.';
} else {
if (strlen($row->image_id_lists) > 0 && $is_delete === 1) {
$img_names = explode(';', $row->image_id_lists);
for ($i = 0; $i < count($img_names); $i++) {
if (false === wp_delete_attachment($img_names[$i], true)) {
echo "Не удалось удалить файл с изображением: " . $img_names[$i]->get_error_message();
array_push($errors, "Не удалось удалить файл с изображением: " . $img_names[$i]->get_error_message());
}
}
}
if (count($errors) === 0) {
if ($is_delete === 1) {
$sql = "DELETE FROM " . TZS_AUCTIONS_TABLE . " WHERE id={$id} AND user_id={$user_id};";
} else {
$sql = "UPDATE " . TZS_AUCTIONS_TABLE . " SET active=0 WHERE id={$id} AND user_id={$user_id};";
}
if (false === $wpdb->query($sql)) {
if ($is_delete === 1) {
echo "Не удалось удалить Ваш тендер. Свяжитесь, пожалуйста, с администрацией сайта ";
} else {
echo "Не удалось перенести в архив Ваш тендер. Свяжитесь, пожалуйста, с администрацией сайта ";
}
} else {
echo "1";
}
}
}
}
}
}
}
die;
}
开发者ID:serker72,项目名称:T3S,代码行数:58,代码来源:tzs.my.auctions.php
示例15: delete_attachment
function delete_attachment($post)
{
//echo $_POST['att_ID'];
$msg = 'Attachment ID [' . $_POST['att_ID'] . '] has been deleted!';
if (wp_delete_attachment($_POST['att_ID'], true)) {
echo $msg;
}
die;
}
开发者ID:seanyainkiranina,项目名称:Write-Here,代码行数:9,代码来源:write-here.php
示例16: delete_file
function delete_file($attach_id)
{
$attachment = get_post($attach_id);
//post author or editor role
if (get_current_user_id() == $attachment->post_author || current_user_can('delete_private_pages')) {
wp_delete_attachment($attach_id, true);
return true;
}
exit;
}
开发者ID:ediamin,项目名称:wp-erp,代码行数:10,代码来源:class-uploader.php
示例17: rssmi_delete_attachment
function rssmi_delete_attachment($id_ID)
{
$args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => 'any', 'post_parent' => $id_ID);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
wp_delete_attachment($attachment->ID, true);
}
}
}
开发者ID:adams0917,项目名称:woocommerce_eht,代码行数:10,代码来源:db_functions.php
示例18: rssmi_delete_attachment
/**
* Delete the attachments of a parent post
*
* @param $pid
*/
function rssmi_delete_attachment($pid)
{
$attachments = get_children(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'any', 'post_parent' => $pid));
if (empty($attachments)) {
return;
}
foreach ($attachments as $attachment) {
wp_delete_attachment($attachment->ID, TRUE);
}
}
开发者ID:scottnkerr,项目名称:eeco,代码行数:15,代码来源:db_functions.php
示例19: rssmi_uninstall_delete_attachment
function rssmi_uninstall_delete_attachment($id_ID)
{
// DELETE ATTACHMENTS CREATED BY THIS PLUGIN
$args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => 'any', 'post_parent' => $id_ID);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
wp_delete_attachment($attachment->ID, true);
}
}
}
开发者ID:scottnkerr,项目名称:eeco,代码行数:11,代码来源:uninstall.php
示例20: wl_delete_post_attachments
/**
* Delete the attachments related to the specified post.
*
* @param $post_id
*/
function wl_delete_post_attachments($post_id)
{
// Get all the attachments related to the post.
$attachments = wl_get_attachments($post_id);
// Delete each attachment.
foreach ($attachments as $attachment) {
if (false === wp_delete_attachment($attachment->ID)) {
wl_write_log("wl_delete_post_attachments : error [ post id :: {$post_id} ]");
}
}
}
开发者ID:efueger,项目名称:wordlift-plugin,代码行数:16,代码来源:functions.php
注:本文中的wp_delete_attachment函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论