Attachments - Version 1.5.9

Version Description

  • Retrieve file size when firing attachments_get_attachments()
Download this release

Release Info

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

Code changes from version 1.5.8 to 1.5.9

Files changed (3) hide show
  1. attachments.options.php +25 -5
  2. attachments.php +30 -2
  3. readme.txt +9 -2
attachments.options.php CHANGED
@@ -1,17 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
1
  <div class="wrap">
 
2
  <div id="icon-options-general" class="icon32"><br /></div>
3
  <h2>Attachments Options</h2>
 
 
 
 
 
 
 
4
  <form action="options.php" method="post">
5
  <?php wp_nonce_field('update-options'); ?>
6
 
7
  <?php if( function_exists( 'get_post_types' ) ) : ?>
8
-
9
- <?php
10
  $args = array(
11
  'public' => true,
12
  'show_ui' => true,
13
  '_builtin' => false
14
- );
15
  $output = 'objects';
16
  $operator = 'and';
17
  $post_types = get_post_types( $args, $output, $operator );
@@ -23,9 +42,9 @@
23
  $post_types['page']->name = 'page';
24
 
25
  ?>
26
-
27
  <?php if( count( $post_types ) ) : ?>
28
-
29
  <h3><?php _e("Post Type Settings", "attachments"); ?></h3>
30
  <p><?php _e("Include Attachments in the following Post Types:", "attachments"); ?></p>
31
  <?php foreach($post_types as $post_type) : ?>
@@ -59,4 +78,5 @@
59
  </p>
60
 
61
  </form>
 
62
  </div>
1
+ <?php
2
+
3
+ if( isset( $_GET['dismisspro'] ) )
4
+ {
5
+ update_option( '_attachments_dismiss_pro', 1 );
6
+ // wp_redirect( 'options-general.php?page=attachments/attachments.php' );
7
+ // die();
8
+ }
9
+
10
+ ?>
11
+
12
  <div class="wrap">
13
+
14
  <div id="icon-options-general" class="icon32"><br /></div>
15
  <h2>Attachments Options</h2>
16
+
17
+ <?php $attachments_dismiss_pro = get_option( '_attachments_dismiss_pro' ); if( !$attachments_dismiss_pro ) : ?>
18
+ <div class="updated">
19
+ <?php _e( '<p><strong>Attachments Pro is now available!</strong> <a href="http://mondaybynoon.com/store/attachments-pro/">Find out more</a> about Attachments Pro. <a href="options-general.php?page=attachments/attachments.php&dismisspro=1">Dismiss</a>.</p>', 'attachments' ); ?>
20
+ </div>
21
+ <?php endif; ?>
22
+
23
  <form action="options.php" method="post">
24
  <?php wp_nonce_field('update-options'); ?>
25
 
26
  <?php if( function_exists( 'get_post_types' ) ) : ?>
27
+
28
+ <?php
29
  $args = array(
30
  'public' => true,
31
  'show_ui' => true,
32
  '_builtin' => false
33
+ );
34
  $output = 'objects';
35
  $operator = 'and';
36
  $post_types = get_post_types( $args, $output, $operator );
42
  $post_types['page']->name = 'page';
43
 
44
  ?>
45
+
46
  <?php if( count( $post_types ) ) : ?>
47
+
48
  <h3><?php _e("Post Type Settings", "attachments"); ?></h3>
49
  <p><?php _e("Include Attachments in the following Post Types:", "attachments"); ?></p>
50
  <?php foreach($post_types as $post_type) : ?>
78
  </p>
79
 
80
  </form>
81
+
82
  </div>
attachments.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Attachments
4
  Plugin URI: http://mondaybynoon.com/wordpress-attachments/
5
  Description: Attachments gives the ability to append any number of Media Library items to Pages, Posts, and Custom Post Types
6
- Version: 1.5.8
7
  Author: Jonathan Christopher
8
  Author URI: http://mondaybynoon.com/
9
  */
@@ -37,6 +37,9 @@ if( !defined( 'IS_ADMIN' ) )
37
  // ===========
38
 
39
  global $wpdb;
 
 
 
40
 
41
  // environment check
42
  $wp_version = get_bloginfo( 'version' );
@@ -97,6 +100,8 @@ function attachments_update_message()
97
  <li style="width:48%;padding-right:2%;float:left;">Ability to define rules limiting the availability of Attachments on edit screens</li>
