Example #1
0
/**
 * 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' => __('← 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' => __('← 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…'), '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' => __('← 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' => __('← 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');
        wp_enqueue_script('image-edit');
    }
    wp_enqueue_style('imgareaselect');
    wp_plupload_default_settings();
    require_once ABSPATH . WPINC . '/media-template.php';
    add_action('admin_footer', 'wp_print_media_templates');
    add_action('wp_footer', 'wp_print_media_templates');
    add_action('customize_controls_print_footer_scripts', 'wp_print_media_templates');
    /**
     * Fires at the conclusion of wp_enqueue_media().
     *
     * @since 3.5.0
     */
    do_action('wp_enqueue_media');
}
Example #2
0
/**
 * Enqueues all scripts, styles, settings, and templates necessary to use
 * all media JS APIs.
 *
 * @since 3.5.0
 */
function wp_enqueue_media( $args = array() ) {
	$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(
		// handler action suffix => tab label
		'type'     => '',
		'type_url' => '',
		'gallery'  => '',
		'library'  => '',
	);

	$tabs = apply_filters( 'media_upload_tabs', $tabs );
	unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] );

	$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,
		),
	);

	$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 ),
		);

		if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) {
			$featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );
			$settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
		}
	}

	$hier = $post && is_post_type_hierarchical( $post->post_type );

	$strings = array(
		// Generic
		'url'         => __( 'URL' ),
		'addMedia'    => __( 'Add Media' ),
		'search'      => __( 'Search' ),
		'select'      => __( 'Select' ),
		'cancel'      => __( 'Cancel' ),
		/* translators: This is a would-be plural string used in the media manager.
		   If there is not a word you can use in your language to avoid issues with the
		   lack of plural support here, turn it into "selected: %d" then translate it.
		 */
		'selected'    => __( '%d selected' ),
		'dragInfo'    => __( 'Drag and drop to reorder images.' ),

		// Upload
		'uploadFilesTitle'  => __( 'Upload Files' ),
		'uploadImagesTitle' => __( 'Upload Images' ),

		// Library
		'mediaLibraryTitle'  => __( 'Media Library' ),
		'insertMediaTitle'   => __( 'Insert Media' ),
		'createNewGallery'   => __( 'Create a new gallery' ),
		'returnToLibrary'    => __( '← Return to library' ),
		'allMediaItems'      => __( 'All media items' ),
		'noItemsFound'       => __( 'No items found.' ),
		'insertIntoPost'     => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
		'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
		'warnDelete' =>      __( "You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete." ),

		// From URL
		'insertFromUrlTitle' => __( 'Insert from URL' ),

		// Featured Images
		'setFeaturedImageTitle' => __( 'Set Featured Image' ),
		'setFeaturedImage'    => __( 'Set featured image' ),

		// Gallery
		'createGalleryTitle' => __( 'Create Gallery' ),
		'editGalleryTitle'   => __( 'Edit Gallery' ),
		'cancelGalleryTitle' => __( '← Cancel Gallery' ),
		'insertGallery'      => __( 'Insert gallery' ),
		'updateGallery'      => __( 'Update gallery' ),
		'addToGallery'       => __( 'Add to gallery' ),
		'addToGalleryTitle'  => __( 'Add to Gallery' ),
		'reverseOrder'       => __( 'Reverse order' ),
	);

	$settings = apply_filters( 'media_view_settings', $settings, $post );
	$strings  = apply_filters( 'media_view_strings',  $strings,  $post );

	$strings['settings'] = $settings;

	wp_localize_script( 'media-views', '_wpMediaViewsL10n', $strings );

	wp_enqueue_script( 'media-editor' );
	wp_enqueue_style( 'media-views' );
	wp_plupload_default_settings();

	require_once ABSPATH . WPINC . '/media-template.php';
	add_action( 'admin_footer', 'wp_print_media_templates' );
	add_action( 'wp_footer', 'wp_print_media_templates' );

	do_action( 'wp_enqueue_media' );
}
Example #3
0
/**
 * Enqueues all scripts, styles, settings, and templates necessary to use
 * all media JS APIs.
 *
 * @since 3.5.0
 */
