Skip to:

Feature Request: Filterable xProfile Field Labels

  • Garrett Hyder



    Looking to request a feature for the xProfile fields, if this isn’t the right place to make sure a request can someone point me in the right direction.

    I would love the xProfile classes be updated so the field labels are filterable, in my case this would be useful so I can replace the standard (required) denotation specifically when the xProfile field is included on the WooCommerce Checkout form to utilize the standard woocommerce asterisk (*) denotation.

    The concept comes from the custom xProfile classes created by @donmik for the Buddypress Xprofile Custom Fields Type plugin;

    My specific implementation where the Xprofile fields are incorporated onto the Woocommerce Checkout form comes with the tandem implementation of the paid and free plugins by themekraft
    Paid Primary –
    Free Addon –
    Together these include the Xprofile fields onto the Checkout, however they don’t quite match with the Woocommerce fields so I had to add classes to them (currently capable through the bp_xprofile_field_edit_html_elements filter) and want to replace the (required) in the label with the appropriate asterisk.

    My current workaround involves jQuery to do the label replace, but I would prefer a label filter.

     * Add Javascript to replace Buddypress (required) with Woocommerce required asterisk (*)
    add_action('woocommerce_after_checkout_form', 'wc4bp_woo_replace_required_for_xprofile_checkout_fields');
    function wc4bp_woo_replace_required_for_xprofile_checkout_fields() {
        echo '<script>jQuery(document).ready(function($){$(".wc4bp_custom_checkout_fields_group label").each(function(i){$(this).html($(this).html().replace("(required)","<abbr class=\"required\" title=\"required\">*</abbr>"));});});</script>';

    An example how @donmik implemented a label filter for his custom Xprofile fields;

    $label = sprintf(
    	'<label for="%s">%s%s</label>',
    		(bp_get_the_profile_field_is_required()) ?
    			' ' . esc_html__( '(required)', 'buddypress' ) : ''
    // Label.
    echo apply_filters('bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required());

    Hoping this is the right channel for this request, otherwise hoping someone can point me to it. Or if the plugin is available on github would be happy to make a fork request and code the change myself.

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)

  • shanebp


    Did you try using:
    apply_filters( 'bp_get_the_profile_field_name', $field->name );
    and / or
    apply_filters( 'bp_get_the_profile_field_is_required', (bool) $retval );
    from bp-xprofile\bp-xprofile-template.php ?

    You can open an enhancement ticket here.

    Garrett Hyder


    Thanks @shanebp,

    Sadly neither of these filters will allow me to modify the ‘(required)’ text itself which is what I’m looking for, I guess I’m a little off in my request encompassing the entire label text as you pointed out the field name is filterable it’s the required portion that is outside of it as you can see in the code snippet;

    <label for="<?php bp_the_profile_field_input_name(); ?>">
    	<?php bp_the_profile_field_name(); ?>
    	<?php if ( bp_get_the_profile_field_is_required() ) : ?>
    		<?php esc_html_e( '(required)', 'buddypress' ); ?>
    	<?php endif; ?>

    And yes I realize I can replace it through the text-domain and a .po file, but I’d like to keep the (required) in the Buddypress Xprofile and target the inclusion of these fields specifically on the Woocommerce Checkout page where they’re included through the Buddypress for Woocommerce integration.

    I’ll open an enhancement request, thanks for pointing that out, and specify the targetting of the (required) portion of the label specifically.


    Garrett Hyder


    Posted Enhancement Request –
    If you have any suggestions or changes @shanebp your input is appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Feature Request: Filterable xProfile Field Labels’ is closed to new replies.
Skip to toolbar