当前位置: 首页>>代码示例>>PHP>>正文


PHP get_attached_file函数代码示例

本文整理汇总了PHP中get_attached_file函数的典型用法代码示例。如果您正苦于以下问题:PHP get_attached_file函数的具体用法?PHP get_attached_file怎么用?PHP get_attached_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_attached_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: themify_make_image_size

 /**
  * Creates new image size.
  *
  * @uses get_attached_file()
  * @uses image_make_intermediate_size()
  * @uses wp_update_attachment_metadata()
  * @uses get_post_meta()
  * @uses update_post_meta()
  *
  * @param $attachment_id
  * @param $width
  * @param $height
  * @param $meta
  * @param $original_src
  *
  * @return array
  */
 function themify_make_image_size($attachment_id, $width, $height, $meta, $original_src)
 {
     setlocale(LC_CTYPE, get_locale() . '.UTF-8');
     $attached_file = get_attached_file($attachment_id);
     if (apply_filters('themify_image_script_use_large_size', true) && isset($meta['sizes']['large']['file'])) {
         $attached_file = str_replace($meta['file'], trailingslashit(dirname($meta['file'])) . $meta['sizes']['large']['file'], $attached_file);
     }
     $resized = image_make_intermediate_size($attached_file, $width, $height, true);
     if ($resized && !is_wp_error($resized)) {
         // Save the new size in meta data
         $key = sprintf('resized-%dx%d', $width, $height);
         $meta['sizes'][$key] = $resized;
         $src = str_replace(basename($original_src), $resized['file'], $original_src);
         wp_update_attachment_metadata($attachment_id, $meta);
         // Save size in backup sizes so it's deleted when original attachment is deleted.
         $backup_sizes = get_post_meta($attachment_id, '_wp_attachment_backup_sizes', true);
         if (!is_array($backup_sizes)) {
             $backup_sizes = array();
         }
         $backup_sizes[$key] = $resized;
         update_post_meta($attachment_id, '_wp_attachment_backup_sizes', $backup_sizes);
         // Return resized image url, width and height.
         return array('url' => esc_url($src), 'width' => $width, 'height' => $height);
     }
     // Return resized image url, width and height.
     return array('url' => $original_src, 'width' => $width, 'height' => $height);
 }
开发者ID:rgrasiano,项目名称:viabasica-hering,代码行数:44,代码来源:img.php

示例2: regenerateThumbnails

 public function regenerateThumbnails($image_id)
 {
     require_once 'wp-admin/includes/image.php';
     $fullsizepath = get_attached_file($image_id);
     $metadata = wp_generate_attachment_metadata($image_id, $fullsizepath);
     wp_update_attachment_metadata($image_id, $metadata);
 }
开发者ID:jeckel,项目名称:sp-plg-recent-posts,代码行数:7,代码来源:renderer.php

示例3: _generate_attachment

 /**
  * Creates a cropped version of an image for a given attachment ID.
  *
  * @param int $attachment_id The attachment for which to generate a cropped image.
  * @param int $width The width of the cropped image in pixels.
  * @param int $height The height of the cropped image in pixels.
  * @param bool $crop Whether to crop the generated image.
  * @return string The full path to the cropped image.  Empty if failed.
  */
 private function _generate_attachment($attachment_id = 0, $width = 0, $height = 0, $crop = true)
 {
     $attachment_id = (int) $attachment_id;
     $width = (int) $width;
     $height = (int) $height;
     $crop = (bool) $crop;
     $original_path = get_attached_file($attachment_id);
     // fix a WP bug up to 2.9.2
     if (!function_exists('wp_load_image')) {
         require_once ABSPATH . 'wp-admin/includes/image.php';
     }
     $resized_path = @new_image_resize($original_path, $width, $height, $crop);
     if (!is_wp_error($resized_path) && !is_array($resized_path)) {
         return $resized_path;
         // perhaps this image already exists.  If so, return it.
     } else {
         $orig_info = pathinfo($original_path);
         $suffix = "{$width}x{$height}";
         $dir = $orig_info['dirname'];
         $ext = $orig_info['extension'];
         $name = basename($original_path, ".{$ext}");
         $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
         if (file_exists($destfilename)) {
             return $destfilename;
         }
     }
     return '';
 }
