Skip to content

Commit

Permalink
Merge branch 'PRJ-59' into PRJ-60
Browse files Browse the repository at this point in the history
  • Loading branch information
annrra committed Feb 3, 2025
2 parents cc4f85c + 5fa0dd6 commit 7cf6a90
Show file tree
Hide file tree
Showing 26 changed files with 1,038 additions and 207 deletions.
138 changes: 138 additions & 0 deletions src/bp-core/bb-core-readylaunch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* BuddyBoss Core Readylaunch.
*
* Handles the core functions related to the BB Readylaunch.
*
* @since BuddyBoss [BBVERSION]
*/

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

/**
* Register readyLaunch widgets.
*
* @since BuddyBoss [BBVERSION]
*/
function bb_rl_register_widgets () {
if ( bb_get_enabled_readylaunch() && function_exists( 'bp_get_following_ids' ) ) {
$plugin_dir = BP_PLUGIN_DIR;
if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && ! empty( constant( 'BP_SOURCE_SUBDIRECTORY' ) ) ) {
$plugin_dir = $plugin_dir . 'src';
}
$widget_file = $plugin_dir . '/bp-core/classes/class-bb-core-follow-my-network-widget.php';
if ( file_exists( $widget_file ) ) {
require_once $widget_file;
if ( class_exists( 'BB_Core_Follow_My_Network_Widget' ) ) {
add_action(
'widgets_init',
function() {
register_widget( 'BB_Core_Follow_My_Network_Widget' );
}
);
}
}
}
}

add_action( 'bp_register_widgets', 'bb_rl_register_widgets' );

