Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author donmik

    (@atallos)

    I believe the best way to achieve this, is using the filter “bp_get_displayed_user_mentionname” to modify the user nicename returned. At the end you can add an image or if you want add a span with a custom css class and the background-color.

    Something like this should work:

    add_filter('bp_get_displayed_user_mentionname', 'my_custom_displayed_user_mentionname');
    function my_custom_displayed_user_mentionname($user_nicename) {
        $checkbox = (int) maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( ID_OF_CHECKBOX_FIELD, bp_displayed_user_id() ) );
        if ($checkbox) {
            $color = xprofile_get_field_data(ID_OF_COLOR_FIELD);
            if (!empty($color)) {
                $user_nicename .= '<span class="triangle-class" style="background-color: ' .
                    $color .'"></span>';
            }
        }
        return $user_nicename;
    }

    Replace ID_OF_CHECKBOX_FIELD with the Id of your checkbox acceptance field.
    Replace ID_OF_COLOR_FIELD with the Id of your color field.
    Replace “triangle-class” with the name of your css class.

    Thread Starter markyeoj

    (@markyeoj)

    Thanks, how can I check if that code is working? I want to display it beside the name all through out the site specially in profile page after the nice-name. Here’s my code in my child theme’s functions.php

    add_filter('bp_get_displayed_user_mentionname', 'my_custom_displayed_user_mentionname');
    function my_custom_displayed_user_mentionname($user_nicename) {
        $checkbox = (int) maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( field_570, bp_displayed_user_id() ) );
        if ($checkbox) {
            $color = xprofile_get_field_data(field_569);
            if (!empty($color)) {
                $user_nicename .= '<span class="triangle-class" style="background-color: ' .
                    $color .'"></span>';
            }
        }
        return $user_nicename;
    }

    Thanks.

    Plugin Author donmik

    (@atallos)

    If you put the code in functions.php, you must see the checkbox in all places where user_nicename is displayed. For example in members header when viewing a user profile. Check the html code of user nicename and see if the span is added at the end.

    Thread Starter markyeoj

    (@markyeoj)

    Sorry, the code seems not working ?? I can’t see any triangle-class on the code.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display colorpicker value if checkbox acceptance is checked.’ is closed to new replies.