PluginProbe
WP Attachments / 3.5
WP Attachments v3.5
6.0.2 6.0.3 trunk 2.0 3 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.2 3.1.3 3.1.4 3.2 3.2.1 3.2.2 3.2.3 3.2.4 3.3 3.4 3.5 3.5.1 3.5.2 3.5.3 3.5.4 All 52 releases
wp-attachments / wp-attachments.php

wp-attachments.php in WP Attachments 3.5, at wp-attachments.php

169 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Attachments
4 Plugin URI: http://marcomilesi.ml
5 Description: Automatically shows your attachments under every post and page content. Simple. Automatic. Easy. As it has to be!
6 Author: Marco Milesi
7 Version: 3.5
8 Author URI: http://marcomilesi.ml
9 */
10
11 function wpa_action_init()
12 {
13 load_plugin_textdomain( 'wp-attachments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
14 update_option( 'wpa_version_number', '3.4' );
15 wp_enqueue_style('wpa-css', plugin_dir_url(__FILE__) . 'styles/frontend.css');
16 }
17
18 // Add actions
19 add_action('init', 'wpa_action_init');
20 require_once(plugin_dir_path(__FILE__) . 'settings.php');
21 require_once(plugin_dir_path(__FILE__) . 'ij-post-attachments.php');
22 require_once(plugin_dir_path(__FILE__) . 'attach_unattach_reattach.php');
23
24 function wpatt_format_bytes($a_bytes)
25 {
26
27 if ($a_bytes < 1024)
28 {
29
30 return '< 1KB';
31
32 }
33 elseif ($a_bytes < 1048576)
34 {
35
36 return round($a_bytes / 1024, 2) . ' KB';
37
38 }
39 elseif ($a_bytes < 1073741824)
40 {
41
42 return round($a_bytes / 1048576, 2) . ' MB';
43
44 }
45 elseif ($a_bytes < 1099511627776)
46 {
47
48 return round($a_bytes / 1073741824, 2) . ' GB';
49
50 }
51 else
52 {
53
54 return round($a_bytes / 1208925819614629174706176, 2) . ' ERROR';
55
56 }
57
58 }
59
60
61 add_filter('the_content', 'wpatt_job_cpt_template_filter');
62
63 function wpatt_job_cpt_template_filter($content)
64 {
65 global $post;
66 $somethingtoshow = 0;
67 $content_l = null;
68
69 if ($post->ID == '0' || $post->ID == NULL) { return $content; } //Skip the attachments list if POST ID is null
70
71 $attachments = get_posts(array(
72 'post_type' => 'attachment',
73 'orderby' => 'menu_order',
74 'order' => 'ASC',
75 'posts_per_page' => 100,
76 'post_parent' => $post->ID
77 ));
78
79 if ($attachments)
80 {
81 $content_l .= '<div style="width:100%;float:left;margin:10px 0 10px 0;"><h3>' . get_option('wpatt_option_localization') . '</h3>
82 <ul class="post-attachments">';
83
84 foreach ($attachments as $attachment)
85 {
86
87 $wpatt_option_includeimages_get = get_option('wpatt_option_includeimages');
88 if ($wpatt_option_includeimages_get == '1') {
89 } else if ( wp_attachment_is_image( $attachment->ID ) ) {
90 continue;
91 }
92 $somethingtoshow = 1;
93
94 $class = "post-attachment mime-" . sanitize_title($attachment->post_mime_type);
95
96 $wpatt_option_targetblank_get = get_option('wpatt_option_targetblank');
97
98 $content_l .= '<li class="' . $class . '"><a ';
99
100 if ($wpatt_option_targetblank_get == '1') { $content_l .= 'target="_blank" '; }
101
102 if ((file_exists(get_attached_file($attachment->ID)))) {
103 $wpatt_fs = wpatt_format_bytes(filesize(get_attached_file($attachment->ID)));
104 } else {
105 $wpatt_fs = 'not found';
106 }
107
108 $content_l .= 'href="' . wp_get_attachment_url($attachment->ID) . '">' . $attachment->post_title . '</a> (' . $wpatt_fs;
109
110
111 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
112
113 if ($wpatt_option_showdate_get == '1')
114 {
115
116 $wpatt_date = new DateTime($attachment->post_date);
117
118 $content_l .= '<div style="float:right;">' . $wpatt_date->format('d.m.Y') . '</div>';
119
120 }
121
122 $content_l .= ')</li>';
123
124 }
125 $content_l .= '</ul></div>';
126
127 }
128 if ($somethingtoshow == 1) {
129 $content .= $content_l;
130 }
131 return $content;
132 }
133
134
135 /* Register Settings */
136
137 add_action('admin_init', 'wpatt_reg_settings');
138
139 function wpatt_reg_settings()
140 {
141
142 register_setting('wpatt_options_group', 'wpatt_option_showdate', 'intval');
143
144 register_setting('wpatt_options_group', 'wpatt_option_includeimages', 'intval');
145
146 register_setting('wpatt_options_group', 'wpatt_option_localization');
147
148 register_setting('wpatt_options_group', 'wpatt_disable_backend');
149
150 register_setting('wpatt_options_group', 'wpatt_option_targetblank', 'intval');
151
152 /* Preopulate 'Attachments' */
153
154 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
155
156 if (get_option('wpatt_option_localization') == '')
157 {
158 $value = __('Attachments','wp-attachments');
159 update_option('wpatt_option_localization', $value);
160 }
161 }
162
163 add_action('admin_menu', 'wpatt_plugin_menu');
164
165 function wpatt_plugin_menu(){
166 add_options_page('WP Attachments - Settings', 'WP Attachments', 'manage_options', 'wpatt-option-page', 'wpatt_plugin_options');
167 }
168
169 ?>