/**
* Register the readyLaunch sidebar.
*
* @since BuddyBoss [BBVERSION]
*/
function bb_rl_register_sidebar() {
$sidebar_id = 'bb-readylaunch-members-sidebar';
register_sidebar(
array(
'name' => __( 'BB ReadyLaunch™ Members Sidebar', 'buddyboss' ),
'id' => $sidebar_id,
'description' => __( 'Add widgets here to appear in the right sidebar on ReadyLaunch pages. This sidebar is used to display additional content or tools specific to ReadyLaunch.', 'buddyboss' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'bb_rl_register_sidebar' );

/**
* Hide readylaunch sidebar to be viewing in admin area.
*
* @since BuddyBoss [BBVERSION]
*/
function bb_rl_modify_members_sidebars_widgets( $sidebars_widgets ) {
if ( is_admin() ) {
unset( $sidebars_widgets['bb-readylaunch-members-sidebar'] ); // Remove all widgets from specific sidebar
}
return $sidebars_widgets;
}
add_filter( 'sidebars_widgets', 'bb_rl_modify_members_sidebars_widgets', 11 ); // Runs after widgets_init

/**
* Manually add readylaunch sidebar widgets.
*
* @since BuddyBoss [BBVERSION]
*/
function bb_rl_manually_add_members_sidebar_widgets() {
// Get the sidebar ID.
$sidebar_id = 'bb-readylaunch-members-sidebar'; // Use the correct sidebar ID.
$widget_id = 'bb_core_follow_my_network_widget'; // The widget's registered ID.
$instance_id = '999';
$widget_instance_id = $widget_id . '-' . $instance_id;
$sidebars_widgets = get_option( 'sidebars_widgets', array() );

// Ensure it's an array, even if the option exists but is empty.
if ( ! is_array( $sidebars_widgets ) ) {
$sidebars_widgets = array();
}

// The widget details
$widget_instance = array(
'widget_id' => $widget_id ,
'instance_id' => $instance_id, // Use the correct instance ID.
);

$widget_settings = array(
'max_users' => 15,
'member_default' => 'followers',
);

// Save widget settings to the options table
$option_name = 'widget_' . $widget_id; // Key for this widget settings.
$current_settings = get_option( $option_name, array() );

// Ensure it's an array, even if the option exists but is empty.
if ( ! is_array( $current_settings ) ) {
$current_settings = array();
}

// Add the widget settings to the existing ones (or create new if not present).
if ( ! array_key_exists( $widget_instance_id, $current_settings ) ) {
$current_settings[ $instance_id ] = $widget_settings;
}

// Save the updated widget settings back to the options table.
update_option( $option_name, $current_settings );

// Remove from inactive.
if ( isset( $sidebars_widgets[ 'wp_inactive_widgets' ] ) && ( $key = array_search( $widget_instance_id, $sidebars_widgets[ 'wp_inactive_widgets' ] ) ) !== false ) {
unset( $sidebars_widgets[ 'wp_inactive_widgets' ][ $key ] );
}

if ( ! isset( $sidebars_widgets[ $sidebar_id ] ) ) {
$sidebars_widgets[ $sidebar_id ] = array( $widget_instance_id );

// Add widget instance to sidebar.
wp_set_sidebars_widgets( $sidebars_widgets );
} elseif ( ! in_array( $widget_instance_id, $sidebars_widgets[ $sidebar_id ], true ) ) {
$sidebars_widgets[ $sidebar_id ][] = $widget_instance_id;

// Add widget instance to sidebar.
wp_set_sidebars_widgets( $sidebars_widgets );
}
}
add_action( 'widgets_init', 'bb_rl_manually_add_members_sidebar_widgets', 99 );
23 changes: 0 additions & 23 deletions src/bp-core/bp-core-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
add_filter( 'bp_login_redirect', 'bb_login_redirect', PHP_INT_MAX, 3 );
add_filter( 'logout_redirect', 'bb_logout_redirect', PHP_INT_MAX, 3 );

add_action( 'bp_register_widgets', 'bb_register_readylaunch_widgets' );

// Avatars.
/**
* Disable gravatars fallback for member avatars.
Expand Down Expand Up @@ -2652,24 +2650,3 @@ function bb_redirection_allowed_third_party_domains( $hosts ) {

return $hosts;
}

function bb_register_readylaunch_widgets () {
if ( bb_get_enabled_readylaunch() && function_exists( 'bp_get_following_ids' ) ) {
$plugin_dir = BP_PLUGIN_DIR;
if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && ! empty( constant( 'BP_SOURCE_SUBDIRECTORY' ) ) ) {
$plugin_dir = $plugin_dir . 'src';
}
$widget_file = $plugin_dir . '/bp-core/classes/class-bb-core-follow-my-network-widget.php';
if ( file_exists( $widget_file ) ) {
require_once $widget_file;
if ( class_exists( 'BB_Core_Follow_My_Network_Widget' ) ) {
add_action(
'widgets_init',
function() {
register_widget( 'BB_Core_Follow_My_Network_Widget' );
}
);
}
}
}
}
83 changes: 42 additions & 41 deletions src/bp-core/classes/class-bb-core-follow-my-network-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function __construct() {
*/
function widget( $args, $instance ) {

// do not do anything if user isn't logged in
// Do not do anything if user isn't logged in
if ( ! is_user_logged_in() || ! bp_is_activity_follow_active() ) {
return;
}
Expand Down Expand Up @@ -73,7 +73,6 @@ function widget( $args, $instance ) {
// Get widget settings.
$settings = $this->parse_settings( $instance );


$follower = bp_get_follower_ids( array( 'user_id' => $id ) );
$following = bp_get_following_ids( array( 'user_id' => $id ) );

Expand All @@ -88,9 +87,10 @@ function widget( $args, $instance ) {
$ids = $following;
}

$follower_array = explode( ',', $follower );

$follower_array = ! empty( $follower ) ? explode( ',', $follower ) : array();
$follower_count = count( $follower_array );
$following_array = explode( ',', $following );
$following_array = ! empty( $following ) ? explode( ',', $following ) : array();
$following_count = count( $following_array );

$instance['title'] = (
Expand Down Expand Up @@ -121,7 +121,24 @@ function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
$title = $settings['link_title'] ? '<a href="' . $members_dir_url . '">' . $title . '</a>' : $title;

// show the users the logged-in user is follower.
do_action( 'bb_before_my_network_widget' );

echo $args['before_widget'];
echo $args['before_title']
. $title
. '<div class="bb-rl-see-all"><a href="' . $members_dir_url . '" class="count-more">' . esc_html__( 'See all', 'buddyboss' ) . '<i class="bb-icon-l bb-icon-angle-right"></i></a></div>'
. $args['after_title'];
?>
<div class="bb-rl-members-item-options">
<a href="javascript:void();" id="bb-rl-my-network-followers"
<?php echo ( empty( $settings['member_default'] ) || 'followers' === $settings['member_default'] ) ? 'class="selected"' : ''; ?>><?php esc_html_e( 'Followers', 'buddyboss' ); ?><span class="bb-rl-widget-tab-count"><?php echo $follower_count; ?></span></a>
<a href="javascript:void();" id="bb-rl-my-network-following" data-max="<?php echo esc_attr( $settings['max_users'] ); ?>"
<?php echo ( 'following' === $settings['member_default'] ) ? 'class="selected"' : ''; ?>><?php esc_html_e( 'Following', 'buddyboss' ); ?><span class="bb-rl-widget-tab-count"><?php echo $following_count; ?></span></a>
</div>
<div class="bb-rl-my-network-members-list bb-rl-avatar-block">
<?php

// show the members lists.
if ( bp_has_members(
array(
'include' => $ids,
Expand All @@ -130,47 +147,31 @@ function widget( $args, $instance ) {
'member_type__not_in' => false,
)
) ) {
do_action( 'bb_before_my_network_widget' );

echo $args['before_widget'];
echo $args['before_title']
. $title
. '<div class="bb-rl-see-all"><a href="' . $members_dir_url . '" class="count-more">' . esc_html__( "See all", "buddyboss" ) . '<i class="bb-icon-l bb-icon-angle-right"></i></a></div>'
. $args['after_title'];
?>

<div class="bb-rl-members-item-options">
<a href="javascript:void();" id="bb-rl-my-network-followers"
<?php echo ( empty( $settings['member_default'] ) || 'followers' === $settings['member_default'] ) ? 'class="selected"' : '' ?>><?php esc_html_e( 'Followers', 'buddyboss' ); ?><span class="bb-rl-widget-tab-count"><?php echo $follower_count; ?></span></a>
<a href="javascript:void();" id="bb-rl-my-network-following" data-max="<?php echo esc_attr( $settings['max_users'] ); ?>"
<?php echo ( 'following' === $settings['member_default'] ) ? 'class="selected"' : '' ?>><?php esc_html_e( 'Following', 'buddyboss' ); ?><span class="bb-rl-widget-tab-count"><?php echo $following_count; ?></span></a>
</div>

<div class="bb-rl-my-network-members-list bb-rl-avatar-block">
while ( bp_members() ) :
bp_the_member();
?>
<div class="item-avatar">
<a href="<?php bp_members_directory_permalink(); ?>" class="bp-tooltip" data-bp-tooltip-pos="up" data-bp-tooltip="<?php echo esc_attr( bp_core_get_user_displayname( bp_get_member_user_id() ) ); ?>"><?php bp_member_avatar(); ?></a>
<?php bb_user_presence_html( $members_template->member->id ); ?>
</div>
<?php
while ( bp_members() ) :
bp_the_member();
?>
<div class="item-avatar">
<a href="<?php bp_members_directory_permalink(); ?>" class="bp-tooltip" data-bp-tooltip-pos="up" data-bp-tooltip="<?php echo esc_attr( bp_core_get_user_displayname( bp_get_member_user_id() ) ); ?>"><?php bp_member_avatar(); ?></a>
<?php bb_user_presence_html( $members_template->member->id ); ?>
</div>
<?php endwhile; ?>
</div>

<?php wp_nonce_field( 'bb_core_widget_follow_my_network', '_wpnonce-follow-my-network', false ); ?>
endwhile;
}
?>
</div>
<?php

<input type="hidden" name="bb_rl_my_network_widget_max" id="bb_rl_my_network_widget_max" value="<?php echo esc_attr( $settings['max_users'] ); ?>"/>
wp_nonce_field( 'bb_core_widget_follow_my_network', '_wpnonce-follow-my-network', false );
?>

<?php echo $args['after_widget']; ?>
<input type="hidden" name="bb_rl_my_network_widget_max" id="bb_rl_my_network_widget_max" value="<?php echo esc_attr( $settings['max_users'] ); ?>"/>

<?php do_action( 'bb_after_my_network_widget' ); ?>
<?php echo $args['after_widget'];

<?php
do_action( 'bb_after_my_network_widget' );

// Restore the global.
$members_template = $old_members_template;
}
// Restore the global.
$members_template = $old_members_template;
}

/**
Expand Down Expand Up @@ -293,7 +294,7 @@ function bb_ajax_widget_follow_my_network() {
}

if ( empty( $instance['max_users'] ) ) {
$instance['max_users'] = 10;
$instance['max_users'] = 15;
}

if ( 'following' === $type ) {
Expand Down
Loading

0 comments on commit 7cf6a90

Please sign in to comment.