Hey Dono12!
What worries me is that you say you don’t want to lose it in the next update of WordPress. Have you edited the core file ( general-template.php ) to read that or you using that particular code in a plugin/theme?
I’m not sure if you are aware of functionality plugins but you may want to look into them. What’s neat is that WordPress does have some great hooks and filters so that you can modify how some things look and act. The wp_register function is one.
If you look at line 535 of that file:
link: https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/general-template.php#L535
$link = apply_filters( 'register', $link );
What this means is you can do something like:
add_filter( 'register', 'my_custom_register_thingy' );
function my_custom_register_thingy( $link ){
if ( ! is_user_logged_in() ) {
if ( get_option('users_can_register') )
$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register', 'text-domain') . '</a>' . $after;
else
$link = '';
} elseif ( current_user_can( 'read' ) ) {
$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin', 'text-domain') . '</a>' . $after;
} else {
$link = '';
}
That is a quick example of how you can do it; I am currently not able to test that but feel free to dabble with that to suit your needs. 🙂
Thread Starter
Dono12
(@dono12)
It was an edit to the core file general-template.php. Not a plugin. Thanks for your help by the way, but the code above gave me the white screen of death when I placed it in functions.php. I think there’s also an extra bracket in the code you gave me. I tried removing one of the brackets and still got the white screen :(. Any further assistance would be greatly appreciated.
Wow, didn’t realize I missed the closing bracket for the function. 🙁
And that’s why I need to be drinking my coffee. Helps me focus. 🙂
Thread Starter
Dono12
(@dono12)
It still doesn’t work. This is what I have::::
function my_custom_register( $link ){
if ( ! is_user_logged_in() ) {
if ( get_option('users_can_register') )
$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register', 'buddypress') . '</a>' . $after;
else
$link = '';
} elseif ( current_user_can( 'read' ) ) {
$link = $before . '<a href="' . bp_loggedin_user_domain('/') . "profile" . '">' . __('User Profile', 'buddypress') . '</a>' . $after;
} else {
$link = '';
}
}
add_filter( 'register', 'my_custom_register' );
If I change general-template.php to its original coding
$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
and place the custom function you gave me into my functions.php, I still get Site-Admin in the sidebar Widget area.
Just before the closing bracket add:
if ( $echo ) {
echo $link;
} else {
return $link;
}
Thread Starter
Dono12
(@dono12)
It worked like a charm. Thanks a lot Jose.
Of course! Happy to help! 🙂