Spring Sale! Save 30% on all books w/ code: PLANET24
Web Dev + WordPress + Security

FAQs for User Submitted Posts

This post contains overflow FAQs for the free version of User Submitted Posts (hosted at WordPress.org). I am moving a bunch of the FAQs to this post in order to clean up the plugin’s ever-growing readme.txt file. For FAQs about the Pro version of USP, check out USP Pro – FAQs & Presales over at Plugin Planet. Note that these FAQs are in no particular order. So without further ado..

Tip: This post contains numerous code snippets for customizing USP. They can be added via theme functions.php or via simple plugin. Here is a guide that explains more about adding custom code to WordPress.

Is it possible to set up conditional redirects?

I haven’t tried it myself, but it might be possible. In the form code, there is a hidden input that specifies the redirect URL. The hidden input has a name attribute with a value of redirect-override. So you could target this input with some JavaScript, and then change the value of the hidden field based on whatever criteria you need.

What is the plugin setting for the “From” email header?

That setting enables you to customize the address used as the “From” header for email messages. If your email address is a domain-based address, then this setting should be the same as the previous Email setting. Otherwise, if you are using a 3rd-party email service, this setting should be a local, domain-based address. If you find that email messages are getting sent to the spam bin, this setting may help.

How can I display the form again after the user has successfully submitted a post?

Follow the steps to create a custom form, but use submission-form-alt.php instead of submission-form.php. Note the alternate form template still needs a way to clear cookies after successful form submission, so not recommended for public sites.

Does USP require the functions exec(), exec.php, or url_fopen?

Nope. User Submitted Posts does not use any of those functions.

Can I delete the free version of USP after upgrading to Pro?

Question: “I have recently upgraded to USP pro. Can I safely delete the old plugin and still keep all the existing post data and meta?”

Answer: Yes it is safe to remove the free version at any time. As explained in the plugin documentation:

“Note: uninstalling the plugin from the WP Plugins screen results in the removal of all settings from the WP database. Submitted posts are NOT removed if you deactivate the plugin, reset default options, or uninstall the plugins; that is, all submitted posts (and any attached meta data) must be removed manually.”

Tip: If you want to remember how USP (free version) is configured, take a screenshot of the settings page before you uninstall the plugin. And just FYI: the Pro version includes an Export feature so you can save your settings at any time.

Why doesn’t the USP shortcode work when added to the WP Text widget?

By default, WordPress does not enable shortcodes in widgets. I have added a plugin setting called “Enable Shortcodes” that will enable any/all shortcodes to work in widgets. Enable that setting and you should be good to go.

Note: the “Enable Shortcodes” setting applies to all shortcodes, even those of other plugins. Check out WP-Mix for more information on enabling shortcodes in widgets.

My form has lots of extra spacing between each field, how to fix?

There are numerous reasons why a form might be displayed with too much spacing between the fields. Here are some possible things to look at:

  • The USP shortcode may be wrapped with <code> tags; solution: remove the code tags.
  • Theme CSS may be interfering with its own styles; solution: examine theme styles and edit as needed.
  • There may be interference from some other plugin/theme; solution: troubleshoot your plugins and themes (check out the sections on troubleshooting plugins and themes).

The Name and URL fields are not displayed in the form, even though they are set to display in the plugin options.

The setting “Registered Username” when enabled will automatically hide the Name field. Likewise the setting “User Profile URL” when enabled will automatically hide the URL field. Try enabling these settings, logging out of WordPress, and then refreshing the form page.

How do I display success and error messages when the “Redirect URL” setting is enabled?

Add the following template tag in your theme template, wherever you want to display the success/error messages:

<?php echo usp_redirect_message(); ?>

You can then style the output via the following selectors:

.usp-error {}
#usp-error-message {}
#usp-success-message {}

Check out more CSS hooks for User Submitted Posts.

Nothing happens when you click on the “Add another image” link.

The “Add another image” link is dependent on the required JavaScript being included in the page. Check the plugin setting to “Include JavaScript?” and you should be good to go. Also make sure that the “Image Uploads” settings are configured to allow multiple files.

The height of my form fields are all messed up, how to fix?

