Search Results for 'code'
-
AuthorSearch Results
-
May 10, 2021 at 5:07 pm #220516
In reply to: Adding post meta to user replies
Robin W
Moderatorso maybe have a function that says
add_action( 'bbp_theme_after_reply_form_content', 'rew_add_checkbox' ); function rew_add_checkbox () { echo '<p class="whatever"> <input name="my_parameter" id="my_parameter" type="checkbox" value="whatever_value_you_want" checked="checked"> <label for="whatever">Tick this box to do whatever</label> </p>' ; }This will put the checkbox after the content
May 10, 2021 at 5:04 pm #220515In reply to: Adding post meta to user replies
Robin W
Moderatorwithout knowing what you are trying to achieve hard to say.
Typically you’d use JS for stuff you want to change on the fly without reloading the screen.
For an input form you would more normally use html and php
But I do fully appreciate that we all play to our strengths and I would tend to use PHP where JS would be better as I know it well, and I suspect you are the reverse 🙂
So you would add a checkbox, you can do this by amending the reply template, or better using one of the do_action hooks in the template. You can also do this using JS
In essence you are adding this to the form, you can use whatever names you want
<p class="whatever"> <input name="my_parameter" id="my_parameter" type="checkbox" value="whatever_value_you_want" checked="checked"> <label for="whatever">Tick this box to do whatever</label> </p>This will create a box which when submitted will set
$_POST[‘my_parameter’] to “whatever_value_you_want” if ticked or be blank if notyou can use the code above to set your meta data
May 10, 2021 at 4:45 pm #220514In reply to: Adding post meta to user replies
vincenzon617
ParticipantI am having some difficulty figuring out what this does, apologies, my PHP knowledge is very minimal. What exactly is the
if (! empty($_POST[‘my_parameter’] ) ) { $myvalue = $_POST[‘my_parameter’] ; } else $myvalue='empty';part doing? Specifically, what would ‘my_parameter’ be? Would this be the name or value of what I would like the meta to be?
I have looked up what $_POST does, and the variables that I am using are declared using JavaScript. Now I am wondering if I will have to change my approach to checking the user input for the checkbox (something which isn’t related to bbpress).Many thanks
May 10, 2021 at 1:48 pm #220505In reply to: bbpress redirection
Robin W
Moderatorhow are they loggong on wp-logon, or widget or shortcode?
May 9, 2021 at 6:12 pm #220491In reply to: Adding post meta to user replies
Robin W
Moderatoryou’ll want to use
update_post_meta– this creates the entry if not there and amends it if it is.
in the new reply handler, there is a hook which contains the reply_id which fires after the reply is created.so something like
add_action( 'bbp_new_reply_post_extras', 'rew_reply_checkbox' ); add_action( 'bbp_edit_reply_post_extras', 'rew_reply_checkbox' ); function rew_reply_checkbox ($reply_id) { //and probably set the value to a $_POST parameter you set in the form if (! empty($_POST[‘my_parameter’] ) ) { $myvalue = $_POST[‘my_parameter’] ; } else $myvalue='empty' ; update_post_meta ($reply_id , 'my_parameter', $myvalue) ; }May 9, 2021 at 5:21 pm #220490Topic: Adding post meta to user replies
in forum Troubleshootingvincenzon617
ParticipantI would like to add metadata to replies depending on a checkbox that the user selects. The function I think I will need to use is
add_post_metabut one of the parameters ispost_id. What would I put in this as the reply would not be created yet and so I believe it won’t have an associated ID yet?I suppose it is the same concept as replying to a topic as the text the user writes will go into the post’s (with a postID) ‘main’ data. So basically I would like to do the same thing but adding to the metadata. Hopefully, that makes sense and someone knows the solution.
Thanks!
May 7, 2021 at 1:12 pm #220470In reply to: Using JavaScript to append text to the reply form.
vincenzon617
ParticipantI have managed to find the solution! For anyone else who may have this problem, change this part of the code above:
.innerHTML = "clicked";
to
.value += "clicked";May 6, 2021 at 2:59 pm #220461Topic: Using JavaScript to append text to the reply form.
in forum Troubleshootingvincenzon617
ParticipantIs there a way to append text to the reply form using JavaScript?
I have this functionwindow.onload=function() { document.getElementById("toggle-check").addEventListener("click", funct1); function funct1() { if(this.checked) { document.getElementById('bbp_reply_content').innerHTML = "clicked"; } else { document.getElementById('bbp_reply_content').innerHTML = "notclicked"; }; }; };which is used when the user clicks a checkbox that I have made. I would like the text to be appended to the reply form at the end of their message, depending on whether or not they have clicked the checkbox. Currently, the
.innerHTMLis not working when there is text already in the reply form but it works when the reply form is empty.Has anyone got any ideas on how to do this? Maybe there is a text variable that stores the user’s message that I can append to – if so what is the name?
Many thanks
May 6, 2021 at 8:27 am #220451In reply to: Reverse order replies and pagination
webmasterfreya
ParticipantHi Back to Front,
I also have buddypress installed. As admin you have for each member a page wich among other things shows topics started and replies made by the member. The replies did not show up (and there were definitly replies).
As buddypress makes use of bbpress for fora i expected your code to work but it did not (is the culprit then buddypress or bbpress or your code? I haven’t the faintest idea).
Maybe : if( $bbPress_post_type ==’topic’ ){
/** TOPIC **/
$query[‘order’]=’DESC’;
return $query;should have an } else {return $query}
May 6, 2021 at 2:00 am #220437sino27
ParticipantHi there. Sorry for reviving this thread. But I had to as this is some serious privacy issue.
A code from “bjornwebdesign” is definitely working but not completely. I mean on this code posted in his “Ok, last time, I promise :p…”
/* * Do stuff when the user's xprofile is updated */ function xprofile_updated ( $user_id, $posted_field_ids, $errors, $old_values, $new_values) { /* * Change the user_nicename which is used as profile url, we do NOT want the username in url! Bad bad BP... * Please note: the user profile url can now be changed by the user, direct linking from other places on the web may result in 404. * Altough this should run AFTER updating profile fields (saving to DB), the nicename is only updated after a second save. So we need to check from $new_values */ $new_display_name = ''; foreach ( $new_values as $key => $value ) { if ( is_array($value) && $key == 1 ) { // field display_name = 1, make sure this is correct foreach ( $value as $k => $v ) { if ( $k == 'value' ) { $new_display_name = $v; } } } } //error_log('******** xprofile_updated: '.$user_id.' | NEW DISPLAY_NAME: '.$new_display_name.' *********'); $search = array( ' ', '.' ); $replace = array( '_', '' ); $user = get_user_by( 'ID', $user_id ); if ( $user ) { if ( $user->data->user_status == 0 && $new_display_name ) { $new_user_nicename = strtolower(str_replace( $search, $replace, $new_display_name) ); if ( strlen ( $new_user_nicename ) > 50 ) { $new_user_nicename = substr ( $new_user_nicename, 0, 50 ); } if ( $user->data->user_nicename != $new_user_nicename ) { // && $user->ID == 80 <-Add this if you only want to run it for 1 user, so you can test it. $args = array( 'ID' => $user->ID, 'user_nicename' => $new_user_nicename ); wp_update_user( $args ); //error_log('******** updated user_nicename: '.$user->ID.' | NEW USER_NICENAME: '.$new_user_nicename.' *********'); wp_redirect( get_site_url().'/leden/'.$new_user_nicename.'/profile/edit/group/1/' ); // we cant use bp_core_get_user_domain() here, because it still uses the old user_nicename exit; } } } } add_action( 'xprofile_updated_profile', 'xprofile_updated', 100, 5 );– but there is one critical flaw. After code is applied, user can not update their profile anymore. Like you can go to (example) update name or nickname. You press save and nothing changes. Profile is not updated.
If I apply “bjornwebdesign” previous code (meaning code he posted just before his latest code) –
/* * Change the user_nicename which is used as profile url, we do NOT want the username in url! Bad bad BP... * This runs allways (with init hook), we should only do this once and then on user register & profile update.. * Please note: the user profile url can now be changed by the user, direct linking from other places on the web may result in 404. * And offcourse allways use something like: 'bp_core_get_user_domain( $user_id )' when you want to get the user's profile url. */ $search = array( ' ', '.' ); $replace = array( '_', '' ); $all_users = get_users(); foreach ( $all_users as $user ) { $display_name = $user->data->display_name; if ( $user->data->user_status == 0 && $display_name ) { $new_user_nicename = strtolower(str_replace( $search, $replace, $display_name) ); if ( strlen ( $new_user_nicename ) > 50 ) { $new_user_nicename = substr ( $new_user_nicename, 0, 50 ); } if ( $user->data->user_nicename != $new_user_nicename ) { // && $user->ID == 80 <-Add this if you only want to run it for 1 user, so you can test it. $args = array( 'ID' => $user->ID, 'user_nicename' => $new_user_nicename ); wp_update_user( $args ); } } }then updating of profile is working. User can update profile but after pressing “Save” there is 404 error. Even 404 is acceptable as at least user can update their profile. However performance is severely degraded on a website with many members.
So basically only his latest code is working in a way that their profile URL is hidden, performance is not degraded but user profiles can not be saved or updated. Can anyone help and update his code so that user are able to update their profiles?
May 5, 2021 at 7:02 pm #220433In reply to: bbPress 2.0 – Shortcodes
deborah86
ParticipantWill the shortcodes be converted into blocks to work fully with the block editor? Is bbPress preparing for full-site editing that is coming this year?
May 5, 2021 at 12:48 pm #220428Topic: Twenty Twenty Theme Causing Jumbled Text on Forum Page
in forum Themesdeborah86
ParticipantI am currently using the Twenty Twenty theme. The theme is causing jumbled text on the forum page.
I have tried both bbPress and BuddyBoss. I have the same issue. I contacted BuddyBoss, they stated there is an issue with the Twenty Twenty theme. I contacted the admins at the Twenty Twenty theme. They told me to go to bbPress for support. I cannot locate the issue in the code.
See Twenty Twenty theme ticket
I also completed the additional troubleshooting steps:
- Deactive plugins – this did not solve the issue
- Themes – switching the themes fixes the issue. I contacted the Twenty Twenty theme authors. They told me to contact you.
- Selecting the default permalinks – I am already using the default permalinks
- Repair Forums – this did not solve the issue
- Using WP Debug – no debug issues appeared
- Diagnose Javascript errors – there are no javascript errors appearing
I have basically tried everything besides resetting my WordPress website. Nothing seems to work.
May 3, 2021 at 7:46 am #220395In reply to: Get reply IDs from topic
Robin W
Moderatorah yes, it should have been
bbp_get_reply_type()to make it a function, but ‘reply’ is equally as good
May 3, 2021 at 7:39 am #220394In reply to: Get reply IDs from topic
vincenzon617
ParticipantThanks, Robin works great, although the
bbp_get_reply_typeandbbp_get_topic_typecaused an error so I replaced it withbbp_get_all_child_ids($topicID, 'reply');and it seems to have done the trick!May 2, 2021 at 5:52 pm #220387In reply to: Get reply IDs from topic
Robin W
Moderatoror
$ids = bbp_get_all_child_ids($topicID , bbp_get_reply_type) ;May 2, 2021 at 5:51 pm #220386In reply to: Get reply IDs from topic
Robin W
Moderatora quick look at that function would seem to be
$ids = bbp_get_all_child_ids($topicID , bbp_get_topic_type) ;May 2, 2021 at 1:48 pm #220381Robin W
Moderatoruntested, but try
add_filter( 'bbp_get_view_query_args', 'rew_limit') ; function rew_limit ($args) { $args['posts_per_page'] = -1 ; $args['posts_per_page'= 10 ; return $args ; }not sure which 10 it will show!!
May 1, 2021 at 3:48 pm #220376vincenzon617
ParticipantIs there a way to limit the number of topics shown when using the shortcode
[bbp-single-view id=’popular’]?I would only like to show the top 10 most popular topics.
Thanks
April 30, 2021 at 2:08 pm #220360In reply to: Reverse order replies and pagination
webmasterfreya
ParticipantHi,
Your piece of code has an unwanted side effect. When looking at a subscriber as admin the created replies of this subscriber do not show anymore.
I reverted back to the original code (on top of this topic) and presto the replies of the subscriber show up again.April 28, 2021 at 9:44 am #220346Topic: Spam and Pending Post Delete
in forum Requests & Feedbackmaxx203
ParticipantHello
to clean up my pending and spam threads and answers, iam using two show SQL queries. Is there maybe any plugin or cron which can execute them?
DELETE FROM wp_posts WHERE post_status = "pending"; DELETE FROM wp_posts WHERE post_status = "spam";Regards
MaxxApril 28, 2021 at 4:47 am #220343In reply to: Reverse order replies and pagination
Robin W
Moderator@traverser11 – great that you are posting the answers here – so many don’t 🙂 🙂 🙂
can you summarise where you are at, so eg
use this plugin (are you still using the sort topic replies plugin?)
delete this code from it
add this code to this placeetc.
so it is all in one thread, I’ll then try to give to some switch on and off code
April 27, 2021 at 10:33 pm #220341In reply to: Reverse order replies and pagination
Back to Front
ParticipantOh here is an answer!
This snippet works – i’m just a bit confused how to turn it on when replies are descending and off when they are ascending…
add_filter('bbp_get_reply_position', 'lugpa_get_reply_position', 10, 3); function lugpa_get_reply_position($reply_position, $reply_id, $topic_id){ if(empty($topic_id)) $topic_id = bbp_get_reply_topic_id ($reply_id); $numReplies = bbp_get_topic_reply_count($topic_id); return ($numReplies+1) - $reply_position; // plus one because of thread description }April 27, 2021 at 3:55 am #220323In reply to: Reverse order replies and pagination
Robin W
Moderatorhttps://codex.bbpress.org/bbp_show_lead_topic/ should fix that
April 27, 2021 at 12:51 am #220320In reply to: Reverse order replies and pagination
Back to Front
ParticipantI gave it a go, and it kinda worked, lol…
But this reverses all the replies INCLUDING the original topic.
So the original topic goes to the bottom…
What I would ideally want is the Topic, THEN the replies in reverse order…// Reverse reply order on News topic add_filter('bbp_has_replies_query','bbp_reverse_reply_order'); function bbp_reverse_reply_order( $query = array() ) { // Identify post type $bbPress_post_id = get_the_ID(); $bbPress_post_type = get_post_type($bbPress_post_id); if( $bbPress_post_type =='topic' ){ /** TOPIC **/ $query['order']='DESC'; return $query; } };April 27, 2021 at 12:14 am #220319In reply to: Reverse order replies and pagination
Back to Front
ParticipantChecking in because I want this too… there was a plugin called ‘bbpress sort topic replies’, that no longer works, but I’m going to try to grab the code from that
-
AuthorSearch Results