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

    (@atallos)

    If you want to do this, you can create a new filter in your functions.php overriding the filter of this plugin.

    Put this in your functions.php:

    function my_bxcft_get_field_value( $value, $type, $id) {
    
        if ($type == 'birthdate') {
            $value = str_replace("<p>", "", $value);
            $value = str_replace("</p>", "", $value);
            $field = new BP_XProfile_Field($id);
            // Get children.
            $childs = $field->get_children();
            $show_age = false;
            if (isset($childs) && count($childs) > 0) {
                // Get the name of custom post type.
                if ($childs[0]->name == 'show_age')
                    $show_age = true;
            }
            if ($show_age) {
                return '<p>'.floor((time() - strtotime($value))/31556926).'</p>';
            }
            return '<p>'.date_i18n( 'F j' , strtotime($value) ).'</p>';
        }
    
        return $value;
    }
    add_filter( 'bp_get_the_profile_field_value', 'my_bxcft_get_field_value', 15, 3);

    It will override the filter from the plugin and show only the day and month of birthdate. If you want to change the date format, you need to change this line:
    return '<p>'.date_i18n( 'F j' , strtotime($value) ).'</p>';

    F => Name of month.
    j => Day.

    Thread Starter sabya23

    (@sabya23)

    Thanks for your reply. I am checking…

    Thread Starter sabya23

    (@sabya23)

    Thanks. You are awesome.

    Plugin Author donmik

    (@atallos)

    You welcome!

    Thank you. I did try this and it will always show the current month + date, instead of the birthday and month..

    Also users can still select a year when editing their profile and I do not want them to select a year.

    If I manually hide the year by removing it in bp-xpprofile-custom-fields-type.php then it will not save when they edit their page.

    Hi,

    I added the code in the ‘functions.php’ file in the theme I’m using but it shows the whole thing at the top of the website.

    What ‘functions.php’ file am I supposed to add it to?

    Got it! I though I should post an update in case someone else is wondering.

    The code has to be added in ‘wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-functions.php’

    Plugin Author donmik

    (@atallos)

    It’s weird it does not work in your functions.php. If you put this in the bp-xprofile-functions.php and you update buddypress you will lose your code…

    I agree. It’s really weird and it’s actually the first time I come across this kind of problem.

    I’ll contact the theme’s support and I may be able to figure it out.

    I know that I’m going to lose it, but hopefully that’s a temporarily solution.

    Did I pick the right file though?

    Plugin Author donmik

    (@atallos)

    The functions.php in your theme is the right file yes. If it works in other file it should work here also.

    One more thing. After I added the code it shows the birthdate as ‘April 13’ in all users.

    How can I fix this?

    Plugin Author donmik

    (@atallos)

    If you want to show the year also you need to modify the date format:

    return '<p>'.date_i18n( 'F j' , strtotime($value) ).'</p>';

    Change “F j” with the format you want, you can see how to customize here.

    If you want the year, write this: “F j Y”.

    I don’t want to show the year actually. That was the reason I added the function you wrote above.

    The problem I have is that after entering the code it shows the birthdate as ‘April 13’ for all users no matter what they select.

    If you go to the ‘edit’ page though you see correctly, but it’s always April 13 in the ‘view’ page.

    I hope I make sense.

    Plugin Author donmik

    (@atallos)

    Mmmm, I think then there is an error when saving the birthdate. Can you check if “$value” is empty? If it’s empty, it must be showing april 13, today date.

    That’s what it does because now it shows ‘April 15’.

    How can I fix this?

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘Hide year of birth’ is closed to new replies.