USP provides its own, very minimal styles. Nothing that sets the height for any form fields. So if your field heights look weird, most likely your theme or a plugin is adding its own CSS styles. To resolve, you can try adding this bit of CSS to your stylesheet:

#usp_form .usp-input, #usp_form .usp-select, #usp_form .usp-textarea, #usp_form .usp-submit { height: initial; }

That line basically resets the height property of all form fields to the original value. So it should override any other height styles.

How can I customize the login-required message and URL?

When the setting “Require User Login” is enabled, and the user is not logged in, they will see a message that says, “Please log in to submit content!”. To customize this, add the following code to your theme’s functions.php file:

function usp_customize_login_required_message($message) {
	return '<p>Please <a href="http://example.com/wp-login.php">register</a> to submit content.</p>';
}
add_filter('usp_require_login', 'usp_customize_login_required_message');

Then customize the return line however is desired. This trick uses USP’s filter hook, usp_require_login.

To also customize the URL that is used for the “log in” link, add this code:

function usp_require_login_url($url) {
	$url = 'https://example.com/'; // edit this to whatever you want
	return $url;
}
add_filter('usp_require_login_url', 'usp_require_login_url');

The only thing you need to edit is the value of the $url variable. Change it to whatever URL you would like to use for the “log in” link.

How to change the default Post Type?

By default User Submitted Posts submits user posts as regular WP Posts. So for example, they will be displayed in the WP Admin Area on the Posts screen. To change that, and submit posts instead as any other post type or Custom Post Type, add the following function to your theme’s functions file or via simple plugin:

// USP submit posts to CPT
function usp_modify_post_type($post_type) {
	
	return 'book'; // change this to the slug of your post type 
	
}
add_filter('usp_post_type', 'usp_modify_post_type');

This is a very simple function that simply returns a value to use for the submitted post type. So change the book value to the actual slug/id of the post type or CPT that you want to use. Note: you must specify a valid/correct slug or this technique will not work.

Bonus Tip: If you are submitting posts to a custom post type, you can also add the name of your CPT to the “Post Type” option on the plugin settings page. Here is the code:

// USP add CPT to plugin options
function usp_add_post_type_option($post_types) {
	
	$post_types['book'] = array('value' => 'book', 'label' => 'Book');
	
	return $post_types;
	
}
add_filter('usp_post_type_options', 'usp_add_post_type_option');

Remember to replace book and Book with the name and label of your CPT, respectively.

How to change the default Post Format?

If you theme supports Post Formats, you can use the following code to assign a post format to all submitted posts:

function usp_set_post_format($post) {
	
	$id = isset($post['id']) ? $post['id'] : null;
	
	if ($id) set_post_format($id, 'YOUR_POST_FORMAT');
	
}
add_action('usp_insert_after', 'usp_set_post_format');

Replace YOUR_POST_FORMAT with the name of the post format that you want to use. This code can be added to your theme functions.php or added via simple custom plugin. Here is a guide that explains more about adding custom code to WordPress.

How to change the submit button text?

To change the text that’s displayed on the form’s submit button, add this code snippet to the plugin setting “Custom Content”:

<script>
	jQuery(document).ready(function($){
		$('.usp-submit').prop('value', 'Submit Post');
	});
</script>

Then change the phrase “Submit Post” to whatever you want. Don’t forget to save changes.

How to display a “Non-USP” button to filter non-submitted posts?

By default, USP provides a button that enables filtering of all submitted posts on the Posts screen in the WP Admin Area. So when you click on the “USP” button on the Posts screen, it will display only submitted posts. As of USP version 20190825, it also is possible to display a “Non-USP” button that filters all non-submitted posts. Just add this code via your theme functions or custom plugin:

// USP add button to display only non-submitted posts
function usp_filter_posts_link($link, $current) {
	
	$non  = '<a id="usp-admin-filter-other" class="button" ';
	$non .= 'href="'. admin_url('edit.php?post_type='. $current .'&user_submitted=0') .'" ';
	$non .= 'title="'. esc_attr__('Show non-submitted posts', 'usp') .'">';
	$non .= esc_html__('Non-USP', 'usp') .'</a>';
	
	return $non . $link;
	
}
add_filter('usp_filter_posts_link', 'usp_filter_posts_link', 10, 2);