function wp_enqueue_media($args = array())
{
    // Enqueue me just once per page, please.
    if (did_action('wp_enqueue_media')) {
        return;
    }
    $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' => '');
    $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'));
    $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, 'embedExts' => array_merge(wp_get_audio_extensions(), wp_get_video_extensions()));
    $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));
        if (current_theme_supports('post-thumbnails', $post->post_type) && post_type_supports($post->post_type, 'thumbnail')) {
            $featured_image_id = get_post_meta($post->ID, '_thumbnail_id', true);
            $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
        }
    }
    $hier = $post && is_post_type_hierarchical($post->post_type);
    $strings = array('url' => __('URL'), 'addMedia' => __('Add Media'), 'search' => __('Search'), 'select' => __('Select'), 'cancel' => __('Cancel'), 'selected' => __('%d selected'), 'dragInfo' => __('Drag and drop to reorder images.'), 'uploadFilesTitle' => __('Upload Files'), 'uploadImagesTitle' => __('Upload Images'), 'mediaLibraryTitle' => __('Media Library'), 'insertMediaTitle' => __('Insert Media'), 'createNewGallery' => __('Create a new gallery'), 'returnToLibrary' => __('← Return to library'), 'allMediaItems' => __('All media items'), 'noItemsFound' => __('No items found.'), 'insertIntoPost' => $hier ? __('Insert into page') : __('Insert into post'), 'uploadedToThisPost' => $hier ? __('Uploaded to this page') : __('Uploaded to this post'), 'warnDelete' => __("You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete."), 'insertFromUrlTitle' => __('Insert from URL'), 'setFeaturedImageTitle' => __('Set Featured Image'), 'setFeaturedImage' => __('Set featured image'), 'createGalleryTitle' => __('Create Gallery'), 'editGalleryTitle' => __('Edit Gallery'), 'cancelGalleryTitle' => __('← Cancel Gallery'), 'insertGallery' => __('Insert gallery'), 'updateGallery' => __('Update gallery'), 'addToGallery' => __('Add to gallery'), 'addToGalleryTitle' => __('Add to Gallery'), 'reverseOrder' => __('Reverse order'));
    $settings = apply_filters('media_view_settings', $settings, $post);
    $strings = apply_filters('media_view_strings', $strings, $post);
    $strings['settings'] = $settings;
    wp_localize_script('media-views', '_wpMediaViewsL10n', $strings);
    wp_enqueue_script('media-editor');
    wp_enqueue_style('media-views');
    wp_plupload_default_settings();
    require_once ABSPATH . WPINC . '/media-template.php';
    add_action('admin_footer', 'wp_print_media_templates');
    add_action('wp_footer', 'wp_print_media_templates');
    add_action('customize_controls_print_footer_scripts', 'wp_print_media_templates');
    do_action('wp_enqueue_media');
}
Example #4
0
 * @package WordPress
 * @subpackage Administration
 */
// don't load directly
if (!defined('ABSPATH')) {
    die('-1');
}
wp_enqueue_script('post');
if (wp_is_mobile()) {
    wp_enqueue_script('jquery-touch-punch');
}
if (post_type_supports($post_type, 'editor') || post_type_supports($post_type, 'thumbnail')) {
    add_thickbox();
    wp_enqueue_script('media-upload');
    wp_enqueue_style('media-views');
    wp_plupload_default_settings();
    add_action('admin_footer', 'wp_print_media_templates');
}
/**
 * Post ID global
 * @name $post_ID
 * @var int
 */
