| 1 |
<?php // User Submitted Posts - Core Functions |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die(); |
| 4 |
|
| 5 |
function usp_auto_display_images($content) { |
| 6 |
|
| 7 |
global $usp_options; |
| 8 |
|
| 9 |
$enable = isset($usp_options['auto_display_images']) ? $usp_options['auto_display_images'] : 'disable'; |
| 10 |
|
| 11 |
if (usp_is_public_submission() && ($enable === 'before' || $enable === 'after')) { |
| 12 |
|
| 13 |
$markup = isset($usp_options['auto_image_markup']) ? $usp_options['auto_image_markup'] : ''; |
| 14 |
$author = get_post_meta(get_the_ID(), 'user_submit_name', true); |
| 15 |
|
| 16 |
$args = array( |
| 17 |
'post_type' => 'attachment', |
| 18 |
'post_parent' => get_the_ID(), |
| 19 |
'numberposts' => -1, |
| 20 |
); |
| 21 |
|
| 22 |
$args = apply_filters('usp_image_args', $args); |
| 23 |
|
| 24 |
$attachments = get_posts($args); |
| 25 |
|
| 26 |
if ($attachments) { |
| 27 |
|
| 28 |
$images = '<p>'; |
| 29 |
|
| 30 |
foreach ($attachments as $attachment) { |
| 31 |
|
| 32 |
$title = apply_filters('usp_image_title', $attachment->post_title); |
| 33 |
|
| 34 |
$thumb = apply_filters('usp_image_thumb', wp_get_attachment_image_src($attachment->ID, 'thumbnail', false)); |
| 35 |
$medium = apply_filters('usp_image_medium', wp_get_attachment_image_src($attachment->ID, 'medium', false)); |
| 36 |
$large = apply_filters('usp_image_large', wp_get_attachment_image_src($attachment->ID, 'large', false)); |
| 37 |
$full = apply_filters('usp_image_full', wp_get_attachment_image_src($attachment->ID, 'full', false)); |
| 38 |
|
| 39 |
$custom_size = apply_filters('usp_image_custom_size', 'custom'); |
| 40 |
$custom = apply_filters('usp_image_custom', wp_get_attachment_image_src($attachment->ID, $custom_size, false)); |
| 41 |
|
| 42 |
$parent_id = wp_get_post_parent_id($attachment->ID); |
| 43 |
$parent_title = get_the_title($parent_id); |
| 44 |
|
| 45 |
$url = apply_filters('usp_url_custom_field', get_post_meta(get_the_ID(), 'user_submit_url', true)); |
| 46 |
|
| 47 |
$images .= usp_replace_image_vars($markup, $title, $thumb, $medium, $large, $full, $custom, $parent_title, $author, $url); |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
$images .= '</p>'; |
| 52 |
|
| 53 |
if ($enable === 'before') $content = $images . $content; |
| 54 |
elseif ($enable === 'after') $content = $content . $images; |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
return $content; |
| 61 |
|
| 62 |
} |
| 63 |
add_filter('the_content', 'usp_auto_display_images'); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
function usp_replace_image_vars($markup, $title, $thumb, $medium, $large, $full, $custom, $parent_title, $author, $url) { |
| 68 |
|
| 69 |
$patterns = array(); |
| 70 |
$patterns[0] = "/%%title%%/"; |
| 71 |
$patterns[1] = "/%%thumb%%/"; |
| 72 |
$patterns[2] = "/%%medium%%/"; |
| 73 |
$patterns[3] = "/%%large%%/"; |
| 74 |
$patterns[4] = "/%%full%%/"; |
| 75 |
$patterns[5] = "/%%custom%%/"; |
| 76 |
$patterns[6] = "/%%width%%/"; |
| 77 |
$patterns[7] = "/%%height%%/"; |
| 78 |
$patterns[8] = "/%%title_parent%%/"; |
| 79 |
$patterns[9] = "/%%author%%/"; |
| 80 |
$patterns[10] = "/%%url%%/"; |
| 81 |
|
| 82 |
$replacements = array(); |
| 83 |
$replacements[0] = esc_attr($title); |
| 84 |
$replacements[1] = esc_url($thumb[0]); |
| 85 |
$replacements[2] = esc_url($medium[0]); |
| 86 |
$replacements[3] = esc_url($large[0]); |
| 87 |
$replacements[4] = esc_url($full[0]); |
| 88 |
$replacements[5] = esc_url($custom[0]); |
| 89 |
|
| 90 |
if (stripos($markup, '%%thumb%%')) { |
| 91 |
|
| 92 |
$replacements[6] = esc_attr($thumb[1]); |
| 93 |
$replacements[7] = esc_attr($thumb[2]); |
| 94 |
|
| 95 |
} elseif (stripos($markup, '%%medium%%')) { |
| 96 |
|
| 97 |
$replacements[6] = esc_attr($medium[1]); |
| 98 |
$replacements[7] = esc_attr($medium[2]); |
| 99 |
|
| 100 |
} elseif (stripos($markup, '%%large%%')) { |
| 101 |
|
| 102 |
$replacements[6] = esc_attr($large[1]); |
| 103 |
$replacements[7] = esc_attr($large[2]); |
| 104 |
|
| 105 |
} elseif (stripos($markup, '%%full%%')) { |
| 106 |
|
| 107 |
$replacements[6] = esc_attr($full[1]); |
| 108 |
$replacements[7] = esc_attr($full[2]); |
| 109 |
|
| 110 |
} elseif (stripos($markup, '%%custom%%')) { |
| 111 |
|
| 112 |
$replacements[6] = esc_attr($custom[1]); |
| 113 |
$replacements[7] = esc_attr($custom[2]); |
| 114 |
} |
| 115 |
|
| 116 |
$replacements[8] = esc_attr($parent_title); |
| 117 |
$replacements[9] = esc_attr($author); |
| 118 |
$replacements[10] = esc_url($url); |
| 119 |
|
| 120 |
$image = preg_replace($patterns, $replacements, $markup); |
| 121 |
|
| 122 |
return $image; |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
function usp_auto_display_email($content) { |
| 129 |
|
| 130 |
global $usp_options; |
| 131 |
|
| 132 |
$enable = isset($usp_options['auto_display_email']) ? $usp_options['auto_display_email'] : 'disable'; |
| 133 |
|
| 134 |
if (usp_is_public_submission() && ($enable === 'before' || $enable === 'after')) { |
| 135 |
|
| 136 |
$markup = isset($usp_options['auto_email_markup']) ? $usp_options['auto_email_markup'] : ''; |
| 137 |
$author = apply_filters('usp_author_custom_field', get_post_meta(get_the_ID(), 'user_submit_name', true)); |
| 138 |
$email = apply_filters('usp_email_custom_field', get_post_meta(get_the_ID(), 'user_submit_email', true)); |
| 139 |
$title = get_the_title(get_the_ID()); |
| 140 |
|
| 141 |
if (!empty($email)) { |
| 142 |
|
| 143 |
$patterns = array(); |
| 144 |
$patterns[0] = "/%%author%%/"; |
| 145 |
$patterns[1] = "/%%email%%/"; |
| 146 |
$patterns[2] = "/%%title%%/"; |
| 147 |
|
| 148 |
$replacements = array(); |
| 149 |
$replacements[0] = esc_attr($author); |
| 150 |
$replacements[1] = esc_attr($email); |
| 151 |
$replacements[2] = esc_attr($title); |
| 152 |
|
| 153 |
$markup = preg_replace($patterns, $replacements, $markup); |
| 154 |
|
| 155 |
if ($enable === 'before') $content = $markup . $content; |
| 156 |
elseif ($enable === 'after') $content = $content . $markup; |
| 157 |
|
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
return $content; |
| 163 |
|
| 164 |
} |
| 165 |
add_filter('the_content', 'usp_auto_display_email'); |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
function usp_auto_display_name($content) { |
| 170 |
|
| 171 |
global $usp_options; |
| 172 |
|
| 173 |
$enable = isset($usp_options['auto_display_name']) ? $usp_options['auto_display_name'] : 'disable'; |
| 174 |
|
| 175 |
if (usp_is_public_submission() && ($enable === 'before' || $enable === 'after')) { |
| 176 |
|
| 177 |
$markup = isset($usp_options['auto_name_markup']) ? $usp_options['auto_name_markup'] : ''; |
| 178 |
|
| 179 |
$author = apply_filters('usp_author_custom_field', get_post_meta(get_the_ID(), 'user_submit_name', true)); |
| 180 |
|
| 181 |
if (!empty($author)) { |
| 182 |
|
| 183 |
$patterns = array(); |
| 184 |
$patterns[0] = "/%%author%%/"; |
| 185 |
|
| 186 |
$replacements = array(); |
| 187 |
$replacements[0] = esc_attr($author); |
| 188 |
|
| 189 |
$markup = preg_replace($patterns, $replacements, $markup); |
| 190 |
|
| 191 |
if ($enable === 'before') $content = $markup . $content; |
| 192 |
elseif ($enable === 'after') $content = $content . $markup; |
| 193 |
|
| 194 |
} |
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
return $content; |
| 199 |
|
| 200 |
} |
| 201 |
add_filter('the_content', 'usp_auto_display_name'); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
function usp_auto_display_url($content) { |
| 206 |
|
| 207 |
global $usp_options; |
| 208 |
|
| 209 |
$enable = isset($usp_options['auto_display_url']) ? $usp_options['auto_display_url'] : 'disable'; |
| 210 |
|
| 211 |
if (usp_is_public_submission() && ($enable === 'before' || $enable === 'after')) { |
| 212 |
|
| 213 |
$markup = isset($usp_options['auto_url_markup']) ? $usp_options['auto_url_markup'] : ''; |
| 214 |
$author = apply_filters('usp_author_custom_field', get_post_meta(get_the_ID(), 'user_submit_name', true)); |
| 215 |
$url = apply_filters('usp_url_custom_field', get_post_meta(get_the_ID(), 'user_submit_url', true)); |
| 216 |
$title = get_the_title(get_the_ID()); |
| 217 |
|
| 218 |
if (!empty($url)) { |
| 219 |
|
| 220 |
$patterns = array(); |
| 221 |
$patterns[0] = "/%%author%%/"; |
| 222 |
$patterns[1] = "/%%url%%/"; |
| 223 |
$patterns[2] = "/%%title%%/"; |
| 224 |
|
| 225 |
$replacements = array(); |
| 226 |
$replacements[0] = esc_attr($author); |
| 227 |
$replacements[1] = esc_url($url); |
| 228 |
$replacements[2] = esc_attr($title); |
| 229 |
|
| 230 |
$markup = preg_replace($patterns, $replacements, $markup); |
| 231 |
|
| 232 |
if ($enable === 'before') $content = $markup . $content; |
| 233 |
elseif ($enable === 'after') $content = $content . $markup; |
| 234 |
|
| 235 |
} |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
return $content; |
| 240 |
|
| 241 |
} |
| 242 |
add_filter('the_content', 'usp_auto_display_url'); |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
function usp_auto_display_custom_2($content) { |
| 247 |
|
| 248 |
global $usp_options; |
| 249 |
|
| 250 |
$enable = isset($usp_options['auto_display_custom_2']) ? $usp_options['auto_display_custom_2'] : 'disable'; |
| 251 |
|
| 252 |
if (usp_is_public_submission() && ($enable === 'before' || $enable === 'after')) { |
| 253 |
|
| 254 |
$markup = isset($usp_options['auto_custom_markup_2']) ? $usp_options['auto_custom_markup_2'] : ''; |
| 255 |
$label = isset($usp_options['custom_label_2']) ? $usp_options['custom_label_2'] : __('Custom Field 2', 'usp'); |
| 256 |
$name = isset($usp_options['custom_name_2']) ? $usp_options['custom_name_2'] : 'usp_custom_field_2'; |
| 257 |
|
| 258 |
$author = apply_filters('usp_author_custom_field_2', get_post_meta(get_the_ID(), 'user_submit_name', true)); |
| 259 |
$value = apply_filters('usp_custom_custom_field_2', get_post_meta(get_the_ID(), $name, true)); |
| 260 |
$title = get_the_title(get_the_ID()); |
| 261 |
|
| 262 |
if (!empty($value)) { |
| 263 |
|
| 264 |
$value = htmlspecialchars_decode($value); |
| 265 |
$value = nl2br($value); |
| 266 |
|
| 267 |
$patterns = array(); |
| 268 |
$patterns[0] = "/%%author%%/"; |
| 269 |
$patterns[1] = "/%%custom_label_2%%/"; |
| 270 |
$patterns[2] = "/%%custom_name_2%%/"; |
| 271 |
$patterns[3] = "/%%custom_value_2%%/"; |
| 272 |
$patterns[4] = "/%%title%%/"; |
| 273 |
|
| 274 |
$replacements = array(); |
| 275 |
$replacements[0] = esc_attr(wp_kses_post($author)); |
| 276 |
$replacements[1] = esc_attr(wp_kses_post($label)); |
| 277 |
$replacements[2] = esc_attr(wp_kses_post($name)); |
| 278 |
$replacements[3] = esc_attr(wp_kses_post($value)); |
| 279 |
$replacements[4] = esc_attr(wp_kses_post($title)); |
| 280 |
|
| 281 |
$markup = preg_replace($patterns, $replacements, $markup); |
| 282 |
|
| 283 |
if ($enable === 'before') $content = $markup . $content; |
| 284 |
elseif ($enable === 'after') $content = $content . $markup; |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
return $content; |
| 291 |
|
| 292 |
} |
| 293 |
add_filter('the_content', 'usp_auto_display_custom_2'); |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
function usp_auto_display_custom($content) { |
| 298 |
|
| 299 |
global $usp_options; |
| 300 |
|
| 301 |
$enable = isset($usp_options['auto_display_custom']) ? $usp_options['auto_display_custom'] : 'disable'; |
| 302 |
|
| 303 |
if (usp_is_public_submission() && ($enable === 'before' || $enable === 'after')) { |
| 304 |
|
| 305 |
$markup = isset($usp_options['auto_custom_markup']) ? $usp_options['auto_custom_markup'] : ''; |
| 306 |
$label = isset($usp_options['custom_label']) ? $usp_options['custom_label'] : __('Custom Field 1', 'usp'); |
| 307 |
$name = isset($usp_options['custom_name']) ? $usp_options['custom_name'] : 'usp_custom_field'; |
| 308 |
|
| 309 |
$author = apply_filters('usp_author_custom_field', get_post_meta(get_the_ID(), 'user_submit_name', true)); |
| 310 |
$value = apply_filters('usp_custom_custom_field', get_post_meta(get_the_ID(), $name, true)); |
| 311 |
$title = get_the_title(get_the_ID()); |
| 312 |
|
| 313 |
if (!empty($value)) { |
| 314 |
|
| 315 |
$value = htmlspecialchars_decode($value); |
| 316 |
$value = nl2br($value); |
| 317 |
|
| 318 |
$patterns = array(); |
| 319 |
$patterns[0] = "/%%author%%/"; |
| 320 |
$patterns[1] = "/%%custom_label%%/"; |
| 321 |
$patterns[2] = "/%%custom_name%%/"; |
| 322 |
$patterns[3] = "/%%custom_value%%/"; |
| 323 |
$patterns[4] = "/%%title%%/"; |
| 324 |
|
| 325 |
$replacements = array(); |
| 326 |
$replacements[0] = esc_attr(wp_kses_post($author)); |
| 327 |
$replacements[1] = esc_attr(wp_kses_post($label)); |
| 328 |
$replacements[2] = esc_attr(wp_kses_post($name)); |
| 329 |
$replacements[3] = esc_attr(wp_kses_post($value)); |
| 330 |
$replacements[4] = esc_attr(wp_kses_post($title)); |
| 331 |
|
| 332 |
$markup = preg_replace($patterns, $replacements, $markup); |
| 333 |
|
| 334 |
if ($enable === 'before') $content = $markup . $content; |
| 335 |
elseif ($enable === 'after') $content = $content . $markup; |
| 336 |
|
| 337 |
} |
| 338 |
|
| 339 |
} |
| 340 |
|
| 341 |
return $content; |
| 342 |
|
| 343 |
} |
| 344 |
add_filter('the_content', 'usp_auto_display_custom'); |
| 345 |
|