Guest Author is a kind of guest account in which the visitors can register and use it to submit a post without any admin permission. This helps you have more content for your site, so it absolutely benefits you. From an order of my client, I saw that adding this is pretty interesting then want to share with you how to do it. Of course, using Meta Box.

The order from my client has a form as below:

  1. The guest can register an account and manage it in frontend as a Guest Author account;
  2. Guest Author can submit posts to the website;
  3. Every guest post from Guest Author must be review before publishing;
  4. Guest Author can manage their posts list, edit each one before reviewing.

I will show you how to solve all the above requirements in two posts. In the first one, I’m solving the 1st and 2nd. The left ones are going on in the next post.

Before Get Started

To solve all the above requirements, we should use Meta Box and its three extensions, which are:

  • Meta Box Builder (premium): provides an intuitive UI to create custom fields. This is optional.
  • MB User Profile (premium): allows you to create register/login forms, or manage accounts in the frontend.
  • MB Frontend Submission (premium): helps you create a form to submit posts in frontend.

Now, let’s get started.

1. Create My Account page in the frontend

Step 1: Allow guest user to register and login an account

Turning on this function is quite easy. In the admin dashboard, go to the Settings menu > General, then check the box Anyone can register in the Membership item.

Allow guest user to register and login an account
Allow guest users to register an account

In the New User Default Role item, you should choose a Subscriber to restrict the permission of the new user.

Now, go to the default login page of WordPress (URL: yourdomain.com/wp-login), you will see the Register link as in the below image.

the Register link as in the below image

When someone clicks to the text Register, they will be redirected to the register page.

Step 2: Create fields for user profile

In this step, we will use MB User Profile to create fields for the user profile, which can be managed and edited from the frontend.

Firstly, we create a new custom field group (means custom meta box). Go to the Meta Box menu > Custom fields > Add New in the admin dashboard.

Create a new custom field group (means custom meta box)
Create a new custom field group (means custom meta box)

I set ID for this field group is user-profile. Then, I created custom fields inside this group as First name, Last name, Description.

All the above information is text, so I created Text fields for First name and Last name and a Textarea field for Description.

Create fields for User Profile
Create fields for User Profile

If you want the user profile has avatar and title, just create additional fields with the correspondence type.

For your quick reference, this is the instruction to create the basic fields using Meta Box.

After creating all the essential fields, still in the Edit Field Group screen, go to the Settings tab, choose Users in the Show for item.

Set the custom fields to show for Users
Set the custom fields to show for Users

Finally, press Publish to save these custom fields.

Step 3: Create “My Account” page in the frontend

This page is where the guest author manages and updates their profile.

3.1. Create a template for My Account page

First, create a new file named page-account.php in the theme folder with the content as below:

<?php
/*
*     Template Name: My Account
*/
?>

Aside from that, add this code to the file:

<?php if ( !is_user_logged_in() ) {
       auth_redirect();
} ?>

This forces users to go to the login page before access My Account page if they haven’t logged in any account yet.

3.2. Create My Account page

Back to the admin dashboard, go to Page > Add New to create a new page.

Create a new page
Create a new page

I set its name is My Account. In the edit page of this page, go to Page Attributes > Template in the right sidebar, then choose a template named My Account. This is the template created in the previous step.

 

Choose a template for the My Account page
Choose a template for the My Account page

Now, save the page.

3.3. Show content and the essential fields in the My Account page

Open the file page-account.php once again, add the the_content() function right after get_header() and before get_footer().

For your quick reference, this is the whole code for this file which I made with Twenty Seventeen theme:

Back to the edit page of the My Account page in the admin area, add the below shortcode to its content:

[mb_user_profile_info id="user-profile" label_submit="Update"]
Add shortcode to the content of the My Account page to show all the fields
Add shortcode to the content of the My Account page to show all the fields

In there:

  • mb_user_profile_info: Shortcode to show the form of the user profile;
  • id: ID of the Custom Field Group;
  • label_submit: this is the label of the submit button. I set it is Update.

Apart from that, there are dozens of shortcode which MB User Profile supports. You will find out more here.

Then, save the page and go to My Account page in the frontend. You’ll see something like this:

 Account page background
This is my My Account page

In addition, if you allow users to change their passwords from the My Account page, add this below shortcode to the content of that page:

[mb_user_profile_info id="rwmb-user-info"]

So, you’ve finished the page to manage the user profile in the frontend already.

2. Allow guest user to submit posts in the frontend

Post submission in the frontend is the same as the listing submission which we had an instruction to do in the post How to Create a Classified Ads Website using Meta Box.

Step 1: Create a Custom Field Group

As creating a field group for the user profile, I created a new field group as following:

Create a new field group
Create a new field group

In my case, fields for the post submission just include title and content, so I did not create any sub-fields inside this field group. In your cases, if you need any further fields, just add them as you want.

You will see the shortcode of the field group when you go to Meta Box > Custom Fields.

Shortcode of the field group
Shortcode of the field group

Copy and save it somewhere.

Step 2: Create the Post Submission Page in the Frontend

Create a new page by going to Page > Add New. Then, paste the above shortcode into the content fields of this page.

Create the post submission page
Create the post submission page

Save it and go to this page in the frontend, you will see this:

The post submission page in the frontend
The post submission page in the frontend

Step 3: Set a Layout and Login Requirement for the Post Submission Page

The post submission page has the same layout and requirements that users must log in before access as the My Account page. So, I do the same actions to this page as the My Account page as following.

Create a file named page-submission.php in the theme folder with the content copied from thepage-account.php, but changed the template name.

<?php
/*
*     Template Name: Publish Post
*/

?>
<?php if ( !is_user_logged_in() ) {
       auth_redirect();
} ?>

The whole code of my post submission page is below:

After that, go back to the edit page of this submission page in admin, choose the template named Publish Post (which I set in the page-submisson.php file) in the Page Attributes section.

Add a template for the post submission page
Add a template for the post submission page

Now, you’ve finished already.

Finish setting a Layout and Login Requirement for the Post Submission Page

Final Words

Well, we have created two pages which are My Account and Post Submission for the Guest Author. Please pay heed that we need to install all three extensions from Meta Box to do the above execution. Especially, thanks to Meta Box Builder that I created custom fields easily without touching any line of code in some steps.

We will use this plugin and its extensions in the next part to solve the 3rd and 4th requirements, which are the guest post review and management.

Leave a Reply