PluginProbe
User Submitted Posts – Enable Users to Submit Posts from the Front End / 20260916
User Submitted Posts – Enable Users to Submit Posts from the Front End v20260916
20260916 20260810 20260608 20230806 20230809 20230811 20230901 20230902 20230914 20231102 20240319 20240516 20240703 20241026 20250327 20250329 20251121 20251210 20260110 20260113 20260207 20260217 20260407 20260422 trunk All 59 releases
← All changes | user-submitted-posts.php +121 -53 2025032920260916 View file →
@@ -8,18 +8,16 @@
8 8 Author URI: https://plugin-planet.com/
9 9 Donate link: https://monzillamedia.com/donate.html
10 10 Contributors: specialk
11 11 Requires at least: 4.7
12 - Tested up to: 6.8
13 - Stable tag: 20250329
14 - Version: 20250329
12 + Tested up to: 7.1
13 + Stable tag: 20260916
14 + Version: 20260916
15 15 Requires PHP: 5.6.20
16 16 Text Domain: usp
17 17 Domain Path: /languages
18 18 License: GPL v2 or later
19 -*/
20 -
21 -/*
19 +
22 20 This program is free software; you can redistribute it and/or
23 21 modify it under the terms of the GNU General Public License
24 22 as published by the Free Software Foundation; either version
25 23 2 of the License, or (at your option) any later version.
@@ -31,15 +29,15 @@
31 29
32 30 You should have received a copy of the GNU General Public License
33 31 with this program. If not, visit: https://www.gnu.org/licenses/
34 32
35 - Copyright 2025 Monzilla Media. All rights reserved.
33 + Copyright 2011-2026 Monzilla Media. All rights reserved.
36 34 */
37 35
38 36 if (!defined('ABSPATH')) die();
39 37
40 38 if (!defined('USP_WP_VERSION')) define('USP_WP_VERSION', '4.7');
41 -if (!defined('USP_VERSION')) define('USP_VERSION', '20250329');
39 +if (!defined('USP_VERSION')) define('USP_VERSION', '20260916');
42 40 if (!defined('USP_PLUGIN')) define('USP_PLUGIN', 'User Submitted Posts');
43 41 if (!defined('USP_FILE')) define('USP_FILE', plugin_basename(__FILE__));
44 42 if (!defined('USP_PATH')) define('USP_PATH', plugin_dir_path(__FILE__));
45 43 if (!defined('USP_URL')) define('USP_URL', plugin_dir_url (__FILE__));
@@ -68,8 +66,47 @@
68 66 //
69 67
70 68
71 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 +
72 109 function usp_require_wp_version() {
73 110
74 111 $wp_version = get_bloginfo('version');
75 112
@@ -82,10 +119,10 @@
82 119 deactivate_plugins(USP_FILE);
83 120
84 121 $msg = '<strong>'. USP_PLUGIN .'</strong> ';
85 122 $msg .= esc_html__('requires WordPress ', 'usp') . USP_WP_VERSION;
86 - $msg .= esc_html__(' or higher, and has been deactivated! ', 'usp');
87 - $msg .= esc_html__('Please return to the', 'usp') .' <a href="'. admin_url() .'">';
123 + $msg .= esc_html__(' or higher, and has been deactivated. ', 'usp');
124 + $msg .= esc_html__('Please return to the', 'usp') .' <a href="'. admin_url('plugins.php') .'">';
88 125 $msg .= esc_html__('WordPress Admin Area', 'usp') .'</a> ';
89 126 $msg .= esc_html__('to upgrade WordPress and try again.', 'usp');
90 127
91 128 wp_die($msg);
@@ -256,8 +293,12 @@
256 293
257 294
258 295 function usp_get_submitted_category() {
259 296
297 + global $usp_options;
298 +
299 + $allowed_cats = isset($usp_options['categories']) ? array_map('intval', $usp_options['categories']) : array();
300 +
260 301 $category = isset($_POST['user-submitted-category']) ? $_POST['user-submitted-category'] : '';
261 302
262 303 if (is_array($category)) {
263 304
@@ -262,20 +303,30 @@
262 303 if (is_array($category)) {
263 304
264 305 $cats = array();
265 306
266 - foreach ($category as $cat) $cats[] = sanitize_text_field($cat);
307 + foreach ($category as $cat) $cats[] = intval($cat);
267 308
309 + $cats = array_intersect($cats, $allowed_cats);
310 +
268 311 } else {
269 312
270 313 if (strpos($category, ',') !== false) {
271 314
272 - $cats = array_map('trim', explode(',', $category));
315 + $cats = array_map('intval', array_map('trim', explode(',', $category)));
273 316
317 + $cats = array_intersect($cats, $allowed_cats);
318 +
274 319 } else {
275 320
276 - $cats = sanitize_text_field($category);
321 + $cats = intval($category);
277 322
323 + if (!in_array($cats, $allowed_cats)) {
324 +
325 + $cats = isset($allowed_cats[0]) ? $allowed_cats[0] : '';
326 +
327 + }
328 +
278 329 }
279 330
280 331 }
281 332
@@ -433,24 +484,13 @@
433 484 }
434 485
435 486 if ($post_id) {
436 487
437 - if (!empty($_POST['redirect-override'])) {
438 -
439 - $redirect = $_POST['redirect-override'];
440 -
441 - $redirect = remove_query_arg(array('usp-error'), $redirect);
442 - $redirect = add_query_arg(array('usp_redirect' => '1', 'success' => 1, 'post_id' => $post_id), $redirect);
443 -
444 - } else {
445 -
446 - $redirect = $_SERVER['REQUEST_URI'];
447 -
448 - $redirect = remove_query_arg(array('usp-error'), $redirect);
449 - $redirect = add_query_arg(array('success' => 1, 'post_id' => $post_id), $redirect);
450 -
451 - }
488 + $redirect = $_SERVER['REQUEST_URI'];
452 489
490 + $redirect = remove_query_arg(array('usp-error'), $redirect);
491 + $redirect = add_query_arg(array('success' => 1, 'post_id' => $post_id), $redirect);
492 +
453 493 do_action('usp_submit_success', $redirect);
454 494
455 495 } else {
456 496
@@ -655,12 +695,12 @@
655 695 if (!empty($name) || !empty($email) || !empty($url) || !empty($ip)) {
656 696
657 697 echo '<ul style="margin-left:24px;list-style:square outside;">';
658 698
659 - if (!empty($name)) echo '<li>'. esc_html__('Submitter Name: ', 'usp') . $name .'</li>';
660 - if (!empty($email)) echo '<li>'. esc_html__('Submitter Email: ', 'usp') . $email .'</li>';
661 - if (!empty($url)) echo '<li>'. esc_html__('Submitter URL: ', 'usp') . $url .'</li>';
662 - if (!empty($ip) && !$usp_options['disable_ip_tracking']) echo '<li>'. esc_html__('Submitter IP: ', 'usp') . $ip .'</li>';
699 + if (!empty($name)) echo '<li>'. esc_html__('Submitter Name: ', 'usp') . esc_html($name) .'</li>';
700 + if (!empty($email)) echo '<li>'. esc_html__('Submitter Email: ', 'usp') . esc_html($email) .'</li>';
701 + if (!empty($url)) echo '<li>'. esc_html__('Submitter URL: ', 'usp') . esc_html($url) .'</li>';
702 + if (!empty($ip) && !$usp_options['disable_ip_tracking']) echo '<li>'. esc_html__('Submitter IP: ', 'usp') . esc_html($ip) .'</li>';
663 703
664 704 echo '</ul>';
665 705
666 706 }
@@ -687,9 +727,9 @@
687 727
688 728 return apply_filters('usp_form_shortcode', ob_get_clean());
689 729
690 730 }
691 -add_shortcode ('user-submitted-posts', 'usp_display_form');
731 +add_shortcode('user-submitted-posts', 'usp_display_form');
692 732
693 733
694 734
695 735 function user_submitted_posts() {
@@ -1381,8 +1421,9 @@
1381 1421 $new_status = (isset($postData['post_status']) && !empty($postData['post_status'])) ? sanitize_text_field($postData['post_status']) : apply_filters('usp_post_status', 'pending');
1382 1422 $postData['post_status'] = apply_filters('usp_post_status', 'pending');
1383 1423
1384 1424 do_action('usp_insert_before', $postData);
1425 + $postData = apply_filters('usp_insert_post_vars', $postData);
1385 1426 $newPost['id'] = wp_insert_post($postData);
1386 1427 do_action('usp_insert_after', $newPost);
1387 1428
1388 1429 $post_id = isset($newPost['id']) ? $newPost['id'] : null;
@@ -1443,13 +1484,13 @@
1443 1484
1444 1485
1445 1486 function usp_include_deps() {
1446 1487
1447 - if (!function_exists('media_handle_upload')) {
1488 + if (!function_exists('media_handle_upload') || !function_exists('wp_crop_image')) {
1448 1489
1449 - require_once (ABSPATH .'/wp-admin/includes/media.php');
1450 - require_once (ABSPATH .'/wp-admin/includes/file.php');
1451 - require_once (ABSPATH .'/wp-admin/includes/image.php');
1490 + require_once(ABSPATH .'/wp-admin/includes/media.php');
1491 + require_once(ABSPATH .'/wp-admin/includes/file.php');
1492 + require_once(ABSPATH .'/wp-admin/includes/image.php');
1452 1493
1453 1494 }
1454 1495
1455 1496 }
@@ -1523,8 +1564,24 @@
1523 1564 return true;
1524 1565
1525 1566 }
1526 1567
1568 +function usp_post_cats($post_id) {
1569 +
1570 + $cats = '';
1571 +
1572 + foreach((get_the_category($post_id)) as $category) {
1573 +
1574 + $cats .= $category->cat_name .', ';
1575 +
1576 + }
1577 +
1578 + $cats = trim($cats, ', ');
1579 +
1580 + return $cats;
1581 +
1582 +}
1583 +
1527 1584 function usp_send_mail_alert($post_id, $title, $content, $author, $email, $url, $custom, $custom_2, $post_date) {
1528 1585
1529 1586 global $usp_options;
1530 1587
@@ -1532,8 +1589,9 @@
1532 1589
1533 1590 $blog_url = get_bloginfo('url'); // %%blog_url%%
1534 1591 $blog_name = get_bloginfo('name'); // %%blog_name%%
1535 1592 $post_url = get_permalink($post_id); // %%post_url%%
1593 + $post_cats = usp_post_cats($post_id); // %%post_cats%%
1536 1594 $admin_url = admin_url(); // %%admin_url%%
1537 1595 $post_title = $title; // %%post_title%%
1538 1596 $post_content = $content; // %%post_content%%
1539 1597 $post_author = $author; // %%post_author%%
@@ -1544,22 +1602,23 @@
1544 1602 $delete_link = usp_remote_delete_post_link($post_id); // %%delete_link%%
1545 1603
1546 1604 $patterns = array();
1547 1605
1548 - $patterns[0] = "/%%blog_url%%/";
1549 - $patterns[1] = "/%%blog_name%%/";
1550 - $patterns[2] = "/%%post_url%%/";
1551 - $patterns[3] = "/%%admin_url%%/";
1552 - $patterns[4] = "/%%post_title%%/";
1553 - $patterns[5] = "/%%post_content%%/";
1554 - $patterns[6] = "/%%post_author%%/";
1555 - $patterns[7] = "/%%user_email%%/";
1556 - $patterns[8] = "/%%user_url%%/";
1557 - $patterns[9] = "/%%edit_link%%/";
1558 - $patterns[10] = "/%%custom_field%%/";
1559 - $patterns[11] = "/%%custom_field_2%%/";
1560 - $patterns[12] = "/%%delete_link%%/";
1561 - $patterns[13] = "/%%post_date%%/";
1606 + $patterns[0] = "%%blog_url%%";
1607 + $patterns[1] = "%%blog_name%%";
1608 + $patterns[2] = "%%post_url%%";
1609 + $patterns[3] = "%%admin_url%%";
1610 + $patterns[4] = "%%post_title%%";
1611 + $patterns[5] = "%%post_content%%";
1612 + $patterns[6] = "%%post_author%%";
1613 + $patterns[7] = "%%user_email%%";
1614 + $patterns[8] = "%%user_url%%";
1615 + $patterns[9] = "%%edit_link%%";
1616 + $patterns[10] = "%%custom_field%%";
1617 + $patterns[11] = "%%custom_field_2%%";
1618 + $patterns[12] = "%%delete_link%%";
1619 + $patterns[13] = "%%post_date%%";
1620 + $patterns[14] = "%%post_cats%%";
1562 1621
1563 1622 $replacements = array();
1564 1623
1565 1624 $replacements[0] = $blog_url;
@@ -1575,19 +1634,28 @@
1575 1634 $replacements[10] = $custom;
1576 1635 $replacements[11] = $custom_2;
1577 1636 $replacements[12] = $delete_link;
1578 1637 $replacements[13] = $post_date;
1638 + $replacements[14] = $post_cats;
1579 1639
1580 1640 //
1581 1641
1582 1642 $subject_default = $blog_name .': New user-submitted post!';
1583 1643 $subject = (isset($usp_options['email_alert_subject']) && !empty($usp_options['email_alert_subject'])) ? $usp_options['email_alert_subject'] : $subject_default;
1584 - $subject = preg_replace($patterns, $replacements, $subject);
1644 + for($i = 0; $i < count($patterns); $i++) {
1645 + $pattern = isset($patterns[$i]) ? $patterns[$i] : '';
1646 + $replace = isset($replacements[$i]) ? $replacements[$i] : '';
1647 + $subject = str_replace($pattern, $replace, $subject);
1648 + }
1585 1649 $subject = apply_filters('usp_mail_subject', $subject);
1586 1650
1587 1651 $message_default = 'Hello, there is a new user-submitted post:'. "\r\n\n" . 'Title: '. $post_title . "\r\n\n" .'Visit Admin Area: '. $admin_url;
1588 1652 $message = (isset($usp_options['email_alert_message']) && !empty($usp_options['email_alert_message'])) ? $usp_options['email_alert_message'] : $message_default;
1589 - $message = preg_replace($patterns, $replacements, $message);
1653 + for($i = 0; $i < count($patterns); $i++) {
1654 + $pattern = isset($patterns[$i]) ? $patterns[$i] : '';
1655 + $replace = isset($replacements[$i]) ? $replacements[$i] : '';
1656 + $message = str_replace($pattern, $replace, $message);
1657 + }
1590 1658 $message = apply_filters('usp_mail_message', $message);
1591 1659
1592 1660 $html = isset($usp_options['usp_email_html']) ? $usp_options['usp_email_html'] : false;
1593 1661 $format = $html ? 'text/html' : 'text/plain';