BuddyDev

BuddyPress Simple Front End Post

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.

Do you need a more powerful solution for front-end posting? Try BuddyBlog Pro. You can create unlimited forms, fields, and user profile tabs with the BuddyBlog Pro plugin.

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

Release History

  • Version: 1.3.9

    Wednesday, 30 June, 2021
    • Tested With: BuddyPress 8.0.0
    • Compatible With: BuddyPress 6.0+

    Added action hooks to allow intercept the form saving.

  • Version: 1.3.8

    Tuesday, 07 May, 2019
    • Tested With: BuddyPress 4.3.0
    • Compatible With: BuddyPress 2.5+

    Fix js bug due to undefined object property

  • Version: 1.3.6

    Saturday, 01 December, 2018
    • Tested With: BuddyPress 4.0
    • Compatible With: BuddyPress 2.5+

    Fix the taxonomy checkbox issue. The checkbox now works for all taxonomies.

  • Version: 1.3.5

    Tuesday, 31 July, 2018
    • Tested With: BuddyPress 3.1
    • Compatible With: BuddyPress 2.5+

    Add support for post visibility(public,private)

  • Version: 1.3.4

    Friday, 23 March, 2018
    • Tested With: BuddyPress 2.9.3
    • Compatible With: BuddyPress 2.5+

    Post date as per creation date if updated

  • Version: 1.3.3

    Saturday, 03 March, 2018
    • Tested With: BuddyPress 2.9.3
    • Compatible With: BuddyPress 2.5+

    Fix the sanitization for check boxes.

  • Version: 1.3.2

    Thursday, 04 January, 2018
    • Tested With: BuddyPress 2.9.2
    • Compatible With: BuddyPress 2.5+

    Categories in dropdown fix

  • Version: 1.3.1

    Friday, 11 August, 2017
    • Tested With: BuddyPress 2.9.0
    • Compatible With: BuddyPress 2.5+

    Updated with various action hook. The changes are limited to form.php

  • Version: 1.3.0

    Saturday, 17 September, 2016
    • Tested With: BuddyPress 2.6.2
    • Compatible With: BuddyPress 2.0+

    Updated to fix the thumbnail attachment and the New button.

  • Version: 1.2.9

    Tuesday, 19 April, 2016
    • Tested With: BuddyPress 2.5.2
    • Compatible With: BuddyPress 2.0+

    Fixed loading of form from theme files.
    Fixed notices.
    Added from id to forms.

  • Version: 1.2.8

    Friday, 18 March, 2016
    • Tested With: BuddyPress 2.5.1
    • Compatible With: BuddyPress 2.0+

    Updated to fix notices, improve code quality and fix an issue with custom field due to the auto draft usage.

  • Version: 1.2.7

    Monday, 14 December, 2015
    • Tested With: BuddyPress 2.4.2
    • Compatible With: BuddyPress 2.0+

    Fix upload permissions for subscribers

  • Version: 1.2.6

    Sunday, 13 December, 2015
    • Tested With: BuddyPress 2.4.2
    • Compatible With: BuddyPress 2.0+

    Add proper support for post thumbnail and upload

  • Version: 1.2.5

    Saturday, 12 December, 2015
    • Tested With: BuddyPress 2.4.2
    • Compatible With: BuddyPress 2.0+

    Add support for Media uploader

  • Version: 1.2.4

    Wednesday, 18 November, 2015
    • Tested With: BuddyPress 2.4.0
    • Compatible With: BuddyPress 2.0+

    Add support for number, url custom field type.

  • Version: 1.2.3

    Saturday, 22 August, 2015
    • Tested With: BuddyPress 2.3.2.1
    • Compatible With: BuddyPress 2.0+

    Update to allow the dropdown categories to be ordered and sorted.

  • Version: 1.2.2

    Thursday, 20 August, 2015
    • Tested With: BuddyPress 2.3.2.1
    • Compatible With: BuddyPress 2.0+

    Allow passing child_of with specific term id

  • Version: 1.2.1

    Tuesday, 04 August, 2015
    • Tested With: BuddyPress 2.3.2.1
    • Compatible With: BuddyPress 2.0+

    Allow the developers to register an update_callback with each form that gets called after saving the post successfully.

  • Version: 1.2

    Tuesday, 16 June, 2015
    • Tested With: BuddyPress 2.3
    • Compatible With: BuddyPess 2.0+

    Refactored and updated. Fixes various notices. Breaks down into multiple files with better architectre.

  • Version: 1.1.4

    Wednesday, 05 February, 2014
    • Tested With: BuddyPress 1.9.1
    • Compatible With: BuddyPress 1.8+

    Update to support post thumbnail.