98
  <li style="width:48%;padding-right:2%;float:left;">Limit the number of Attachments that can be added</li>
99
  <li style="width:48%;padding-right:2%;float:left;">Limit Attach-able Media items by file/mime type</li>
 
 
100
  </ul>
101
  <p>Attachments has always been and <em>will always be free</em>. <a href="http://mondaybynoon.com/store/attachments-pro/">Attachments Pro</a> is <strong>available now</strong>. To find out more about the new features already added, and to stay up-to-date on what's to come, <a href="http://mondaybynoon.com/store/attachments-pro/">have a look at the details</a>. From there, you can make formal support and feature requests.</p>
102
  </div>
@@ -391,6 +396,28 @@ function attachments_save($post_id)
391
  }
392
 
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  /**
395
  * Retrieves all Attachments for provided Post or Page
396
  *
@@ -460,6 +487,7 @@ function attachments_get_attachments( $post_id=null )
460
  'mime' => stripslashes( get_post_mime_type( $data['id'] ) ),
461
  'title' => stripslashes( $data['title'] ),
462
  'caption' => stripslashes( $data['caption'] ),
 
463
  'location' => stripslashes( wp_get_attachment_url( $data['id'] ) ),
464
  'order' => stripslashes( $data['order'] )
465
  ));
@@ -540,7 +568,7 @@ function attachments_filter_plugin_row_meta( $plugin_meta, $plugin_file )
540
  if( strstr( $plugin_file, 'attachments/attachments.php' ) )
541
  {
542
  $plugin_meta[2] = '<a title="Attachments Pro" href="http://mondaybynoon.com/store/attachments-pro/">Attachments Pro</a>';
543
- $plugin_meta[3] = 'Visit <a title="Iron to Iron" href="http://irontoiron.com/">' . __( 'Iron to Iron', 'attachmentspro' ) . '</a>';
544
  return $plugin_meta;
545
  }
546
  else
3
  Plugin Name: Attachments
4
  Plugin URI: http://mondaybynoon.com/wordpress-attachments/
5
  Description: Attachments gives the ability to append any number of Media Library items to Pages, Posts, and Custom Post Types
6
+ Version: 1.5.9
7
  Author: Jonathan Christopher
8
  Author URI: http://mondaybynoon.com/
9
  */
37
  // ===========
38
 
39
  global $wpdb;
40
+ global $units;
41
+
42
+ $units = array( ' bytes', ' KB', ' MB', ' GB', ' TB', ' PB' );
43
 
44
  // environment check
45
  $wp_version = get_bloginfo( 'version' );
100
  <li style="width:48%;padding-right:2%;float:left;">Ability to define rules limiting the availability of Attachments on edit screens</li>
101
  <li style="width:48%;padding-right:2%;float:left;">Limit the number of Attachments that can be added</li>
102
  <li style="width:48%;padding-right:2%;float:left;">Limit Attach-able Media items by file/mime type</li>
103
+ <li style="width:48%;padding-right:2%;float:left;">Shortcode support</li>
104
+ <li style="width:48%;padding-right:2%;float:left;">Auto-inclusion of Attachments content within the_content()</li>
105
  </ul>
106
  <p>Attachments has always been and <em>will always be free</em>. <a href="http://mondaybynoon.com/store/attachments-pro/">Attachments Pro</a> is <strong>available now</strong>. To find out more about the new features already added, and to stay up-to-date on what's to come, <a href="http://mondaybynoon.com/store/attachments-pro/">have a look at the details</a>. From there, you can make formal support and feature requests.</p>
107
  </div>
396
  }
397
 
398
 
