- This topic has 14 replies, 3 voices, and was last updated 6 years ago by
Tom.
-
AuthorPosts
-
December 3, 2017 at 10:26 am #440667
Nathan Pinno
Hi Tom and folks,
Can someone help me with this? I’m creating a social network (for adults only) using GP, and one of the abilities for members is the ability to blog. All blogs are shown on the front page, and I want the author names to link to their BP profiles instead of the default blog author page WordPress uses. How do I do this? I think I need to create a filter, but I forget how to do so.
Thanks,
Nathan PinnoPS. I’m using the 2.0 Beta if that helps.
December 3, 2017 at 12:40 pm #440772Nathan Pinno
If anyone’s curious, here’s the code that I found (thanks to mastershas from the BuddyPress.org support forums!):
// Change Post's Author URL to Buddypress Profile URL add_filter('generate_post_author_output','generate_post_author_output_buddyprss_url'); function generate_post_author_output_buddyprss_url( $post_author_profile_link ){ $post_author_profile_link = sprintf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a href="%2$s" title="%3$s" rel="author"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by','generatepress'), esc_url( bp_core_get_user_domain( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'Know more about %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ) ) ) ; return $post_author_profile_link;
December 3, 2017 at 12:42 pm #440775Leo
StaffCustomer SupportGlad you found the solution!
December 3, 2017 at 1:02 pm #440786Nathan Pinno
Okay, when I tested the code for 2.0beta3 (as that’s what the site is running on for GP), it white screened my site. Not good! Don’t know if it’s a bug, or something else. Figured I’d better report this so that it can get fixed and a solution to my problem be found.
December 3, 2017 at 5:10 pm #440862Leo
StaffCustomer SupportHmm I don’t see why it would cause the white screen.
Can you try adding it using Code Snippets? https://docs.generatepress.com/article/adding-php/
December 3, 2017 at 5:12 pm #440865Nathan Pinno
Tried using both a plugin and via a child theme. Both refused to work and gave me the infamous white screen of death. Given that this worked with 1.4 of the theme (and WP 4.8 and the latest version of BP), something must have changed.
December 3, 2017 at 7:43 pm #440934Tom
Lead DeveloperLead DeveloperYour PHP is broken.
It should look like this:
add_filter('generate_post_author_output','generate_post_author_output_buddyprss_url'); function generate_post_author_output_buddyprss_url( $post_author_profile_link ) { $post_author_profile_link = sprintf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a href="%2$s" title="%3$s" rel="author"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by','generatepress'), esc_url( bp_core_get_user_domain( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'Know more about %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ) ) ) ; return $post_author_profile_link; }
December 3, 2017 at 8:26 pm #440943Nathan Pinno
Tried it and still got a White Screen of Death. π Anything else or should I give this up as a lost cause?
I’m getting very tempted to switch to a theme with built-in BP support in the blog author profiles, and will most likely do so if we can’t find a solution for this.
December 3, 2017 at 11:00 pm #441010Tom
Lead DeveloperLead DeveloperThe only way that code will trigger a fatal error is if
bp_core_get_user_domain()
doesn’t exist.You can guard against that like this:
add_filter('generate_post_author_output','generate_post_author_output_buddyprss_url'); function generate_post_author_output_buddyprss_url( $post_author_profile_link ) { if ( ! function_exists( 'bp_core_get_user_domain' ) ) { return $post_author_profile_link; } $post_author_profile_link = sprintf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a href="%2$s" title="%3$s" rel="author"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by','generatepress'), esc_url( bp_core_get_user_domain( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'Know more about %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ) ) ); return $post_author_profile_link; }
Tested the above, and it doesn’t cause any errors.
However, if that function doesn’t exist, the function won’t work (obviously).
December 3, 2017 at 11:16 pm #441019Nathan Pinno
Worked before I added it to the child theme’s functions.php, but after I added it, I got the white screen of death still! π
December 3, 2017 at 11:19 pm #441023Tom
Lead DeveloperLead DeveloperYou’ll want to check your error_log file for a specific error – the white screen isn’t very helpful.
It’s possible that you’re running out of PHP memory: https://docs.generatepress.com/article/increasing-php-memory-limit/
December 3, 2017 at 11:27 pm #441027Nathan Pinno
According to the log, it’s a syntax error:
syntax error, unexpected end of file in /home/ao/public_html/wp-content/themes/generatepress-child/functions.php on line 25
It’s also what caused the last 3 white screens of death. RAM appears to be just fine.
The code is:
<?php // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; // BEGIN ENQUEUE PARENT ACTION // AUTO GENERATED - Do not modify or remove comment markers above or below: // END ENQUEUE PARENT ACTION
So how do I fix it so that the error doesn’t pop up when I add the code to change the author link?
December 4, 2017 at 10:09 am #441429Tom
Lead DeveloperLead DeveloperThere’s no syntax error in that example there.
What’s the file look like once you add the function?
December 4, 2017 at 10:21 am #441437Nathan Pinno
<?php // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; // BEGIN ENQUEUE PARENT ACTION // AUTO GENERATED - Do not modify or remove comment markers above or below: // END ENQUEUE PARENT ACTION add_filter('generate_post_author_output','generate_post_author_output_buddyprss_url'); function generate_post_author_output_buddyprss_url( $post_author_profile_link ) { if ( ! function_exists( 'bp_core_get_user_domain' ) ) { return $post_author_profile_link; } $post_author_profile_link = sprintf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a href="%2$s" title="%3$s" rel="author"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by','generatepress'), esc_url( bp_core_get_user_domain( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'Know more about %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ) ) ); return $post_author_profile_link; }
This is what it looks like. I missed that last } though… oops!
/me feels embarrassed…December 4, 2017 at 10:24 am #441442Tom
Lead DeveloperLead DeveloperYea, I don’t see any issues there now.
-
AuthorPosts
- You must be logged in to reply to this topic.