No changes are necessary, USP plugin provides all the other code to style the button and make this work. Once added, this code will display a “Non-USP” button on the Posts screen (or whatever post type is selected for the USP “Post Type” setting).

How to display the USP Meta Box on other post types?

By default USP limits display of its meta box to Posts and Pages only (post types = post or page). As of USP version 20190825, there is a filter that can be used to add other post types to the list. Add the following snippet to your theme functions or via simple plugin:

// Add custom post type to USP Meta Box
function usp_meta_box_custom_post_types($post_types) {
	
	array_push($post_types, 'book'); // change 'book' to your custom post type
	
	return $post_types;
	
}
add_filter('usp_meta_box_post_types', 'usp_meta_box_custom_post_types');

As-is this function adds the “book” CPT to the list for displaying the USP meta box. You can change “book” to your post type, or even add multiple CPTs as needed, etc.

How can I change the default Post Title?

When the Post Title field is not included in the submission form, USP automatically uses the default: “User Submitted Post”. To customize the default Post Title, you can use the provided USP filter hook, usp_default_title. Here is an example:

function usp_customize_default_title($title, $time) {
	return $title .' - '. $time;
}
add_filter('usp_default_title', 'usp_customize_default_title', 10, 2);

That will append a unique date/time string to the default Post Title.

How to allow tags in post titles?

By default, USP removes all tags from submitted post titles. This is for security and is recommended in general. If you need to allow tags like <em> and <strong> in titles, you can enable them by adding the following code snippet:

function usp_title_tags_allow($allow) { 
	return true; 
}
add_filter('usp_title_tags_allow', 'usp_title_tags_allow');

By default, this filter allows only the tags <em>, <i>, <strong>, and <b> in post titles. To allow other tags, you can add the following code:

function usp_title_tags_allowed($tags) {
	return '<em><i><strong><b><span>'; // adds <span> to default allowed tags
}
add_filter('usp_title_tags_allowed', 'usp_title_tags_allowed');

Edit the <em><i><strong><b><span> to allow the necessary tags. Here we have added <span> to the default allowed tags. Just be very careful with the tags you allow, and never allow anything other than simple inline tags. To be safe, only allow from the following HTML tags:

<em>, <i>, <strong>, <b>, <span>, <code>, <a>, <center>

Recommended to only allow tags from that list. To be 100% safe, never allow any other tags in post titles.

How can I change the label “Post Tags”?

To change the “Post Tags” label, add the following jQuery code to the plugin setting “Custom Content”:

<script>
	jQuery(document).ready(function(){
		jQuery('.usp-tags label').text('Whatever');
	});
</script>

Change the text Whatever to whatever you want the label to display. Don’t forget to save changes. Note: similar code can be used to change the labels for other fields, just replace .usp-tags with .usp-content, etc.

How can I change the default Post Status?

By default, the Post Status for submitted posts is “pending”. To change that to whatever you want, add the following code to your functions or custom plugin:

function usp_custom_post_status($postData) {
	$postData['post_status'] = 'private';
	return $postData;
}
add_filter('usp_post_data', 'usp_custom_post_status');

As written, that code will set the status to “private” for all submitted posts. You can change it to any valid Post Status.

How to NOT allow any HTML tags in submitted content?

By default, USP (free version) allows only HTML tags that are normally allowed in post content. This is done via WordPress’ wp_kses_allowed_html() set to post. To change that, for example to NOT allow any HTML tags in post content, add the following custom code:

function usp_content_allowed_tags($allowed_tags) {
	return array(); // customize the array of allowed tags as needed
}
add_filter('usp_content_allowed', 'usp_content_allowed_tags');

As written, the above code prevents any HTML tags from submitted post content. So you can change the return value and customize the array of allowed tags to whatever is best for your site. Note that line breaks and automatic paragraph tags (i.e., basic text formatting) continues to work even when using the above function/hook.

How to stop certain IP addresses from posting?

Here is a way to block certain IP addresses from submitting post content. Add the following custom code to your WordPress site:

