本文整理汇总了PHP中get_post_mime_type函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_mime_type函数的具体用法?PHP get_post_mime_type怎么用?PHP get_post_mime_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_mime_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hybrid_get_content_template
/**
* Loads a post content template based off the post type and/or the post format. This functionality is
* not feasible with the WordPress get_template_part() function, so we have to rely on some custom logic
* and locate_template().
*
* Note that using this function assumes that you're creating a content template to handle attachments.
* This filter must be removed since we're bypassing the WP template hierarchy and focusing on templates
* specific to the content.
*
* @since 1.6.0
* @access public
* @return string
*/
function hybrid_get_content_template()
{
/* Set up an empty array and get the post type. */
$templates = array();
$post_type = get_post_type();
/* Assume the theme developer is creating an attachment template. */
if ('attachment' === $post_type) {
remove_filter('the_content', 'prepend_attachment');
$mime_type = get_post_mime_type();
list($type, $subtype) = false !== strpos($mime_type, '/') ? explode('/', $mime_type) : array($mime_type, '');
$templates[] = "content-attachment-{$type}.php";
$templates[] = "content/attachment-{$type}.php";
}
/* If the post type supports 'post-formats', get the template based on the format. */
if (post_type_supports($post_type, 'post-formats')) {
/* Get the post format. */
$post_format = get_post_format() ? get_post_format() : 'standard';
/* Template based off post type and post format. */
$templates[] = "content-{$post_type}-{$post_format}.php";
$templates[] = "content/{$post_type}-{$post_format}.php";
/* Template based off the post format. */
$templates[] = "content-{$post_format}.php";
$templates[] = "content/{$post_format}.php";
}
/* Template based off the post type. */
$templates[] = "content-{$post_type}.php";
$templates[] = "content/{$post_type}.php";
/* Fallback 'content.php' template. */
$templates[] = 'content.php';
$templates[] = 'content/content.php';
/* Allow devs to filter the content template hierarchy. */
$templates = apply_filters('hybrid_content_template_hierarchy', $templates);
/* Apply filters and return the found content template. */
include apply_filters('hybrid_content_template', locate_template($templates, false, false));
}
示例2: sfc_media_find_images
function sfc_media_find_images($post, $content = '')
{
if (empty($content)) {
$content = apply_filters('the_content', $post->post_content);
}
$images = array();
// we get the post thumbnail, put it first in the image list
if (current_theme_supports('post-thumbnails') && has_post_thumbnail($post->ID)) {
$thumbid = get_post_thumbnail_id($post->ID);
$att = wp_get_attachment_image_src($thumbid, 'full');
if (!empty($att[0])) {
$images[] = $att[0];
}
}
if (is_attachment() && preg_match('!^image/!', get_post_mime_type($post))) {
$images[] = wp_get_attachment_url($post->ID);
}
// now search for images in the content itself
if (preg_match_all('/<img\\s+(.+?)>/i', $content, $matches)) {
foreach ($matches[1] as $match) {
foreach (wp_kses_hair($match, array('http')) as $attr) {
$img[strtolower($attr['name'])] = $attr['value'];
}
if (isset($img['src'])) {
if (!isset($img['class']) || isset($img['class']) && false === straipos($img['class'], apply_filters('sfc_img_exclude', array('wp-smiley')))) {
// ignore smilies
if (!in_array($img['src'], $images) && strpos($img['src'], 'fbcdn.net') === false && strpos($img['src'], '/plugins/') === false) {
$images[] = $img['src'];
}
}
}
}
}
return $images;
}
示例3: 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;
}
示例4: should_resize
/**
* Check whether Image should be resized or not
*
* @param string $params
* @param string $action
*
* @return bool
*/
private function should_resize($id = '')
{
//If resizing not enabled, or if both max width and height is set to 0, return
if (!$this->resize_enabled || $this->max_w == 0 && $this->max_h == 0) {
return false;
}
$file_path = get_attached_file($id);
if (!empty($file_path)) {
// Skip: if "noresize" is included in the filename, Thanks to Imsanity
if (strpos($file_path, 'noresize') !== false) {
return false;
}
//If file doesn't exists, return
if (!file_exists($file_path)) {
return false;
}
}
//Check for a supported mime type
global $wpsmushit_admin;
//Get image mime type
$mime = get_post_mime_type($id);
$mime_supported = in_array($mime, $wpsmushit_admin->mime_types);
//If type of upload doesn't matches the criteria return
if (!empty($mime) && !($mime_supported = apply_filters('wp_smush_resmush_mime_supported', $mime_supported, $mime))) {
return false;
}
//Check if already resized
$resize_meta = get_post_meta($id, WP_SMUSH_PREFIX . 'resize_savings', true);
if (!empty($resize_meta)) {
return false;
}
return true;
}
示例5: compress_attachment
public function compress_attachment($metadata, $attachment_id)
{
$mime_type = get_post_mime_type($attachment_id);
$tiny_metadata = new Tiny_Metadata($attachment_id);
if ($this->compressor === null || strpos($mime_type, 'image/') !== 0) {
return $metadata;
}
$path_info = pathinfo($metadata['file']);
$upload_dir = wp_upload_dir();
$prefix = $upload_dir['basedir'] . '/' . $path_info['dirname'] . '/';
if (!$tiny_metadata->is_compressed()) {
try {
$response = $this->compressor->compress_file("{$prefix}{$path_info['basename']}");
$tiny_metadata->add_response($response);
} catch (Tiny_Exception $e) {
$tiny_metadata->add_exception($e);
}
}
$settings = $this->settings->get_sizes();
foreach ($metadata['sizes'] as $size => $info) {
if (isset($settings[$size]) && $settings[$size]['tinify'] && !$tiny_metadata->is_compressed($size)) {
try {
$response = $this->compressor->compress_file("{$prefix}{$info['file']}");
$tiny_metadata->add_response($response, $size);
} catch (Tiny_Exception $e) {
$tiny_metadata->add_exception($e, $size);
}
}
}
$tiny_metadata->update();
return $metadata;
}
示例6: render_file
function render_file($id = null)
{
if (!$id) {
echo "";
return;
}
// vars
$file_src = wp_get_attachment_url($id);
preg_match("~[^/]*\$~", $file_src, $file_name);
$class = "active";
?>
<ul class="hl">
<li data-mime="<?php
echo get_post_mime_type($id);
?>
">
<img class="acf-file-icon" src="<?php
echo wp_mime_type_icon($id);
?>
" alt=""/>
</li>
<li>
<span class="acf-file-name"><?php
echo $file_name[0];
?>
</span><br />
<a href="javascript:;" class="acf-file-delete"><?php
_e('Remove File', 'acf');
?>
</a>
</li>
</ul>
<?php
}
示例7: wp_generate_attachment_metadata
/**
* wp_generate_attachment_metadata() - Generate post Image attachment Metadata
*
* @package WordPress
* @internal Missing Long Description
* @param int $attachment_id Attachment Id to process
* @param string $file Filepath of the Attached image
* @return mixed Metadata for attachment
*
*/
function wp_generate_attachment_metadata($attachment_id, $file)
{
$attachment = get_post($attachment_id);
$metadata = array();
if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) {
$imagesize = getimagesize($file);
$metadata['width'] = $imagesize[0];
$metadata['height'] = $imagesize[1];
list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']);
$metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'";
$metadata['file'] = $file;
// make thumbnails and other intermediate sizes
$sizes = array('thumbnail', 'medium');
$sizes = apply_filters('intermediate_image_sizes', $sizes);
foreach ($sizes as $size) {
$resized = image_make_intermediate_size($file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop"));
if ($resized) {
$metadata['sizes'][$size] = $resized;
}
}
// fetch additional metadata from exif/iptc
$image_meta = wp_read_image_metadata($file);
if ($image_meta) {
$metadata['image_meta'] = $image_meta;
}
}
return apply_filters('wp_generate_attachment_metadata', $metadata);
}
示例8: grayscale_check_grayscale_image
function grayscale_check_grayscale_image($metadata, $attachment_id)
{
global $_wp_additional_image_sizes;
$attachment = get_post($attachment_id);
if (preg_match('!image!', get_post_mime_type($attachment))) {
require_once 'class-grayscale-image-editor.php';
foreach ($_wp_additional_image_sizes as $size => $size_data) {
if (isset($size_data['grayscale']) && $size_data['grayscale']) {
if (is_array($metadata['sizes']) && isset($metadata['sizes'][$size])) {
$file = pathinfo(get_attached_file($attachment_id));
$filename = $file['dirname'] . '/' . $metadata['sizes'][$size]['file'];
$metadata['sizes'][$size . '-gray'] = $metadata['sizes'][$size];
} else {
// this size has no image attached, probably because the original is too small
// create the grayscale image from the original file
$file = wp_upload_dir();
$filename = $file['basedir'] . '/' . $metadata['file'];
$metadata['sizes'][$size . '-gray'] = array('width' => $metadata['width'], 'height' => $metadata['height']);
}
$image = new Grayscale_Image_Editor($filename);
$image->load();
$image->make_grayscale();
$result = $image->save($image->generate_filename('gray'));
$metadata['sizes'][$size . '-gray']['file'] = $result['file'];
}
}
}
return $metadata;
}
示例9: cherry_attachment_is_video
/**
* Check if the attachment is a 'video'.
*
* @author Justin Tadlock <justin@justintadlock.com>
* @author Cherry Team <support@cherryframework.com>
* @since 4.0.0
* @param int $post_id Attachment ID.
* @return bool
*/
function cherry_attachment_is_video($post_id = null)
{
$post_id = null === $post_id ? get_the_ID() : $post_id;
$mime_type = get_post_mime_type($post_id);
list($type, $subtype) = false !== strpos($mime_type, '/') ? explode('/', $mime_type) : array($mime_type, '');
return 'video' === $type ? true : false;
}
示例10: compress
private function compress($metadata, $attachment_id)
{
$mime_type = get_post_mime_type($attachment_id);
$tiny_metadata = new Tiny_Metadata($attachment_id, $metadata);
if ($this->settings->get_compressor() === null || strpos($mime_type, 'image/') !== 0) {
return array($tiny_metadata, null);
}
$success = 0;
$failed = 0;
$compressor = $this->settings->get_compressor();
$active_tinify_sizes = $this->settings->get_active_tinify_sizes();
$uncompressed_sizes = $tiny_metadata->get_uncompressed_sizes($active_tinify_sizes);
foreach ($uncompressed_sizes as $uncompressed_size) {
try {
$tiny_metadata->add_request($uncompressed_size);
$tiny_metadata->update();
$resize = $tiny_metadata->is_resizable($uncompressed_size) ? $this->settings->get_resize_options() : false;
$response = $compressor->compress_file($tiny_metadata->get_filename($uncompressed_size), $resize);
$tiny_metadata->add_response($response, $uncompressed_size);
$tiny_metadata->update();
$success++;
} catch (Tiny_Exception $e) {
$tiny_metadata->add_exception($e, $uncompressed_size);
$tiny_metadata->update();
$failed++;
}
}
return array($tiny_metadata, array('success' => $success, 'failed' => $failed));
}
示例11: __addRoutes
/**
* Adds all routes to the existing HTTP API instance
*/
protected function __addRoutes()
{
// Regenerate all sizes for all images
$this->http_api->post('regenerate-all(/)', function () {
// Set time limit of 30 minutes
set_time_limit(60 * 30);
$response = [];
$query = new \WP_Query(['fields' => 'ids', 'post_type' => 'attachment', 'post_status' => 'inherit', 'numberposts' => -1]);
if ($query->posts) {
foreach ($query->posts as $id) {
if (strpos(get_post_mime_type($id), 'image/') !== false) {
$image = new Image($id);
$response[] = ['id' => $id, 'status' => $image->generateAllSizes()];
}
}
}
return $response;
});
// Returns status about all sizes or a single one, for a single image
$this->http_api->get(':id/status(/:size)(/)', function ($id, $size = null) {
$image = new Image($id);
return $image->getStatus($size);
});
// Generate all sizes for a single image
$this->http_api->post(':id/generate-all(/)', function ($id) {
$image = new Image($id);
return $image->generateAllSizes();
});
// Generate a single image size
$this->http_api->post(':id/generate/:size(/)', function ($id, $size) {
$image = new Image($id);
return $image->generateSize($size);
});
}
示例12: hybrid_attachment_is_video
/**
* Checks if the current post has a mime type of 'video'.
*
* @since 1.6.0
* @access public
* @param int $post_id
* @return bool
*/
function hybrid_attachment_is_video($post_id = 0)
{
$post_id = empty($post_id) ? get_the_ID() : $post_id;
$mime = get_post_mime_type($post_id);
$mime_type = explode('/', $mime);
return 'video' == array_shift($mime_type) ? true : false;
}
示例13: stormbringer_body_class
/**
* Body Class - Thanks to Theme Hyprid (http://themehybrid.com/)
*/
function stormbringer_body_class($classes = '')
{
global $wp_query;
global $current_user;
// User role
$current_user->ID;
$user = new WP_User($current_user->ID);
// $user->roles
foreach ($user->roles as $role) {
$classes[] = 'role-' . $role;
}
/* Text direction (which direction does the text flow). */
$classes[] = 'wordpress';
$classes[] = get_bloginfo('text_direction');
$classes[] = get_locale();
/* Check if the current theme is a parent or child theme. */
$classes[] = is_child_theme() ? 'child-theme' : 'parent-theme';
/* Multisite check adds the 'multisite' class and the blog ID. */
if (is_multisite()) {
$classes[] = 'multisite';
$classes[] = 'blog-' . get_current_blog_id();
}
/* Date classes. */
$time = time() + get_option('gmt_offset') * 3600;
$classes[] = strtolower(gmdate('\\yY \\mm \\dd \\hH l', $time));
/* Is the current user logged in. */
$classes[] = is_user_logged_in() ? 'logged-in' : 'logged-out';
/* WP admin bar. */
if (is_admin_bar_showing()) {
$classes[] = 'admin-bar';
}
/* Merge base contextual classes with $classes. */
$classes = array_merge($classes, stormbringer_get_context());
/* Singular post (post_type) classes. */
if (is_singular()) {
/* Get the queried post object. */
$post = get_queried_object();
/* Checks for custom template. */
$template = str_replace(array("{$post->post_type}-template-", "{$post->post_type}-", '.php'), '', get_post_meta(get_queried_object_id(), "_wp_{$post->post_type}_template", true));
if (!empty($template)) {
$classes[] = "{$post->post_type}-template-{$template}";
}
/* Post format. */
if (current_theme_supports('post-formats') && post_type_supports($post->post_type, 'post-formats')) {
$post_format = get_post_format(get_queried_object_id());
$classes[] = empty($post_format) || is_wp_error($post_format) ? "{$post->post_type}-format-standard" : "{$post->post_type}-format-{$post_format}";
}
/* Attachment mime types. */
if (is_attachment()) {
foreach (explode('/', get_post_mime_type()) as $type) {
$classes[] = "attachment-{$type}";
}
}
}
/* Paged views. */
if ((($page = $wp_query->get('paged')) || ($page = $wp_query->get('page'))) && $page > 1) {
$classes[] = 'paged paged-' . intval($page);
}
return $classes;
}
示例14: bpmn_media_to_shortcode
function bpmn_media_to_shortcode($html, $id, $attachment)
{
$mime = get_post_mime_type($id);
if ($mime == 'application/bpmn+xml') {
$html = '[bpmn url="' . $attachment['url'] . '"]';
}
return $html;
}
示例15: bpmn_media_to_editor
function bpmn_media_to_editor($html, $id, $attachment)
{
$mime = get_post_mime_type($id);
if ($mime == 'application/bpmn+xml') {
$html = bpmnio_file_html($attachment['url']);
}
return $html;
}