Latest TweetsPleased to announce my new LinkedIn video course on WordPress & Shared Hosting: m0n.co/wp-shared-hosting
Perishable Press

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. And so without further ado..

Note that these FAQs are in no particular order..

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 can I 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 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 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.

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 using either of the following methods:

  • Replace your theme’s current author tags with USP’s usp_author_link()
  • Add some custom code to your theme’s functions.php file. If interested, please contact me directly, and I will send the code and steps to implement.

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 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 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! :)

Jeff Starr
About the Author Jeff Starr = Web Developer. Book Author. Secretly Important.
Archives
[ Comments are closed for this post ]