Attachments - Version 3.5

Version Description

  • Initial implementation of limiting the number of Attachments
  • You can now change an Attachment asset without having to remove the entire Attachment and re-add something new
  • New filter: attachments_location_{my_instance} (where **{my_instance}** is your instance name) allows for more fine-grained control over where meta boxes show up (e.g. limiting to your Home page)
  • New action: attachments_extension facilitates Attachments extensions
  • New method width( $size ) to retrieve the width of the current Attachment
  • New method height( $size ) to retrieve the height of the current Attachment
  • New document structure, various additions to documentation
  • Attachments Pro migration script. If you've been waiting to migrate from Attachments Pro please back up your database and run the migration script.
  • Fixed an asset URL issue if Attachments is added as a must-use plugin
  • Italian translation (props Marco Chiesi)
Download this release

Release Info

Developer jchristopher
Plugin Icon wp plugin Attachments
Version 3.5
Comparing to
See all releases

Code changes from version 3.4.2.1 to 3.5

README.md CHANGED
@@ -1,604 +1,37 @@
1
- This is a WordPress plugin. [Official download available on WordPress Extend](http://wordpress.org/extend/plugins/attachments/).
2
 
3
  # Attachments
4
 
5
  Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
6
 
7
- * [Description](#description)
8
- * [Installation](#installation)
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)
16
- * [Pulling Attachments to your Theme](#pulling-attachments-to-your-theme)
17
- * [Retrieve Attachments Outside The Loop](#retrieve-attachments-outside-the-loop)
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)
27
- * [Roadmap](#roadmap)
28
 
29
- ## Description
30
 
31
- 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.
32
 
33
- ### Updated for WordPress 3.5!
34
 
35
- WordPress 3.5 ships with an amazing new Media workflow and Attachments 3.0 makes great use of it. *If you are not running WordPress 3.5, the (now deprecated) version 1.6.2.1 (included with Attachments 3.x) will be used until you upgrade to WordPress 3.5+*
36
 
37
- ### Associate Media items with posts
38
 
39
- The idea behind Attachments is to give developers the ability to directly associate Media items with any post. This is accomplished by adding a meta box to post edit screens as determined by the developer. Once Media items have been associated with a post, you're able to retrieve those Attachments and include them directly within your template files using any specific markup you wish.
40
 
41
- ### Integrate Attachments within your theme with fine grained control
 
 
 
 
 
 
 
 
42
 
43
- **Attachments does not automatically integrate itself with your theme.** Since the idea behind Attachments is to allow integration of Media within posts using developer-crafted, unique markup, *it's up to you to integrate with your theme*. The most basic integration includes editing the [appropriate template file](http://codex.wordpress.org/Template_Hierarchy) and adding your call(s) to Attachments. For example, if you have set up Attachments to be used with your Posts entries, edit `single.php` to include the following within The Loop:
44
 
45
- ```php
46
- <?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
47
- <?php if( $attachments->exist() ) : ?>
48
- <h3>Attachments</h3>
49
- <ul>
50
- <?php while( $attachments->get() ) : ?>
51
- <li>
52
- ID: <?php echo $attachments->id(); ?><br />
53
- Type: <?php echo $attachments->type(); ?><br />
54
- Subtype: <?php echo $attachments->subtype(); ?><br />
55
- URL: <?php echo $attachments->url(); ?><br />
56
- Image: <?php echo $attachments->image( 'thumbnail' ); ?><br />
57
- Source: <?php echo $attachments->src( 'full' ); ?><br />
58
- Size: <?php echo $attachments->filesize(); ?><br />
59
- Title Field: <?php echo $attachments->field( 'title' ); ?><br />
60
- Caption Field: <?php echo $attachments->field( 'caption' ); ?>
61
- </li>
62
- <?php endwhile; ?>
63
- </ul>
64
- <?php endif; ?>
65
- ```
66
 
67
- That snippet will request all of the existing Attachments defined for the current Post within The Loop, and retrieve each itemized property for that Attachment. Using the provided details you're able to integrate the attached Media items in any way you please.
68
 
69
- ## Installation
70
-
71
- 1. Download the plugin and extract the files
72
- 1. Upload `attachments` to your `~/wp-content/plugins/` directory
73
- 1. Activate the plugin through the 'Plugins' menu in WordPress
74
- 1. Implement Attachments in your theme's `functions.php` or your own plugin (see **[Usage](#usage)**)
75
- 1. Update your templates where applicable (see **[Usage](#usage)**)
76
-
77
- ## Upgrade Notice
78
-
79
- #### 3.0
80
- **You will need to update your theme files that use Attachments 3.0**. Version 1.x of Attachments has been **fully deprecated** but is still available *and included with Attachments 3.x*. If you would like to continue to use the (no longer supported) 1.x version you may add the following to your `wp-config.php`:
81
-
82
- ```php
83
- define( 'ATTACHMENTS_LEGACY', true ); // force the legacy version of Attachments
84
- ```
85
-
86
- Version 3 is a **major** rewrite. While I've taken precautions in ensuring you won't lose any saved data it is important to back up your databse prior to upgrading in case something goes wrong. This version is a complete rewrite so all legacy data will be left in place, but a migration must take place to match the new data storage model and workflow.
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`:
95
-
96
- ```php
97
- define( 'ATTACHMENTS_SETTINGS_SCREEN', false ); // disable the Settings screen
98
- ```
99
-
100
- ### Setting Up Instances
101
-
102
- When Attachments is first activated, a default instance is created titled Attachments. It has two fields:
103
-
104
- 1. Title
105
- 1. Caption
106
-
107
- #### Disable the Default Instance
108
-
109
- 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` *before* `require_once(ABSPATH . 'wp-settings.php');`:
110
-
111
- ```php
112
- define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );
113
- ```
114
-
115
- #### Create Custom Instances
116
-
117
- 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:
118
-
119
- ```php
120
- <?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
128
- 'label' => __( 'Title', 'attachments' ), // label to display
129
- 'default' => 'title', // default value upon selection
130
- ),
131
- array(
132
- 'name' => 'caption', // unique field name
133
- 'type' => 'textarea', // registered field type
134
- 'label' => __( 'Caption', 'attachments' ), // label to display
135
- 'default' => 'caption', // default value upon selection
136
- ),
137
- );
138
-
139
- $args = array(
140
-
141
- // title of the meta box (string)
142
- 'label' => 'My Attachments',
143
-
144
- // all post types to utilize (string|array)
145
- 'post_type' => array( 'post', 'page' ),
146
-
147
- // meta box position (string) (normal, side or advanced)
148
- 'position' => 'normal',
149
-
150
- // meta box priority (string) (high, default, low, core)
151
- 'priority' => 'high',
152
-
153
- // allowed file type(s) (array) (image|video|text|audio|application)
154
- 'filetype' => null, // no filetype limit
155
-
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
-
166
- // text for modal 'Attach' button (string)
167
- 'modal_text' => __( 'Attach', 'attachments' ),
168
-
169
- // which tab should be the default in the modal (string) (browse|upload)
170
- 'router' => 'browse',
171
-
172
- // fields array
173
- 'fields' => $fields,
174
-
175
- );
176
-
177
- $attachments->register( 'my_attachments', $args ); // unique instance name
178
- }
179
-
180
- add_action( 'attachments_register', 'my_attachments' );
181
- ```
182
-
183
- #### Fields Reference
184
-
185
- At this time there are **four** field types available:
186
-
187
- 1. `text`
188
- 1. `textarea`
189
- 1. `select`
190
- 1. `wysiwyg`
191
-
192
- 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:
193
-
194
- ```php
195
- /**
196
- * Fields for the instance are stored in an array. Each field consists of
197
- * an array with three required keys: name, type, label
198
- * and one optional key: meta
199
- *
200
- * name - (string) The field name used. No special characters.
201
- * type - (string) The registered field type.
202
- * Fields available: text, textarea, wysiwyg, select
203
- * label - (string) The label displayed for the field.
204
- * default - (string) The default WordPress metadata to use when initially adding the Attachment
205
- * Defaults available: title, caption, alt, description
206
- * meta - (array) The field-specific parameters that apply only to that field type
207
- */
208
-
209
- $fields => array(
210
- array(
211
- 'name' => 'title', // unique field name
212
- 'type' => 'text', // registered field type
213
- 'label' => __( 'Title', 'attachments' ), // label to display
214
- 'default' => 'title', // default value upon selection
215
- ),
216
- array(
217
- 'name' => 'caption', // unique field name
218
- 'type' => 'textarea', // registered field type
219
- 'label' => __( 'Caption', 'attachments' ), // label to display
220
- 'default' => 'caption', // default value upon selection
221
- ),
222
- array(
223
- 'name' => 'option', // unique field name
224
- 'type' => 'select', // registered field type
225
- 'label' => __( 'Option', 'attachments' ), // label to display
226
- 'meta' => array( // field-specific meta as defined by field class
227
- 'allow_null' => true, // allow null value? (adds 'empty' <option>)
228
- 'multiple' => true, // multiple <select>?
229
- 'options' => array( // the <option>s to use
230
- '1' => 'Option 1',
231
- '2' => 'Option 2',
232
- )
233
- ),
234
- ),
235
- array(
236
- 'name' => 'description', // unique field name
237
- 'type' => 'wysiwyg', // registered field type
238
- 'label' => __( 'Description', 'attachments' ), // label to display
239
- 'default' => 'description', // default value upon selection
240
- ),
241
- );
242
- ```
243
-
244
- ### Pulling Attachments to your Theme
245
-
246
- 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:
247
-
248
- ```php
249
- <?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
250
- <?php if( $attachments->exist() ) : ?>
251
- <h3>Attachments</h3>
252
- <ul>
253
- <?php while( $attachment = $attachments->get() ) : ?>
254
- <li>
255
- <pre><?php print_r( $attachment ); ?></pre>
256
- </li>
257
- <?php endwhile; ?>
258
- </ul>
259
- <?php endif; ?>
260
- ```
261
-
262
- #### Retrieve Attachments Outside The Loop
263
-
264
- If you want to get the Attachments for a post **outside The Loop**, add a second parameter with the post ID when instantiating Attachments:
265
-
266
- ```php
267
- <?php
268
- // retrieve all Attachments for the 'attachments' instance of post 123
269
- $attachments = new Attachments( 'attachments', 123 );
270
- ?>
271
- <?php if( $attachments->exist() ) : ?>
272
- <h3>Attachments</h3>
273
- <ul>
274
- <?php while( $attachment = $attachments->get() ) : ?>
275
- <li>
276
- <pre><?php print_r( $attachment ); ?></pre>
277
- </li>
278
- <?php endwhile; ?>
279
- </ul>
280
- <?php endif; ?>
281
- ```
282
-
283
- #### Retrieve Attachment Attributes
284
-
285
- You can also retrieve various attributes of the current Attachment directly using these utility functions:
286
-
287
- ```php
288
- <?php $attachments = new Attachments( 'attachments' ); ?>
289
- <?php if( $attachments->exist() ) : ?>
290
- <h3>Attachments</h3>
291
- <p>Total Attachments: <?php echo $attachments->total(); ?></p>
292
- <ul>
293
- <?php while( $attachments->get() ) : ?>
294
- <li>
295
- ID: <?php echo $attachments->id(); ?><br />
296
- Type: <?php echo $attachments->type(); ?><br />
297
- Subtype: <?php echo $attachments->subtype(); ?><br />
298
- URL: <?php echo $attachments->url(); ?><br />
299
- Image: <?php echo $attachments->image( 'thumbnail' ); ?><br />
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>
307
- <?php endif; ?>
308
- ```
309
-
310
- #### Retrieve Single Attachments
311
-
312
- If you don't want to use the above implementation to loop through your Attachments, can also retrieve them explicitly:
313
-
314
- ```php
315
- <?php $attachments = new Attachments( 'attachments' ); ?>
316
- <?php if( $attachments->exist() ) : ?>
317
- <?php $my_index = 0; ?>
318
- <?php if( $attachment = $attachments->get_single( $my_index ) ) : ?>
319
- <h3>Attachment at index 0:</h3>
320
- <pre><?php print_r( $attachment ); ?></pre>
321
- <ul>
322
- <li>
323
- ID: <?php echo $attachments->id( $my_index ); ?><br />
324
- Type: <?php echo $attachments->type( $my_index ); ?><br />
325
- Subtype: <?php echo $attachments->subtype( $my_index ); ?><br />
326
- URL: <?php echo $attachments->url( $my_index ); ?><br />
327
- Image: <?php echo $attachments->image( 'thumbnail', $my_index ); ?><br />
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; ?>
335
- <?php endif; ?>
336
- ```
337
-
338
- ### Search
339
-
340
- 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.
341
-
342
- ```php
343
- <?php
344
- $attachments = new Attachments();
345
-
346
- $search_args = array(
347
- 'instance' => 'attachments', // search all instances
348
- 'fields' => array( 'caption' ), // search the 'caption' field only
349
- );
350
-
351
- $attachments->search( 'lorem ipsum', $search_args ); // search for 'lorem ipsum'
352
-
353
- if( $attachments->exist() ) : ?>
354
- <h3>Attachments</h3>
355
- <ul>
356
- <?php while( $attachments->get() ) : ?>
357
- <li>
358
- Attachment ID: <?php echo $attachments->id(); ?><br />
359
- Post ID: <?php echo $attachments->post_id(); ?><br />
360
- Title Field: <?php echo $attachments->field( 'title' ); ?><br />
361
- Caption Field: <?php echo $attachments->field( 'caption' ); ?>
362
- </li>
363
- <?php endwhile; ?>
364
- </ul>
365
- <?php endif;
366
- ?>
367
- ```
368
-
369
- The full list of available search arguments (and their defaults) is as follows:
370
-
371
- ```php
372
- $defaults = array(
373
- 'attachment_id' => null, // (int) not searching for a single attachment ID
374
- 'instance' => 'attachments', // (string) the instance you want to search
375
- 'post_type' => null, // (string) search 'any' post type
376
- 'post_id' => null, // (int) searching all posts
377
- 'post_status' => 'publish', // (string) search only published posts
378
- 'fields' => null, // (string|array) search all Attachment fields
379
- 'filetype' => null, // (string|array) search all Attachment filetypes
380
- );
381
- ```
382
-
383
- Once you've performed your search, you can loop through the returned Attachments as you normally would.
384
-
385
- ## Filters
386
-
387
- 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`.
388
-
389
- ### Post Meta Key
390
-
391
- 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:
392
-
393
- ```php
394
- function my_attachments_meta_key()
395
- {
396
- return '_my_attachments_meta_key';
397
- }
398
-
399
- add_filter( 'attachments_meta_key', 'my_attachments_meta_key' );
400
- ```
401
-
402
- 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).
403
-
404
- ### Get Attachments
405
-
406
- 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:
407
-
408
- ```php
409
- function my_attachments_randomize( $attachments )
410
- {
411
- return shuffle( $attachments );
412
- }
413
-
414
- add_filter( 'attachments_get_my_attachments', 'my_attachments_randomize' );
415
- ```
416
-
417
- **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:
418
-
419
- ```php
420
- function my_attachments_reverse( $attachments )
421
- {
422
- return array_reverse( $attachments );
423
- }
424
-
425
- add_filter( 'attachments_get_foo_bar', 'my_attachments_reverse' );
426
- ```
427
-
428
- Please keep in mind the instance name requirement when setting up this filter.
429
-
430
- ## Screenshots
431
-
432
- ##### An Attachments meta box sitting below the content editor
433
- ![An Attachments meta box sitting below the content editor](http://mondaybynoon.com/images/attachments/screenshot-1.png)
434
-
435
- ##### Direct integration with WordPress 3.5+ Media
436
- ![Direct integration with WordPress 3.5+ Media](http://mondaybynoon.com/images/attachments/screenshot-2.png)
437
-
438
- ##### Attach multiple files at once
439
- ![Attach multiple files at once](http://mondaybynoon.com/images/attachments/screenshot-3.png)
440
-
441
- ##### Custom fields for each Attachment
442
- ![Custom fields for each Attachment](http://mondaybynoon.com/images/attachments/screenshot-4.png)
443
-
444
- ##### Drag and drop to sort
445
- ![Drag and drop to sort](http://mondaybynoon.com/images/attachments/screenshot-5.png)
446
-
447
- ## Frequently Asked Questions
448
-
449
- #### Attachments isn't showing up on my edit screens
450
-
451
- You will need to tell Attachments which instances you'd like to use. Please reference the **[Usage](#usage)** instructions.
452
-
453
- #### Attachments are not showing up in my theme
454
-
455
- You will need to edit your theme files where applicable. Please reference the **[Usage](#usage)** instructions.
456
-
457
- #### How do I disable the default Attachments meta box?
458
-
459
- You will need to edit your Attachments configuration. Please reference the **[Usage](#usage)** instructions.
460
-
461
- #### How do I change the fields for each Attachment?
462
-
463
- You will need to edit your Attachments configuration. Please reference the **[Usage](#usage)** instructions.
464
-
465
- #### Where are uploads saved?
466
-
467
- Attachments uses WordPress' built in Media library for uploads and storage.
468
-
469
- #### I lost my Attachments after upgrading!
470
-
471
- ***DO NOT update any Post/Page/CPT with Attachments***, the data has not been lost. Please reference the **[Upgrade notice](#upgrade-notice)**.
472
-
473
- ## Changelog
474
-
475
- <dl>
476
-
477
- <dt>3.4.2.1</dt>
478
- <dd>Fixed a regression that prevented the <code>type</code> method from returning</dd>
479
-
480
- <dt>3.4.2</dt>
481
- <dd>Fixed an issue where the <code>languages</code> directory wouldn't be utilized for l10n</dd>
482
- <dd>Search now respects custom <code>meta_key</code></dd>
483
- <dd>You can now pass in a <code>filetype</code> parameter when searching to limit results in that way</dd>
484
-
485
- <dt>3.4.1</dt>
486
- <dd>Class abstraction and cleanup</dd>
487
- <dd>Better support for plugin-created custom image sizes</dd>
488
-
489
- <dt>3.4</dt>
490
- <dd>New filter: <code>attachments_meta_key</code> facilitates using a different meta key for Attachments storage</dd>
491
- <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>
492
- <dd>Fixed an issue where retrieving single Attachments didn't properly pass the index to attribute methods</dd>
493
- <dd>Fixed PHP Warnings when Network Activating</dd>
494
- <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>
495
-
496
- <dt>3.3.3</dt>
497
- <dd>Fixed a PHP Warning when activated using Multisite</dd>
498
- <dd>Slightly modified the migration process to better handle plugins like WPML (props sebastian.friedrich)</dd>
499
-
500
- <dt>3.3.2</dt>
501
- <dd>You can now specify which view is default when browsing the Media modal (e.g. have 'Upload Files' be default instead of 'Media Library')</dd>
502
-
503
- <dt>3.3.1</dt>
504
- <dd>Added meta box positioning arguments when registering instances</dd>
505
- <dd>Cleaned up some CSS when Attachments instances are in the sidebar</dd>
506
-
507
- <dt>3.3</dt>
508
- <dd>Added a <code>search()</code> method to allow searching for Attachments based on their attributes (e.g. attachment ID, post ID, post type, field values, etc.)</dd>
509
- <dd>Improved the 'Remove' animation</dd>
510
- <dd>New field: select</dd>
511
- <dd>New parameter for Attachments attributes methods. You can pass the index (<code>int</code>) of the Attachment you'd like to utilize when firing the method.</dd>
512
-
513
- <dt>3.2</dt>
514
- <dd>Added option to disable the Settings screen</dd>
515
- <dd>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.</dd>
516
- <dd>Added a <code>get_single()</code> method that allows you to specifically retrieve a single Attachment</dd>
517
- <dd>Clarified some documentation</dd>
518
-
519
- <dt>3.1.4</dt>
520
- <dd>Changed 'Delete' to 'Remove' so as to not make it sound like the file itself would be deleted from Media (props Lane Goldberg)</dd>
521
- <dd>Better handling of posts that have no Attachments when saving</dd>
522
-
523
- <dt>3.1.3</dt>
524
- <dd>Fixed a potential issue with the WYSIWYG field not working on CPT without editor support</dd>
525
- <dd>Field assets are less aggressive and only fire when necessary</dd>
526
- <dd>Reorganized the migration process a bit in prep for Attachments Pro support</dd>
527
-
528
- <dt>3.1.2</dt>
529
- <dd>Fixed a regression that prevented successful migration of legacy Attachments data</dd>
530
-
531
- <dt>3.1.1</dt>
532
- <dd>Fixed a Fatal Error when registering the text field</dd>
533
-
534
- <dt>3.1</dt>
535
- <dd>New field: wysiwyg</dd>
536
- <dd>Fields will now properly respect line breaks</dd>
537
- <dd>Fields will now properly return HTML instead of escaped HTML</dd>
538
-
539
- <dt>3.0.9</dt>
540
- <dd>Fixed an issue where special characters would break title/caption fields during migration</dd>
541
-
542
- <dt>3.0.8.2</dt>
543
- <dd>Fixed a CSS issue with only one text field</dd>
544
-
545
- <dt>3.0.8.1</dt>
546
- <dd>Better storage of special characters for PHP 5.4+</dd>
547
-
548
- <dt>3.0.8</dt>
549
- <dd>Fixed an issue in Firefox where you weren't able to focus inputs unless you clicked their label</dd>
550
- <dd>New field: textarea</dd>
551
-
552
- <dt>3.0.7</dt>
553
- <dd>Proper sanitization of Custom Post Type names (as WordPress does it)</dd>
554
-
555
- <dt>3.0.6</dt>
556
- <dd>Fixed a possible JavaScript error if an Attachment that's an image doesn't have a proper thumbnail URL</dd>
557
- <dd>Added a <code>total()</code> method that will return the number of Attachments for the current instance</dd>
558
- <dd>When requesting the </code>image()</code> for a non-image Attachment, the WordPress-defined icon will be returned</dd>
559
- <dd>Added an <code>icon()</code> method that will return the WordPress-defined icon for the Attachment</dd>
560
- <dd>Cleaned up a PHP Warning when trying to save for an undefined field type</dd>
561
- <dd>Fixed an issue where template tags would be output for non-image Attachments after saving</dd>
562
-
563
- <dt>3.0.5</dt>
564
- <dd>Fixed a regression in handling Custom Post Type names that would too aggressively interfere with instance regustration</dd>
565
- <dd>Fixed an issue when working with non-image Attachments</dd>
566
-
567
- <dt>3.0.4</dt>
568
- <dd>Fixed an issue that prevented the choosing of a Featured Image for a Custom Post Type if Attachments was activated</dd>
569
- <dd>Attachments now only enqueues its assets on edit screens that actually utilize Attachments</dd>
570
- <dd>Fixed a potential JavaScript error triggered when a 'thumbnail' image size was not available</dd>
571
- <dd>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)</dd>
572
- <dd>Prevented re-running of migration process to avoid duplicates (e.g. on browser reload)</dd>
573
-
574
- <dt>3.0.3</dt>
575
- <dd>Fixed an issue that prevented defining a post ID when retrieving Attachments outside The Loop</dd>
576
- <dd>Cleaned up potential PHP warning when Attachments were requested for a post that had none</dd>
577
-
578
- <dt>3.0.2</dt>
579
- <dd>Fixed an issue where some HTML entities were not properly stored</dd>
580
-
581
- <dt>3.0.1</dt>
582
- <dd>Fixed an issue where legacy mode was always enabled</dd>
583
-
584
- <dt>3.0</dt>
585
- <dd> <strong>Major</strong> rewrite. After three years of development, Attachments has been rewritten to make
586
- even better use of what WordPress has to offer</dd>
587
- <dd> Utilizes the brand spanking new 3.5 Media workflow</dd>
588
- <dd> Configuration now takes place within your theme or a plugin</dd>
589
- <dd> Multiple meta boxes! You can segment groups of Attachments with new instances, each unique</dd>
590
- <dd> Dynamic fields! You can manipulate which fields each instance uses</dd>
591
- <dd> File type limits. Limit which files are available to Attachments (e.g. images, audio, video)</dd>
592
-
593
- </dl>
594
-
595
- ## Roadmap
596
-
597
- Planned feature additions include:
598
-
599
- * Additional field type: checkbox
600
- * Additional field type: radio
601
- * User-defined limiting the number of Attachments per instance
602
- * User-defined custom field types
603
- * Shortcode(s)
604
- * Output templates
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
 
3
  # Attachments
4
 
5
  Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
6
 
7
+ ## Philosophy
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ Attachments is a code-focused plugin; there's no configuration UI out of the box. This was an intentional move based on personal preference that offers a number of other benefits, primarily the ability to version control your configuration without having to worry about the database aspect.
10
 
11
+ Attachments is based on the concept of Instances. An Attachments Instance can be thought of as a meta box on an edit screen. Each Instance can have various attributes that control the file types allowed, the fields for each asset, and the number of assets you're allowed to attach for example. Understanding this is **fundamental** to understanding the configuration and usage as the name is used both to define each Instance *and* retrieve it's data. Once you've got your mind around that, implementation should be a breeze.
12
 
13
+ ### Attachments UI
14
 
15
+ Some people prefer an interface whenever possible. To accommodate those developers, Attachments has an extension called [Attachments UI](https://mondaybynoon.com/members/plugins/attachments-ui/). Using this plugin, you don't have to write any code at all to define your Instances, and it even tosses out a customized code snippet tied directly to the Instance you just generated. It's a great way to get up and running very quickly. Further, there's also the option to auto-append your Attachments Instance assets to `the_content()` using an easy templating language.
16
 
17
+ ## Documentation
18
 
19
+ There's quite a bit of documentation available. I would suggest checking out the [Table of Contents](docs/TOC.md) first. The primary segments of documentation are:
20
 
21
+ * [Overview](docs/overview.md)
22
+ * [Installation](docs/installation.md)
23
+ * **[Upgrade Notice](docs/upgrade.md)** *Pay specific attention if upgrading from a version of Attachments before 3.0*
24
+ * [Usage](docs/usage.md)
25
+ * [Hooks](docs/hooks.md)
26
+ * [Screenshots](docs/screenshots.md)
27
+ * [Frequently Asked Questions](docs/faq.md)
28
+ * [Changelog](docs/changelog.md)
29
+ * [Roadmap](docs/roadmap.md)
30
 
31
+ ## Main Screenshot
32
 
33
+ This is an Attachments Instance on a Post edit screen. The fields are fully customizable and you can have as many Instances as you'd like, anywhere.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
+ ![Attachments on an edit screen](http://mondaybynoon.com/images/attachments/main.png)
36
 
37
+ [View other Screenshots](docs/screenshots.md)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class.attachments.legacy.php CHANGED
@@ -45,7 +45,7 @@ class AttachmentsLegacyHandler
45
  if( is_multisite() )
46
  {
47
  $plugins = get_site_option( 'active_sitewide_plugins' );
48
- if ( isset($plugins['attachments/index.php']) )
49
  return;
50
  }
51
 
@@ -56,8 +56,7 @@ class AttachmentsLegacyHandler
56
 
57
  if( $legacy_attachments_settings && is_array( $legacy_attachments_settings['post_types'] ) && count( $legacy_attachments_settings['post_types'] ) )
58
  {
59
- // we have legacy settings, so we're going to use the post types
60
- // that Attachments is currently utilizing
61
 
62
  // the keys are the actual CPT names, so we need those
63
  foreach( $legacy_attachments_settings['post_types'] as $post_type => $value )
45
  if( is_multisite() )
46
  {
47
  $plugins = get_site_option( 'active_sitewide_plugins' );
48
+ if( isset( $plugins['attachments/index.php'] ) )
49
  return;
50
  }
51
 
56
 
57
  if( $legacy_attachments_settings && is_array( $legacy_attachments_settings['post_types'] ) && count( $legacy_attachments_settings['post_types'] ) )
58
  {
59
+ // we have legacy settings, so we're going to use the post types that Attachments is currently utilizing
 
60
 
61
  // the keys are the actual CPT names, so we need those
62
  foreach( $legacy_attachments_settings['post_types'] as $post_type => $value )
classes/class.attachments.migrate.php CHANGED
@@ -36,6 +36,8 @@ class AttachmentsMigrate extends Attachments
36
 
37
  $legacy_attachments_settings = get_option( 'attachments_settings' );
38
 
 
 
39
  if( $legacy_attachments_settings && is_array( $legacy_attachments_settings['post_types'] ) && count( $legacy_attachments_settings['post_types'] ) )
40
  {
41
  // we have legacy settings, so we're going to use the post types
@@ -98,7 +100,7 @@ class AttachmentsMigrate extends Attachments
98
  // we have our Attachments entries
99
 
100
  // let's check to see if we're migrating after population has taken place
101
- $existing_attachments = get_post_meta( $query->post->ID, 'attachments', false );
102
 
103
  if( !isset( $existing_attachments[0] ) )
104
  $existing_attachments[0] = '';
@@ -232,4 +234,662 @@ class AttachmentsMigrate extends Attachments
232
  add_option( 'attachments_migrated', true, '', 'no' );
233
  }
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  }
36
 
37
  $legacy_attachments_settings = get_option( 'attachments_settings' );
38
 
39
+ $query = false;
40
+
41
  if( $legacy_attachments_settings && is_array( $legacy_attachments_settings['post_types'] ) && count( $legacy_attachments_settings['post_types'] ) )
42
  {
43
  // we have legacy settings, so we're going to use the post types
100
  // we have our Attachments entries
101
 
102
  // let's check to see if we're migrating after population has taken place
103
+ $existing_attachments = get_post_meta( $query->post->ID, $this->get_meta_key(), false );
104
 
105
  if( !isset( $existing_attachments[0] ) )
106
  $existing_attachments[0] = '';
234
  add_option( 'attachments_migrated', true, '', 'no' );
235
  }
236
 
237
+
238
+
239
+ /**
240
+ * Step 1 of the Pro migration process. Allows the user to define the target instance and field names.
241
+ *
242
+ * @since 3.5
243
+ */
244
+ function prepare_pro_migration()
245
+ {
246
+ if( !wp_verify_nonce( $_GET['nonce'], 'attachments-pro-migrate-1') ) wp_die( __( 'Invalid request', 'attachments' ) );
247
+ ?>
248
+ <h3><?php _e( 'Migration Step 1', 'attachments' ); ?></h3>
249
+ <form action="options-general.php" method="get">
250
+ <input type="hidden" name="page" value="attachments" />
251
+ <input type="hidden" name="migrate-pro" value="2" />
252
+ <input type="hidden" name="nonce" value="<?php echo wp_create_nonce( 'attachments-pro-migrate-2' ); ?>" />
253
+
254
+ <?php
255
+ /**
256
+ * We need to use the stored Attachments Pro settings to generate a dynamic form encompassing all
257
+ * Pro instances, their fields, their rules, and their auto-append statuses
258
+ */
259
+ $attachments_pro_settings = get_option( '_iti_apro_settings' );
260
+ ?>
261
+
262
+ <?php if( is_array( $attachments_pro_settings['positions'] ) ) : ?>
263
+ <p><?php _e( 'The following Attachments Pro Instances will be migrated:', 'attachments' ); ?></p>
264
+ <ul style="padding-left:32px;list-style:disc;">
265
+ <?php foreach( $attachments_pro_settings['positions'] as $attachments_pro_instance ) : ?>
266
+ <li><?php echo $attachments_pro_instance['label']; ?></li>
267
+ <?php endforeach; ?>
268
+ </ul>
269
+ <h2><?php _e( 'Note: this is a multi-step process', 'attachments' ); ?></h2>
270
+ <p><?php _e( 'The data from each Pro Instance will be migrated to an equivalent Attachments Instance, and you will be provided code to copy and paste into your <code>functions.php</code>.', 'attachments' ); ?></p>
271
+ <p><?php _e( '<em>This data migration is only the first step. <strong>You must add the code from the following page to your <code>functions.php</code></strong> to restore your meta boxes</em>.', 'attachments' ); ?></p>
272
+ <?php endif; ?>
273
+
274
+ <p class="submit">
275
+ <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Start Migration', 'attachments' ); ?>" />
276
+ </p>
277
+ </form>
278
+ <?php
279
+ }
280
+
281
+
282
+
283
+ /**
284
+ * Step 2 of the Pro migration process. Validates migration requests and fires the migration method.
285
+ *
286
+ * @since 3.5
287
+ */
288
+ function init_pro_migration()
289
+ {
290
+ global $current_user;
291
+
292
+ get_currentuserinfo();
293
+
294
+ if( !wp_verify_nonce( $_GET['nonce'], 'attachments-pro-migrate-2') )
295
+ wp_die( __( 'Invalid request', 'attachments' ) );
296
+
297
+ $attachments_pro_settings = get_option( '_iti_apro_settings' );
298
+ if( is_array( $attachments_pro_settings['positions'] ) )
299
+ {
300
+ $totals = array();
301
+
302
+ foreach( $attachments_pro_settings['positions'] as $attachments_pro_instance )
303
+ $totals[] = $this->migrate_pro( $attachments_pro_instance );
304
+
305
+ $total_attachments = 0;
306
+
307
+ if( !empty( $totals ) )
308
+ foreach( $totals as $instance_total )
309
+ $total_attachments += $instance_total['total'];
310
+
311
+ if( false == get_option( 'attachments_pro_migrated' ) ) :
312
+ ?>
313
+ <h3><?php _e( 'Data conversion complete!', 'attachments' ); ?></h3>
314
+ <p><?php _e( 'The data conversion has been completed successfully.', 'attachments' ); ?> <strong><?php _e( 'Converted', 'attachments'); ?>: <?php echo $total_attachments; ?> <?php echo ( $total_attachments == 1 ) ? __( 'Attachment', 'attachments' ) : __( 'Attachments', 'attachments' ); ?></strong></p>
315
+ <h2><?php _e( 'The migration is NOT COMPLETE', 'attachments' ); ?></h2>
316
+ <p><?php _e( "While the data migration has taken place, you still need to add the following to your <code>functions.php</code> in order to have Attachments' meta boxes show up where appropriate:", 'attachments' ); ?></p>
317
+ <?php ob_start(); ?>if( !function_exists( 'migrated_pro_attachments' ) )
318
+ {
319
+ function migrated_pro_attachments( $attachments )
320
+ {<?php foreach( $attachments_pro_settings['positions'] as $attachments_pro_instance ) : ?>
321
+
322
+ $fields = array(<?php if( is_array( $attachments_pro_instance['fields'] ) ) : foreach( $attachments_pro_instance['fields'] as $field ) : if( $field['type'] == 'textfield' ) { $field['type'] = 'text'; } ?>
323
+
324
+ array(
325
+ 'name' => '<?php echo str_replace( '-', '_', sanitize_title( $field['label'] ) ); ?>',
326
+ 'type' => '<?php echo $field['type']; ?>',
327
+ 'label' => '<?php echo $field['label']; ?>',
328
+ 'default' => '<?php echo isset( $field['mapped_to'] ) ? $field['mapped_to'] : ''; ?>',
329
+ ),<?php endforeach; echo "\n"; endif; ?>
330
+ );
331
+ <?php
332
+ $post_types = array();
333
+ if( isset( $attachments_pro_instance['conditions'] ) && is_array( $attachments_pro_instance['conditions'] ) && !empty( $attachments_pro_instance['conditions'] ) )
334
+ foreach( $attachments_pro_instance['conditions'] as $condition )
335
+ if( $condition['param'] == 'post_type' && $condition['operator'] == 'is' )
336
+ $post_types[] = $condition['limiter'];
337
+ ?>
338
+ $args = array(
339
+ 'label' => '<?php echo $attachments_pro_instance['label']; ?>',
340
+ 'post_type' => array( '<?php echo implode( "', '", array_unique( $post_types ) ); ?>' ),
341
+ 'note' => '<?php echo $attachments_pro_instance['description']; ?>',
342
+ 'fields' => $fields,
343
+ );
344
+
345
+ $attachments->register( '<?php echo $attachments_pro_instance['name']; ?>', $args );<?php endforeach; ?>
346
+
347
+ }
348
+ }
349
+
350
+ add_action( 'attachments_register', 'migrated_pro_attachments' );
351
+
352
+ <?php
353
+ $integrate_conditions = false;
354
+ foreach( $attachments_pro_settings['positions'] as $attachments_pro_instance )
355
+ {
356
+ if( isset( $attachments_pro_instance['conditions'] ) && is_array( $attachments_pro_instance['conditions'] ) && !empty( $attachments_pro_instance['conditions'] ) )
357
+ {
358
+ $integrate_conditions = true;
359
+ break;
360
+ }
361
+ }
362
+
363
+ if( $integrate_conditions ) : ?>
364
+ /**
365
+ * Facilitate Attachments conditional inclusion of meta boxes for existing instances
366
+ */
367
+
368
+ if( !function_exists( 'attachments_is_allowed' ) )
369
+ {
370
+ function attachments_is_allowed( $conditions = array(), $match = 'any' )
371
+ {
372
+ global $post;
373
+
374
+ $match = ( $match == 'any' ) ? 'any' : 'all';
375
+ $allowed = false;
376
+ $short_circuit = false;
377
+
378
+ if( is_array( $conditions ) && !empty( $conditions ) )
379
+ {
380
+ foreach( $conditions as $condition )
381
+ {
382
+ if( ( $match == 'all' && !$short_circuit ) || $match == 'any' )
383
+ {
384
+ $parameter = $condition['param'];
385
+ $operator = $condition['operator'];
386
+ $limiter = $condition['limiter'];
387
+
388
+ switch( $parameter )
389
+ {
390
+ case 'post_type':
391
+ if( $operator == 'is' )
392
+ {
393
+ if( $post->post_type == $limiter )
394
+ {
395
+ $allowed = true;
396
+ }
397
+ elseif( $match == 'all' )
398
+ {
399
+ $short_circuit = true;
400
+ }
401
+ }
402
+ else
403
+ {
404
+ if( $post->post_type != $limiter )
405
+ {
406
+ $allowed = true;
407
+ }
408
+ elseif( $match == 'all' )
409
+ {
410
+ $short_circuit = true;
411
+ }
412
+ }
413
+ break;
414
+
415
+ case 'post_format':
416
+ $post_format = get_post_format( $post->ID );
417
+ if( $operator == 'is' )
418
+ {
419
+ if( $post_format == $limiter )
420
+ {
421
+ $allowed = true;
422
+ }
423
+ elseif( $match == 'all' )
424
+ {
425
+ $short_circuit = true;
426
+ }
427
+ }
428
+ else
429
+ {
430
+ if( $post_format != $limiter )
431
+ {
432
+ $allowed = true;
433
+ }
434
+ elseif( $match == 'all' )
435
+ {
436
+ $short_circuit = true;
437
+ }
438
+ }
439
+ break;
440
+
441
+ case 'page':
442
+ if( $operator == 'is' )
443
+ {
444
+ if( $post->ID == $limiter )
445
+ {
446
+ $allowed = true;
447
+ }
448
+ elseif( $match == 'all' )
449
+ {
450
+ $short_circuit = true;
451
+ }
452
+ }
453
+ else
454
+ {
455
+ if( $post->ID != $limiter )
456
+ {
457
+ $allowed = true;
458
+ }
459
+ elseif( $match == 'all' )
460
+ {
461
+ $short_circuit = true;
462
+ }
463
+ }
464
+ break;
465
+
466
+ case 'role':
467
+ $current_user = wp_get_current_user();
468
+ if( $operator == 'is' )
469
+ {
470
+ if( array_search( strtolower( $limiter ), $current_user->roles ) !== false )
471
+ {
472
+ $allowed = true;
473
+ }
474
+ elseif( $match == 'all' )
475
+ {
476
+ $short_circuit = true;
477
+ }
478
+ }
479
+ else
480
+ {
481
+ if( array_search( strtolower( $limiter ), $current_user->roles ) === false )
482
+ {
483
+ $allowed = true;
484
+ }
485
+ elseif( $match == 'all' )
486
+ {
487
+ $short_circuit = true;
488
+ }
489
+ }
490
+ break;
491
+
492
+ case 'template':
493
+ $current_template = get_post_meta( $post->ID, '_wp_page_template', true );
494
+ if( $operator == 'is' )
495
+ {
496
+ if( $current_template == $limiter )
497
+ {
498
+ $allowed = true;
499
+ }
500
+ elseif( $match == 'all' )
501
+ {
502
+ $short_circuit = true;
503
+ }
504
+ }
505
+ else
506
+ {
507
+ if( $current_template != $limiter )
508
+ {
509
+ $allowed = true;
510
+ }
511
+ elseif( $match == 'all' )
512
+ {
513
+ $short_circuit = true;
514
+ }
515
+ }
516
+ break;
517
+
518
+ case 'parent':
519
+ if( $operator == 'is' )
520
+ {
521
+ if( $post->post_parent == $limiter )
522
+ {
523
+ $allowed = true;
524
+ }
525
+ elseif( $match == 'all' )
526
+ {
527
+ $short_circuit = true;
528
+ }
529
+ }
530
+ else
531
+ {
532
+ if( $post->post_parent != $limiter )
533
+ {
534
+ $allowed = true;
535
+ }
536
+ elseif( $match == 'all' )
537
+ {
538
+ $short_circuit = true;
539
+ }
540
+ }
541
+ break;
542
+
543
+ default:
544
+ break;
545
+ }
546
+ }
547
+ }
548
+ }
549
+ return ( $allowed && !$short_circuit ) ? true : false;
550
+ }
551
+ }
552
+ <?php endif; ?>
553
+
554
+ <?php foreach( $attachments_pro_settings['positions'] as $attachments_pro_instance ) { if( isset( $attachments_pro_instance['conditions'] ) && is_array( $attachments_pro_instance['conditions'] ) && !empty( $attachments_pro_instance['conditions'] ) ) { ?>function attachments_check_<?php echo $attachments_pro_instance['name']; ?>()
555
+ {
556
+ $conditions = array(<?php foreach( $attachments_pro_instance['conditions'] as $condition ) : ?>
557
+
558
+ array(
559
+ 'param' => '<?php echo $condition['param']; ?>',
560
+ 'operator' => '<?php echo $condition['operator']; ?>',
561
+ 'limiter' => '<?php echo $condition['limiter']; ?>',
562
+ ),<?php endforeach; ?>
563
+
564
+ );
565
+
566
+ return attachments_is_allowed( $conditions, '<?php echo $attachments_pro_instance['match']; ?>' );
567
+ }
568
+
569
+ add_filter( "attachments_location_<?php echo $attachments_pro_instance['name']; ?>", 'attachments_check_<?php echo $attachments_pro_instance['name']; ?>' );
570
+ <?php }
571
+ }
572
+ ?>
573
+
574
+ <?php
575
+ $integrate_auto_append = false;
576
+ foreach( $attachments_pro_settings['positions'] as $attachments_pro_instance )
577
+ {
578
+ if( isset( $attachments_pro_instance['auto_append_enable'] ) )
579
+ {
580
+ $integrate_auto_append = true;
581
+ break;
582
+ }
583
+ }
584
+
585
+ if( $integrate_auto_append ) : ?>
586
+ /**
587
+ * Facilitate Attachments auto-append template parsing
588
+ */
589
+
590
+ if( !function_exists( 'attachments_magic_tags_processor' ) )
591
+ {
592
+ function attachments_magic_tags_processor( $in )
593
+ {
594
+ global $attachments_magic_tag_index, $attachments_auto_append_ref;
595
+ $name = $in[2];
596
+
597
+ switch( $name )
598
+ {
599
+ case 'index':
600
+ $value = $attachments_magic_tag_index;
601
+ break;
602
+
603
+ case 'id':
604
+ $value = $attachments_auto_append_ref->id();
605
+ break;
606
+
607
+ case 'thumb':
608
+ $value = $attachments_auto_append_ref->image( 'thumbnail' );
609
+ break;
610
+
611
+ case 'url':
612
+ $value = $attachments_auto_append_ref->url();
613
+ break;
614
+
615
+ case 'mime':
616
+ case 'type':
617
+ $value = $attachments_auto_append_ref->type();
618
+ break;
619
+
620
+ case 'subtype':
621
+ $value = $attachments_auto_append_ref->subtype();
622
+ break;
623
+
624
+ case 'filesize':
625
+ $value = $attachments_auto_append_ref->filesize();
626
+ break;
627
+
628
+ default:
629
+ $value = '';
630
+ break;
631
+ }
632
+
633
+ // we might be dealing with fields
634
+ if( empty( $value ) )
635
+ {
636
+ if( strpos( $name, 'field_' ) !== false )
637
+ {
638
+ // we are dealing with a field
639
+ $field = explode( '_', $name );
640
+
641
+ if( isset( $field[1] ) )
642
+ $value = $attachments_auto_append_ref->field( $field[1] );
643
+ }
644
+ }
645
+
646
+ // image details
647
+ if( empty( $value ) )
648
+ {
649
+ $request = explode( '.', $name );
650
+
651
+ if( is_array( $request ) && count( $request ) == 2 )
652
+ {
653
+ switch ( $request[1] )
654
+ {
655
+ case 'url':
656
+ case 'src':
657
+ $value = $attachments_auto_append_ref->src( $request[0] );
658
+ break;
659
+
660
+ case 'width':
661
+ $value = $attachments_auto_append_ref->width( $request[0] );
662
+ break;
663
+
664
+ case 'height':
665
+ $value = $attachments_auto_append_ref->height( $request[0] );
666
+ break;
667
+
668
+ case 'filesize':
669
+ $value = $attachments_auto_append_ref->filesize( null, $request[0] );
670
+ break;
671
+
672
+ default:
673
+ $value = '';
674
+ break;
675
+ }
676
+ }
677
+ }
678
+
679
+ return $value;
680
+ }
681
+ }
682
+ <?php endif; ?>
683
+
684
+ <?php foreach( $attachments_pro_settings['positions'] as $attachments_pro_instance ) : if( isset( $attachments_pro_instance['auto_append_enable'] ) && isset( $attachments_pro_instance['auto_append_template'] ) ) : ?>
685
+ if( !is_admin() )
686
+ {
687
+ function attachments_auto_append_<?php echo $attachments_pro_instance['name']; ?>( $content )
688
+ {
689
+ global $attachments_magic_tag_index, $attachments_auto_append_ref;
690
+
691
+ $original = $content;
692
+ $output = '';
693
+ $template = <<<EOD
694
+ <?php echo $attachments_pro_instance['auto_append_template']; ?>
695
+
696
+ EOD;
697
+
698
+ $attachments_auto_append_ref = new Attachments( '<?php echo $attachments_pro_instance['name']; ?>' );
699
+ if( $attachments_auto_append_ref->exist() )
700
+ {
701
+ $pattern = '/\s*\{@begin_attachments_loop\}\s*(.*?)\s*\{@end_attachments_loop\}\s*/xmis';
702
+ preg_match( $pattern, $template, $matches );
703
+ $loop_content = '';
704
+ if( isset( $matches[1] ) )
705
+ {
706
+ $loop_content = $matches[1];
707
+ $attachments_magic_tag_index = 1;
708
+ while( $attachments_auto_append_ref->get() )
709
+ {
710
+ $output .= preg_replace_callback( "/({@(.*?)})/m", 'attachments_magic_tags_processor', $loop_content );
711
+ $attachments_magic_tag_index++;
712
+ }
713
+ $output = preg_replace( $pattern, $output, $template );
714
+ }
715
+ }
716
+
717
+ return $original . $output;
718
+ }
719
+
720
+ add_filter( 'the_content', 'attachments_auto_append_<?php echo $attachments_pro_instance['name']; ?>' );
721
+ }
722
+ <?php endif; endforeach; ?><?php $code_for_functionsphp = ob_get_clean(); ?>
723
+ <textarea style="font-family:monospace; display:block; width:100%; height:300px;"><?php echo $code_for_functionsphp; ?></textarea>
724
+ <p><?php _e( "This code snippet has also been emailed to you for future reference as the migration only runs once. When you have verified your meta boxes have been restored and Attachments is operating as expected, you should <strong>deactivate Attachments Pro</strong>.", 'attachments' ); ?></p>
725
+ <h2><?php _e( 'The migration is STILL NOT COMPLETE', 'attachments' ); ?></h2>
726
+ <p><?php _e( 'While the data has been migrated and the meta boxes restored, <em>you still need to edit your template files where appropriate</em>. Please see the documentation for more information. The following sample code can be used as a starting point:', 'attachments' ); ?></p>
727
+ <?php ob_start(); foreach( $attachments_pro_settings['positions'] as $attachments_pro_instance ) : ?>
728
+ &lt;?php $attachments = new Attachments( '<?php echo $attachments_pro_instance['name']; ?>' ); ?&gt;
729
+ &lt;?php if( $attachments-&gt;exist() ) : ?&gt;
730
+ &lt;h3&gt;<?php echo $attachments_pro_instance['label']; ?>&lt;/h3&gt;
731
+ &lt;p&gt;Total <?php echo $attachments_pro_instance['label']; ?>: &lt;?php echo $attachments-&gt;total(); ?&gt;&lt;/p&gt;
732
+ &lt;ul&gt;
733
+ &lt;?php while( $attachments-&gt;get() ) : ?&gt;
734
+ &lt;li&gt;
735
+ ID: &lt;?php echo $attachments-&gt;id(); ?&gt;&lt;br /&gt;
736
+ Type: &lt;?php echo $attachments-&gt;type(); ?&gt;&lt;br /&gt;
737
+ Subtype: &lt;?php echo $attachments-&gt;subtype(); ?&gt;&lt;br /&gt;
738
+ URL: &lt;?php echo $attachments-&gt;url(); ?&gt;&lt;br /&gt;
739
+ Image: &lt;?php echo $attachments-&gt;image( 'thumbnail' ); ?&gt;&lt;br /&gt;
740
+ Source: &lt;?php echo $attachments-&gt;src( 'full' ); ?&gt;&lt;br /&gt;
741
+ Size: &lt;?php echo $attachments-&gt;filesize(); ?&gt;&lt;br /&gt;<?php if( is_array( $attachments_pro_instance['fields'] ) ) : ?><?php foreach( $attachments_pro_instance['fields'] as $field ) : ?><?php if( $field['type'] == 'textfield' ) { $field['type'] = 'text'; } ?>
742
+
743
+ <?php echo $field['label']; ?>: &lt;?php echo $attachments-&gt;field( '<?php echo str_replace( '-', '_', sanitize_title( $field['label'] ) ); ?>' ); ?&gt;&lt;br /&gt;<?php endforeach; endif; ?>
744
+
745
+ &lt;/li&gt;
746
+ &lt;?php endwhile; ?&gt;
747
+ &lt;/ul&gt;
748
+ &lt;?php endif; ?&gt;
749
+ <?php endforeach; $sample_template_code = ob_get_clean(); ?>
750
+ <textarea style="display:block; width:100%; font-family:monospace; height:200px;"><?php echo $sample_template_code; ?></textarea>
751
+ <?php
752
+ // send email with all code samples
753
+ $message = __( "Please add the following to your theme's functions.php, it will reinstate your meta boxes now that the data has been migrated from Attachments Pro.", 'attachments' );
754
+ $message .= "\n\n// ===== " . __( 'BEGIN functions.php COPY' ) . " ========================================\n\n";
755
+ $message .= $code_for_functionsphp;
756
+ $message .= "\n\n// ===== " . __( 'END functions.php COPY' ) . " ========================================\n\n";
757
+ $message .= "\n\n";
758
+ $message .= __( "You will also need to edit your theme template files where you want to use Attachments data. The syntax is quite different than it was for Attachments Pro, but you can use the code sample below to rebuild your output:", 'attachments' );
759
+ $message .= "\n\n\n// ===== " . __( 'BEGIN TEMPLATE COPY' ) . " ========================================\n\n";
760
+ $message .= html_entity_decode( $sample_template_code );
761
+ $message .= "\n\n// ===== " . __( 'END TEMPLATE COPY' ) . " ========================================\n\n";
762
+
763
+ $sent = wp_mail( $current_user->user_email, '[Attachments] ' . get_bloginfo( 'name' ) . ' - Code Samples', $message );
764
+
765
+ // we're also going to store them in the database for future reference
766
+ update_option( 'attachments_pro_functions', $code_for_functionsphp );
767
+ update_option( 'attachments_pro_template', $sample_template_code );
768
+ ?>
769
+ <p><?php _e( 'This code sample has been emailed to you for future reference as well.', 'attachments' ); ?>
770
+ <?php else : ?>
771
+ <h3><?php _e( 'Migration has already Run!', 'attachments' ); ?></h3>
772
+ <p><?php _e( 'The migration has already been run. The migration process has not been repeated.', 'attachments' ); ?></p>
773
+ <h2><?php _e( 'Required code for your functions.php', 'attachments' ); ?></h2>
774
+ <textarea style="display:block; width:100%; font-family:monospace; height:300px;"><?php echo get_option( 'attachments_pro_functions '); ?></textarea>
775
+ <h2><?php _e( 'Starter code for your theme templates', 'attachments' ); ?></h2>
776
+ <textarea style="display:block; width:100%; font-family:monospace; height:200px;"><?php echo get_option( 'attachments_pro_template '); ?></textarea>
777
+ <?php endif;
778
+ }
779
+
780
+ // make sure the database knows the migration has run
781
+ add_option( 'attachments_pro_migrated', true, '', 'no' );
782
+ }
783
+
784
+
785
+
786
+ function migrate_pro( $instance = array() )
787
+ {
788
+ if( !is_array( $instance ) || empty( $instance ) )
789
+ return false;
790
+
791
+ $post_types = get_post_types();
792
+
793
+ // set up our WP_Query args to grab anything (really anything) with legacy data
794
+ $args = array(
795
+ 'post_type' => !empty( $post_types ) ? $post_types : array( 'post', 'page' ),
796
+ 'post_status' => 'any',
797
+ 'posts_per_page' => -1,
798
+ 'meta_key' => '_attachments_pro',
799
+ 'suppress_filters' => true,
800
+ );
801
+
802
+ $query = new WP_Query( $args );
803
+
804
+ $count = array( 'instance' => $instance['name'], 'total' => 0 );
805
+
806
+ if( $query )
807
+ {
808
+ while( $query->have_posts() )
809
+ {
810
+ // set up postdata
811
+ $query->the_post();
812
+
813
+ // let's first decode our Attachments Pro data
814
+ $existing_instances = get_post_meta( $query->post->ID, '_attachments_pro', true );
815
+ $existing_instances = isset( $existing_instances['attachments'] ) ? $existing_instances['attachments'] : false;
816
+
817
+ // check to make sure we've got data
818
+ if( is_array( $existing_instances ) && count( $existing_instances ) > 0 )
819
+ {
820
+ $post_attachments = array();
821
+ foreach( $existing_instances as $instance_name => $instance_attachments )
822
+ {
823
+ if( $instance_name == $instance['name'] )
824
+ {
825
+ $post_attachments[$instance_name] = array();
826
+ $converted_attachment = array();
827
+ foreach( $instance_attachments as $instance_attachment )
828
+ {
829
+ $converted_attachment['id'] = $instance_attachment['id'];
830
+ if( is_array( $instance_attachment['fields'] ) )
831
+ {
832
+ $converted_attachment['fields'] = array();
833
+ foreach( $instance_attachment['fields'] as $instance_attachment_field_key => $instance_attachment_field )
834
+ {
835
+ $destination_field_name = $instance['fields'][$instance_attachment_field_key]['label'];
836
+ $destination_field_name = str_replace( '-', '_', sanitize_title( $destination_field_name ) );
837
+
838
+ $converted_attachment['fields'][$destination_field_name] = $instance_attachment_field;
839
+ }
840
+ unset( $instance_attachment_field_key );
841
+ }
842
+ unset( $instance_attachment );
843
+ $post_attachments[$instance_name][] = $converted_attachment;
844
+ $count['total']++;
845
+ }
846
+ }
847
+ }
848
+
849
+ if( !empty( $post_attachments ) )
850
+ {
851
+ // before saving the converted data, we need to see if there is existing Attachments data
852
+ $this->apply_init_filters();
853
+ $existing_attachments = get_post_meta( $query->post->ID, $this->get_meta_key(), false );
854
+
855
+ if( !isset( $existing_attachments[0] ) )
856
+ $existing_attachments[0] = '';
857
+
858
+ $existing_attachments = json_decode( $existing_attachments[0] );
859
+
860
+ if( !is_object( $existing_attachments ) )
861
+ $existing_attachments = new stdClass();
862
+
863
+ foreach( $post_attachments as $instance => $attachments )
864
+ {
865
+ // check to see if the existing Attachments have our target instance
866
+ if( !isset( $existing_attachments->$instance ) )
867
+ {
868
+ // the instance doesn't exist so we need to create it
869
+ $existing_attachments->$instance = array();
870
+ }
871
+
872
+ // loop through the instance attachments and integrate new and old
873
+ foreach( $attachments as $attachment )
874
+ {
875
+ // we need to convert our array to an object
876
+ $attachment['fields'] = (object) $attachment['fields'];
877
+ $attachment = (object) $attachment;
878
+
879
+ array_push( $existing_attachments->$instance, $attachment );
880
+ }
881
+ }
882
+
883
+ // now we can save
884
+ $existing_attachments = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $existing_attachments, JSON_UNESCAPED_UNICODE ) : json_encode( $existing_attachments );
885
+ update_post_meta( $query->post->ID, $this->get_meta_key(), $existing_attachments );
886
+
887
+ }
888
+ }
889
+ }
890
+ }
891
+
892
+ return $count;
893
+ }
894
+
895
  }
classes/class.attachments.php CHANGED
@@ -14,7 +14,7 @@
14
  if( !defined( 'ABSPATH' ) ) exit;
15
 
16
  // Declare our class
17
- if ( !class_exists( 'Attachments' ) ) :
18
 
19
  /**
20
  * Main Attachments Class
@@ -22,8 +22,8 @@ if ( !class_exists( 'Attachments' ) ) :
22
  * @since 3.0
23
  */
24
 
25
- class Attachments {
26
-
27
  private $version; // stores Attachments' version number
28
  private $url; // stores Attachments' URL
29
  private $dir; // stores Attachments' directory
@@ -33,7 +33,6 @@ if ( !class_exists( 'Attachments' ) ) :
33
  private $attachments; // stores all of the Attachments for the given instance
34
 
35
  private $image_sizes = array( 'full' ); // store all registered image sizes
36
- private $default_instance = true; // use the default instance?
37
  private $attachments_ref = -1; // flags where a get() loop last did it's thing
38
  private $meta_key = 'attachments'; // our meta key
39
  private $valid_filetypes = array( // what WordPress considers to be valid file types
@@ -56,10 +55,10 @@ if ( !class_exists( 'Attachments' ) ) :
56
  global $_wp_additional_image_sizes;
57
 
58
  // establish our environment variables
59
-
60
- $this->version = '3.4.2.1';
61
  $this->url = ATTACHMENTS_URL;
62
  $this->dir = ATTACHMENTS_DIR;
 
63
 
64
  // includes
65
  include_once( ATTACHMENTS_DIR . 'upgrade.php' );
@@ -73,9 +72,15 @@ if ( !class_exists( 'Attachments' ) ) :
73
  // set our image sizes
74
  $this->image_sizes = array_merge( $this->image_sizes, get_intermediate_image_sizes() );
75
 
 
 
 
76
  // set up l10n
77
  add_action( 'plugins_loaded', array( $this, 'l10n' ) );
78
 
 
 
 
79
  // hook into WP
80
  add_action( 'admin_enqueue_scripts', array( $this, 'assets' ), 999, 1 );
81
 
@@ -96,6 +101,8 @@ if ( !class_exists( 'Attachments' ) ) :
96
  add_action( 'admin_head', array( $this, 'field_inits' ) );
97
  add_action( 'admin_print_footer_scripts', array( $this, 'field_assets' ) );
98
 
 
 
99
  // execution of actions varies depending on whether we're in the admin or not and an instance was passed
100
  if( is_admin() )
101
  {
@@ -112,6 +119,106 @@ if ( !class_exists( 'Attachments' ) ) :
112
 
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  /**
116
  * Getter for the current meta_key
117
  *
@@ -124,6 +231,18 @@ if ( !class_exists( 'Attachments' ) ) :
124
 
125
 
126
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  /**
128
  * Register our textdomain for l10n
129
  *
@@ -131,7 +250,14 @@ if ( !class_exists( 'Attachments' ) ) :
131
  */
132
  function l10n()
133
  {
134
- load_plugin_textdomain( 'attachments', false, trailingslashit( ATTACHMENTS_DIR ) . 'languages/' );
 
 
 
 
 
 
 
135
  }
136
 
137
 
@@ -310,27 +436,53 @@ if ( !class_exists( 'Attachments' ) ) :
310
 
311
 
312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  /**
314
  * Returns the formatted filesize of the current Attachment
315
  *
316
  * @since 3.0
317
  */
318
- function filesize( $index = null )
319
  {
320
  $index = is_null( $index ) ? $this->attachments_ref : intval( $index );
321
 
322
  if( !isset( $this->attachments[$index]->id ) )
323
  return false;
324
 
325
- $url = wp_get_attachment_url( $this->attachments[$index]->id );
 
326
  $uploads = wp_upload_dir();
327
  $file_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
328
 
329
  $formatted = '0 bytes';
330
  if( file_exists( $file_path ) )
331
- {
332
  $formatted = size_format( @filesize( $file_path ) );
333
- }
334
  return $formatted;
335
  }
336
 
@@ -498,13 +650,29 @@ if ( !class_exists( 'Attachments' ) ) :
498
  {
499
  foreach( $this->instances_for_post_type as $instance )
500
  {
 
 
 
 
501
  $instance_name = $instance;
502
  $instance = (object) $this->instances[$instance];
503
  $instance->name = $instance_name;
504
  $position = isset($instance->position) ? $instance->position : 'normal';
505
  $priority = isset($instance->priority) ? $instance->priority : 'high';
506
 
507
- add_meta_box( 'attachments-' . $instance_name, __( esc_attr( $instance->label ) ), array( $this, 'meta_box_markup' ), $this->get_post_type(), $position, $priority, array( 'instance' => $instance, 'setup_nonce' => !$nonce_sent ) );
 
 
 
 
 
 
 
 
 
 
 
 
508
 
509
  $nonce_sent = true;
510
  }
@@ -562,13 +730,22 @@ if ( !class_exists( 'Attachments' ) ) :
562
  title = '<?php echo __( esc_attr( $instance->label ) ); ?>',
563
  button = '<?php echo __( esc_attr( $instance->modal_text ) ); ?>',
564
  router = '<?php echo __( esc_attr( $instance->router ) ); ?>',
565
- attachmentsframe;
 
 
 
566
 
567
  $element.on( 'click', '.attachments-invoke', function( event ) {
568
- var options, attachment;
569
 
570
  event.preventDefault();
571
 
 
 
 
 
 
 
572
  // if the frame already exists, open it
573
  if ( attachmentsframe ) {
574
  attachmentsframe.open();
@@ -576,7 +753,7 @@ if ( !class_exists( 'Attachments' ) ) :
576
  return;
577
  }
578
 
579
- // set our seetings
580
  attachmentsframe = wp.media({
581
 
582
  title: title,
@@ -597,9 +774,9 @@ if ( !class_exists( 'Attachments' ) ) :
597
  });
598
 
599
  // set up our select handler
600
- attachmentsframe.on( 'select', function() {
601
 
602
- selection = attachmentsframe.state().get('selection');
603
 
604
  if ( ! selection )
605
  return;
@@ -615,6 +792,11 @@ if ( !class_exists( 'Attachments' ) ) :
615
  // loop through the selected files
616
  selection.each( function( attachment ) {
617
 
 
 
 
 
 
618
  // set our attributes to the template
619
  attachment.attributes.attachment_uid = attachments_uniqid( 'attachmentsjs' );
620
 
@@ -639,6 +821,9 @@ if ( !class_exists( 'Attachments' ) ) :
639
  // append the template
640
  $element.find('.attachments-container').<?php if( $instance->append ) : ?>append<?php else : ?>prepend<?php endif; ?>(template(templateData));
641
 
 
 
 
642
  // if we're in a sidebar we DO want to show the fields which are normally hidden on load via CSS
643
  if($element.parents('#side-sortables')){
644
  $element.find('.attachments-attachment:last .attachments-fields').show();
@@ -672,6 +857,64 @@ if ( !class_exists( 'Attachments' ) ) :
672
 
673
  });
674
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
675
  $element.on( 'click', '.delete-attachment a', function( event ) {
676
 
677
  var targetAttachment;
@@ -845,7 +1088,7 @@ if ( !class_exists( 'Attachments' ) ) :
845
  ),
846
  array(
847
  'name' => 'caption', // unique field name
848
- 'type' => 'wysiwyg', // registered field type
849
  'label' => __( 'Caption', 'attachments' ), // label to display
850
  'default' => 'caption', // default value upon selection
851
  ),
@@ -1060,7 +1303,7 @@ if ( !class_exists( 'Attachments' ) ) :
1060
  <div class="attachments-attachment attachments-attachment-<?php echo $instance; ?>">
1061
  <?php $array_flag = ( isset( $attachment->uid ) ) ? $attachment->uid : '{{ attachments.attachment_uid }}'; ?>
1062
 
1063
- <input type="hidden" name="attachments[<?php echo $instance; ?>][<?php echo $array_flag; ?>][id]" value="<?php echo isset( $attachment->id ) ? $attachment->id : '{{ attachments.id }}' ; ?>" />
1064
 
1065
  <?php
1066
  // since attributes can change over time (image gets replaced, cropped, etc.) we'll pull that info
@@ -1097,6 +1340,7 @@ if ( !class_exists( 'Attachments' ) ) :
1097
  <?php if( ( isset( $attachment->id ) && isset( $attachment->width ) ) || !isset( $attachment->id ) ) : ?>
1098
  <div class="dimensions"><?php echo isset( $attachment->width ) ? $attachment->width : '{{ attachments.width }}' ; ?> &times; <?php echo isset( $attachment->height ) ? $attachment->height : '{{ attachments.height }}' ; ?></div>
1099
  <?php endif; ?>
 
1100
  <div class="delete-attachment"><a href="#"><?php _e( 'Remove', 'attachments' ); ?></a></div>
1101
  <div class="attachments-attachment-fields-toggle"><a href="#"><?php _e( 'Toggle Fields', 'attachments' ); ?></a></div>
1102
  </div>
@@ -1237,6 +1481,26 @@ if ( !class_exists( 'Attachments' ) ) :
1237
  // if the user deleted all Attachments we won't have our key
1238
  $attachments_meta = isset( $_POST['attachments'] ) ? $_POST['attachments'] : array();
1239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1240
  // final data store
1241
  $attachments = array();
1242
 
@@ -1246,36 +1510,41 @@ if ( !class_exists( 'Attachments' ) ) :
1246
  // loop through each Attachment of this instance
1247
  foreach( $instance_attachments as $key => $attachment )
1248
  {
1249
- // since we're using JSON for storage in the database, we need
1250
- // to make sure that characters are encoded that would otherwise
1251
- // break the JSON
1252
- if( isset( $attachment['fields'] ) && is_array( $attachment['fields'] ) )
1253
  {
1254
-
1255
- foreach( $attachment['fields'] as $key => $field_value )
 
 
1256
  {
1257
- // take care of our returns
1258
- $field_value = str_replace( "\r\n", "\n", $field_value );
1259
- $field_value = str_replace( "\r", "\n", $field_value );
1260
 
1261
- // we dont want to strip out our newlines so we're going to flag them
1262
- $field_value = str_replace("\n", "%%ATTACHMENTS_NEWLINE%%", $field_value );
 
 
 
 
 
 
1263
 
1264
- // slashes were already added so we're going to strip them
1265
- $field_value = stripslashes_deep( $field_value );
1266
 
1267
- // put back our newlines
1268
- $field_value = str_replace("%%ATTACHMENTS_NEWLINE%%", "\\n", $field_value );
1269
 
1270
- // encode the whole thing
1271
- $field_value = $this->encode_field_value( $field_value );
1272
 
1273
- // encode things properly
1274
- $attachment['fields'][$key] = $field_value;
 
1275
  }
1276
- }
1277
 
1278
- $attachments[$instance][] = $attachment;
 
1279
  }
1280
  }
1281
 
@@ -1285,15 +1554,13 @@ if ( !class_exists( 'Attachments' ) ) :
1285
  $attachments = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $attachments, JSON_UNESCAPED_UNICODE ) : json_encode( $attachments );
1286
 
1287
  // we're going to wipe out any existing Attachments meta (because we'll put it back)
1288
- update_post_meta( $post_id, $this->meta_key, $attachments );
1289
  }
1290
  else
1291
  {
1292
  // there are no attachments so we'll clean up the record
1293
- delete_post_meta( $post_id, $this->meta_key );
1294
  }
1295
-
1296
- return $post_id;
1297
  }
1298
 
1299
 
@@ -1308,7 +1575,7 @@ if ( !class_exists( 'Attachments' ) ) :
1308
  function encode_field_value( $field_value = null )
1309
  {
1310
  if( is_null( $field_value ) )
1311
- return;
1312
 
1313
  if( is_object( $field_value ) )
1314
  {
@@ -1357,10 +1624,15 @@ if ( !class_exists( 'Attachments' ) ) :
1357
  elseif( is_null( $instance ) )
1358
  {
1359
  // return them all, regardless of instance
1360
- if( is_array( $attachments_raw ) && count( $attachments_raw ) )
 
 
 
 
1361
  foreach( $attachments_raw as $instance => $attachments_unprocessed )
1362
  foreach( $attachments_unprocessed as $unprocessed_attachment )
1363
  $attachments[] = $this->process_attachment( $unprocessed_attachment, $instance );
 
1364
  }
1365
 
1366
  // tack on the post ID for each attachment
@@ -1432,7 +1704,8 @@ if ( !class_exists( 'Attachments' ) ) :
1432
  /**
1433
  * Processes Attachment (including fields) in preparation for return
1434
  * @param object $attachment An Attachment object as it was stored as post metadata
1435
- * @return object Post-processed Attachment data
 
1436
  *
1437
  * @since 3.3
1438
  */
@@ -1490,7 +1763,7 @@ if ( !class_exists( 'Attachments' ) ) :
1490
  function decode_field_value( $field_value = null )
1491
  {
1492
  if( is_null( $field_value ) )
1493
- return;
1494
 
1495
  if( is_object( $field_value ) )
1496
  {
14
  if( !defined( 'ABSPATH' ) ) exit;
15
 
16
  // Declare our class
17
+ if( !class_exists( 'Attachments' ) ) :
18
 
19
  /**
20
  * Main Attachments Class
22
  * @since 3.0
23
  */
24
 
25
+ class Attachments
26
+ {
27
  private $version; // stores Attachments' version number
28
  private $url; // stores Attachments' URL
29
  private $dir; // stores Attachments' directory
33
  private $attachments; // stores all of the Attachments for the given instance
34
 
35
  private $image_sizes = array( 'full' ); // store all registered image sizes
 
36
  private $attachments_ref = -1; // flags where a get() loop last did it's thing
37
  private $meta_key = 'attachments'; // our meta key
38
  private $valid_filetypes = array( // what WordPress considers to be valid file types
55
  global $_wp_additional_image_sizes;
56
 
57
  // establish our environment variables
58
+ $this->version = '3.5';
 
59
  $this->url = ATTACHMENTS_URL;
60
  $this->dir = ATTACHMENTS_DIR;
61
+ $plugin = 'attachments/index.php';
62
 
63
  // includes
64
  include_once( ATTACHMENTS_DIR . 'upgrade.php' );
72
  // set our image sizes
73
  $this->image_sizes = array_merge( $this->image_sizes, get_intermediate_image_sizes() );
74
 
75
+ // add 'Extend' link
76
+ add_filter( "plugin_action_links_$plugin", array( $this, 'plugin_settings_link' ) );
77
+
78
  // set up l10n
79
  add_action( 'plugins_loaded', array( $this, 'l10n' ) );
80
 
81
+ // load extensions
82
+ add_action( 'plugins_loaded', array( $this, 'load_extensions' ) );
83
+
84
  // hook into WP
85
  add_action( 'admin_enqueue_scripts', array( $this, 'assets' ), 999, 1 );
86
 
101
  add_action( 'admin_head', array( $this, 'field_inits' ) );
102
  add_action( 'admin_print_footer_scripts', array( $this, 'field_assets' ) );
103
 
104
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
105
+
106
  // execution of actions varies depending on whether we're in the admin or not and an instance was passed
107
  if( is_admin() )
108
  {
119
 
120
 
121
 
122
+ function plugin_settings_link( $links )
123
+ {
124
+ $extend_link = '<a href="https://mondaybynoon.com/members/plugins/#attachments">'. __( 'Extend', 'attachments' ) . '</a>';
125
+ array_unshift( $links, $extend_link );
126
+ return $links;
127
+ }
128
+
129
+
130
+
131
+ /**
132
+ * Callback for WordPress' admin_init action
133
+ *
134
+ * @since 3.4.3
135
+ */
136
+ function admin_init()
137
+ {
138
+ if( current_user_can( 'delete_posts' ) )
139
+ add_action( 'delete_post', array( $this, 'handle_wp_post_delete' ), 10 );
140
+ }
141
+
142
+
143
+
144
+ /**
145
+ * Getter for the existing fields
146
+ *
147
+ * @return array
148
+ * @since 3.5
149
+ */
150
+ function get_fields()
151
+ {
152
+ return $this->fields;
153
+ }
154
+
155
+
156
+
157
+ /**
158
+ * Callback for WordPress' delete_post action. Searches all saved Attachments
159
+ * data for any records using a deleted attachment. If found, the record is removed.
160
+ *
161
+ * @param int $pid Post ID
162
+ * @since 3.4.3
163
+ */
164
+ function handle_wp_post_delete( $pid )
165
+ {
166
+ // check to make sure it was an attachment
167
+ if( 'attachment' != get_post_type( $pid ) )
168
+ return;
169
+
170
+ // if a user deletes an attachment from the Media library (but it's been used
171
+ // in Attachments somewhere else) we need to clean that up...
172
+
173
+ // we hook into delete_post because the only other option is to filter
174
+ // each Attachment when retrieving Attachments via get_attachments()
175
+ // which could potentially be a ton of database calls
176
+
177
+ // so we're going to use the search class to find all instances
178
+ // for any occurrence of the deleted attachment (which has an ID of $pid)
179
+
180
+ if( is_array( $this->instances ) )
181
+ {
182
+ foreach( $this->instances as $instance => $details )
183
+ {
184
+ $search_args = array(
185
+ 'instance' => $instance,
186
+ 'attachment_id' => intval( $pid ),
187
+ );
188
+
189
+ $this->search( null, $search_args );
190
+
191
+ if( $this->exist() )
192
+ {
193
+ // we've got a hit (e.g. an existing post uses the deleted attachment)
194
+ while( $attachment = $this->get() )
195
+ {
196
+ $post_id = $attachment->post_id;
197
+
198
+ // we'll use the post ID to snag the details
199
+ $post_attachments = $this->get_attachments_metadata( $post_id );
200
+
201
+ if( is_object( $post_attachments ) )
202
+ {
203
+ foreach( $post_attachments as $existing_instance => $existing_instance_attachments )
204
+ foreach( $existing_instance_attachments as $existing_instance_attachment_key => $existing_instance_attachment )
205
+ if( $pid == intval( $existing_instance_attachment->id ) )
206
+ unset( $post_attachments->{$existing_instance}[$existing_instance_attachment_key] );
207
+
208
+ // saving routine assumes array from POST so we'll typecast it
209
+ $post_attachments = (array) $post_attachments;
210
+
211
+ // save the revised Attachments metadata
212
+ $this->save_metadata( $post_id, $post_attachments );
213
+ }
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+
221
+
222
  /**
223
  * Getter for the current meta_key
224
  *
231
 
232
 
233
 
234
+ /**
235
+ * Getter for our URL
236
+ *
237
+ * @since 3.5
238
+ */
239
+ function get_url()
240
+ {
241
+ return $this->url;
242
+ }
243
+
244
+
245
+
246
  /**
247
  * Register our textdomain for l10n
248
  *
250
  */
251
  function l10n()
252
  {
253
+ load_plugin_textdomain( 'attachments', false, trailingslashit( ATTACHMENTS_DIR ) . 'languages' );
254
+ }
255
+
256
+
257
+
258
+ function load_extensions()
259
+ {
260
+ do_action( 'attachments_extension', $this );
261
  }
262
 
263
 
436
 
437
 
438
 
439
+ /**
440
+ * Returns the width of the current Attachment if it's an image
441
+ *
442
+ * @since 3.5
443
+ */
444
+ function width( $size = 'thumbnail', $index = null )
445
+ {
446
+ $asset = $this->asset( $size, $index );
447
+ return $asset[1];
448
+ }
449
+
450
+
451
+
452
+ /**
453
+ * Returns the height of the current Attachment if it's an image
454
+ *
455
+ * @since 3.5
456
+ */
457
+ function height( $size = 'thumbnail', $index = null )
458
+ {
459
+ $asset = $this->asset( $size, $index );
460
+ return $asset[2];
461
+ }
462
+
463
+
464
+
465
  /**
466
  * Returns the formatted filesize of the current Attachment
467
  *
468
  * @since 3.0
469
  */
470
+ function filesize( $index = null, $size = null )
471
  {
472
  $index = is_null( $index ) ? $this->attachments_ref : intval( $index );
473
 
474
  if( !isset( $this->attachments[$index]->id ) )
475
  return false;
476
 
477
+ // if an image size is passed along, use that
478
+ $url = is_string( $size ) ? $this->src( $size, $index ) : wp_get_attachment_url( $this->attachments[$index]->id );
479
  $uploads = wp_upload_dir();
480
  $file_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
481
 
482
  $formatted = '0 bytes';
483
  if( file_exists( $file_path ) )
 
484
  $formatted = size_format( @filesize( $file_path ) );
485
+
486
  return $formatted;
487
  }
488
 
650
  {
651
  foreach( $this->instances_for_post_type as $instance )
652
  {
653
+ // facilitate more fine-grained meta box positioning than post type
654
+ $applicable = apply_filters( "attachments_location_{$instance}", true, $instance );
655
+
656
+ // obtain other details about instance
657
  $instance_name = $instance;
658
  $instance = (object) $this->instances[$instance];
659
  $instance->name = $instance_name;
660
  $position = isset($instance->position) ? $instance->position : 'normal';
661
  $priority = isset($instance->priority) ? $instance->priority : 'high';
662
 
663
+ if( $applicable )
664
+ add_meta_box(
665
+ 'attachments-' . $instance_name,
666
+ __( esc_attr( $instance->label ) ),
667
+ array( $this, 'meta_box_markup' ),
668
+ $this->get_post_type(),
669
+ $position,
670
+ $priority,
671
+ array(
672
+ 'instance' => $instance,
673
+ 'setup_nonce' => !$nonce_sent
674
+ )
675
+ );
676
 
677
  $nonce_sent = true;
678
  }
730
  title = '<?php echo __( esc_attr( $instance->label ) ); ?>',
731
  button = '<?php echo __( esc_attr( $instance->modal_text ) ); ?>',
732
  router = '<?php echo __( esc_attr( $instance->router ) ); ?>',
733
+ limit = <?php echo intval( $instance->limit ); ?>,
734
+ existing = <?php echo ( isset( $instance->attachments ) && !empty( $instance->attachments ) ) ? count( $instance->attachments ): 0; ?>,
735
+ attachmentsframe,
736
+ editframe;
737
 
738
  $element.on( 'click', '.attachments-invoke', function( event ) {
739
+ var attachment;
740
 
741
  event.preventDefault();
742
 
743
+ existing = $element.find('.attachments-container > .attachments-attachment').length;
744
+ if( limit > -1 && existing >= limit ){
745
+ alert('<?php _e( "Currently limited to", "attachments" ); ?> ' + limit);
746
+ return false;
747
+ }
748
+
749
  // if the frame already exists, open it
750
  if ( attachmentsframe ) {
751
  attachmentsframe.open();
753
  return;
754
  }
755
 
756
+ // set our settings
757
  attachmentsframe = wp.media({
758
 
759
  title: title,
774
  });
775
 
776
  // set up our select handler
777
+ attachmentsframe.on( 'select', function(){
778
 
779
+ var selection = attachmentsframe.state().get('selection');
780
 
781
  if ( ! selection )
782
  return;
792
  // loop through the selected files
793
  selection.each( function( attachment ) {
794
 
795
+ // make sure we respect the limit
796
+ if( limit > -1 && existing >= limit ){
797
+ return;
798
+ }
799
+
800
  // set our attributes to the template
801
  attachment.attributes.attachment_uid = attachments_uniqid( 'attachmentsjs' );
802
 
821
  // append the template
822
  $element.find('.attachments-container').<?php if( $instance->append ) : ?>append<?php else : ?>prepend<?php endif; ?>(template(templateData));
823
 
824
+ // update the number of existing Attachments
825
+ existing = $element.find('.attachments-container > .attachments-attachment').length;
826
+
827
  // if we're in a sidebar we DO want to show the fields which are normally hidden on load via CSS
828
  if($element.parents('#side-sortables')){
829
  $element.find('.attachments-attachment:last .attachments-fields').show();
857
 
858
  });
859
 
860
+ $element.on( 'click', '.edit-attachment-asset', function( event ) {
861
+ event.preventDefault();
862
+ if ( editframe ) {
863
+ editframe.open();
864
+ editframe.content.mode(router);
865
+ return;
866
+ }
867
+ editframe = wp.media({
868
+ title: title,
869
+ multiple: false,
870
+ library: {
871
+ type: '<?php echo esc_attr( implode( ",", $instance->filetype ) ); ?>'
872
+ },
873
+ button: {
874
+ text: '<?php _e( "Change", 'attachments' ); ?>'
875
+ }
876
+ });
877
+ editframe.on( 'select', function(){
878
+ var selection = editframe.state().get('selection');
879
+
880
+ if ( ! selection )
881
+ return;
882
+
883
+ selection.each( function( attachment ) {
884
+
885
+ // update the ID
886
+ $element.find('input.attachments-track-id').val(attachment.id);
887
+
888
+ // update the thumbnail
889
+ var updatedThumb = false;
890
+ if(attachments_isset(attachment.attributes)){
891
+ if(attachments_isset(attachment.attributes.sizes)){
892
+ if(attachments_isset(attachment.attributes.sizes.thumbnail)){
893
+ if(attachments_isset(attachment.attributes.sizes.thumbnail.url)){
894
+ updatedThumb = true;
895
+ $element.find('.attachment-thumbnail img').attr('src',attachment.attributes.sizes.thumbnail.url);
896
+ }
897
+ }
898
+ }
899
+ }
900
+ if( !updatedThumb ){
901
+ $element.find('.attachment-thumbnail img').attr('src','');
902
+ }
903
+
904
+ // update the name
905
+ $element.find('.attachment-details .filename').text(attachment.attributes.filename);
906
+
907
+ // update the dimensions
908
+ if(attachments_isset(attachment.attributes.width)&&attachments_isset(attachment.attributes.height)){
909
+ $element.find('.attachment-details .dimensions').html(attachment.attributes.width + ' &times; ' + attachment.attributes.height).show();
910
+ }
911
+
912
+ } );
913
+ });
914
+ editframe.open();
915
+ editframe.content.mode(router);
916
+ } );
917
+
918
  $element.on( 'click', '.delete-attachment a', function( event ) {
919
 
920
  var targetAttachment;
1088
  ),
1089
  array(
1090
  'name' => 'caption', // unique field name
1091
+ 'type' => 'wysiwyg', // registered field type
1092
  'label' => __( 'Caption', 'attachments' ), // label to display
1093
  'default' => 'caption', // default value upon selection
1094
  ),
1303
  <div class="attachments-attachment attachments-attachment-<?php echo $instance; ?>">
1304
  <?php $array_flag = ( isset( $attachment->uid ) ) ? $attachment->uid : '{{ attachments.attachment_uid }}'; ?>
1305
 
1306
+ <input type="hidden" class="attachments-track-id" name="attachments[<?php echo $instance; ?>][<?php echo $array_flag; ?>][id]" value="<?php echo isset( $attachment->id ) ? $attachment->id : '{{ attachments.id }}' ; ?>" />
1307
 
1308
  <?php
1309
  // since attributes can change over time (image gets replaced, cropped, etc.) we'll pull that info
1340
  <?php if( ( isset( $attachment->id ) && isset( $attachment->width ) ) || !isset( $attachment->id ) ) : ?>
1341
  <div class="dimensions"><?php echo isset( $attachment->width ) ? $attachment->width : '{{ attachments.width }}' ; ?> &times; <?php echo isset( $attachment->height ) ? $attachment->height : '{{ attachments.height }}' ; ?></div>
1342
  <?php endif; ?>
1343
+ <div class="edit-attachment-asset"><a href="#"><?php _e( 'Change', 'attachments' ); ?></a></div>
1344
  <div class="delete-attachment"><a href="#"><?php _e( 'Remove', 'attachments' ); ?></a></div>
1345
  <div class="attachments-attachment-fields-toggle"><a href="#"><?php _e( 'Toggle Fields', 'attachments' ); ?></a></div>
1346
  </div>
1481
  // if the user deleted all Attachments we won't have our key
1482
  $attachments_meta = isset( $_POST['attachments'] ) ? $_POST['attachments'] : array();
1483
 
1484
+ $this->save_metadata( $post_id, $attachments_meta );
1485
+
1486
+ return $post_id;
1487
+ }
1488
+
1489
+
1490
+
1491
+ /**
1492
+ * Processes submitted fields and saves Attachments' post metadata
1493
+ *
1494
+ * @param int $post_id The post ID
1495
+ * @param array $attachments_meta Multidimenaional array containing Attachments data
1496
+ * @return bool
1497
+ * @since 3.4.3
1498
+ */
1499
+ function save_metadata( $post_id = 0, $attachments_meta = null )
1500
+ {
1501
+ if( !is_array( $attachments_meta ) || !is_int( $post_id ) || intval( $post_id ) < 1 )
1502
+ return false;
1503
+
1504
  // final data store
1505
  $attachments = array();
1506
 
1510
  // loop through each Attachment of this instance
1511
  foreach( $instance_attachments as $key => $attachment )
1512
  {
1513
+ $attachment_exists = get_post( $attachment['id'] );
1514
+ // make sure the attachment exists
1515
+ if( $attachment_exists )
 
1516
  {
1517
+ // since we're using JSON for storage in the database, we need
1518
+ // to make sure that characters are encoded that would otherwise
1519
+ // break the JSON
1520
+ if( isset( $attachment['fields'] ) && is_array( $attachment['fields'] ) )
1521
  {
 
 
 
1522
 
1523
+ foreach( $attachment['fields'] as $key => $field_value )
1524
+ {
1525
+ // take care of our returns
1526
+ $field_value = str_replace( "\r\n", "\n", $field_value );
1527
+ $field_value = str_replace( "\r", "\n", $field_value );
1528
+
1529
+ // we don't want to strip out our newlines so we're going to flag them
1530
+ $field_value = str_replace("\n", "%%ATTACHMENTS_NEWLINE%%", $field_value );
1531
 
1532
+ // slashes were already added so we're going to strip them
1533
+ $field_value = stripslashes_deep( $field_value );
1534
 
1535
+ // put back our newlines
1536
+ $field_value = str_replace("%%ATTACHMENTS_NEWLINE%%", "\\n", $field_value );
1537
 
1538
+ // encode the whole thing
1539
+ $field_value = $this->encode_field_value( $field_value );
1540
 
1541
+ // encode things properly
1542
+ $attachment['fields'][$key] = $field_value;
1543
+ }
1544
  }
 
1545
 
1546
+ $attachments[$instance][] = $attachment;
1547
+ }
1548
  }
1549
  }
1550
 
1554
  $attachments = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $attachments, JSON_UNESCAPED_UNICODE ) : json_encode( $attachments );
1555
 
1556
  // we're going to wipe out any existing Attachments meta (because we'll put it back)
1557
+ return update_post_meta( $post_id, $this->meta_key, $attachments );
1558
  }
1559
  else
1560
  {
1561
  // there are no attachments so we'll clean up the record
1562
+ return delete_post_meta( $post_id, $this->meta_key );
1563
  }
 
 
1564
  }
1565
 
1566
 
1575
  function encode_field_value( $field_value = null )
1576
  {
1577
  if( is_null( $field_value ) )
1578
+ return false;
1579
 
1580
  if( is_object( $field_value ) )
1581
  {
1624
  elseif( is_null( $instance ) )
1625
  {
1626
  // return them all, regardless of instance
1627
+ if( ( is_array( $attachments_raw ) && count( $attachments_raw ) ) || is_object( $attachments_raw ) )
1628
+ {
1629
+ // cast an object if necessary
1630
+ if( is_object( $attachments_raw ) ) $attachments_raw = (array) $attachments_raw;
1631
+
1632
  foreach( $attachments_raw as $instance => $attachments_unprocessed )
1633
  foreach( $attachments_unprocessed as $unprocessed_attachment )
1634
  $attachments[] = $this->process_attachment( $unprocessed_attachment, $instance );
1635
+ }
1636
  }
1637
 
1638
  // tack on the post ID for each attachment
1704
  /**
1705
  * Processes Attachment (including fields) in preparation for return
1706
  * @param object $attachment An Attachment object as it was stored as post metadata
1707
+ * @param string $instance The applicable instance
1708
+ * @return object Post-processed Attachment data
1709
  *
1710
  * @since 3.3
1711
  */
1763
  function decode_field_value( $field_value = null )
1764
  {
1765
  if( is_null( $field_value ) )
1766
+ return false;
1767
 
1768
  if( is_object( $field_value ) )
1769
  {
classes/class.attachments.search.php CHANGED
@@ -124,17 +124,17 @@ class AttachmentsSearch extends Attachments
124
  // we only want to check certain fields
125
  foreach( $params['fields'] as $field )
126
  if( isset( $potential_attachments[$i]->fields->$field ) ) // does the field exist?
127
- if( !$query || strpos( strtolower( $potential_attachments[$i]->fields->$field ),
128
  strtolower( $query ) ) !== false ) // does the value match?
129
- if( !is_null( $params['filetype'] ) && in_array( parent::get_mime_type( $potential_attachments[$i]->id ), $params['filetype'] ) )
130
  $valid = true;
131
  }
132
  else
133
  {
134
  // we want to check all fields
135
  foreach( $potential_attachments[$i]->fields as $field_name => $field_value )
136
- if( !$query || strpos( strtolower( $field_value) , strtolower( $query ) ) !== false )
137
- if( !is_null( $params['filetype'] ) && in_array( parent::get_mime_type( $potential_attachments[$i]->id ), $params['filetype'] ) )
138
  $valid = true;
139
  }
140
 
124
  // we only want to check certain fields
125
  foreach( $params['fields'] as $field )
126
  if( isset( $potential_attachments[$i]->fields->$field ) ) // does the field exist?
127
+ if( empty( $query ) || strpos( strtolower( $potential_attachments[$i]->fields->$field ),
128
  strtolower( $query ) ) !== false ) // does the value match?
129
+ if( is_null( $params['filetype'] ) || ( !is_null( $params['filetype'] ) && in_array( parent::get_mime_type( $potential_attachments[$i]->id ), $params['filetype'] ) ) )
130
  $valid = true;
131
  }
132
  else
133
  {
134
  // we want to check all fields
135
  foreach( $potential_attachments[$i]->fields as $field_name => $field_value )
136
+ if( empty( $query ) || strpos( strtolower( $field_value) , strtolower( $query ) ) !== false )
137
+ if( is_null( $params['filetype'] ) || ( !is_null( $params['filetype'] ) && in_array( parent::get_mime_type( $potential_attachments[$i]->id ), $params['filetype'] ) ) )
138
  $valid = true;
139
  }
140
 
classes/fields/class.field.select.php CHANGED
@@ -24,15 +24,15 @@ class Attachments_Field_Select extends Attachments_Field
24
  function __construct( $name = 'name', $label = 'Name', $value = null, $meta = array() )
25
  {
26
  $defaults = array(
27
- 'allow_null' => true,
28
- 'multiple' => false,
29
  'options' => array(), // no <option>s by default
 
 
30
  );
31
 
32
  $meta = array_merge( $defaults, $meta );
33
 
34
  $this->options = is_array( $meta['options'] ) ? $meta['options'] : array();
35
- $this->allow_null = is_bool( $meta['allow_null'] ) ? $meta['allow_null'] : true;
36
  $this->multiple = is_bool( $meta['multiple'] ) ? $meta['multiple'] : false;
37
 
38
  parent::__construct( $name, $label, $value, $meta );
24
  function __construct( $name = 'name', $label = 'Name', $value = null, $meta = array() )
25
  {
26
  $defaults = array(
 
 
27
  'options' => array(), // no <option>s by default
28
+ 'allow_null' => false,
29
+ 'multiple' => false,
30
  );
31
 
32
  $meta = array_merge( $defaults, $meta );
33
 
34
  $this->options = is_array( $meta['options'] ) ? $meta['options'] : array();
35
+ $this->allow_null = is_bool( $meta['allow_null'] ) ? $meta['allow_null'] : false;
36
  $this->multiple = is_bool( $meta['multiple'] ) ? $meta['multiple'] : false;
37
 
38
  parent::__construct( $name, $label, $value, $meta );
css/attachments.css CHANGED
@@ -293,3 +293,11 @@ a.attachments-invoke {
293
  margin-left: 30px;
294
  display:none;
295
  }
 
 
 
 
 
 
 
 
293
  margin-left: 30px;
294
  display:none;
295
  }
296
+
297
+ .attachment-details .edit-attachment-asset {
298
+ float:left;
299
+ }
300
+
301
+ .attachment-details .delete-attachment {
302
+ float:right;
303
+ }
docs/TOC.md ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ # Attachments
4
+
5
+ Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
6
+
7
+ ## Documentation Table of Contents
8
+
9
+ * [Overview](overview.md)
10
+ * [Installation](installation.md)
11
+ * **[Upgrade Notice](upgrade.md)** *Pay specific attention if upgrading from a version before 3.0*
12
+ * [Usage](usage.md)
13
+ * [Disable Settings Screen](usage.md#disable-settings-screen)
14
+ * [Setting Up Instances](usage.md#setting-up-instances) - Create meta boxes for your Posts, Pages, and Custom Post Types
15
+ * [Disable the Default Instance](usage.md#disable-the-default-instance)
16
+ * [Create Custom Instances](usage.md#create-custom-instances)
17
+ * [Fields Reference](usage.md#fields-reference)
18
+ * [Pulling Attachments to your Theme](usage.md#pulling-attachments-to-your-theme)
19
+ * [Retrieve Attachments Outside The Loop](usage.md#retrieve-attachments-outside-the-loop)
20
+ * [Retrieve Attachment Attributes](usage.md#retrieve-attachment-attributes)
21
+ * [Retrieve Single Attachments](usage.md#retrieve-single-attachments)
22
+ * [Search](usage.md#search)
23
+ * [Hooks](hooks.md)
24
+ * [Filters](hooks.md#filters)
25
+ * [Post Meta Key](hooks.md#post-meta-key) - Change the `meta_key` used to store Attachments' data
26
+ * [Get Attachments](hooks.md#get-attachments) - Edit the order of Attachments in your theme
27
+ * [Fine Tune Instance Location](hooks.md#fine-tune-instance-location) - Real-time control over whether or not to show your Instance
28
+ * [Actions](hooks.md#actions)
29
+ * [Extend Attachments](hooks.md#extend-attachments) - Integrate your own extensions with Attachments
30
+ * [Screenshots](screenshots.md)
31
+ * [Frequently Asked Questions](faq.md)
32
+ * [Changelog](changelog.md)
33
+ * [Roadmap](roadmap.md)
docs/changelog.md ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ ## [Docs TOC](TOC.md) / Changelog
4
+
5
+ <dl>
6
+
7
+ <dt>3.5</dt>
8
+ <dd>Initial implementation of limiting the number of Attachments</dd>
9
+ <dd>You can now change an Attachment asset without having to remove the entire Attachment and re-add something new</dd>
10
+ <dd>New filter: <code>attachments_location_{my_instance}</code> (where <code><strong>{my_instance}</strong></code> is your instance name) allows for more fine-grained control over where meta boxes show up (e.g. limiting to your Home page)</dd>
11
+ <dd>New action: <code>attachments_extension</code> facilitates Attachments extensions</dd>
12
+ <dd>New extension: <a href="http://mondaybynoon.com/members/plugins/attachments-ui/">Attachments UI</a> to create "code-free" Instances in the WordPress admin</dd>
13
+ <dd>New method <code>width( $size )</code> to retrieve the width of the current Attachment</dd>
14
+ <dd>New method <code>height( $size )</code> to retrieve the height of the current Attachment</dd>
15
+ <dd>New document structure, various additions to documentation</dd>
16
+ <dd>Attachments Pro migration script. If you've been waiting to migrate from Attachments Pro please <strong>back up your database</strong> and run the migration script.</dd>
17
+ <dd>Fixed an asset URL issue if Attachments is added as a must-use plugin</dd>
18
+ <dd>Italian translation (props Marco Chiesi)</dd>
19
+
20
+ <dt>3.4.3</dt>
21
+ <dd>Attachments now takes into account media deleted outside Attachments meta boxes and removes deleted attachments automatically</dd>
22
+ <dd>Added working Polish translation, props <a href="https://github.com/mleczakm">@mleczakm</a></dd>
23
+
24
+ <dt>3.4.2.1</dt>
25
+ <dd>Fixed a regression that prevented the <code>type</code> method from returning</dd>
26
+
27
+ <dt>3.4.2</dt>
28
+ <dd>Fixed an issue where the <code>languages</code> directory wouldn't be utilized for l10n</dd>
29
+ <dd>Search now respects custom <code>meta_key</code></dd>
30
+ <dd>You can now pass in a <code>filetype</code> parameter when searching to limit results in that way</dd>
31
+
32
+ <dt>3.4.1</dt>
33
+ <dd>Class abstraction and cleanup</dd>
34
+ <dd>Better support for plugin-created custom image sizes</dd>
35
+
36
+ <dt>3.4</dt>
37
+ <dd>New filter: <code>attachments_meta_key</code> facilitates using a different meta key for Attachments storage</dd>
38
+ <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>
39
+ <dd>Fixed an issue where retrieving single Attachments didn't properly pass the index to attribute methods</dd>
40
+ <dd>Fixed PHP Warnings when Network Activating</dd>
41
+ <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>
42
+
43
+ <dt>3.3.3</dt>
44
+ <dd>Fixed a PHP Warning when activated using Multisite</dd>
45
+ <dd>Slightly modified the migration process to better handle plugins like WPML (props sebastian.friedrich)</dd>
46
+
47
+ <dt>3.3.2</dt>
48
+ <dd>You can now specify which view is default when browsing the Media modal (e.g. have 'Upload Files' be default instead of 'Media Library')</dd>
49
+
50
+ <dt>3.3.1</dt>
51
+ <dd>Added meta box positioning arguments when registering instances</dd>
52
+ <dd>Cleaned up some CSS when Attachments instances are in the sidebar</dd>
53
+
54
+ <dt>3.3</dt>
55
+ <dd>Added a <code>search()</code> method to allow searching for Attachments based on their attributes (e.g. attachment ID, post ID, post type, field values, etc.)</dd>
56
+ <dd>Improved the 'Remove' animation</dd>
57
+ <dd>New field: select</dd>
58
+ <dd>New parameter for Attachments attributes methods. You can pass the index (<code>int</code>) of the Attachment you'd like to utilize when firing the method.</dd>
59
+
60
+ <dt>3.2</dt>
61
+ <dd>Added option to disable the Settings screen</dd>
62
+ <dd>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.</dd>
63
+ <dd>Added a <code>get_single()</code> method that allows you to specifically retrieve a single Attachment</dd>
64
+ <dd>Clarified some documentation</dd>
65
+
66
+ <dt>3.1.4</dt>
67
+ <dd>Changed 'Delete' to 'Remove' so as to not make it sound like the file itself would be deleted from Media (props Lane Goldberg)</dd>
68
+ <dd>Better handling of posts that have no Attachments when saving</dd>
69
+
70
+ <dt>3.1.3</dt>
71
+ <dd>Fixed a potential issue with the WYSIWYG field not working on CPT without editor support</dd>
72
+ <dd>Field assets are less aggressive and only fire when necessary</dd>
73
+ <dd>Reorganized the migration process a bit in prep for Attachments Pro support</dd>
74
+
75
+ <dt>3.1.2</dt>
76
+ <dd>Fixed a regression that prevented successful migration of legacy Attachments data</dd>
77
+
78
+ <dt>3.1.1</dt>
79
+ <dd>Fixed a Fatal Error when registering the text field</dd>
80
+
81
+ <dt>3.1</dt>
82
+ <dd>New field: wysiwyg</dd>
83
+ <dd>Fields will now properly respect line breaks</dd>
84
+ <dd>Fields will now properly return HTML instead of escaped HTML</dd>
85
+
86
+ <dt>3.0.9</dt>
87
+ <dd>Fixed an issue where special characters would break title/caption fields during migration</dd>
88
+
89
+ <dt>3.0.8.2</dt>
90
+ <dd>Fixed a CSS issue with only one text field</dd>
91
+
92
+ <dt>3.0.8.1</dt>
93
+ <dd>Better storage of special characters for PHP 5.4+</dd>
94
+
95
+ <dt>3.0.8</dt>
96
+ <dd>Fixed an issue in Firefox where you weren't able to focus inputs unless you clicked their label</dd>
97
+ <dd>New field: textarea</dd>
98
+
99
+ <dt>3.0.7</dt>
100
+ <dd>Proper sanitization of Custom Post Type names (as WordPress does it)</dd>
101
+
102
+ <dt>3.0.6</dt>
103
+ <dd>Fixed a possible JavaScript error if an Attachment that's an image doesn't have a proper thumbnail URL</dd>
104
+ <dd>Added a <code>total()</code> method that will return the number of Attachments for the current instance</dd>
105
+ <dd>When requesting the </code>image()</code> for a non-image Attachment, the WordPress-defined icon will be returned</dd>
106
+ <dd>Added an <code>icon()</code> method that will return the WordPress-defined icon for the Attachment</dd>
107
+ <dd>Cleaned up a PHP Warning when trying to save for an undefined field type</dd>
108
+ <dd>Fixed an issue where template tags would be output for non-image Attachments after saving</dd>
109
+
110
+ <dt>3.0.5</dt>
111
+ <dd>Fixed a regression in handling Custom Post Type names that would too aggressively interfere with instance regustration</dd>
112
+ <dd>Fixed an issue when working with non-image Attachments</dd>
113
+
114
+ <dt>3.0.4</dt>
115
+ <dd>Fixed an issue that prevented the choosing of a Featured Image for a Custom Post Type if Attachments was activated</dd>
116
+ <dd>Attachments now only enqueues its assets on edit screens that actually utilize Attachments</dd>
117
+ <dd>Fixed a potential JavaScript error triggered when a 'thumbnail' image size was not available</dd>
118
+ <dd>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)</dd>
119
+ <dd>Prevented re-running of migration process to avoid duplicates (e.g. on browser reload)</dd>
120
+
121
+ <dt>3.0.3</dt>
122
+ <dd>Fixed an issue that prevented defining a post ID when retrieving Attachments outside The Loop</dd>
123
+ <dd>Cleaned up potential PHP warning when Attachments were requested for a post that had none</dd>
124
+
125
+ <dt>3.0.2</dt>
126
+ <dd>Fixed an issue where some HTML entities were not properly stored</dd>
127
+
128
+ <dt>3.0.1</dt>
129
+ <dd>Fixed an issue where legacy mode was always enabled</dd>
130
+
131
+ <dt>3.0</dt>
132
+ <dd> <strong>Major</strong> rewrite. After three years of development, Attachments has been rewritten to make
133
+ even better use of what WordPress has to offer</dd>
134
+ <dd> Utilizes the brand spanking new 3.5 Media workflow</dd>
135
+ <dd> Configuration now takes place within your theme or a plugin</dd>
136
+ <dd> Multiple meta boxes! You can segment groups of Attachments with new instances, each unique</dd>
137
+ <dd> Dynamic fields! You can manipulate which fields each instance uses</dd>
138
+ <dd> File type limits. Limit which files are available to Attachments (e.g. images, audio, video)</dd>
139
+
140
+ </dl>
141
+
142
+ -----
143
+
144
+ #### Next: [Roadmap](roadmap.md)
docs/faq.md ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ ## [Docs TOC](TOC.md) / Frequently Asked Questions
4
+
5
+ #### Attachments isn't showing up on my edit screens
6
+
7
+ You will need to tell Attachments which instances you'd like to use. Please reference the **[Usage](#usage)** instructions.
8
+
9
+ #### Attachments are not showing up in my theme
10
+
11
+ You will need to edit your theme files where applicable. Please reference the **[Usage](#usage)** instructions.
12
+
13
+ #### How do I disable the default Attachments meta box?
14
+
15
+ You will need to edit your Attachments configuration. Please reference the **[Usage](#usage)** instructions.
16
+
17
+ #### How do I change the fields for each Attachment?
18
+
19
+ You will need to edit your Attachments configuration. Please reference the **[Usage](#usage)** instructions.
20
+
21
+ #### Where are uploads saved?
22
+
23
+ Attachments uses WordPress' built in Media library for uploads and storage.
24
+
25
+ #### I lost my Attachments after upgrading!
26
+
27
+ ***DO NOT update any Post/Page/CPT with Attachments***, the data has not been lost. Please reference the **[Upgrade notice](#upgrade-notice)**.
28
+
29
+ -----
30
+
31
+ #### Next: [Changelog](changelog.md)
docs/hooks.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ # [Docs TOC](TOC.md) / Hooks
4
+
5
+ ## Filters
6
+
7
+ 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`.
8
+
9
+ ### Post Meta Key
10
+
11
+ 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:
12
+
13
+ ```php
14
+ function my_attachments_meta_key()
15
+ {
16
+ return '_my_attachments_meta_key';
17
+ }
18
+
19
+ add_filter( 'attachments_meta_key', 'my_attachments_meta_key' );
20
+ ```
21
+
22
+ 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).
23
+
24
+ ### Get Attachments
25
+
26
+ 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:
27
+
28
+ ```php
29
+ function my_attachments_randomize( $attachments )
30
+ {
31
+ return shuffle( $attachments );
32
+ }
33
+
34
+ add_filter( 'attachments_get_my_attachments', 'my_attachments_randomize' );
35
+ ```
36
+
37
+ **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:
38
+
39
+ ```php
40
+ function my_attachments_reverse( $attachments )
41
+ {
42
+ return array_reverse( $attachments );
43
+ }
44
+
45
+ add_filter( 'attachments_get_foo_bar', 'my_attachments_reverse' );
46
+ ```
47
+
48
+ Please keep in mind the instance name requirement when setting up this filter.
49
+
50
+ ### Fine Tune Instance Location
51
+
52
+ Many times simply defining a post type for your Instance is too broad of a rule. You'll often want to limit your Attachments Instance to a single page or user role. The attachments_location_{my_instance} facilitates just that.
53
+
54
+ ```php
55
+ function my_attachments_location_limit( $val )
56
+ {
57
+ global $post;
58
+
59
+ // our home page ID is 10 and we only want this instance to show up there
60
+ return ( $post->ID == 10 ) ? true : false;
61
+ }
62
+
63
+ add_filter( 'attachments_location_my_attachments', 'my_attachments_location_limit' );
64
+ ```
65
+
66
+ You can have your callback be as elaborate as you'd like, using any attributes WordPress has to offer at runtime.
67
+
68
+ ## Actions
69
+
70
+ Actions allow you to integrate with the internals of Attachments without effecting the codebase itself.
71
+
72
+ ### Extend Attachments
73
+
74
+ Attachments will load any extensible code you've written to enhance what you're aiming to do with the `attachments_extension` action.
75
+
76
+ ```php
77
+ function init_my_attachments_extension( $attachments )
78
+ {
79
+ // do your thing
80
+ }
81
+
82
+ add_action( 'attachments_extension', 'init_my_attachments_extension', 10, 1 );
83
+ ```
84
+
85
+ -----
86
+
87
+ #### Next: [Screenshots](screenshots.md)
docs/installation.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ ## [Docs TOC](TOC.md) / Installation
4
+
5
+ 1. Download the plugin and extract the files
6
+ 1. Upload `attachments` to your `~/wp-content/plugins/` directory
7
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
8
+ 1. Implement Attachments in your theme's `functions.php` or your own plugin (see **[Usage](#usage)**)
9
+ 1. Update your templates where applicable (see **[Usage](#usage)**)
10
+
11
+ -----
12
+
13
+ #### Next: [Upgrade Notice](upgrade.md)
docs/overview.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ ## [Docs TOC](TOC.md) / Attachments Overview
4
+
5
+ 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.
6
+
7
+ ### Updated for WordPress 3.5!
8
+
9
+ WordPress 3.5 ships with an amazing new Media workflow and Attachments 3.0 makes great use of it. *If you are not running WordPress 3.5, the (now deprecated) version 1.6.2.1 (included with Attachments 3.x) will be used until you upgrade to WordPress 3.5+*
10
+
11
+ ### Associate Media items with posts
12
+
13
+ The idea behind Attachments is to give developers the ability to directly associate Media items with any post. This is accomplished by adding a meta box to post edit screens as determined by the developer. Once Media items have been associated with a post, you're able to retrieve those Attachments and include them directly within your template files using any specific markup you wish.
14
+
15
+ ### Integrate Attachments within your theme with fine grained control
16
+
17
+ **Attachments does not automatically integrate itself with your theme.** Since the idea behind Attachments is to allow integration of Media within posts using developer-crafted, unique markup, *it's up to you to integrate with your theme*. The most basic integration includes editing the [appropriate template file](http://codex.wordpress.org/Template_Hierarchy) and adding your call(s) to Attachments. For example, if you have set up Attachments to be used with your Posts entries, edit `single.php` to include the following within The Loop:
18
+
19
+ ```php
20
+ <?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
21
+ <?php if( $attachments->exist() ) : ?>
22
+ <h3>Attachments</h3>
23
+ <ul>
24
+ <?php while( $attachments->get() ) : ?>
25
+ <li>
26
+ ID: <?php echo $attachments->id(); ?><br />
27
+ Type: <?php echo $attachments->type(); ?><br />
28
+ Subtype: <?php echo $attachments->subtype(); ?><br />
29
+ URL: <?php echo $attachments->url(); ?><br />
30
+ Image: <?php echo $attachments->image( 'thumbnail' ); ?><br />
31
+ Source: <?php echo $attachments->src( 'full' ); ?><br />
32
+ Size: <?php echo $attachments->filesize(); ?><br />
33
+ Title Field: <?php echo $attachments->field( 'title' ); ?><br />
34
+ Caption Field: <?php echo $attachments->field( 'caption' ); ?>
35
+ </li>
36
+ <?php endwhile; ?>
37
+ </ul>
38
+ <?php endif; ?>
39
+ ```
40
+
41
+ That snippet will request all of the existing Attachments defined for the current Post within The Loop, and retrieve each itemized property for that Attachment. Using the provided details you're able to integrate the attached Media items in any way you please.
42
+
43
+ -----
44
+
45
+ #### Next: [Installation](installation.md)
docs/roadmap.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ ## [Docs TOC](TOC.md) / Roadmap
4
+
5
+ Planned feature additions include:
6
+
7
+ * Additional field type: checkbox
8
+ * Additional field type: radio
9
+ * User-defined custom field types
docs/screenshots.md ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ ## [Docs TOC](TOC.md) / Screenshots
4
+
5
+ ##### An Attachments meta box sitting below the content editor
6
+ ![An Attachments meta box sitting below the content editor](http://mondaybynoon.com/images/attachments/screenshot-1.png)
7
+
8
+ ##### Direct integration with WordPress 3.5+ Media
9
+ ![Direct integration with WordPress 3.5+ Media](http://mondaybynoon.com/images/attachments/screenshot-2.png)
10
+
11
+ ##### Attach multiple files at once
12
+ ![Attach multiple files at once](http://mondaybynoon.com/images/attachments/screenshot-3.png)
13
+
14
+ ##### Custom fields for each Attachment
15
+ ![Custom fields for each Attachment](http://mondaybynoon.com/images/attachments/screenshot-4.png)
16
+
17
+ ##### Drag and drop to sort
18
+ ![Drag and drop to sort](http://mondaybynoon.com/images/attachments/screenshot-5.png)
19
+
20
+ -----
21
+
22
+ #### Next: [Frequently Asked Questions](faq.md)
docs/upgrade.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ ## [Docs TOC](TOC.md) / Upgrade Notice
4
+
5
+ #### 3.0
6
+ **You will need to update your theme files that use Attachments 3.0**. Version 1.x of Attachments has been **fully deprecated** but is still available *and included with Attachments 3.x*. If you would like to continue to use the (no longer supported) 1.x version you may add the following to your `wp-config.php`:
7
+
8
+ ```php
9
+ define( 'ATTACHMENTS_LEGACY', true ); // force the legacy version of Attachments
10
+ ```
11
+
12
+ Version 3 is a **major** rewrite. While I've taken precautions in ensuring you won't lose any saved data it is important to back up your databse prior to upgrading in case something goes wrong. This version is a complete rewrite so all legacy data will be left in place, but a migration must take place to match the new data storage model and workflow.
13
+
14
+ -----
15
+
16
+ #### Next: [Usage](usage.md)
docs/usage.md ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/).
2
+
3
+ ## [Docs TOC](TOC.md) / Usage
4
+
5
+ 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).
6
+
7
+ ### Disable Settings Screen
8
+
9
+ 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`:
10
+
11
+ ```php
12
+ define( 'ATTACHMENTS_SETTINGS_SCREEN', false ); // disable the Settings screen
13
+ ```
14
+
15
+ ### Setting Up Instances
16
+
17
+ When Attachments is first activated, a default instance is created titled Attachments. It has two fields:
18
+
19
+ 1. Title
20
+ 1. Caption
21
+
22
+ #### Disable the Default Instance
23
+
24
+ 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` *before* `require_once(ABSPATH . 'wp-settings.php');`:
25
+
26
+ ```php
27
+ define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );
28
+ ```
29
+
30
+ #### Create Custom Instances
31
+
32
+ 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:
33
+
34
+ ```php
35
+ <?php
36
+
37
+ function my_attachments( $attachments )
38
+ {
39
+ $fields = array(
40
+ array(
41
+ 'name' => 'title', // unique field name
42
+ 'type' => 'text', // registered field type
43
+ 'label' => __( 'Title', 'attachments' ), // label to display
44
+ 'default' => 'title', // default value upon selection
45
+ ),
46
+ array(
47
+ 'name' => 'caption', // unique field name
48
+ 'type' => 'textarea', // registered field type
49
+ 'label' => __( 'Caption', 'attachments' ), // label to display
50
+ 'default' => 'caption', // default value upon selection
51
+ ),
52
+ );
53
+
54
+ $args = array(
55
+
56
+ // title of the meta box (string)
57
+ 'label' => 'My Attachments',
58
+
59
+ // all post types to utilize (string|array)
60
+ 'post_type' => array( 'post', 'page' ),
61
+
62
+ // meta box position (string) (normal, side or advanced)
63
+ 'position' => 'normal',
64
+
65
+ // meta box priority (string) (high, default, low, core)
66
+ 'priority' => 'high',
67
+
68
+ // allowed file type(s) (array) (image|video|text|audio|application)
69
+ 'filetype' => null, // no filetype limit
70
+
71
+ // include a note within the meta box (string)
72
+ 'note' => 'Attach files here!',
73
+
74
+ // by default new Attachments will be appended to the list
75
+ // but you can have then prepend if you set this to false
76
+ 'append' => true,
77
+
78
+ // text for 'Attach' button in meta box (string)
79
+ 'button_text' => __( 'Attach Files', 'attachments' ),
80
+
81
+ // text for modal 'Attach' button (string)
82
+ 'modal_text' => __( 'Attach', 'attachments' ),
83
+
84
+ // which tab should be the default in the modal (string) (browse|upload)
85
+ 'router' => 'browse',
86
+
87
+ // fields array
88
+ 'fields' => $fields,
89
+
90
+ );
91
+
92
+ $attachments->register( 'my_attachments', $args ); // unique instance name
93
+ }
94
+
95
+ add_action( 'attachments_register', 'my_attachments' );
96
+ ```
97
+
98
+ #### Fields Reference
99
+
100
+ At this time there are **four** field types available:
101
+
102
+ 1. `text`
103
+ 1. `textarea`
104
+ 1. `select`
105
+ 1. `wysiwyg`
106
+
107
+ 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:
108
+
109
+ ```php
110
+ /**
111
+ * Fields for the instance are stored in an array. Each field consists of
112
+ * an array with three required keys: name, type, label
113
+ * and one optional key: meta
114
+ *
115
+ * name - (string) The field name used. No special characters.
116
+ * type - (string) The registered field type.
117
+ * Fields available: text, textarea, wysiwyg, select
118
+ * label - (string) The label displayed for the field.
119
+ * default - (string) The default WordPress metadata to use when initially adding the Attachment
120
+ * Defaults available: title, caption, alt, description
121
+ * meta - (array) The field-specific parameters that apply only to that field type
122
+ */
123
+
124
+ $fields = array(
125
+ array(
126
+ 'name' => 'title', // unique field name
127
+ 'type' => 'text', // registered field type
128
+ 'label' => __( 'Title', 'attachments' ), // label to display
129
+ 'default' => 'title', // default value upon selection
130
+ ),
131
+ array(
132
+ 'name' => 'caption', // unique field name
133
+ 'type' => 'textarea', // registered field type
134
+ 'label' => __( 'Caption', 'attachments' ), // label to display
135
+ 'default' => 'caption', // default value upon selection
136
+ ),
137
+ array(
138
+ 'name' => 'option', // unique field name
139
+ 'type' => 'select', // registered field type
140
+ 'label' => __( 'Option', 'attachments' ), // label to display
141
+ 'meta' => array( // field-specific meta as defined by field class
142
+ 'allow_null' => true, // allow null value? (adds 'empty' <option>)
143
+ 'multiple' => true, // multiple <select>?
144
+ 'options' => array( // the <option>s to use
145
+ '1' => 'Option 1',
146
+ '2' => 'Option 2',
147
+ )
148
+ ),
149
+ ),
150
+ array(
151
+ 'name' => 'description', // unique field name
152
+ 'type' => 'wysiwyg', // registered field type
153
+ 'label' => __( 'Description', 'attachments' ), // label to display
154
+ 'default' => 'description', // default value upon selection
155
+ ),
156
+ );
157
+ ```
158
+
159
+ ### Pulling Attachments to your Theme
160
+
161
+ 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:
162
+
163
+ ```php
164
+ <?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
165
+ <?php if( $attachments->exist() ) : ?>
166
+ <h3>Attachments</h3>
167
+ <ul>
168
+ <?php while( $attachment = $attachments->get() ) : ?>
169
+ <li>
170
+ <pre><?php print_r( $attachment ); ?></pre>
171
+ </li>
172
+ <?php endwhile; ?>
173
+ </ul>
174
+ <?php endif; ?>
175
+ ```
176
+
177
+ #### Retrieve Attachments Outside The Loop
178
+
179
+ If you want to get the Attachments for a post **outside The Loop**, add a second parameter with the post ID when instantiating Attachments:
180
+
181
+ ```php
182
+ <?php
183
+ // retrieve all Attachments for the 'attachments' instance of post 123
184
+ $attachments = new Attachments( 'attachments', 123 );
185
+ ?>
186
+ <?php if( $attachments->exist() ) : ?>
187
+ <h3>Attachments</h3>
188
+ <ul>
189
+ <?php while( $attachment = $attachments->get() ) : ?>
190
+ <li>
191
+ <pre><?php print_r( $attachment ); ?></pre>
192
+ </li>
193
+ <?php endwhile; ?>
194
+ </ul>
195
+ <?php endif; ?>
196
+ ```
197
+
198
+ #### Retrieve Attachment Attributes
199
+
200
+ You can also retrieve various attributes of the current Attachment directly using these utility functions:
201
+
202
+ ```php
203
+ <?php $attachments = new Attachments( 'attachments' ); ?>
204
+ <?php if( $attachments->exist() ) : ?>
205
+ <h3>Attachments</h3>
206
+ <p>Total Attachments: <?php echo $attachments->total(); ?></p>
207
+ <ul>
208
+ <?php while( $attachments->get() ) : ?>
209
+ <li>
210
+ ID: <?php echo $attachments->id(); ?><br />
211
+ Type: <?php echo $attachments->type(); ?><br />
212
+ Subtype: <?php echo $attachments->subtype(); ?><br />
213
+ URL: <?php echo $attachments->url(); ?><br />
214
+ Image: <?php echo $attachments->image( 'thumbnail' ); ?><br />
215
+ Source: <?php echo $attachments->src( 'full' ); ?><br />
216
+ Size: <?php echo $attachments->filesize(); ?><br />
217
+ Title Field: <?php echo $attachments->field( 'title' ); ?><br />
218
+ Caption Field: <?php echo $attachments->field( 'caption' ); ?>
219
+ </li>
220
+ <?php endwhile; ?>
221
+ </ul>
222
+ <?php endif; ?>
223
+ ```
224
+
225
+ #### Retrieve Single Attachments
226
+
227
+ If you don't want to use the above implementation to loop through your Attachments, can also retrieve them explicitly:
228
+
229
+ ```php
230
+ <?php $attachments = new Attachments( 'attachments' ); ?>
231
+ <?php if( $attachments->exist() ) : ?>
232
+ <?php $my_index = 0; ?>
233
+ <?php if( $attachment = $attachments->get_single( $my_index ) ) : ?>
234
+ <h3>Attachment at index 0:</h3>
235
+ <pre><?php print_r( $attachment ); ?></pre>
236
+ <ul>
237
+ <li>
238
+ ID: <?php echo $attachments->id( $my_index ); ?><br />
239
+ Type: <?php echo $attachments->type( $my_index ); ?><br />
240
+ Subtype: <?php echo $attachments->subtype( $my_index ); ?><br />
241
+ URL: <?php echo $attachments->url( $my_index ); ?><br />
242
+ Image: <?php echo $attachments->image( 'thumbnail', $my_index ); ?><br />
243
+ Source: <?php echo $attachments->src( 'full', $my_index ); ?><br />
244
+ Size: <?php echo $attachments->filesize( $my_index ); ?><br />
245
+ Title Field: <?php echo $attachments->field( 'title', $my_index ); ?><br />
246
+ Caption Field: <?php echo $attachments->field( 'caption', $my_index ); ?>
247
+ </li>
248
+ </ul>
249
+ <?php endif; ?>
250
+ <?php endif; ?>
251
+ ```
252
+
253
+ ### Search
254
+
255
+ 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.
256
+
257
+ ```php
258
+ <?php
259
+ $attachments = new Attachments();
260
+
261
+ $search_args = array(
262
+ 'instance' => 'attachments', // search 'attachments' instance
263
+ 'fields' => array( 'caption' ), // search the 'caption' field only
264
+ );
265
+
266
+ $attachments->search( 'lorem ipsum', $search_args ); // search for 'lorem ipsum'
267
+
268
+ if( $attachments->exist() ) : ?>
269
+ <h3>Attachments</h3>
270
+ <ul>
271
+ <?php while( $attachments->get() ) : ?>
272
+ <li>
273
+ Attachment ID: <?php echo $attachments->id(); ?><br />
274
+ Post ID: <?php echo $attachments->post_id(); ?><br />
275
+ Title Field: <?php echo $attachments->field( 'title' ); ?><br />
276
+ Caption Field: <?php echo $attachments->field( 'caption' ); ?>
277
+ </li>
278
+ <?php endwhile; ?>
279
+ </ul>
280
+ <?php endif;
281
+ ?>
282
+ ```
283
+
284
+ The full list of available search arguments (and their defaults) is as follows:
285
+
286
+ ```php
287
+ $defaults = array(
288
+ 'attachment_id' => null, // (int) not searching for a single attachment ID
289
+ 'instance' => 'attachments', // (string) the instance you want to search
290
+ 'post_type' => null, // (string) search 'any' post type
291
+ 'post_id' => null, // (int) searching all posts
292
+ 'post_status' => 'publish', // (string) search only published posts
293
+ 'fields' => null, // (string|array) search all Attachment fields
294
+ 'filetype' => null, // (string|array) search all Attachment filetypes
295
+ );
296
+ ```
297
+
298
+ Once you've performed your search, you can loop through the returned Attachments as you normally would.
299
+
300
+ -----
301
+
302
+ #### Next: [Hooks](hooks.md)
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.4.2.1
10
  * Text Domain: attachments
11
  * Domain Path: /languages/
12
  * License: GPLv2 or later
@@ -39,7 +39,7 @@ else
39
  else
40
  {
41
  define( 'ATTACHMENTS_DIR', plugin_dir_path( __FILE__ ) );
42
- define( 'ATTACHMENTS_URL', plugins_url( 'attachments' ) );
43
 
44
  // load current version of Attachments
45
  require_once 'classes/class.attachments.php';
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.5
10
  * Text Domain: attachments
11
  * Domain Path: /languages/
12
  * License: GPLv2 or later
39
  else
40
  {
41
  define( 'ATTACHMENTS_DIR', plugin_dir_path( __FILE__ ) );
42
+ define( 'ATTACHMENTS_URL', plugin_dir_url( __FILE__ ) );
43
 
44
  // load current version of Attachments
45
  require_once 'classes/class.attachments.php';
languages/attachments-it_IT.mo ADDED
Binary file
languages/attachments-it_IT.po ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Attachments v3.4\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2013-05-09 18:09+0100\n"
6
+ "PO-Revision-Date: 2013-05-09 18:58+0100\n"
7
+ "Last-Translator: Marco <marco@blackstudio.it>\n"
8
+ "Language-Team: Black Studio <info@blackstudio.it>\n"
9
+ "Language: it_IT\n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e;_ngettext:1,2\n"
14
+ "X-Poedit-Basepath: ../\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
+ "X-Generator: Poedit 1.5.5\n"
18
+ "X-Poedit-SearchPath-0: .\n"
19
+
20
+ #: index.php:30
21
+ msgid ""
22
+ "Attachments requires PHP 5.2+. Attachments has been automatically "
23
+ "deactivated."
24
+ msgstr ""
25
+ "Attachments richiede PHP 5.2 o una versione successiva. Il plugin è stato "
26
+ "automaticamente disattivato."
27
+
28
+ #: classes/class.attachments.legacy.php:112
29
+ msgid ""
30
+ "<strong>Attachments has detected legacy Attachments data.</strong> A lot has "
31
+ "changed since Attachments 1.x."
32
+ msgstr ""
33
+ "<strong>Attachments ha rilevato la presenza di dati di una versione "
34
+ "precedente.</strong> Molte cose sono cambiate rispetto ad Attachments 1.x."
35
+
36
+ #: classes/class.attachments.legacy.php:112
37
+ msgid "Find out more"
38
+ msgstr "Maggiori informazioni"
39
+
40
+ #: classes/class.attachments.migrate.php:162
41
+ #: classes/class.attachments.migrate.php:218 views/options.php:13
42
+ msgid "Invalid request"
43
+ msgstr "Richiesta non valida"
44
+
45
+ #: classes/class.attachments.migrate.php:164
46
+ msgid "Migration Step 1"
47
+ msgstr "Migrazione - Passo 1"
48
+
49
+ #: classes/class.attachments.migrate.php:165
50
+ msgid ""
51
+ "In order to migrate Attachments 1.x data, you need to set which instance and "
52
+ "fields in version 3.0+ you'd like to use:"
53
+ msgstr ""
54
+ "Per migrare i dati di Attachments 1.x, devi impostare quale istanza e quali "
55
+ "campi della versione 3.0+ vorresti utilizzare:"
56
+
57
+ #: classes/class.attachments.migrate.php:174
58
+ msgid "Attachments 3.x Instance"
59
+ msgstr "Istanza di Attachments 3.x"
60
+
61
+ #: classes/class.attachments.migrate.php:178
62
+ msgid "The instance name you would like to use in the migration. Required."
63
+ msgstr ""
64
+ "Il nome dell'istanza che vorresti utilizzare nella migrazione. Necessario."
65
+
66
+ #: classes/class.attachments.migrate.php:183
67
+ msgid "Attachments 3.x Title"
68
+ msgstr "Titolo Attachments 3.x"
69
+
70
+ #: classes/class.attachments.migrate.php:187
71
+ msgid ""
72
+ "The <code>Title</code> field data will be migrated to this field name in "
73
+ "Attachments 3.x. Leave empty to disregard."
74
+ msgstr ""
75
+ "Il campo <code>Titolo</code> sarà migrato a questo campo in Attachments 3.x. "
76
+ "Lasciare vuoto per ignorare."
77
+
78
+ #: classes/class.attachments.migrate.php:192
79
+ msgid "Attachments 3.x Caption"
80
+ msgstr "Didascalia Attachments 3.x"
81
+
82
+ #: classes/class.attachments.migrate.php:196
83
+ msgid ""
84
+ "The <code>Caption</code> field data will be migrated to this field name in "
85
+ "Attachments 3.x. Leave empty to disregard."
86
+ msgstr ""
87
+ "Il campo <code>Didascalia</code> sarà migrato a questo campo in Attachments "
88
+ "3.x. Lasciare vuoto per ignorare."
89
+
90
+ #: classes/class.attachments.migrate.php:224
91
+ msgid "Migration Complete!"
92
+ msgstr "Migrazione completata!"
93
+
94
+ #: classes/class.attachments.migrate.php:225
95
+ msgid "The migration has completed."
96
+ msgstr "La migrazione è stata completata."
97
+
98
+ #: classes/class.attachments.migrate.php:225
99
+ msgid "Migrated"
100
+ msgstr "Migrato"
101
+
102
+ #: classes/class.attachments.migrate.php:227
103
+ msgid "Migration has already Run!"
104
+ msgstr "La migrazione è già stata eseguita!"
105
+
106
+ #: classes/class.attachments.migrate.php:228
107
+ msgid ""
108
+ "The migration has already been run. The migration process has not been "
109
+ "repeated."
110
+ msgstr "La migrazione è già stata eseguita. Il processo non è stato ripetuto."
111
+
112
+ #: classes/class.attachments.php:769 classes/class.attachments.php:843
113
+ #: deprecated/attachments.php:365
114
+ msgid "Title"
115
+ msgstr "Titolo"
116
+
117
+ #: classes/class.attachments.php:805 classes/class.attachments.php:1524
118
+ #: deprecated/attachments.php:417 views/options.php:24
119
+ msgid "Attachments"
120
+ msgstr "Attachments"
121
+
122
+ #: classes/class.attachments.php:830 classes/class.attachments.php:833
123
+ #: deprecated/attachments.php:312
124
+ msgid "Attach"
125
+ msgstr "Allega"
126
+
127
+ #: classes/class.attachments.php:849 deprecated/attachments.php:369
128
+ msgid "Caption"
129
+ msgstr "Didascalia"
130
+
131
+ #: classes/class.attachments.php:1100
132
+ msgid "Remove"
133
+ msgstr "Rimuovi"
134
+
135
+ #: classes/class.attachments.php:1101
136
+ msgid "Toggle Fields"
137
+ msgstr "Alterna campi"
138
+
139
+ #: deprecated/attachments.php:51
140
+ msgid ""
141
+ "Attachments requires PHP 5.2 or higher, as does WordPress 3.2+. Attachments "
142
+ "has been automatically deactivated."
143
+ msgstr ""
144
+ "Attachments richiede PHP 5.2 o superiore, così come WordPress 3.2+. "
145
+ "Attachments è stato automaticamente disattivato."
146
+
147
+ #: deprecated/attachments.php:361
148
+ msgid "Delete"
149
+ msgstr "Elimina"
150
+
151
+ #: views/options.php:29
152
+ msgid ""
153
+ "<strong>Attachments has changed significantly since it's last update.</"
154
+ "strong> These changes <em>will affect your themes and plugins</em>."
155
+ msgstr ""
156
+ "<strong>Attachments è cambiato significativamente dall'ultimo aggiornamento."
157
+ "</strong> Queste modifiche <em>avranno effetto sui tuoi temi e plugin</em>."
158
+
159
+ #: views/options.php:32
160
+ msgid "Immediate Reversal to Attachments 1.x"
161
+ msgstr "Torna subito ad Attachments 1.x"
162
+
163
+ #: views/options.php:34
164
+ msgid ""
165
+ "If you would like to immediately <em>revert to the old version of "
166
+ "Attachments</em> you may do so by downgrading the plugin install itself, or "
167
+ "adding the following to your"
168
+ msgstr ""
169
+ "Se vuoi <em>ripristinare la vecchia versione di Attachments</em> lo puoi "
170
+ "fare reinstallando la versione precedente, oppure aggiungendo il seguente "
171
+ "codice al tuo"
172
+
173
+ #: views/options.php:38
174
+ msgid "Overview of changes from Attachments 1.x"
175
+ msgstr "Panoramica delle modifiche rispetto ad Attachments 1.x"
176
+
177
+ #: views/options.php:40
178
+ msgid ""
179
+ "A lot has changed since Attachments 1.x. The entire codebase was rewritten "
180
+ "to not only make better use of the stellar Media updates in WordPress 3.5, "
181
+ "but to also facilitate some exciting features coming down the line. With "
182
+ "this rewrite came significant changes to the way you will work with "
183
+ "Attachments. One of the biggest changes in Attachments 3.0 is the ability to "
184
+ "create multiple meta boxes of Attachments, each with any number of custom "
185
+ "fields you define. By default, Attachments will re-implement the meta box "
186
+ "you've been using until now, but <strong>you will need to trigger a "
187
+ "migration to the new format</strong>."
188
+ msgstr ""
189
+ "Molte cose sono cambiate rispetto ad Attachments 1.x. Tutto il codice è "
190
+ "stato riscritto non solo per fare un uso migliore degli aggiornamenti della "
191
+ "Libreria Media di Wordpress 3.5, ma anche per facilitare l'aggiunta di nuove "
192
+ "funzionalità. Come conseguenza di questo ci sono significativi cambiamenti "
193
+ "al modo con cui operare con Attachments. Una delle modifiche principali in "
194
+ "Attachments 3.0 è la possibilità di creare istanze multiple di allegati, "
195
+ "ognuna con un numero indefinito di campi personalizzati che si possono "
196
+ "definire. Come impostazione predefinita, Attachments reimplementerà "
197
+ "l'istanza che hai utilizzato fino ad ora, ma <strong>dovrai effettuare una "
198
+ "migrazione al nuovo formato</strong>."
199
+
200
+ #: views/options.php:42
201
+ msgid "Migrating Attachments 1.x data to Attachments 3.x"
202
+ msgstr "Migrazione da Attachments 1.x ad Attachments 3.x"
203
+
204
+ #: views/options.php:44
205
+ msgid ""
206
+ "If you have existing Attachments 1.x data and are using it, a migration "
207
+ "script has been bundled here and you can use it below. If you would like to "
208
+ "directly migrate from Attachments 1.x to Attachments 3.x you can use the "
209
+ "defaults put in place and your data will be migrated to the new format "
210
+ "quickly and easily. Alternatively, if you'd like to customize the fields "
211
+ "you're using a bit, you can do that first and then adjust the migration "
212
+ "parameters to map the old fields to your new ones."
213
+ msgstr ""
214
+ "Se hai dei dati esistenti di Attachments 1.x e li stai utilizzando, è "
215
+ "disponibile uno script di migrazione che puoi utilizzare qui sotto. Se vuoi "
216
+ "migrare direttamente da Attachments 1.x ad Attachments 3.x puoi utilizzare "
217
+ "le impostazioni predefinite ed i tuoi dati saranno migrati al nuovo formato "
218
+ "in modo semplice e rapido. In alternativa, se vuoi personalizzare i campi in "
219
+ "uso, lo puoi fare preventivamente ed in seguito impostare i parametri di "
220
+ "migrazione per la corrispondenza tra i vecchi campi e quelli nuovi."
221
+
222
+ #: views/options.php:46
223
+ msgid "Setting up Instances"
224
+ msgstr "Impostazione istanze"
225
+
226
+ #: views/options.php:48
227
+ msgid ""
228
+ "Attachments 3.0 ships with what are called <em>instances</em>. An instance "
229
+ "is equivalent to a meta box on an edit screen and it has a number of "
230
+ "properties you can customize. Please read the README for more information."
231
+ msgstr ""
232
+ "Attachments 3.0 supporta le cosiddette <em>istanze</em>. Una istanza è "
233
+ "l'equivalente di un riquadro (meta box) nella schermata di modifica ed ha "
234
+ "delle caratteristiche personalizzabili. Leggere il file README per maggiori "
235
+ "informazioni."
236
+
237
+ #: views/options.php:48 views/options.php:52
238
+ msgid "Additinoal instructions"
239
+ msgstr "Istruzioni addizionali"
240
+
241
+ #: views/options.php:50
242
+ msgid "Retrieving Attachments in your theme"
243
+ msgstr "Visualizzare gli allegati nel tuo tema"
244
+
245
+ #: views/options.php:52
246
+ msgid ""
247
+ "As always has been the case with Attachments, editing your theme files is "
248
+ "required. The syntax to do so has changed in Attachments 3.0. Please read the"
249
+ msgstr ""
250
+ "Così com'è sempre stato con Attachments, è necessario modificare i file del "
251
+ "tuo tema. La sintassi per fare ciò è cambiata in Attachments 3.0. Leggi il"
252
+
253
+ #: views/options.php:85
254
+ msgid "Migrate legacy Attachments data"
255
+ msgstr "Migrazione dati versione precedente di Attachments"
256
+
257
+ #: views/options.php:86
258
+ msgid ""
259
+ "Attachments has found records from version 1.x. Would you like to migrate "
260
+ "them to version 3?"
261
+ msgstr ""
262
+ "Attachments ha rilevato dei dati della versione 1.x. Vuoi effettuare la "
263
+ "migrazione di questi alla versione 3?"
264
+
265
+ #: views/options.php:87
266
+ msgid "Migrate legacy data"
267
+ msgstr "Migra dati precedenti"
268
+
269
+ #: views/options.php:89
270
+ msgid "You have already migrated your legacy Attachments data."
271
+ msgstr "Hai già migrato i tuoi dati precedenti di Attachments."
272
+
273
+ #: views/options.php:92
274
+ msgid "Revert to version 1.x"
275
+ msgstr "Ritorna alla versione 1.x"
276
+
277
+ #: views/options.php:93
278
+ msgid ""
279
+ "If you would like to forcefully revert to the 1.x version branch of "
280
+ "Attachments, add the following to your"
281
+ msgstr ""
282
+ "Se vuoi forzare l'utilizzo della versione 1.x di Attachments, aggiungi il "
283
+ "seguente codice al tuo"
284
+
285
+ #: views/options.php:95
286
+ msgid "Meta box customization"
287
+ msgstr "Personalizzazione meta box"
288
+
289
+ #: views/options.php:96
290
+ msgid ""
291
+ "By default, Attachments implements a single meta box on Posts and Pages with "
292
+ "two fields. You can disable this default instance by adding the following to "
293
+ "your"
294
+ msgstr ""
295
+ "Come impostazione predefinita, Attachments implementa un singolo meta box "
296
+ "negli Articoli e nella Pagine con due campi. Puoi disabilitare questa "
297
+ "istanza di default aggiungendo il seguente codice al tuo"
298
+
299
+ #: views/options.php:98
300
+ msgid ""
301
+ "Your Attachments meta box(es) can be customized by adding the following to "
302
+ "your theme's"
303
+ msgstr ""
304
+ "Il tuo meta box può essere personalizzato aggiungendo il seguente codice al "
305
+ "tuo"
306
+
307
+ #: views/options.php:100
308
+ msgid "Using Attachments data in your theme"
309
+ msgstr "Visualizzare i dati degli allegati nel tuo tema"
310
+
311
+ #: views/options.php:101
312
+ msgid ""
313
+ "Attachments does not directly integrate with your theme out of the box, you "
314
+ "will need to edit your theme's template files where appropriate. You can add "
315
+ "the following within The Loop to retrieve all Attachments data for the "
316
+ "current post:"
317
+ msgstr ""
318
+ "Attachments non si integra direttamente con il tuo tema, ma dovrai "
319
+ "modificare i file dei template del tuo tema in modo appropriato. Puoi "
320
+ "aggiungere il seguente codice all'interno del \"Loop\" per recuperare i dati "
321
+ "degli allegati per il post corrente."
languages/attachments-pl_PL.mo ADDED
Binary file
languages/attachments-pl_PL.po ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: attachments-0.1\n"
4
+ "POT-Creation-Date: 2013-04-10 01:55+0100\n"
5
+ "PO-Revision-Date: 2013-04-10 01:55+0100\n"
6
+ "Last-Translator: Michał Mleczko <mleczakm91@gmail.com>\n"
7
+ "Language-Team: Michał Mleczko <mleczakm91@gmail.com>\n"
8
+ "Language: Polish\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.5.5\n"
13
+ "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e;_n:1,2;_n_noop:1,2;"
14
+ "_nx:1,2;_nx_noop:1,2\n"
15
+ "X-Poedit-Basepath: .\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-SearchPath-0: ..\n"
18
+ "X-Poedit-SearchPath-1: ../views\n"
19
+ "X-Poedit-SearchPath-2: ../classes\n"
20
+ "X-Poedit-SearchPath-3: ../classes/fields\n"
21
+ "X-Poedit-SearchPath-4: ..\n"
22
+
23
+ #: ../index.php:30
24
+ msgid ""
25
+ "Attachments requires PHP 5.2+. Attachments has been automatically "
26
+ "deactivated."
27
+ msgstr ""
28
+ "Wtyczka Załączniki została automatycznie zablokowana, ponieważ wymaga PHP w "
29
+ "wersji 5.2 lub wyższej. "
30
+
31
+ #: ../classes/class.attachments.legacy.php:112
32
+ msgid ""
33
+ "<strong>Attachments has detected legacy Attachments data.</strong> A lot has "
34
+ "changed since Attachments 1.x."
35
+ msgstr ""
36
+ "<strong>Wtyczka wykryła przestarzały typ danych.</strong> Wiele się zmieniło "
37
+ "od wersji 1.x."
38
+
39
+ #: ../classes/class.attachments.legacy.php:112
40
+ msgid "Find out more"
41
+ msgstr "Zobacz więcej"
42
+
43
+ #: ../classes/class.attachments.migrate.php:162
44
+ #: ../classes/class.attachments.migrate.php:218 ../views/options.php:13
45
+ msgid "Invalid request"
46
+ msgstr "Nieprawidłowe zapytanie."
47
+
48
+ #: ../classes/class.attachments.migrate.php:164
49
+ msgid "Migration Step 1"
50
+ msgstr "Migracja - krok 1"
51
+
52
+ #: ../classes/class.attachments.migrate.php:165
53
+ msgid ""
54
+ "In order to migrate Attachments 1.x data, you need to set which instance and "
55
+ "fields in version 3.0+ you'd like to use:"
56
+ msgstr ""
57
+ "Aby migrować dane z wersji1.x wtyczki, potrzebujesz ustalić której instancji "
58
+ "Załączników użyć oraz jakie pola wybrać:"
59
+
60
+ #: ../classes/class.attachments.migrate.php:174
61
+ msgid "Attachments 3.x Instance"
62
+ msgstr "Załączniki 3.x - Instancja"
63
+
64
+ #: ../classes/class.attachments.migrate.php:178
65
+ msgid "The instance name you would like to use in the migration. Required."
66
+ msgstr "Nazwa instancji do której chcesz migrować stare dane. Wymagana."
67
+
68
+ #: ../classes/class.attachments.migrate.php:183
69
+ msgid "Attachments 3.x Title"
70
+ msgstr "Załączniki 3.x - Tytuł"
71
+
72
+ #: ../classes/class.attachments.migrate.php:187
73
+ msgid ""
74
+ "The <code>Title</code> field data will be migrated to this field name in "
75
+ "Attachments 3.x. Leave empty to disregard."
76
+ msgstr ""
77
+ "Pole <code>Tytuł</code> zostanie przeniesione do pola o tej nazwie w wersji "
78
+ "3.x. Pozostaw puste, aby zignorować."
79
+
80
+ #: ../classes/class.attachments.migrate.php:192
81
+ msgid "Attachments 3.x Caption"
82
+ msgstr "Załączniki 3.x - Nagłówek"
83
+
84
+ #: ../classes/class.attachments.migrate.php:196
85
+ msgid ""
86
+ "The <code>Caption</code> field data will be migrated to this field name in "
87
+ "Attachments 3.x. Leave empty to disregard."
88
+ msgstr ""
89
+ "Pole <code>Nagłówek</code> zostanie przeniesione do pola o tej nazwie w "
90
+ "wersji 3.x. Pozostaw puste, aby zignorować."
91
+
92
+ #: ../classes/class.attachments.migrate.php:224
93
+ msgid "Migration Complete!"
94
+ msgstr "Migracja zakończona pomyślnie!"
95
+
96
+ #: ../classes/class.attachments.migrate.php:225
97
+ msgid "The migration has completed."
98
+ msgstr "Migracja zakończona."
99
+
100
+ #: ../classes/class.attachments.migrate.php:225
101
+ msgid "Migrated"
102
+ msgstr "Migrowanie"
103
+
104
+ #: ../classes/class.attachments.migrate.php:227
105
+ msgid "Migration has already Run!"
106
+ msgstr "Proces migracji już się odbył!"
107
+
108
+ #: ../classes/class.attachments.migrate.php:228
109
+ msgid ""
110
+ "The migration has already been run. The migration process has not been "
111
+ "repeated."
112
+ msgstr "Proces migracji już się odbył. Procesu migracji nie był powtórzony."
113
+
114
+ #: ../classes/class.attachments.php:769 ../classes/class.attachments.php:843
115
+ #: ../deprecated/attachments.php:365 ../languages/class.attachments.php:769
116
+ #: ../languages/class.attachments.php:843
117
+ msgid "Title"
118
+ msgstr "Tytuł"
119
+
120
+ #: ../classes/class.attachments.php:805 ../classes/class.attachments.php:1524
121
+ #: ../deprecated/attachments.php:417 ../languages/class.attachments.php:805
122
+ #: ../languages/class.attachments.php:1524 ../views/options.php:24
123
+ msgid "Attachments"
124
+ msgstr "Załączniki"
125
+
126
+ #: ../classes/class.attachments.php:830 ../classes/class.attachments.php:833
127
+ #: ../deprecated/attachments.php:312 ../languages/class.attachments.php:830
128
+ #: ../languages/class.attachments.php:833
129
+ msgid "Attach"
130
+ msgstr "Załącz plik"
131
+
132
+ #: ../classes/class.attachments.php:849 ../deprecated/attachments.php:369
133
+ #: ../languages/class.attachments.php:849
134
+ msgid "Caption"
135
+ msgstr "Nagłówek"
136
+
137
+ #: ../classes/class.attachments.php:1100
138
+ #: ../languages/class.attachments.php:1100
139
+ msgid "Remove"
140
+ msgstr "Usuń"
141
+
142
+ #: ../classes/class.attachments.php:1101
143
+ #: ../languages/class.attachments.php:1101
144
+ msgid "Toggle Fields"
145
+ msgstr "Przełącz pola"
146
+
147
+ #: ../deprecated/attachments.php:51
148
+ msgid ""
149
+ "Attachments requires PHP 5.2 or higher, as does WordPress 3.2+. Attachments "
150
+ "has been automatically deactivated."
151
+ msgstr ""
152
+ "Wtyczka Załączniki została automatycznie zablokowana, ponieważ podobnie jak "
153
+ "Wordpress 3.2+ wymaga PHP w wersji 5.2 lub wyższej. "
154
+
155
+ #: ../deprecated/attachments.php:361
156
+ msgid "Delete"
157
+ msgstr "Usuń"
158
+
159
+ #: ../views/options.php:29
160
+ msgid ""
161
+ "<strong>Attachments has changed significantly since it's last update.</"
162
+ "strong> These changes <em>will affect your themes and plugins</em>."
163
+ msgstr ""
164
+ "<strong>Wtyczka zmieniła się znacząco od ostatniej aktualizacji.</strong> Te "
165
+ "zmiany <em>będą widoczne w Twoich motywach i wtyczkach</em>."
166
+
167
+ #: ../views/options.php:32
168
+ msgid "Immediate Reversal to Attachments 1.x"
169
+ msgstr "Natychmiast wróć do wersji 1.x wtyczki Załączniki."
170
+
171
+ #: ../views/options.php:34
172
+ msgid ""
173
+ "If you would like to immediately <em>revert to the old version of "
174
+ "Attachments</em> you may do so by downgrading the plugin install itself, or "
175
+ "adding the following to your"
176
+ msgstr ""
177
+ "Jeśli chciałbyś natychmiastowo <em>powrócić do starej wersji Załączników</"
178
+ "em> możesz to zrobić zmieniając pliki wtyczki na starsze lub dodając "
179
+ "poniższy kod do "
180
+
181
+ #: ../views/options.php:38
182
+ msgid "Overview of changes from Attachments 1.x"
183
+ msgstr "Przegląd zmian od wersji 1.x"
184
+
185
+ #: ../views/options.php:40
186
+ msgid ""
187
+ "A lot has changed since Attachments 1.x. The entire codebase was rewritten "
188
+ "to not only make better use of the stellar Media updates in WordPress 3.5, "
189
+ "but to also facilitate some exciting features coming down the line. With "
190
+ "this rewrite came significant changes to the way you will work with "
191
+ "Attachments. One of the biggest changes in Attachments 3.0 is the ability to "
192
+ "create multiple meta boxes of Attachments, each with any number of custom "
193
+ "fields you define. By default, Attachments will re-implement the meta box "
194
+ "you've been using until now, but <strong>you will need to trigger a "
195
+ "migration to the new format</strong>."
196
+ msgstr ""
197
+ "Wiele się zmieniło od wersji 1.x. Cały kod bazowy został przepisany, aby nie "
198
+ "tylko lepiej wykorzystać aktualizację Mediów w WordPress 3.5, ale również "
199
+ "ułatwić użytkowanie dzięki kilku nowo wprowadzonym funkcjom. Dzięki "
200
+ "przepisaniu kodu pojawiły się ważne zmiany w sposobie używania Załączników. "
201
+ "Jedną z największych zmian w wersji 3 jest możliwość tworzenia wielu pól "
202
+ "meta załączników, każde z dowolnej liczby niestandardowych pól "
203
+ "zdefiniowanych przez użytkownika. Domyślnie Załączniki zaimplementują "
204
+ "ponownie pole meta które używałeś do tej pory, ale <strong> trzeba będzie "
205
+ "wywołać migrację do nowego formatu </ strong>."
206
+
207
+ #: ../views/options.php:42
208
+ msgid "Migrating Attachments 1.x data to Attachments 3.x"
209
+ msgstr "Migrowanie danych z wersji 1.x do 3.x"
210
+
211
+ #: ../views/options.php:44
212
+ msgid ""
213
+ "If you have existing Attachments 1.x data and are using it, a migration "
214
+ "script has been bundled here and you can use it below. If you would like to "
215
+ "directly migrate from Attachments 1.x to Attachments 3.x you can use the "
216
+ "defaults put in place and your data will be migrated to the new format "
217
+ "quickly and easily. Alternatively, if you'd like to customize the fields "
218
+ "you're using a bit, you can do that first and then adjust the migration "
219
+ "parameters to map the old fields to your new ones."
220
+ msgstr ""
221
+ "Jeśli masz już wtyczkę Załączniki 1.x i używasz jej, możesz użyć dołączonego "
222
+ "skryptu migracji. Jeśli chcesz, aby bezpośrednio migrować z danymi z wersji "
223
+ "1.x do 3.x można użyć domyślnych ustawień a twoje dane zostaną przeniesione "
224
+ "do nowego formatu szybko i łatwo. Ewentualnie, jeśli chcesz najpierw "
225
+ "dostosować pola których używasz, można to zrobić, a potem dostosować "
226
+ "parametry migracji aby zmapować stare pola do nowych."
227
+
228
+ #: ../views/options.php:46
229
+ msgid "Setting up Instances"
230
+ msgstr "Dodawanie instancji"
231
+
232
+ #: ../views/options.php:48
233
+ msgid ""
234
+ "Attachments 3.0 ships with what are called <em>instances</em>. An instance "
235
+ "is equivalent to a meta box on an edit screen and it has a number of "
236
+ "properties you can customize. Please read the README for more information."
237
+ msgstr ""
238
+ "Załączniki w wersji 3 wprowadza nową funkcjonalność zwaną <em>instancjami</"
239
+ "em>. Jedna instancja oznacza jeden metabox w panelu edycji. Każda posiada "
240
+ "możliwość dostosowania do potrzeb. Przeczytaj README aby uzyskać więcej "
241
+ "informacji."
242
+
243
+ #: ../views/options.php:48 ../views/options.php:52
244
+ msgid "Additinoal instructions"
245
+ msgstr "Dodatkowe instrukcje"
246
+
247
+ #: ../views/options.php:50
248
+ msgid "Retrieving Attachments in your theme"
249
+ msgstr "Wyświetlanie Załączników w twoim motywie"
250
+
251
+ #: ../views/options.php:52
252
+ msgid ""
253
+ "As always has been the case with Attachments, editing your theme files is "
254
+ "required. The syntax to do so has changed in Attachments 3.0. Please read the"
255
+ msgstr ""
256
+ "Jak zawsze w przypadku wtyczki Załączniki, musisz edytować pliki swojego "
257
+ "profilu. Składnia zmieniła się znacznie w wersji 3 Załączników. Proszę, "
258
+ "przeczytaj "
259
+
260
+ #: ../views/options.php:85
261
+ msgid "Migrate legacy Attachments data"
262
+ msgstr "Migrowanie starszych danych wtyczki Załączniki"
263
+
264
+ #: ../views/options.php:86
265
+ msgid ""
266
+ "Attachments has found records from version 1.x. Would you like to migrate "
267
+ "them to version 3?"
268
+ msgstr ""
269
+ "Załączniki wykryły dane z wersji 1.x. Chciałbyś migrować je do wersji 3?"
270
+
271
+ #: ../views/options.php:87
272
+ msgid "Migrate legacy data"
273
+ msgstr "Migracja starszych danych"
274
+
275
+ #: ../views/options.php:89
276
+ msgid "You have already migrated your legacy Attachments data."
277
+ msgstr "Starsze dane Załączników zostały już migrowane do nowej instancji."
278
+
279
+ #: ../views/options.php:92
280
+ msgid "Revert to version 1.x"
281
+ msgstr "Powrót do wersji 1.x"
282
+
283
+ #: ../views/options.php:93
284
+ msgid ""
285
+ "If you would like to forcefully revert to the 1.x version branch of "
286
+ "Attachments, add the following to your"
287
+ msgstr ""
288
+ "Jeśli chciałbyś zmusić Załączniki do powrotu do wersji 1.x, dodaj poniższą "
289
+ "linijkę kodu do "
290
+
291
+ #: ../views/options.php:95
292
+ msgid "Meta box customization"
293
+ msgstr "Dostosowanie wyświetlania w kokpicie (metaboxy)"
294
+
295
+ #: ../views/options.php:96
296
+ msgid ""
297
+ "By default, Attachments implements a single meta box on Posts and Pages with "
298
+ "two fields. You can disable this default instance by adding the following to "
299
+ "your"
300
+ msgstr ""
301
+ "Domyślnie wtyczka Załączniki dodaje pojedynczy metabox na Stronach i Wpisach "
302
+ "z dwoma polami. Możesz zablokować tę standardową instancję Załączników "
303
+ "dodając poniższą linijkę kodu do pliku "
304
+
305
+ #: ../views/options.php:98
306
+ msgid ""
307
+ "Your Attachments meta box(es) can be customized by adding the following to "
308
+ "your theme's"
309
+ msgstr ""
310
+ "Metabox załącznik może być łatwo dostosowany poprzez dodanie poniższego kodu "
311
+ "do twojego motywu do pliku "
312
+
313
+ #: ../views/options.php:100
314
+ msgid "Using Attachments data in your theme"
315
+ msgstr "Wyświetlanie załączników na stronie"
316
+
317
+ #: ../views/options.php:101
318
+ msgid ""
319
+ "Attachments does not directly integrate with your theme out of the box, you "
320
+ "will need to edit your theme's template files where appropriate. You can add "
321
+ "the following within The Loop to retrieve all Attachments data for the "
322
+ "current post:"
323
+ msgstr ""
324
+ "Wtyczka Załączniki nie integruje się bezpośrednio z twoim motywem zaraz po "
325
+ "instalacji, trzeba edytować odpowiednie pliki. Możesz dodać poniższy kod w "
326
+ "pętli (The Loop) aby wyświetlić wszystkie dostępne Załączniki i ich dane dla "
327
+ "aktualnego elementu (wpisu, strony itp.):"
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: jchristopher
3
  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.4.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,14 +12,10 @@ Attachments allows you to simply append any number of items from your WordPress
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! =
20
-
21
- WordPress 3.5 ships with an amazing new Media workflow and Attachments 3.0 makes great use of it. *If you are not running WordPress 3.5, the (now deprecated) version 1.6.2.1 (included with Attachments 3.x) will be used until you upgrade to WordPress 3.5+*
22
-
23
  = Associate Media items with posts =
24
 
25
  The idea behind Attachments is to give developers the ability to directly associate Media items with any post. This is accomplished by adding a meta box to post edit screens as determined by the developer. Once Media items have been associated with a post, you're able to retrieve those Attachments and include them directly within your template files using any specific markup you wish.
@@ -67,7 +63,7 @@ There is a lot more information on [Attachments' GitHub page](https://github.com
67
 
68
  `define( 'ATTACHMENTS_LEGACY', true ); // force the legacy version of Attachments`
69
 
70
- Version 3 is a *major* rewrite. While I've taken precautions in ensuring you won't lose any saved data it is important to back up your databse prior to upgrading in case something goes wrong. This version is a complete rewrite so all legacy data will be left in place, but a migration must take place to match the new data storage model and workflow.
71
 
72
  == Frequently Asked Questions ==
73
 
@@ -83,7 +79,139 @@ Please see [Issues on GitHub](https://github.com/jchristopher/attachments/issues
83
 
84
  == Changelog ==
85
 
86
- Please see [Attachments on GitHub](https://github.com/jchristopher/attachments#changelog)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  == Upgrade Notice ==
89
 
@@ -92,8 +220,8 @@ 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)
3
  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.6
7
+ Stable tag: 3.5
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/docs/usage.md)
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
  = Associate Media items with posts =
20
 
21
  The idea behind Attachments is to give developers the ability to directly associate Media items with any post. This is accomplished by adding a meta box to post edit screens as determined by the developer. Once Media items have been associated with a post, you're able to retrieve those Attachments and include them directly within your template files using any specific markup you wish.
63
 
64
  `define( 'ATTACHMENTS_LEGACY', true ); // force the legacy version of Attachments`
65
 
66
+ Version 3 is a *major* rewrite. While I've taken precautions in ensuring you won't lose any saved data it is important to back up your database prior to upgrading in case something goes wrong. This version is a complete rewrite so all legacy data will be left in place, but a migration must take place to match the new data storage model and workflow.
67
 
68
  == Frequently Asked Questions ==
69
 
79
 
80
  == Changelog ==
81
 
82
+ Please see [Attachments' changelog on GitHub](https://github.com/jchristopher/attachments/docs/changelog.md)
83
+
84
+ = 3.5 =
85
+ * Initial implementation of limiting the number of Attachments
86
+ * You can now change an Attachment asset without having to remove the entire Attachment and re-add something new
87
+ * New filter: `attachments_location_{my_instance}` (where `**{my_instance}**` is your instance name) allows for more fine-grained control over where meta boxes show up (e.g. limiting to your Home page)
88
+ * New action: `attachments_extension` facilitates Attachments extensions
89
+ * New method `width( $size )` to retrieve the width of the current Attachment
90
+ * New method `height( $size )` to retrieve the height of the current Attachment
91
+ * New document structure, various additions to documentation
92
+ * Attachments Pro migration script. If you've been waiting to migrate from Attachments Pro please **back up your database** and run the migration script.
93
+ * Fixed an asset URL issue if Attachments is added as a must-use plugin
94
+ * Italian translation (props Marco Chiesi)
95
+
96
+ = 3.4.3 =
97
+ * Attachments now takes into account media deleted outside Attachments meta boxes and removes deleted attachments automatically
98
+ * Added working Polish translation, props <a href="https://github.com/mleczakm">@mleczakm</a>
99
+
100
+ = 3.4.2.1 =
101
+ * Fixed a regression that prevented the `type` method from returning
102
+
103
+ = 3.4.2 =
104
+ * Fixed an issue where the `languages` directory wouldn't be utilized for l10n
105
+ * Search now respects custom `meta_key`
106
+ * You can now pass in a `filetype` parameter when searching to limit results in that way
107
+
108
+ = 3.4.1 =
109
+ * Class abstraction and cleanup
110
+ * Better support for plugin-created custom image sizes
111
+
112
+ = 3.4 =
113
+ * New filter: `attachments_meta_key` facilitates using a different meta key for Attachments storage
114
+ * New filter: `attachments_get_ **{my_instance}**` (where `**{my_instance}**` is your instance name) allows you to filter Attachments per instance once they've been retrieved
115
+ * Fixed an issue where retrieving single Attachments didn't properly pass the index to attribute methods
116
+ * Fixed PHP Warnings when Network Activating
117
+ * You can now have new Attachments <em>prepend</em> the list instead of append by setting `append => false` in your instance
118
+
119
+ = 3.3.3 =
120
+ * Fixed a PHP Warning when activated using Multisite
121
+ * Slightly modified the migration process to better handle plugins like WPML (props sebastian.friedrich)
122
+
123
+ = 3.3.2 =
124
+ * You can now specify which view is default when browsing the Media modal (e.g. have 'Upload Files' be default instead of 'Media Library')
125
+
126
+ = 3.3.1 =
127
+ * Added meta box positioning arguments when registering instances
128
+ * Cleaned up some CSS when Attachments instances are in the sidebar
129
+
130
+ = 3.3 =
131
+ * Added a `search()` method to allow searching for Attachments based on their attributes (e.g. attachment ID, post ID, post type, field values, etc.)
132
+ * Improved the 'Remove' animation
133
+ * New field: select
134
+ * New parameter for Attachments attributes methods. You can pass the index (`int`) of the Attachment you'd like to utilize when firing the method.
135
+
136
+ = 3.2 =
137
+ * Added option to disable the Settings screen
138
+ * 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.
139
+ * Added a `get_single()` method that allows you to specifically retrieve a single Attachment
140
+ * Clarified some documentation
141
+
142
+ = 3.1.4 =
143
+ * Changed 'Delete' to 'Remove' so as to not make it sound like the file itself would be deleted from Media (props Lane Goldberg)
144
+ * Better handling of posts that have no Attachments when saving
145
+
146
+ = 3.1.3 =
147
+ * Fixed a potential issue with the WYSIWYG field not working on CPT without editor support
148
+ * Field assets are less aggressive and only fire when necessary
149
+ * Reorganized the migration process a bit in prep for Attachments Pro support
150
+
151
+ = 3.1.2 =
152
+ * Fixed a regression that prevented successful migration of legacy Attachments data
153
+
154
+ = 3.1.1 =
155
+ * Fixed a Fatal Error when registering the text field
156
+
157
+ = 3.1 =
158
+ * New field: wysiwyg
159
+ * Fields will now properly respect line breaks
160
+ * Fields will now properly return HTML instead of escaped HTML
161
+
162
+ = 3.0.9 =
163
+ * Fixed an issue where special characters would break title/caption fields during migration
164
+
165
+ = 3.0.8.2 =
166
+ * Fixed a CSS issue with only one text field
167
+
168
+ = 3.0.8.1 =
169
+ * Better storage of special characters for PHP 5.4+
170
+
171
+ = 3.0.8 =
172
+ * Fixed an issue in Firefox where you weren't able to focus inputs unless you clicked their label
173
+ * New field: textarea
174
+
175
+ = 3.0.7 =
176
+ * Proper sanitization of Custom Post Type names (as WordPress does it)
177
+
178
+ = 3.0.6 =
179
+ * Fixed a possible JavaScript error if an Attachment that's an image doesn't have a proper thumbnail URL
180
+ * Added a `total()` method that will return the number of Attachments for the current instance
181
+ * When requesting the `image()` for a non-image Attachment, the WordPress-defined icon will be returned
182
+ * Added an `icon()` method that will return the WordPress-defined icon for the Attachment
183
+ * Cleaned up a PHP Warning when trying to save for an undefined field type
184
+ * Fixed an issue where template tags would be output for non-image Attachments after saving
185
+
186
+ = 3.0.5 =
187
+ * Fixed a regression in handling Custom Post Type names that would too aggressively interfere with instance regustration
188
+ * Fixed an issue when working with non-image Attachments
189
+
190
+ = 3.0.4 =
191
+ * Fixed an issue that prevented the choosing of a Featured Image for a Custom Post Type if Attachments was activated
192
+ * Attachments now only enqueues its assets on edit screens that actually utilize Attachments
193
+ * Fixed a potential JavaScript error triggered when a 'thumbnail' image size was not available
194
+ * 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)
195
+ * Prevented re-running of migration process to avoid duplicates (e.g. on browser reload)
196
+
197
+ = 3.0.3 =
198
+ * Fixed an issue that prevented defining a post ID when retrieving Attachments outside The Loop
199
+ * Cleaned up potential PHP warning when Attachments were requested for a post that had none
200
+
201
+ = 3.0.2 =
202
+ * Fixed an issue where some HTML entities were not properly stored
203
+
204
+ = 3.0.1 =
205
+ * Fixed an issue where legacy mode was always enabled
206
+
207
+ = 3.0 =
208
+ * **Major** rewrite. After three years of development, Attachments has been rewritten to make
209
+ even better use of what WordPress has to offer
210
+ * Utilizes the brand spanking new 3.5 Media workflow
211
+ * Configuration now takes place within your theme or a plugin
212
+ * Multiple meta boxes! You can segment groups of Attachments with new instances, each unique
213
+ * Dynamic fields! You can manipulate which fields each instance uses
214
+ * File type limits. Limit which files are available to Attachments (e.g. images, audio, video)
215
 
216
  == Upgrade Notice ==
217
 
220
 
221
  == Roadmap ==
222
 
223
+ Please see [Attachments on GitHub](https://github.com/jchristopher/attachments/docs/roadmap.md)
224
 
225
  == Usage ==
226
 
227
+ **Extensive** usage instructions are [available on GitHub](https://github.com/jchristopher/docs/usage.md)
views/options.php CHANGED
@@ -15,6 +15,15 @@
15
  // set our flag that the user wants to ignore the migration message
16
  add_option( 'attachments_ignore_migration', true, '', 'no' );
17
  }
 
 
 
 
 
 
 
 
 
18
  ?>
19
 
20
  <div class="wrap">
@@ -78,6 +87,19 @@
78
  break;
79
  }
80
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  else
82
  { ?>
83
 
@@ -89,11 +111,23 @@
89
  <p><?php _e( 'You have already migrated your legacy Attachments data.', 'attachments' ); ?></p>
90
  <?php endif; ?>
91
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  <h2><?php _e( 'Revert to version 1.x', 'attachments' ); ?></h2>
93
  <p><?php _e( 'If you would like to forcefully revert to the 1.x version branch of Attachments, add the following to your', 'attachments' ); ?> <code>wp-config.php</code>:</p>
94
  <p><code>define( 'ATTACHMENTS_LEGACY', true );</code></p>
95
  <h2><?php _e( 'Meta box customization', 'attachments' ); ?></h2>
96
- <p><?php _e( 'By default, Attachments implements a single meta box on Posts and Pages with two fields. You can disable this default instance by adding the following to your', 'attachments' ); ?> <code>wp-config.php</code>:</p>
97
  <p><code>define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );</code></p>
98
  <p><?php _e( "Your Attachments meta box(es) can be customized by adding the following to your theme's", 'attachments' ); ?> <code>functions.php</code>:</p>
99
  <script src="https://gist.github.com/4217475.js"> </script>
@@ -101,7 +135,6 @@
101
  <p><?php _e( "Attachments does not directly integrate with your theme out of the box, you will need to edit your theme's template files where appropriate. You can add the following within The Loop to retrieve all Attachments data for the current post:", 'attachments' ); ?></p>
102
  <script src="https://gist.github.com/4217483.js"> </script>
103
  <?php }
104
-
105
  ?>
106
 
107
  </div>
15
  // set our flag that the user wants to ignore the migration message
16
  add_option( 'attachments_ignore_migration', true, '', 'no' );
17
  }
18
+
19
+ if( isset( $_GET['dismiss-pro'] ) )
20
+ {
21
+ if( !wp_verify_nonce( $_GET['nonce'], 'attachments-pro-dismiss') )
22
+ wp_die( __( 'Invalid request', 'attachments' ) );
23
+
24
+ // set our flag that the user wants to ignore the migration message
25
+ add_option( 'attachments_pro_ignore_migration', true, '', 'no' );
26
+ }
27
  ?>
28
 
29
  <div class="wrap">
87
  break;
88
  }
89
  }
90
+ elseif( isset( $_GET['migrate-pro'] ) )
91
+ {
92
+ switch( intval( $_GET['migrate-pro'] ) )
93
+ {
94
+ case 1:
95
+ $migrator->prepare_pro_migration();
96
+ break;
97
+
98
+ case 2:
99
+ $migrator->init_pro_migration();
100
+ break;
101
+ }
102
+ }
103
  else
104
  { ?>
105
 
111
  <p><?php _e( 'You have already migrated your legacy Attachments data.', 'attachments' ); ?></p>
112
  <?php endif; ?>
113
 
114
+ <?php if( false == get_option( 'attachments_pro_migrated' ) && $legacy->legacy_pro ) : ?>
115
+ <h2><?php _e( 'Migrate Attachments Pro data', 'attachments' ); ?></h2>
116
+ <p><?php _e( 'Attachments has found records stored in Attachments Pro. Would you like to migrate them to Attachments?', 'attachments' ); ?></p>
117
+ <p><a href="?page=attachments&amp;migrate-pro=1&amp;nonce=<?php echo wp_create_nonce( 'attachments-pro-migrate-1' ); ?>" class="button-primary button"><?php _e( 'Migrate Attachments Pro data', 'attachments' ); ?></a></p>
118
+ <?php elseif( true == get_option( 'attachments_pro_migrated' ) ) : ?>
119
+ <p><?php _e( 'You have already migrated your Attachments Pro data.', 'attachments' ); ?></p>
120
+ <h2><?php _e( 'Moving from Attachments Pro: required code for your functions.php', 'attachments' ); ?></h2>
121
+ <textarea style="display:block; width:100%; font-family:monospace; height:300px;"><?php echo get_option( 'attachments_pro_functions '); ?></textarea>
122
+ <h2><?php _e( 'Moving from Attachments Pro: starter code for your theme templates', 'attachments' ); ?></h2>
123
+ <textarea style="display:block; width:100%; font-family:monospace; height:200px;"><?php echo get_option( 'attachments_pro_template '); ?></textarea>
124
+ <?php endif; ?>
125
+
126
  <h2><?php _e( 'Revert to version 1.x', 'attachments' ); ?></h2>
127
  <p><?php _e( 'If you would like to forcefully revert to the 1.x version branch of Attachments, add the following to your', 'attachments' ); ?> <code>wp-config.php</code>:</p>
128
  <p><code>define( 'ATTACHMENTS_LEGACY', true );</code></p>
129
  <h2><?php _e( 'Meta box customization', 'attachments' ); ?></h2>
130
+ <p><?php _e( 'Attachments requires manual creation of meta boxes using code outlined in the documentation. If you would prefer a UI for managing Attachments Instances, please see', 'attachments' ); ?> <a href="http://mondaybynoon.com/members/plugins/attachments-ui/">Attachments UI</a>. <?php _e( 'By default, Attachments implements a single meta box on Posts and Pages with two fields. You can disable this default instance by adding the following to your', 'attachments' ); ?> <code>wp-config.php</code>:</p>
131
  <p><code>define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );</code></p>
132
  <p><?php _e( "Your Attachments meta box(es) can be customized by adding the following to your theme's", 'attachments' ); ?> <code>functions.php</code>:</p>
133
  <script src="https://gist.github.com/4217475.js"> </script>
135
  <p><?php _e( "Attachments does not directly integrate with your theme out of the box, you will need to edit your theme's template files where appropriate. You can add the following within The Loop to retrieve all Attachments data for the current post:", 'attachments' ); ?></p>
136
  <script src="https://gist.github.com/4217483.js"> </script>
137
  <?php }
 
138
  ?>
139
 
140
  </div>