Forum Replies Created
-
Thank you so much! In case you couldn’t tell I’m not that familiar with accessing the database.
This completely worked, just in case anyone needs this for the future here is what I used:
<?php //get ids of members I want to include by grabbing members from db $memberPressMembers = $wpdb->get_col("SELECT DISTINCT user_id FROM wp_mepr_transactions WHERE status IN('confirmed','complete') AND (expires_at >= NOW() OR expires_at = '0000-00-00 00:00:00')"); $include_string = '&include=' . implode(", ", $memberPressMembers); //print out array of IDs to console to find how many people we are getting //echo '<script>console.log(' . json_encode($memberPressMembers, JSON_HEX_TAG) . ');</script>'; ?> <?php if ( bp_has_members( bp_ajax_querystring( 'members' ). $include_string ) ) : ?>
I didn’t actually need product id, because I want anyone who has an active membership to appear here, but be careful about a lot of “OR” statements as this could lead to grabbing people who also have a pending transaction as well (displaying people with pending but not complete transactions). If you want specific memberships I would probably add
AND product_id IN (MEMBERSHIPIDs)
Thanks again for all of your help @shanebp!
Hello,
So I found that if I change my $memberPressMembers to:
$memberPressMembers = $wpdb->get_results("SELECT DISTINCT user_id FROM wp_mepr_transactions WHERE status IN('confirmed','complete') AND (expires_at >= NOW() OR expires_at = '0000-00-00 00:00:00') AND product_id = MEMBERSHIPID", ARRAY_N);
Then I actually can see my list of IDs when I do this:
echo '<script>console.log(' . json_encode($memberPressMembers, JSON_HEX_TAG) . ');</script>';
The only issue is, if I do this but add the $include_string to the bp_has_members line it displays no members.
I believe this is because ARRAY_N is placing all of my items into arrays. Looking at the console log I see that the arrays split at 100 records (0-99, 100-199, etc.).I’ve also tried then taking my memberPressMembers variable and adding each into an array ($include_these_users) like so:
foreach($memberPressMember as $member){ array_push($include_these_users, $member); }
with no luck.
Could you help me in forming my variable so it will work in the include_string?Thank you! I should probably note, I’m attempting all of this code within members-loop.php. I’m assuming this is still the correct spot to do this as the bp_has_members(bp_ajax_querystring(‘members’)) is part of the loop.
Hey @shanebp thank you so much for your fast response!
Unfortunately, MemberPress support didn’t know of a function that gets user IDs with specific memberships so they handed me this SQL query:
SELECT DISTINCT user_id FROM wp_mepr_transactions WHERE status IN('confirmed','complete') AND (expires_at >= NOW() OR expires_at = '0000-00-00 00:00:00') AND product_id = 123;
Where I would need to change my Product ID to match the Membership ID. I’m assuming I would just add this SQL query to your code bit:
<?php //get ids of members I want to include by grabbing members from db $memberPressMembers = $wpdb->get_results("SELECT DISTINCT user_id FROM wp_mepr_transactions WHERE status IN('confirmed','complete') AND (expires_at >= NOW() OR expires_at = '0000-00-00 00:00:00') AND product_id = MEMBERSHIPID"); $include_string = '&include=' . implode(", ", $memberPressMembers); ?> <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) . $include_string ) ) : ?>
This would only call my database 1 time to grab all members who have those specific IDs.
Is that correct? Am I missing anything? When I attempted this I kept getting a 500 error on my admin_ajax.
@kobrakai75
It seems to have worked, but is there a way to have a more clear error message? I noticed that it worked for notifying the user that there was an error, but it doesn’t specify anything and it leaves the field that had the problem blank. If they just wrote their whole life story in a Textarea field this could be very heart shattering that all of their work is now gone instead of just specifying that it was a specific field and then saying “this field has too many characters”.@kobrakai75 thank you so much for this!
Just asking about this one piece.
$allowed_len = 0 isn’t a problem because the if loop will only run if $allowed_len is anything other than 0 right? if($allowed_len) would be if(0) which translates to if(false) i.e. (don’t run), right?
The link in your previously linked solution is broken, but archive.org shows this from March 2, 2017 (https://web.archive.org/web/20170302040249/http://snippetbarn.bp-fr.net/xprofile-field-length-control)
Google Translated to English:
Imagine that you have a profile field containing any biography or presentation and want to display it, at least as an excerpt, on the membership directory.
Let’s imagine you have an xprofile containing a biography that you want to display, even partially, on the members directory.function bpfr_custom_textfield_length() { //Check if user is logged in & if xprofile component is activated if ( is_user_logged_in() && bp_is_active( 'xprofile' ) ) : $my_custom_textfield = bp_get_member_profile_data( 'field=Brief Biography&user_id='.bp_get_member_user_id() ); /* * The length = number of characters, not words. * Set the number of caracters to show. * The 3 dots are the appended text ending the excerpt. * Don't remove the quotes if you change this * BuddyPress 2.1 will add new class and id for custom fields. * The span can be omited to style this part. See ticket #5741 */ if ( strlen($my_custom_textfield) > 20) : //adjust to your need $my_custom_textfield = substr($my_custom_textfield, 20).'...'; //adjust to your need endif; // uncomment the following line to get a span around the displayed field content // echo '<span class="short-custom">'. $my_custom_textfield; .'</span>'; // comment the following line if you use the span echo $my_custom_textfield; endif; // is_user_logged_in } add_action( 'bp_directory_members_item', 'bpfr_custom_textfield_length' );
I have not tested this code, just reporting what was originally said to resolve this issue. I am looking to find out if this works as well.
Hello guys,
Just in case anyone else was wondering. If you want to grab data from topics or replies you need to grab the hook that fires after it is saved. These 2 did the trick:
//for when new topic was created add_action('bbp_new_topic_post_extras', 'group_has_new_topic', 10, 2); //for when new reply was created to a topic add_action('bbp_new_reply_post_extras', 'group_topic_has_new_reply', 10, 2);
I know that this will grab all bbPress topics and replies, but it fits my purposes.
If anyone knows how to grab only BuddyPress Group Forums’ Topics and Replies that would be awesome, but for now this will work for me and I hope it works for others!These actions rely on $topic_id and $reply_id only and respectfully, but you can grab any other data such as Topic Title, Forum Name, Topic or Reply Author, etc. through the Topic or Reply ID alone like so:
$topic_id = bbp_get_reply_topic_id($reply_id); $topic_title = bbp_get_topic_title($topic_id); $forum_id = bbp_get_topic_forum_id($topic_id); $forum_title = bbp_get_forum_title($forum_id); $user = bbp_get_reply_author_id($reply_id); $user_info = get_userdata($user); $username = $user_info->user_login;
Quick followup note, I changed that code in buddypress-messages.js, but then I needed to use a javascript minifier such as https://javascript-minifier.com/ and then save that as buddypress-messages.min.js.
When I click submit the URL looks like this: https://buddypress.org/?post_type=topic&p=303301 I’m assuming p = is the post ID that I’m attempting to create? When I tried again I got p=303302.
Wow. of course this one would work.
I found that if I made this file directory in my theme (as per Theme Compatibility Codex) I could resolve the issue with the Compose field:
/buddypress/common/js-templates/messages/index.php
So for anyone else looking for messaging template changes. It’s located in:
plugins/buddypress/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php
Anyone looking for the search field for members list, it’s located in:
/plugins/buddypress/bp-templates/bp-nouveau/buddypress/common/search/search-form.php
Quite a few of my users also wish to be able to crop their cover photos. Is there custom code I can add to allow users to do this? I haven’t found it on any of the forum posts so far and most are over a year old. This seems to be the most recent.
For those searching, here’s the codex of cover images (group and profile) and tells you how to customize the image size that you will accept for this area, but still not telling you how to allow cropping.
I’m on Version 4.1.0