Plugin Planet

Premium WordPress Plugins

Announcing a new extension for USP Pro: Auto-Expire Posts! This addon enables users to submit posts that expire at a specific date and/or time. Very useful for things like contest sites, special offers, and social media promotional adventures.

How to use

Easy. Just add the shortcode [usp_post_expire] to your USP Form. It automatically will display a date-time field for the user to select a date. So there is no configuration required, but the shortcode provides plenty of attributes so you can customize things like the type of field, label text, and more. Here is a handy reference guide:

Shortcode: Date/Time Expiration Input

Returns markup for date/time field, hidden field, and some jQuery

Syntax: [usp_post_expire]

Attributes:
	type     = (optional)  type of input field (date, time, datetime-local) [default: date]
	label    = (optional)  text for associated input label                  [default: Date]
	required = (optional)  whether the input should be required             [default: true]
	fieldset = (optional)  enable fieldset: true, false, or custom class    [default: true]
	class    = (optional)  comma-separated list of classes                  [default: none]
	custom   = (optional)  any attributes or custom code                    [default: none]
	max      = (optional)  maximum number of allowed characters             [default: unlimited (999999)]
	error    = (optional)  custom name (displayed if there is an error)     [default: value of label attribute]

Example: [usp_post_expire type="datetime-local" label="Post Expiration Date" required="true" fieldset="true" max="999" error="Post Expiration Date"]

Here is a basic example of how it works:

  1. Add the shortcode to your form
  2. User selects a date and submits the post
  3. The post will expire on the specified date

So if the submitted post is “published”, it will be expired to “draft” status at the specified date. Otherwise, if the post is not published, then basically nothing will happen (other than the usp-custom-expires custom field will change to usp-custom-expired, which may be useful for certain implementations).

Get the extension!

Buy Auto-Expire Posts

Check out more extensions »

Advanced: Custom Fields

By default, the shortcode generates one of three types of fields: date, time, or datetime-local. These are the standard HTML5 date-related input fields, and they cover a lot of use cases. But there may be situations where you need more control over the input field markup. Or maybe you don’t want to give the users a choice, and would rather just specify a static expiration date.

Expiration date with custom field

If you would rather use your own markup for the date/time input field, follow these steps.

Step 1: Add Custom Field

First, define your custom field and add it to the form. Here is an example that you can use as a starting point:

field#input|name#expires|type#datetime-local|label#Custom Date/Time Input|placeholder#Custom Date/Time Input

Make sure that the field attribute is input, and the name attribute is expires. Everything else may be customized as desired. Here is a shortcode reference for custom fields, providing all available attributes, etc.

Step 2: Add hidden field

Once you have defined your custom field and added it to the form, the next step is to add the required hidden field:

<input type="hidden" class="usp-post-expires" name="usp-post-expires" value="">

You can add this anywhere in the form content. No modifications are required.

Step 3: Add JavaScript

Lastly, add the required JavaScript to the form content, anywhere after the hidden field from step 2.

<script>
jQuery(document).ready(function($) {
	$('.usp-form').on('submit', function(e) {
		var usp_input = '#usp-custom-expires';
		if ($(usp_input).val().trim()) {
			var usp_expires = $(usp_input).val().replace('T', ' ');
			$('.usp-post-expires').val(usp_expires);
		}
	});
	$('.usp-error').each(function(index) {
		var text = $(this).text(); 
		$(this).text(text.replace('expires', 'Post Expiration'));
	});
});
</script>

Once you have completed all three steps, remember to save your changes. Then visit the form on the frontend and try submitting a few test posts to see how it works. Note that this tutorial provides the basic markup/JavaScript required; feel free to modify further if desired.

Specify a fixed/static expiration date

To set a fixed or static expiration date that will apply to all posts submitted via your USP Form, add the following code to the form content (on the “Edit USP Form” screen):

<input type="hidden" name="usp-post-expires" value="2017-11-15 07:04">

And then change the 2017-11-15 07:04 to the date/time at which you would like the submitted posts to expire. Note that the date must be written in Unix/POSIX format (which is a 24-hour format).

Get the extension!

Buy Auto-Expire Posts

Check out more extensions »