cedaro/metamedia

There is no license information available for the latest version (v1.0.0) of this package.

A WordPress plugin to register media selection meta boxes.

Installs: 67

Dependents: 0

Suggesters: 0

Security: 0

Stars: 8

Watchers: 6

Forks: 0

Open Issues: 0

Type:wordpress-plugin

v1.0.0 2013-05-27 16:15 UTC

This package is auto-updated.

Last update: 2024-03-29 02:47:31 UTC


README

A WordPress plugin to register media selection meta boxes.

Contributors: Brady Vercher
Requires: 3.5
Tested up to: 4.0
License: GPL-2.0+

With the release of WordPress 3.5, an effort was made to decouple attachments from the posts where they were uploaded, which was a shift from previous versions, and a greater emphasis was placed on the [gallery] shortcode. Backward compatibility was maintained, but it became a little less intuitive to manage a gallery of images that were simply attached to a post. In any case it has always been a little difficult to select multiple featured images, or multiple galleries, for use in different areas in a template.

Metamedia allows for registering simple meta boxes like the "Featured Image" meta box for selecting a single image or gallery of images to be stored in a post meta field for easy retrieval and usage in templates. It can be used with any post type and uses the native media frame.

Gallery Meta Box
An example gallery meta box. The images can be sorted directly in the meta box.

Featured Image Meta Box
An example meta box with custom labels for selecting a single image.

Usage

To add a meta box similar to the "Featured Post" meta box, simply register it using register_metamedia_metabox() like this:

function themename_register_metamedia() {
	if ( ! is_admin() || ! function_exists( 'register_metamedia_meta_box' ) ) {
		return;
	}

	// Register a meta box for assigning a 'hero' image to posts.
	register_metamedia_meta_box( 'hero', 'post' );
}
add_action( 'init', 'themename_register_metamedia' );

Now in a template, the image ID can be retrieved using get_post_meta( $post_id, 'hero', true ).

Methods

The parameters for both methods are the same. Most labels and properties of registered meta boxes and the media modal can be customized using the optional $args parameter.

register_metamedia_meta_box( $meta_key, $post_type, $args = array() )

register_metamedia_gallery_meta_box( $meta_key, $post_type, $args = array() )

Arguments

Key Description Example
meta_box_title The title of the meta box. Hero Image
meta_box_context Where the meta box should appear. side
choose_label Label of the button used to open the media frame. Select Image
remove_label Label of the link used to remove a selected image. Remove image
frame_title The title of the media frame. 2-10
frame_button The label of the button used to select an image in the media frame. Update Image

Some arguments may not work with the gallery meta box. Additional arguments are available for more advanced usage.

Installation

Metamedia is available in the WordPress plugin repository, so it can be installed from within your admin panel like any other plugin. You may also download it directly from GitHub using one of the following methods:

Upload

  1. Download the latest release from GitHub.
  2. Go to the Plugins → Add New screen in your WordPress admin panel and click the Upload tab at the top.
  3. Upload the zipped archive.
  4. Click the Activate Plugin link after installation completes.

Manual

  1. Download the latest release from GitHub.
  2. Unzip the archive.
  3. Copy the folder to /wp-content/plugins/.
  4. Go to the Plugins screen in your WordPress admin panel and click the Activate link under Metamedia.

Read the Codex for more information about installing plugins manually.

Git

Clone this repository in /wp-content/plugins/:

git clone git@github.com:cedaro/metamedia.git

Then go to the Plugins screen in your WordPress admin panel and click the Activate link under Metamedia.