Front end registration/login & publish/update 1 custom post

I want to be able to allow a user to register/login via a front end form and be able to create 1 custom post which only they will be able to edit and update via a front end form.

This will be part of a “dashboard”.

Read More

It’s very important that this works with the http://www.advancedcustomfield.com plugin.

I’ve managed to get some of the way there by using the front end forms from ACF. This allows the editing and updating of a custom post.

The problem with this is that:

  1. There is no front end registration/login.
  2. The post was already created, whereas I need a user to login and create 1 post initially.
  3. I’m only able to front end edit the post when I’m on the actual page. I need the user to only be able to edit their own post.

If anyone could point me in the right direction with those issues or has any creative ways to get around them then that would be great. I need to do this without using lot’s of other plugins.

UPDATE:

I’ve found that this will allow me to create a new post via a front end form. Using the action of the form I think I can redirect the user to the custom post they just created. Therefore that will allow them to update/edit the post via the 2nd code box below.

So all that I need to do is the user registration/login!

<?php $postTitle = $_POST['post_title'];
$post = $_POST['post'];
$submit = $_POST['submit'];

if(isset($submit)){

    global $user_ID;

    $new_post = array(
        'post_title' => $postTitle,
        'post_content' => $post,
        'post_status' => 'publish',
        'post_date' => date('Y-m-d H:i:s'),
        'post_author' => $user_ID,
        'post_type' => 'post',
        'post_category' => array(0)
    );

    wp_insert_post($new_post);

}

?>
<!DOCTYPE HTML SYSTEM>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled Document</title>
</head>

<body>
<div id="wrap">
<form action="" method="post">
<table border="1" width="200">
  <tr>
    <td><label for="post_title">Post Title</label></td>
    <td><input name="post_title" type="text" /></td>
  </tr>
  <tr>
    <td><label for="post">Post</label></td>
    <td><input name="post" type="text" /></td>
  </tr>
</table>

<input name="submit" type="submit" value="submit" />
</form>
</div>

</body>
</html>

The code below allows the user to edit/update the post they just created.

<?php
/**
 * @package WordPress
 * @subpackage Default_Theme
 * Template Name: Login
 */
acf_form_head();
get_header(); ?>

    <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>

<div style="width:719px;">
<?php global $current_user;
get_currentuserinfo();
$page_name = $current_user->user_login; ?>
Logged in as: <?php echo $page_name; ?> (<?php echo $current_user->ID; ?>)
<br />
List posts by <?php echo $page_name; ?>:

<?php               
$loop = new WP_Query( array(
    'post_type' => 'page',
    'author' => $current_user->ID
));

while ( $loop->have_posts() ) : $loop->the_post(); 
the_title();
echo "<br>";
endwhile;

//Reset Query
wp_reset_query();

?>

<?php $defaults = array(
    'post_id' => $post->ID, // post id to get field groups from and save data to
    'field_groups' => array(), // this will find the field groups for this post (post ID's of the acf post objects)
    'form_attributes' => array( // attributes will be added to the form element
        'class' => ''
    ),
    'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
    'html_field_open' => '<div class="field">', // field wrapper open
    'html_field_close' => '</div>', // field wrapper close
    'html_before_fields' => '', // html inside form before fields
    'html_after_fields' => '', // html inside form after fields
    'submit_value' => 'Update', // value for submit field
    'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
);

acf_form(); ?>
</div>

        <?php endwhile; ?>
    <?php endif; ?>

<?php get_footer(); ?>

Related posts

Leave a Reply

4 comments

  1. The WP User Frontend plugin will meet all your needs. You can find the plugin here: https://wordpress.org/extend/plugins/wp-user-frontend/.
    The plugin gives ability to the user to create new post, edit post, edit profile from site frontend. So users doesn’t need to enter the admin panel. Everything they need to do can be done from the frontend.

    If you do a small Google search you will encounter many other plugins with similair feautures. I do believe the WP User Frontend will be most compatibible with your needs and wants.

  2. Since you have already solved the editing issue, to settle your frontend login and registration use s2member plugin. I use it on my site to handle memberships and prevent members from accessing the backend of WordPress.

  3. For only managing user registration and login in the front-end, Theme My Login does quite a nice job.

    This plugin themes the WordPress login, registration and forgot
    password pages according to your current theme. It creates a page to
    use in place of wp-login.php, using a page template from your theme.
    Also includes a widget for sidebar login.

    The plugin page doesn’t have Screenshots, so here they go:
    enter image description here


    Here’s where you’d redirect the users to the page that uses the Template Name: Login:
    enter image description here

  4. I am using wp-members plugin for user registration and login without accessing WordPress back end.
    You would need some custom coding for password reset though. I am using this solution.

    Thanks for the code which allows users to create new posts!