开发者ID:TheMysticalSock,项目名称:westmichigansymphony,代码行数:37,代码来源:filosofo-custom-image-sizes.php

示例4: cycloneslider_thumb

function cycloneslider_thumb($original_attachment_id, $width, $height, $refresh = false, $slide_meta = array())
{
    $dir = wp_upload_dir();
    // Get full path to the slide image
    $image_path = get_attached_file($original_attachment_id);
    $image_path = apply_filters('cycloneslider_image_path', $image_path, $slide_meta);
    if (empty($image_path)) {
        return false;
    }
    // Full url to the slide image
    $image_url = wp_get_attachment_url($original_attachment_id);
    $image_url = apply_filters('cycloneslider_image_url', $image_url, $slide_meta);
    if (empty($image_url)) {
        return false;
    }
    $info = pathinfo($image_path);
    $dirname = isset($info['dirname']) ? $info['dirname'] : '';
    // Path to directory
    $ext = isset($info['extension']) ? $info['extension'] : '';
    // File extension Eg. "jpg"
    $thumb = wp_basename($image_path, ".{$ext}") . "-{$width}x{$height}.{$ext}";
    // Thumbname. Eg. [imagename]-[width]x[height].hpg
    // Check if thumb already exists. If it is, return its url, unless refresh is true
    if (file_exists($dirname . '/' . $thumb) and !$refresh) {
        return dirname($image_url) . '/' . $thumb;
        //We used dirname() since we need the URL format not the path
    }
    $resizeObj = new Image_Resizer($image_path);
    $resizeObj->resizeImage($width, $height);
    $resizeObj->saveImage($dirname . '/' . $thumb, 80);
    return dirname($image_url) . '/' . $thumb;
}
开发者ID:joffcrabtree,项目名称:wp-cyclone-slider,代码行数:32,代码来源:cyclone-slider.php

示例5: mla_wp_title_filter

/**
 * Customize the <title> tag content for the Tag Gallery and Single Image pages
 *
 * @param string The default page title
 * @param string $sep How to separate the various items within the page title
 * @param string $seplocation Optional. Direction to display title, 'right'.
 *
 * @return string updated title value
 */
function mla_wp_title_filter($title, $sep, $seplocation)
{
    $sep = " {$sep} ";
    if (is_page()) {
        $page = single_post_title('', false);
        /*
         * Match specific page titles and replace the default, page title,
         * with more interesting term or file information.
         */
        if ('Tag Gallery' == $page) {
            $taxonomy = isset($_REQUEST['my_taxonomy']) ? $_REQUEST['my_taxonomy'] : NULL;
            $slug = isset($_REQUEST['my_term']) ? $_REQUEST['my_term'] : NULL;
            if ($taxonomy && $slug) {
                $term = get_term_by('slug', $slug, $taxonomy);
                return $term->name . $sep;
            }
        } elseif ('Single Image' == $page) {
            $post_id = isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : 0;
            if ($post_id) {
                $file = get_attached_file($post_id);
                $pathinfo = pathinfo($file);
                return $pathinfo['basename'] . $sep;
            }
        }
    }
    // is_page
    return $title;
}
开发者ID:Bakerpedia,项目名称:Development_Site5,代码行数:37,代码来源:functions.php

