To avoid the “This page is restricted. Please Log in to view this page.” message and allow non-logged in users to access the WP User Frontend form, you have to modify 1 file in the plugin and then add a code block to your theme’s functions.php file.
[Note: this fix is wiped the next time you upgrade to the latest/greatest version of this plugin. Hopefully the plugin author (Tareq Hasan) will build this functionality into his next release.]
1) Plugin Edits:
In the ‘wp-user-frontend’ plugin folder, find ‘wpuf-add-post.php.’
Change this:
if ( is_user_logged_in() ) {
$this->show_form();
} else {
printf( __( “This page is restricted. Please %s to view this page.”);
}
To this:
if ( is_user_logged_in() ) {
$this->post_form( $post_type );
} else {
$this->post_form( $post_type );
}
This displays the form to non-logged-in users. However, after successful submission the plugin takes the user to the post they just created. Because the new post is probably in pending status for approval and the non-logged in user does not have access to the new page, they are redirected to a 404 page.
2) Theme Edits:
To avoid the 404 redirect mentioned above, we have to add some code to your theme so that users are redirected to a different page. Scroll to the bottom of your theme’s functions.php file.
Add the following:
/*——– WP User Frontend – Post Redirect ——–*/
function custom_redirect( $url ) {
global $post;
return get_permalink( $post->ID=ENTER_PAGE_ID_HERE );
}
add_filter( ‘wpuf_after_post_redirect’, ‘custom_redirect’ );
Above, where it says ‘ENTER_PAGE_ID_HERE,’ enter the ID of the page/post you want to take the user to.
In my case, I created a simple Thank you page for the user, after submission. Hope that helps!