function usp_check_if_allowed() {
	
	$ip = usp_get_ip_address(); // user's current ip address
	
	$not_allowed = array('111.111.111.111', '123.123.123.123'); // array of not allowed ip addresses
	
	if (in_array($ip, $not_allowed)) return false;
	
	return true;
	
}
add_filter('usp_check_if_allowed', 'usp_check_if_allowed');

The two IP addresses contained in the array are just examples. You can change those to whatever IP address(es) as needed. You could also customize the above code to filter unwanted user names, or any other criteria.

How can I change the Polylang post language?

USP provides a filter hook to change the function that is used by the Polylang plugin. By default it uses the “default” language. To change that to “current”, add the following code snippet to your theme functions file:

function usp_pll_set_post_language($default_or_current) {
	
	return 'current'; // accepts default or current
	
}
add_filter('usp_pll_set_post_language', 'usp_pll_set_post_language');

The filter function returns one of two values: “default” or “current”. Use whichever one is required for desired Polylang functionality.

How can I change the language for Parsley validation?

User Submitted Posts uses Parsley.js for form validation. By default the validation messages (like when the user does not fill out required fields) are displayed in English. To display errors in another supported language, follow these steps:

  1. Check if your language is supported
  2. Download the JavaScript file for your language (e.g., fr.js)
  3. In your WordPress theme directory, create a folder named usp
  4. Copy/paste your language file into the /usp/ directory
  5. Add the following custom code to your WordPress site:
function usp_custom_parsley_language($hook) {
	
	wp_enqueue_script('usp-parsley', get_template_directory_uri() .'/usp/fr.js');
	
}
add_action('wp_enqueue_scripts', 'usp_custom_parsley_language');

Lastly, edit the above code to reflect the name of your language file. So change fr.js to the actual file name you are using. After that, upload everything to your site and done. Your USP form now will display any error messages in your chosen language.

Also, here is a guide that explains how to add custom code snippets like the one above.

Change the default option for Category and Tag fields

By default, the Category and Tag dropdown/select fields display the default “Please select” option as:

  • Please select a category..
  • Please select some tags..

To change these default options, you can either use the custom form template (as explained in the plugin documentation), or you can add the following jQuery code snippet to the USP option, “Custom Content”:

<script>
var usp_disable_chosen = true;
jQuery(document).ready(function($) {
	$('select option:contains("Please select some tags..")').text('Whatever..');
	$('select option:contains("Please select a category..")').text('Whatever..');
});
</script>

Then edit the “Whatever..” text in the code above to whatever you want. The first instance is for the Tag field. The second instance is for the Category field. Save changes and done. Note that you may need to empty/clear browser cache and/or reload the form page to view changes.

How to change the “Please select” for select fields?

By default the Category and Tag fields display the text “Please select..” when using the select field type. To change that text, you can either set up the custom form (as explained in the documentation). OR you can add a bit of jQuery:

1) Add the following code to the option “Custom Content”:

<script>
var usp_disable_chosen = true;
jQuery(document).ready(function($) {
	$('select option:contains("Please select some tags..")').text('Whatever..');
	$('select option:contains("Please select a category..")').text('Whatever..');
});
</script>

2) Edit the “Whatever..” text in the code above to whatever you want. The first instance is for the Tag field. The second instance is for the Category field.

Save changes and done. May need to empty/clear browser cache and/or reload the form page to view changes.

Is it possible to highlight required fields with an asterisk or similar?

Yes there are two ways to go about it:

* Use the custom form and change the labels and placeholders to include an asterisk or whatever is needed.

* OR use CSS to add whatever characters and/or styles, for example:

<style>.usp-name label:before { content: '* '; }</style>

That will add an asterisk to the Name field label. You can add that line (or any code) via the plugin setting “Custom Content”, or you can add via your theme or any number of ways. Similar rules can be added for any fields that are required. Tip: To get the class names of any field, use your browser’s code inspector.

How to include a link or markup in the deny message?

For these shortcodes:

[usp_access deny=""]
[usp_visitor deny=""]
[usp_member deny=""]

You can add a link or other markup inside of the deny attribute like so:

