Enable your users to Pay-PER-Post, or create your own Advertise-On-This-Site ad system.

Hi all,

This is a follow-up to a previous post in which I hinted at an "option to submit premium listings" to a custom store directory: https://premium.wpmudev.org/forums/topic/diy-create-a-categorized-directory-of-marketplace-stores-with-unique-store-ratings-review-pages

The "premium listings" are in the form of paid user-submitted posts to blog categories of your choosing, and they can even be used for a custom Advertise-on-This-Site scenario. At the heart of this technique is WPMUdev's unique Pay-per-View plugin:

Thanks to help from @Hakan in another thread to pin down the most secure way to delete the cookie left by the PPV plugin, Pay-Per-Post is now a workable thing. Here's the thread for those interested: https://premium.wpmudev.org/forums/topic/ppv-with-gravity-form-post-form

Once I finish working on the write-up to detail how to git 'er done, I'll post it in this thread. Stay tuned... it's ossum!

In the meantime, you can see the technique working here: http://etcemall.com/
Click any ad placeholder - "Feature your store here" at the top of the page or "Click to get your ad here" in the footer. Then go ahead and click the pretty blue button with the $ sign... don't worry, we're in sandbox-mode at PayPal so it won't cost anything to try it out.

Back soon with more fun... :slight_smile:

  • aecnu
    • WP Unicorn

    Greetings pcwriter,

    Did you say possum? That pic in the woods looks like there might be some possum out there.

    I will get Granny going and Elley May and I will be there shortly for some vittles and possum :slight_smile: Sounds absolutely delicious.

    Thank you pcwriter for a little fun and we look forward to your next post, I just could not help myself poking a little fun at ossum ~or~ was that possum?

    Cheers, Joe

  • Patrick
    • Support Monkey

    Here it is... Enable your users to Pay-PER-Post, or create your own Advertise-On-This-Site ad system.

    You can see it working live here: http://etcemall.com/

    One important caveat before we begin:

    If you decide to implement this technique as a pay-to-post solution, you will NOT be able to use the Pay-Per-View plugin for any other purpose on your site except selling one-off access to single posts/pages. Even if you do that, it would be wise to post a notice on your post-submission page(s) to users warning them that once they submit their post, they will lose access to any other posts/pages they have paid for. Why? Because using PPV as a pay-to-post medium requires that the one-off cookie it leaves behind on the user's computer be deleted as soon as the user's paid-for post is submitted. Otherwise, users lacking in ethics or morality could abuse your system during that access period to submit multiple posts while having to pay only once.

    Other notes:

    I've set this up to use blog categories so your user's paid content will be posted to, and available in, standard archives and stuff. But you could just as easily create a custom post-type for this purpose. If you are using your site's blog for, well, blogging, and want to use this technique for ads, it's probably best that you do create a custom post-type for them. Otherwise, your blog archives may get cluttered with ads. On the other hand, from the advertiser's perspective, that's not such a bad thing, is it? :slight_smile:

    Also, I'm using Gravity Forms as a front-end post-form, but you can use any other solution as long as it allows you to post to predefined categories (or post-types).

    Be sure you're comfortable editing code as you'll see near the end of this tut (Step 11).

    Ready? Here we go...

    1. Install Pay-per-view plugin :slight_smile:
    Under "Accessibility Settings", set "Admin sees full content" to "No" for now (until we're done testing everything, then you can set it to Yes). Set the "Payment Options" to "One time view". Then set PayPal to "Sandbox" and enter your sandbox credentials. If you don't have a sandbox account and don't know how to set one up, check this out:

    2. Get yourself a cup of coffee.

    3. If you want to enable your users to submit to existing blog categories, you can skip this step. If you want them to post to categories reserved for user-submitted content, go to Posts > Categories in your WP dashboard and create the category (or categories) you want them to use. If you're using this technique for ad placement, I recommend giving the categories names that reflect the type of ad the user can place: 468x60px-banner, 480x360px-video, etc.

    3a. If you prefer custom post-types for your user-submitted content, there's a pretty cool plugin available right here to help you with that:

    So, PPV and PayPal sandbox are set up, and so are your categories/post-types? Let's set up an ad-submission form.

    4. Go to Gravity Forms and create a new form (if you're using a different post-form, go there now and adapt this part). Let's make one for user-submitted ads. You'll need the following fields (label them as below or any way you see fit):

    Title field = optional, and label not required (see below)
    Body field = label not required (see below)
    Image field = Upload your ad
    Website field = Link URL
    Category field = Ad type

    The Title field is only required if you are using post-types for your user-submitted content. Why? Because this plugin needs it:
    It's a free addon that allows you to use GF to post to your custom post-types. Cool huh? Under the "Advanced" tab for the Title field, tick the "Save As Post Type" checkbox. A dropdown will appear with the available post types. Select the one you want. Also, set the "Visibility" to Admin Only so the field does not display on the form.

    For the image field, a nice touch is including the Title metadata. That creates a little tooltip that pops up with whatever is entered when site visitors hover their mouse pointers over the submitted ad. Remember to select "Set as Featured Image"

    The website field is simply where the form user will enter the URL they want their ad to link to. Nothing special to do there.

    In the Category field, determine how you want users to select the appropriate one(s). Dropdown or Radio buttons for single categories, Checkboxes or Multiselect if you want to allow multiple categories. For ads, it's best to use the single options.

    Save your form before going to the Body field (this is to update the merge fields we need for the next step).

    Saved? Now, in the Body field, check "Create content template". You'll want to insert 2 merge fields into the box in this format to wrap the uploaded image in the URL (don't copy/paste this, select your own fields!):

    <a href="{Link URL:4}">{Upload your ad:1:full}</a>

    Under the "Advanced" tab in the Body field, check Admin Only so it doesn't display in the form.

    Save and preview your form. You should only see Image, URL and Category.

    5. Create a new page in WP for your new submission form. Add any intoductory text or instructions for your users. Then insert your form shortcode. If you're using Gravity Forms, be sure to clear the "Display form title" and "Display form description" checkboxes so that info does not display.

    6. At the top-right of your screen, you should see a new widget "Pay Per View". In the "Method" dropdown, select "Use selection tool". While in the Visual Editor, you'll see a new icon on the far right of your tray. Highlight your form shortcode and click that icon. Enter any description you like and the price you want to sell your ad/post space for. Save your page.

    7. When you visit your new page, you should only see your intro text and the PPV button with your pricetag on it. CLICK THAT BUTTON. Go through the PayPal process to be sure everything works. When you're redirected back to your page, click the Payment Confirmation button and, get ready, there's your form!

    8. Fill out your form by uploading an image that you'll easily recognize when you see it appear on your site in the next step.

    9. This step is fun. Get your hands on this plugin:
    It enables you to display any number of posts from any category(ies) in any way you want, anywhere you want, via shortcodes or widgets. It can even detect the category of the page it's on and display posts ONLY from that category. You can also add parameters to the shortcodes to wrap the content in HTML tags & CSS classes that you can then style via your theme's stylesheet. Get yourself familiar with this plugin and you'll be able to have your user-submitted content display anywhere you want, anyway you want. Cool!

    10. By now, you should have gotten the ad you uploaded in step 8 to display somewhere on your site. Maybe on a page, in a post, or in a widget. Now visit your form page again. If the form is still visible, it's because PPV set a cookie on your machine to keep that URL accessible to you for an hour. Let's make sure that doesn't happen anymore (and that's the whole point of this tutorial!).

    11. You'll need to write a new function to your theme's functions.php file.

    If you're using Gravity Forms, copy/paste the code below, just below the opening <?php tag. You only need to modify one thing in the code: your form ID. That's the number at the end of gform_after_submission_ (You'll find your form ID on your GF Edit Forms page in your WP backend.)

    add_action("gform_after_submission_2", "clear_ppv_cookie", 10, 2);
    function clear_ppv_cookie() {

    If you're using a front-end post-form OTHER than Gravity Forms, paste the following code in your functions.php file. You'll need to insert the NAME of your form's Submit button where it says "submit_name" (with the quotes).

    add_action('init', 'clear_ppv_cookie');
    function clear_ppv_cookie() {
     if ( isset( $_POST["submit_name"] ) ) { // Name of the submit button

    After uploading your newly edited functions.php to your server, test if the function is working by submitting a new ad, and going through the whole PayPal sandbox routine again (that'll freshen the cookie for ya). Revisit and refresh your form page. If you don't see your form, the cookie is gone. To be sure, in Firefox, visit Tools > Options > remove individual cookies. Scroll until you find your site, double-click the folder to open it; if you don't see pay_per_view in there, the function is working.

    If it is not working, replace the setcookie line with this:
    Apparently, not all server setups require the trailing "/"

    If it still doesn't work, please, invest in Gravity Forms; it's well-worth it.

    Congrats! You now have a fully-functional, pay-to-post, user-submitted content apparatus.

    Oh, but wait, there's one more thing: if we're selling ads, when do they expire? Aha, next step please...

    12. For user-submitted ads, this plugin is essential:
    It enables you to set a display duration for posts in selected categories. Once that duration has expired, posts are either permanently deleted or sent to Trash. Although this plugin hasn't been updated in 1½ years, it works just fine on WP 3.3.1. If you know of a more recent alternative, please, reply to this thread and let everyone know.

    We're done! I hope you had as much fun following along here as I did putting this stuff together. :slight_smile:


    The cookie-crumbling snippets above were made possible thanks to oodles of help from @Hakan in another thread to pin down the most secure way to do it. Here's the thread for those interested:

    And here are some great resources to bookmark if you plan on getting media-crazy with this technique:

  • aecnu
    • WP Unicorn


    I totally agree with pcwriter that one should always use a test environment unless it is a new install or one can that is not a production necessity.

    Another thing is that backups of the web site as well as the database should be done on a regular basis.

    Cheers, Joe

  • Sean Johnson
    • Site Builder, Child of Zeus


    Oh, Wow... this is so close to what I need. I can see instantly how I am much closer to implementing this from reading your post here. But still looking for *a little* direction for my senario.

    I have a few caveats:
    (1) I want this to purchase an existing post and the purchase to be facilitated through MarketPress - I can handle this as i've created a plugin to create a marketpress product (with reference to the post id) on the fly. What I don't know is how PPV's gateway should be over-ridden.
    (2) I would like the post to be able to be update-able by the user.
    (3) Some users may want to buy multiple posts, so how can they administer these altogether? ...as it was my understanding that gravity forms doesn't yet allow a user to edit their submitted form.

    I'm new to GF and PPV - I'm currently reviewing their code structure.

    Let me know if you've got any thoughts for direction for me :slight_smile: - big thanks for the awesome tutorial above.

  • josh
    • Site Builder, Child of Zeus

    @Patrick Cohen

    Great stuff here! Thank you for taking your time to help us out.

    Couple questions.

    Is there a new link the demo/live example? The one you listed above is no longer working

    Also, As you have been helping me so much, you probably know that I am setting up a MU + Marketpress + Prosites site. I want to use this to sell featured product spaces on the homepage. So shop owners can buy/rent the space for x amount of time and have the product of their choice show up on the front page.
    From what I understand, this is possible following this tut, as long as I use the custom post type 'Product'????

    In addition lets say there is my advertisement up selling the space. If someone buys it and posts their product up, will that space be temporarily occupied so no one else can buy it? And when the time, that I define, expires, will my ad come back up and anyone can buy it? Basically is it all automated?

  • Jim Flannery
    • WPMU DEV Initiate

    I'm working on this same approach.

    I am looking for two things.
    1) The ability to offer discount coupons or free posts to users. This would be without actually turning on 'free posting' for everyone. Just for those with a coupon.
    2) The ability to offer 'packages' - where a user, for example, could get 10 posts for the price of 5. Is this available?

    Not sure if its bad etiquette but I posted this on it's own ticket here:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.