Attachments - Version 1.5.3.1

Version Description

  • PHP warning cleanup
  • Settings now respect Custom Post Types that are set to show_ui
Download this release

Release Info

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

Code changes from version 1.5.3 to 1.5.3.1

Files changed (3) hide show
  1. attachments.options.php +3 -2
  2. attachments.php +142 -144
  3. readme.txt +5 -1
attachments.options.php CHANGED
@@ -8,8 +8,9 @@
8
 
9
  <?php
10
  $args = array(
11
- 'public' => true,
12
- '_builtin' => false
 
13
  );
14
  $output = 'objects';
15
  $operator = 'and';
8
 
9
  <?php
10
  $args = array(
11
+ 'public' => true,
12
+ 'show_ui' => true,
13
+ '_builtin' => false
14
  );
15
  $output = 'objects';
16
  $operator = 'and';
attachments.php CHANGED
@@ -1,29 +1,29 @@
1
  <?php
2
  /*
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.3
7
- Author: Jonathan Christopher
8
- Author URI: http://mondaybynoon.com/
9
  */
10
 
11
  /* Copyright 2009 Jonathan Christopher (email : jonathandchr@gmail.com)
12
 
13
- This program is free software; you can redistribute it and/or modify
14
- it under the terms of the GNU General Public License as published by
15
- the Free Software Foundation; either version 2 of the License, or
16
- (at your option) any later version.
17
 
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
 
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
- */
27
 
28
 
29
  // ===========
@@ -37,7 +37,7 @@ global $wpdb;
37
  // =========
38
  // = HOOKS =
39
  // =========
