BuddyDev

Search

[Resolved] BP Simple Front End Post Form


  • Keymaster
    Level: Guru
    (BuddyDev Team)
    Posts: 884
    Ravi on #3495

    Hi Leo,

    It is difficult to navigate the user to the page from where the post was published as it is a custom form and can be called on any places. But we can edit it from BuddyBlog edit form. Please modify the code for registering custom form

    
    function buudydev_post_form() {
    
        $settings = array(
    
            'post_type' => 'post',
            'post_author' =>  bp_loggedin_user_id(),
            'post_status' => 'publish',
            'tax' => array(
                'category' => array(
                    'include' => array( 61 ), //category ids
                    'view_type' => 'checkbox',
                )
            ),
    
            'current_user_can_post' => is_user_logged_in(),
            'show_categories' => true,
            'allow_upload' => true
        );
    
        bp_new_simple_blog_post_form( 'my_custom_form', $settings );
    
    }
    add_action( 'bp_init', 'buudydev_post_form', 4 );
    

    with this code

    
     function buudydev_post_form() {
    
        $settings = array(
    
            'post_type' => 'post',
            'post_author' =>  bp_loggedin_user_id(),
            'post_status' => 'publish',
            'tax' => array(
                'category' => array(
                    'include' => array( 65 ), //category ids
                    'view_type' => 'checkbox',
                )
            ),
            'custom_fields'				=> array(
                 '_my_custom_form' => array( 'type' => 'hidden', 'id' => 'my_custom_form', 'name' => 'my_custom_form', 'default' => 'my_custom_form' )
            ),
            'current_user_can_post' => is_user_logged_in(),
            'show_categories' => true,
            'allow_upload' => 1
        );
    
        bp_new_simple_blog_post_form( 'my_custom_form', $settings );
    
    }
    add_action( 'bp_init', 'buudydev_post_form', 4 );
    
    

    Also we need to override the buddyblog form template by copy “buddyblog/template/buddyblog/edit.php” file to your theme folder “buddyblog/edit.php” after copying, modify the following section

    
       $form = bp_get_simple_blog_post_form( 'buddyblog-user-posts' );
                                
        $form->show();
    

    with

    
      $form_id ='buddyblog-user-posts';
    
        $post_id = bp_action_variable( 0 );
        
        if( ! empty( $post_id ) && ! empty( get_post_meta( $post_id, '_my_custom_form', true ) ) ) {
            $form_id ='my_custom_form';
        }
    
        $form = bp_get_simple_blog_post_form( $form_id );
    

    it will load over custom form instead of BuddyBlog Form.


  • Participant
    Level: Enlightened
    Posts: 79
    Leo on #3537

    Hi Ravi,

    Thank you very much.

    I tried and replaced the codes you provided but it doesn’t load any form at all, the edit page loads without any form both for these posts and the main buddyblog posts. What could be the reason for that?

    Thank you,
    Leo


  • Keymaster
    (BuddyDev Team)
    Posts: 13806
    Brajesh Singh on #3544

    Hi Leo,
    I am sorry. Ravi will be back tomorrow.
    I had a look at the above code and I see that Ravi missed to post the last line.

    Please add this line

    
    $form->show();
    

    after this

    
    $form = bp_get_simple_blog_post_form( $form_id );
    

    That should work.

    Regards
    Brajesh


  • Participant
    Level: Enlightened
    Posts: 79
    Leo on #3548

    Hi Brajesh,

    Thank you. I added the line to show the form, but it still doesn’t show the correct form and after editing the posts go to other category.

    Thank you,
    Leo


  • Keymaster
    (BuddyDev Team)
    Posts: 13806
    Brajesh Singh on #3549

    Hi Leo,
    Is it happening for new posts or the old posts? This solution should only work with new posts using the custom form.

    Please let me know and I will check the code.

    Thank you
    Brajesh


  • Participant
    Level: Enlightened
    Posts: 79
    Leo on #3552

    Hi Brajesh,

    It happens for new posts, too. I just created a post and after editing, it does the same, goes to another category.

    Also, can you please check this?
    wp-debug is enabled and when I edit the form and submit, there’re such a notice and a warning:
    Notice: Undefined index: bp_simple_post_upload_thumbnail in /home/artsyner/public_html/test/wp-admin/includes/media.php on line 277
    Warning: Cannot modify header information – headers already sent by (output started at /home/artsyner/public_html/test/wp-admin/includes/media.php:277) in /home/artsyner/public_html/test/wp-includes/pluggable.php on line 1228

    maybe it has something to do with this all?

    Thank you,
    Leo


  • Keymaster
    (BuddyDev Team)
    Posts: 13806
    Brajesh Singh on #3553

    Hi Leo,
    Thank you. I will look into it and will get back to you in next couple of hours.

    Thank you
    Brajesh


  • Participant
    Level: Enlightened
    Posts: 79
    Leo on #3558

    Hi Brajesh,

    I just wonder if it would be easier if instead of different categories I make a custom post type? What do you think?

    Also, there’s the issue with form submission in Spanish and at WPML they’re trying to solve it.
    They also asked if you would like to apply for plugin compatibility. I remember you were interested.

    “It would be great if you can also contact the author asking him to apply to our Go Global program: http://wpml.org/documentation/theme-compatibility/go-global-program/ .”

    Thank you,
    Leo


  • Keymaster
    (BuddyDev Team)
    Posts: 13806
    Brajesh Singh on #3563

    Hi Leo,
    Thank you for the details.

    1. Are you using any custom code to assign categories or terms? Please post me the custom codes you are using.
    2. The two forms are different and even if they are being edited from same place, should have different setup unless some custom code is being used to assign/manipulate categories.

    There is no problem in using categories.

    I will be contacting the wpml.org about the plan. Hoping that it will help us in providing compatible plugins in future.

    Thank you
    Brajesh


  • Participant
    Level: Enlightened
    Posts: 79
    Leo on #3566

    Hi Brajesh,

    here’s the code Ravi provided, I use only categories, no tags:

    function buudydev_post_form() {

    $settings = array(

    'post_type' => 'post',
    'post_author' => bp_loggedin_user_id(),
    'post_status' => 'publish',
    'tax' => array(
    'category' => array(
    'include' => array( 65 ), //category ids
    'view_type' => 'checkbox',
    )
    ),
    'custom_fields' => array(
    '_my_custom_form' => array( 'type' => 'hidden', 'id' => 'my_custom_form', 'name' => 'my_custom_form', 'default' => 'my_custom_form' )
    ),
    'current_user_can_post' => is_user_logged_in(),
    'show_categories' => true,
    'allow_upload' => 1
    );

    bp_new_simple_blog_post_form( 'my_custom_form', $settings );

    }
    add_action( 'bp_init', 'buudydev_post_form', 4 );

    The 2 forms are different, the problem is when you want to edit the post, it doesn’t load the 2nd custom form and that’s why after editing the post falls under the first form’s category.

    Concerning WPML, yes, that would be great, however, all BuddyDev plugins that I use are quite compatible with WPML, just a few issues, that usually are solved here in this forum.

    Thanks,
    Leo

The topic ‘ [Resolved] BP Simple Front End Post Form’ is closed to new replies.

This topic is: resolved
Subscribe