BuddyDev

Search

[Resolved] BuddyBlog Pro – Custom field types

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #46299

    Hi Nik,
    I will suggest creating custom field type. The field type can have its own validation rules and will be much cleaner without any hardcoded dependency.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 279
    NikB on #46302

    Hi Brajesh

    Hopefully obviously, the code I posted was not complete and really only designed to test a theory, but I do take your point that creating a field type and then setting the postmeta directly with that may be a cleaner way to go.

    That said, I’d still love to understand why $_POST[‘my_custom_field’] (ie. where my_custom_field is any custom field that has been created in BuddyBlog) doesn’t seem to return a value regardless of the field type it has been assigned. If it’s easy to explain, I’d be very grateful… if not, no worries… I’ll focus on doing things the way you suggest for now.

    Regards
    Nik

  • Participant
    Level: Master
    Posts: 279
    NikB on #46822

    Hi Brajesh

    Whilst waiting for the final tweaks to BuddyBlog Groups, I thought I’d come back to this to see if I could figure out how to create my own custom field type for a date/time field which stores both date AND time (or indeed, even just a time field) but having looked at your implementation in buddyblog-pro/core/fields, I’m still not quite sure how to approach this eg. you have a file called class_bbl_field_type_date.php which I can probably examine further to create my own field type (which I assume I can store in my child theme) but how would I then use this with the filter ‘bblpro_registered_field_type_classes’?

    If you have any pointers to set me in the right direction, I’d be very grateful.

    With many thanks in advance
    Nik

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #46825

    Hi Nik,

    Here is how you register a field type

    
    
    add_filter( 'bblpro_registered_field_type_classes', function( $types ) {
    
    	$types['datetime'] = YourFieldTypeClassName;// please change it. 
    	return $types;
    });
    
    

    Also, The only issue with group which is remaining is Activity action string in BuddyBoss. I could not find time in last 3 days due to other release. I am hoping to work on it today/tomorrow and push a release.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 279
    NikB on #46838

    Thank you so much Brajesh… that’s just the kind of hint I needed. I’ll have a play and see what I can come up with.

    Good luck with the Activity action string and will look out for that in due course.

    Regards
    Nik

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #46840

    Hi Nik,
    You are welcome.

    I have released the update for BuddyBlog Groups now. Please update.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 279
    NikB on #46991

    Hi Brajesh

    So far I have attempted to add a new field type (‘time’) by creating a new file class-bbl-fieldtype-time.php and saving it in the same location as the other field type files (ie. buddyblogpro/src/core/fields). Then edited the source file bbl-field-type-functions.php ie. by adding

    use BuddyBlog_Pro\Core\Fields\BBL_Field_Type_Time;

    AND

    ‘time’ => BBL_Field_Type_Time::class (to the function bbl_get_registered_field_type_classes).

    Not very surprisingly, this works but clearly editing the source files isn’t the right way and I’m not quite sure how to make it work with a filter as you’ve suggested above ie. where should I be saving my class-bbl-fieldtype-datetime.php file? And is there anything else I need to change in my code in order to make the filter work from within my child theme?

    With very many thanks in advance for your thoughts.
    Nik

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #46998

    Hi Nik,
    We don’t have any restriction on where you put your class. The problem is you are using a namespace which is form the plugin and our auto loader looks for that into the fields directory(due to name space hierarchy).

    Please remove the name space at the top and the use statement and you can put it anywhere. If you can share the code on pastebin.php, I can gladly show how to put it in your theme’s functions.php(everything, no need to touch BuddyBlog Pro code).

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 279
    NikB on #47005
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #47080
    This reply has been marked as private.

The topic ‘ [Resolved] BuddyBlog Pro – Custom field types’ is closed to new replies.

This topic is: resolved