本文整理汇总了PHP中wp_attachment_is_image函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_attachment_is_image函数的具体用法?PHP wp_attachment_is_image怎么用?PHP wp_attachment_is_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_attachment_is_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: plusify_content
/**
*
* @param string $content
* @return string
*/
function plusify_content($content)
{
include_once ATTACHMENTS_PP_PATH . 'class-library.php';
// only handle attachments that aren't already embedded (namely, not images)
if (is_attachment() && !wp_attachment_is_image()) {
$embed = AttachmentsPPLib::get_embedded_attachment();
if (!empty($embed)) {
// remove "attachment" class from $content -- it will be
// included in the outer div around the embedder & existing content
$regex = '#(.*)<(p|div)\\s*class=[\'"]([-_A-Za-z ]*)attachment([-_A-Za-z ]*)[\'"]>(.*)</\\2>(.*)#is';
if (preg_match($regex, $content, $matches)) {
$matches[3] = trim($matches[3]);
$matches[4] = trim($matches[4]);
$classes = '';
if (!empty($matches[3]) || !empty($matches[4])) {
if (!empty($matches[3]) && !empty($matches[4])) {
$classes = ' class="' . $matches[3] . ' ' . $matches[4] . '"';
} else {
$classes = ' class="' . $matches[3] . $matches[4] . '"';
}
}
$content = $matches[1] . '<' . $matches[2] . $classes . '>' . $matches[5] . '</' . $matches[2] . '>' . $matches[6];
}
$content = '<div class="attachment">' . $embed . $content . '</div>';
}
}
// Returns the content.
return $content;
}
示例2: output
/**
* Check AM_MBF for description.
*
* @todo Set class on div to set if the image has been selected and get rid of $hide_upload_button and $hide_clear_button.
*
* @since 1.0.0
*/
public function output()
{
// Get the file id, 0 represents a new field.
$image_id = intval($this->value) > 0 ? intval($this->value) : 0;
$image_url = '';
$image_title = '';
$class_icon = '';
$hide_upload_button = $hide_clear_button = ' style="display:none;"';
// Make sure the selected image is valid.
if ($image_id > 0) {
$post = get_post($image_id);
if (isset($post) && wp_attachment_is_image($image_id)) {
$image_url = wp_get_attachment_thumb_url($image_id);
$image_title = $post->post_title;
} else {
$this->error = __(sprintf('Selected Image (ID:%1$d) is invalid.', $image_id), 'am-cpts');
$class_icon = ' invalid';
}
$hide_clear_button = '';
} else {
$hide_upload_button = '';
}
// Text used by wp.media frame.
$wp_media_data = sprintf(' data-title="%1$s" data-button="%2$s"', esc_attr__('Choose an Image', 'am-cpts'), esc_attr__('Use this Image', 'am-cpts'));
return sprintf('
<div%11$s>
<input name="%2$s" type="hidden" class="meta-box-upload-image" value="%1$d"%12$s />
<img src="%10$s" class="meta-box-preview-image%3$s" title="%7$s" alt="%6$s"%5$s />
<a href="#" class="meta-box-upload-image-button button"%4$s%13$s>%8$s</a>
<span class="meta-box-image-title"%5$s>%6$s</span>
<a href="#" class="meta-box-clear-image-button"%5$s>%9$s</a>
</div>', esc_attr($image_id), esc_attr($this->name), $class_icon, $hide_upload_button, $hide_clear_button, isset($this->error) ? esc_html($this->error) : $image_title, esc_attr__('Selected Image', 'am-cpts'), esc_html__('Choose Image', 'am-cpts'), esc_html__('Remove Image', 'am-cpts'), esc_url($image_url), $this->get_classes('meta-box-image'), $this->get_data_atts(), $wp_media_data);
}
示例3: format_value
/**
* Format the value of the property before it's returned
* to WordPress admin or the site.
*
* @param mixed $value
* @param string $slug
* @param int $post_id
*
* @return mixed
*/
public function format_value($value, $slug, $post_id)
{
if (is_numeric($value)) {
$meta = wp_get_attachment_metadata($value);
if (isset($meta) && !empty($meta)) {
$att = get_post($value);
$mine = ['alt' => trim(strip_tags(get_post_meta($value, '_wp_attachment_image_alt', true))), 'caption' => trim(strip_tags($att->post_excerpt)), 'description' => trim(strip_tags($att->post_content)), 'id' => intval($value), 'is_image' => (bool) wp_attachment_is_image($value), 'title' => esc_html($att->post_title), 'url' => wp_get_attachment_url($value)];
$meta = is_array($meta) ? $meta : ['file' => $meta];
if (isset($meta['sizes'])) {
foreach (array_keys($meta['sizes']) as $size) {
if ($src = wp_get_attachment_image_src($mine['id'], $size)) {
$meta['sizes'][$size]['url'] = $src[0];
}
}
}
return (object) array_merge($meta, $mine);
}
return (int) $value;
}
if (is_array($value)) {
foreach ($value as $k => $v) {
$value[$k] = $this->format_value($v, $slug, $post_id);
}
return $value;
}
if (is_object($value) && !isset($value->url)) {
return;
}
return $value;
}
示例4: attach_html
public static function attach_html($attach_id, $type = NULL)
{
if (!$type) {
$type = isset($_GET['type']) ? $_GET['type'] : 'image';
}
$attachment = get_post($attach_id);
if (!$attachment) {
return;
}
if (wp_attachment_is_image($attach_id)) {
$image = wp_get_attachment_image_src($attach_id, 'thumbnail');
$image = $image[0];
} else {
$image = wp_mime_type_icon($attach_id);
}
$html = '<li class="wpuf-image-wrap thumbnail">';
$html .= sprintf('<div class="attachment-name"><img src="%s" alt="%s" /></div>', $image, esc_attr($attachment->post_title));
if (wpuf_get_option('image_caption', 'wpuf_general', 'off') == 'on') {
$html .= '<div class="wpuf-file-input-wrap">';
$html .= sprintf('<input type="text" name="wpuf_files_data[%d][title]" value="%s" placeholder="%s">', $attach_id, esc_attr($attachment->post_title), __('Title', 'wpuf'));
$html .= sprintf('<textarea name="wpuf_files_data[%d][caption]" placeholder="%s">%s</textarea>', $attach_id, __('Caption', 'wpuf'), esc_textarea($attachment->post_excerpt));
$html .= sprintf('<textarea name="wpuf_files_data[%d][desc]" placeholder="%s">%s</textarea>', $attach_id, __('Description', 'wpuf'), esc_textarea($attachment->post_content));
$html .= '</div>';
}
$html .= sprintf('<input type="hidden" name="wpuf_files[%s][]" value="%d">', $type, $attach_id);
$html .= sprintf('<div class="caption"><a href="#" class="btn btn-danger btn-small attachment-delete" data-attach_id="%d">%s</a></div>', $attach_id, __('Delete', 'wpuf'));
$html .= '</li>';
return $html;
}
示例5: yoimg_media_row_actions
function yoimg_media_row_actions($actions, $post, $detached)
{
if (wp_attachment_is_image($post->ID) && current_user_can('edit_post', $post->ID)) {
$actions['yoimg_crop'] = yoimg_get_edit_image_anchor($post->ID);
}
return $actions;
}
示例6: 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;
}
示例7: get_title
function get_title()
{
if (wp_attachment_is_image($this->item->ID)) {
return wp_get_attachment_image($this->item->ID, 'thumbnail', false);
}
return get_the_title($this->item);
}
示例8: jbst_posttype_set_classes
function jbst_posttype_set_classes()
{
if (wp_attachment_is_image()) {
return 'image-attachment';
}
return 'site-content';
}
示例9: fifteen_scripts
function fifteen_scripts()
{
wp_enqueue_style('fifteen-basic-style', get_stylesheet_uri());
if (function_exists('of_get_option') && of_get_option('sidebar-layout', true) != 1) {
if (of_get_option('sidebar-layout', true) == 'right') {
wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/content-sidebar.css");
} else {
wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/sidebar-content.css");
}
} else {
wp_enqueue_style('fifteen-layout', get_template_directory_uri() . "/css/layouts/content-sidebar.css");
}
wp_enqueue_style('fifteen-bootstrap-style', get_template_directory_uri() . "/css/bootstrap/bootstrap.min.css", array('fifteen-layout'));
wp_enqueue_style('fifteen-main-skin', get_template_directory_uri() . "/css/skins/default.css", array('fifteen-layout', 'fifteen-bootstrap-style'));
wp_enqueue_script('fifteen-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true);
wp_enqueue_script('fifteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true);
wp_enqueue_script('fifteen-bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'));
wp_enqueue_script('fifteen-custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'));
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
if (is_singular() && wp_attachment_is_image()) {
wp_enqueue_script('fifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array('jquery'), '20120202');
}
}
示例10: anno_media_send_to_editor
function anno_media_send_to_editor($html, $id, $attachment)
{
if (!anno_is_article($_REQUEST['post_id'])) {
return $html;
}
$html = '';
$attachment_object = get_post($id);
if (!$attachment_object) {
return '';
}
// Attachment is not an image, insert it as a link
if (!wp_attachment_is_image($id)) {
//@TODO NEEDS TO BE CONVERTED TO THE TEXTORUM EXPECTED TAG
$html = '<span class="ext-link" xmlns:xlink="http://www.w3.org/1999/xlink" data-xmlel="ext-link" ext-link-type="uri" xlink:href="' . esc_url($attachment['url']) . '">' . $attachment['post_title'] . '</span> ';
} else {
if (!isset($attachment['display'])) {
$attachment['display'] = 'figure';
}
$img_data = wp_get_attachment_image_src($id, $attachment['image-size']);
$img_url = is_array($img_data) && isset($img_data[0]) ? $img_data[0] : '';
if (trim($attachment['display']) == 'figure') {
$meta = array('label' => '_anno_attachment_image_label', 'copyright_statement' => '_anno_attachment_image_copyright_statement', 'copyright_holder' => '_anno_attachment_image_copyright_holder', 'license' => '_anno_attachment_image_license');
foreach ($meta as $key => $meta_key) {
$attachment[$key] = get_post_meta($id, $meta_key, true);
}
if (!empty($attachment['url'])) {
$fig_uri = '<div class="uri" data-xmlel="uri" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . $attachment['url'] . '"></div>';
} else {
$fig_uri = '';
}
// Editor removes empty items, need this to be valid
$attachment['license'] = empty($attachment['license']) ? ' ' : $attachment['license'];
$html = '
<div class="fig" data-xmlel="fig">
<img src="' . esc_attr($img_url) . '" data-mce-src="' . esc_attr($img_url) . '" alt="' . esc_attr($attachment['image_alt']) . '" />
<div class="label" data-xmlel="label">' . $attachment['label'] . '</div>
<div class="caption" data-xmlel="caption">
<div class="p" data-xmlel="p">' . $attachment['post_excerpt'] . '</div>
</div>
<div class="media" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . esc_attr($img_url) . '" data-xmlel="media">
<span class="alt-text" data-xmlel="alt-text">' . $attachment['image_alt'] . '</span>
<span class="long-desc" data-xmlel="long-desc">' . $attachment['post_content'] . '</span>
' . $fig_uri . '
<div class="permissions" data-xmlel="permissions">
<span class="copyright-statement" data-xmlel="copyright-statement">' . $attachment['copyright_statement'] . '</span>
<span class="copyright-holder" data-xmlel="copyright-holder">' . $attachment['copyright_holder'] . '</span>
<div class="license" data-xmlel="license" license-type="creative-commons">
<span class="license-p" data-xmlel="license-p">' . $attachment['license'] . '</span>
</div>
</div>
</div>
<div _mce_bogus="1" class="clearfix"></div>
</div>';
} else {
$html = '<span class="inline-graphic" data-xmlel="inline-graphic" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' . esc_attr($img_url) . '"><img src="' . esc_url($img_url) . '" data-mce-src="' . esc_attr($img_url) . '" alt="' . esc_attr($attachment['image_alt']) . '" /></span><span> </span>';
}
}
return $html;
}
示例11: wck_preprocess_field_upload
function wck_preprocess_field_upload($field)
{
if ($field == '' || !is_numeric($field)) {
return false;
}
if (is_null(get_post($field))) {
return false;
}
if (wp_attachment_is_image($field)) {
$attachment = get_post($field);
// create array to hold value data
$src = wp_get_attachment_image_src($attachment->ID, 'full');
$value = array('id' => $attachment->ID, 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'url' => $src[0], 'width' => $src[1], 'height' => $src[2], 'sizes' => array());
// find all image sizes
$image_sizes = get_intermediate_image_sizes();
if ($image_sizes) {
foreach ($image_sizes as $image_size) {
// find src
$src = wp_get_attachment_image_src($attachment->ID, $image_size);
// add src
$value['sizes'][$image_size] = $src[0];
$value['sizes'][$image_size . '-width'] = $src[1];
$value['sizes'][$image_size . '-height'] = $src[2];
}
}
return $value;
} else {
$attachement = get_post($field);
return $attachement;
}
}
示例12: image_attachments
function image_attachments($image_size = 'large', $width_min = 0, $height_min = 0)
{
// Initialize images array; only fetch images for singular content, exit early and return an empty array otherwise
$images = [];
if (!is_singular()) {
return $images;
}
global $post;
// @TODO: use get_the_ID()
// Override default image size; for reference, Facebook likes large images (1200 x 630 pixels) and Twitter likes smaller ones (less than 1 Mb)
$image_size = apply_filters('ubik_seo_image_attachments_size', $image_size);
// Are we are dealing with an actual image attachment page?
if (wp_attachment_is_image()) {
// Get all metadata (includes mime type) and image source in the usual way
$attachment = wp_get_attachment_metadata($post->ID);
$image_src = wp_get_attachment_image_src($post->ID, $image_size);
// Is there an attachment of the desired size? Fill the mime type and appropriate height/width info
if (!empty($attachment['sizes'][$image_size])) {
$images[] = ['url' => $image_src[0], 'type' => $attachment['sizes'][$image_size]['mime-type'], 'width' => $attachment['sizes'][$image_size]['width'], 'height' => $attachment['sizes'][$image_size]['height']];
// Otherwise fallback to the default image size
} else {
$images[] = ['url' => $image_src[0], 'type' => get_post_mime_type($post->ID), 'width' => $image_src[1], 'height' => $image_src[2]];
}
// All other posts, pages, etc.
} else {
// Featured image/post thumbnail first; Facebook prioritizes larger images so this might not have much of an effect
if (has_post_thumbnail($post->ID)) {
$image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $image_size);
$images[] = ['url' => $image_src[0], 'type' => get_post_mime_type(get_post_thumbnail_id($post->ID)), 'width' => $image_src[1], 'height' => $image_src[2]];
}
// Get all images attachments sorted by date (oldest first)
$attachments = get_children(['post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'posts_per_page' => apply_filters('ubik_seo_image_attachments_limit', 20), 'orderby' => 'date', 'order' => 'ASC']);
// Cycle through all attachments and extract relevant image metadata
if (count($attachments) >= 1) {
foreach ($attachments as $attachment) {
$image_src = wp_get_attachment_image_src($attachment->ID, $image_size);
// Don't duplicate featured image
if (has_post_thumbnail($post->ID)) {
if ($image_src[0] !== $images[0]['url']) {
$images[] = ['url' => $image_src[0], 'type' => get_post_mime_type(get_post_thumbnail_id($post->ID)), 'width' => $image_src[1], 'height' => $image_src[2]];
}
} else {
$images[] = ['url' => $image_src[0], 'type' => get_post_mime_type($attachment->ID), 'width' => $image_src[1], 'height' => $image_src[2]];
}
}
}
}
// Restrict output based on width and height requirements
if ($images) {
for ($i = 0; $i < count($images); $i++) {
if ($images[$i]['width'] <= $width_min || $images[$i]['height'] <= $height_min) {
unset($images[$i]);
}
}
}
// Re-index array (removes gaps)
$images = array_values($images);
// Return an array of image attachment metadata: url, type (mime type; optional), width, and height; usage e.g. $images[0]['url']
return apply_filters('ubik_seo_image_attachments', $images);
}
示例13: ajax_create_slide
/**
* Create a new slide and echo the admin HTML
*/
public function ajax_create_slide()
{
// security check
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'metaslider_addslide')) {
echo "<tr><td colspan='2'>" . __("Security check failed. Refresh page and try again.", 'metaslider') . "</td></tr>";
wp_die();
}
$slider_id = absint($_POST['slider_id']);
$selection = $_POST['selection'];
if (is_array($selection) && count($selection) && $slider_id > 0) {
foreach ($selection as $slide_id) {
$this->set_slide($slide_id);
$this->set_slider($slider_id);
if ($this->slide_exists_in_slideshow($slider_id, $slide_id)) {
echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide already exists in slideshow.", 'metaslider') . "</td></tr>";
} else {
if (!$this->slide_is_unassigned_or_image_slide($slider_id, $slide_id)) {
echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide is not of type 'image'.", 'metaslider') . "</td></tr>";
} else {
if (!wp_attachment_is_image($slide_id)) {
echo "<tr><td colspan='2'>ID: {$slide_id} \"" . get_the_title($slide_id) . "\" - " . __("Failed to add slide. Slide is not an image.", 'metaslider') . "</td></tr>";
} else {
$this->tag_slide_to_slider();
$this->add_or_update_or_delete_meta($slide_id, 'type', 'image');
// override the width and height to kick off the AJAX image resizing on save
$this->settings['width'] = 0;
$this->settings['height'] = 0;
echo $this->get_admin_slide();
}
}
}
}
}
wp_die();
}
示例14: zacklive_scripts
/**
* Enqueue scripts and styles
*/
function zacklive_scripts()
{
// load zacklive styles
wp_enqueue_style('zacklive-style', get_stylesheet_uri());
// load bootstrap css
wp_enqueue_style('zacklive-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap/bootstrap.min.css');
// load bootstrap for WordPress css
wp_enqueue_style('zacklive-bootstrapwp', get_template_directory_uri() . '/assets/css/bootstrap-wp.css');
// load font awesome css
wp_enqueue_style('zacklive-fontawesome', get_template_directory_uri() . '/assets/css/FontAwesome/font-awesome.min.css', array(), '4.3.0', 'all');
// load bootstrap.js
wp_enqueue_script('zacklive-bootstrapjs', get_template_directory_uri() . '/assets/js/bootstrap/bootstrap.js', array('jquery'));
// load bootstrap-wp.js
wp_enqueue_script('zacklive-bootstrapwp', get_template_directory_uri() . '/assets/js/bootstrap-wp.js', array('jquery'));
// FitVid (responsive video)
wp_enqueue_script('zacklive-fitvids', get_template_directory_uri() . '/assets/js/FitVids.js-master/jquery.fitvids.js', array('jquery'));
wp_enqueue_script('zacklive-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20130115', true);
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
//load keyboard-image-navigation.js
if (is_singular() && wp_attachment_is_image()) {
wp_enqueue_script('zacklive-keyboard-image-navigation', get_template_directory_uri() . '/assets/js/keyboard-image-navigation.js', array('jquery'), '20120202');
}
}
示例15: hoot_get_image_size_links
/**
* Returns a set of image attachment links based on size.
*
* @since 1.0.0
* @access public
* @return string
*/
function hoot_get_image_size_links()
{
/* If not viewing an image attachment page, return. */
if (!wp_attachment_is_image(get_the_ID())) {
return;
}
/* Set up an empty array for the links. */
$links = array();
/* Get the intermediate image sizes and add the full size to the array. */
$sizes = get_intermediate_image_sizes();
$sizes[] = 'full';
/* Loop through each of the image sizes. */
foreach ($sizes as $size) {
/* Get the image source, width, height, and whether it's intermediate. */
$image = wp_get_attachment_image_src(get_the_ID(), $size);
/* Add the link to the array if there's an image and if $is_intermediate (4th array value) is true or full size. */
if (!empty($image) && (true === $image[3] || 'full' == $size)) {
/* Translators: Media dimensions - 1 is width and 2 is height. */
$label = sprintf(__('%1$s × %2$s', 'chromatic'), number_format_i18n(absint($image[1])), number_format_i18n(absint($image[2])));
$links[] = sprintf('<a class="image-size-link">%s</a>', $label);
}
}
/* Join the links in a string and return. */
return join(' <span class="sep">/</span> ', $links);
}