[usp_member deny="This is a {a href='https://example.com'}link{/a}"]

When the deny message is displayed, the curly quotes will be replaced automatically, so a link will be displayed.

For this to work:

  • Replace angle brackets in the link with curly brackets
  • Use single quotes for the attribute values (important)

This works for any of the above-listed shortcodes.

How to display a success message when a user deletes their post?

USP provides a shortcut, %%delete_link%%, that can be included in email alerts. When included, the shortcut outputs a link in the email message. When the user clicks the link, the specified submitted post will be deleted, and the user taken to the homepage with no message displayed. That’s fine for users who understand what’s going on. But for other users it may be confusing to not get some sort of confirmation. So, to display a “success” or “error” message, a developer or savvy WordPress user could use the following code as a starting point.

function usp_remote_delete_post_alert() {
	
	if (isset($_GET['usp-delete-post']) && $_GET['usp-delete-post'] === 'true') {
		
		// successful delete
		
	} else {
		
		// not successful
		
	}
	
}

That checks if the requested URL contains the query string, usp-delete-post, and if so, whether the value is true (post delete success) or false (post delete failure). So a developer can hook that into the WordPress init hook or anywhere that makes sense. From there, custom code may be used to display some markup and a message, or whatever is needed.

I’m new to WordPress and just installed USP. How do I display the form?

To add the form via shortcode, you can visit the Post or Page on which you would like to display the form, and then paste the shortcode into place. Remember to save your changes.

To add the form via template tag, it really depends on the theme, because each theme tends to use template files differently. It also depends on where on the page you would like to display the form, for example the sidebar (sidebar.php), the footer (footer.php), and so forth. Also, chances are that you’ll need to add the form to more than one template file, for example index.php and page.php, etc. A good first place to try would be the sidebar, or maybe index.php and then go from there.

How do I display the submitted Author Name and Author URL instead of the Default Assigned Author?

This functionality is built in to the Pro version of USP, but it’s also possible by replacing your theme’s current author tags with USP’s usp_author_link() tag.

Update

In the latest version of USP (free), the author is replaced automatically (unless you disable via the settings). And for the author URL, you can add the following code:

function usp_replace_author_link($link, $author_id, $author_nicename) {
	global $post;
	if (is_object($post)) {
		$is_submission = get_post_meta($post->ID, 'is_submission', true);
		$usp_url       = get_post_meta($post->ID, 'user_submit_url', true);
		
		if ($is_submission && !empty($usp_url)) return $usp_url;
		
	}
	return $link;
}
add_filter('author_link', 'usp_replace_author_link', 10, 3);

That can be added directly to your theme’s functions.php file, or added via simple plugin. No modifications required.

How do I remove the appended number from submitted image file names?

By default, USP appends a “dash-number” to the name of each submitted image. To prevent this, you can add the following code to your theme functions.php or add via custom plugin:

function usp_customize_filename_append($append) {
	return '';
}
add_filter('usp_filename_append', 'usp_customize_filename_append');

No modifications are required; simply add and done.

How do I add a name attribute to the submit button?

Enter the following code in the plugin option “Custom Content”.

<script>
	jQuery(document).ready(function($){
		$('.usp-submit').attr('name', 'submit');
	});
</script> 

This technique can be modified to add other attributes to other form elements. Check the docs for the jQuery attr() function for details. Note that this code snippet relies on jQuery in order to work, so make sure jQuery is loaded on the page before use.

How do I customize the names of uploaded images?

Here is some code that you can add to your theme functions.php or add via custom plugin:

function usp_customize_attachment_data($attachment) {
	
	/*
		$attachment includes:
		
		array(5) {
		  ["post_mime_type"]=>
		  string(10) "image/jpeg"
		  ["post_name"]=>
		  string(13) "example.jpg"
		  ["post_title"]=>
		  string(13) "example.jpg"
		  ["post_status"]=>
		  string(7) "inherit"
		  ["guid"]=>
		  string(67) "https://example.com/wp-content/uploads/2018/05/example.jpg"
		}
		
	*/
	
	// do your thing..
	
	return $attachment;
	
}
add_filter('usp_insert_attachment_data', 'usp_customize_attachment_data');

