BuddyDev

BuddyPress Simple Front End Post

August 1st, 2013: BuddyPress Simple Front End Post plugin is tested to Work With BuddyPress 1.8


BuddyPress Simple Front End post plugin allows developer to create unlimited post forms for the front end posting. The current release includes support for custom posts type and categories but not the custom taxonomies. I will include custom taxonomy support in future.

I created this plugin to use with Blog categories with groups plugin as I could not find a nice solution for the purpose. Currently this plugin is aimed as 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 they like.

Here is a screenshot of it being used with Blog Categories for groups plugin

Features:-

  • Allows to create  any number of customized post forms
  • supports custom post type
  • supports including a list of categories
  • has a very simple to use API for developers(I will show an example below)
  • It is very very Light weight

How to Use It:-

The basic philosophy is to allow developers to create an Instance of  ’BPSimpleBlogPostEditForm’ class for each of their form. This class handles the view and behavior both. Once you create an instance, you will need to register it to the ‘BPSimpleBlogPostEditor’ class(which is implemented as singleton pattern). Ok, so that seems nasty, right? No worries, you don’t need to delve into that. There are two api functions which will do it for you. You just need to pass the form name(which should be a unique name, it can contain spaces etc) 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 ‘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 allowed parameters.

add_action('bp_init','my_post_form',4);//register a form
//it will register a fomr
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
}

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 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 existance 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 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 plugin version 1.0.4 supports this plugin. You will simply need to activate this plugin and the plugin will work as the form handler for Bp Blog Categories.

Code Repository: https://github.com/sbrajesh/bp-simple-front-end-post

Release History

  • Version: 1.1.4

    Wednesday, 05 February, 2014

    • Tested With: BuddyPress 1.9.1
    • Compatible With: BuddyPress 1.8+

    Update to support post thumbnail.

  • Version: 1.1.3

    Friday, 15 March, 2013

    • Tested With: BuddyPress 1.7+BuddyPress1.8
    • Compatible With: BuddyPress 1.7+BuddyPress1.8

    Updated to allow settings comment status for post.

  • Version: 1.1.2

    Saturday, 23 February, 2013

    • Tested With: BuddyPress 1.6.4/BuddyPress 1.7 Beta
    • Compatible With: BuddyPress 1.6+

    Update to allow validation of post data by other plugins. Also, add enhancements to keep the form data when a post is not successful.

  • Version: 1.1

    Monday, 18 February, 2013

    • Tested With: BuddyPress 1.6.4/BuddyPress 1.7 beta
    • Compatible With: BuddyPress 1.6+

    A major update to Simple Front End Post Plugin.
    It allows adding custom post type, custom taxonomy and custom fields now.

  • Version: 1.0

    Thursday, 01 December, 2011

    • Tested With: BuddyPress 1.5.1
    • Compatible With: BuddyPress 1.5+

    Initial release with support for custom post types and Categories. No taxonomy support in this release.