$post_ID = isset($post_ID) ? (int) $post_ID : 0;
$user_ID = isset($user_ID) ? (int) $user_ID : 0;
$action = isset($action) ? $action : '';
$messages = array();
$messages['post'] = array(0 => '', 1 => sprintf(__('Post updated. <a href="%s">View post</a>'), esc_url(get_permalink($post_ID))), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Post updated.'), 5 => isset($_GET['revision']) ? sprintf(__('Post restored to revision from %s'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Post published. <a href="%s">View post</a>'), esc_url(get_permalink($post_ID))), 7 => __('Post saved.'), 8 => sprintf(__('Post submitted. <a target="_blank" href="%s">Preview post</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), 9 => sprintf(__('Post scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview post</a>'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))), 10 => sprintf(__('Post draft updated. <a target="_blank" href="%s">Preview post</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))));
$messages['page'] = array(0 => '', 1 => sprintf(__('Page updated. <a href="%s">View page</a>'), esc_url(get_permalink($post_ID))), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Page updated.'), 5 => isset($_GET['revision']) ? sprintf(__('Page restored to revision from %s'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Page published. <a href="%s">View page</a>'), esc_url(get_permalink($post_ID))), 7 => __('Page saved.'), 8 => sprintf(__('Page submitted. <a target="_blank" href="%s">Preview page</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), 9 => sprintf(__('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))), 10 => sprintf(__('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))));
$messages['attachment'] = array_fill(1, 10, __('Media attachment updated'));
// Hack, for now.
Example #5
0
 public function enqueue_scripts()
 {
     wp_register_script('g1_ui_widget_ajax_image_upload', trailingslashit(G1_FRAMEWORK_URI) . 'admin/js/g1-ui-widget-ajax-image-upload.js', array('jquery'));
     wp_enqueue_script('g1_ui_widget_ajax_image_upload');
     wp_localize_script('g1_ui_widget_ajax_image_upload', $this->get_id(), json_encode($this->get_js_config()));
     wp_register_style('g1_ui_widget_ajax_image_upload', trailingslashit(G1_FRAMEWORK_URI) . 'admin/css/g1-ui-widget-ajax-image-upload.css');
     wp_enqueue_style('g1_ui_widget_ajax_image_upload');
     wp_plupload_default_settings();
     wp_enqueue_script('wp-plupload');
 }
Example #6
0
/**
 * Adds the media button to the editor
 *
 * @since 2.5.0
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    wp_enqueue_script('media-upload');
    wp_enqueue_style('media-views');
    wp_plupload_default_settings();
    add_action('admin_footer', 'wp_print_media_templates');
    $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
    $img = '<span class="wp-media-buttons-icon"></span>';
    echo '<a href="#" class="button insert-media add_media" data-editor="' . esc_attr($editor_id) . '" title="' . esc_attr__('Add Media') . '">' . $img . ' Beta Media</a>';
    echo '<a href="' . esc_url(get_upload_iframe_src()) . '" class="thickbox add_media" id="' . esc_attr($editor_id) . '-add_media" title="' . esc_attr__('Add Media') . '" onclick="return false;">' . sprintf($context, $img) . '</a>';
}
Example #7
0
/**
 * Enqueues all scripts, styles, settings, and templates necessary to use
 * all media JS APIs.
 *
 * @since 3.5.0
 */
function wp_enqueue_media($args = array())
{
    $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' => '');
    $tabs = apply_filters('media_upload_tabs', $tabs);
    unset($tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library']);
    $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')), 'postId' => 0);
    $post = null;
    if (isset($args['post'])) {
        $post = get_post($args['post']);
        $settings['postId'] = $post->ID;
    }
    $hier = $post && is_post_type_hierarchical($post->post_type);
    $strings = array('url' => __('URL'), 'addMedia' => __('Add Media'), 'search' => __('Search'), 'select' => __('Select'), 'cancel' => __('Cancel'), 'addImages' => __('Add images'), 'selected' => __('selected'), 'dragInfo' => __('Drag and drop to reorder images.'), 'uploadFilesTitle' => __('Upload Files'), 'selectFiles' => __('Select files'), 'uploadImagesTitle' => __('Upload Images'), 'uploadMoreFiles' => __('Upload more files'), 'mediaLibraryTitle' => __('Media Library'), 'createNewGallery' => __('Create a new gallery'), 'returnToLibrary' => __('&#8592; Return to library'), 'allMediaItems' => __('All media items'), 'insertIntoPost' => $hier ? __('Insert into page') : __('Insert into post'), 'uploadedToThisPost' => $hier ? __('Uploaded to this page') : __('Uploaded to this post'), 'warnDelete' => __("You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete."), 'fromUrlTitle' => __('From URL'), 'createGalleryTitle' => __('Create Gallery'), 'editGalleryTitle' => __('Edit Gallery'), 'cancelGalleryTitle' => __('&#8592; Cancel Gallery'), 'insertGallery' => __('Insert gallery'), 'updateGallery' => __('Update gallery'), 'continueEditing' => __('Continue editing'), 'addToGallery' => __('Add to gallery'));
    $settings = apply_filters('media_view_settings', $settings, $post);
    $strings = apply_filters('media_view_strings', $strings, $post);
    $strings['settings'] = $settings;
    wp_localize_script('media-views', '_wpMediaViewsL10n', $strings);
    wp_enqueue_script('media-editor');
    wp_enqueue_style('media-views');
    wp_plupload_default_settings();
    add_action('admin_footer', 'wp_print_media_templates');
    add_action('wp_footer', 'wp_print_media_templates');
}
/**
 * Enqueues all scripts, styles, settings, and templates necessary to use
 * all media JS APIs.
 *
 * @since 3.5.0
 */
function wp_enqueue_media($args = array())
{
    // Enqueue me just once per page, please.
    if (did_action('wp_enqueue_media')) {
        return;
    }
    global $content_width;
    $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;
            }
        }
    }
    $audio = $video = 0;
    $counts = (array) wp_count_attachments();
    foreach ($counts as $mime => $total) {
        if (0 === strpos($mime, 'audio/')) {
            $audio += (int) $total;
        } elseif (0 === strpos($mime, 'video/')) {
            $video += (int) $total;
        }
    }
    $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' => $audio, 'video' => $video), 'embedExts' => $exts, 'embedMimes' => $ext_mimes, 'contentWidth' => $content_width);
    $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 (0 === strpos($post->post_mime_type, 'audio/')) {
                $thumbnail_support = post_type_supports('attachment:audio', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:audio');
            } elseif (0 === strpos($post->post_mime_type, 'video/')) {
                $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;
        }
    }
    $hier = $post && is_post_type_hierarchical($post->post_type);
    $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 images.'), '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'), 'noItemsFound' => __('No items found.'), 'insertIntoPost' => $hier ? __('Insert into page') : __('Insert into post'), 'uploadedToThisPost' => $hier ? __('Uploaded to this page') : __('Uploaded to this post'), 'warnDelete' => __("You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete."), 'insertFromUrlTitle' => __('Insert from URL'), 'setFeaturedImageTitle' => __('Set Featured Image'), 'setFeaturedImage' => __('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;
    wp_localize_script('media-views', '_wpMediaViewsL10n', $strings);
    wp_enqueue_script('media-editor');
    wp_enqueue_script('media-audiovideo');
    wp_enqueue_style('media-views');
    if (is_admin()) {
        wp_enqueue_script('mce-view');
        wp_enqueue_script('image-edit');
    }
    wp_enqueue_style('imgareaselect');
    wp_plupload_default_settings();
    require_once ABSPATH . WPINC . '/media-template.php';
    add_action('admin_footer', 'wp_print_media_templates');
    add_action('wp_footer', 'wp_print_media_templates');
    add_action('customize_controls_print_footer_scripts', 'wp_print_media_templates');
    /**
     * Fires at the conclusion of wp_enqueue_media().
     *
     * @since 3.5.0
     */
    do_action('wp_enqueue_media');
}
Example #9
0
 /**
  * Take over the template loading process for a GifDrop repository page
  *
  * @param string $template the template WordPress wants to load
  * @return string the modified template we tell WordPress to load
  */
 public function template_include($template)
 {
     if (is_singular()) {
         if ($this->is_gifdrop_page(get_queried_object_id())) {
             $this->register_frontend_scripts();
             $this->register_frontend_styles();
             // To-Do: Caching of this call
             $images = get_posts(array('post_parent' => get_queried_object_id(), 'post_type' => 'attachment', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => -1));
             // Filter out some of the attachment fields so the object is as small as possible
             array_walk($images, array($this, 'only_some_attachment_fields'));
             wp_localize_script('gifdrop', 'gifdropSettings', array('id' => (int) get_queried_object_id(), 'nonce' => wp_create_nonce('gifdrop_' . get_queried_object_id()), 'attachments' => $images, 'canUpload' => current_user_can('edit_post', (int) get_queried_object_id()) ? '1' : '0'));
             wp_plupload_default_settings();
             return $this->get_path() . '/templates/page.php';
         }
     }
     return $template;
 }
 protected function render_upload_form()
 {
     /**
      * Filter the maximum allowed upload size for import files.
      *
      * @since 2.3.0
      *
      * @see wp_max_upload_size()
      *
      * @param int $max_upload_size Allowed upload size. Default 1 MB.
      */
     $max_upload_size = apply_filters('import_upload_size_limit', wp_max_upload_size());
     $upload_dir = wp_upload_dir();
     if (!empty($upload_dir['error'])) {
         $error = '<div class="error inline"><p>';
         $error .= esc_html__('Before you can upload your import file, you will need to fix the following error:', 'wordpress-importer');
         $error .= sprintf('<p><strong>%s</strong></p></div>', $upload_dir['error']);
         echo $error;
         return;
     }
     // Queue the JS needed for the page
     $url = plugins_url('assets/intro.js', __FILE__);
     $deps = array('wp-backbone', 'wp-plupload');
     wp_enqueue_script('import-upload', $url, $deps, false, true);
     // Set uploader settings
     wp_plupload_default_settings();
     $settings = array('next_url' => wp_nonce_url($this->get_url(1), 'import-upload') . '&id={id}', 'plupload' => array('filter' => array('max_file_size' => $max_upload_size . 'b'), 'file_data_name' => 'import', 'multipart_params' => array('action' => 'wxr-import-upload', '_wpnonce' => wp_create_nonce('wxr-import-upload'))));
     wp_localize_script('import-upload', 'importUploadSettings', $settings);
     wp_enqueue_style('wxr-import-upload', plugins_url('assets/intro.css', __FILE__), array(), '20160412');
     // Load the template
     remove_action('post-plupload-upload-ui', 'media_upload_flash_bypass');
     require __DIR__ . '/templates/upload.php';
     add_action('post-plupload-upload-ui', 'media_upload_flash_bypass');
 }