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


PHP wp_attachment_is函数代码示例

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


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

示例1: barcelona_prevent_prepend_attachment

function barcelona_prevent_prepend_attachment($content)
{
    $post = get_post();
    if (!empty($post->post_type) && $post->post_type == 'attachment' && wp_attachment_is('image', $post)) {
        return '';
    }
    return $content;
}
开发者ID:yalmaa,项目名称:little-magazine,代码行数:8,代码来源:filters.php

示例2: __construct

 public function __construct()
 {
     global $cb_post_id;
     $subviews = array();
     if (wp_attachment_is('image', $cb_post_id)) {
         require_once CLEARBASE_DIR . '/views/subviews/class-subview-image.php';
         $subview_image = new Clearbase_Subview_Image();
         $subviews[$subview_image->ID()] = $subview_image;
     } else {
         //TODO implement specific subviews for other attachment types
         require_once CLEARBASE_DIR . '/views/subviews/class-subview-post.php';
         $subview_post = new Clearbase_Subview_Post();
         $subviews[$subview_post->ID()] = $subview_post;
     }
     parent::__construct($subviews);
 }
开发者ID:unity3software,项目名称:clearbase,代码行数:16,代码来源:class-view-attachment.php

示例3: get_video_metadata

/**
 * Retrieve the creation timestamp out of a video upon upload.
 *
 * @param array $metadata      An array of attachment meta data.
 * @param int   $attachment_id Current attachment ID.
 */
function get_video_metadata($metadata, $attachment_id)
{
    if (!wp_attachment_is('video', $attachment_id)) {
        return $metadata;
    }
    if (!class_exists('getID3', false)) {
        require_once ABSPATH . WPINC . '/ID3/getid3.php';
    }
    $file = get_attached_file($attachment_id);
    $id3 = new \getID3();
    $data = $id3->analyze($file);
    if (empty($metadata['created_timestamp'])) {
        $metadata['created_timestamp'] = wp_get_media_creation_timestamp($data);
    }
    return $metadata;
}
开发者ID:stevegrunwell,项目名称:parse-video-metadata,代码行数:22,代码来源:parse-video-metadata.php

示例4: get_oembed_response_data_rich

/**
 * Filters the oEmbed response data to return an iframe embed code.
 *
 * @since 4.4.0
 *
 * @param array   $data   The response data.
 * @param WP_Post $post   The post object.
 * @param int     $width  The requested width.
 * @param int     $height The calculated height.
 * @return array The modified response data.
 */
function get_oembed_response_data_rich($data, $post, $width, $height)
{
    $data['width'] = absint($width);
    $data['height'] = absint($height);
    $data['type'] = 'rich';
    $data['html'] = get_post_embed_html($width, $height, $post);
    // Add post thumbnail to response if available.
    $thumbnail_id = false;
    if (has_post_thumbnail($post->ID)) {
        $thumbnail_id = get_post_thumbnail_id($post->ID);
    }
    if ('attachment' === get_post_type($post)) {
        if (wp_attachment_is_image($post)) {
            $thumbnail_id = $post->ID;
        } else {
            if (wp_attachment_is('video', $post)) {
                $thumbnail_id = get_post_thumbnail_id($post);
                $data['type'] = 'video';
            }
        }
    }
    if ($thumbnail_id) {
        list($thumbnail_url, $thumbnail_width, $thumbnail_height) = wp_get_attachment_image_src($thumbnail_id, array($width, 99999));
        $data['thumbnail_url'] = $thumbnail_url;
        $data['thumbnail_width'] = $thumbnail_width;
        $data['thumbnail_height'] = $thumbnail_height;
    }
    return $data;
}
开发者ID:nxty2011,项目名称:WordPress,代码行数:40,代码来源:embed-functions.php

示例5: wp_ajax_send_attachment_to_editor

