Version Description
= 3.0 = Now piggybacking the awesome Media workflow introduced in WordPress 3.5
Download this release
Release Info
Developer | jchristopher |
Plugin | Attachments |
Version | 3.4 |
Comparing to | |
See all releases |
Code changes from version 3.3.3 to 3.4
- CONTRIBUTING.md +2 -2
- README.md +65 -5
- classes/class.attachments.php +63 -16
- css/attachments.css +22 -0
- index.php +1 -1
- readme.txt +7 -539
CONTRIBUTING.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
# Contributing to Attachments development
|
2 |
|
3 |
-
Thank you so much for contributing to this project, I love pull requests! To
|
4 |
|
5 |
1. Create a GitHub account
|
6 |
1. [Fork](https://help.github.com/articles/fork-a-repo) the repo
|
@@ -11,4 +11,4 @@ Thank you so much for contributing to this project, I love pull requests! To eff
|
|
11 |
1. Push your changes to your branch of your fork
|
12 |
1. Submit a pull request
|
13 |
|
14 |
-
Thank you!
|
1 |
# Contributing to Attachments development
|
2 |
|
3 |
+
Thank you so much for contributing to this project, I love pull requests! To effectively contribute to the development of Attachments please do the following:
|
4 |
|
5 |
1. Create a GitHub account
|
6 |
1. [Fork](https://help.github.com/articles/fork-a-repo) the repo
|
11 |
1. Push your changes to your branch of your fork
|
12 |
1. Submit a pull request
|
13 |
|
14 |
+
Thank you!
|
README.md
CHANGED
@@ -9,7 +9,7 @@ Attachments allows you to simply append any number of items from your WordPress
|
|
9 |
* **[Upgrade Notice](#upgrade-notice)** *Pay specific attention if upgrading from a version before 3.0*
|
10 |
* [Usage](#usage)
|
11 |
* [Disable Settings Screen](#disable-settings-screen)
|
12 |
-
* [Setting Up Instances](#setting-up-instances)
|
13 |
* [Disable the Default Instance](#disable-the-default-instance)
|
14 |
* [Create Custom Instances](#create-custom-instances)
|
15 |
* [Fields Reference](#fields-reference)
|
@@ -18,6 +18,9 @@ Attachments allows you to simply append any number of items from your WordPress
|
|
18 |
* [Retrieve Attachment Attributes](#retrieve-attachment-attributes)
|
19 |
* [Retrieve Single Attachments](#retrieve-single-attachments)
|
20 |
* [Search](#search)
|
|
|
|
|
|
|
21 |
* [Screenshots](#screenshots)
|
22 |
* [Frequently Asked Questions](#frequently-asked-questions)
|
23 |
* [Changelog](#changelog)
|
@@ -84,6 +87,8 @@ Version 3 is a **major** rewrite. While I've taken precautions in ensuring you w
|
|
84 |
|
85 |
## Usage
|
86 |
|
|
|
|
|
87 |
### Disable Settings Screen
|
88 |
|
89 |
Attachments ships with a `Settings` screen (found under the `Settings` menu in the main WordPress admin navigation) that facilitates data migration from version 1.x and also offers some code snippets. If you would like to **disable the Settings screen** add the following to your theme's `functions.php`:
|
@@ -116,7 +121,7 @@ You may create instances with your own custom fields by using the `attachments_r
|
|
116 |
|
117 |
function my_attachments( $attachments )
|
118 |
{
|
119 |
-
$fields
|
120 |
array(
|
121 |
'name' => 'title', // unique field name
|
122 |
'type' => 'text', // registered field type
|
@@ -151,6 +156,10 @@ function my_attachments( $attachments )
|
|
151 |
// include a note within the meta box (string)
|
152 |
'note' => 'Attach files here!',
|
153 |
|
|
|
|
|
|
|
|
|
154 |
// text for 'Attach' button in meta box (string)
|
155 |
'button_text' => __( 'Attach Files', 'attachments' ),
|
156 |
|
@@ -291,7 +300,7 @@ You can also retrieve various attributes of the current Attachment directly usin
|
|
291 |
Source: <?php echo $attachments->src( 'full' ); ?><br />
|
292 |
Size: <?php echo $attachments->filesize(); ?><br />
|
293 |
Title Field: <?php echo $attachments->field( 'title' ); ?><br />
|
294 |
-
Caption Field:
|
295 |
</li>
|
296 |
<?php endwhile; ?>
|
297 |
</ul>
|
@@ -319,7 +328,7 @@ If you don't want to use the above implementation to loop through your Attachmen
|
|
319 |
Source: <?php echo $attachments->src( 'full', $my_index ); ?><br />
|
320 |
Size: <?php echo $attachments->filesize( $my_index ); ?><br />
|
321 |
Title Field: <?php echo $attachments->field( 'title', $my_index ); ?><br />
|
322 |
-
Caption Field:
|
323 |
</li>
|
324 |
</ul>
|
325 |
<?php endif; ?>
|
@@ -372,6 +381,51 @@ $defaults = array(
|
|
372 |
|
373 |
Once you've performed your search, you can loop through the returned Attachments as you normally would.
|
374 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
## Screenshots
|
376 |
|
377 |
##### An Attachments meta box sitting below the content editor
|
@@ -419,6 +473,13 @@ Attachments uses WordPress' built in Media library for uploads and storage.
|
|
419 |
|
420 |
<dl>
|
421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
<dt>3.3.3</dt>
|
423 |
<dd>Fixed a PHP Warning when activated using Multisite</dd>
|
424 |
<dd>Slightly modified the migration process to better handle plugins like WPML (props sebastian.friedrich)</dd>
|
@@ -526,6 +587,5 @@ Planned feature additions include:
|
|
526 |
* Additional field type: radio
|
527 |
* User-defined limiting the number of Attachments per instance
|
528 |
* User-defined custom field types
|
529 |
-
* Additional hooks/actions from top to bottom
|
530 |
* Shortcode(s)
|
531 |
* Output templates
|
9 |
* **[Upgrade Notice](#upgrade-notice)** *Pay specific attention if upgrading from a version before 3.0*
|
10 |
* [Usage](#usage)
|
11 |
* [Disable Settings Screen](#disable-settings-screen)
|
12 |
+
* [Setting Up Instances](#setting-up-instances) - Create meta boxes for your Posts, Pages, and Custom Post Types
|
13 |
* [Disable the Default Instance](#disable-the-default-instance)
|
14 |
* [Create Custom Instances](#create-custom-instances)
|
15 |
* [Fields Reference](#fields-reference)
|
18 |
* [Retrieve Attachment Attributes](#retrieve-attachment-attributes)
|
19 |
* [Retrieve Single Attachments](#retrieve-single-attachments)
|
20 |
* [Search](#search)
|
21 |
+
* [Filters](#filters)
|
22 |
+
* [Post Meta Key](#post-meta-key) - Change the `meta_key` used to store Attachments' data
|
23 |
+
* [Get Attachments](#get-attachments) - Edit the order of Attachments in your theme
|
24 |
* [Screenshots](#screenshots)
|
25 |
* [Frequently Asked Questions](#frequently-asked-questions)
|
26 |
* [Changelog](#changelog)
|
87 |
|
88 |
## Usage
|
89 |
|
90 |
+
Attachments is based on *instances* which correlate directly with the meta boxes that appear on edit screens of Posts, Pages, and Custom Post Types. By default Attachments ships with a single meta box that appears *only on Posts and Pages*. It has two fields: one for Title and one for Caption. If you would like to disable or customize the default instance, or you'd like to create additional instances with custom fields for different post types, please see [Setting Up Instances](#setting-up-instances).
|
91 |
+
|
92 |
### Disable Settings Screen
|
93 |
|
94 |
Attachments ships with a `Settings` screen (found under the `Settings` menu in the main WordPress admin navigation) that facilitates data migration from version 1.x and also offers some code snippets. If you would like to **disable the Settings screen** add the following to your theme's `functions.php`:
|
121 |
|
122 |
function my_attachments( $attachments )
|
123 |
{
|
124 |
+
$fields = array(
|
125 |
array(
|
126 |
'name' => 'title', // unique field name
|
127 |
'type' => 'text', // registered field type
|
156 |
// include a note within the meta box (string)
|
157 |
'note' => 'Attach files here!',
|
158 |
|
159 |
+
// by default new Attachments will be appended to the list
|
160 |
+
// but you can have then prepend if you set this to false
|
161 |
+
'append' => true,
|
162 |
+
|
163 |
// text for 'Attach' button in meta box (string)
|
164 |
'button_text' => __( 'Attach Files', 'attachments' ),
|
165 |
|
300 |
Source: <?php echo $attachments->src( 'full' ); ?><br />
|
301 |
Size: <?php echo $attachments->filesize(); ?><br />
|
302 |
Title Field: <?php echo $attachments->field( 'title' ); ?><br />
|
303 |
+
Caption Field: <?php echo $attachments->field( 'caption' ); ?>
|
304 |
</li>
|
305 |
<?php endwhile; ?>
|
306 |
</ul>
|
328 |
Source: <?php echo $attachments->src( 'full', $my_index ); ?><br />
|
329 |
Size: <?php echo $attachments->filesize( $my_index ); ?><br />
|
330 |
Title Field: <?php echo $attachments->field( 'title', $my_index ); ?><br />
|
331 |
+
Caption Field: <?php echo $attachments->field( 'caption', $my_index ); ?>
|
332 |
</li>
|
333 |
</ul>
|
334 |
<?php endif; ?>
|
381 |
|
382 |
Once you've performed your search, you can loop through the returned Attachments as you normally would.
|
383 |
|
384 |
+
## Filters
|
385 |
+
|
386 |
+
Attachments makes use of various filters to allow customization of it's internals without having to edit any of the code within the plugin. These filters can be utilized within your theme's `functions.php`.
|
387 |
+
|
388 |
+
### Post Meta Key
|
389 |
+
|
390 |
+
Attachments stores it's data in the `postmeta` table of the WordPress database alongside your other Custom Field data. The default `meta_key` is `attachments` but you might want to change the `meta_key` Attachments uses to store it's data. You can use the `attachments_meta_key` filter to do just that:
|
391 |
+
|
392 |
+
```php
|
393 |
+
function my_attachments_meta_key()
|
394 |
+
{
|
395 |
+
return '_my_attachments_meta_key';
|
396 |
+
}
|
397 |
+
|
398 |
+
add_filter( 'attachments_meta_key', 'my_attachments_meta_key' );
|
399 |
+
```
|
400 |
+
|
401 |
+
Adding the above to your theme's `functions.php` will tell Attachments to save all of it's data using a `meta_key` of `_my_attachments_meta_key` (keys prefixed with _ will be hidden from the Custom Fields meta box).
|
402 |
+
|
403 |
+
### Get Attachments
|
404 |
+
|
405 |
+
There may be a time where you'd like to alter Attachments' data before working with it in your theme. For example you may want to randomize Attachments before outputting them. The `attachments_get_{$instance}` filter allows you to do just that:
|
406 |
+
|
407 |
+
```php
|
408 |
+
function my_attachments_randomize( $attachments )
|
409 |
+
{
|
410 |
+
return shuffle( $attachments );
|
411 |
+
}
|
412 |
+
|
413 |
+
add_filter( 'attachments_get_my_attachments', 'my_attachments_randomize' );
|
414 |
+
```
|
415 |
+
|
416 |
+
**NOTE** that this filter *depends on your instance name*. In the example above the filter only applies when working with the `my_attachments` instance. If your instance name was `foo_bar` and you wanted to reverse the order of your Attachments before using them, the filter would look like this:
|
417 |
+
|
418 |
+
```php
|
419 |
+
function my_attachments_reverse( $attachments )
|
420 |
+
{
|
421 |
+
return array_reverse( $attachments );
|
422 |
+
}
|
423 |
+
|
424 |
+
add_filter( 'attachments_get_foo_bar', 'my_attachments_reverse' );
|
425 |
+
```
|
426 |
+
|
427 |
+
Please keep in mind the instance name requirement when setting up this filter.
|
428 |
+
|
429 |
## Screenshots
|
430 |
|
431 |
##### An Attachments meta box sitting below the content editor
|
473 |
|
474 |
<dl>
|
475 |
|
476 |
+
<dt>3.4</dt>
|
477 |
+
<dd>New filter: <code>attachments_meta_key</code> facilitates using a different meta key for Attachments storage</dd>
|
478 |
+
<dd>New filter: <code>attachments_get_<strong>{my_instance}</strong></code> (where <code><strong>{my_instance}</strong></code> is your instance name) allows you to filter Attachments per instance once they've been retrieved</dd>
|
479 |
+
<dd>Fixed an issue where retrieving single Attachments didn't properly pass the index to attribute methods</dd>
|
480 |
+
<dd>Fixed PHP Warnings when Network Activating</dd>
|
481 |
+
<dd>You can now have new Attachments <em>prepend</em> the list instead of append by setting <code>append => false</code> in your instance</dd>
|
482 |
+
|
483 |
<dt>3.3.3</dt>
|
484 |
<dd>Fixed a PHP Warning when activated using Multisite</dd>
|
485 |
<dd>Slightly modified the migration process to better handle plugins like WPML (props sebastian.friedrich)</dd>
|
587 |
* Additional field type: radio
|
588 |
* User-defined limiting the number of Attachments per instance
|
589 |
* User-defined custom field types
|
|
|
590 |
* Shortcode(s)
|
591 |
* Output templates
|
classes/class.attachments.php
CHANGED
@@ -59,7 +59,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
59 |
|
60 |
// establish our environment variables
|
61 |
|
62 |
-
$this->version = '3.
|
63 |
$this->url = ATTACHMENTS_URL;
|
64 |
$this->dir = ATTACHMENTS_DIR;
|
65 |
|
@@ -81,7 +81,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
81 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_pointer' ), 999 );
|
82 |
|
83 |
// register our user-defined instances
|
84 |
-
add_action( 'init', array( $this, '
|
85 |
|
86 |
// determine which instances apply to the current post type
|
87 |
add_action( 'init', array( $this, 'set_instances_for_current_post_type' ) );
|
@@ -100,9 +100,31 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
100 |
add_action( 'admin_head', array( $this, 'field_inits' ) );
|
101 |
add_action( 'admin_print_footer_scripts', array( $this, 'field_assets' ) );
|
102 |
|
103 |
-
//
|
104 |
-
if(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
$this->attachments = $this->get_attachments( $instance, $post_id );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
}
|
107 |
|
108 |
|
@@ -114,6 +136,15 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
114 |
*/
|
115 |
function check_for_legacy_data()
|
116 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
// deal with our legacy issues if the user hasn't dismissed or migrated already
|
118 |
if( false == get_option( 'attachments_migrated' ) && false == get_option( 'attachments_ignore_migration' ) )
|
119 |
{
|
@@ -370,7 +401,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
370 |
else
|
371 |
{
|
372 |
// either it's not an image or we don't have the proper size, so we'll use the icon
|
373 |
-
$asset = $this->icon();
|
374 |
}
|
375 |
|
376 |
return $asset;
|
@@ -399,7 +430,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
399 |
*/
|
400 |
function image( $size = 'thumbnail', $index = null )
|
401 |
{
|
402 |
-
$asset = $this->asset( $size );
|
403 |
|
404 |
$image_src = $asset[0];
|
405 |
$image_width = $asset[1];
|
@@ -421,7 +452,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
421 |
*/
|
422 |
function src( $size = 'thumbnail', $index = null )
|
423 |
{
|
424 |
-
$asset = $this->asset( $size );
|
425 |
return $asset[0];
|
426 |
}
|
427 |
|
@@ -550,7 +581,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
550 |
*
|
551 |
* @since 3.0
|
552 |
*/
|
553 |
-
function
|
554 |
{
|
555 |
// implement our default instance if appropriate
|
556 |
if( !defined( 'ATTACHMENTS_DEFAULT_INSTANCE' ) )
|
@@ -632,10 +663,15 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
632 |
|
633 |
?>
|
634 |
|
635 |
-
<div id="attachments-<?php echo $instance->name; ?>" class="attachments-parent-container">
|
636 |
<?php if( !empty( $instance->note ) ) : ?>
|
637 |
<div class="attachments-note"><?php echo apply_filters( 'the_content', $instance->note ); ?></div>
|
638 |
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
639 |
<div class="attachments-container attachments-<?php echo $instance->name; ?>"><?php
|
640 |
if( isset( $instance->attachments ) && !empty( $instance->attachments ) )
|
641 |
{
|
@@ -649,9 +685,11 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
649 |
}
|
650 |
}
|
651 |
?></div>
|
652 |
-
|
653 |
-
<
|
654 |
-
|
|
|
|
|
655 |
</div>
|
656 |
<script type="text/javascript">
|
657 |
jQuery(document).ready(function($){
|
@@ -734,7 +772,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
734 |
var templateData = attachment.attributes;
|
735 |
|
736 |
// append the template
|
737 |
-
$element.find('.attachments-container')
|
738 |
|
739 |
// if we're in a sidebar we DO want to show the fields which are normally hidden on load via CSS
|
740 |
if($element.parents('#side-sortables')){
|
@@ -919,6 +957,10 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
919 |
// include a note within the meta box (string)
|
920 |
'note' => null, // no note
|
921 |
|
|
|
|
|
|
|
|
|
922 |
// text for 'Attach' button (string)
|
923 |
'button_text' => __( 'Attach', 'attachments' ),
|
924 |
|
@@ -1450,15 +1492,20 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
1450 |
elseif( is_null( $instance ) )
|
1451 |
{
|
1452 |
// return them all, regardless of instance
|
1453 |
-
|
1454 |
-
foreach( $
|
1455 |
-
$
|
|
|
1456 |
}
|
1457 |
|
1458 |
// tack on the post ID for each attachment
|
1459 |
for( $i = 0; $i < count( $attachments ); $i++ )
|
1460 |
$attachments[$i]->post_id = $post_id;
|
1461 |
|
|
|
|
|
|
|
|
|
1462 |
return $attachments;
|
1463 |
}
|
1464 |
|
59 |
|
60 |
// establish our environment variables
|
61 |
|
62 |
+
$this->version = '3.4';
|
63 |
$this->url = ATTACHMENTS_URL;
|
64 |
$this->dir = ATTACHMENTS_DIR;
|
65 |
|
81 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_pointer' ), 999 );
|
82 |
|
83 |
// register our user-defined instances
|
84 |
+
add_action( 'init', array( $this, 'setup_instances' ) );
|
85 |
|
86 |
// determine which instances apply to the current post type
|
87 |
add_action( 'init', array( $this, 'set_instances_for_current_post_type' ) );
|
100 |
add_action( 'admin_head', array( $this, 'field_inits' ) );
|
101 |
add_action( 'admin_print_footer_scripts', array( $this, 'field_assets' ) );
|
102 |
|
103 |
+
// execution of actions varies depending on whether we're in the admin or not and an instance was passed
|
104 |
+
if( is_admin() )
|
105 |
+
{
|
106 |
+
add_action( 'after_setup_theme', array( $this, 'apply_init_filters' ) );
|
107 |
+
$this->attachments = $this->get_attachments( $instance, $post_id );
|
108 |
+
}
|
109 |
+
elseif( !is_null( $instance ) )
|
110 |
+
{
|
111 |
+
$this->apply_init_filters();
|
112 |
$this->attachments = $this->get_attachments( $instance, $post_id );
|
113 |
+
}
|
114 |
+
|
115 |
+
}
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Various initialization filter triggers
|
121 |
+
*
|
122 |
+
* @since 3.4
|
123 |
+
*/
|
124 |
+
function apply_init_filters()
|
125 |
+
{
|
126 |
+
// allows a different meta_key to be used
|
127 |
+
$this->meta_key = apply_filters( 'attachments_meta_key', $this->meta_key );
|
128 |
}
|
129 |
|
130 |
|
136 |
*/
|
137 |
function check_for_legacy_data()
|
138 |
{
|
139 |
+
// we'll get a warning issued if fired when Network Activated
|
140 |
+
// since it's supremely unlikely we'd have legacy data at this point, we're going to short circuit
|
141 |
+
if( is_multisite() )
|
142 |
+
{
|
143 |
+
$plugins = get_site_option( 'active_sitewide_plugins' );
|
144 |
+
if ( isset($plugins['attachments/index.php']) )
|
145 |
+
return;
|
146 |
+
}
|
147 |
+
|
148 |
// deal with our legacy issues if the user hasn't dismissed or migrated already
|
149 |
if( false == get_option( 'attachments_migrated' ) && false == get_option( 'attachments_ignore_migration' ) )
|
150 |
{
|
401 |
else
|
402 |
{
|
403 |
// either it's not an image or we don't have the proper size, so we'll use the icon
|
404 |
+
$asset = $this->icon( $index );
|
405 |
}
|
406 |
|
407 |
return $asset;
|
430 |
*/
|
431 |
function image( $size = 'thumbnail', $index = null )
|
432 |
{
|
433 |
+
$asset = $this->asset( $size, $index );
|
434 |
|
435 |
$image_src = $asset[0];
|
436 |
$image_width = $asset[1];
|
452 |
*/
|
453 |
function src( $size = 'thumbnail', $index = null )
|
454 |
{
|
455 |
+
$asset = $this->asset( $size, $index );
|
456 |
return $asset[0];
|
457 |
}
|
458 |
|
581 |
*
|
582 |
* @since 3.0
|
583 |
*/
|
584 |
+
function setup_instances()
|
585 |
{
|
586 |
// implement our default instance if appropriate
|
587 |
if( !defined( 'ATTACHMENTS_DEFAULT_INSTANCE' ) )
|
663 |
|
664 |
?>
|
665 |
|
666 |
+
<div id="attachments-<?php echo $instance->name; ?>" class="attachments-parent-container<?php if( $instance->append == false ) : ?> attachments-prepend<?php endif; ?>">
|
667 |
<?php if( !empty( $instance->note ) ) : ?>
|
668 |
<div class="attachments-note"><?php echo apply_filters( 'the_content', $instance->note ); ?></div>
|
669 |
<?php endif; ?>
|
670 |
+
<?php if( $instance->append == false ) : ?>
|
671 |
+
<div class="attachments-invoke-wrapper">
|
672 |
+
<a class="button attachments-invoke"><?php _e( esc_attr( $instance->button_text ), 'attachments' ); ?></a>
|
673 |
+
</div>
|
674 |
+
<?php endif; ?>
|
675 |
<div class="attachments-container attachments-<?php echo $instance->name; ?>"><?php
|
676 |
if( isset( $instance->attachments ) && !empty( $instance->attachments ) )
|
677 |
{
|
685 |
}
|
686 |
}
|
687 |
?></div>
|
688 |
+
<?php if( $instance->append == true ) : ?>
|
689 |
+
<div class="attachments-invoke-wrapper">
|
690 |
+
<a class="button attachments-invoke"><?php _e( esc_attr( $instance->button_text ), 'attachments' ); ?></a>
|
691 |
+
</div>
|
692 |
+
<?php endif; ?>
|
693 |
</div>
|
694 |
<script type="text/javascript">
|
695 |
jQuery(document).ready(function($){
|
772 |
var templateData = attachment.attributes;
|
773 |
|
774 |
// append the template
|
775 |
+
$element.find('.attachments-container').<?php if( $instance->append ) : ?>append<?php else : ?>prepend<?php endif; ?>(template(templateData));
|
776 |
|
777 |
// if we're in a sidebar we DO want to show the fields which are normally hidden on load via CSS
|
778 |
if($element.parents('#side-sortables')){
|
957 |
// include a note within the meta box (string)
|
958 |
'note' => null, // no note
|
959 |
|
960 |
+
// by default new Attachments will be appended to the list
|
961 |
+
// but you can have then prepend if you set this to false
|
962 |
+
'append' => true,
|
963 |
+
|
964 |
// text for 'Attach' button (string)
|
965 |
'button_text' => __( 'Attach', 'attachments' ),
|
966 |
|
1492 |
elseif( is_null( $instance ) )
|
1493 |
{
|
1494 |
// return them all, regardless of instance
|
1495 |
+
if( is_array( $attachments_raw ) && count( $attachments_raw ) )
|
1496 |
+
foreach( $attachments_raw as $instance => $attachments_unprocessed )
|
1497 |
+
foreach( $attachments_unprocessed as $unprocessed_attachment )
|
1498 |
+
$attachments[] = $this->process_attachment( $unprocessed_attachment, $instance );
|
1499 |
}
|
1500 |
|
1501 |
// tack on the post ID for each attachment
|
1502 |
for( $i = 0; $i < count( $attachments ); $i++ )
|
1503 |
$attachments[$i]->post_id = $post_id;
|
1504 |
|
1505 |
+
// we don't want the filter to run on the admin side of things
|
1506 |
+
if( !is_admin() )
|
1507 |
+
$attachments = apply_filters( "attachments_get_{$instance}", $attachments );
|
1508 |
+
|
1509 |
return $attachments;
|
1510 |
}
|
1511 |
|
css/attachments.css
CHANGED
@@ -62,6 +62,28 @@ a.attachments-invoke {
|
|
62 |
border-top:1px solid #dfdfdf;
|
63 |
}
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
.attachments-container .ui-sortable-helper {
|
66 |
background:#F9F9F9;
|
67 |
}
|
62 |
border-top:1px solid #dfdfdf;
|
63 |
}
|
64 |
|
65 |
+
.attachments-prepend {
|
66 |
+
padding-top:34px;
|
67 |
+
}
|
68 |
+
|
69 |
+
.attachments-prepend .attachments-container {
|
70 |
+
padding-bottom:0;
|
71 |
+
}
|
72 |
+
|
73 |
+
.attachments-prepend .attachments-container .attachments-attachment:first-of-type {
|
74 |
+
margin-top:20px;
|
75 |
+
}
|
76 |
+
|
77 |
+
.attachments-prepend .attachments-invoke-wrapper {
|
78 |
+
bottom:auto;
|
79 |
+
top:-6px;
|
80 |
+
margin-bottom:0;
|
81 |
+
border-bottom-left-radius:0;
|
82 |
+
border-bottom-right-radius:0;
|
83 |
+
border-top:0;
|
84 |
+
border-bottom:1px solid #dfdfdf;
|
85 |
+
}
|
86 |
+
|
87 |
.attachments-container .ui-sortable-helper {
|
88 |
background:#F9F9F9;
|
89 |
}
|
index.php
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
* Description: Attachments gives the ability to append any number of Media Library items to Pages, Posts, and Custom Post Types
|
7 |
* Author: Jonathan Christopher
|
8 |
* Author URI: http://mondaybynoon.com/
|
9 |
-
* Version: 3.
|
10 |
* Text Domain: attachments
|
11 |
* Domain Path: /languages/
|
12 |
* License: GPLv2 or later
|
6 |
* Description: Attachments gives the ability to append any number of Media Library items to Pages, Posts, and Custom Post Types
|
7 |
* Author: Jonathan Christopher
|
8 |
* Author URI: http://mondaybynoon.com/
|
9 |
+
* Version: 3.4
|
10 |
* Text Domain: attachments
|
11 |
* Domain Path: /languages/
|
12 |
* License: GPLv2 or later
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://mondaybynoon.com/donate/
|
|
4 |
Tags: post, page, posts, pages, images, PDF, doc, Word, image, jpg, jpeg, picture, pictures, photos, attachment
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.5.1
|
7 |
-
Stable tag: 3.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -12,6 +12,8 @@ Attachments allows you to simply append any number of items from your WordPress
|
|
12 |
|
13 |
== Description ==
|
14 |
|
|
|
|
|
15 |
Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types. This plugin *does not* directly interact with your theme, you will need to edit your template files.
|
16 |
|
17 |
= Updated for WordPress 3.5! =
|
@@ -69,33 +71,7 @@ Version 3 is a *major* rewrite. While I've taken precautions in ensuring you won
|
|
69 |
|
70 |
== Frequently Asked Questions ==
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
You need to turn on Attachments for your post types. View the Attachments settings under the main Settings menu in the WordPress admin.
|
75 |
-
|
76 |
-
= Attachments are not showing up in my theme =
|
77 |
-
|
78 |
-
You will need to edit your theme files where applicable. Please reference the **Other Notes > Usage** instructions.
|
79 |
-
|
80 |
-
= How do I disable the default Attachments meta box? =
|
81 |
-
|
82 |
-
You will need to edit your Attachments configuration. Please reference the **Other Notes > Usage** instructions.
|
83 |
-
|
84 |
-
= How do I change the fields for each Attachment? =
|
85 |
-
|
86 |
-
You will need to edit your Attachments configuration. Please reference the **Other Notes > Usage** instructions.
|
87 |
-
|
88 |
-
= Where are uploads saved? =
|
89 |
-
|
90 |
-
Attachments uses WordPress' built in Media library for uploads and storage.
|
91 |
-
|
92 |
-
= I lost my Attachments after upgrading! =
|
93 |
-
|
94 |
-
***DO NOT update any Post/Page/CPT that should have existing Attachments***, the data *has not been lost*.
|
95 |
-
|
96 |
-
If you disabled the default intsance after migrating, used the default values when migrating, and used a snippet from the docs to add a new one, **make sure your instance names match**. The default value during migration uses an instance name of `attachments` while many snippets use `my_attachments`.
|
97 |
-
|
98 |
-
Else: please reference the **Installation > Upgrade Notice** details.
|
99 |
|
100 |
== Screenshots ==
|
101 |
|
@@ -107,525 +83,17 @@ Else: please reference the **Installation > Upgrade Notice** details.
|
|
107 |
|
108 |
== Changelog ==
|
109 |
|
110 |
-
|
111 |
-
* Fixed a PHP Warning when activated using Multisite
|
112 |
-
* Slightly modified the migration process to better handle plugins like WPML (props sebastian.friedrich)
|
113 |
-
|
114 |
-
= 3.3.2 =
|
115 |
-
* You can now specify which view is default when browsing the Media modal (e.g. have 'Upload Files' be default instead of 'Media Library')
|
116 |
-
|
117 |
-
= 3.3.1 =
|
118 |
-
* Added meta box positioning arguments when registering instances
|
119 |
-
* Cleaned up some CSS when Attachments instances are in the sidebar
|
120 |
-
|
121 |
-
= 3.3 =
|
122 |
-
* Added a `search()` method to allow searching for Attachments based on their attributes (e.g. attachment ID, post ID, post type, field values, etc.)
|
123 |
-
* Improved the 'Remove' animation
|
124 |
-
* New field: select
|
125 |
-
* New parameter for Attachments attributes methods. You can pass the index (`int`) of the Attachment you'd like to utilize when firing the method.
|
126 |
-
|
127 |
-
= 3.2 =
|
128 |
-
* Added option to disable the Settings screen
|
129 |
-
* Added the ability to set a default for fields using the metadata that exists in WordPress. Available defaults include: title, caption, alt, and description. If set, the metadata for the correlating field will be used as the field default when initially adding an Attachment from the Media modal. Only applies to text, textarea, and wysiwyg fields.
|
130 |
-
* Added a `get_single()` method that allows you to specifically retrieve a single Attachment
|
131 |
-
* Clarified some documentation
|
132 |
-
|
133 |
-
= 3.1.4 =
|
134 |
-
* Changed 'Delete' to 'Remove' so as to not make it sound like the file itself would be deleted from Media (props Lane Goldberg)
|
135 |
-
* Better handling of posts that have no Attachments when saving
|
136 |
-
|
137 |
-
= 3.1.3 =
|
138 |
-
* Fixed a potential issue with the WYSIWYG field not working on CPT without editor support
|
139 |
-
* Field assets are less aggressive and only fire when necessary
|
140 |
-
* Reorganized the migration process a bit in prep for Attachments Pro support
|
141 |
-
|
142 |
-
= 3.1.2 =
|
143 |
-
* Fixed a regression that prevented successful migration of legacy Attachments data
|
144 |
-
|
145 |
-
= 3.1.1 =
|
146 |
-
* Fixed a Fatal Error when registering the text field
|
147 |
-
|
148 |
-
= 3.1 =
|
149 |
-
* New field: wysiwyg
|
150 |
-
* Fields will now properly respect line breaks
|
151 |
-
* Fields will now properly return HTML instead of escaped HTML
|
152 |
-
|
153 |
-
= 3.0.9 =
|
154 |
-
* Fixed an issue where special characters would break title/caption fields during migration
|
155 |
-
|
156 |
-
= 3.0.8.2 =
|
157 |
-
* Fixed a CSS issue with only one text field
|
158 |
-
|
159 |
-
= 3.0.8.1 =
|
160 |
-
* Better storage of special characters for PHP 5.4+
|
161 |
-
|
162 |
-
= 3.0.8 =
|
163 |
-
* Fixed an issue in Firefox where you weren't able to focus inputs unless you clicked their label
|
164 |
-
* New field: textarea
|
165 |
-
|
166 |
-
= 3.0.7 =
|
167 |
-
* Proper sanitization of Custom Post Type names (as WordPress does it)
|
168 |
-
|
169 |
-
= 3.0.6 =
|
170 |
-
* Fixed a possible JavaScript error if an Attachment that's an image doesn't have a proper thumbnail URL
|
171 |
-
* Added a total() method that will return the number of Attachments for the current instance
|
172 |
-
* When requesting the image() for a non-image Attachment, the WordPress-defined icon will be returned
|
173 |
-
* Added an icon() method that will return the WordPress-defined icon for the Attachment
|
174 |
-
* Cleaned up a PHP Warning when trying to save for an undefined field type
|
175 |
-
* Fixed an issue where template tags would be output for non-image Attachments after saving
|
176 |
-
|
177 |
-
= 3.0.5 =
|
178 |
-
* Fixed a regression in handling Custom Post Type names that would too aggressively interfere with instance regustration
|
179 |
-
* Fixed an issue when working with non-image Attachments
|
180 |
-
|
181 |
-
= 3.0.4 =
|
182 |
-
* Fixed an issue that prevented the choosing of a Featured Image for a Custom Post Type if Attachments was activated
|
183 |
-
* Attachments now only enqueues its assets on edit screens that actually utilize Attachments
|
184 |
-
* Fixed a potential JavaScript error triggered when a 'thumbnail' image size was not available
|
185 |
-
* Prevented incorrect usage of dashes used in CPT names for post_type argument when registering Attachments instances (fixes an integration issue with WP e-Commerce)
|
186 |
-
* Prevented re-running of migration process to avoid duplicates (e.g. on browser reload)
|
187 |
-
|
188 |
-
= 3.0.3 =
|
189 |
-
* Fixed an issue that prevented defining a post ID when retrieving Attachments outside The Loop
|
190 |
-
* Cleaned up potential PHP warning when Attachments were requested for a post that had none
|
191 |
-
|
192 |
-
= 3.0.2 =
|
193 |
-
* Fixed an issue where some HTML entities were not properly stored
|
194 |
-
|
195 |
-
= 3.0.1 =
|
196 |
-
* Fixed an issue where legacy mode was always enabled
|
197 |
-
|
198 |
-
= 3.0 =
|
199 |
-
* **Major** rewrite. After three years of development, Attachments has been rewritten to make
|
200 |
-
even better use of what WordPress has to offer
|
201 |
-
* Utilizes the brand spanking new 3.5 Media workflow
|
202 |
-
* Configuration now takes place within your theme or a plugin
|
203 |
-
* Multiple meta boxes! You can segment groups of Attachments with new instances, each unique
|
204 |
-
* Dynamic fields! You can manipulate which fields each instance uses
|
205 |
-
* File type limits. Limit which files are available to Attachments (e.g. images, audio, video)
|
206 |
-
|
207 |
-
= 1.6.2.1 =
|
208 |
-
* Fixed an issue with Handlebars in Firefox
|
209 |
-
* Better handling of Attachment name
|
210 |
-
|
211 |
-
= 1.6.2 =
|
212 |
-
* Fixed an issue when you both add and delete Attachments prior to saving posts
|
213 |
-
* Cleaned up the JavaScript that powers the file browse interaction
|
214 |
-
* Swapped out some custom code for WordPress native function calls
|
215 |
-
* Better handling of asset inclusion
|
216 |
-
|
217 |
-
= 1.6.1 =
|
218 |
-
* Fixed a conflict with WP-Ecommerce
|
219 |
-
|
220 |
-
= 1.6 =
|
221 |
-
* Updated settings to use the Settings API
|
222 |
-
* Tested with WordPress 3.3
|
223 |
-
* Removed support for extremely legacy Attachments storage. If you have upgraded from a version before 1.0.7, please downgrade to 1.5.10 and let me know.
|
224 |
-
|
225 |
-
= 1.5.10 =
|
226 |
-
* WordPress 3.3 compatibility
|
227 |
-
* Updated Polish translation
|
228 |
-
* Removed soon-to-be deprecated jQuery methods in prep for 1.7
|
229 |
-
|
230 |
-
= 1.5.9 =
|
231 |
-
* Retrieve file size when `firing attachments_get_attachments()`
|
232 |
-
|
233 |
-
= 1.5.8 =
|
234 |
-
* Code cleanup
|
235 |
-
|
236 |
-
= 1.5.7 =
|
237 |
-
* Translation update
|
238 |
-
|
239 |
-
= 1.5.6 =
|
240 |
-
* Better restriction of JavaScript assets as a preventative measure for potential plugin conflicts
|
241 |
-
|
242 |
-
= 1.5.5 =
|
243 |
-
* Re-implemented bulk Attach
|
244 |
-
|
245 |
-
= 1.5.4 =
|
246 |
-
* Updated the way Thickbox is hijacked in an effort to be more stable among tab switching. As an unfortunate result, bulk attaching is no longer possible.
|
247 |
-
* Added environment check in preparation for future feature updates
|
248 |
-
* Updated Polish translation, courtesy of Wiktor Maj
|
249 |
-
|
250 |
-
= 1.5.3.1 =
|
251 |
-
* Hotfix for an oversight where Attachments no longer display with Custom Post Types
|
252 |
-
|
253 |
-
= 1.5.3.1 =
|
254 |
-
* PHP warning cleanup
|
255 |
-
* Settings now respect Custom Post Types that are set to show_ui
|
256 |
-
|
257 |
-
= 1.5.3 =
|
258 |
-
* Added Polish translation, courtesy of Wiktor Maj
|
259 |
-
* Added Posts and Pages to Settings
|
260 |
-
* Added new setting to natively 'Attach' Attachments via $post->post_parent
|
261 |
-
|
262 |
-
|
263 |
-
= 1.5.2 =
|
264 |
-
* Added Swedish translation, courtesy of Sebastian Johansson
|
265 |
-
* 'Attach' button is now localized
|
266 |
-
* Fixed a couple of other miscellaneous localization issues
|
267 |
-
* Added Italian translation, courtesy of Andrea Bersi
|
268 |
-
* Fixed a number of PHP notices/warnings in more strict environments
|
269 |
-
|
270 |
-
= 1.5.1.2 =
|
271 |
-
* Fixed bug with handling legacy Attachments data store
|
272 |
-
* Updated localization hook for options screen
|
273 |
-
|
274 |
-
= 1.5.1.1 =
|
275 |
-
* Fixed JS var naming error in IE
|
276 |
-
* Hid NextGen tab in browser
|
277 |
-
|
278 |
-
= 1.5.1 =
|
279 |
-
* Fixed thumbnail rendering issue
|
280 |
-
* Fixed issue where browse modal included extraneous items after filtering or searching
|
281 |
-
|
282 |
-
= 1.5 =
|
283 |
-
* Completely revamped the upload/browse experience. Attachments now uses WordPress default modal dialogs.
|
284 |
-
|
285 |
-
= 1.1.1 =
|
286 |
-
* Fixed a bug with storing foreign characters
|
287 |
-
* Added live search to Browse Existing Dialog
|
288 |
-
|
289 |
-
= 1.1 =
|
290 |
-
* Fixed a bug where Attachments meta box would display on Custom Post Types even when set not to
|
291 |
-
* Fixed a bug where special characters were lost on save
|
292 |
-
* Fixed a bug where Browse/Add buttons failed to work when an Editor was not available on a Custom Post Type
|
293 |
-
|
294 |
-
= 1.0.9 =
|
295 |
-
* Support for Custom Post Types (found in Settings)
|
296 |
-
* Revised Portuguese Translation by [Miriam de Paula](http://www.tecsite.com.br)
|
297 |
-
|
298 |
-
= 1.0.8 =
|
299 |
-
* Fixed possible bug with images not thumbnailing properly
|
300 |
-
* Tabbed media browsing implemented
|
301 |
-
|
302 |
-
= 1.0.7.2 =
|
303 |
-
* Revised Portuguese Translation by [Nicolas Mollet](http://www.nicolasmollet.com)
|
304 |
-
* Added French Translation
|
305 |
-
|
306 |
-
= 1.0.7.1 =
|
307 |
-
* Added Portuguese Translation (rough)
|
308 |
-
|
309 |
-
= 1.0.7 =
|
310 |
-
* Numerous fixes to enhance data integrity
|
311 |
-
* Implemented a change to improve data portability
|
312 |
-
* Moved to Thickbox (from Shadowbox) as to be more in line with WordPress
|
313 |
-
|
314 |
-
= 1.0.5 =
|
315 |
-
* Added the option to limit available Attachments to the current user (defaults to *false*)
|
316 |
-
|
317 |
-
= 1.0.4.1 =
|
318 |
-
* Removed all shortcodes in an effort to boost compatibility
|
319 |
-
|
320 |
-
= 1.0.4 =
|
321 |
-
* Fixed a potential error resulting in PHP issuing a Warning when trying to attach Attachments
|
322 |
-
|
323 |
-
= 1.0.3 =
|
324 |
-
* Fixed an issue when `attachments_get_attachments()` returning no Attachments generating a warning
|
325 |
-
|
326 |
-
= 1.0.2 =
|
327 |
-
* Fixed an issue with deleting Attachments
|
328 |
-
|
329 |
-
= 1.0.1 =
|
330 |
-
* Fixed an error when adding only one attachment
|
331 |
-
* Added MIME type array value (`mime`) to available attachments
|
332 |
-
|
333 |
-
= 1.0 =
|
334 |
-
* First stable release
|
335 |
|
336 |
== Upgrade Notice ==
|
337 |
|
338 |
= 3.0 =
|
339 |
Now piggybacking the awesome Media workflow introduced in WordPress 3.5
|
340 |
|
341 |
-
= 1.0.8 =
|
342 |
-
As always, be sure to back up your database and files before upgrading.
|
343 |
-
|
344 |
-
= 1.0.7 =
|
345 |
-
Attachments are now stored in such a way that removes an in-place limitation on string lengths for both titles and captions.
|
346 |
-
|
347 |
== Roadmap ==
|
348 |
|
349 |
-
|
350 |
-
|
351 |
-
* Additional field type: checkbox
|
352 |
-
* Additional field type: radio
|
353 |
-
* User-defined limiting the number of Attachments per instance
|
354 |
-
* User-defined custom field types
|
355 |
-
* Additional hooks/actions from top to bottom
|
356 |
-
* Shortcode(s)
|
357 |
-
* Output templates
|
358 |
|
359 |
== Usage ==
|
360 |
|
361 |
-
|
362 |
-
|
363 |
-
Attachments ships with a `Settings` screen (found under the `Settings` menu in the main WordPress admin navigation) that facilitates data migration from version 1.x and also offers some code snippets. If you would like to **disable the Settings screen** add the following to your theme's `functions.php`:
|
364 |
-
|
365 |
-
`define( 'ATTACHMENTS_SETTINGS_SCREEN', false ); // disable the Settings screen`
|
366 |
-
|
367 |
-
= Setting Up Instances =
|
368 |
-
|
369 |
-
When Attachments is first activated, a default instance is created titled Attachments. It has two fields:
|
370 |
-
|
371 |
-
1. Title
|
372 |
-
1. Caption
|
373 |
-
|
374 |
-
**Disable the Default Instance**
|
375 |
-
|
376 |
-
If you would like to *disable the default instance* (meta box titled 'Attachments' with a 'Title' and 'Caption' field) add the following to your `wp-config.php`:
|
377 |
-
|
378 |
-
`define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );`
|
379 |
-
|
380 |
-
**Create Custom Instances**
|
381 |
-
|
382 |
-
You may create instances with your own custom fields by using the `attachments_register` action. To create your own instance add the following to your theme's `functions.php` or your own plugin:
|
383 |
-
|
384 |
-
`<?php
|
385 |
-
|
386 |
-
function my_attachments( $attachments )
|
387 |
-
{
|
388 |
-
$fields => array(
|
389 |
-
array(
|
390 |
-
'name' => 'title', // unique field name
|
391 |
-
'type' => 'text', // registered field type
|
392 |
-
'label' => __( 'Title', 'attachments' ), // label to display
|
393 |
-
'default' => 'title', // default value upon selection
|
394 |
-
),
|
395 |
-
array(
|
396 |
-
'name' => 'caption', // unique field name
|
397 |
-
'type' => 'textarea', // registered field type
|
398 |
-
'label' => __( 'Caption', 'attachments' ), // label to display
|
399 |
-
'default' => 'caption', // default value upon selection
|
400 |
-
),
|
401 |
-
);
|
402 |
-
|
403 |
-
$args = array(
|
404 |
-
|
405 |
-
// title of the meta box (string)
|
406 |
-
'label' => 'My Attachments',
|
407 |
-
|
408 |
-
// all post types to utilize (string|array)
|
409 |
-
'post_type' => array( 'post', 'page' ),
|
410 |
-
|
411 |
-
// meta box position (string) (normal, side or advanced)
|
412 |
-
'position' => 'normal',
|
413 |
-
|
414 |
-
// meta box priority (string) (high, default, low, core)
|
415 |
-
'priority' => 'high',
|
416 |
-
|
417 |
-
// allowed file type(s) (array) (image|video|text|audio|application)
|
418 |
-
'filetype' => null, // no filetype limit
|
419 |
-
|
420 |
-
// include a note within the meta box (string)
|
421 |
-
'note' => 'Attach files here!',
|
422 |
-
|
423 |
-
// text for 'Attach' button in meta box (string)
|
424 |
-
'button_text' => __( 'Attach Files', 'attachments' ),
|
425 |
-
|
426 |
-
// text for modal 'Attach' button (string)
|
427 |
-
'modal_text' => __( 'Attach', 'attachments' ),
|
428 |
-
|
429 |
-
// which tab should be the default in the modal (string) (browse|upload)
|
430 |
-
'router' => 'browse',
|
431 |
-
|
432 |
-
// fields array
|
433 |
-
'fields' => $fields,
|
434 |
-
|
435 |
-
);
|
436 |
-
|
437 |
-
$attachments->register( 'my_attachments', $args ); // unique instance name
|
438 |
-
}
|
439 |
-
|
440 |
-
add_action( 'attachments_register', 'my_attachments' );`
|
441 |
-
|
442 |
-
**Fields Reference**
|
443 |
-
|
444 |
-
At this time there are **four** field types available:
|
445 |
-
|
446 |
-
1. `text`
|
447 |
-
1. `textarea`
|
448 |
-
1. `select`
|
449 |
-
1. `wysiwyg`
|
450 |
-
|
451 |
-
When declaring fields for your instance, you'll be composing an array of fields, each with an array of parameters that set the various attributes of each field. Here is a full example of all available parameters for all available fields:
|
452 |
-
|
453 |
-
`<?php
|
454 |
-
/**
|
455 |
-
* Fields for the instance are stored in an array. Each field consists of
|
456 |
-
* an array with three required keys: name, type, label
|
457 |
-
* and one optional key: meta
|
458 |
-
*
|
459 |
-
* name - (string) The field name used. No special characters.
|
460 |
-
* type - (string) The registered field type.
|
461 |
-
* Fields available: text, textarea, wysiwyg, select
|
462 |
-
* label - (string) The label displayed for the field.
|
463 |
-
* default - (string) The default WordPress metadata to use when initially adding the Attachment
|
464 |
-
* Defaults available: title, caption, alt, description
|
465 |
-
* meta - (array) The field-specific parameters that apply only to that field type
|
466 |
-
*/
|
467 |
-
|
468 |
-
$fields => array(
|
469 |
-
array(
|
470 |
-
'name' => 'title', // unique field name
|
471 |
-
'type' => 'text', // registered field type
|
472 |
-
'label' => __( 'Title', 'attachments' ), // label to display
|
473 |
-
'default' => 'title', // default value upon selection
|
474 |
-
),
|
475 |
-
array(
|
476 |
-
'name' => 'caption', // unique field name
|
477 |
-
'type' => 'textarea', // registered field type
|
478 |
-
'label' => __( 'Caption', 'attachments' ), // label to display
|
479 |
-
'default' => 'caption', // default value upon selection
|
480 |
-
),
|
481 |
-
array(
|
482 |
-
'name' => 'option', // unique field name
|
483 |
-
'type' => 'select', // registered field type
|
484 |
-
'label' => __( 'Option', 'attachments' ), // label to display
|
485 |
-
'meta' => array( // field-specific meta as defined by field class
|
486 |
-
'allow_null' => true, // allow null value? (adds 'empty' <option>)
|
487 |
-
'multiple' => true, // multiple <select>?
|
488 |
-
'options' => array( // the <option>s to use
|
489 |
-
'1' => 'Option 1',
|
490 |
-
'2' => 'Option 2',
|
491 |
-
)
|
492 |
-
),
|
493 |
-
),
|
494 |
-
array(
|
495 |
-
'name' => 'description', // unique field name
|
496 |
-
'type' => 'wysiwyg', // registered field type
|
497 |
-
'label' => __( 'Description', 'attachments' ), // label to display
|
498 |
-
'default' => 'description', // default value upon selection
|
499 |
-
),
|
500 |
-
);
|
501 |
-
?>`
|
502 |
-
|
503 |
-
= Pulling Attachments to your Theme =
|
504 |
-
|
505 |
-
Once your instances are set up and working, you'll also need to edit your theme's template files to pull the data to the front end. To retrieve the Attachments for the current post, add this within The Loop:
|
506 |
-
|
507 |
-
`<?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
|
508 |
-
<?php if( $attachments->exist() ) : ?>
|
509 |
-
<h3>Attachments</h3>
|
510 |
-
<ul>
|
511 |
-
<?php while( $attachment = $attachments->get() ) : ?>
|
512 |
-
<li>
|
513 |
-
<pre><?php print_r( $attachment ); ?></pre>
|
514 |
-
</li>
|
515 |
-
<?php endwhile; ?>
|
516 |
-
</ul>
|
517 |
-
<?php endif; ?>`
|
518 |
-
|
519 |
-
**Retrieve Attachments Outside The Loop**
|
520 |
-
|
521 |
-
If you want to get the Attachments for a post **outside The Loop**, add a second parameter with the post ID when instantiating Attachments:
|
522 |
-
|
523 |
-
`<?php
|
524 |
-
// retrieve all Attachments for the 'attachments' instance of post 123
|
525 |
-
$attachments = new Attachments( 'attachments', 123 );
|
526 |
-
?>
|
527 |
-
<?php if( $attachments->exist() ) : ?>
|
528 |
-
<h3>Attachments</h3>
|
529 |
-
<ul>
|
530 |
-
<?php while( $attachment = $attachments->get() ) : ?>
|
531 |
-
<li>
|
532 |
-
<pre><?php print_r( $attachment ); ?></pre>
|
533 |
-
</li>
|
534 |
-
<?php endwhile; ?>
|
535 |
-
</ul>
|
536 |
-
<?php endif; ?>`
|
537 |
-
|
538 |
-
**Retrieve Attachment Attributes**
|
539 |
-
|
540 |
-
You can also retrieve various attributes of the current Attachment using these utility functions:
|
541 |
-
|
542 |
-
`<?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
|
543 |
-
<?php if( $attachments->exist() ) : ?>
|
544 |
-
<h3>Attachments</h3>
|
545 |
-
<p>Total Attachments: <?php echo $attachments->total(); ?></p>
|
546 |
-
<ul>
|
547 |
-
<?php while( $attachments->get() ) : ?>
|
548 |
-
<li>
|
549 |
-
ID: <?php echo $attachments->id(); ?><br />
|
550 |
-
Type: <?php echo $attachments->type(); ?><br />
|
551 |
-
Subtype: <?php echo $attachments->subtype(); ?><br />
|
552 |
-
URL: <?php echo $attachments->url(); ?><br />
|
553 |
-
Image: <?php echo $attachments->image( 'thumbnail' ); ?><br />
|
554 |
-
Source: <?php echo $attachments->src( 'full' ); ?><br />
|
555 |
-
Size: <?php echo $attachments->filesize(); ?><br />
|
556 |
-
Title Field: <?php echo $attachments->field( 'title' ); ?><br />
|
557 |
-
Caption Field: <?php echo $attachments->field( 'caption' ); ?>
|
558 |
-
</li>
|
559 |
-
<?php endwhile; ?>
|
560 |
-
</ul>
|
561 |
-
<?php endif; ?>`
|
562 |
-
|
563 |
-
**Retrieve Single Attachments**
|
564 |
-
|
565 |
-
If you don't want to use the above implementation to loop through your Attachments, can also retrieve them explicitly:
|
566 |
-
|
567 |
-
`<?php $attachments = new Attachments( 'attachments' ); ?>
|
568 |
-
<?php if( $attachments->exist() ) : ?>
|
569 |
-
<?php $my_index = 0; ?>
|
570 |
-
<?php if( $attachment = $attachments->get_single( $my_index ) ) : ?>
|
571 |
-
<h3>Attachment at index 0:</h3>
|
572 |
-
<pre><?php print_r( $attachment ); ?></pre>
|
573 |
-
<ul>
|
574 |
-
<li>
|
575 |
-
ID: <?php echo $attachments->id( $my_index ); ?><br />
|
576 |
-
Type: <?php echo $attachments->type( $my_index ); ?><br />
|
577 |
-
Subtype: <?php echo $attachments->subtype( $my_index ); ?><br />
|
578 |
-
URL: <?php echo $attachments->url( $my_index ); ?><br />
|
579 |
-
Image: <?php echo $attachments->image( 'thumbnail', $my_index ); ?><br />
|
580 |
-
Source: <?php echo $attachments->src( 'full', $my_index ); ?><br />
|
581 |
-
Size: <?php echo $attachments->filesize( $my_index ); ?><br />
|
582 |
-
Title Field: <?php echo $attachments->field( 'title', $my_index ); ?><br />
|
583 |
-
Caption Field: Name: <?php echo $attachments->field( 'caption', $my_index ); ?>
|
584 |
-
</li>
|
585 |
-
</ul>
|
586 |
-
<?php endif; ?>
|
587 |
-
<?php endif; ?>`
|
588 |
-
|
589 |
-
= Search =
|
590 |
-
|
591 |
-
Attachments provides a method of searching it's own data using a number of attributes. This faciliates a search to be as widespread or as specific as you'd like.
|
592 |
-
|
593 |
-
`<?php
|
594 |
-
$attachments = new Attachments();
|
595 |
-
|
596 |
-
$search_args = array(
|
597 |
-
'instance' => 'attachments', // search all instances
|
598 |
-
'fields' => array( 'caption' ), // search the 'caption' field only
|
599 |
-
);
|
600 |
-
|
601 |
-
$attachments->search( 'lorem ipsum', $search_args ); // search for 'lorem ipsum'
|
602 |
-
|
603 |
-
if( $attachments->exist() ) : ?>
|
604 |
-
<h3>Attachments</h3>
|
605 |
-
<ul>
|
606 |
-
<?php while( $attachments->get() ) : ?>
|
607 |
-
<li>
|
608 |
-
Attachment ID: <?php echo $attachments->id(); ?><br />
|
609 |
-
Post ID: <?php echo $attachments->post_id(); ?><br />
|
610 |
-
Title Field: <?php echo $attachments->field( 'title' ); ?><br />
|
611 |
-
Caption Field: <?php echo $attachments->field( 'caption' ); ?>
|
612 |
-
</li>
|
613 |
-
<?php endwhile; ?>
|
614 |
-
</ul>
|
615 |
-
<?php endif;
|
616 |
-
?>`
|
617 |
-
|
618 |
-
The full list of available search arguments (and their defaults) is as follows:
|
619 |
-
|
620 |
-
`<?php
|
621 |
-
$defaults = array(
|
622 |
-
'attachment_id' => null, // (int) not searching for a single attachment ID
|
623 |
-
'instance' => 'attachments', // (string) the instance you want to search
|
624 |
-
'post_type' => null, // (string) search 'any' post type
|
625 |
-
'post_id' => null, // (int) searching all posts
|
626 |
-
'post_status' => 'publish', // (string) search only published posts
|
627 |
-
'fields' => null, // (string|array) search all fields
|
628 |
-
);
|
629 |
-
?>`
|
630 |
-
|
631 |
-
Once you've performed your search, you can loop through the returned Attachments as you normally would.
|
4 |
Tags: post, page, posts, pages, images, PDF, doc, Word, image, jpg, jpeg, picture, pictures, photos, attachment
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.5.1
|
7 |
+
Stable tag: 3.4
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
**Extensive** usage instructions are [available on GitHub](https://github.com/jchristopher/attachments#usage)
|
16 |
+
|
17 |
Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types. This plugin *does not* directly interact with your theme, you will need to edit your template files.
|
18 |
|
19 |
= Updated for WordPress 3.5! =
|
71 |
|
72 |
== Frequently Asked Questions ==
|
73 |
|
74 |
+
Please see [Issues on GitHub](https://github.com/jchristopher/attachments/issues)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
== Screenshots ==
|
77 |
|
83 |
|
84 |
== Changelog ==
|
85 |
|
86 |
+
Please see [Attachments on GitHub](https://github.com/jchristopher/attachments#changelog)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
== Upgrade Notice ==
|
89 |
|
90 |
= 3.0 =
|
91 |
Now piggybacking the awesome Media workflow introduced in WordPress 3.5
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
== Roadmap ==
|
94 |
|
95 |
+
Please see [Attachments on GitHub](https://github.com/jchristopher/attachments#roadmap)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
== Usage ==
|
98 |
|
99 |
+
**Extensive** usage instructions are [available on GitHub](https://github.com/jchristopher/attachments#usage)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|