Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 25 replies - 1 through 25 (of 33 total)
  • Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    So, instead of modifying the bp_has_broups query in the template, I figured I needed to do an if / else to check if the user has not set the sort option yet. To do that, in bp-custom.php I hooked in to the bp_ajax_querystring filter:

    add_filter( 'bp_ajax_querystring', 'mediclique_bp_ajax_querystring', 32, 2 );
    function mediclique_bp_ajax_querystring( $query_string, $object ) {
    
    	if ( 'groups' == $object ) {
    	
    		$query_args = wp_parse_args( $query_string, array() );
    	
    		if ( empty( $query_args['type'] ) ) {
    		
    			$query_args['type'] = 'alphabetical';		
    			$query_string = http_build_query( $query_args );
    		}
    	}
    
    	return $query_string;
    }
    
    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    FYI – this approach still shows the ‘Home’ nav item to logged out users, but it can effectively be hidden via CSS.

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Solution:

    There is an action to hook to inside bp_core_activate_signup() that fires right after activating the account ( user clicked the link in the email ), so when the user hits /activate this will fire and reset the user_status to 3 ( 1 is spammer I guess ). Now to figure out the rest…

    Here is the code ( the second function disallows the user from logging in with custom message ):

    add_action( 'bp_core_activated_user', 'custom_bp_core_activated_user' );
    function custom_bp_core_activated_user( $user ) {
    
    	if ( empty( $user ) ) {
    		
    		return false;
    	}
    
    	if ( is_array($user) ) {
    		
    		$user_id = $user['user_id'];
    	}
    	else {
    		
    		$user_id = $user;
    	}
    
    	$member_type = bp_get_member_type($user_id);
    	
    	if ( $member_type == 'member_type_to_manually_activate' ) {
    		
    		global $wpdb;
    		
    		$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 3 WHERE ID = %d", $user_id ) );
    	}
    }
    
    add_filter( 'authenticate', 'custom_authenticate', 30 );
    function custom_authenticate( $user ) {
    
    	if ( is_wp_error( $user ) || empty( $user ) ) {
    
    		return $user;
    	}
    
    	if ( 3 == $user->user_status ) {
    
    		$member_type_name = bp_get_member_type($user->ID);
    		$member_type = bp_get_member_type_object($member_type_name);
    		
    		return new WP_Error( 'invalid_username', __( '<strong>ERROR</strong>: All ' . $member_type->labels['name'] . ' accounts require manual confirmation from an admin. You might be contacted soon to verify your identity. You will recieve an email once your account is approved.', 'buddypress' ) );
    	}
    
    	return $user;
    }
    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Scratch that.
    I need the forum id based on group id.

    Aaaaand the solution: bbp_get_group_forum_ids()

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Found the solution!
    So, in /buddypress/bp-groups/bp-groups-loader.php if found that it’s checking for a “front” template along with Activity Streams being disabled.
    So, I just created an empty front.php file in my overloads /buddypress/groups/single/ folder and, boom!

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Couple things to consider / need direction on:
    – the URL is still /home. Looking to have /members
    – the “Manage” section for admins—what is the proper way to handle visibility in the nav?

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    To be clear, and provide further details to demonstrate that this hasn’t been answered previously, I’m looking to have 2 nav items in every group: Forum, Members.
    In that order, with the default page being Forum.
    I have achieved the default page being Forum with this:

    add_filter( 'bp_groups_default_extension', 'custom_bp_groups_default_extension' );
    function custom_bp_groups_default_extension() { return 'forum'; }

    But, again, when Activity Stream is disabled, Members becomes Home.
    So right now my nav is: Home, Forum
    I need a way to tell Home to revert to Members and go below Forum in the nav.

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Ok, the one i found that has the ajax check does work.
    I have narrowed all issues down to a redirect loop on ajax actions inside a custom loop on a page template.
    Starting a new topic… thanks all.

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Thought I had found the silver bullet here:

    https://buddypress.org/support/topic/need-to-disable-the-user-access-to-wordpress-admin-panel/#post-183537

    which includes a check for ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )…still has a redirect loop when performing the ajax actions.

    The search continues…

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Sorry, correction:
    This doesn’t cause a redirect loop…but it doesn’t prevent access of non-admins to admin section.
    And it DOES now cause a redirect loop on the actions that were, before, loading the whole home page into the middle of the template.

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Switching the action to wp causes a redirect loop.
    But we’re thinking it’s just a matter of finding the right action to hook into?

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Ok, I’ve found that it is tied to my redirect function mentioned in https://buddypress.org/support/topic/only-administrator-can-change-avatar/. I’ll repeat it here for posterity:

    // keep the 'normies' out of the admin
    add_action( 'admin_init', 'custom_admin_init', 1 );
    function custom_admin_init() {
    
    	if ( is_user_logged_in() && ! current_user_can( 'administrator' ) ) {
    
    		wp_redirect( home_url() ); die();
    	}
    }

    Seems like some (ajax?) content population requires accessing the admin in someway.
    So, how to keep everyone except admins out of the admin area but still allow all this content stuff to be uninterrupted?

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    I wasn’t gonna say anything… 🙂

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Oooooh, this must be my issue.
    Here is my current redirect:

    // keep the 'normies' out of the admin
    add_action( 'admin_init', 'custom_admin_init', 1 );
    function custom_admin_init() {
    
    	if ( is_user_logged_in() && ! current_user_can( 'administrator' ) ) {
    
    		wp_redirect( home_url() ); die();
    	}
    }
    

    Were you able to figure out how to keep the redirect but allow the uploads?

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Works!
    Thank you.

    WP: 4.4.1
    BP: 2.4.3

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    ^ Bump. Why didn’t you *ADD* a wysiwyg field type? Really need a plain textarea.

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Decided to give up modifying my existing plugin and just modify the Skeleton plugin that r-a-y recommended—much better idea. I now have the notification count displaying! No notification text but I’m pretty sure I’ll get there. Thanks all!

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Thanks everyone, I’m on my way. But, now I’m getting a 500 error on plugin activation. I replaced out the deprecated component creation function above with the following:

    define( 'BP_PCN_IS_INSTALLED', 1 );
    define( 'BP_PCN_PLUGIN_DIR', dirname( __FILE__ ) );

    /* Only load the component if BuddyPress is loaded and initialized. */
    function bp_pcn_init() {
    // Because the loader file uses BP_Component, it requires BP 1.5 or greater.
    if ( version_compare( BP_VERSION, '1.5', 'active_components[$this->id] = '1';

    }

    function setup_globals() {
    global $bp;

    // Defining the slug in this way makes it possible for site admins to override it
    if ( !defined( 'BP_PCN_SLUG' ) )
    define( 'BP_PCN_SLUG', $this->id );

    // Set up the $globals array to be passed along to parent::setup_globals()
    $globals = array(
    'slug' => BP_PCN_SLUG,
    'root_slug' => isset( $bp->pages->{$this->id}->slug ) ? $bp->pages->{$this->id}->slug : BP_PCN_SLUG,
    'has_directory' => false, // Set to false if not required
    'notification_callback' => 'bp_pcn_format_notifications'
    );

    // Let BP_Component::setup_globals() do its work.
    parent::setup_globals( $globals );

    }

    }

    /* load component into $bp global */
    function bp_pcn_load_core_component() {
    global $bp;

    $bp->pcn = new BP_PCN_Component;
    }
    add_action( 'bp_loaded', 'bp_pcn_load_core_component' );

    Anyone know what I’m missing?

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Are there any existing situations in the code I can look at?

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    It seems that screen notifications in Buddypress 1.6.1 are busted. I’ve been struggling with this for days,weeks,months—also found this: https://buddypress.org/support/topic/notifications-do-not-seem-to-work/ Can anyone confirm or deny?

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Okaaay, the plugin IS working. Does anyone know why an entry in wp_bp_notifications would not be showing up in notifications?

    entry in wp_bp_notifications:

    id user_id item_id secondary_item_id component_name component_action date_notified is_new

    196 4 209 0 pc_notifier new_post_comment_209 2012-12-07 17:08:16 1

    User id#3 is creating the comment and user id#4 is not receiving the notification in the top bar. Anyone know why?

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Ok, I think I’ve narrowed it down to this function in the plugin. I know that the function that it is hooking into works. Anyone know why this would fail?

    function pc_notifier_notify($activity_id) {
    global $bp;

    $activity = new BP_Activity_Activity($activity_id);
    $comment = get_comment($activity->secondary_item_id);
    $users = pc_notifier_find_involved_persons($comment->comment_post_ID);
    $link = get_permalink($comment->comment_post_ID);

    if($activity->hide_sitewide) return;

    if(!in_array($activity->user_id, $users)&&($bp->loggedin_user->id!=$activity->user_id)) array_push ($users, $activity->user_id);

    foreach((array)$users as $user_id){
    bp_core_add_notification( $activity_id, $user_id, $bp->pc_notifier->id, 'new_post_comment_'.$activity_id );
    }

    }
    add_action("bp_blogs_comment_recorded","pc_notifier_notify",10,1); // hook to bp_blogs_comment_recorded for adding notification

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Actually, this function is working—it is creating activity items based on blog posts and comments. I found out that it’s my custom plugin that is supposed to hook into this custom post or comment action to create a notification. Here is the plugin. I know no one will even try to tackle this but I have to post this because it’s my only option and I one for due diligence…

    /**
    * Plugin Name:BuddyPress Post Comment Notifier
    * Description: Mod of Brajesh Singh's BuddyPress Activity Comment Notifier to work for Blog Post Comments
    *
    */

    // we are not much concerned with the slug, it is not visible
    define("BP_COMMENT_NOTIFIER_SLUG","pc_notification");

    //register a dummy notifier component, I don't want to do it, but bp has no other mechanism for passing the notification data to function, so we need the format_notification_function
    function pc_notifier_setup_globals() {
    global $bp, $current_blog;
    $bp->pc_notifier=new stdClass();
    $bp->pc_notifier->id = 'pc_notifier';//I asume others are not going to use this is
    $bp->pc_notifier->slug = BP_COMMENT_NOTIFIER_SLUG;
    $bp->pc_notifier->notification_callback = 'pc_notifier_format_notifications';//show the notification
    /* Register this in the active components array */
    $bp->active_components[$bp->pc_notifier->slug] = $bp->pc_notifier->id;

    do_action( 'pc_notifier_setup_globals' );
    }
    add_action( 'bp_setup_globals', 'pc_notifier_setup_globals' );

    /**
    * storing notification for users
    * notify all the users who have commented, or who was the original poster of the update, when someone comments
    * hook to bp_blogs_comment_recorded action
    */
    function pc_notifier_notify($activity_id) {
    global $bp;

    $activity = new BP_Activity_Activity($activity_id);
    $comment = get_comment($activity->secondary_item_id);
    $users = pc_notifier_find_involved_persons($comment->comment_post_ID);
    $link = get_permalink($comment->comment_post_ID);

    if($activity->hide_sitewide) return;

    if(!in_array($activity->user_id, $users)&&($bp->loggedin_user->id!=$activity->user_id)) array_push ($users, $activity->user_id);

    foreach((array)$users as $user_id){
    bp_core_add_notification( $activity_id, $user_id, $bp->pc_notifier->id, 'new_post_comment_'.$activity_id );
    }

    }
    add_action("bp_blogs_comment_recorded","pc_notifier_notify",10,1); // hook to bp_blogs_comment_recorded for adding notification

    /** our notification format function which shows notification to user
    *
    * @global $bp
    * @param $action
    * @param $activity_id
    * @param $secondary_item_id
    * @param $total_items
    * @return
    * @since 1.0.2
    * @desc format and show the notification to the user
    */
    function pc_notifier_format_notifications( $action, $activity_id, $secondary_item_id, $total_items, $format='string' ) {

    global $bp;
    $glue = '';
    $user_names = array();
    $activity = new BP_Activity_Activity( $activity_id );
    $comment = get_comment($activity->secondary_item_id);
    $link = get_permalink($comment->comment_post_ID);
    $comment_post = get_post($comment->comment_post_ID);

    if ( $activity->user_id == $bp->loggedin_user->id ) $text = __("your post");
    else $text = sprintf(__("%s"), $comment_post->post_title);

    $pc_action = 'new_post_comment_'.$activity_id;

    if ( $action == $pc_action ) {

    $users = pc_notifier_find_involved_persons($comment->comment_post_ID);

    $total_user = $count = count($users);//how many unique users have commented

    if ( $count > 2 ) {
    $users = array_slice($users, $count-2);//just show name of two poster, rest should be as and 'n' other also commeted
    $count = $count-2;
    $glue=", ";
    }
    else if ( $total_user == 2 ) $glue = " and ";//if there are 2 unique users , say x and y commented

    foreach ( (array)$users as $user_id )
    $user_names[] = bp_core_get_user_displayname($user_id);

    if ( !empty($user_names) )
    $commenting_users = join($glue,$user_names);

    if ( $total_user > 2 )
    $text = $commenting_users." and ".$count." others commented on ".$comment_post->post_title;
    else
    $text = $commenting_users." commented on ".$comment_post->post_title;

    if ( $format == 'string' )
    return apply_filters('bp_activity_multiple_new_comment_notification','comment_ID.'">'.$text.'');
    else {
    $link .= '#comment-'.$comment->comment_ID;
    return array('link'=>$link,'text'=>$text);
    }

    }

    return false;

    }

    /*
    * Remove activity for the comments on new_blog_post & new_blog_comment activity item.
    * Since these items do not have a single activity view and are linked to the single post screen, we will do the needed on single post view
    */

    function pc_notifier_remove_notification_for_blog_posts(){
    if( !( is_user_logged_in() && is_singular() ) )
    return;

    global $bp,$wpdb;
    $blog_id = (int)$wpdb->blogid;
    $post = wp_get_single_post();
    $activity_id = bp_activity_get_activity_id(
    array(
    'user_id' => $post->post_author,
    'component' => $bp->blogs->id,
    'type' => "new_blog_post",
    'item_id' => $blog_id,
    'secondary_item_id' => $post->ID
    )
    );
    //delete the notification for activity comment on new_blog_post
    if( !empty($activity_id) )
    bp_core_delete_notifications_by_item_id( $bp->loggedin_user->id, $activity_id, $bp->pc_notifier->id, 'new_post_comment_'.$activity_id );

    //for replies on blog comments in activity stream
    $comments = pc_notifier_get_all_blog_post_comment_ids($post->ID);//get all the comment ids as array

    //added in v 1.0.3 for better database performance, no more looping to get individual activity ids
    $activities = pc_notifier_get_activity_ids(
    array(
    "type"=>"new_blog_comment",
    "component" => $bp->blogs->id,
    "item_id"=>$blog_id,
    "secondary_ids"=>$comments
    )
    );

    foreach( (array)$activities as $pc_id )
    bp_core_delete_notifications_by_item_id( $bp->loggedin_user->id, $pc_id, $bp->pc_notifier->id, 'new_post_comment_'.$pc_id );

    }
    add_action("wp_head","pc_notifier_remove_notification_for_blog_posts");

    /**
    * @since v 1.0.2
    * @desc delete notification when an activity is deleted, thanks to @kat_uk for pointing the issue
    * @param pc_ids:we get an arry of activity ids
    */
    function bp_pc_clear_notification_on_activity_delete($pc_ids){
    global $bp;

    foreach ( (array)$pc_ids as $activity_id )
    bp_core_delete_all_notifications_by_type( $activity_id, $bp->pc_notifier->id, 'new_post_comment_'.$activity_id, $secondary_item_id = false );
    }
    add_action("bp_activity_deleted_activities","bp_pc_clear_notification_on_activity_delete");

    /************************************ HELPER FUNCTIONS ********************************************************/

    // find all users who commented on the post
    function pc_notifier_find_involved_persons($comment_post_ID){
    global $bp,$wpdb;

    return $wpdb->get_col($wpdb->prepare("SELECT DISTINCT(user_id) from {$wpdb->comments} where comment_post_ID=%d and user_id!=%d",$comment_post_ID,$bp->loggedin_user->id));
    }

    // return an array of comment ids for the post
    function pc_notifier_get_all_blog_post_comment_ids($post_id) {
    global $wpdb;

    return $wpdb->get_col($wpdb->prepare("SELECT comment_ID as id FROM {$wpdb->comments} WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post_id));
    }

    // get activity ids when type, component, secondary_ids, item_id is specified
    function pc_notifier_get_activity_ids($params){
    global $bp,$wpdb;
    extract($params);
    $list="(".join(",", $secondary_ids).")";//create a set to use in the query;

    return $wpdb->get_col($wpdb->prepare("SELECT id from {$bp->activity->table_name} where type=%s and component=%s and item_id=%d and secondary_item_id in {$list}",$type,$component,$item_id));
    }

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Anyone in the know with the new BP guts wanna take a crack at this? It may be a useful plugin…

    Profile photo of Andrew Tibbetts
    Andrew Tibbetts
    Participant

    @andrewgtibbetts

    Yikes! Sorry, Bob, I just realized I was not subscribed to this thread. Anyway, the functions that I had gotten to work for creating activity notifications from actual blog comments (not activity comments) was working but is now broken. :\ Here is the new thread I have created to tackle this new situation. Feel free to add a “bump”. 😉 https://buddypress.org/support/topic/help-me-fix-a-function-that-adds-blog-comments-to-activity/

Viewing 25 replies - 1 through 25 (of 33 total)
Skip to toolbar