/**
 * Ajax handler for sending an attachment to the editor.
 *
 * Generates the HTML to send an attachment to the editor.
 * Backwards compatible with the media_send_to_editor filter
 * and the chain of filters that follow.
 *
 * @since 3.5.0
 */
function wp_ajax_send_attachment_to_editor()
{
    check_ajax_referer('media-send-to-editor', 'nonce');
    $attachment = wp_unslash($_POST['attachment']);
    $id = intval($attachment['id']);
    if (!($post = get_post($id))) {
        wp_send_json_error();
    }
    if ('attachment' != $post->post_type) {
        wp_send_json_error();
    }
    if (current_user_can('edit_post', $id)) {
        // If this attachment is unattached, attach it. Primarily a back compat thing.
        if (0 == $post->post_parent && ($insert_into_post_id = intval($_POST['post_id']))) {
            wp_update_post(array('ID' => $id, 'post_parent' => $insert_into_post_id));
        }
    }
    $rel = '';
    $url = empty($attachment['url']) ? '' : $attachment['url'];
    if (strpos($url, 'attachment_id') || get_attachment_link($id) == $url) {
        $rel = ' rel="attachment wp-att-' . $id . '"';
    }
    remove_filter('media_send_to_editor', 'image_media_send_to_editor');
    if ('image' === substr($post->post_mime_type, 0, 5)) {
        $align = isset($attachment['align']) ? $attachment['align'] : 'none';
        $size = isset($attachment['image-size']) ? $attachment['image-size'] : 'medium';
        $alt = isset($attachment['image_alt']) ? $attachment['image_alt'] : '';
        // No whitespace-only captions.
        $caption = isset($attachment['post_excerpt']) ? $attachment['post_excerpt'] : '';
        if ('' === trim($caption)) {
            $caption = '';
        }
        $title = '';
        // We no longer insert title tags into <img> tags, as they are redundant.
        $html = get_image_send_to_editor($id, $caption, $title, $align, $url, $rel, $size, $alt);
    } elseif (wp_attachment_is('video', $post) || wp_attachment_is('audio', $post)) {
        $html = stripslashes_deep($_POST['html']);
    } else {
        $html = isset($attachment['post_title']) ? $attachment['post_title'] : '';
        if (!empty($url)) {
            $html = '<a href="' . esc_url($url) . '"' . $rel . '>' . $html . '</a>';
        }
    }
    /** This filter is documented in wp-admin/includes/media.php */
    $html = apply_filters('media_send_to_editor', $html, $id, $attachment);
    wp_send_json_success($html);
}
开发者ID:hughnet,项目名称:WordPress,代码行数:56,代码来源:ajax-actions.php

示例6: prepend_attachment

/**
 * Wrap attachment in paragraph tag before content.
 *
 * @since 2.0.0
 *
 * @param string $content
 * @return string
 */
function prepend_attachment($content)
{
    $post = get_post();
    if (empty($post->post_type) || $post->post_type != 'attachment') {
        return $content;
    }
    if (wp_attachment_is('video', $post)) {
        $meta = wp_get_attachment_metadata(get_the_ID());
        $atts = array('src' => wp_get_attachment_url());
        if (!empty($meta['width']) && !empty($meta['height'])) {
            $atts['width'] = (int) $meta['width'];
            $atts['height'] = (int) $meta['height'];
        }
        if (has_post_thumbnail()) {
            $atts['poster'] = wp_get_attachment_url(get_post_thumbnail_id());
        }
        $p = wp_video_shortcode($atts);
    } elseif (wp_attachment_is('audio', $post)) {
        $p = wp_audio_shortcode(array('src' => wp_get_attachment_url()));
    } else {
        $p = '<p class="attachment">';
        // show the medium sized image representation of the attachment if available, and link to the raw file
        $p .= wp_get_attachment_link(0, 'medium', false);
        $p .= '</p>';
    }
    /**
     * Filters the attachment markup to be prepended to the post content.
     *
     * @since 2.0.0
     *
     * @see prepend_attachment()
     *
     * @param string $p The attachment HTML output.
     */
    $p = apply_filters('prepend_attachment', $p);
    return "{$p}\n{$content}";
}
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:45,代码来源:post-template.php

