Version Description
- Fixed an issue when
attachments_get_attachments()
returning no Attachments generating a warning
Download this release
Release Info
Developer | jchristopher |
Plugin | Attachments |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- attachments.php +48 -11
- readme.txt +4 -1
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 and Posts
|
6 |
-
Version: 1.0.
|
7 |
Author: Jonathan Christopher
|
8 |
Author URI: http://jchristopher.me
|
9 |
*/
|
@@ -25,29 +25,50 @@ Author URI: http://jchristopher.me
|
|
25 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
26 |
*/
|
27 |
|
|
|
|
|
|
|
|
|
|
|
28 |
global $wpdb;
|
29 |
|
|
|
|
|
30 |
// =========
|
31 |
// = HOOKS =
|
32 |
// =========
|
|
|
33 |
add_action('admin_menu', 'attachments_init');
|
34 |
add_action('admin_head', 'attachments_init_js');
|
35 |
add_action('save_post', 'attachments_save');
|
36 |
|
37 |
|
38 |
|
39 |
-
|
40 |
-
|
41 |
// =============
|
42 |
// = FUNCTIONS =
|
43 |
// =============
|
44 |
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
function cmp($a, $b)
|
47 |
{
|
48 |
return strcmp($a["order"], $b["order"]);
|
49 |
}
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
function attachments_add()
|
52 |
{?>
|
53 |
|
@@ -118,7 +139,7 @@ function attachments_add()
|
|
118 |
|
119 |
|
120 |
/**
|
121 |
-
* Creates meta box on all
|
122 |
*
|
123 |
* @return void
|
124 |
* @author Jonathan Christopher
|
@@ -135,6 +156,12 @@ function attachments_meta_box()
|
|
135 |
|
136 |
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
function attachments_init_js()
|
139 |
{
|
140 |
echo '<script type="text/javascript" charset="utf-8">';
|
@@ -146,6 +173,13 @@ function attachments_init_js()
|
|
146 |
|
147 |
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
function attachments_save($post_id)
|
150 |
{
|
151 |
// verify this came from the our screen and with proper authorization,
|
@@ -212,7 +246,13 @@ function attachments_save($post_id)
|
|
212 |
|
213 |
|
214 |
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
function attachments_get_attachments($post_id=null)
|
217 |
{
|
218 |
global $post;
|
@@ -224,7 +264,7 @@ function attachments_get_attachments($post_id=null)
|
|
224 |
|
225 |
$existing_attachments = unserialize(get_post_meta($post_id, '_attachments', true));
|
226 |
|
227 |
-
if( count($existing_attachments) > 0 )
|
228 |
{
|
229 |
$post_attachments = array();
|
230 |
if( count($existing_attachments) > 1 )
|
@@ -248,11 +288,8 @@ function attachments_get_attachments($post_id=null)
|
|
248 |
|
249 |
|
250 |
|
251 |
-
|
252 |
-
|
253 |
/**
|
254 |
-
* This is the main initialization function, it will
|
255 |
-
* as well as invoke the necessary meta_box
|
256 |
*
|
257 |
* @return void
|
258 |
* @author Jonathan Christopher
|
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 and Posts
|
6 |
+
Version: 1.0.3
|
7 |
Author: Jonathan Christopher
|
8 |
Author URI: http://jchristopher.me
|
9 |
*/
|
25 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
26 |
*/
|
27 |
|
28 |
+
|
29 |
+
// ===========
|
30 |
+
// = GLOBALS =
|
31 |
+
// ===========
|
32 |
+
|
33 |
global $wpdb;
|
34 |
|
35 |
+
|
36 |
+
|
37 |
// =========
|
38 |
// = HOOKS =
|
39 |
// =========
|
40 |
+
|
41 |
add_action('admin_menu', 'attachments_init');
|
42 |
add_action('admin_head', 'attachments_init_js');
|
43 |
add_action('save_post', 'attachments_save');
|
44 |
|
45 |
|
46 |
|
|
|
|
|
47 |
// =============
|
48 |
// = FUNCTIONS =
|
49 |
// =============
|
50 |
|
51 |
+
/**
|
52 |
+
* Compares two array values with the same key "order"
|
53 |
+
*
|
54 |
+
* @param string $a First value
|
55 |
+
* @param string $b Second value
|
56 |
+
* @return int
|
57 |
+
* @author Jonathan Christopher
|
58 |
+
*/
|
59 |
function cmp($a, $b)
|
60 |
{
|
61 |
return strcmp($a["order"], $b["order"]);
|
62 |
}
|
63 |
|
64 |
+
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Inserts HTML for meta box, including all existing attachments
|
68 |
+
*
|
69 |
+
* @return void
|
70 |
+
* @author Jonathan Christopher
|
71 |
+
*/
|
72 |
function attachments_add()
|
73 |
{?>
|
74 |
|
139 |
|
140 |
|
141 |
/**
|
142 |
+
* Creates meta box on all Posts and Pages
|
143 |
*
|
144 |
* @return void
|
145 |
* @author Jonathan Christopher
|
156 |
|
157 |
|
158 |
|
159 |
+
/**
|
160 |
+
* Echos JavaScript that sets some required global variables
|
161 |
+
*
|
162 |
+
* @return void
|
163 |
+
* @author Jonathan Christopher
|
164 |
+
*/
|
165 |
function attachments_init_js()
|
166 |
{
|
167 |
echo '<script type="text/javascript" charset="utf-8">';
|
173 |
|
174 |
|
175 |
|
176 |
+
/**
|
177 |
+
* Fired when Post or Page is saved. Serializes all attachment data and saves to post_meta
|
178 |
+
*
|
179 |
+
* @param int $post_id The ID of the current post
|
180 |
+
* @return void
|
181 |
+
* @author Jonathan Christopher
|
182 |
+
*/
|
183 |
function attachments_save($post_id)
|
184 |
{
|
185 |
// verify this came from the our screen and with proper authorization,
|
246 |
|
247 |
|
248 |
|
249 |
+
/**
|
250 |
+
* Retrieves all Attachments for provided Post or Page
|
251 |
+
*
|
252 |
+
* @param int $post_id (optional) ID of target Post or Page, otherwise pulls from global $post
|
253 |
+
* @return array $post_attachments
|
254 |
+
* @author Jonathan Christopher
|
255 |
+
*/
|
256 |
function attachments_get_attachments($post_id=null)
|
257 |
{
|
258 |
global $post;
|
264 |
|
265 |
$existing_attachments = unserialize(get_post_meta($post_id, '_attachments', true));
|
266 |
|
267 |
+
if( is_array($existing_attachments) && count($existing_attachments) > 0 )
|
268 |
{
|
269 |
$post_attachments = array();
|
270 |
if( count($existing_attachments) > 1 )
|
288 |
|
289 |
|
290 |
|
|
|
|
|
291 |
/**
|
292 |
+
* This is the main initialization function, it will invoke the necessary meta_box
|
|
|
293 |
*
|
294 |
* @return void
|
295 |
* @author Jonathan Christopher
|
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: 2.8
|
6 |
Tested up to: 2.9
|
7 |
-
Stable tag: 1.0.
|
8 |
|
9 |
Attachments allows you to append any number of items from your WordPress Media Library to Posts and Pages
|
10 |
|
@@ -33,6 +33,9 @@ Attachments uses WordPress' built in Media library for uploads and storage.
|
|
33 |
|
34 |
== Changelog ==
|
35 |
|
|
|
|
|
|
|
36 |
= 1.0.2 =
|
37 |
* Fixed an issue with deleting Attachments
|
38 |
|
4 |
Tags: post, page, posts, pages, images, PDF, doc, Word, image, jpg, jpeg, picture, pictures, photos, attachment
|
5 |
Requires at least: 2.8
|
6 |
Tested up to: 2.9
|
7 |
+
Stable tag: 1.0.3
|
8 |
|
9 |
Attachments allows you to append any number of items from your WordPress Media Library to Posts and Pages
|
10 |
|
33 |
|
34 |
== Changelog ==
|
35 |
|
36 |
+
= 1.0.3 =
|
37 |
+
* Fixed an issue when `attachments_get_attachments()` returning no Attachments generating a warning
|
38 |
+
|
39 |
= 1.0.2 =
|
40 |
* Fixed an issue with deleting Attachments
|
41 |
|