forked from chrisguitarguy/WPSE-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allow-gpx-files.php
70 lines (59 loc) · 1.97 KB
/
allow-gpx-files.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
Plugin Name: Allow GPX Files
Plugin URI: http://wordpress.stackexchange.com/q/66651/6035
Description: Allow uploads of zip files through the WP Uploader.
Author: Christopher Davis
Author URI: http://christopherdavis.me
License: GPL2
Copyright 2012 Christopher Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
add_filter('upload_mimes', 'wpse66651_allow_gpx');
/**
* Allow the uploading of .gpx files.
*
* @param array $mimes The allowed mime types in file extension => mime format
* @return array
*/
function wpse66651_allow_gpx($mimes)
{
$mimes['gpx'] = 'application/xml';
return $mimes;
}
//add_filter('the_content', 'wpse66651_display_files');
/**
* Example of how to add links to attachments to the bottom of posts
* automatically.
*
* @param string $c the post content
* @return string The content + the list of files.
*/
function wpse66651_display_files($c)
{
global $post;
if(!in_the_loop())
return $c;
$attachments = get_posts(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'application/xml',
'nopaging' => true,
));
if(!$attachments)
return $c;
$list = '<ul class="gpx-list">';
foreach($attachments as $a)
$list .= '<li>' . wp_get_attachment_link($a->ID) . '</li>';
$list .= '</ul>';
return $c . $list;
}