This code snippet enables you to intercept the image filename before the image is added to the WP Media Library. So you can customize the name however is desired.

How can I customize/change uploaded file names?

USP provides numerous filter hooks for modifying the names of uploaded files. Here is an example that shows how to do this using the powerful usp_file_name hook:

function usp_file_name($file_name, $filename, $append, $ext) {
	
	/*
		$file_name = return value
		$filename  = root file name
		$append    = appended number
		$ext       = file extension
	*/
	
	// make any modifications and then return the full file name below
	
	return $file_name;
	
}
add_filter('usp_file_name', 'usp_file_name', 10, 4);

The hook passes several useful parameters, giving you complete control over file names.

How to add a “Disable Comments” checkbox?

A user asked if it is possible to add a checkbox to the form that disables comments on the submitted post. The answer is yes, it is possible but requires a bit of work. Here are the steps to make it happen:

  1. Choose “Custom Form” for the option “Form Style”. Save changes.
  2. Follow the instructions to implement the custom form.
  3. Locate the following line in the custom form template:
    <?php echo usp_display_custom_checkbox(); ?>
  4. Just before that line, add the following code:
<fieldset class="usp-checkbox">
	<input id="user-submitted-comments" name="user-submitted-comments" type="checkbox"> 
	<label for="user-submitted-comments">Disable comments on this post?</label>
</fieldset>

Save changes, upload and done. When the box is checked, comments will be disabled on the post. When the box is not checked, comments will be open (or whatever default WordPress setting is enabled).

How do I make changes to the custom form?

The free version of USP provides a custom form. Say if you want to do some basic customizing and so forth. The instructions in the USP Installation docs (under “Custom Submission Form”) explain how to set up and enable the custom form. So then you’re all set to make any changes as needed.

But what if you are not sure how to proceed from there. Like once the custom form is set up, how to do something simple like change the labels or placeholders? Hopefully the following mini-tutorial will help get you started.

First understand the purpose of each of the two custom form files:

  • usp.css — this is a CSS file, used to change appearance, like colors, font sizes, margins, et al.
  • submission-form.php — this is a PHP file, it uses scripted language to output dynamic content. You’ll notice code wrapped in <?php tags, stuff like variables and simple logic. This file also uses HTML to provide form structure, for example you will notice tags such as <label>, <input>, and <p>, among others.

With that in mind, let’s say that we want to change the text displayed for a certain label and placeholder. Just for an example. To achieve it, follow these steps:

  1. Open submission-form.php in a code editor or plain-text editor (do not use any rich-text processor like Microsoft Word. Plain text or code editor only. This is important to keep your code free from artifacts like “smart”/curly quotes.
  2. Inside of the file, take a look around and get a basic idea of scope, structure, and contents.
  3. Now locate the <label> tag or placeholder attribute that you want to change. And change it.
  4. Save the file and upload to your server.
  5. Visit the form in a browser and test thoroughly.

Important: make sure not to change anything in the custom form unless you are 100% sure that you 1) know what it does, and 2) understand “why” you want to change it. Basically know what you are doing before making any changes.

Note: unless you are comfortable with editing code you may want to hire a pro. But of course one of the great things about WordPress is that it is within reach for just about anyone. Walking through a few basic HTML & CSS tutorials should be enough to enable simple form customization.

I need help doing basic troubleshooting, can you provide any resources?

Yes, check out these tutorials:

For troubleshooting plugins and themes, check out the first tutorial sections on “Plugins” and “Themes”.

More FAQs & Infos

For more USP FAQs (for the free version of the plugin), visit the User Submitted Posts homepage at WordPress.org. For FAQs about the Pro version of USP, check out USP Pro – FAQs & Presales over at Plugin Planet.

Questions? Feedback?

Send any questions or feedback via my contact form, and I’ll get back to you asap. Thanks! :)

About the Author
Jeff Starr = Web Developer. Book Author. Secretly Important.
.htaccess made easy: Improve site performance and security.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
WP Themes In Depth: Build and sell awesome WordPress themes.
Thoughts
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
First snow of the year :)
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.