PluginProbe
WP Attachments / 3.2.1
WP Attachments v3.2.1
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.2.1, at wp-attachments.php

152 lines 4.2 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.2.1
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.2.1' );
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
23 function wpatt_format_bytes($a_bytes)
24 {
25
26 if ($a_bytes < 1024)
27 {
28
29 return $a_bytes . ' B';
30
31 }
32 elseif ($a_bytes < 1048576)
33 {
34
35 return round($a_bytes / 1024, 2) . ' KB';
36
37 }
38 elseif ($a_bytes < 1073741824)
39 {
40
41 return round($a_bytes / 1048576, 2) . ' MB';
42
43 }
44 elseif ($a_bytes < 1099511627776)
45 {
46
47 return round($a_bytes / 1073741824, 2) . ' GB';
48
49 }
50 else
51 {
52
53 return round($a_bytes / 1208925819614629174706176, 2) . ' ERROR';
54
55 }
56
57 }
58
59
60 add_filter('the_content', 'wpatt_job_cpt_template_filter');
61
62 function wpatt_job_cpt_template_filter($content)
63 {
64 global $post;
65 $somethingtoshow = 0;
66
67 $attachments = get_posts(array(
68 'post_type' => 'attachment',
69 'orderby' => 'menu_order',
70 'order' => 'ASC',
71 'posts_per_page' => 100,
72 'post_parent' => $post->ID
73 ));
74
75 if ($attachments)
76 {
77 $content_l .= '<div style="width:100%;float:left;margin:10px 0 10px 0;"><h3>' . get_option('wpatt_option_localization') . '</h3>
78 <ul class="post-attachments">';
79
80 foreach ($attachments as $attachment)
81 {
82
83 $wpatt_option_includeimages_get = get_option('wpatt_option_includeimages');
84 if ($wpatt_option_includeimages_get == '1') {
85 } else if ( wp_attachment_is_image( $attachment->ID ) ) {
86 continue;
87 }
88 $somethingtoshow = 1;
89
90 $class = "post-attachment mime-" . sanitize_title($attachment->post_mime_type);
91
92 $content_l .= '<li class="' . $class . '"><a href="' . wp_get_attachment_url($attachment->ID) . '">' . $attachment->post_title . '</a> (' . wpatt_format_bytes(filesize(get_attached_file($attachment->ID)));
93
94
95 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
96
97 if ($wpatt_option_showdate_get == '1')
98 {
99
100 $wpatt_date = new DateTime($attachment->post_date);
101
102 $content_l .= '<div style="float:right;">' . $wpatt_date->format('d.m.Y') . '</div>';
103
104 }
105
106 $content_l .= ')</li>';
107
108 }
109 $content_l .= '</ul></div>';
110
111 }
112 if ($somethingtoshow == 1) {
113 $content .= $content_l;
114 }
115 return $content;
116 }
117
118
119 /* Register Settings */
120
121 add_action('admin_init', 'wpatt_reg_settings');
122
123 function wpatt_reg_settings()
124 {
125
126 register_setting('wpatt_options_group', 'wpatt_option_showdate', 'intval');
127
128 register_setting('wpatt_options_group', 'wpatt_option_includeimages', 'intval');
129
130 register_setting('wpatt_options_group', 'wpatt_option_localization');
131
132 register_setting('wpatt_options_group', 'wpatt_disable_backend');
133
134 /* Preopulate 'Attachments' */
135
136 $wpatt_option_showdate_get = get_option('wpatt_option_showdate');
137
138 if (get_option('wpatt_option_localization') == '')
139 {
140 $value = __('Attachments','wp-attachments');
141 update_option('wpatt_option_localization', $value);
142 }
143 }
144
145 add_action('admin_menu', 'wpatt_plugin_menu');
146
147 function wpatt_plugin_menu(){
148 add_options_page('WP Attachments - Settings', 'WP Attachments', 'manage_options', 'wpatt-option-page', 'wpatt_plugin_options');
149 }
150
151
152 ?>