399
+ /**
400
+ * Returns a formatted filesize
401
+ *
402
+ * @param string $path Path to file on disk
403
+ * @return string $formatted formatted filesize
404
+ * @author Jonathan Christopher
405
+ */
406
+ function attachments_get_filesize_formatted( $path = NULL )
407
+ {
408
+ global $units;
409
+ $formatted = '0 bytes';
410
+ if( file_exists( $path ) )
411
+ {
412
+ $bytes = intval( filesize( $path ) );
413
+ $s = $units;
414
+ $e = floor( log( $bytes ) / log( 1024 ) );
415
+ $formatted = sprintf( '%.2f ' . $s[$e], ( $bytes / pow( 1024, floor( $e ) ) ) );
416
+ }
417
+ return $formatted;
418
+ }
419
+
420
+
421
  /**
422
  * Retrieves all Attachments for provided Post or Page
423
  *
487
  'mime' => stripslashes( get_post_mime_type( $data['id'] ) ),
488
  'title' => stripslashes( $data['title'] ),
489
  'caption' => stripslashes( $data['caption'] ),
490
+ 'filesize' => stripslashes( attachments_get_filesize_formatted( get_attached_file( $data['id'] ) ) ),
491
  'location' => stripslashes( wp_get_attachment_url( $data['id'] ) ),
492
  'order' => stripslashes( $data['order'] )
493
  ));
568
  if( strstr( $plugin_file, 'attachments/attachments.php' ) )
569
  {
570
  $plugin_meta[2] = '<a title="Attachments Pro" href="http://mondaybynoon.com/store/attachments-pro/">Attachments Pro</a>';
571
+ $plugin_meta[3] = 'Visit <a title="Iron to Iron" href="http://irontoiron.com/">Iron to Iron</a>';
572
  return $plugin_meta;
573
  }
574
  else
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://mondaybynoon.com/donate/
4
  Tags: post, page, posts, pages, images, PDF, doc, Word, image, jpg, jpeg, picture, pictures, photos, attachment
5
  Requires at least: 3.0
6
  Tested up to: 3.2.1
7
- Stable tag: 1.5.8
8
 
9
  Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
10
 
@@ -19,6 +19,8 @@ Attachments Pro brings a number of frequently requested features:
19
  * Ability to define rules limiting the availability of Attachments on edit screens
20
  * Limit the number of Attachments that can be added
21
  * Limit Attach-able Media items by file/mime type
 
 
22
 
23
  **Much more information** available about [Attachments Pro](http://mondaybynoon.com/store/attachments-pro/)
24
 
@@ -60,6 +62,9 @@ Attachments uses WordPress' built in Media library for uploads and storage.
60
 
61
  == Changelog ==
62
 
 
 
 
63
  = 1.5.8 =
64
  * Code cleanup
65
 
@@ -175,7 +180,7 @@ Attachments are now stored in such a way that removes an in-place limitation on
175
 
176
  Planned feature additions include:
177
 
178
- * Code refactoring in preparation for future features
179
 
180
  == Usage ==
181
 
@@ -190,6 +195,7 @@ Firing `attachments_get_attachments()` returns an array consisting of all availa
190
  * **id** - The WordPress assigned attachment id (for use with other WordPress media functions)
191
  * **location** - The attachment URI
192
  * **mime** - The attachment MIME type (as defined by WordPress)
 
193
 
194
  Here is a basic implementation:
195
 
@@ -206,6 +212,7 @@ Here is a basic implementation:
206
  <li><?php echo $attachments[$i]['id']; ?></li>
207
  <li><?php echo $attachments[$i]['location']; ?></li>
208
  <li><?php echo $attachments[$i]['mime']; ?></li>
 
209
  <?php endfor; ?>
210
  </ul>
211
  <?php endif; ?>
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.2.1
7
+ Stable tag: 1.5.9
8
 
9
  Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
10
 
19
  * Ability to define rules limiting the availability of Attachments on edit screens
20
  * Limit the number of Attachments that can be added
21
  * Limit Attach-able Media items by file/mime type
22
+ * Shortcode support
23
+ * Auto-inclusion of Attachments content within `the_content()`
24
 
25
  **Much more information** available about [Attachments Pro](http://mondaybynoon.com/store/attachments-pro/)
26
 
62
 
63
  == Changelog ==
64
 
65
+ = 1.5.9 =
66
+ * Retrieve file size when `firing attachments_get_attachments()`
67
+
68
  = 1.5.8 =
69
  * Code cleanup
70
 
180
 
181
  Planned feature additions include:
182
 
183
+ * Update Settings to use official Settings API
184
 
185
  == Usage ==
186
 
195
  * **id** - The WordPress assigned attachment id (for use with other WordPress media functions)
196
  * **location** - The attachment URI
197
  * **mime** - The attachment MIME type (as defined by WordPress)
198
+ * **filesize** - Formatted file size
199
 
200
  Here is a basic implementation:
201
 
212
  <li><?php echo $attachments[$i]['id']; ?></li>
213
  <li><?php echo $attachments[$i]['location']; ?></li>
214
  <li><?php echo $attachments[$i]['mime']; ?></li>
215
+ <li><?php echo $attachments[$i]['filesize']; ?></li>
216
  <?php endfor; ?>
217
  </ul>
218
  <?php endif; ?>