示例6: opml_import

 /**
  * Shows The Import Page and import form for step 1.
  * Calls the parsing and importing function for step 2.
  * 
  * @since 3.3
  * @return void
  */
 public function opml_import()
 {
     // Show the Icon and Title
     echo '<div class="wrap">';
     screen_icon();
     echo '<h2>Import OPML</h2>';
     // Get the current step from URL query string
     $step = empty($_GET['step']) ? 0 : (int) $_GET['step'];
     // Check the current step
     switch ($step) {
         default:
         case 0:
             // Show the Import Message and the import upload form
             echo '<p>' . __('Howdy! Import your feeds here from an OPML (.xml) export file.', 'wprss') . '</p>';
             echo '<p>' . __("Click the button below, choose your file, and click 'Upload'.", 'wprss') . '</p>';
             echo '<p>' . __('We will take care of the rest.', 'wprss') . '</p>';
             // Show an import upload form that submits to the same page, with GET parameter step=1
             wp_import_upload_form('admin.php?import=wprss_opml_importer&amp;step=1');
             break;
         case 1:
             // Check referer
             check_admin_referer('import-upload');
             // If the handle_upload function returns true
             if ($this->handle_upload()) {
                 // Get the uploaded file
                 $file = get_attached_file($this->id);
                 set_time_limit(0);
                 // Parse the File and Import the feeds
                 $this->parse_and_import($file);
             }
             break;
     }
     echo '</div>';
 }
开发者ID:kivivuori,项目名称:jotain,代码行数:41,代码来源:opml-importer.php

示例7: wp_crop_image

/**
 * Crop an Image to a given size.
 *
 * @since 2.1.0
 *
 * @param string|int $src_file The source file or Attachment ID.
 * @param int $src_x The start x position to crop from.
 * @param int $src_y The start y position to crop from.
 * @param int $src_w The width to crop.
 * @param int $src_h The height to crop.
 * @param int $dst_w The destination width.
 * @param int $dst_h The destination height.
 * @param int $src_abs Optional. If the source crop points are absolute.
 * @param string $dst_file Optional. The destination file to write to.
 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
 */
function wp_crop_image($src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false)
{
    if (is_numeric($src_file)) {
        // Handle int as attachment ID
        $src_file = get_attached_file($src_file);
    }
    $src = wp_load_image($src_file);
    if (!is_resource($src)) {
        return new WP_Error('error_loading_image', $src, $src_file);
    }
    $dst = wp_imagecreatetruecolor($dst_w, $dst_h);
    if ($src_abs) {
        $src_w -= $src_x;
        $src_h -= $src_y;
    }
    if (function_exists('imageantialias')) {
        imageantialias($dst, true);
    }
    imagecopyresampled($dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    imagedestroy($src);
    // Free up memory
    if (!$dst_file) {
        $dst_file = str_replace(basename($src_file), 'cropped-' . basename($src_file), $src_file);
    }
    $dst_file = preg_replace('/\\.[^\\.]+$/', '.jpg', $dst_file);
    if (imagejpeg($dst, $dst_file, apply_filters('jpeg_quality', 90, 'wp_crop_image'))) {
        return $dst_file;
    } else {
        return false;
    }
}
开发者ID:laiello,项目名称:cartonbank,代码行数:47,代码来源:image.php

示例8: ajax_change_slide_image

 /**
  * Change the slide image.
  *
  * This creates a copy of the selected (new) image and assigns the copy to our existing media file/slide.
  */
 public function ajax_change_slide_image()
 {
     if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'metaslider_changeslide')) {
         wp_die(json_encode(array('status' => 'fail', 'msg' => __("Security check failed. Refresh page and try again.", "ml-slider"))));
     }
     $slide_from = absint($_POST['slide_from']);
     $slide_to = absint($_POST['slide_to']);
     // find the paths for the image we want to change to
     // Absolute path
     $abs_path = get_attached_file($slide_to);
     $abs_path_parts = pathinfo($abs_path);
     $abs_file_directory = $abs_path_parts['dirname'];
     // Relative path
     $rel_path = get_post_meta($slide_to, '_wp_attached_file', true);
     $rel_path_parts = pathinfo($rel_path);
     $rel_file_directory = $rel_path_parts['dirname'];
     // old file name
     $file_name = $abs_path_parts['basename'];
     // new file name
     $dest_file_name = wp_unique_filename($abs_file_directory, $file_name);
     // generate absolute and relative paths for the new file name
     $dest_abs_path = trailingslashit($abs_file_directory) . $dest_file_name;
     $dest_rel_path = trailingslashit($rel_file_directory) . $dest_file_name;
     // make a copy of the image
     if (@copy($abs_path, $dest_abs_path)) {
         // update the path on our slide
         update_post_meta($slide_from, '_wp_attached_file', $dest_rel_path);
         wp_update_attachment_metadata($slide_from, wp_generate_attachment_metadata($slide_from, $dest_abs_path));
         update_attached_file($slide_from, $dest_rel_path);
         wp_die(json_encode(array('status' => 'success')));
     }
     wp_die(json_encode(array('status' => 'fail', 'msg' => __("File copy failed. Please check upload directory permissions.", "ml-slider"))));
 }
