Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'code'

Viewing 25 results - 1,651 through 1,675 (of 32,466 total)
  • Author
    Search Results
  • #220650
    Anonymous User 18731058
    Inactive

    Hi Robin,
    Unfortunately, the code you’ve provided isn’t working for me. However, bbp_get_user_topic_count_raw and bbp_get_user_reply_count_raw work fine, so I’ve replaced the functions using JavaScript.

    <?php
    $topicCount = bbp_get_user_topic_count_raw(wp_get_current_user()->ID);
    $replyCount = bbp_get_user_reply_count_raw(wp_get_current_user()->ID);
    ?>
    
    <script>
    var topicCount = document.querySelector('.bbp-user-topic-count');
    var replyCount = document.querySelector('.bbp-user-reply-count');
    if(topicCount){topicCount.innerHTML = 'Topics Created: ' + '<?php echo $topicCount ?>'}
    if(replyCount){replyCount.innerHTML = 'Replies Created: ' + '<?php echo $replyCount ?>'}
    </script>
    #220644
    Robin W
    Moderator

    yes, this has been happening for a while (it happens on this site!) , and I’ve not got round to looking at why until you posted (I am a bbpress user who helps out here, not one of the bbpress authors).

    I’ve just dug into the code and created a trac fix ticket for it

    https://bbpress.trac.wordpress.org/ticket/3429#ticket

    in the meantime, this code fixes the problem

    add_filter ('bbp_bump_user_topic_count' , 'rew_new_topic_count', 10 , 4) ;
    
    function rew_new_topic_count ($user_topic_count, $user_id, $difference, $count) {
    	//check if count is 2 and should be 1 by seeing if user topic count is empty!!
    	if ($user_topic_count==2 && empty (bbp_get_user_topic_count( $user_id, true )) )$user_topic_count = 1 ;
    return $user_topic_count ;	
    }
    
    add_filter ('bbp_bump_user_reply_count' , 'rew_new_reply_count', 10 , 4) ;
    
    function rew_new_reply_count ($user_reply_count, $user_id, $difference, $count) {
    	//check if count is 2 and should be 1 by seeing if user topic count is empty!!
    	if ($user_reply_count==2 && empty (bbp_get_user_reply_count( $user_id, true )) )$user_reply_count = 1 ;
    return $user_reply_count ;	
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    biznisoka
    Participant

    I can’t find the solution for custom redirect when forgot password form is sent (the form with only one field, your username or email, and “get new password” button, which triggers the email with the reset password link in it, which then opens the reset password form).

    The reset password form which has two fields, “new password” and “repeat new password” (and buton save password). I solved the reset password redirect with code snippet

    function wpse_lost_password_redirect() {
        wp_redirect( 'myurl' ); 
        exit;
    }
    add_action('password_reset', 'wpse_lost_password_redirect');

    But it doesn’t work for the lost password form. Is there also a redirect function for forgot password, which I could use?

    Have WP 5.7.2., bbpress 2.6.6., also use themeMyLogin plugin.

    Thanks in advance!

    #220623
    biznisoka
    Participant

    Changed the theme, but the issue was still there.

    I now found this solution, it worked for me:

    add_action('wp_logout','ps_redirect_after_logout');
    function ps_redirect_after_logout(){
             wp_redirect( 'your url here' );
             exit();
    }
    #220612
    Robin W
    Moderator

    This code is from version 1 of bbpress, so probably no longer works.

    #220603
    kwk
    Participant

    Please, how did you use the code <<echo bb_get_avatar( bb_get_current_user_info( ‘id’ ), 32 )>> to display the avatar or gravatar of the logged-in user in the header. Any explanation on what to do?

    #220601
    Robin W
    Moderator

    I saw your one before the edit.

    I put this in my form-reply

    <input name="toggle-check" id="toggle-check" type="checkbox" value="value">hello

    and this in my theme’s functions file

    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['toggle-check'] ) ) {
    $myvalue = $_POST['toggle-check'] ;
    }
    else $myvalue='empty' ;
    
    update_post_meta ($reply_id , 'toggle-check', $myvalue) ;

    and that works fine

    #220595
    vincenzon617
    Participant

    Sorry, I should have been more clear. I did post a reply but it got deleted while I was trying to get the code in the correct format to make it clearer to read!

    The form that I am adding to is within the ‘form-reply.php’ file and I have the checkbox working fine. The struggle I have is that even when the checkbox is clicked the $_POST['my_parameter'] is always empty and so the wrong value is being added as metadata. I have looked up some solutions to this, and the majority of them are suggesting it is something to do with the “action” part of the form, so I am wondering if this is the case or possibly something else?

    If you would like me to post the code I will try again!

    #220593
    Robin W
    Moderator

    ok, I’m very confused.

    if you are adding this code to a form, then it is already in a form, so you don’t need the <form…

    you’d just need to code I put above ie

    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>' ;

    maybe you could post the entire form you are trying to change, and indeed say where/what it is?

    #220592
    vincenzon617
    Participant

    I have been implementing this feature to my site today and I have managed to add the metadata to the database however, I can’t seem to be able to receive the POST variable. I have added this checkbox within the form: <form id="new-post" name="new-post" method="post" action="<?php the_permalink(); ?>">. This is the form used to get the user’s reply but as you can see the ‘action’ is set to <?php the_permalink(); ?>. Would this still allow me to access the variable within my functions.php file or will I have to change the action / create another form and submit button?

    Many thanks

    n3wjack
    Participant

    What I do in this case is use client side JavaScript code to inject a new HTML element at the position you want it, with your custom code.
    I put a Custom HTML widget on the page which has all the required JS & CSS code.
    The advantage of this approach is that you don’t need to mess with the PHP files of your WordPress or bbPress setup, so when you do an upgrade in the future, you don’t have to worry about your changes being overwritten, or your site to break because of your changes.

    I use the code below to place a Reply button on top of the page. When it’s clicked, it will scroll down to the new post form at the bottom of the page (the most recent post is on top).

    <script type="text/javascript">
    	// Add the reply shortcut button at the top.
    	let btn = document.createElement("a");
        btn.href='javascript:document.getElementsByClassName("bbp-footer")[0].scrollIntoView()'	
    
    	btn.innerText='Reply'
    	btn.className='nj-replybtn'
    
    	let n = document.getElementsByClassName('bbp-replies')[0];
    
    	if (n !== null) {  
    		n.parentNode.insertBefore(btn, n);
    	}
    
    </script>
    <style>
    	.nj-replybtn {
    		color: white;
    		background-color: #007acc;
    		
    		padding: 5px;
    		margin: 2px;
    	}
    </style>
    #220560
    lolataylor1
    Participant

    WP version 5.7.2
    bbPress Version: 2.6.6
    Astra Theme Version: 3.4.2
    Website: https://authorready.com/forum

    I did a new install of bbPress on my existing site with the Astra LearnDash theme with no child theme. I followed the instructions on the step-by-step page (https://codex.bbpress.org/step-by-step-guide-to-setting-up-a-bbpress-forum/) to set up the forum and am using the shortcode [bbp-forum-index] to display the forum on my page.

    When I navigate to a topic from the forum (i.e., Forum > Announcements > Test Topic Creation), it shows my 404 page instead of the topic. The same thing happens if I go into the topic from the admin panel and try to preview the page. I have tried to following from other topic support tickets with no success:

    1. Dashboard > Settings > Permalinks and clicked save. No change.
    2. Installed Health Check & Troubleshooting. Health Check was good.
    3. Entered troubleshooting mode and deactivated all but the bbPress plugin with the Twenty Twenty theme. Still no topics, but redirected to the home page instead of the 404.
    4. Installed bbPress WP Tweaks and tried all of the .php page settings with no change.

    Is there something I’m missing? I’m at a loss of what else to try or why it may not be working.

    #220553
    Robin W
    Moderator

    unanswered can be done by

    bbp style pack

    once activated

    create a wordpress page and use the [bsp-display-topic-index …..] shortcode

    see

    dashboard>settings>bbp style pack>Shortcodes for how to use it – but create one with noreply

    then you just create a link to that page

    #220516
    Robin W
    Moderator

    so 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

    #220515
    Robin W
    Moderator

    without 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 not

    you can use the code above to set your meta data

    #220514
    vincenzon617
    Participant

    I 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

    #220505

    In reply to: bbpress redirection

    Robin W
    Moderator

    how are they loggong on wp-logon, or widget or shortcode?

    #220491
    Robin W
    Moderator

    you’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) ;
    }
    #220490
    #220470
    vincenzon617
    Participant

    I 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";

    vincenzon617
    Participant

    Is there a way to append text to the reply form using JavaScript?
    I have this function

    window.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 .innerHTML is 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

    #220451
    webmasterfreya
    Participant

    Hi 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}

    sino27
    Participant

    Hi 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?

    #220433
    deborah86
    Participant

    Will 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?

    deborah86
    Participant

    I am currently using the Twenty Twenty theme. The theme is causing jumbled text on the forum page.

    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.

Viewing 25 results - 1,651 through 1,675 (of 32,466 total)
Skip to toolbar