示例7: wp_attachment_is_image

/**
 * Checks if the attachment is an image.
 *
 * @since 2.1.0
 * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
 *              allowed WP_Post object to be passed.
 *
 * @param int|WP_Post $post Optional. Attachment ID. Default 0.
 * @return bool Whether the attachment is an image.
 */
function wp_attachment_is_image($post = 0)
{
    return wp_attachment_is('image', $post);
}
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:14,代码来源:post.php

示例8: edit_form_image_editor

/**
 * Displays the image and editor in the post editor
 *
 * @since 3.5.0
 */
function edit_form_image_editor($post)
{
    $open = isset($_GET['image-editor']);
    if ($open) {
        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    }
    $thumb_url = false;
    if ($attachment_id = intval($post->ID)) {
        $thumb_url = wp_get_attachment_image_src($attachment_id, array(900, 450), true);
    }
    $alt_text = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
    $att_url = wp_get_attachment_url($post->ID);
    ?>
	<div class="wp_attachment_holder">
	<?php 
    if (wp_attachment_is_image($post->ID)) {
        $image_edit_button = '';
        if (wp_image_editor_supports(array('mime_type' => $post->post_mime_type))) {
            $nonce = wp_create_nonce("image_editor-{$post->ID}");
            $image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>";
        }
        ?>

		<div class="imgedit-response" id="imgedit-response-<?php 
        echo $attachment_id;
        ?>
"></div>

		<div<?php 
        if ($open) {
            echo ' style="display:none"';
        }
        ?>
 class="wp_attachment_image" id="media-head-<?php 
        echo $attachment_id;
        ?>
">
			<p id="thumbnail-head-<?php 
        echo $attachment_id;
        ?>
"><img class="thumbnail" src="<?php 
        echo set_url_scheme($thumb_url[0]);
        ?>
" style="max-width:100%" alt="" /></p>
			<p><?php 
        echo $image_edit_button;
        ?>
</p>
		</div>
		<div<?php 
        if (!$open) {
            echo ' style="display:none"';
        }
        ?>
 class="image-editor" id="image-editor-<?php 
        echo $attachment_id;
        ?>
">
			<?php 
        if ($open) {
            wp_image_editor($attachment_id);
        }
        ?>
		</div>
	<?php 
    } elseif ($attachment_id && wp_attachment_is('audio', $post)) {
        wp_maybe_generate_attachment_metadata($post);
        echo wp_audio_shortcode(array('src' => $att_url));
    } elseif ($attachment_id && wp_attachment_is('video', $post)) {
        wp_maybe_generate_attachment_metadata($post);
        $meta = wp_get_attachment_metadata($attachment_id);
        $w = !empty($meta['width']) ? min($meta['width'], 640) : 0;
        $h = !empty($meta['height']) ? $meta['height'] : 0;
        if ($h && $w < $meta['width']) {
            $h = round($meta['height'] * $w / $meta['width']);
        }
        $attr = array('src' => $att_url);
        if (!empty($w) && !empty($h)) {
            $attr['width'] = $w;
            $attr['height'] = $h;
        }
        $thumb_id = get_post_thumbnail_id($attachment_id);
        if (!empty($thumb_id)) {
            $attr['poster'] = wp_get_attachment_url($thumb_id);
        }
        echo wp_video_shortcode($attr);
    }
    ?>
	</div>
	<div class="wp_attachment_details edit-form-section">
		<p>
			<label for="attachment_caption"><strong><?php 
    _e('Caption');
    ?>
</strong></label><br />
//.........这里部分代码省略.........
开发者ID:riasnelli,项目名称:WordPress,代码行数:101,代码来源:media.php

示例9: wp_enqueue_media

/**
 * Enqueues all scripts, styles, settings, and templates necessary to use
 * all media JS APIs.
 *
 * @since 3.5.0
 *
 * @global int       $content_width
 * @global wpdb      $wpdb
 * @global WP_Locale $wp_locale
 *
 * @param array $args {
 *     Arguments for enqueuing media scripts.
 *
 *     @type int|WP_Post A post object or ID.
 * }
 */
function wp_enqueue_media($args = array())
{
    // Enqueue me just once per page, please.
    if (did_action('wp_enqueue_media')) {
        return;
    }
    global $content_width, $wpdb, $wp_locale;
    $defaults = array('post' => null);
    $args = wp_parse_args($args, $defaults);
    // We're going to pass the old thickbox media tabs to `media_upload_tabs`
    // to ensure plugins will work. We will then unset those tabs.
    $tabs = array('type' => '', 'type_url' => '', 'gallery' => '', 'library' => '');
    /** This filter is documented in wp-admin/includes/media.php */
    $tabs = apply_filters('media_upload_tabs', $tabs);
    unset($tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library']);
    $props = array('link' => get_option('image_default_link_type'), 'align' => get_option('image_default_align'), 'size' => get_option('image_default_size'));
    $exts = array_merge(wp_get_audio_extensions(), wp_get_video_extensions());
    $mimes = get_allowed_mime_types();
    $ext_mimes = array();
    foreach ($exts as $ext) {
        foreach ($mimes as $ext_preg => $mime_match) {
            if (preg_match('#' . $ext . '#i', $ext_preg)) {
                $ext_mimes[$ext] = $mime_match;
                break;
            }
        }
    }
    $has_audio = $wpdb->get_var("\n\t\tSELECT ID\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_type = 'attachment'\n\t\tAND post_mime_type LIKE 'audio%'\n\t\tLIMIT 1\n\t");
    $has_video = $wpdb->get_var("\n\t\tSELECT ID\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_type = 'attachment'\n\t\tAND post_mime_type LIKE 'video%'\n\t\tLIMIT 1\n\t");
    $months = $wpdb->get_results($wpdb->prepare("\n\t\tSELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_type = %s\n\t\tORDER BY post_date DESC\n\t", 'attachment'));
    foreach ($months as $month_year) {
        $month_year->text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($month_year->month), $month_year->year);
    }
    $settings = array('tabs' => $tabs, 'tabUrl' => add_query_arg(array('chromeless' => true), admin_url('media-upload.php')), 'mimeTypes' => wp_list_pluck(get_post_mime_types(), 0), 'captions' => !apply_filters('disable_captions', ''), 'nonce' => array('sendToEditor' => wp_create_nonce('media-send-to-editor')), 'post' => array('id' => 0), 'defaultProps' => $props, 'attachmentCounts' => array('audio' => $has_audio ? 1 : 0, 'video' => $has_video ? 1 : 0), 'embedExts' => $exts, 'embedMimes' => $ext_mimes, 'contentWidth' => $content_width, 'months' => $months, 'mediaTrash' => MEDIA_TRASH ? 1 : 0);
    $post = null;
    if (isset($args['post'])) {
        $post = get_post($args['post']);
        $settings['post'] = array('id' => $post->ID, 'nonce' => wp_create_nonce('update-post_' . $post->ID));
        $thumbnail_support = current_theme_supports('post-thumbnails', $post->post_type) && post_type_supports($post->post_type, 'thumbnail');
        if (!$thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type) {
            if (wp_attachment_is('audio', $post)) {
                $thumbnail_support = post_type_supports('attachment:audio', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:audio');
            } elseif (wp_attachment_is('video', $post)) {
                $thumbnail_support = post_type_supports('attachment:video', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:video');
            }
        }
        if ($thumbnail_support) {
            $featured_image_id = get_post_meta($post->ID, '_thumbnail_id', true);
            $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
        }
    }
    if ($post) {
        $post_type_object = get_post_type_object($post->post_type);
    } else {
        $post_type_object = get_post_type_object('post');
    }
    $strings = array('url' => __('URL'), 'addMedia' => __('Add Media'), 'search' => __('Search'), 'select' => __('Select'), 'cancel' => __('Cancel'), 'update' => __('Update'), 'replace' => __('Replace'), 'remove' => __('Remove'), 'back' => __('Back'), 'selected' => __('%d selected'), 'dragInfo' => __('Drag and drop to reorder media files.'), 'uploadFilesTitle' => __('Upload Files'), 'uploadImagesTitle' => __('Upload Images'), 'mediaLibraryTitle' => __('Media Library'), 'insertMediaTitle' => __('Insert Media'), 'createNewGallery' => __('Create a new gallery'), 'createNewPlaylist' => __('Create a new playlist'), 'createNewVideoPlaylist' => __('Create a new video playlist'), 'returnToLibrary' => __('&#8592; Return to library'), 'allMediaItems' => __('All media items'), 'allDates' => __('All dates'), 'noItemsFound' => __('No items found.'), 'insertIntoPost' => $post_type_object->labels->insert_into_item, 'unattached' => __('Unattached'), 'trash' => _x('Trash', 'noun'), 'uploadedToThisPost' => $post_type_object->labels->uploaded_to_this_item, 'warnDelete' => __("You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete."), 'warnBulkDelete' => __("You are about to permanently delete these items.\n  'Cancel' to stop, 'OK' to delete."), 'warnBulkTrash' => __("You are about to trash these items.\n  'Cancel' to stop, 'OK' to delete."), 'bulkSelect' => __('Bulk Select'), 'cancelSelection' => __('Cancel Selection'), 'trashSelected' => __('Trash Selected'), 'untrashSelected' => __('Untrash Selected'), 'deleteSelected' => __('Delete Selected'), 'deletePermanently' => __('Delete Permanently'), 'apply' => __('Apply'), 'filterByDate' => __('Filter by date'), 'filterByType' => __('Filter by type'), 'searchMediaLabel' => __('Search Media'), 'noMedia' => __('No media attachments found.'), 'attachmentDetails' => __('Attachment Details'), 'insertFromUrlTitle' => __('Insert from URL'), 'setFeaturedImageTitle' => $post_type_object->labels->featured_image, 'setFeaturedImage' => $post_type_object->labels->set_featured_image, 'createGalleryTitle' => __('Create Gallery'), 'editGalleryTitle' => __('Edit Gallery'), 'cancelGalleryTitle' => __('&#8592; Cancel Gallery'), 'insertGallery' => __('Insert gallery'), 'updateGallery' => __('Update gallery'), 'addToGallery' => __('Add to gallery'), 'addToGalleryTitle' => __('Add to Gallery'), 'reverseOrder' => __('Reverse order'), 'imageDetailsTitle' => __('Image Details'), 'imageReplaceTitle' => __('Replace Image'), 'imageDetailsCancel' => __('Cancel Edit'), 'editImage' => __('Edit Image'), 'chooseImage' => __('Choose Image'), 'selectAndCrop' => __('Select and Crop'), 'skipCropping' => __('Skip Cropping'), 'cropImage' => __('Crop Image'), 'cropYourImage' => __('Crop your image'), 'cropping' => __('Cropping&hellip;'), 'suggestedDimensions' => __('Suggested image dimensions:'), 'cropError' => __('There has been an error cropping your image.'), 'audioDetailsTitle' => __('Audio Details'), 'audioReplaceTitle' => __('Replace Audio'), 'audioAddSourceTitle' => __('Add Audio Source'), 'audioDetailsCancel' => __('Cancel Edit'), 'videoDetailsTitle' => __('Video Details'), 'videoReplaceTitle' => __('Replace Video'), 'videoAddSourceTitle' => __('Add Video Source'), 'videoDetailsCancel' => __('Cancel Edit'), 'videoSelectPosterImageTitle' => __('Select Poster Image'), 'videoAddTrackTitle' => __('Add Subtitles'), 'playlistDragInfo' => __('Drag and drop to reorder tracks.'), 'createPlaylistTitle' => __('Create Audio Playlist'), 'editPlaylistTitle' => __('Edit Audio Playlist'), 'cancelPlaylistTitle' => __('&#8592; Cancel Audio Playlist'), 'insertPlaylist' => __('Insert audio playlist'), 'updatePlaylist' => __('Update audio playlist'), 'addToPlaylist' => __('Add to audio playlist'), 'addToPlaylistTitle' => __('Add to Audio Playlist'), 'videoPlaylistDragInfo' => __('Drag and drop to reorder videos.'), 'createVideoPlaylistTitle' => __('Create Video Playlist'), 'editVideoPlaylistTitle' => __('Edit Video Playlist'), 'cancelVideoPlaylistTitle' => __('&#8592; Cancel Video Playlist'), 'insertVideoPlaylist' => __('Insert video playlist'), 'updateVideoPlaylist' => __('Update video playlist'), 'addToVideoPlaylist' => __('Add to video playlist'), 'addToVideoPlaylistTitle' => __('Add to Video Playlist'));
    /**
     * Filter the media view settings.
     *
     * @since 3.5.0
     *
     * @param array   $settings List of media view settings.
     * @param WP_Post $post     Post object.
     */
    $settings = apply_filters('media_view_settings', $settings, $post);
    /**
     * Filter the media view strings.
     *
     * @since 3.5.0
     *
     * @param array   $strings List of media view strings.
     * @param WP_Post $post    Post object.
     */
    $strings = apply_filters('media_view_strings', $strings, $post);
    $strings['settings'] = $settings;
    // Ensure we enqueue media-editor first, that way media-views is
    // registered internally before we try to localize it. see #24724.
    wp_enqueue_script('media-editor');
    wp_localize_script('media-views', '_wpMediaViewsL10n', $strings);
    wp_enqueue_script('media-audiovideo');
    wp_enqueue_style('media-views');
    if (is_admin()) {
        wp_enqueue_script('mce-view');
//.........这里部分代码省略.........
开发者ID:nakamuraagatha,项目名称:reseptest,代码行数:101,代码来源:media.php

示例10: wp_get_post_revisions

if (post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status) {
    $revisions = wp_get_post_revisions($post_ID);
    // We should aim to show the revisions meta box only when there are revisions.
    if (count($revisions) > 1) {
        reset($revisions);
        // Reset pointer for key()
        $publish_callback_args = array('revisions_count' => count($revisions), 'revision_id' => key($revisions));
        add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
    }
}
if ('attachment' == $post_type) {
    wp_enqueue_script('image-edit');
    wp_enqueue_style('imgareaselect');
    add_meta_box('submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core');
    add_action('edit_form_after_title', 'edit_form_image_editor');
    if (wp_attachment_is('audio', $post)) {
        add_meta_box('attachment-id3', __('Metadata'), 'attachment_id3_data_meta_box', null, 'normal', 'core');
    }
} else {
    add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args);
}
if (current_theme_supports('post-formats') && post_type_supports($post_type, 'post-formats')) {
    add_meta_box('formatdiv', _x('Format', 'post format'), 'post_format_meta_box', null, 'side', 'core');
}
// all taxonomies
foreach (get_object_taxonomies($post) as $tax_name) {
    $taxonomy = get_taxonomy($tax_name);
    if (!$taxonomy->show_ui || false === $taxonomy->meta_box_cb) {
        continue;
    }
    $label = $taxonomy->labels->name;
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:31,代码来源:edit-form-advanced.php

示例11: test_wp_attachment_is_default

 public function test_wp_attachment_is_default()
 {
     // On Multisite, psd is not an allowed mime type by default.
     if (is_multisite()) {
         add_filter('upload_mimes', array($this, 'whitelist_psd_mime_type'), 10, 2);
     }
     $filename = DIR_TESTDATA . '/images/test-image.psd';
     $contents = file_get_contents($filename);
     $upload = wp_upload_bits(basename($filename), null, $contents);
     $attachment_id = $this->_make_attachment($upload);
     $this->assertFalse(wp_attachment_is_image($attachment_id));
     $this->assertTrue(wp_attachment_is('psd', $attachment_id));
     $this->assertFalse(wp_attachment_is('audio', $attachment_id));
     $this->assertFalse(wp_attachment_is('video', $attachment_id));
     if (is_multisite()) {
         remove_filter('upload_mimes', array($this, 'whitelist_psd_mime_type'), 10, 2);
     }
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:18,代码来源:attachments.php

示例12: wp_generate_attachment_metadata

/**
 * Generate post thumbnail attachment meta data.
 *
 * @since 2.1.0
 *
 * @global array $_wp_additional_image_sizes
 *
 * @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();
    $support = false;
    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];
        // Make the file path relative to the upload dir.
        $metadata['file'] = _wp_relative_upload_path($file);
        // Make thumbnails and other intermediate sizes.
        global $_wp_additional_image_sizes;
        $sizes = array();
        foreach (get_intermediate_image_sizes() as $s) {
            $sizes[$s] = array('width' => '', 'height' => '', 'crop' => false);
            if (isset($_wp_additional_image_sizes[$s]['width'])) {
                $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']);
            } else {
                $sizes[$s]['width'] = get_option("{$s}_size_w");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['height'])) {
                $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']);
            } else {
                $sizes[$s]['height'] = get_option("{$s}_size_h");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['crop'])) {
                $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop'];
            } else {
                $sizes[$s]['crop'] = get_option("{$s}_crop");
            }
            // For default sizes set in options
        }
        /**
         * Filter the image sizes automatically generated when uploading an image.
         *
         * @since 2.9.0
         * @since 4.4.0 Added the `$metadata` argument.
         *
         * @param array $sizes    An associative array of image sizes.
         * @param array $metadata An associative array of image metadata: width, height, file.
         */
        $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes, $metadata);
        if ($sizes) {
            $editor = wp_get_image_editor($file);
            if (!is_wp_error($editor)) {
                $metadata['sizes'] = $editor->multi_resize($sizes);
            }
        } else {
            $metadata['sizes'] = array();
        }
        // Fetch additional metadata from EXIF/IPTC.
        $image_meta = wp_read_image_metadata($file);
        if ($image_meta) {
            $metadata['image_meta'] = $image_meta;
        }
    } elseif (wp_attachment_is('video', $attachment)) {
        $metadata = wp_read_video_metadata($file);
        $support = current_theme_supports('post-thumbnails', 'attachment:video') || post_type_supports('attachment:video', 'thumbnail');
    } elseif (wp_attachment_is('audio', $attachment)) {
        $metadata = wp_read_audio_metadata($file);
        $support = current_theme_supports('post-thumbnails', 'attachment:audio') || post_type_supports('attachment:audio', 'thumbnail');
    }
    if ($support && !empty($metadata['image']['data'])) {
        // Check for existing cover.
        $hash = md5($metadata['image']['data']);
        $posts = get_posts(array('fields' => 'ids', 'post_type' => 'attachment', 'post_mime_type' => $metadata['image']['mime'], 'post_status' => 'inherit', 'posts_per_page' => 1, 'meta_key' => '_cover_hash', 'meta_value' => $hash));
        $exists = reset($posts);
        if (!empty($exists)) {
            update_post_meta($attachment_id, '_thumbnail_id', $exists);
        } else {
            $ext = '.jpg';
            switch ($metadata['image']['mime']) {
                case 'image/gif':
                    $ext = '.gif';
                    break;
                case 'image/png':
                    $ext = '.png';
                    break;
            }
            $basename = str_replace('.', '-', basename($file)) . '-image' . $ext;
            $uploaded = wp_upload_bits($basename, '', $metadata['image']['data']);
            if (false === $uploaded['error']) {
                $image_attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => '');
                /**
                 * Filter the parameters for the attachment thumbnail creation.
                 *
//.........这里部分代码省略.........
开发者ID:skinnard,项目名称:FTL-2,代码行数:101,代码来源:image.php

示例13: printf

printf('<div class="ev-attachment-upload-container %s" %s>', esc_attr($container_class), implode(' ', $data_attrs));
?>
	<?php 
if (!empty($value)) {
    foreach (explode(',', $value) as $id) {
        $title = get_the_title($id);
        $file = get_attached_file($id);
        $extension = basename($file);
        $size = size_format(filesize($file));
        $extension = sprintf("%s (%s)", esc_html($extension), esc_html($size));
        $type = '';
        if (wp_attachment_is_image($id)) {
            $type = 'image';
        } elseif (wp_attachment_is('audio', $id)) {
            $type = 'audio';
        } elseif (wp_attachment_is('video', $id)) {
            $type = 'video';
        } else {
            $check = wp_check_filetype($file);
            if (isset($check['ext'])) {
                $type = $check['ext'];
            } else {
                $type = 'unknown';
            }
        }
        printf(ev_attachment_upload_generic_placeholder_template(), esc_attr($type), esc_html(__('Remove', 'ev_framework')), esc_attr($id), esc_html($title), esc_attr(wp_get_attachment_url($id)), esc_html($extension));
    }
}
?>

	<div class="ev-attachment-upload-action">
开发者ID:Themes-Protoarte,项目名称:evolve-framework,代码行数:31,代码来源:attachment.php

示例14: esc_attr

    ?>
<section class="post-media post-media-audio-<?php 
    echo esc_attr($post_format_meta['type']);
    ?>
">

	<?php 
    switch ($post_format_meta['type']) {
        case 'embed':
            global $wp_embed;
            if (is_a($wp_embed, 'WP_Embed')) {
                echo $wp_embed->autoembed($post_format_meta['embed']);
            } else {
                echo $post_format_meta['embed'];
            }
            break;
        case 'hosted':
            if (has_post_thumbnail()) {
                the_post_thumbnail('full', array('itemprop' => 'image'));
            }
            if (wp_attachment_is('audio', $post_format_meta['src'])) {
                echo wp_audio_shortcode(array('src' => wp_get_attachment_url($post_format_meta['src'])));
            }
            break;
    }
    ?>
</section>
<?php 
} else {
    Youxi()->templates->get('media/media', null, get_post_type());
}
开发者ID:yemingyuen,项目名称:mingsg,代码行数:31,代码来源:media-audio.php

示例15: printf

            global $wp_embed;
            if (is_a($wp_embed, 'WP_Embed')) {
                echo $wp_embed->autoembed($post_format_meta['embed']);
            } else {
                echo $post_format_meta['embed'];
            }
            ?>
		</div>
		<?php 
            break;
        case 'hosted':
            ?>
		<div class="media">
			<?php 
            // Check if the attachment is a video
            if (wp_attachment_is('video', $post_format_meta['src'])) {
                $meta = wp_get_attachment_metadata($post_format_meta['src']);
                if (isset($meta['width'], $meta['height'])) {
                    $video_ar = 100.0 * $meta['height'] / $meta['width'];
                    printf('<div class="wp-video-wrapper" style="padding-top: %s%%">', $video_ar);
                }
                echo wp_video_shortcode(array('src' => wp_get_attachment_url($post_format_meta['src']), 'poster' => wp_get_attachment_url($post_format_meta['poster'])));
                if (isset($video_ar)) {
                    echo '</div>';
                }
            }
            ?>
		</div>

		<?php 
            break;
开发者ID:yemingyuen,项目名称:mingsg,代码行数:31,代码来源:media-video.php


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