40
- if( WP_ADMIN )
41
  {
42
  add_action( 'admin_menu', 'attachments_init' );
43
  add_action( 'admin_head', 'attachments_init_js' );
@@ -53,13 +53,13 @@ if( WP_ADMIN )
53
  // =============
54
 
55
  /**
56
- * Compares two array values with the same key "order"
57
- *
58
- * @param string $a First value
59
- * @param string $b Second value
60
- * @return int
61
- * @author Jonathan Christopher
62
- */
63
  function attachments_cmp($a, $b)
64
  {
65
  $a = intval( $a['order'] );
@@ -83,11 +83,11 @@ function attachments_cmp($a, $b)
83
 
84
 
85
  /**
86
- * Creates the markup for the WordPress admin options page
87
- *
88
- * @return void
89
- * @author Jonathan Christopher
90
- */
91
  function attachments_options()
92
  {
93
  include 'attachments.options.php';
@@ -97,11 +97,11 @@ function attachments_options()
97
 
98
 
99
  /**
100
- * Creates the entry for Attachments Options under Settings in the WordPress Admin
101
- *
102
- * @return void
103
- * @author Jonathan Christopher
104
- */
105
  function attachments_menu()
106
  {
107
  add_options_page('Settings', 'Attachments', 'manage_options', __FILE__, 'attachments_options');
@@ -111,102 +111,100 @@ function attachments_menu()
111
 
112
 
113
  /**
114
- * Inserts HTML for meta box, including all existing attachments
115
- *
116
- * @return void
117
- * @author Jonathan Christopher
118
- */
119
  function attachments_add()
120
  {?>
121
 
122
  <div id="attachments-inner">
123
 
124
  <?php
125
- $media_upload_iframe_src = "media-upload.php?type=image&TB_iframe=1";
126
- $image_upload_iframe_src = apply_filters( 'image_upload_iframe_src', "$media_upload_iframe_src" );
127
- ?>
128
-
129
- <ul id="attachments-actions">
130
- <li>
131
- <a id="attachments-thickbox" href="<?php echo $image_upload_iframe_src; ?>&attachments_thickbox=1" title="Attachments" class="button button-highlighted">
132
- <?php _e( 'Attach', 'attachments' ) ?>
133
- </a>
134
- </li>
135
- </ul>
136
-
137
- <div id="attachments-list">
138
- <input type="hidden" name="attachments_nonce" id="attachments_nonce" value="<?php echo wp_create_nonce( plugin_basename(__FILE__) ); ?>" />
139
- <ul>
140
- <?php
141
- if( !empty($_GET['post']) )
142
- {
143
- // get all attachments
144
- $existing_attachments = attachments_get_attachments( intval( $_GET['post'] ) );
145
-
146
- if( is_array($existing_attachments) && !empty($existing_attachments) )
147
- {
148
- $attachment_index = 0;
149
- foreach ($existing_attachments as $attachment) : $attachment_index++; ?>
150
- <li class="attachments-file">
151
- <h2>
152
- <a href="#" class="attachment-handle">
153
- <span class="attachment-handle-icon"><img src="<?php echo WP_PLUGIN_URL; ?>/attachments/images/handle.gif" alt="Drag" /></span>
154
  </a>
155
- <span class="attachment-name"><?php echo $attachment['name']; ?></span>
156
- <span class="attachment-delete"><a href="#"><?php _e("Delete", "attachments")?></a></span>
157
- </h2>
158
- <div class="attachments-fields">
159
- <div class="textfield" id="field_attachment_title_<?php echo $attachment_index ; ?>">
160
- <label for="attachment_title_<?php echo $attachment_index; ?>"><?php _e("Title", "attachments")?></label>
161
- <input type="text" id="attachment_title_<?php echo $attachment_index; ?>" name="attachment_title_<?php echo $attachment_index; ?>" value="<?php echo $attachment['title']; ?>" size="20" />
162
- </div>
163
- <div class="textfield" id="field_attachment_caption_<?php echo $attachment_index; ?>">
164
- <label for="attachment_caption_<?php echo $attachment_index; ?>"><?php _e("Caption", "attachments")?></label>
165
- <input type="text" id="attachment_caption_<?php echo $attachment_index; ?>" name="attachment_caption_<?php echo $attachment_index; ?>" value="<?php echo $attachment['caption']; ?>" size="20" />
166
- </div>
167
- </div>
168
- <div class="attachments-data">
169
- <input type="hidden" name="attachment_id_<?php echo $attachment_index; ?>" id="attachment_id_<?php echo $attachment_index; ?>" value="<?php echo $attachment['id']; ?>" />
170
- <input type="hidden" class="attachment_order" name="attachment_order_<?php echo $attachment_index; ?>" id="attachment_order_<?php echo $attachment_index; ?>" value="<?php echo $attachment['order']; ?>" />
171
- </div>
172
- <div class="attachment-thumbnail">
173
- <span class="attachments-thumbnail">
174
- <?php echo wp_get_attachment_image( $attachment['id'], array(80, 60), 1 ); ?>
175
- </span>
176
- </div>
177
- </li>
178
- <?php endforeach;
179
- }
180
- }
181
- ?>
182
- </ul>
183
- </div>
184
-
185
- </div>
186
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  <?php }
188
 
189
 
190
 
191
  /**
192
- * Creates meta box on all Posts and Pages
193
- *
194
- * @return void
195
- * @author Jonathan Christopher
196
- */
197
-
198
  function attachments_meta_box()
199
  {
200
  // for custom post types
201
  if( function_exists( 'get_post_types' ) )
202
  {
203
  $args = array(
204
- 'public' => true,
205
- '_builtin' => true
 
206
  );
207
- $output = 'objects';
208
- $operator = 'and';
209
- $post_types = get_post_types( $args, $output, $operator );
210
  foreach($post_types as $post_type)
211
  {
212
  if (get_option('attachments_cpt_' . $post_type->name)=='true')
@@ -220,33 +218,33 @@ function attachments_meta_box()
220
 
221
 
222
  /**
223
- * Echos JavaScript that sets some required global variables
224
- *
225
- * @return void
226
- * @author Jonathan Christopher
227
- */
228
  function attachments_init_js()
229
  {
230
  global $pagenow;
231
 
232
  echo '<script type="text/javascript" charset="utf-8">';
233
- echo ' var attachments_base = "' . WP_PLUGIN_URL . '/attachments"; ';
234
- echo ' var attachments_media = ""; ';
235
  if ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow )
236
  {
237
- echo ' var attachments_upload = true; ';
238
  }
239
  else
240
  {
241
- echo ' var attachments_upload = false; ';
242
  }
243
  if( ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow ) && is_attachments_context() )
244
  {
245
- echo ' var attachments_is_attachments_context = true; ';
246
  }
247
  else
248
  {
249
- echo ' var attachments_is_attachments_context = false; ';
250
  }
251
  echo '</script>';
252
  }
@@ -254,13 +252,13 @@ function attachments_init_js()
254
 
255
 
256
  /**
257
- * Fired when Post or Page is saved. Serializes all attachment data and saves to post_meta
258
- *
259
- * @param int $post_id The ID of the current post
260
- * @return void
261
- * @author Jonathan Christopher
262
- * @author JR Tashjian
263
- */
264
  function attachments_save($post_id)
265
  {
266
  // verify this came from the our screen and with proper authorization,
@@ -369,13 +367,13 @@ function attachments_save($post_id)
369
 
370
 
371
  /**
372
- * Retrieves all Attachments for provided Post or Page
373
- *
374
- * @param int $post_id (optional) ID of target Post or Page, otherwise pulls from global $post
375
- * @return array $post_attachments
376
- * @author Jonathan Christopher
377
- * @author JR Tashjian
378
- */
379
  function attachments_get_attachments( $post_id=null )
380
  {
381
  global $post;
@@ -467,7 +465,7 @@ function is_attachments_context()
467
  global $pagenow;
468
 
469
  // if post_id is set, it's the editor upload...
470
- if ( ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow ) && ( empty( $_REQUEST['post_id'] ) && $_REQUEST['post_id'] != '0' ) )
471
  {
472
  return true;
473
  }
@@ -490,11 +488,11 @@ function hijack_thickbox_text($translated_text, $source_text, $domain)
490
 
491
 
492
  /**
493
- * This is the main initialization function, it will invoke the necessary meta_box
494
- *
495
- * @return void
496
- * @author Jonathan Christopher
497
- */
498
 
499
  function attachments_init()
500
  {
1
  <?php
2
  /*
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.3.1
7
+ Author: Jonathan Christopher
8
+ Author URI: http://mondaybynoon.com/
9
  */
10
 
11
  /* Copyright 2009 Jonathan Christopher (email : jonathandchr@gmail.com)
12
 
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; either version 2 of the License, or
16
+ (at your option) any later version.
17
 
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
 
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
 
28
 
29
  // ===========
37
  // =========
38
  // = HOOKS =
39
  // =========
40
+ if( is_admin() )
41
  {
42
  add_action( 'admin_menu', 'attachments_init' );
43
  add_action( 'admin_head', 'attachments_init_js' );
53
  // =============
54
 
55
  /**
56
+ * Compares two array values with the same key "order"
57
+ *
58
+ * @param string $a First value
59
+ * @param string $b Second value
60
+ * @return int
61
+ * @author Jonathan Christopher
62
+ */
63
  function attachments_cmp($a, $b)
64
  {
65
  $a = intval( $a['order'] );
83
 
84
 
85
  /**
86
+ * Creates the markup for the WordPress admin options page
87
+ *
88
+ * @return void
89
+ * @author Jonathan Christopher
90
+ */
91
  function attachments_options()
92
  {
93
  include 'attachments.options.php';
97
 
98
 
99
  /**
100
+ * Creates the entry for Attachments Options under Settings in the WordPress Admin
101
+ *
102
+ * @return void
103
+ * @author Jonathan Christopher
104
+ */
105
  function attachments_menu()
106
  {
107
  add_options_page('Settings', 'Attachments', 'manage_options', __FILE__, 'attachments_options');
111
 
112
 
113
  /**
114
+ * Inserts HTML for meta box, including all existing attachments
115
+ *
116
+ * @return void
117
+ * @author Jonathan Christopher
118
+ */
119
  function attachments_add()
120
  {?>
121
 
122
  <div id="attachments-inner">
123
 
124
  <?php
125
+ $media_upload_iframe_src = "media-upload.php?type=image&TB_iframe=1";
126
+ $image_upload_iframe_src = apply_filters( 'image_upload_iframe_src', "$media_upload_iframe_src" );
127
+ ?>
128
+
129
+ <ul id="attachments-actions">
130
+ <li>
131
+ <a id="attachments-thickbox" href="<?php echo $image_upload_iframe_src; ?>&attachments_thickbox=1" title="Attachments" class="button button-highlighted">
132
+ <?php _e( 'Attach', 'attachments' ) ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  </a>
134
+ </li>
135
+ </ul>
136
+
137
+ <div id="attachments-list">
138
+ <input type="hidden" name="attachments_nonce" id="attachments_nonce" value="<?php echo wp_create_nonce( plugin_basename(__FILE__) ); ?>" />
139
+ <ul>
140
+ <?php
141
+ if( !empty($_GET['post']) )
142
+ {
143
+ // get all attachments
144
+ $existing_attachments = attachments_get_attachments( intval( $_GET['post'] ) );
145
+
146
+ if( is_array($existing_attachments) && !empty($existing_attachments) )
147
+ {
148
+ $attachment_index = 0;
149
+ foreach ($existing_attachments as $attachment) : $attachment_index++; ?>
150
+ <li class="attachments-file">
151
+ <h2>
152
+ <a href="#" class="attachment-handle">
153
+ <span class="attachment-handle-icon"><img src="<?php echo WP_PLUGIN_URL; ?>/attachments/images/handle.gif" alt="Drag" /></span>
154
+ </a>
155
+ <span class="attachment-name"><?php echo $attachment['name']; ?></span>
156
+ <span class="attachment-delete"><a href="#"><?php _e("Delete", "attachments")?></a></span>
157
+ </h2>
158
+ <div class="attachments-fields">
159
+ <div class="textfield" id="field_attachment_title_<?php echo $attachment_index ; ?>">
160
+ <label for="attachment_title_<?php echo $attachment_index; ?>"><?php _e("Title", "attachments")?></label>
161
+ <input type="text" id="attachment_title_<?php echo $attachment_index; ?>" name="attachment_title_<?php echo $attachment_index; ?>" value="<?php echo $attachment['title']; ?>" size="20" />
162
+ </div>
163
+ <div class="textfield" id="field_attachment_caption_<?php echo $attachment_index; ?>">
164
+ <label for="attachment_caption_<?php echo $attachment_index; ?>"><?php _e("Caption", "attachments")?></label>
165
+ <input type="text" id="attachment_caption_<?php echo $attachment_index; ?>" name="attachment_caption_<?php echo $attachment_index; ?>" value="<?php echo $attachment['caption']; ?>" size="20" />
166
+ </div>
167
+ </div>
168
+ <div class="attachments-data">
169
+ <input type="hidden" name="attachment_id_<?php echo $attachment_index; ?>" id="attachment_id_<?php echo $attachment_index; ?>" value="<?php echo $attachment['id']; ?>" />
170
+ <input type="hidden" class="attachment_order" name="attachment_order_<?php echo $attachment_index; ?>" id="attachment_order_<?php echo $attachment_index; ?>" value="<?php echo $attachment['order']; ?>" />
171
+ </div>
172
+ <div class="attachment-thumbnail">
173
+ <span class="attachments-thumbnail">
174
+ <?php echo wp_get_attachment_image( $attachment['id'], array(80, 60), 1 ); ?>
175
+ </span>
176
+ </div>
177
+ </li>
178
+ <?php endforeach;
179
+ }
180
+ }
181
+ ?>
182
+ </ul>
183
+ </div>
184
+ </div>
185
  <?php }
186
 
187
 
188
 
189
  /**
190
+ * Creates meta box on all Posts and Pages
191
+ *
192
+ * @return void
193
+ * @author Jonathan Christopher
194
+ */
 
195
  function attachments_meta_box()
196
  {
197
  // for custom post types
198
  if( function_exists( 'get_post_types' ) )
199
  {
200
  $args = array(
201
+ 'public' => true,
202
+ 'show_ui' => true,
203
+ '_builtin' => true
204
  );
205
+ $output = 'objects';
206
+ $operator = 'and';
207
+ $post_types = get_post_types( $args, $output, $operator );
208
  foreach($post_types as $post_type)
209
  {
210
  if (get_option('attachments_cpt_' . $post_type->name)=='true')
218
 
219
 
220
  /**
221
+ * Echos JavaScript that sets some required global variables
222
+ *
223
+ * @return void
224
+ * @author Jonathan Christopher
225
+ */
226
  function attachments_init_js()
227
  {
228
  global $pagenow;
229
 
230
  echo '<script type="text/javascript" charset="utf-8">';
231
+ echo ' var attachments_base = "' . WP_PLUGIN_URL . '/attachments"; ';
232
+ echo ' var attachments_media = ""; ';
233
  if ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow )
234
  {
235
+ echo ' var attachments_upload = true; ';
236
  }
237
  else
238
  {
239
+ echo ' var attachments_upload = false; ';
240
  }
241
  if( ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow ) && is_attachments_context() )
242
  {
243
+ echo ' var attachments_is_attachments_context = true; ';
244
  }
245
  else
246
  {
247
+ echo ' var attachments_is_attachments_context = false; ';
248
  }
249
  echo '</script>';
250
  }
252
 
253
 
254
  /**
255
+ * Fired when Post or Page is saved. Serializes all attachment data and saves to post_meta
256
+ *
257
+ * @param int $post_id The ID of the current post
258
+ * @return void
259
+ * @author Jonathan Christopher
260
+ * @author JR Tashjian
261
+ */
262
  function attachments_save($post_id)
263
  {
264
  // verify this came from the our screen and with proper authorization,
367
 
368
 
369
  /**
370
+ * Retrieves all Attachments for provided Post or Page
371
+ *
372
+ * @param int $post_id (optional) ID of target Post or Page, otherwise pulls from global $post
373
+ * @return array $post_attachments
374
+ * @author Jonathan Christopher
375
+ * @author JR Tashjian
376
+ */
377
  function attachments_get_attachments( $post_id=null )
378
  {
379
  global $post;
465
  global $pagenow;
466
 
467
  // if post_id is set, it's the editor upload...
468
+ if ( !isset( $_REQUEST['post_id'] ) || ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow ) && ( empty( $_REQUEST['post_id'] ) && $_REQUEST['post_id'] != '0' ) )
469
  {
470
  return true;
471
  }
488
 
489
 
490
  /**
491
+ * This is the main initialization function, it will invoke the necessary meta_box
492
+ *
493
+ * @return void
494
+ * @author Jonathan Christopher
495
+ */
496
 
497
  function attachments_init()
498
  {
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
7
- Stable tag: 1.5.3
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
 
@@ -44,6 +44,10 @@ Attachments uses WordPress' built in Media library for uploads and storage.
44
 
45
  == Changelog ==
46
 
 
 
 
 
47
  = 1.5.3 =
48
  * Added Polish translation, courtesy of Wiktor Maj
49
  * Added Posts and Pages to Settings
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
7
+ Stable tag: 1.5.3.1
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
 
44
 
45
  == Changelog ==
46
 
47
+ = 1.5.3.1 =
48
+ * PHP warning cleanup
49
+ * Settings now respect Custom Post Types that are set to show_ui
50
+
51
  = 1.5.3 =
52
  * Added Polish translation, courtesy of Wiktor Maj
53
  * Added Posts and Pages to Settings