Using Cforms and Memberwing on WordPress

While my nights are spent defending the rights of A.D.D.ers throughout Gotham City, during the day I’m a mild-mannered web developer. One of my on-going tasks as a web developer is the maintenance of a membership-based website. Paid members come to the website and, after logging in, they can access the members-only sections of the site. Recently I needed to add a new section to the website that would have a sign-up form that is only accessible to members. Since the website is based on WordPress, I created this sign-up form using a combination of three plugins – CForms II (for forms creation); Exec-PHP (for executing PHP code within a post or page); Member-Wing (for creating protected pages/posts in WordPress) – and a bit of PHP script.

Here are the steps for creating a “protected” form using these three plugins (assuming you installed and activated them).

1. Create your sign up form in CForms. Make note of the name of the form. You’ll need it later.

2. Go to the page or post where you want to create the protected form.

3. Switch the editor to HTML mode. Below is the code you’ll need.

<h2>This is a Members-Only Meeting</h2>
{+}
<?php
global $user_ID;
if ( '' != $user_ID ) insert_cform('THE NAME OF YOUR FORM GOES HERE');
?>

Explanation of the Code

{+}

This code (brace, plus sign, brace) is used by MemberWing to mark premium content, that is, content that is only accessible to paid members. (See the note about “premium content” for more information.) Anything that appears below this code will not be visible to a visitor unless they are logged into the website. For example, going to the page without logging in, a visitor sees the following.

global $user_ID;
if ( '' != $user_ID ) insert_cform('THE NAME OF YOUR FORM GOES HERE');

If the visitor is logged in, then their user ID will not be equal to an empty string. Therefore, the insert_cform command used by CForms will display the form.

This is what the visitor sees after logging in.

Why Not Use This Code – <!–cforms name=”XYZ”–> – To Insert The Form?

You may be wondering why I had to use three plugins and some PHP code to create this members-only sign-up form. The reason is that if you just use the code <!–cforms name=”XYZ”–> to insert the form in your post or page, the form will be automatically inserted regardless of the premium content designation. That is, it will ignore the {+} because, well, it doesn’t “see” it.

Q.E.D.

blog comments powered by Disqus