本文整理汇总了PHP中update_attached_file函数 的典型用法代码示例。如果您正苦于以下问题:PHP update_attached_file函数的具体用法?PHP update_attached_file怎么用?PHP update_attached_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_attached_file函数 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: update_attachments
/**
* Run the converter now
*
* @since 1.0
*
* @param array $args can be extension
* @param array $vars
*/
function update_attachments($args = array(), $vars = array())
{
$images = Tiff_Converter::get_images();
$mime_type = 'image/jpg';
// Maybe $args[0] for changing it
if ($images) {
$succeed = $failed = 0;
foreach ($images as $image) {
$file = get_attached_file($image->ID);
$result = Tiff_Converter_Handle::convert_image($file, $mime_type);
if (!is_wp_error($result)) {
$update_args = array('ID' => $image->ID, 'post_mime_type' => $result['mime-type']);
$result2 = wp_update_post($update_args, true);
if ($result2 && !is_wp_error($result2)) {
unlink($file);
update_attached_file($image->ID, $result['path']);
wp_update_attachment_metadata($image->ID, wp_generate_attachment_metadata($image->ID, $result['path']));
$succeed++;
} else {
unlink($result['path']);
$failed++;
}
} else {
$failed++;
}
}
WP_CLI::success(sprintf('%d images are converted and %s failed', $succeed, $failed));
} else {
WP_CLI::success('No images to convert');
}
}
开发者ID:markoheijnen, 项目名称:WordPress-Tiff-Converter, 代码行数:39, 代码来源:wp-cli.php
示例2: secure_attachment_file
/**
* Sufffix random characters to attachment to prevent direct access to it by guessing URL
*
* @param int $attachment_id ID of attachment
* @return boolean True on success else false
*/
public function secure_attachment_file($attachment_id)
{
$file = get_attached_file($attachment_id);
$file_parts = pathinfo($file);
$file_new = $file_parts['dirname'] . '/' . $file_parts['filename'] . '_' . wp_generate_password(5, false) . '.' . $file_parts['extension'];
if (rename($file, $file_new)) {
update_attached_file($attachment_id, $file_new);
return true;
} else {
return false;
}
}
开发者ID:nagyistoce, 项目名称:supportflow, 代码行数:18, 代码来源:class-supportflow-attachments.php
示例3: detheme_get_image_id
function detheme_get_image_id($image_url)
{
if (!function_exists('wp_generate_attachment_metadata')) {
require_once ABSPATH . 'wp-admin/includes/image.php';
}
global $wpdb;
$upload_dir_paths = wp_upload_dir();
$attachment = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", $image_url));
if (!$attachment && false !== strpos($image_url, $upload_dir_paths['baseurl'])) {
// If this is the URL of an auto-generated thumbnail, get the URL of the original image
$attachment_url = preg_replace('/-\\d+x\\d+(?=\\.(jpg|jpeg|png|gif)$)/i', '', $image_url);
// Remove the upload path base directory from the attachment URL
$attachment_url = str_replace($upload_dir_paths['baseurl'] . '/', '', $attachment_url);
$image_path = $upload_dir_paths['basedir'] . "/" . $attachment_url;
$attachment = wp_insert_attachment(array('post_title' => sanitize_title(basename($image_url)), 'post_mime_type' => 'image/jpg', 'guid' => $image_url));
wp_update_attachment_metadata($attachment, wp_generate_attachment_metadata($attachment, $image_path));
update_attached_file($attachment, $image_path);
}
return $attachment;
}
开发者ID:estrategasdigitales, 项目名称:lactibox, 代码行数:20, 代码来源:migration.php
示例4: ewww_image_optimizer_update_attachment
/**
* Update the attachment's meta data after being converted
*/
function ewww_image_optimizer_update_attachment($meta, $ID)
{
global $ewww_debug;
global $wpdb;
$ewww_debug .= "<b>ewww_image_optimizer_update_attachment()</b><br>";
// update the file location in the post metadata based on the new path stored in the attachment metadata
update_attached_file($ID, $meta['file']);
// retrieve the post information based on the $ID
$post = get_post($ID);
// save the previous attachment address
$old_guid = $post->guid;
// construct the new guid based on the filename from the attachment metadata
$guid = dirname($post->guid) . "/" . basename($meta['file']);
// retrieve any posts that link the image
$esql = $wpdb->prepare("SELECT ID, post_content FROM {$wpdb->posts} WHERE post_content LIKE '%%%s%%'", $old_guid);
// while there are posts to process
$rows = $wpdb->get_results($esql, ARRAY_A);
foreach ($rows as $row) {
// replace all occurences of the old guid with the new guid
$post_content = str_replace($old_guid, $guid, $row['post_content']);
$ewww_debug .= "replacing {$old_guid} with {$guid} in post " . $row['ID'] . '<br>';
// send the updated content back to the database
$wpdb->update($wpdb->posts, array('post_content' => $post_content), array('ID' => $row['ID']));
}
if (isset($meta['sizes'])) {
// for each resized version
foreach ($meta['sizes'] as $size => $data) {
// if the resize was converted
if (isset($data['converted'])) {
// generate the url for the old image
if (empty($data['real_orig_file'])) {
$old_sguid = dirname($post->guid) . "/" . basename($data['orig_file']);
} else {
$old_sguid = dirname($post->guid) . "/" . basename($data['real_orig_file']);
unset($meta['sizes'][$size]['real_orig_file']);
}
$ewww_debug .= "processing: {$size}<br>";
$ewww_debug .= "old guid: {$old_sguid} <br>";
// generate the url for the new image
$sguid = dirname($post->guid) . "/" . basename($data['file']);
$ewww_debug .= "new guid: {$sguid} <br>";
// retrieve any posts that link the resize
$ersql = $wpdb->prepare("SELECT ID, post_content FROM {$wpdb->posts} WHERE post_content LIKE '%%%s%%'", $old_sguid);
$ewww_debug .= "using query: {$ersql}<br>";
$rows = $wpdb->get_results($ersql, ARRAY_A);
// while there are posts to process
foreach ($rows as $row) {
// replace all occurences of the old guid with the new guid
$post_content = str_replace($old_sguid, $sguid, $row['post_content']);
$ewww_debug .= "replacing {$old_sguid} with {$sguid} in post " . $row['ID'] . '<br>';
// send the updated content back to the database
$wpdb->update($wpdb->posts, array('post_content' => $post_content), array('ID' => $row['ID']));
}
}
}
}
// if the new image is a JPG
if (preg_match('/.jpg$/i', basename($meta['file']))) {
// set the mimetype to JPG
$mime = 'image/jpg';
}
// if the new image is a PNG
if (preg_match('/.png$/i', basename($meta['file']))) {
// set the mimetype to PNG
$mime = 'image/png';
}
if (preg_match('/.gif$/i', basename($meta['file']))) {
// set the mimetype to GIF
$mime = 'image/gif';
}
// update the attachment post with the new mimetype and guid
wp_update_post(array('ID' => $ID, 'post_mime_type' => $mime, 'guid' => $guid));
ewww_image_optimizer_debug_log();
ewwwio_memory(__FUNCTION__);
return $meta;
}
开发者ID:goodbayscott, 项目名称:wwr-temp, 代码行数:79, 代码来源:common.php
示例5: wp_insert_post
//.........这里部分代码省略.........
if (isset($postarr['tags_input']) && is_object_in_taxonomy($post_type, 'post_tag')) {
wp_set_post_tags($post_ID, $postarr['tags_input']);
}
// New-style support for all custom taxonomies.
if (!empty($postarr['tax_input'])) {
foreach ($postarr['tax_input'] as $taxonomy => $tags) {
$taxonomy_obj = get_taxonomy($taxonomy);
if (!$taxonomy_obj) {
/* translators: %s: taxonomy name */
_doing_it_wrong(__FUNCTION__, sprintf(__('Invalid taxonomy: %s.'), $taxonomy), '4.4.0');
continue;
}
// array = hierarchical, string = non-hierarchical.
if (is_array($tags)) {
$tags = array_filter($tags);
}
if (current_user_can($taxonomy_obj->cap->assign_terms)) {
wp_set_post_terms($post_ID, $tags, $taxonomy);
}
}
}
if (!empty($postarr['meta_input'])) {
foreach ($postarr['meta_input'] as $field => $value) {
update_post_meta($post_ID, $field, $value);
}
}
$current_guid = get_post_field('guid', $post_ID);
// Set GUID.
if (!$update && '' == $current_guid) {
$wpdb->update($wpdb->posts, array('guid' => get_permalink($post_ID)), $where);
}
if ('attachment' === $postarr['post_type']) {
if (!empty($postarr['file'])) {
update_attached_file($post_ID, $postarr['file']);
}
if (!empty($postarr['context'])) {
add_post_meta($post_ID, '_wp_attachment_context', $postarr['context'], true);
}
}
clean_post_cache($post_ID);
$post = get_post($post_ID);
if (!empty($postarr['page_template']) && 'page' == $data['post_type']) {
$post->page_template = $postarr['page_template'];
$page_templates = wp_get_theme()->get_page_templates($post);
if ('default' != $postarr['page_template'] && !isset($page_templates[$postarr['page_template']])) {
if ($wp_error) {
return new WP_Error('invalid_page_template', __('The page template is invalid.'));
}
update_post_meta($post_ID, '_wp_page_template', 'default');
} else {
update_post_meta($post_ID, '_wp_page_template', $postarr['page_template']);
}
}
if ('attachment' !== $postarr['post_type']) {
wp_transition_post_status($data['post_status'], $previous_status, $post);
} else {
if ($update) {
/**
* Fires once an existing attachment has been updated.
*
* @since 2.0.0
*
* @param int $post_ID Attachment ID.
*/
do_action('edit_attachment', $post_ID);
$post_after = get_post($post_ID);
开发者ID:SayenkoDesign, 项目名称:ividf, 代码行数:67, 代码来源:post.php
示例6: wp_save_image
/**
* Saves image to post along with enqueued changes
* in $_REQUEST['history']
*
* @param int $post_id
* @return \stdClass
*/
function wp_save_image($post_id)
{
global $_wp_additional_image_sizes;
$return = new stdClass();
$success = $delete = $scaled = $nocrop = false;
$post = get_post($post_id);
$img = wp_get_image_editor(_load_image_to_edit_path($post_id, 'full'));
if (is_wp_error($img)) {
$return->error = esc_js(__('Unable to create new image.'));
return $return;
}
$fwidth = !empty($_REQUEST['fwidth']) ? intval($_REQUEST['fwidth']) : 0;
$fheight = !empty($_REQUEST['fheight']) ? intval($_REQUEST['fheight']) : 0;
$target = !empty($_REQUEST['target']) ? preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['target']) : '';
$scale = !empty($_REQUEST['do']) && 'scale' == $_REQUEST['do'];
if ($scale && $fwidth > 0 && $fheight > 0) {
$size = $img->get_size();
$sX = $size['width'];
$sY = $size['height'];
// Check if it has roughly the same w / h ratio.
$diff = round($sX / $sY, 2) - round($fwidth / $fheight, 2);
if (-0.1 < $diff && $diff < 0.1) {
// Scale the full size image.
if ($img->resize($fwidth, $fheight)) {
$scaled = true;
}
}
if (!$scaled) {
$return->error = esc_js(__('Error while saving the scaled image. Please reload the page and try again.'));
return $return;
}
} elseif (!empty($_REQUEST['history'])) {
$changes = json_decode(wp_unslash($_REQUEST['history']));
if ($changes) {
$img = image_edit_apply_changes($img, $changes);
}
} else {
$return->error = esc_js(__('Nothing to save, the image has not changed.'));
return $return;
}
$meta = wp_get_attachment_metadata($post_id);
$backup_sizes = get_post_meta($post->ID, '_wp_attachment_backup_sizes', true);
if (!is_array($meta)) {
$return->error = esc_js(__('Image data does not exist. Please re-upload the image.'));
return $return;
}
if (!is_array($backup_sizes)) {
$backup_sizes = array();
}
// Generate new filename.
$path = get_attached_file($post_id);
$path_parts = pathinfo($path);
$filename = $path_parts['filename'];
$suffix = time() . rand(100, 999);
if (defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE && isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename']) {
if ('thumbnail' == $target) {
$new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}";
} else {
$new_path = $path;
}
} else {
while (true) {
$filename = preg_replace('/-e([0-9]+)$/', '', $filename);
$filename .= "-e{$suffix}";
$new_filename = "{$filename}.{$path_parts['extension']}";
$new_path = "{$path_parts['dirname']}/{$new_filename}";
if (file_exists($new_path)) {
$suffix++;
} else {
break;
}
}
}
// Save the full-size file, also needed to create sub-sizes.
if (!wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id)) {
$return->error = esc_js(__('Unable to save the image.'));
return $return;
}
if ('nothumb' == $target || 'all' == $target || 'full' == $target || $scaled) {
$tag = false;
if (isset($backup_sizes['full-orig'])) {
if ((!defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE) && $backup_sizes['full-orig']['file'] != $path_parts['basename']) {
$tag = "full-{$suffix}";
}
} else {
$tag = 'full-orig';
}
if ($tag) {
$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
}
$success = $path === $new_path || update_attached_file($post_id, $new_path);
$meta['file'] = _wp_relative_upload_path($new_path);
$size = $img->get_size();
//.........这里部分代码省略.........
开发者ID:cybKIRA, 项目名称:roverlink-updated, 代码行数:101, 代码来源:image-edit.php
示例7: wpcf_image_add_to_library
/**
* Adds image to library.
*
* @param type $post
* @param type $abspath
*/
function wpcf_image_add_to_library($post, $abspath)
{
$guid = wpcf_image_attachment_url($abspath);
if (!wpcf_image_is_attachment($guid)) {
$wp_filetype = wp_check_filetype(basename($abspath), null);
$attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($abspath)), 'post_content' => '', 'post_status' => 'inherit', 'guid' => $guid);
$attach_id = wp_insert_attachment($attachment, $abspath, $post->ID);
require_once ABSPATH . "wp-admin" . '/includes/image.php';
$attach_data = wp_generate_attachment_metadata($attach_id, $abspath);
$attach_data['file'] = str_replace('\\', '/', wpcf_image_normalize_attachment($attach_data['file']));
wp_update_attachment_metadata($attach_id, $attach_data);
update_attached_file($attach_id, $attach_data['file']);
}
}
开发者ID:torch2424, 项目名称:Team-No-Comply-Games-Wordpress, 代码行数:20, 代码来源:image.php
示例8: wpsc_convert_products_to_posts
//.........这里部分代码省略.........
$post_created = array('original_id' => $product['id'], 'post_id' => $post_id);
set_transient('wpsc_update_current_product', $post_created, 604800);
}
$product_meta_sql = $wpdb->prepare("\n\t\t\t\tSELECT \tIF( ( `custom` != 1\t),\n\t\t\t\t\t\tCONCAT( '_wpsc_', `meta_key` ) ,\n\t\t\t\t\t`meta_key`\n\t\t\t\t\t) AS `meta_key`,\n\t\t\t\t\t`meta_value`\n\t\t\t\tFROM `" . WPSC_TABLE_PRODUCTMETA . "`\n\t\t\t\tWHERE `product_id` = %d\n\t\t\t\tAND `meta_value` != ''", $product['id']);
$product_meta = $wpdb->get_results($product_meta_sql, ARRAY_A);
$post_data = array();
foreach ($product_meta as $k => $pm) {
if ($pm['meta_value'] == 'om') {
$pm['meta_value'] = 1;
}
$pm['meta_value'] = maybe_unserialize($pm['meta_value']);
if (strpos($pm['meta_key'], '_wpsc_') === 0) {
$post_data['_wpsc_product_metadata'][$pm['meta_key']] = $pm['meta_value'];
} else {
update_post_meta($post_id, $pm['meta_key'], $pm['meta_value']);
}
}
$post_data['_wpsc_original_id'] = (int) $product['id'];
$post_data['_wpsc_price'] = (double) $product['price'];
$post_data['_wpsc_special_price'] = $post_data['_wpsc_price'] - (double) $product['special_price'];
// special price get stored in a weird way in 3.7.x
$post_data['_wpsc_stock'] = (double) $product['quantity'];
$post_data['_wpsc_is_donation'] = $product['donation'];
$post_data['_wpsc_sku'] = $sku;
if ((bool) $product['quantity_limited'] != true) {
$post_data['_wpsc_stock'] = false;
}
unset($post_data['_wpsc_limited_stock']);
$post_data['_wpsc_product_metadata']['is_stock_limited'] = (int) (bool) $product['quantity_limited'];
// Product Weight
$post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($product['weight'], $product['weight_unit'], "pound", true);
$post_data['_wpsc_product_metadata']['weight_unit'] = $product['weight_unit'];
$post_data['_wpsc_product_metadata']['display_weight_as'] = $product['weight_unit'];
$post_data['_wpsc_product_metadata']['has_no_shipping'] = (int) (bool) $product['no_shipping'];
$post_data['_wpsc_product_metadata']['shipping'] = array('local' => $product['pnp'], 'international' => $product['international_pnp']);
$post_data['_wpsc_product_metadata']['quantity_limited'] = (int) (bool) $product['quantity_limited'];
$post_data['_wpsc_product_metadata']['special'] = (int) (bool) $product['special'];
if (isset($post_data['meta'])) {
$post_data['_wpsc_product_metadata']['notify_when_none_left'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'];
$post_data['_wpsc_product_metadata']['unpublish_when_none_left'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'];
}
$post_data['_wpsc_product_metadata']['no_shipping'] = (int) (bool) $product['no_shipping'];
foreach ($post_data as $meta_key => $meta_value) {
// prefix all meta keys with _wpsc_
update_post_meta($post_id, $meta_key, $meta_value);
}
// get the wordpress upload directory data
$wp_upload_dir_data = wp_upload_dir();
$wp_upload_basedir = $wp_upload_dir_data['basedir'];
$category_ids = array();
$category_data = $wpdb->get_col("SELECT `category_id` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` WHERE `product_id` IN ('{$product['id']}')");
foreach ($category_data as $old_category_id) {
$category_ids[] = wpsc_get_meta($old_category_id, 'category_id', 'wpsc_old_category');
}
wp_set_product_categories($post_id, $category_ids);
$product_data = get_post($post_id);
$image_data_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PRODUCT_IMAGES . "` WHERE `product_id` = %d ORDER BY `image_order` ASC", $product['id']);
$image_data = $wpdb->get_results($image_data_sql, ARRAY_A);
foreach ((array) $image_data as $image_row) {
$wpsc_update->check_timeout('</div>');
// Get the image path info
$image_pathinfo = pathinfo($image_row['image']);
// use the path info to clip off the file extension
$image_name = basename($image_pathinfo['basename'], ".{$image_pathinfo['extension']}");
// construct the full image path
$full_image_path = WPSC_IMAGE_DIR . $image_row['image'];
$attached_file_path = str_replace($wp_upload_basedir . "/", '', $full_image_path);
$upload_dir = wp_upload_dir();
$new_path = $upload_dir['path'] . '/' . $image_name . '.' . $image_pathinfo['extension'];
if (is_file($full_image_path)) {
copy($full_image_path, $new_path);
} else {
continue;
}
// construct the full image url
$subdir = $upload_dir['subdir'] . '/' . $image_name . '.' . $image_pathinfo['extension'];
$subdir = substr($subdir, 1);
$attachment_id_sql = $wpdb->prepare("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_title` = %s AND `post_parent` = %d LIMIT 1", $image_name, $post_id);
$attachment_id = (int) $wpdb->get_var($attachment_id_sql);
// get the image MIME type
$mime_type_data = wpsc_get_mimetype($full_image_path, true);
if ((int) $attachment_id == 0) {
// construct the image data array
$image_post_values = array('post_author' => $user_ID, 'post_parent' => $post_id, 'post_date' => $product_data->post_date, 'post_content' => $image_name, 'post_title' => $image_name, 'post_status' => "inherit", 'post_type' => "attachment", 'post_name' => sanitize_title($image_name), 'post_mime_type' => $mime_type_data['mime_type'], 'menu_order' => absint($image_row['image_order']), 'guid' => $new_path);
$attachment_id = wp_insert_post($image_post_values);
}
update_attached_file($attachment_id, $new_path);
wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $new_path));
}
$i++;
$progress->update($i);
set_transient('wpsc_update_product_offset', $i, 604800);
}
$offset += $limit;
}
//Just throwing the payment gateway update in here because it doesn't really warrant it's own function :)
$custom_gateways = get_option('custom_gateway_options');
array_walk($custom_gateways, "wpec_update_gateway");
update_option('custom_gateway_options', $custom_gateways);
}
开发者ID:ashik968, 项目名称:digiplot, 代码行数:101, 代码来源:updating-functions.php
示例9: attachment_fields_to_save
public static function attachment_fields_to_save($post, $attachment)
{
if (isset($attachment[self::META_POSITION]) && $attachment[self::META_POSITION]) {
$previousPosition = self::getMeta($post['ID']);
$position = json_decode($attachment[self::META_POSITION]);
update_post_meta($post['ID'], self::META_POSITION, $position);
// Update the thumbnail if the position changed
if ($previousPosition[0] != $position[0] || $previousPosition[1] != $position[1]) {
$realOldImagePath = get_attached_file($post['ID']);
$oldImagePath = str_ireplace('-focalcropped', '', $realOldImagePath);
// Rename file, while keeping the previous version
// Generate new filename
$oldImagePathParts = pathinfo($oldImagePath);
$filename = $oldImagePathParts['filename'];
$suffix = '-focalcropped';
//time() . rand(100, 999);
$filename = str_ireplace('-focalcropped', '', $filename);
$filename .= $suffix;
$newImageFile = "{$filename}.{$oldImagePathParts['extension']}";
$newImagePath = "{$oldImagePathParts['dirname']}/{$newImageFile}";
$url = '';
if (copy($oldImagePath, $newImagePath)) {
$url = $newImagePath;
}
if (!$url) {
return false;
}
@set_time_limit(900);
// 5 minutes per image should be PLENTY
update_attached_file($post['ID'], $url);
$metadata = wp_generate_attachment_metadata($post['ID'], $url);
if (!$metadata || is_wp_error($metadata)) {
wp_send_json_error('empty metadata');
}
wp_update_attachment_metadata($post['ID'], $metadata);
//@unlink($file);
clean_post_cache($post['ID']);
}
}
return $post;
}
开发者ID:redink-no, 项目名称:wp-focalpoint, 代码行数:41, 代码来源:FocalPointMisc.php
示例10: unitydog_add_attachment
function unitydog_add_attachment($pid)
{
$post = get_post($pid);
$file = get_attached_file($pid);
$path = pathinfo($file);
// If it's not a unity file - get outa here stalker
if ($path['extension'] != "unity3d") {
return;
}
$newfile = $file . ".zip";
// add a zip
rename($file, $newfile);
update_attached_file($pid, $newfile);
}
开发者ID:The-Keep-Studios, 项目名称:tks-website, 代码行数:14, 代码来源:unitydog.php
示例11: update_review_widget
/**
* Updates the review widget graphic and saves it as an attachment
*/
public function update_review_widget()
{
$filename = $this->id . '.gif';
$raw_data = file_get_contents('https://www.trustedshops.com/bewertung/widget/widgets/' . $filename);
$uploads = wp_upload_dir(date('Y-m'));
if (is_wp_error($uploads)) {
return;
}
$filepath = $uploads['path'] . '/' . $filename;
file_put_contents($filepath, $raw_data);
$attachment = array('guid' => $uploads['url'] . '/' . basename($filepath), 'post_mime_type' => 'image/gif', 'post_title' => _x('Trusted Shops Customer Reviews', 'trusted-shops', 'woocommerce-germanized'), 'post_content' => '', 'post_status' => 'publish');
if (!$this->get_review_widget_attachment()) {
$attachment_id = wp_insert_attachment($attachment, $filepath);
update_option('woocommerce_gzd_trusted_shops_review_widget_attachment', $attachment_id);
} else {
$attachment_id = $this->get_review_widget_attachment();
update_attached_file($attachment_id, $filepath);
$attachment['ID'] = $attachment_id;
wp_update_post($attachment);
}
require_once ABSPATH . 'wp-admin/includes/image.php';
// Generate the metadata for the attachment, and update the database record.
$attach_data = wp_generate_attachment_metadata($attachment_id, $filepath);
wp_update_attachment_metadata($attachment_id, $attach_data);
}
开发者ID:ronzeiller, 项目名称:woocommerce-germanized, 代码行数:28, 代码来源:class-wc-gzd-trusted-shops.php
示例12: woo_cd_admin_init
//.........这里部分代码省略.........
woo_ce_update_file_detail( $post_ID, '_woo_idle_memory_end', woo_ce_current_memory_usage() );
woo_ce_update_file_detail( $post_ID, '_woo_end_time', time() );
delete_option( WOO_CD_PREFIX . '_exported' );
$objWriter->save( 'php://output' );
} else {
// Save to file and insert to WordPress Media
$temp_filename = tempnam( apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ), 'tmp' );
// Check if we were given a temporary filename
if( $temp_filename == false ) {
$message = sprintf( __( 'We could not create a temporary export file in <code>%s</code>, ensure that WordPress can read and write files here and try again.', 'woo_ce' ), apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ) );
woo_cd_admin_notice( $message, 'error' );
wp_redirect( esc_url( add_query_arg( array( 'failed' => true, 'message' => urlencode( $message ) ) ) ) );
exit();
} else {
$objWriter->save( $temp_filename );
$bits = file_get_contents( $temp_filename );
}
unlink( $temp_filename );
$post_ID = woo_ce_save_file_attachment( $export->filename, $post_mime_type );
$upload = wp_upload_bits( $export->filename, null, $bits );
// Check if the upload succeeded otherwise delete Post and return error notice
if( ( $post_ID == false ) || $upload['error'] ) {
wp_delete_attachment( $post_ID, true );
if( isset( $upload['error'] ) )
wp_redirect( esc_url( add_query_arg( array( 'failed' => true, 'message' => urlencode( $upload['error'] ) ) ) ) );
else
wp_redirect( esc_url( add_query_arg( array( 'failed' => true ) ) ) );
return;
}
if( file_exists( ABSPATH . 'wp-admin/includes/image.php' ) ) {
$attach_data = wp_generate_attachment_metadata( $post_ID, $upload['file'] );
wp_update_attachment_metadata( $post_ID, $attach_data );
update_attached_file( $post_ID, $upload['file'] );
if( !empty( $post_ID ) ) {
woo_ce_save_file_guid( $post_ID, $export->type, $upload['url'] );
woo_ce_save_file_details( $post_ID );
}
} else {
error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'Could not load image.php within /wp-admin/includes/image.php', 'woo_ce' ) ) );
}
// The end memory usage and time is collected at the very last opportunity prior to the file header being rendered to the screen
woo_ce_update_file_detail( $post_ID, '_woo_idle_memory_end', woo_ce_current_memory_usage() );
woo_ce_update_file_detail( $post_ID, '_woo_end_time', time() );
delete_option( WOO_CD_PREFIX . '_exported' );
$objWriter->save( 'php://output' );
}
// Clean up PHPExcel
$excel->disconnectWorksheets();
unset( $objWriter, $excel );
exit();
} else {
// Save to temporary file then dump into export log screen
$objWriter->setUseBOM( true );
$temp_filename = tempnam( apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ), 'tmp' );
// Check if we were given a temporary filename
if( $temp_filename == false ) {
$message = sprintf( __( 'We could not create a temporary export file in <code>%s</code>, ensure that WordPress can read and write files here and try again.', 'woo_ce' ), apply_filters( 'woo_ce_sys_get_temp_dir', sys_get_temp_dir() ) );
woo_cd_admin_notice( $message, 'error' );
} else {
$objWriter->save( $temp_filename );
$bits = file_get_contents( $temp_filename );
开发者ID:helloworld-digital, 项目名称:katemorgan, 代码行数:67, 代码来源:exporter-deluxe.php
示例13: woo_ce_cron_export
//.........这里部分代码省略.........
if( is_wp_error( $response ) ) {
error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $response->get_error_message() ) );
return false;
} else {
error_log( sprintf( '[store-exporter-deluxe] %s: Success: %s', $export->filename, sprintf( __( 'Remote POST sent to %s', 'woo_ce' ), $export->to ) ) );
}
// Output to screen in friendly design with on-screen error responses
} else if( $gui == 'gui' ) {
if( file_exists( WOO_CD_PATH . 'templates/admin/cron.php' ) ) {
include_once( WOO_CD_PATH . 'templates/admin/cron.php' );
} else {
error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'Could not load template file within /templates/admin/cron.php', 'woo_ce' ) ) );
}
if( isset( $output ) )
echo $output;
echo '
</body>
</html>';
// Save export file to WordPress Media before sending/saving/etc. action
} else if( in_array( $gui, array( 'gui', 'archive', 'url', 'file', 'email', 'ftp' ) ) ) {
$upload = false;
if( $export->filename && !empty( $bits ) ) {
$post_ID = woo_ce_save_file_attachment( $export->filename, $post_mime_type );
$upload = wp_upload_bits( $export->filename, null, $bits );
if( ( $post_ID == false ) || $upload['error'] ) {
wp_delete_attachment( $post_ID, true );
error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, $upload['error'] ) );
return false;
}
if( file_exists( ABSPATH . 'wp-admin/includes/image.php' ) ) {
include_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_data = wp_generate_attachment_metadata( $post_ID, $upload['file'] );
wp_update_attachment_metadata( $post_ID, $attach_data );
update_attached_file( $post_ID, $upload['file'] );
if( !empty( $post_ID ) ) {
woo_ce_save_file_guid( $post_ID, $export->type, $upload['url'] );
woo_ce_save_file_details( $post_ID );
}
} else {
error_log( sprintf( '[store-exporter-deluxe] %s: Error: %s', $export->filename, __( 'Could not load image.php within /wp-admin/includes/image.php', 'woo_ce' ) ) );
}
}
// Return URL to export file
if( $gui == 'url' )
return $upload['url'];
// Return system path to export file
if( $gui == 'file' )
return $upload['file'];
// E-mail export file to preferred address or WordPress site owner address
if( $gui == 'email' ) {
global $woocommerce;
$mailer = $woocommerce->mailer();
$subject = woo_ce_cron_email_subject( $export->type, $export->filename );
$attachment = $upload['file'];
$email_heading = sprintf( __( 'Export: %s', 'woo_ce' ), ucwords( $export->type ) );
$recipient_name = apply_filters( 'woo_ce_email_recipient_name', __( 'there', 'woo_ce' ) );
$email_contents = apply_filters( 'woo_ce_email_contents', wpautop( __( 'Please find attached your export ready to review.', 'woo_ce' ) ) );
// Buffer
ob_start();
// Get mail template
if( file_exists( WOO_CD_PATH . 'templates/emails/scheduled_export.php' ) ) {
include_once( WOO_CD_PATH . 'templates/emails/scheduled_export.php' );
开发者ID:helloworld-digital, 项目名称:katemorgan, 代码行数:67, 代码来源:cron.php
示例14: ajax_process_image
/**
* Process a single image ID (this is an AJAX handler)
*
* @access public
* @since 1.0
*/
function ajax_process_image()
{
// No timeout limit
set_time_limit(0);
// Don't break the JSON result
error_reporting(0);
$id = (int) $_REQUEST['id'];
try {
header('Content-type: application/json');
$image = get_post($id);
if (is_null($image)) {
throw new Exception(sprintf(__('Failed: %d is an invalid image ID.', 'force-regenerate-thumbnails'), $id));
}
if ('attachment' != $image->post_type || 'image/' != substr($image->post_mime_type, 0, 6)) {
throw new Exception(sprintf(__('Failed: %d is an invalid image ID.', 'force-regenerate-thumbnails'), $id));
}
if (!current_user_can($this->capability)) {
throw new Exception(__('Your user account does not have permission to regenerate images.', 'force-regenerate-thumbnails'));
}
/**
* Fix for get_option('upload_path')
* Thanks (@DavidLingren)
*
* @since 2.0.1
*/
$upload_dir = wp_upload_dir();
// Get original image
$image_fullpath = get_attached_file($image->ID);
$debug_1 = $image_fullpath;
$debug_2 = '';
$debug_3 = '';
$debug_4 = '';
// Can't get image path
if (false === $image_fullpath || strlen($image_fullpath) == 0) {
// Try get image path from url
if (strrpos($image->guid, $upload_dir['baseurl']) !== false) {
$image_fullpath = realpath($upload_dir['basedir'] . DIRECTORY_SEPARATOR . substr($image->guid, strlen($upload_dir['baseurl']), strlen($image->guid)));
$debug_2 = $image_fullpath;
if (realpath($image_fullpath) === false) {
throw new Exception(sprintf(__('The originally uploaded image file cannot be found at "%s".', 'force-regenerate-thumbnails'), esc_html((string) $image_fullpath)));
}
} else {
throw new Exception(__('The originally uploaded image file cannot be found.', 'force-regenerate-thumbnails'));
}
}
// Image path incomplete
if (strrpos($image_fullpath, $upload_dir['basedir']) === false) {
$image_fullpath = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $image_fullpath;
$debug_3 = $image_fullpath;
}
// Image don't exists
if (!file_exists($image_fullpath) || realpath($image_fullpath) === false) {
// Try get image path from url
if (strrpos($image->guid, $upload_dir['baseurl']) !== false) {
$image_fullpath = realpath($upload_dir['basedir'] . DIRECTORY_SEPARATOR . substr($image->guid, strlen($upload_dir['baseurl']), strlen($image->guid)));
$debug_4 = $image_fullpath;
if (realpath($image_fullpath) === false) {
throw new Exception(sprintf(__('The originally uploaded image file cannot be found at "%s".', 'force-regenerate-thumbnails'), esc_html((string) $image_fullpath)));
}
} else {
throw new Exception(sprintf(__('The originally uploaded image file cannot be found at "%s".', 'force-regenerate-thumbnails'), esc_html((string) $image_fullpath)));
}
}
/**
* Update META POST
* Thanks (@norecipes)
*
* @since 2.0.2
*/
update_attached_file($image->ID, $image_fullpath);
// Results
$thumb_deleted = array();
$thumb_error = array();
$thumb_regenerate = array();
// Hack to find thumbnail
$file_info = pathinfo($image_fullpath);
$file_info['filename'] .= '-';
/**
* Try delete all thumbnails
*/
$files = array();
$path = opendir($file_info['dirname']);
if (false !== $path) {
while (false !== ($thumb = readdir($path))) {
if (!(strrpos($thumb, $file_info['filename']) === false)) {
$files[] = $thumb;
}
}
closedir($path);
sort($files);
}
foreach ($files as $thumb) {
$thumb_fullpath = $file_info['dirname'] . DIRECTORY_SEPARATOR . $thumb;
$thumb_info = pathinfo($thumb_fullpath);
//.........这里部分代码省略.........
开发者ID:KiyaDigital, 项目名称:tvarchive-canonical_wordpress, 代码行数:101, 代码来源:force-regenerate-thumbnails.php
示例15: wpvp_encode
//.........这里部分代码省略.........
}
//while fileFound ends
//debug_mode is true
if ($debug_mode) {
$helper->wpvp_dump('New files path on the server: video and image ...');
$helper->wpvp_dump('video: ' . $newFile);
$helper->wpvp_dump('image: ' . $newFileTB);
$helper->wpvp_dump('New files url on the server: video and image ...');
$helper->wpvp_dump('video: ' . $guid);
$helper->wpvp_dump('image: ' . $guidTB);
}
if ($file_encoded) {
if ($debug_mode) {
$helper->wpvp_dump('FFMPEG found on the server. Encoding initializing...');
}
//ffmpeg to get a thumb from the video
$this->wpvp_convert_thumb($originalFilePath, $newFileTB);
//ffmpeg to convert video
$this->wpvp_convert_video($originalFilePath, $newFile, $encodeFormat);
//pathinfo on the FULL path to the NEW file
if ($debug_mode) {
if (!file_exists($newFile)) {
$helper->wpvp_dump('Video file was not converted. Possible reasons: missing libraries for ffmpeg, permissions on the directory where the file is being written to...');
} else {
$helper->wpvp_dump('Video was converted: ' . $newFile);
}
if (!file_exists($newFileTB)) {
$helper->wpvp_dump('Thumbnail was not created. Possible reasons: missing libraries for ffmpeg, permissions on the directory where the file is being written to...');
} else {
$helper->wpvp_dump('Thumbnail was created: ' . $newFileTB);
}
}
//update attachment file
$updated = update_attached_file($ID, $newfile);
} else {
if ($debug_mode) {
$helper->wpvp_dump('FFMPEG is not found on the server. Possible reasons: not installed, not properly configured, the path is not provided correctly in the plugin\'s options settings...');
}
$defaultImg = get_option('wpvp_default_img', '') ? get_option('wpvp_default_img') : '';
if ($defaultImg != '') {
$newFileTB = $defaultImg;
$guidTB = str_replace($uploadPath, $uploadUrl, $newFileTB);
} else {
$default_img_path = $uploadPath . '/default_image.jpg';
copy(plugin_dir_path(dirname(__FILE__)) . 'images/default_image.jpg', $default_img_path);
if (file_exists($default_img_path)) {
update_option('wpvp_default_img', $default_img_path);
$newFileTB = $default_img_path;
$guidTB = str_replace($uploadPath, $uploadUrl, $default_img_path);
}
}
$guid = str_replace($uploadPath, $uploadUrl, $originalFilePath);
$newFile = $originalFilePath;
}
//no ffmpeg - no encoding
$newFileDetails = pathinfo($newFile);
$newTmbDetails = pathinfo($newFileTB);
//shortcode for the player
$shortCode = '[wpvp_player src=' . $guid . ' width=' . $width . ' height=' . $height . ' splash=' . $guidTB . ']';
//update the auto created post with our data
if (empty($front_end_postID)) {
$postID = intval($_REQUEST['post_id']);
} else {
$postID = $front_end_postID;
}
$videoPostID = $postID;
开发者ID:ajaycorbus, 项目名称:Plugins, 代码行数:67, 代码来源:wpvp-core-class.php
示例16: evc_save_remote_attachment
PacktPublishing/Python-Machine-Learning-Second-Edition: Python Machine Learning
阅读:927| 2022-08-18
BentoBoxWorld/AOneBlock: A OneBlock Minecraft Game for BentoBox
阅读:538| 2022-08-17
win7系统电脑使用过程中有不少朋友表示遇到过win7系统USB驱动器RAM的状况,当出现win7
阅读:832| 2022-11-06
manur/MATLAB-git: A thin MATLAB wrapper for the Git source control system
阅读:396| 2022-08-17
1、弹出窗体要想在一个窗体中弹出另一个窗体,方法如下:uses窗体单元名;formName.sho
阅读:546| 2022-07-18
nstudio/nativescript-cardview: NativeScript widget for Material Design CardView
阅读:528| 2022-08-17
Microsoft Defender for Endpoint Tampering Vulnerability.
阅读:544| 2022-07-29
elipapa/markdown-cv: a simple template to write your CV in a readable markdown f
阅读:483| 2022-08-17
ravdy/kubernetes
阅读:544| 2022-08-13
Call Me Maybe 中英字幕 对于加拿大歌手卡莉·蕾·吉普森很多人有些陌生,她隶属于贾
阅读:571| 2022-11-06
请发表评论