| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: User Submitted Posts |
| 4 |
Plugin URI: https://perishablepress.com/user-submitted-posts/ |
| 5 |
Description: Enables your visitors to submit posts and images from anywhere on your site. |
| 6 |
Tags: frontend post, submit post, guest post, visitor post, public post |
| 7 |
Author: Jeff Starr |
| 8 |
Author URI: https://plugin-planet.com/ |
| 9 |
Donate link: https://monzillamedia.com/donate.html |
| 10 |
Contributors: specialk |
| 11 |
Requires at least: 4.6 |
| 12 |
Tested up to: 6.6 |
| 13 |
Stable tag: 20240703 |
| 14 |
Version: 20240703 |
| 15 |
Requires PHP: 5.6.20 |
| 16 |
Text Domain: usp |
| 17 |
Domain Path: /languages |
| 18 |
License: GPL v2 or later |
| 19 |
*/ |
| 20 |
|
| 21 |
/* |
| 22 |
This program is free software; you can redistribute it and/or |
| 23 |
modify it under the terms of the GNU General Public License |
| 24 |
as published by the Free Software Foundation; either version |
| 25 |
2 of the License, or (at your option) any later version. |
| 26 |
|
| 27 |
This program is distributed in the hope that it will be useful, |
| 28 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 |
GNU General Public License for more details. |
| 31 |
|
| 32 |
You should have received a copy of the GNU General Public License |
| 33 |
with this program. If not, visit: https://www.gnu.org/licenses/ |
| 34 |
|
| 35 |
Copyright 2024 Monzilla Media. All rights reserved. |
| 36 |
*/ |
| 37 |
|
| 38 |
if (!defined('ABSPATH')) die(); |
| 39 |
|
| 40 |
if (!defined('USP_WP_VERSION')) define('USP_WP_VERSION', '4.6'); |
| 41 |
if (!defined('USP_VERSION')) define('USP_VERSION', '20240703'); |
| 42 |
if (!defined('USP_PLUGIN')) define('USP_PLUGIN', esc_html__('User Submitted Posts', 'usp')); |
| 43 |
if (!defined('USP_FILE')) define('USP_FILE', plugin_basename(__FILE__)); |
| 44 |
if (!defined('USP_PATH')) define('USP_PATH', plugin_dir_path(__FILE__)); |
| 45 |
if (!defined('USP_URL')) define('USP_URL', plugin_dir_url (__FILE__)); |
| 46 |
|
| 47 |
$usp_options = get_option('usp_options'); |
| 48 |
|
| 49 |
require_once('library/core-functions.php'); |
| 50 |
require_once('library/form-functions.php'); |
| 51 |
require_once('library/enqueue-scripts.php'); |
| 52 |
require_once('library/plugin-display.php'); |
| 53 |
require_once('library/plugin-settings.php'); |
| 54 |
require_once('library/shortcode-access.php'); |
| 55 |
require_once('library/shortcode-login.php'); |
| 56 |
require_once('library/shortcode-misc.php'); |
| 57 |
require_once('library/template-tags.php'); |
| 58 |
|
| 59 |
register_activation_hook(__FILE__, 'usp_add_defaults'); |
| 60 |
register_activation_hook(__FILE__, 'usp_dismiss_notice_activate'); |
| 61 |
|
| 62 |
if (isset($usp_options['default_options']) && $usp_options['default_options'] == 1) { |
| 63 |
|
| 64 |
register_deactivation_hook(__FILE__, 'usp_delete_plugin_options'); |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
// |
| 69 |
|
| 70 |
function usp_i18n_init() { |
| 71 |
|
| 72 |
$domain = 'usp'; |
| 73 |
|
| 74 |
$locale = apply_filters('usp_locale', get_locale(), $domain); |
| 75 |
|
| 76 |
$dir = trailingslashit(WP_LANG_DIR); |
| 77 |
|
| 78 |
$file = $domain .'-'. $locale .'.mo'; |
| 79 |
|
| 80 |
$path_1 = $dir . $file; |
| 81 |
|
| 82 |
$path_2 = $dir . $domain .'/'. $file; |
| 83 |
|
| 84 |
$path_3 = $dir .'plugins/'. $file; |
| 85 |
|
| 86 |
$path_4 = $dir .'plugins/'. $domain .'/'. $file; |
| 87 |
|
| 88 |
$paths = array($path_1, $path_2, $path_3, $path_4); |
| 89 |
|
| 90 |
foreach ($paths as $path) { |
| 91 |
|
| 92 |
if ($loaded = load_textdomain($domain, $path)) { |
| 93 |
|
| 94 |
return $loaded; |
| 95 |
|
| 96 |
} else { |
| 97 |
|
| 98 |
return load_plugin_textdomain($domain, false, dirname(USP_FILE) .'/languages/'); |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
} |
| 105 |
add_action('init', 'usp_i18n_init'); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
function usp_require_wp_version() { |
| 110 |
|
| 111 |
$wp_version = get_bloginfo('version'); |
| 112 |
|
| 113 |
if (isset($_GET['activate']) && $_GET['activate'] == 'true') { |
| 114 |
|
| 115 |
if (version_compare($wp_version, USP_WP_VERSION, '<')) { |
| 116 |
|
| 117 |
if (is_plugin_active(USP_FILE)) { |
| 118 |
|
| 119 |
deactivate_plugins(USP_FILE); |
| 120 |
|
| 121 |
$msg = '<strong>'. USP_PLUGIN .'</strong> '; |
| 122 |
$msg .= esc_html__('requires WordPress ', 'usp') . USP_WP_VERSION; |
| 123 |
$msg .= esc_html__(' or higher, and has been deactivated! ', 'usp'); |
| 124 |
$msg .= esc_html__('Please return to the', 'usp') .' <a href="'. admin_url() .'">'; |
| 125 |
$msg .= esc_html__('WordPress Admin Area', 'usp') .'</a> '; |
| 126 |
$msg .= esc_html__('to upgrade WordPress and try again.', 'usp'); |
| 127 |
|
| 128 |
wp_die($msg); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
} |
| 137 |
add_action('admin_init', 'usp_require_wp_version'); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
if (!current_theme_supports('post-thumbnails')) { |
| 142 |
|
| 143 |
if (isset($usp_options['usp_featured_images']) && $usp_options['usp_featured_images']) { |
| 144 |
|
| 145 |
add_theme_support('post-thumbnails'); |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
if (isset($usp_options['enable_shortcodes']) && $usp_options['enable_shortcodes']) { |
| 154 |
|
| 155 |
// add_filter('the_content', 'do_shortcode', 10); |
| 156 |
add_filter('widget_text', 'do_shortcode', 10); |
| 157 |
|
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
function usp_check_required($field) { |
| 163 |
|
| 164 |
global $usp_options; |
| 165 |
|
| 166 |
if ($usp_options[$field] === 'show') return true; |
| 167 |
|
| 168 |
else return false; |
| 169 |
|
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
function usp_get_date_time() { |
| 175 |
|
| 176 |
$date_format = get_option('date_format'); |
| 177 |
|
| 178 |
$time_format = get_option('time_format'); |
| 179 |
|
| 180 |
if (function_exists('current_datetime')) { |
| 181 |
|
| 182 |
$format = $date_format .' \@ '. $time_format; |
| 183 |
|
| 184 |
$date = current_datetime()->format($format); |
| 185 |
|
| 186 |
} else { |
| 187 |
|
| 188 |
$date = date_i18n($date_format, current_time('timestamp')) .' \@ '. date_i18n($time_format, current_time('timestamp')); |
| 189 |
|
| 190 |
} |
| 191 |
|
| 192 |
return apply_filters('usp_date_time', $date); |
| 193 |
|
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
function usp_get_default_title() { |
| 199 |
|
| 200 |
$date = usp_get_date_time(); |
| 201 |
|
| 202 |
$title = esc_html__('User Submitted Post', 'usp'); |
| 203 |
|
| 204 |
$title = apply_filters('usp_default_title', $title, $date); |
| 205 |
|
| 206 |
return $title; |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
function usp_get_submitted_title() { |
| 213 |
|
| 214 |
global $usp_options; |
| 215 |
|
| 216 |
$option = isset($usp_options['usp_title']) ? $usp_options['usp_title'] : null; |
| 217 |
|
| 218 |
$title = usp_get_default_title(); |
| 219 |
|
| 220 |
$allow_tags = apply_filters('usp_title_tags_allow', false); |
| 221 |
$allowed_tags = apply_filters('usp_title_tags_allowed', '<em><i><strong><b>'); |
| 222 |
|
| 223 |
if (isset($_POST['user-submitted-title'])) { |
| 224 |
|
| 225 |
$title = $allow_tags ? strip_tags($_POST['user-submitted-title'], $allowed_tags) : sanitize_text_field($_POST['user-submitted-title']); |
| 226 |
|
| 227 |
} |
| 228 |
|
| 229 |
if ($option === 'optn' && empty($title)) $title = usp_get_default_title(); |
| 230 |
|
| 231 |
return $title; |
| 232 |
|
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
function usp_get_custom_field() { |
| 238 |
|
| 239 |
global $usp_options; |
| 240 |
|
| 241 |
$name = isset($usp_options['custom_name']) ? $usp_options['custom_name'] : ''; |
| 242 |
|
| 243 |
$custom = isset($_POST[$name]) ? usp_sanitize_content($_POST[$name]) : ''; |
| 244 |
|
| 245 |
return $custom; |
| 246 |
|
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
function usp_get_custom_field_2() { |
| 252 |
|
| 253 |
global $usp_options; |
| 254 |
|
| 255 |
$name = isset($usp_options['custom_name_2']) ? $usp_options['custom_name_2'] : ''; |
| 256 |
|
| 257 |
$custom = isset($_POST[$name]) ? usp_sanitize_content($_POST[$name]) : ''; |
| 258 |
|
| 259 |
return $custom; |
| 260 |
|
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
function usp_get_custom_checkbox() { |
| 266 |
|
| 267 |
global $usp_options; |
| 268 |
|
| 269 |
$name = isset($usp_options['custom_checkbox_name']) ? $usp_options['custom_checkbox_name'] : ''; |
| 270 |
|
| 271 |
$custom = isset($_POST[$name]) ? usp_sanitize_content($_POST[$name]) : ''; |
| 272 |
|
| 273 |
return $custom; |
| 274 |
|
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
function usp_get_comment_status() { |
| 280 |
|
| 281 |
global $usp_options; |
| 282 |
|
| 283 |
$post_type = isset($usp_options['usp_post_type']) ? $usp_options['usp_post_type'] : 'post'; |
| 284 |
|
| 285 |
$post_type = apply_filters('usp_post_type', $post_type); |
| 286 |
|
| 287 |
$default = get_default_comment_status($post_type); |
| 288 |
|
| 289 |
return isset($_POST['user-submitted-comments']) ? 'closed' : $default; |
| 290 |
|
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
function usp_get_submitted_category() { |
| 296 |
|
| 297 |
$category = isset($_POST['user-submitted-category']) ? $_POST['user-submitted-category'] : ''; |
| 298 |
|
| 299 |
if (is_array($category)) { |
| 300 |
|
| 301 |
$cats = array(); |
| 302 |
|
| 303 |
foreach ($category as $cat) $cats[] = sanitize_text_field($cat); |
| 304 |
|
| 305 |
} else { |
| 306 |
|
| 307 |
if (strpos($category, ',') !== false) { |
| 308 |
|
| 309 |
$cats = array_map('trim', explode(',', $category)); |
| 310 |
|
| 311 |
} else { |
| 312 |
|
| 313 |
$cats = sanitize_text_field($category); |
| 314 |
|
| 315 |
} |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
return $cats; |
| 320 |
|
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
function usp_get_submitted_tags() { |
| 326 |
|
| 327 |
$submitted_tags = isset($_POST['user-submitted-tags']) ? $_POST['user-submitted-tags'] : ''; |
| 328 |
|
| 329 |
$tags = array(); |
| 330 |
|
| 331 |
if (is_array($submitted_tags)) { |
| 332 |
|
| 333 |
foreach ($submitted_tags as $tag) $tags[] = sanitize_text_field($tag); |
| 334 |
|
| 335 |
} else { |
| 336 |
|
| 337 |
if (strpos($submitted_tags, ',') !== false) { |
| 338 |
|
| 339 |
$tag_array = array_map('trim', explode(',', $submitted_tags)); |
| 340 |
|
| 341 |
foreach ($tag_array as $tag) $tags[] = sanitize_text_field($tag); |
| 342 |
|
| 343 |
} else { |
| 344 |
|
| 345 |
$tags[] = sanitize_text_field($submitted_tags); |
| 346 |
|
| 347 |
} |
| 348 |
|
| 349 |
} |
| 350 |
|
| 351 |
return $tags; |
| 352 |
|
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
function usp_get_ip_address() { |
| 358 |
|
| 359 |
if (isset($_SERVER)) { |
| 360 |
|
| 361 |
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 362 |
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; |
| 363 |
|
| 364 |
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { |
| 365 |
$ip_address = $_SERVER['HTTP_CLIENT_IP']; |
| 366 |
|
| 367 |
} else { |
| 368 |
$ip_address = $_SERVER['REMOTE_ADDR']; |
| 369 |
|
| 370 |
} |
| 371 |
|
| 372 |
} else { |
| 373 |
|
| 374 |
if (getenv('HTTP_X_FORWARDED_FOR')) { |
| 375 |
$ip_address = getenv('HTTP_X_FORWARDED_FOR'); |
| 376 |
|
| 377 |
} elseif (getenv('HTTP_CLIENT_IP')) { |
| 378 |
$ip_address = getenv('HTTP_CLIENT_IP'); |
| 379 |
|
| 380 |
} else { |
| 381 |
$ip_address = getenv('REMOTE_ADDR'); |
| 382 |
|
| 383 |
} |
| 384 |
|
| 385 |
} |
| 386 |
|
| 387 |
return sanitize_text_field($ip_address); |
| 388 |
|
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
function usp_checkForPublicSubmission() { |
| 394 |
|
| 395 |
global $usp_options; |
| 396 |
|
| 397 |
$is_submitted = (isset($_POST['usp-nonce']) && wp_verify_nonce($_POST['usp-nonce'], 'usp-nonce')) ? true : false; |
| 398 |
|
| 399 |
$is_allowed = apply_filters('usp_check_if_allowed', true); |
| 400 |
|
| 401 |
if ($is_submitted && $is_allowed) { |
| 402 |
|
| 403 |
$title = usp_get_submitted_title(); |
| 404 |
|
| 405 |
$ip = usp_get_ip_address(); |
| 406 |
|
| 407 |
$custom = usp_get_custom_field(); |
| 408 |
|
| 409 |
$custom_2 = usp_get_custom_field_2(); |
| 410 |
|
| 411 |
$checkbox = usp_get_custom_checkbox(); |
| 412 |
|
| 413 |
$comments = usp_get_comment_status(); |
| 414 |
|
| 415 |
$category = usp_get_submitted_category(); |
| 416 |
|
| 417 |
$tags = usp_get_submitted_tags(); |
| 418 |
|
| 419 |
$files = isset($_FILES['user-submitted-image']) ? $_FILES['user-submitted-image'] : array(); |
| 420 |
|
| 421 |
$author = isset($_POST['user-submitted-name']) ? sanitize_text_field($_POST['user-submitted-name']) : ''; |
| 422 |
$url = isset($_POST['user-submitted-url']) ? esc_url($_POST['user-submitted-url']) : ''; |
| 423 |
$email = isset($_POST['user-submitted-email']) ? sanitize_text_field($_POST['user-submitted-email']) : ''; |
| 424 |
$captcha = isset($_POST['user-submitted-captcha']) ? sanitize_text_field($_POST['user-submitted-captcha']) : ''; |
| 425 |
$verify = isset($_POST['user-submitted-verify']) ? sanitize_text_field($_POST['user-submitted-verify']) : ''; |
| 426 |
$content = isset($_POST['user-submitted-content']) ? usp_sanitize_content($_POST['user-submitted-content']) : ''; |
| 427 |
|
| 428 |
$result = usp_createPublicSubmission($title, $files, $ip, $author, $url, $email, $tags, $captcha, $verify, $content, $category, $custom, $custom_2, $checkbox, $comments); |
| 429 |
|
| 430 |
$post_id = false; |
| 431 |
|
| 432 |
if (isset($result['id'])) { |
| 433 |
|
| 434 |
$post_id = $result['id']; |
| 435 |
|
| 436 |
/* Polylang plugin */ |
| 437 |
if (function_exists('pll_set_post_language') && function_exists('pll_default_language')) { |
| 438 |
|
| 439 |
$default_or_current = 'default'; |
| 440 |
$default_or_current = apply_filters('usp_pll_set_post_language', $default_or_current); |
| 441 |
|
| 442 |
if ($default_or_current === 'default') { |
| 443 |
|
| 444 |
pll_set_post_language($post_id, pll_default_language()); |
| 445 |
|
| 446 |
} else { |
| 447 |
|
| 448 |
pll_set_post_language($post_id, pll_current_language()); |
| 449 |
|
| 450 |
} |
| 451 |
|
| 452 |
} |
| 453 |
/* Polylang plugin */ |
| 454 |
|
| 455 |
} |
| 456 |
|
| 457 |
$error = false; |
| 458 |
|
| 459 |
if (isset($result['error']) && !empty($result['error'])) $error = array_filter(array_unique($result['error'])); |
| 460 |
|
| 461 |
if ($error) { |
| 462 |
|
| 463 |
$e = implode(',', $error); |
| 464 |
$e = trim($e, ','); |
| 465 |
|
| 466 |
} else { |
| 467 |
|
| 468 |
$e = 'error'; |
| 469 |
|
| 470 |
} |
| 471 |
|
| 472 |
if ($post_id) { |
| 473 |
|
| 474 |
if (!empty($_POST['redirect-override'])) { |
| 475 |
|
| 476 |
$redirect = $_POST['redirect-override']; |
| 477 |
|
| 478 |
$redirect = remove_query_arg(array('usp-error'), $redirect); |
| 479 |
$redirect = add_query_arg(array('usp_redirect' => '1', 'success' => 1, 'post_id' => $post_id), $redirect); |
| 480 |
|
| 481 |
} else { |
| 482 |
|
| 483 |
$redirect = $_SERVER['REQUEST_URI']; |
| 484 |
|
| 485 |
$redirect = remove_query_arg(array('usp-error'), $redirect); |
| 486 |
$redirect = add_query_arg(array('success' => 1, 'post_id' => $post_id), $redirect); |
| 487 |
|
| 488 |
} |
| 489 |
|
| 490 |
do_action('usp_submit_success', $redirect); |
| 491 |
|
| 492 |
} else { |
| 493 |
|
| 494 |
$redirect = $_SERVER['REQUEST_URI']; |
| 495 |
|
| 496 |
$redirect = remove_query_arg(array('success', 'post_id', 'usp-error'), $redirect); |
| 497 |
$redirect = add_query_arg(array('usp-error' => $e), $redirect); |
| 498 |
|
| 499 |
do_action('usp_submit_error', $redirect); |
| 500 |
|
| 501 |
} |
| 502 |
|
| 503 |
wp_redirect(esc_url_raw($redirect)); |
| 504 |
|
| 505 |
exit(); |
| 506 |
|
| 507 |
} |
| 508 |
|
| 509 |
} |
| 510 |
add_action('parse_request', 'usp_checkForPublicSubmission', 1); |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
function usp_check_recaptcha_keys() { |
| 515 |
|
| 516 |
global $usp_options; |
| 517 |
|
| 518 |
$public = isset($usp_options['recaptcha_public']) ? $usp_options['recaptcha_public'] : ''; |
| 519 |
$private = isset($usp_options['recaptcha_private']) ? $usp_options['recaptcha_private'] : ''; |
| 520 |
|
| 521 |
if (empty($public) || empty($private)) return false; |
| 522 |
|
| 523 |
return true; |
| 524 |
|
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
function usp_verify_recaptcha() { |
| 530 |
|
| 531 |
global $usp_options; |
| 532 |
|
| 533 |
$private = isset($usp_options['recaptcha_private']) ? $usp_options['recaptcha_private'] : ''; |
| 534 |
$version = isset($usp_options['recaptcha_version']) ? $usp_options['recaptcha_version'] : 2; |
| 535 |
|
| 536 |
if (!usp_check_recaptcha_keys()) return false; |
| 537 |
|
| 538 |
if ($version == 3) { |
| 539 |
|
| 540 |
$response = isset($_POST['recaptcha_response']) ? $_POST['recaptcha_response'] : null; |
| 541 |
|
| 542 |
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='. $private .'&response='. $response); |
| 543 |
$recaptcha = json_decode($recaptcha); |
| 544 |
|
| 545 |
$score = apply_filters('usp_recaptcha_score', 0.5); |
| 546 |
|
| 547 |
return (($recaptcha->success == true) && ($recaptcha->score >= $score)) ? true : false; |
| 548 |
|
| 549 |
} else { |
| 550 |
|
| 551 |
if (isset($_POST['g-recaptcha-response'])) return require_once(USP_PATH .'recaptcha/connect.php'); |
| 552 |
|
| 553 |
return false; |
| 554 |
|
| 555 |
} |
| 556 |
|
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
function usp_sanitize_content($content) { |
| 562 |
|
| 563 |
$allowed_tags = wp_kses_allowed_html('post'); |
| 564 |
|
| 565 |
$allowed_tags['style'] = array('types' => array()); |
| 566 |
|
| 567 |
$allowed_tags = apply_filters('usp_content_allowed', $allowed_tags); |
| 568 |
|
| 569 |
$patterns = array( |
| 570 |
'/target="_blank"/i', |
| 571 |
"/target='_blank'/i", |
| 572 |
'/user-submitted-posts/i', |
| 573 |
'/usp-login-form/i', |
| 574 |
'/usp_display_posts/i', |
| 575 |
'/usp_gallery/i', |
| 576 |
'/usp-reset-button/i', |
| 577 |
'/usp_access/i', |
| 578 |
'/usp_visitor/i', |
| 579 |
'/usp_member/i' |
| 580 |
); |
| 581 |
|
| 582 |
$patterns = apply_filters('usp_content_patterns', $patterns); |
| 583 |
|
| 584 |
$replacements = array('', '', '', '', '', '', '', '', '', ''); |
| 585 |
|
| 586 |
$replacements = apply_filters('usp_content_replacements', $replacements); |
| 587 |
|
| 588 |
$content = wp_kses(stripslashes($content), $allowed_tags); |
| 589 |
|
| 590 |
$content = preg_replace($patterns, $replacements, $content); |
| 591 |
|
| 592 |
return $content; |
| 593 |
|
| 594 |
} |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
function usp_add_meta_box() { |
| 599 |
|
| 600 |
global $post; |
| 601 |
|
| 602 |
if (usp_is_public_submission()) { |
| 603 |
|
| 604 |
$screens = array('post', 'page'); |
| 605 |
$screens = apply_filters('usp_meta_box_post_types', $screens); |
| 606 |
|
| 607 |
$name = get_post_meta($post->ID, 'user_submit_name', true); |
| 608 |
$email = get_post_meta($post->ID, 'user_submit_email', true); |
| 609 |
$url = get_post_meta($post->ID, 'user_submit_url', true); |
| 610 |
$ip = get_post_meta($post->ID, 'user_submit_ip', true); |
| 611 |
|
| 612 |
if (!empty($name) || !empty($email) || !empty($url) || !empty($ip)) { |
| 613 |
|
| 614 |
foreach ($screens as $screen) { |
| 615 |
|
| 616 |
add_meta_box('usp_section_id', esc_html__('User Submitted Post Info', 'usp'), 'usp_meta_box_callback', $screen, 'normal'); |
| 617 |
|
| 618 |
} |
| 619 |
|
| 620 |
} |
| 621 |
|
| 622 |
} |
| 623 |
|
| 624 |
} |
| 625 |
add_action('add_meta_boxes', 'usp_add_meta_box'); |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
function usp_meta_box_callback($post) { |
| 630 |
|
| 631 |
global $usp_options; |
| 632 |
|
| 633 |
if (usp_is_public_submission()) { |
| 634 |
|
| 635 |
wp_nonce_field('usp_meta_box_nonce', 'usp_meta_box_nonce'); |
| 636 |
|
| 637 |
$name = get_post_meta($post->ID, 'user_submit_name', true); |
| 638 |
$email = get_post_meta($post->ID, 'user_submit_email', true); |
| 639 |
$url = get_post_meta($post->ID, 'user_submit_url', true); |
| 640 |
$ip = get_post_meta($post->ID, 'user_submit_ip', true); |
| 641 |
|
| 642 |
if (!empty($name) || !empty($email) || !empty($url) || !empty($ip)) { |
| 643 |
|
| 644 |
echo '<ul style="margin-left:24px;list-style:square outside;">'; |
| 645 |
|
| 646 |
if (!empty($name)) echo '<li>'. esc_html__('Submitter Name: ', 'usp') . $name .'</li>'; |
| 647 |
if (!empty($email)) echo '<li>'. esc_html__('Submitter Email: ', 'usp') . $email .'</li>'; |
| 648 |
if (!empty($url)) echo '<li>'. esc_html__('Submitter URL: ', 'usp') . $url .'</li>'; |
| 649 |
if (!empty($ip) && !$usp_options['disable_ip_tracking']) echo '<li>'. esc_html__('Submitter IP: ', 'usp') . $ip .'</li>'; |
| 650 |
|
| 651 |
echo '</ul>'; |
| 652 |
|
| 653 |
} |
| 654 |
|
| 655 |
} |
| 656 |
|
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
function usp_display_form() { |
| 662 |
|
| 663 |
global $usp_options; |
| 664 |
|
| 665 |
$default = USP_PATH .'views/submission-form.php'; |
| 666 |
|
| 667 |
$custom = get_stylesheet_directory() .'/usp/submission-form.php'; |
| 668 |
|
| 669 |
ob_start(); |
| 670 |
|
| 671 |
if ($usp_options['usp_form_version'] === 'custom' && file_exists($custom)) include($custom); |
| 672 |
|
| 673 |
else include($default); |
| 674 |
|
| 675 |
return apply_filters('usp_form_shortcode', ob_get_clean()); |
| 676 |
|
| 677 |
} |
| 678 |
add_shortcode ('user-submitted-posts', 'usp_display_form'); |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
function user_submitted_posts() { |
| 683 |
|
| 684 |
echo usp_display_form(); |
| 685 |
|
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
function usp_outputUserSubmissionLink() { |
| 691 |
|
| 692 |
global $pagenow, $usp_options; |
| 693 |
|
| 694 |
$screen_post_type = usp_get_current_screen_post_type(); |
| 695 |
|
| 696 |
$post_type = isset($usp_options['usp_post_type']) ? $usp_options['usp_post_type'] : 'post'; |
| 697 |
|
| 698 |
$current = $screen_post_type ? $screen_post_type : 'post'; |
| 699 |
|
| 700 |
if ($pagenow === 'edit.php' && $post_type === $current) { |
| 701 |
|
| 702 |
$link = '<a id="usp-admin-filter" class="button" '; |
| 703 |
$link .= 'href="'. admin_url('edit.php?post_type='. $current .'&user_submitted=1') .'" '; |
| 704 |
$link .= 'title="'. esc_attr__('Show USP Posts', 'usp') .'">'; |
| 705 |
$link .= esc_html__('USP', 'usp') .'</a>'; |
| 706 |
|
| 707 |
$link = apply_filters('usp_filter_posts_link', $link, $current); |
| 708 |
|
| 709 |
echo $link; |
| 710 |
|
| 711 |
} |
| 712 |
|
| 713 |
} |
| 714 |
add_action ('restrict_manage_posts', 'usp_outputUserSubmissionLink'); |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
function usp_addSubmittedStatusClause($wp_query) { |
| 719 |
|
| 720 |
global $pagenow; |
| 721 |
|
| 722 |
if (is_admin() && $pagenow == 'edit.php' && isset($_GET['user_submitted'])) { |
| 723 |
|
| 724 |
if ($_GET['user_submitted'] === '1') { |
| 725 |
|
| 726 |
set_query_var('meta_key', 'is_submission'); |
| 727 |
set_query_var('meta_value', 1); |
| 728 |
|
| 729 |
} elseif ($_GET['user_submitted'] === '0') { |
| 730 |
|
| 731 |
$meta_query = array( |
| 732 |
'meta_query' => |
| 733 |
array( |
| 734 |
'key' => 'is_submission', |
| 735 |
'compare' => 'NOT EXISTS', |
| 736 |
'value' => '', |
| 737 |
) |
| 738 |
); |
| 739 |
|
| 740 |
$wp_query->set('meta_query', $meta_query); |
| 741 |
|
| 742 |
} |
| 743 |
|
| 744 |
} |
| 745 |
|
| 746 |
} |
| 747 |
add_action ('parse_query', 'usp_addSubmittedStatusClause'); |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
function usp_replaceAuthor($author) { |
| 752 |
|
| 753 |
global $post, $usp_options; |
| 754 |
|
| 755 |
if ($post && is_object($post) && property_exists($post, 'ID')) { |
| 756 |
|
| 757 |
$disable = isset($usp_options['disable_author']) ? $usp_options['disable_author'] : false; |
| 758 |
|
| 759 |
$isSubmission = get_post_meta($post->ID, 'is_submission', true); |
| 760 |
$submissionAuthor = get_post_meta($post->ID, 'user_submit_name', true); |
| 761 |
|
| 762 |
if (!$disable && $isSubmission && !empty($submissionAuthor)) $author = $submissionAuthor; |
| 763 |
|
| 764 |
} |
| 765 |
|
| 766 |
return apply_filters('usp_post_author', $author); |
| 767 |
|
| 768 |
} |
| 769 |
add_filter('the_author', 'usp_replaceAuthor'); |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
function usp_get_author($author) { |
| 774 |
|
| 775 |
global $usp_options; |
| 776 |
|
| 777 |
$error = false; |
| 778 |
|
| 779 |
$author_id = $usp_options['author']; |
| 780 |
|
| 781 |
if (!empty($author)) { |
| 782 |
|
| 783 |
if ($usp_options['usp_use_author']) { |
| 784 |
|
| 785 |
$author_info = get_user_by('login', $author); |
| 786 |
|
| 787 |
if ($author_info) { |
| 788 |
|
| 789 |
$author_id = $author_info->ID; |
| 790 |
|
| 791 |
$author = get_the_author_meta('display_name', $author_id); |
| 792 |
|
| 793 |
} |
| 794 |
|
| 795 |
} |
| 796 |
|
| 797 |
} else { |
| 798 |
|
| 799 |
if ($usp_options['usp_name'] == 'show') { |
| 800 |
|
| 801 |
$error = 'required-name'; |
| 802 |
|
| 803 |
} else { |
| 804 |
|
| 805 |
$author = get_the_author_meta('display_name', $author_id); |
| 806 |
|
| 807 |
} |
| 808 |
|
| 809 |
} |
| 810 |
|
| 811 |
$author_data = array('author' => $author, 'author_id' => $author_id, 'error' => $error); |
| 812 |
|
| 813 |
return $author_data; |
| 814 |
|
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
if (!function_exists('exif_imagetype')) { |
| 820 |
|
| 821 |
function exif_imagetype($filename) { |
| 822 |
|
| 823 |
if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) { |
| 824 |
|
| 825 |
return $type; |
| 826 |
|
| 827 |
} |
| 828 |
|
| 829 |
return false; |
| 830 |
|
| 831 |
} |
| 832 |
|
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
function usp_check_images($files, $newPost) { |
| 838 |
|
| 839 |
global $usp_options; |
| 840 |
|
| 841 |
$error = array(); $file_count = 0; |
| 842 |
|
| 843 |
$name = isset($files['name']) ? array_filter($files['name']) : false; |
| 844 |
$temp = isset($files['tmp_name']) ? array_filter($files['tmp_name']) : false; |
| 845 |
$errr = isset($files['error']) ? array_filter($files['error']) : false; |
| 846 |
|
| 847 |
if ($usp_options['usp_images'] == 'show') { |
| 848 |
|
| 849 |
if (!empty($temp)) { |
| 850 |
|
| 851 |
foreach ($temp as $key => $value) if (is_uploaded_file($value)) $file_count++; |
| 852 |
|
| 853 |
} |
| 854 |
|
| 855 |
if (!empty($errr)) { |
| 856 |
|
| 857 |
foreach ($errr as $key => $value) { |
| 858 |
|
| 859 |
if (!empty($name) && $value > 0) { |
| 860 |
|
| 861 |
error_log('WP Plugin USP: File error message '. $value .'. Info @ https://bit.ly/2uTJc4D', 0); |
| 862 |
|
| 863 |
$error[] = 'file-error'; |
| 864 |
|
| 865 |
} |
| 866 |
|
| 867 |
} |
| 868 |
|
| 869 |
} |
| 870 |
|
| 871 |
if ($file_count < $usp_options['min-images']) $error[] = 'file-min'; |
| 872 |
if ($file_count > $usp_options['max-images']) $error[] = 'file-max'; |
| 873 |
|
| 874 |
for ($i = 0; $i < $file_count; $i++) { |
| 875 |
|
| 876 |
$image = @getimagesize($temp[$i]); |
| 877 |
|
| 878 |
if (false === $image) { |
| 879 |
|
| 880 |
$error[] = 'file-type'; |
| 881 |
|
| 882 |
break; |
| 883 |
|
| 884 |
} else { |
| 885 |
|
| 886 |
if (isset($temp[$i]) && !exif_imagetype($temp[$i])) { |
| 887 |
|
| 888 |
$error[] = 'file-type'; |
| 889 |
|
| 890 |
break; |
| 891 |
|
| 892 |
} |
| 893 |
|
| 894 |
if (isset($image[0]) && !usp_width_min($image[0])) { |
| 895 |
|
| 896 |
$error[] = 'width-min'; |
| 897 |
|
| 898 |
break; |
| 899 |
|
| 900 |
} |
| 901 |
|
| 902 |
if (isset($image[0]) && !usp_width_max($image[0])) { |
| 903 |
|
| 904 |
$error[] = 'width-max'; |
| 905 |
|
| 906 |
break; |
| 907 |
|
| 908 |
} |
| 909 |
|
| 910 |
if (isset($image[1]) && !usp_height_min($image[1])) { |
| 911 |
|
| 912 |
$error[] = 'height-min'; |
| 913 |
|
| 914 |
break; |
| 915 |
|
| 916 |
} |
| 917 |
|
| 918 |
if (isset($image[1]) && !usp_height_max($image[1])) { |
| 919 |
|
| 920 |
$error[] = 'height-max'; |
| 921 |
|
| 922 |
break; |
| 923 |
|
| 924 |
} |
| 925 |
|
| 926 |
if (isset($errr[$i]) && $errr[$i] > 0) { |
| 927 |
|
| 928 |
error_log('WP Plugin USP: File error message '. $errr[$i] .'. Info @ https://bit.ly/2uTJc4D', 0); |
| 929 |
|
| 930 |
$error[] = 'file-error'; |
| 931 |
|
| 932 |
break; |
| 933 |
|
| 934 |
} |
| 935 |
|
| 936 |
} |
| 937 |
|
| 938 |
} |
| 939 |
|
| 940 |
} |
| 941 |
|
| 942 |
$file_data = array('error' => $error, 'file_count' => $file_count); |
| 943 |
|
| 944 |
return $file_data; |
| 945 |
|
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
function usp_prepare_post($title, $content, $author_id, $author, $ip) { |
| 951 |
|
| 952 |
global $usp_options; |
| 953 |
|
| 954 |
$postData = array(); |
| 955 |
$postData['post_title'] = $title; |
| 956 |
$postData['post_content'] = $content; |
| 957 |
$postData['post_author'] = $author_id; |
| 958 |
$postData['post_status'] = apply_filters('usp_post_status', 'pending'); |
| 959 |
$postData['post_name'] = sanitize_title($title); |
| 960 |
|
| 961 |
$postType = isset($usp_options['usp_post_type']) ? $usp_options['usp_post_type'] : 'post'; |
| 962 |
|
| 963 |
$postData['post_type'] = apply_filters('usp_post_type', $postType); |
| 964 |
|
| 965 |
$numberApproved = $usp_options['number-approved']; |
| 966 |
|
| 967 |
if ($numberApproved == 0) { |
| 968 |
|
| 969 |
$postData['post_status'] = apply_filters('usp_post_publish', 'publish'); |
| 970 |
|
| 971 |
} elseif ($numberApproved == -1) { |
| 972 |
|
| 973 |
$postData['post_status'] = apply_filters('usp_post_moderate', 'pending'); |
| 974 |
|
| 975 |
} elseif ($numberApproved == -2) { |
| 976 |
|
| 977 |
$postData['post_status'] = apply_filters('usp_post_draft', 'draft'); |
| 978 |
|
| 979 |
} else { |
| 980 |
|
| 981 |
$posts = get_posts(array('post_status' => 'publish', 'meta_key' => 'user_submit_name', 'meta_value' => $author)); |
| 982 |
|
| 983 |
$counter = 0; |
| 984 |
|
| 985 |
foreach ($posts as $post) { |
| 986 |
|
| 987 |
$submitterName = get_post_meta($post->ID, 'user_submit_name', true); |
| 988 |
$submitterIp = get_post_meta($post->ID, 'user_submit_ip', true); |
| 989 |
|
| 990 |
if ($submitterName == $author && $submitterIp == $ip) $counter++; |
| 991 |
|
| 992 |
} |
| 993 |
|
| 994 |
if ($counter >= $numberApproved) $postData['post_status'] = apply_filters('usp_post_approve', 'publish'); |
| 995 |
|
| 996 |
} |
| 997 |
|
| 998 |
return apply_filters('usp_post_data', $postData); |
| 999 |
|
| 1000 |
} |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
function usp_check_duplicates($title) { |
| 1005 |
|
| 1006 |
global $usp_options; |
| 1007 |
|
| 1008 |
if ($usp_options['titles_unique']) { |
| 1009 |
|
| 1010 |
$check_post = get_page_by_title($title, OBJECT, 'post'); |
| 1011 |
|
| 1012 |
if ($check_post && $check_post->ID) return false; |
| 1013 |
|
| 1014 |
} |
| 1015 |
|
| 1016 |
return true; |
| 1017 |
|
| 1018 |
} |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
function usp_maybe_rotate($tmp_name, $file_local) { |
| 1023 |
|
| 1024 |
$image_type = function_exists('exif_imagetype') ? exif_imagetype($tmp_name) : false; |
| 1025 |
|
| 1026 |
if ($image_type === 2) { |
| 1027 |
|
| 1028 |
$image_exif = function_exists('exif_read_data') ? @exif_read_data($tmp_name) : array(); // @ cuz PHP bug |
| 1029 |
|
| 1030 |
if (isset($image_exif['Orientation']) && !empty($image_exif['Orientation'])) { |
| 1031 |
|
| 1032 |
$src = imagecreatefromjpeg($tmp_name); |
| 1033 |
|
| 1034 |
if ($src) { |
| 1035 |
|
| 1036 |
switch ($image_exif['Orientation']) { |
| 1037 |
|
| 1038 |
case 3: $image = imagerotate($src, 180, 0); break; |
| 1039 |
case 6: $image = imagerotate($src, -90, 0); break; |
| 1040 |
case 8: $image = imagerotate($src, 90, 0); break; |
| 1041 |
default: $image = null; break; |
| 1042 |
} |
| 1043 |
|
| 1044 |
imagedestroy($src); |
| 1045 |
|
| 1046 |
if ($image) { |
| 1047 |
|
| 1048 |
ob_start(); |
| 1049 |
imagejpeg($image, null, 100); |
| 1050 |
$file_local = ob_get_contents(); |
| 1051 |
ob_end_clean(); |
| 1052 |
imagedestroy($image); |
| 1053 |
|
| 1054 |
} |
| 1055 |
} |
| 1056 |
|
| 1057 |
} |
| 1058 |
|
| 1059 |
} |
| 1060 |
|
| 1061 |
return $file_local; |
| 1062 |
|
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
function usp_random_string($length = 12) { |
| 1068 |
|
| 1069 |
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| 1070 |
|
| 1071 |
$string = substr(str_shuffle($chars), 0, $length); |
| 1072 |
|
| 1073 |
return $string; |
| 1074 |
|
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
function usp_unique_filename($file) { |
| 1080 |
|
| 1081 |
$parts = pathinfo($file); // e.g., // /www/htdocs/inc/image.jpg |
| 1082 |
|
| 1083 |
$dirname = isset($parts['dirname']) ? $parts['dirname'] : ''; // /www/htdocs/inc |
| 1084 |
$basename = isset($parts['basename']) ? $parts['basename'] : ''; // image.jpg |
| 1085 |
$extension = isset($parts['extension']) ? $parts['extension'] : ''; // jpg |
| 1086 |
$filename = isset($parts['filename']) ? $parts['filename'] : ''; // image |
| 1087 |
|
| 1088 |
$append = '-'. usp_random_string(); |
| 1089 |
|
| 1090 |
$file = $dirname .'/'. $filename . $append .'.'. $extension; |
| 1091 |
|
| 1092 |
$file = apply_filters('usp_unique_filename', $file, $dirname, $basename, $extension, $filename); |
| 1093 |
|
| 1094 |
return $file; |
| 1095 |
|
| 1096 |
} |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
function usp_attach_images($post_id, $newPost, $files, $file_count, $author_data) { |
| 1101 |
|
| 1102 |
global $usp_options; |
| 1103 |
|
| 1104 |
do_action('usp_files_before', $files); |
| 1105 |
|
| 1106 |
$attach_ids = array(); |
| 1107 |
|
| 1108 |
if ($files && $file_count > 0) { |
| 1109 |
|
| 1110 |
usp_include_deps(); |
| 1111 |
|
| 1112 |
for ($i = 0; $i < $file_count; $i++) { |
| 1113 |
|
| 1114 |
if (isset($files['tmp_name'][$i]) && !empty($files['tmp_name'][$i])) { |
| 1115 |
|
| 1116 |
$file_local = file_get_contents($files['tmp_name'][$i]); |
| 1117 |
|
| 1118 |
$tmp_name = $files['tmp_name'][$i]; |
| 1119 |
|
| 1120 |
} else { |
| 1121 |
|
| 1122 |
continue; |
| 1123 |
|
| 1124 |
} |
| 1125 |
|
| 1126 |
if (isset($files['name'][$i]) && !empty($files['name'][$i])) { |
| 1127 |
|
| 1128 |
$append = ($file_count > 1) ? '-'. $i : ''; |
| 1129 |
|
| 1130 |
$file_name = sanitize_file_name(basename($files['name'][$i])); |
| 1131 |
|
| 1132 |
$parts = pathinfo($file_name); |
| 1133 |
|
| 1134 |
$ext = isset($parts['extension']) ? $parts['extension'] : null; |
| 1135 |
|
| 1136 |
$append = apply_filters('usp_filename_append', $append, $file_name, $ext); |
| 1137 |
|
| 1138 |
$filename = isset($parts['filename']) ? $parts['filename'] : usp_random_string(); |
| 1139 |
|
| 1140 |
$file_name = isset($parts['filename']) ? $parts['filename'] . $append .'.'. $ext : $file_name; |
| 1141 |
|
| 1142 |
$file_name = apply_filters('usp_file_name', $file_name, $filename, $append, $ext); |
| 1143 |
|
| 1144 |
} else { |
| 1145 |
|
| 1146 |
continue; |
| 1147 |
|
| 1148 |
} |
| 1149 |
|
| 1150 |
$file_local = usp_maybe_rotate($tmp_name, $file_local); |
| 1151 |
|
| 1152 |
$file_path = defined('USP_UPLOAD_DIR') ? USP_UPLOAD_DIR : '/'; |
| 1153 |
|
| 1154 |
$upload_dir = apply_filters('usp_upload_directory', wp_upload_dir()); |
| 1155 |
|
| 1156 |
$wp_filetype = wp_check_filetype($file_name, null); |
| 1157 |
|
| 1158 |
if (wp_mkdir_p($upload_dir['path'])) { |
| 1159 |
|
| 1160 |
$file = isset($upload_dir['path']) ? $upload_dir['path'] . $file_path . $file_name : null; |
| 1161 |
$guid = isset($upload_dir['url']) ? $upload_dir['url'] . $file_path . $file_name : null; |
| 1162 |
|
| 1163 |
} else { |
| 1164 |
|
| 1165 |
$file = isset($upload_dir['basedir']) ? $upload_dir['basedir'] . $file_path . $file_name : null; |
| 1166 |
$guid = isset($upload_dir['baseurl']) ? $upload_dir['baseurl'] . $file_path . $file_name : null; |
| 1167 |
|
| 1168 |
} |
| 1169 |
|
| 1170 |
$file = file_exists($file) ? usp_unique_filename($file) : $file; |
| 1171 |
|
| 1172 |
if (in_array(strtolower($ext), array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'webp', 'heic', 'heif', 'svg'))) $bytes = file_put_contents($file, $file_local); |
| 1173 |
|
| 1174 |
$file_type = isset($wp_filetype['type']) ? $wp_filetype['type'] : null; |
| 1175 |
|
| 1176 |
$params = apply_filters('wp_handle_upload', array('file' => $file, 'url' => $guid, 'type' => $file_type)); |
| 1177 |
|
| 1178 |
$file = isset($params['file']) ? $params['file'] : $file; |
| 1179 |
$guid = isset($params['url']) ? $params['url'] : $guid; |
| 1180 |
$file_type = isset($params['type']) ? $params['type'] : $file_type; |
| 1181 |
|
| 1182 |
$attachment = array( |
| 1183 |
'post_mime_type' => $file_type, |
| 1184 |
'post_name' => $file_name, |
| 1185 |
'post_title' => $file_name, |
| 1186 |
'post_status' => 'inherit', |
| 1187 |
'guid' => $guid |
| 1188 |
); |
| 1189 |
|
| 1190 |
if (!is_user_logged_in()) { |
| 1191 |
|
| 1192 |
$attachment_author_id = apply_filters('usp_attachment_author_id', 0); |
| 1193 |
|
| 1194 |
if (!$attachment_author_id) { |
| 1195 |
|
| 1196 |
$attachment_author_id = isset($author_data['author_id']) ? $author_data['author_id'] : 1; |
| 1197 |
|
| 1198 |
} |
| 1199 |
|
| 1200 |
$attachment['post_author'] = $attachment_author_id; |
| 1201 |
|
| 1202 |
} |
| 1203 |
|
| 1204 |
$attachment = apply_filters('usp_insert_attachment_data', $attachment); |
| 1205 |
|
| 1206 |
$attach_id = wp_insert_attachment($attachment, $file, $post_id); |
| 1207 |
|
| 1208 |
if (isset($usp_options['usp_featured_images']) && $usp_options['usp_featured_images']) { |
| 1209 |
|
| 1210 |
if (!has_post_thumbnail($post_id)) set_post_thumbnail($post_id, $attach_id); |
| 1211 |
|
| 1212 |
} |
| 1213 |
|
| 1214 |
$attach_data = wp_generate_attachment_metadata($attach_id, $file); |
| 1215 |
|
| 1216 |
wp_update_attachment_metadata($attach_id, $attach_data); |
| 1217 |
|
| 1218 |
if (!is_wp_error($attach_id) && wp_attachment_is_image($attach_id)) { |
| 1219 |
|
| 1220 |
$attach_ids[] = $attach_id; |
| 1221 |
|
| 1222 |
add_post_meta($post_id, 'user_submit_image', wp_get_attachment_url($attach_id)); |
| 1223 |
|
| 1224 |
} else { |
| 1225 |
|
| 1226 |
wp_delete_attachment($attach_id); |
| 1227 |
|
| 1228 |
wp_delete_post($post_id, true); |
| 1229 |
|
| 1230 |
$newPost['error'][] = 'file-upload'; |
| 1231 |
|
| 1232 |
unset($newPost['id']); |
| 1233 |
|
| 1234 |
} |
| 1235 |
|
| 1236 |
} |
| 1237 |
|
| 1238 |
} else { |
| 1239 |
|
| 1240 |
if (isset($usp_options['usp_featured_image_default']) && !empty($usp_options['usp_featured_image_default'])) { |
| 1241 |
|
| 1242 |
$default_image = attachment_url_to_postid($usp_options['usp_featured_image_default']); |
| 1243 |
|
| 1244 |
if (!empty($default_image) && isset($usp_options['usp_featured_images']) && $usp_options['usp_featured_images']) { |
| 1245 |
|
| 1246 |
if (!has_post_thumbnail($post_id)) set_post_thumbnail($post_id, $default_image); |
| 1247 |
|
| 1248 |
} |
| 1249 |
|
| 1250 |
} |
| 1251 |
|
| 1252 |
} |
| 1253 |
|
| 1254 |
do_action('usp_files_after', $attach_ids); |
| 1255 |
|
| 1256 |
return $newPost; |
| 1257 |
|
| 1258 |
} |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
function usp_createPublicSubmission($title, $files, $ip, $author, $url, $email, $tags, $captcha, $verify, $content, $category, $custom, $custom_2, $checkbox, $comments) { |
| 1263 |
|
| 1264 |
global $usp_options; |
| 1265 |
|
| 1266 |
$newPost = array('id' => null, 'error' => array()); |
| 1267 |
|
| 1268 |
$author_data = usp_get_author($author); |
| 1269 |
$author = $author_data['author']; |
| 1270 |
$author_id = $author_data['author_id']; |
| 1271 |
|
| 1272 |
if (isset($author_data['error']) && !empty($author_data['error'])) { |
| 1273 |
|
| 1274 |
$newPost['error'][] = $author_data['error']; |
| 1275 |
|
| 1276 |
} |
| 1277 |
|
| 1278 |
$file_data = usp_check_images($files, $newPost); |
| 1279 |
$file_count = $file_data['file_count']; |
| 1280 |
|
| 1281 |
if (isset($file_data['error']) && !empty($file_data['error'])) { |
| 1282 |
|
| 1283 |
$newPost['error'] = array_unique(array_merge($file_data['error'], $newPost['error'])); |
| 1284 |
|
| 1285 |
} |
| 1286 |
|
| 1287 |
$tags = is_array($tags) ? array_filter($tags) : $tags; |
| 1288 |
$category = is_array($category) ? array_filter($category) : $category; |
| 1289 |
|
| 1290 |
if (isset($usp_options['usp_title']) && ($usp_options['usp_title'] == 'show') && empty($title)) $newPost['error'][] = 'required-title'; |
| 1291 |
if (isset($usp_options['usp_url']) && ($usp_options['usp_url'] == 'show') && empty($url)) $newPost['error'][] = 'required-url'; |
| 1292 |
if (isset($usp_options['usp_tags']) && ($usp_options['usp_tags'] == 'show') && empty($tags)) $newPost['error'][] = 'required-tags'; |
| 1293 |
if (isset($usp_options['usp_category']) && ($usp_options['usp_category'] == 'show') && empty($category)) $newPost['error'][] = 'required-category'; |
| 1294 |
if (isset($usp_options['usp_content']) && ($usp_options['usp_content'] == 'show') && empty($content)) $newPost['error'][] = 'required-content'; |
| 1295 |
if (isset($usp_options['custom_field']) && ($usp_options['custom_field'] == 'show') && empty($custom)) $newPost['error'][] = 'required-custom'; |
| 1296 |
if (isset($usp_options['custom_field_2']) && ($usp_options['custom_field_2'] == 'show') && empty($custom_2)) $newPost['error'][] = 'required-custom-2'; |
| 1297 |
|
| 1298 |
if (usp_check_recaptcha_keys()) { |
| 1299 |
|
| 1300 |
if (isset($usp_options['usp_recaptcha']) && ($usp_options['usp_recaptcha'] == 'show') && !usp_verify_recaptcha()) $newPost['error'][] = 'required-recaptcha'; |
| 1301 |
|
| 1302 |
} |
| 1303 |
|
| 1304 |
if (isset($usp_options['usp_captcha']) && ($usp_options['usp_captcha'] == 'show') && !usp_spamQuestion($captcha)) $newPost['error'][] = 'required-captcha'; |
| 1305 |
|
| 1306 |
if (isset($usp_options['usp_email']) && ($usp_options['usp_email'] == 'show')) { |
| 1307 |
|
| 1308 |
$email = sanitize_email($email); |
| 1309 |
|
| 1310 |
if (!usp_validateEmail($email)) $newPost['error'][] = 'required-email'; |
| 1311 |
|
| 1312 |
} |
| 1313 |
|
| 1314 |
if (isset($usp_options['usp_email']) && ($usp_options['usp_email'] == 'optn') && !empty($email)) { |
| 1315 |
|
| 1316 |
$email = sanitize_email($email); |
| 1317 |
|
| 1318 |
if (!usp_validateEmail($email)) $newPost['error'][] = 'incorrect-email'; |
| 1319 |
|
| 1320 |
} |
| 1321 |
|
| 1322 |
if (isset($usp_options['titles_unique']) && $usp_options['titles_unique'] && !usp_check_duplicates($title)) $newPost['error'][] = 'duplicate-title'; |
| 1323 |
if (!empty($verify)) $newPost['error'][] = 'spam-verify'; |
| 1324 |
|
| 1325 |
$checkbox_display = (isset($usp_options['custom_checkbox']) && !empty($usp_options['custom_checkbox'])) ? true : false; |
| 1326 |
$checkbox_required = (isset($usp_options['custom_checkbox_req']) && !empty($usp_options['custom_checkbox_req'])) ? true : false; |
| 1327 |
|
| 1328 |
if ($checkbox_display && $checkbox_required && empty($checkbox)) $newPost['error'][] = 'required-checkbox'; |
| 1329 |
|
| 1330 |
if (isset($newPost['error']) && !empty($newPost['error'])) { |
| 1331 |
|
| 1332 |
foreach ($newPost['error'] as $e) { |
| 1333 |
|
| 1334 |
if (!empty($e)) { |
| 1335 |
|
| 1336 |
unset($newPost['id']); |
| 1337 |
|
| 1338 |
return $newPost; |
| 1339 |
|
| 1340 |
} |
| 1341 |
|
| 1342 |
} |
| 1343 |
|
| 1344 |
} |
| 1345 |
|
| 1346 |
$postData = usp_prepare_post($title, $content, $author_id, $author, $ip); |
| 1347 |
|
| 1348 |
$new_status = (isset($postData['post_status']) && !empty($postData['post_status'])) ? sanitize_text_field($postData['post_status']) : apply_filters('usp_post_status', 'pending'); |
| 1349 |
$postData['post_status'] = apply_filters('usp_post_status', 'pending'); |
| 1350 |
|
| 1351 |
do_action('usp_insert_before', $postData); |
| 1352 |
$newPost['id'] = wp_insert_post($postData); |
| 1353 |
do_action('usp_insert_after', $newPost); |
| 1354 |
|
| 1355 |
$post_id = isset($newPost['id']) ? $newPost['id'] : null; |
| 1356 |
|
| 1357 |
if ($post_id && !is_wp_error($post_id)) { |
| 1358 |
|
| 1359 |
$post = get_post($post_id); |
| 1360 |
|
| 1361 |
$post->post_status = $new_status; |
| 1362 |
|
| 1363 |
$post->comment_status = $comments; |
| 1364 |
|
| 1365 |
wp_update_post($post); |
| 1366 |
|
| 1367 |
wp_set_post_tags($post_id, apply_filters('usp_filter_tags', $tags), apply_filters('usp_append_tags', false)); |
| 1368 |
|
| 1369 |
wp_set_post_categories($post_id, apply_filters('usp_filter_cats', $category), apply_filters('usp_append_cats', false)); |
| 1370 |
|
| 1371 |
$newPost = usp_attach_images($post_id, $newPost, $files, $file_count, $author_data); |
| 1372 |
|
| 1373 |
if (isset($newPost['error']) && empty($newPost['error'])) { |
| 1374 |
|
| 1375 |
update_post_meta($post_id, 'is_submission', true); |
| 1376 |
update_post_meta($post_id, 'usp-post-id', $post_id); |
| 1377 |
|
| 1378 |
$custom_name = isset($usp_options['custom_name']) ? $usp_options['custom_name'] : 'usp_custom_field'; |
| 1379 |
$custom_name_2 = isset($usp_options['custom_name_2']) ? $usp_options['custom_name_2'] : 'usp_custom_field_2'; |
| 1380 |
|
| 1381 |
$checkbox_name = isset($usp_options['custom_checkbox_name']) ? $usp_options['custom_checkbox_name'] : 'usp_custom_checkbox'; |
| 1382 |
|
| 1383 |
if (!empty($custom)) update_post_meta($post_id, $custom_name, $custom); |
| 1384 |
if (!empty($custom_2)) update_post_meta($post_id, $custom_name_2, $custom_2); |
| 1385 |
if (!empty($checkbox)) update_post_meta($post_id, $checkbox_name, $checkbox); |
| 1386 |
if (!empty($author)) update_post_meta($post_id, 'user_submit_name', $author); |
| 1387 |
if (!empty($email)) update_post_meta($post_id, 'user_submit_email', $email); |
| 1388 |
if (!empty($url)) update_post_meta($post_id, 'user_submit_url', $url); |
| 1389 |
|
| 1390 |
if (!empty($ip) && !$usp_options['disable_ip_tracking']) update_post_meta($post_id, 'user_submit_ip', $ip); |
| 1391 |
|
| 1392 |
$post_date = apply_filters('usp_post_meta_submit_time_format', get_the_time('l, F j, Y @ h:i:s a', $post_id)); |
| 1393 |
|
| 1394 |
update_post_meta($post_id, 'usp-post-time', $post_date); |
| 1395 |
|
| 1396 |
usp_send_mail_alert($post_id, $title, $content, $author, $email, $url, $custom, $custom_2, $post_date); |
| 1397 |
|
| 1398 |
} |
| 1399 |
|
| 1400 |
} else { |
| 1401 |
|
| 1402 |
$newPost['error'][] = 'post-fail'; |
| 1403 |
|
| 1404 |
} |
| 1405 |
|
| 1406 |
return apply_filters('usp_new_post', $newPost); |
| 1407 |
|
| 1408 |
} |
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
function usp_include_deps() { |
| 1413 |
|
| 1414 |
if (!function_exists('media_handle_upload')) { |
| 1415 |
|
| 1416 |
require_once (ABSPATH .'/wp-admin/includes/media.php'); |
| 1417 |
require_once (ABSPATH .'/wp-admin/includes/file.php'); |
| 1418 |
require_once (ABSPATH .'/wp-admin/includes/image.php'); |
| 1419 |
|
| 1420 |
} |
| 1421 |
|
| 1422 |
} |
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
function usp_width_min($width) { |
| 1427 |
|
| 1428 |
global $usp_options; |
| 1429 |
|
| 1430 |
if (intval($width) < intval($usp_options['min-image-width'])) return false; |
| 1431 |
|
| 1432 |
else return true; |
| 1433 |
|
| 1434 |
} |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
function usp_width_max($width) { |
| 1439 |
|
| 1440 |
global $usp_options; |
| 1441 |
|
| 1442 |
if (intval($width) > intval($usp_options['max-image-width'])) return false; |
| 1443 |
|
| 1444 |
else return true; |
| 1445 |
|
| 1446 |
} |
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
function usp_height_min($height) { |
| 1451 |
|
| 1452 |
global $usp_options; |
| 1453 |
|
| 1454 |
if (intval($height) < intval($usp_options['min-image-height'])) return false; |
| 1455 |
|
| 1456 |
else return true; |
| 1457 |
|
| 1458 |
} |
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
function usp_height_max($height) { |
| 1463 |
|
| 1464 |
global $usp_options; |
| 1465 |
|
| 1466 |
if (intval($height) > intval($usp_options['max-image-height'])) return false; |
| 1467 |
|
| 1468 |
else return true; |
| 1469 |
|
| 1470 |
} |
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
function usp_validateEmail($email) { |
| 1475 |
|
| 1476 |
if (!is_email($email)) return false; |
| 1477 |
|
| 1478 |
$bad_stuff = array("\r", "\n", "mime-version", "content-type", "cc:", "to:"); |
| 1479 |
|
| 1480 |
foreach ($bad_stuff as $bad) { |
| 1481 |
|
| 1482 |
if (strpos(strtolower($email), strtolower($bad)) !== false) { |
| 1483 |
|
| 1484 |
return false; |
| 1485 |
|
| 1486 |
} |
| 1487 |
|
| 1488 |
} |
| 1489 |
|
| 1490 |
return true; |
| 1491 |
|
| 1492 |
} |
| 1493 |
|
| 1494 |
function usp_send_mail_alert($post_id, $title, $content, $author, $email, $url, $custom, $custom_2, $post_date) { |
| 1495 |
|
| 1496 |
global $usp_options; |
| 1497 |
|
| 1498 |
if (isset($usp_options['usp_email_alerts']) && $usp_options['usp_email_alerts']) { |
| 1499 |
|
| 1500 |
$blog_url = get_bloginfo('url'); // %%blog_url%% |
| 1501 |
$blog_name = get_bloginfo('name'); // %%blog_name%% |
| 1502 |
$post_url = get_permalink($post_id); // %%post_url%% |
| 1503 |
$admin_url = admin_url(); // %%admin_url%% |
| 1504 |
$post_title = $title; // %%post_title%% |
| 1505 |
$post_content = $content; // %%post_content%% |
| 1506 |
$post_author = $author; // %%post_author%% |
| 1507 |
$user_email = $email; // %%user_email%% |
| 1508 |
$user_url = $url; // %%user_url%% |
| 1509 |
|
| 1510 |
$edit_link = usp_remote_edit_post_link($post_id); // %%edit_link%% |
| 1511 |
$delete_link = usp_remote_delete_post_link($post_id); // %%delete_link%% |
| 1512 |
|
| 1513 |
$patterns = array(); |
| 1514 |
|
| 1515 |
$patterns[0] = "/%%blog_url%%/"; |
| 1516 |
$patterns[1] = "/%%blog_name%%/"; |
| 1517 |
$patterns[2] = "/%%post_url%%/"; |
| 1518 |
$patterns[3] = "/%%admin_url%%/"; |
| 1519 |
$patterns[4] = "/%%post_title%%/"; |
| 1520 |
$patterns[5] = "/%%post_content%%/"; |
| 1521 |
$patterns[6] = "/%%post_author%%/"; |
| 1522 |
$patterns[7] = "/%%user_email%%/"; |
| 1523 |
$patterns[8] = "/%%user_url%%/"; |
| 1524 |
$patterns[9] = "/%%edit_link%%/"; |
| 1525 |
$patterns[10] = "/%%custom_field%%/"; |
| 1526 |
$patterns[11] = "/%%custom_field_2%%/"; |
| 1527 |
$patterns[12] = "/%%delete_link%%/"; |
| 1528 |
$patterns[13] = "/%%post_date%%/"; |
| 1529 |
|
| 1530 |
$replacements = array(); |
| 1531 |
|
| 1532 |
$replacements[0] = $blog_url; |
| 1533 |
$replacements[1] = $blog_name; |
| 1534 |
$replacements[2] = $post_url; |
| 1535 |
$replacements[3] = $admin_url; |
| 1536 |
$replacements[4] = $post_title; |
| 1537 |
$replacements[5] = $post_content; |
| 1538 |
$replacements[6] = $post_author; |
| 1539 |
$replacements[7] = $user_email; |
| 1540 |
$replacements[8] = $user_url; |
| 1541 |
$replacements[9] = $edit_link; |
| 1542 |
$replacements[10] = $custom; |
| 1543 |
$replacements[11] = $custom_2; |
| 1544 |
$replacements[12] = $delete_link; |
| 1545 |
$replacements[13] = $post_date; |
| 1546 |
|
| 1547 |
// |
| 1548 |
|
| 1549 |
$subject_default = $blog_name .': New user-submitted post!'; |
| 1550 |
$subject = (isset($usp_options['email_alert_subject']) && !empty($usp_options['email_alert_subject'])) ? $usp_options['email_alert_subject'] : $subject_default; |
| 1551 |
$subject = preg_replace($patterns, $replacements, $subject); |
| 1552 |
$subject = apply_filters('usp_mail_subject', $subject); |
| 1553 |
|
| 1554 |
$message_default = 'Hello, there is a new user-submitted post:'. "\r\n\n" . 'Title: '. $post_title . "\r\n\n" .'Visit Admin Area: '. $admin_url; |
| 1555 |
$message = (isset($usp_options['email_alert_message']) && !empty($usp_options['email_alert_message'])) ? $usp_options['email_alert_message'] : $message_default; |
| 1556 |
$message = preg_replace($patterns, $replacements, $message); |
| 1557 |
$message = apply_filters('usp_mail_message', $message); |
| 1558 |
|
| 1559 |
$html = isset($usp_options['usp_email_html']) ? $usp_options['usp_email_html'] : false; |
| 1560 |
$format = $html ? 'text/html' : 'text/plain'; |
| 1561 |
|
| 1562 |
// |
| 1563 |
|
| 1564 |
$default = get_bloginfo('admin_email'); |
| 1565 |
|
| 1566 |
$to = (isset($usp_options['usp_email_address']) && !empty($usp_options['usp_email_address'])) ? $usp_options['usp_email_address'] : $default; |
| 1567 |
$from = (isset($usp_options['usp_email_from']) && !empty($usp_options['usp_email_from'])) ? $usp_options['usp_email_from'] : $to; |
| 1568 |
|
| 1569 |
$to = explode(',', $to); |
| 1570 |
$from = explode(',', $from); |
| 1571 |
|
| 1572 |
$address = array(); |
| 1573 |
|
| 1574 |
foreach ($to as $k => $v) $address[$k]['to'] = trim($v); |
| 1575 |
foreach ($from as $k => $v) $address[$k]['from'] = trim($v); |
| 1576 |
|
| 1577 |
if (!empty($address[0])) { |
| 1578 |
|
| 1579 |
foreach ($address as $k => $v) { |
| 1580 |
|
| 1581 |
$address_to = (isset($v['to']) && !empty($v['to'])) ? $v['to'] : $default; |
| 1582 |
$address_from = (isset($v['from']) && !empty($v['from'])) ? $v['from'] : $default; |
| 1583 |
|
| 1584 |
$headers = 'X-Mailer: User Submitted Posts'. "\n"; |
| 1585 |
$headers .= 'From: '. $blog_name .' <'. $address_from .'>'. "\n"; |
| 1586 |
$headers .= 'Reply-To: '. $blog_name .' <'. $address_from .'>'. "\n"; |
| 1587 |
$headers .= 'Content-Type: '. $format .'; charset='. get_option('blog_charset', 'UTF-8') . "\n"; |
| 1588 |
|
| 1589 |
wp_mail($address_to, $subject, $message, $headers); |
| 1590 |
|
| 1591 |
} |
| 1592 |
|
| 1593 |
} |
| 1594 |
|
| 1595 |
} |
| 1596 |
|
| 1597 |
} |
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
// Thanks to Delete Post plugin @ https://wordpress.org/plugins/delete-post/ |
| 1602 |
|
| 1603 |
function usp_remote_delete_post() { |
| 1604 |
|
| 1605 |
if (isset($_GET['delete_post']) && isset($_GET['nonce'])) { |
| 1606 |
|
| 1607 |
if (wp_verify_nonce($_GET['nonce'], 'delete_post_'. $_GET['delete_post'])) { |
| 1608 |
|
| 1609 |
$post_id = intval($_GET['delete_post']); |
| 1610 |
|
| 1611 |
$post = get_post($post_id); |
| 1612 |
|
| 1613 |
if ($post && get_current_user_id() === (int) $post->post_author) { |
| 1614 |
|
| 1615 |
$force = apply_filters('usp_force_delete_post', true); |
| 1616 |
|
| 1617 |
$result = wp_delete_post($post_id, $force); |
| 1618 |
|
| 1619 |
$result = $result ? 'true' : 'false'; |
| 1620 |
|
| 1621 |
$url = add_query_arg('usp-delete-post', $result, trailingslashit(home_url())); |
| 1622 |
|
| 1623 |
wp_redirect($url); |
| 1624 |
|
| 1625 |
exit; |
| 1626 |
|
| 1627 |
} |
| 1628 |
|
| 1629 |
} |
| 1630 |
|
| 1631 |
} |
| 1632 |
|
| 1633 |
} |
| 1634 |
add_action('init', 'usp_remote_delete_post'); |
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
function usp_remote_delete_post_link($post_id) { |
| 1639 |
|
| 1640 |
return add_query_arg(array('delete_post' => $post_id, 'nonce' => wp_create_nonce('delete_post_'. $post_id)), trailingslashit(home_url())); |
| 1641 |
|
| 1642 |
} |
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
function usp_remote_edit_post_link($post_id) { |
| 1647 |
|
| 1648 |
return admin_url('post.php?post='. $post_id .'&action=edit'); |
| 1649 |
|
| 1650 |
} |
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
function usp_spamQuestion($input) { |
| 1655 |
|
| 1656 |
global $usp_options; |
| 1657 |
|
| 1658 |
$response = $usp_options['usp_response']; |
| 1659 |
|
| 1660 |
$response = sanitize_text_field($response); |
| 1661 |
|
| 1662 |
if ($usp_options['usp_casing'] == false) { |
| 1663 |
|
| 1664 |
return (strtoupper($input) == strtoupper($response)); |
| 1665 |
|
| 1666 |
} else { |
| 1667 |
|
| 1668 |
return ($input == $response); |
| 1669 |
|
| 1670 |
} |
| 1671 |
|
| 1672 |
} |
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
function usp_error_message() { |
| 1677 |
|
| 1678 |
global $usp_options; |
| 1679 |
|
| 1680 |
$min = $usp_options['min-images']; |
| 1681 |
$max = $usp_options['max-images']; |
| 1682 |
|
| 1683 |
if ((int) $min > 1) $min = ' ('. $min . esc_html__(' files required', 'usp') .')'; |
| 1684 |
else $min = ' ('. $min . esc_html__(' file required', 'usp') .')'; |
| 1685 |
|
| 1686 |
if ((int) $max > 1) $max = ' (limit: '. $max . esc_html__(' files', 'usp') .')'; |
| 1687 |
else $max = ' (limit: '. $max . esc_html__(' file', 'usp') .')'; |
| 1688 |
|
| 1689 |
$min_width = ' ('. $usp_options['min-image-width'] . esc_html__(' pixels', 'usp') .')'; |
| 1690 |
$max_width = ' ('. $usp_options['max-image-width'] . esc_html__(' pixels', 'usp') .')'; |
| 1691 |
$min_height = ' ('. $usp_options['min-image-height'] . esc_html__(' pixels', 'usp') .')'; |
| 1692 |
$max_height = ' ('. $usp_options['max-image-height'] . esc_html__(' pixels', 'usp') .')'; |
| 1693 |
|
| 1694 |
$custom_label = isset($usp_options['custom_label']) ? $usp_options['custom_label'] : __('Custom Field 1', 'usp'); |
| 1695 |
$custom_label_2 = isset($usp_options['custom_label_2']) ? $usp_options['custom_label_2'] : __('Custom Field 2', 'usp'); |
| 1696 |
|
| 1697 |
$checkbox_label = isset($usp_options['custom_checkbox_err']) ? $usp_options['custom_checkbox_err'] : __('Custom checkbox required', 'usp'); |
| 1698 |
|
| 1699 |
if (!empty($usp_options['error-message'])) $general_error = $usp_options['error-message']; |
| 1700 |
else $general_error = esc_html__('An error occurred. Please go back and try again.', 'usp'); |
| 1701 |
|
| 1702 |
if (isset($_GET['usp-error']) && !empty($_GET['usp-error'])) { |
| 1703 |
|
| 1704 |
$error_string = sanitize_text_field($_GET['usp-error']); |
| 1705 |
$error_array = explode(',', $error_string); |
| 1706 |
$error = array(); |
| 1707 |
|
| 1708 |
foreach ($error_array as $e) { |
| 1709 |
|
| 1710 |
if ($e == 'required-login') $error[] = esc_html__('User login required', 'usp'); |
| 1711 |
elseif ($e == 'required-name') $error[] = esc_html__('User name required', 'usp'); |
| 1712 |
elseif ($e == 'required-title') $error[] = esc_html__('Post title required', 'usp'); |
| 1713 |
elseif ($e == 'required-url') $error[] = esc_html__('User URL required', 'usp'); |
| 1714 |
elseif ($e == 'required-tags') $error[] = esc_html__('Post tags required', 'usp'); |
| 1715 |
elseif ($e == 'required-category') $error[] = esc_html__('Post category required', 'usp'); |
| 1716 |
elseif ($e == 'required-content') $error[] = esc_html__('Post content required', 'usp'); |
| 1717 |
elseif ($e == 'required-recaptcha') $error[] = esc_html__('Correct captcha required', 'usp'); |
| 1718 |
elseif ($e == 'required-captcha') $error[] = esc_html__('Correct captcha required', 'usp'); |
| 1719 |
elseif ($e == 'required-email') $error[] = esc_html__('User email required', 'usp'); |
| 1720 |
elseif ($e == 'incorrect-email') $error[] = esc_html__('Please check your email and try again', 'usp'); |
| 1721 |
elseif ($e == 'spam-verify') $error[] = esc_html__('Non-empty value for hidden field', 'usp'); |
| 1722 |
elseif ($e == 'file-min') $error[] = esc_html__('Minimum number of images not met', 'usp') . $min; |
| 1723 |
elseif ($e == 'file-max') $error[] = esc_html__('Maximum number of images exceeded ', 'usp') . $max; |
| 1724 |
elseif ($e == 'width-min') $error[] = esc_html__('Minimum image width not met', 'usp') . $min_width; |
| 1725 |
elseif ($e == 'width-max') $error[] = esc_html__('Image width exceeds maximum', 'usp') . $max_width; |
| 1726 |
elseif ($e == 'height-min') $error[] = esc_html__('Minimum image height not met', 'usp') . $min_height; |
| 1727 |
elseif ($e == 'height-max') $error[] = esc_html__('Image height exceeds maximum', 'usp') . $max_height; |
| 1728 |
elseif ($e == 'file-type') $error[] = esc_html__('File type not allowed (please upload images only)', 'usp'); |
| 1729 |
elseif ($e == 'required-custom') $error[] = esc_html($custom_label) . esc_html__(' required', 'usp'); |
| 1730 |
elseif ($e == 'required-custom-2') $error[] = esc_html($custom_label_2) . esc_html__(' required', 'usp'); |
| 1731 |
elseif ($e == 'required-checkbox') $error[] = esc_html($checkbox_label); |
| 1732 |
|
| 1733 |
// general error for file uploads, check error log for description. |
| 1734 |
// check server for proper values of memory_limit, max_execution_time, max_input_time, post_max_size, upload_max_filesize |
| 1735 |
elseif ($e == 'file-error') $error[] = esc_html__('File not uploaded. Please check the file and try again.', 'usp'); |
| 1736 |
|
| 1737 |
// check permissions on /uploads/ directory, check error log for the following error: |
| 1738 |
// PHP Warning: mysql_real_escape_string() expects parameter 1 to be string, object given in /wp-includes/wp-db.php |
| 1739 |
elseif ($e == 'file-upload') $error[] = esc_html__('The file(s) could not be uploaded', 'usp'); |
| 1740 |
|
| 1741 |
elseif ($e == 'post-fail') $error[] = esc_html__('Post not created. Please contact the site administrator for help.', 'usp'); |
| 1742 |
elseif ($e == 'duplicate-title') $error[] = esc_html__('Duplicate post title. Please try again.', 'usp'); |
| 1743 |
|
| 1744 |
elseif ($e == 'error') $error[] = $general_error; |
| 1745 |
|
| 1746 |
} |
| 1747 |
|
| 1748 |
$output = ''; |
| 1749 |
|
| 1750 |
foreach ($error as $e) { |
| 1751 |
|
| 1752 |
$output .= "\t\t\t".'<div class="usp-error">'. esc_html__('Error: ', 'usp') . $e .'</div>'."\n"; |
| 1753 |
|
| 1754 |
} |
| 1755 |
|
| 1756 |
$return = '<div id="usp-error-message">'."\n". $output ."\t\t".'</div>'."\n"; |
| 1757 |
|
| 1758 |
return apply_filters('usp_error_message', $return); |
| 1759 |
|
| 1760 |
} |
| 1761 |
|
| 1762 |
return false; |
| 1763 |
|
| 1764 |
} |
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
function usp_redirect_message($content = '') { |
| 1769 |
|
| 1770 |
global $usp_options; |
| 1771 |
|
| 1772 |
$url = (isset($usp_options['redirect-url']) && !empty($usp_options['redirect-url'])) ? true : false; |
| 1773 |
|
| 1774 |
$enable = (!is_admin() && (isset($_GET['usp_redirect']) && $_GET['usp_redirect'] == '1')) ? true : false; |
| 1775 |
|
| 1776 |
$referrer = (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) ? esc_url($_SERVER['HTTP_REFERER']) : false; |
| 1777 |
|
| 1778 |
$link = $referrer ? '<p id="usp-return-form"><a href="'. $referrer .'">'. esc_html__('Return to form', 'usp') .'</a></p>' : ''; |
| 1779 |
|
| 1780 |
$link = apply_filters('usp_return_form', $link, $referrer); |
| 1781 |
|
| 1782 |
$message = ''; |
| 1783 |
|
| 1784 |
if ($url && $enable) { |
| 1785 |
|
| 1786 |
if (isset($_GET['success']) && $_GET['success'] == '1') { |
| 1787 |
|
| 1788 |
$message = '<p id="usp-success-message"><strong>'. $usp_options['success-message'] .'</strong></p>'. $link; |
| 1789 |
|
| 1790 |
} else { |
| 1791 |
|
| 1792 |
$message = usp_error_message() . $link; |
| 1793 |
|
| 1794 |
} |
| 1795 |
|
| 1796 |
} |
| 1797 |
|
| 1798 |
return $message . $content; |
| 1799 |
|
| 1800 |
} |
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
function usp_login_required_message() { |
| 1805 |
|
| 1806 |
$url = apply_filters('usp_require_login_url', wp_login_url()); |
| 1807 |
|
| 1808 |
$message = '<p>'. esc_html__('Please', 'usp'); |
| 1809 |
$message .= ' <a href="'. esc_url($url) .'">'. esc_html__('log in', 'usp') .'</a> '; |
| 1810 |
$message .= esc_html__('to submit content!', 'usp') .'</p>'; |
| 1811 |
|
| 1812 |
$message = apply_filters('usp_require_login', $message); |
| 1813 |
|
| 1814 |
return $message; |
| 1815 |
|
| 1816 |
} |
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
function usp_clear_cookies() { |
| 1821 |
|
| 1822 |
$cookies = array( |
| 1823 |
'user-submitted-name', |
| 1824 |
'user-submitted-email', |
| 1825 |
'user-submitted-url', |
| 1826 |
'user-submitted-title', |
| 1827 |
'user-submitted-tags', |
| 1828 |
'user-submitted-category', |
| 1829 |
'user-submitted-content', |
| 1830 |
'user-submitted-custom', |
| 1831 |
'user-submitted-checkbox', |
| 1832 |
'user-submitted-captcha' |
| 1833 |
); |
| 1834 |
|
| 1835 |
foreach ($cookies as $cookie) { |
| 1836 |
|
| 1837 |
if (isset($_COOKIE[$cookie]) && !empty($_COOKIE[$cookie])) { |
| 1838 |
|
| 1839 |
unset($_COOKIE[$cookie]); |
| 1840 |
setcookie($cookie, '', time() - 3600, '/'); |
| 1841 |
|
| 1842 |
} |
| 1843 |
|
| 1844 |
} |
| 1845 |
|
| 1846 |
} |
| 1847 |
add_action('wp_logout', 'usp_clear_cookies'); |
| 1848 |
|