开发者ID:WordPressArt,项目名称:conisia,代码行数:38,代码来源:metaslide.class.php

示例9: testImageEditOverwriteConstant

 /**
  * @ticket 32171
  */
 public function testImageEditOverwriteConstant()
 {
     define('IMAGE_EDIT_OVERWRITE', true);
     include_once ABSPATH . 'wp-admin/includes/image-edit.php';
     $filename = DIR_TESTDATA . '/images/canola.jpg';
     $contents = file_get_contents($filename);
     $upload = wp_upload_bits(basename($filename), null, $contents);
     $id = $this->_make_attachment($upload);
     $_REQUEST['action'] = 'image-editor';
     $_REQUEST['context'] = 'edit-attachment';
     $_REQUEST['postid'] = $id;
     $_REQUEST['target'] = 'all';
     $_REQUEST['do'] = 'save';
     $_REQUEST['history'] = '[{"c":{"x":5,"y":8,"w":289,"h":322}}]';
     $ret = wp_save_image($id);
     $media_meta = wp_get_attachment_metadata($id);
     $sizes1 = $media_meta['sizes'];
     $_REQUEST['history'] = '[{"c":{"x":5,"y":8,"w":189,"h":322}}]';
     $ret = wp_save_image($id);
     $media_meta = wp_get_attachment_metadata($id);
     $sizes2 = $media_meta['sizes'];
     $file_path = dirname(get_attached_file($id));
     foreach ($sizes1 as $key => $size) {
         if ($sizes2[$key]['file'] !== $size['file']) {
             $files_that_shouldnt_exist[] = $file_path . '/' . $size['file'];
         }
     }
     foreach ($files_that_shouldnt_exist as $file) {
         $this->assertFileNotExists($file, 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.');
     }
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:34,代码来源:MediaEdit.php

示例10: it_regenerate_wp_images

 function it_regenerate_wp_images()
 {
     return false;
     set_time_limit(0);
     echo "<pre>";
     echo "Regenerating thumbnails...\n";
     $args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null);
     $attachments = get_posts($args);
     if ($attachments) {
         echo count($attachments) . " images were found.\n";
         foreach ($attachments as $attachment) {
             $full_size_path = get_attached_file($attachment->ID);
             if (false === $full_size_path || !file_exists($full_size_path)) {
                 echo "Image ID " . $attachment->ID . " was not found.\n";
                 continue;
             }
             $meta_data = wp_generate_attachment_metadata($attachment->ID, $full_size_path);
             if (is_wp_error($meta_data)) {
                 echo "Image ID " . $attachment->ID . " raised an error: " . $mata_data->get_error_message() . "\n";
                 continue;
             }
             if (empty($meta_data)) {
                 echo "Image ID " . $attachment->ID . " failed with unknown reason\n";
                 continue;
             }
             wp_update_attachment_metadata($attachment->ID, $meta_data);
         }
         echo "Done.";
     }
     echo "</pre>";
 }
开发者ID:hungrig4leben,项目名称:my-gp,代码行数:31,代码来源:intheme-utils.php

示例11: circleflip_make_missing_intermediate_size

 /** generate new image sizes for old uploads
  * 
  * @param mixed $out
  * @param int $id
  * @param string|array $size
  * @return mixed
  */
 function circleflip_make_missing_intermediate_size($out, $id, $size)
 {
     $skip_sizes = array('full', 'large', 'medium', 'thumbnail', 'thumb');
     if (is_array($size) || in_array($size, $skip_sizes)) {
         return $out;
     }
     // the size exists and the attachment doesn't have a pre-generated file of that size
     // or the intermediate size defintion changed ( during development )
     if (circleflip_intermediate_size_exists($size) && (!circleflip_image_has_intermediate_size($id, $size) || circleflip_has_intermediate_size_changed($id, $size))) {
         // get info registerd by add_image_size
         $size_info = circleflip_get_intermediate_size_info($size);
         // get path to the original file
         $file_path = get_attached_file($id);
         // resize the image
         $resized_file = image_make_intermediate_size($file_path, $size_info['width'], $size_info['height'], $size_info['crop']);
         if ($resized_file) {
             // we have a resized image, get the attachment metadata and add the new size to it
             $metadata = wp_get_attachment_metadata($id);
             $metadata['sizes'][$size] = $resized_file;
             if (wp_update_attachment_metadata($id, $metadata)) {
                 // update succeded, call image_downsize again , DRY
                 return image_downsize($id, $size);
             }
         } else {
             // failed to generate the resized image
             // call image_downsize with `full` to prevent infinit loop
             return image_downsize($id, 'full');
         }
     }
     // pre-existing intermediate size
     return $out;
 }
开发者ID:purgesoftwares,项目名称:purges,代码行数:39,代码来源:WP-Make-Missing-Sizes.php

示例12: add_zipped_font

 function add_zipped_font()
 {
     //check if referer is ok
     if (function_exists('check_ajax_referer')) {
         if (check_ajax_referer('redux_file_upload_nonce', 'nonce', false) == false) {
             exit("Error : Your page has been expired");
         }
     }
     //check if capability is ok
     $cap = apply_filters('brad_file_upload_capability', 'update_plugins');
     if (!current_user_can($cap)) {
         exit("Error : Using this feature is reserved for Super Admins. You unfortunately don't have the necessary permissions.");
     }
     //get the file path of the zip file
     $attachment = $_POST['attachment'];
     $path = realpath(get_attached_file($attachment));
     $unzipped = $this->zip_flatten($path, array('\\.eot', '\\.svg', '\\.ttf', '\\.woff', '\\.css', '.json'));
     // if we were able to unzip the file and save it to our temp folder extract the svg file
     if ($unzipped) {
         $this->create_config();
     }
     //if we got no name for the font dont add it and delete the temp folder
     if ($this->font_name == 'empty') {
         $this->delete_folder($this->paths['tempdir']);
         exit('Error : Was not able to retrieve the Font name from your Uploaded Folder');
     }
     $response = array('name' => $this->font_name, 'prefix' => $this->font_prefix, 'css_url' => trailingslashit(trailingslashit($this->paths['fonturl']) . $this->font_name) . $this->css_file, 'css_file' => trailingslashit(trailingslashit($this->paths['fontdir']) . $this->font_name) . $this->css_file);
     // response output
     echo json_encode($response);
     exit;
 }
开发者ID:jmead,项目名称:trucell-cms,代码行数:31,代码来源:brad_iconfont.php

示例13: wp_generate_attachment_metadata

 public function wp_generate_attachment_metadata($metadata, $attachment_id)
 {
     $attachment = get_attached_file($attachment_id);
     if (!preg_match('!^image/!', get_post_mime_type($attachment_id)) || !file_is_displayable_image($attachment)) {
         return $metadata;
     }
     $image_sizes = Helper::get_image_sizes();
     foreach ($image_sizes as $size_name => $size_attributes) {
         if (!empty($metadata['sizes'][$size_name])) {
             continue;
         }
         $image = wp_get_image_editor($attachment);
         if (is_wp_error($image)) {
             continue;
         }
         $resized = $image->resize($size_attributes['width'], $size_attributes['height'], $size_attributes['crop']);
         $image_size = $image->get_size();
         if (!is_wp_error($resized) && !empty($image_size)) {
             $filename = wp_basename($image->generate_filename());
             $extension = pathinfo($filename, PATHINFO_EXTENSION);
             $mime_type = $this->get_mime_type($extension);
             $metadata['sizes'][$size_name] = array('file' => $filename, 'width' => $image_size['width'], 'height' => $image_size['height'], 'mime-type' => $mime_type);
         }
     }
     return $metadata;
 }
开发者ID:brutalenemy666,项目名称:carbon-image-library,代码行数:26,代码来源:WP_Media.php

示例14: dispatch

 /**
  * Registered callback function for the Lightspeed Importer
  *
  * Manages the separate stages of the import process
  */
 function dispatch()
 {
     $this->header();
     // This all from the WordPress Importer plugin, handles most cases
     $step = empty($_GET['step']) ? 0 : (int) $_GET['step'];
     switch ($step) {
         case 0:
             $this->greet();
             break;
         case 1:
             check_admin_referer('import-lightspeed-upload');
             $this->language = isset($_POST['lightspeed_language']) && $_POST['lightspeed_language'] !== '' ? $_POST['lightspeed_language'] : $this->defaults['lightspeed_language'];
             $result = $this->import();
             if (is_wp_error($result)) {
                 echo $result->get_error_message();
             }
             break;
         case 2:
             check_admin_referer('import-lightspeed');
             $this->fetch_attachments = !empty($_POST['fetch_attachments']) && $this->allow_fetch_attachments();
             $this->id = (int) $_POST['import_id'];
             // Provides the actual file upload form
             $file = get_attached_file($this->id);
             set_time_limit(0);
             $this->import($file);
             break;
     }
     $this->footer();
 }
开发者ID:Willemdumee,项目名称:WordPress-Lightspeed-Importer,代码行数:34,代码来源:class-lightspeed-importer.php

示例15: dc_document_shortcode

/**
 * The default mimetype match is for "application/*". For other types, you
 * will need to specifically override that attribute.
 * Examples:
 *
 * Just .XLS files:
 *   [documents ext="xls"]
 *
 * All .DOC, .DOCX, or .PDF files:
 *   [documents ext="doc,docx,pdf"]
 * 
 * Only 'video' types with a .MOV extension:
 *   [documents mimetype="video" ext="mov"]
 * 
 * Just application/pdf mimetypes:
 *   [documents mimetype="application/pdf"]
 */
function dc_document_shortcode($atts)
{
    extract(shortcode_atts(array('mimetype' => 'application', 'ext' => null), $atts));
    $mime = "&post_mime_type={$mimetype}";
    $kids =& get_children('post_type=attachment&post_parent=' . get_the_id() . $mime);
    if (empty($kids)) {
        return '';
    }
    $exts = array();
    if ($ext) {
        $exts = explode(',', $ext);
        $exts = array_map('trim', $exts);
        $exts = array_map('strtolower', $exts);
    }
    $documents = '';
    foreach ($kids as $id => $doc) {
        $url = wp_get_attachment_url($id);
        $file = get_attached_file($id);
        $filetype = wp_check_filetype($file);
        $file_ext = strtolower($filetype['ext']);
        if (count($exts) && !in_array($file_ext, $exts)) {
            // Not in list of requested extensions. Skip it!
            continue;
        }
        $name = $doc->post_title;
        $mime = sanitize_title_with_dashes($file_ext);
        $documents .= "<li class='{$mime}'><a href='{$url}'>{$name}</a></li>\n";
    }
    if (!empty($documents)) {
        // Wrap it up:
        $documents = "<ul class='dc_documents'>\n" . $documents;
        $documents .= "</ul>\n";
    }
    return $documents;
}
开发者ID:sharof2000,项目名称:documents-shortcode,代码行数:52,代码来源:documents-shortcode.php


注:本文中的get_attached_file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。