BuddyPress Simple Front End post plugin allows the developer to create unlimited post forms for the front end posting. The current release includes support for custom posts type and custom taxonomies too.
We created this plugin to use with the Blog Categories with Groups/BuddyBlog plugin since we could not find a nice solution for the purpose. Currently, this plugin is aimed at developers. It has a simple API to create forms and to use them in theme. All the nasty works are handled by the plugin, so a developer does not need to dive into the code. Instead, just use two lines of code to create a custom post form for any purpose.
Here is a screenshot of it being used with the Blog Categories for Groups plugin
Features:-
- Allows to create any number of customized post forms
- Supports custom post type
- Supports custom taxonomies
- Supports front end media upload using native up loader ( added in version 1.2.6)
- Supports front end setting featured image( Added in version 1.2.6)
- has a very simple to use API for developers( see example below)
- It is very very lightweight
How to Use It:-
The basic philosophy is to allow developers to create an Instance of the 'BPSimpleBlogPostEditForm' class for each of their forms. This class handles the view and behavior. Once you create an instance, you will need to register it to the 'BPSimpleBlogPostEditor' class(which is implemented as a singleton pattern). You don't need to delve into all that to use this plugin. There are two API functions that will do it for you. You just need to pass the form name(which should be a unique name, it can contain spaces, etc, there is no such restriction) and the basic settings of the form(like post type, allowed categories, who can write, who will be attributed as the author of the post and the post status).
Registering a Form Instance:-
To create and register a post form(with settings), you will need to use the following code
$form = bp_new_simple_blog_post_form( $form_name, $settings );
The above code creates an instance of the 'BPSimpleBlogPostEditForm' class and registers it to the editor. You can create any number of forms you want. The above code must be called on/before bp_init action priority 10.
Here is a working example with the details of the allowed parameters.
/** * Register a custom Form * */ function my_post_form() { $settings = array( 'post_type' => 'post', //which post type 'post_author' => bp_loggedin_user_id(), //who will be the author of the submitted post 'post_status' => 'draft', //how the post should be saved, change it to 'publish' if you want to make the post published automatically 'current_user_can_post' => is_user_logged_in(), //who can post 'show_categories' => true, //whether to show categories list or not, make sure to keep it true 'allowed_categories' => array( 1, 2, 3, 4 ) //array of allowed categories which should be shown, use get_all_category_ids() if you want to allow all categories ); $form = bp_new_simple_blog_post_form( 'my form', $settings ); //create a Form Instance and register it } add_action( 'bp_init', 'my_post_form', 4 );//register a form
You can modify any parameter as you like. Even you can set it to allow non-logged-in users to submit post and save it to another user account.
The above code will register a new form with the name 'my form' and you can retrieve it later at any point and show the form anywhere using the following code. We need to register the form on/before bp_init priority 10 to allow the controller to have access to this form. If you register the form after bp_init action, the controller will be unaware of the form's existence and can not handle the save action.
Once a form is registered, you can show it anywhere you like using the following function.
//now let us find the form and render it $form = bp_get_simple_blog_post_form( 'my form' ); if ( $form ) {//if this is a valid form $form->show();//it will show the form }
You can use the above code anywhere in your template to render the form.
Though registering the form on/before bp_init action may seem like a bad choice to some of you, It allows for server-side validation of the credentials/authentication and thus helps from any misuse of the form.
It is a free plugin, please feel free to download it and use it on your custom projects. The Blog Categories for Groups & BuddyBlog plugin supports this plugin. You will simply need to activate this plugin and the plugin will work as the form handler for the BuddyBlog/BCG.
Code Repository: https://github.com/sbrajesh/bp-simple-front-end-post