Open teboy opened 10 months ago
I've merged #126 into master branch. Please give latest master branch a try to see if that fixes things.
Hello @r-a-y
I have updated the plugin but I am still getting errors this is message from my debug log file
2023-09-18T09:57:56+00:00 CRITICAL Cannot redeclare bp_follow_screen_followers() (previously declared in /var/www/wptbox/wp-content/plugins/buddypress-followers-master/_inc/users/screens.php:19) in /var/www/wptbox/wp-content/plugins/buddypress-followers-master/_inc/users/screens.php on line 17
2023-09-18T09:58:25+00:00 CRITICAL Cannot redeclare bp_follow_action_start() (previously declared in /var/www/wptbox/wp-content/plugins/buddypress-followers-master/_inc/users/actions.php:22) in /var/www/wptbox/wp-content/plugins/buddypress-followers-master/_inc/users/actions.php on line 21
Thanks
I cannot duplicate this problem. Can you try either renaming or deleting the buddypress-followers-master
folder and downloading the latest version from here -- https://github.com/r-a-y/buddypress-followers/archive/refs/heads/master.zip ?
Or if you are able to start on a fresh, test install of BP 12 beta with the latest version of buddypress-followers
, that would help as well.
Hi
For this error 2023-09-18T09:58:25+00:00 CRITICAL Cannot redeclare bp_follow_action_start() (previously declared in /var/www/wptbox/wp-content/plugins/buddypress-followers-master/_inc/users/actions.php:22) in /var/www/wptbox/wp-content/plugins/buddypress-followers-master/_inc/users/actions.php on line 21
I tried using gpt and it provided me with an updated code and I no longer receive this error again. To fix the error related to the actions.php file in the BuddyPress Follow plugin, you should check for the existence of functions before declaring them to avoid redeclaration issues. Here's the corrected code for the actions.php file:
`<?php /**
// Exit if accessed directly. defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'bp_follow_action_start' ) ) { /**
@uses bp_core_redirect() Safe redirects the user to a particular URL. */ function bp_follow_action_start() { $bp = $GLOBALS['bp'];
if ( ! bp_is_current_component( $bp->follow->followers->slug ) || ! bp_is_current_action( 'start' ) ) {
return;
}
if ( bp_displayed_user_id() === bp_loggedin_user_id() ) {
return;
}
check_admin_referer( 'start_following' );
if ( bp_follow_is_following( array( 'leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id() ) ) ) {
bp_core_add_message( sprintf( __( 'You are already following %s.', 'buddypress-followers' ), bp_get_displayed_user_fullname() ), 'error' );
} else {
if ( ! bp_follow_start_following( array( 'leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id() ) ) ) {
bp_core_add_message( sprintf( __( 'There was a problem when trying to follow %s, please try again.', 'buddypress-followers' ), bp_get_displayed_user_fullname() ), 'error' );
} else {
bp_core_add_message( sprintf( __( 'You are now following %s.', 'buddypress-followers' ), bp_get_displayed_user_fullname() ) );
}
}
// it's possible that wp_get_referer() returns false, so let's fallback to the displayed user's page.
$redirect = wp_get_referer() ? wp_get_referer() : bp_displayed_user_domain();
bp_core_redirect( $redirect );
} add_action( 'bp_actions', 'bp_follow_action_start' ); }
if ( ! function_exists( 'bp_follow_action_stop' ) ) { /**
@uses bp_core_redirect() Safe redirects the user to a particular URL. */ function bp_follow_action_stop() { $bp = $GLOBALS['bp'];
if ( ! bp_is_current_component( $bp->follow->followers->slug ) || ! bp_is_current_action( 'stop' ) ) {
return;
}
if ( bp_displayed_user_id() === bp_loggedin_user_id() ) {
return;
}
check_admin_referer( 'stop_following' );
if ( ! bp_follow_is_following( array( 'leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id() ) ) ) {
bp_core_add_message( sprintf( __( 'You are not following %s.', 'buddypress-followers' ), bp_get_displayed_user_fullname() ), 'error' );
} else {
if ( ! bp_follow_stop_following( array( 'leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id() ) ) ) {
bp_core_add_message( sprintf( __( 'There was a problem when trying to stop following %s, please try again.', 'buddypress-followers' ), bp_get_displayed_user_fullname() ), 'error' );
} else {
bp_core_add_message( sprintf( __( 'You are no longer following %s.', 'buddypress-followers' ), bp_get_displayed_user_fullname() ) );
}
}
// it's possible that wp_get_referer() returns false, so let's fallback to the displayed user's page.
$redirect = wp_get_referer() ? wp_get_referer() : bp_displayed_user_domain();
bp_core_redirect( $redirect );
} add_action( 'bp_actions', 'bp_follow_action_stop' ); }
if ( ! function_exists( 'bp_follow_my_following_feed' ) ) { /**
@author r-a-y */ function bp_follow_my_following_feed() { // only available in BP 1.8+. if ( ! class_exists( 'BP_Activity_Feed' ) ) { return; }
if ( ! bp_is_user_activity() || ! bp_is_current_action( constant( 'BP_FOLLOWING_SLUG' ) ) || ! bp_is_action_variable( 'feed', 0 ) ) {
return false;
}
$bp = $GLOBALS['bp'];
// setup the feed.
$bp->activity->feed = new BP_Activity_Feed( array(
'id' => 'myfollowing',
/* translators: User's following activity RSS title - "[Site Name] | [User Display Name] | Following Activity" */
'title' => sprintf( __( '%1$s | %2$s | Following Activity', 'buddypress-followers' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
'link' => bp_follow_get_user_url( bp_displayed_user_id(), array( bp_get_activity_slug(), constant( 'BP_FOLLOWING_SLUG' ) ) ),
'description' => sprintf( __( "Activity feed for people that %s is following.", 'buddypress' ), bp_get_displayed_user_fullname() ),
'activity_args' => array(
'user_id' => bp_get_following_ids(),
'display_comments' => 'threaded'
)
) );
} add_action( 'bp_actions', 'bp_follow_my_following_feed' ); } `
In this corrected code, I've added conditional checks using `if ( ! function_exists(
The only error left now in my log is
2023-09-21T12:58:02+00:00 CRITICAL Cannot redeclare bp_follow_screen_followers() (previously declared in /var/www/wptbox/wp-content/plugins/buddypress-followers-master/_inc/users/screens.php:19) in /var/www/wptbox/wp-content/plugins/buddypress-followers-master/_inc/users/screens.php on line 17
Are you sure you don't have two different copies of the plugin active? The plugin from the WP repo is in a directory named buddypress-followers, while the one from Github has "-master" at the end, so manually FTP'ing the plugin wouldn't replace the older version. I would check the wp-content/plugins folder for duplicates.
@mrjarbenne im 100% sure I only have one copy. Im only using the copy from github
And the error still exists if you deactivate all your other plugins and activated a default theme? All these re-declarations make it seem like perhaps another plugin or theme has tried to integrate bp-follow functions that are getting triggered first.
Hello @r-a-y @mrjarbenne
This issue is now resolved. The problem was caused by a plugin conflict with https://wordpress.org/plugins/mark-new-posts/ Its quite strange but immediately I deactivated Mark New Post plugin there was no more error
Thanks so much for your support
I looked into the "Mark New Posts" plugin and the problem is with this line: https://plugins.trac.wordpress.org/browser/mark-new-posts/trunk/mark-new-posts.php#L160 .
The plugin is fetching posts on the 'pre_get_posts'
hook, so this means that any plugin hooked to any main post query would run twice. I've added a clause so my code is only included once, but even with this line added, the "Mark New Posts" plugin will still break any BuddyPress page. I've replied to teboy's post on wordpress.org with some recommendations: https://wordpress.org/support/topic/buddypress-follow-conflict/#post-17069687 .
Thank you all for doing this - I downloaded the zip file and it worked great on BP :)
Hello R-A-Y/Buddypress-Followers, can you read me ? There is an error am getting on my site and it's not letting users follow watch other. Please check this screenshot for the errors code and help.
Hello @ray,
I decided to test buddypress 12.0.0 beta 1 & 2 and noticed that clicking the user navigation menu for following and followers tab triggers an error. The plugin is not compatible with the upcoming buddypress 12.0.0
A resolution would be really appreciated
Thanks