• Resolved baptx

    (@baptx)


    Hello,

    Some times ago I made a plugin based on BP Profile Search, it was using standard text fields so I did not need to use custom fields type (unlike the article https://dontdream.it/bp-profile-search/custom-profile-field-types/). I also did not want to use custom fields type to make fields compatible by default with BuddyPress, even if all other plugins are disabled. It was working great up to version 4.9.1 of BP Profile Search and stopped working since version 4.9.2.

    Basically, I was able to customize the search function in the BP Profile Search hook bps_add_fields but now the fields variable is empty in the new versions of BP Profile Search.

    Below is the code that is able to return fields in version 4.9.1 but returns an empty array in version 4.9.2. You can create a new test WordPress plugin and copy-paste the code in order to test it (to test with previous versions of BP Profile Search, you can download an old archive at the end of the page https://www.ads-software.com/plugins/bp-profile-search/advanced/).
    You will see an empty fields array since version 4.9.2, by opening the BuddyPress search page and viewing the HTML source code in a web browser like Firefox by doing a right click and selecting “View Page Source”. Then you can search for “TEST” without quotes to see the HTML comment with empty fields array by using the Ctrl+F shortcut of your browser.

    Do you know why the issue happens and do you plan to fix it? I did not see any deprecation notice in the changelog of version 4.9.2.

    Thanks.

    add_filter('bps_add_fields', myCustomSearch);
    function myCustomSearch($fields)
    {
    	echo '<!-- TEST fields: ' . print_r($fields, true) . ' -->';
    	foreach ($fields as $field) {
    		echo '<!-- TEST field: ' . print_r($field, true) . ' -->';
    	}
    	return $fields;
    }
    • This topic was modified 5 years ago by baptx.
    • This topic was modified 5 years ago by baptx.
    • This topic was modified 5 years ago by baptx.
    • This topic was modified 5 years ago by baptx.
    • This topic was modified 5 years ago by baptx.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hello baptx,

    The filter hook ‘bps_add_fields’ is used to add a field. If you wish to modify a field instead, your code must run after that field has been added, i.e. at a lower priority:

    add_filter('bps_add_fields', 'myCustomSearch', 1000);

    or using the action hook ‘bps_edit_field’:

    add_action('bps_edit_field', 'myCustomSearch');

    Thread Starter baptx

    (@baptx)

    Hi Andrea, it is working now, thanks!
    Do you know why we have to use a lower priority only since BP Profile Search version 4.9.2?
    Is it better to use bps_add_fields or bps_edit_field? For the moment I will keep the first hook, otherwise I need to change more code.
    By the way, I am using the hook bps_request to get fields values and use remove_filter function when I am done since the filter is called several times. Is it a good practice or do you recommend another hook? (maybe using a native BuddyPress hook or function like bp_get_the_profile_field_value is better)
    Thanks.

    • This reply was modified 5 years ago by baptx.
    • This reply was modified 5 years ago by baptx.
    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi baptx,

    You are welcome!

    Version 4.9.2 runs later, to make sure BuddyPress is active, and that changed the previous hook setup sequence.

    You are editing a field so, semantically, it’s better to use bps_edit_field, but practically there is no big difference.

    And yes, I think your usage of bps_request is correct.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘empty fields variable in bps_add_fields hook since BP Profile Search 4.9.2’ is closed to new replies.