Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'code'

Viewing 25 results - 6,226 through 6,250 (of 32,505 total)
  • Author
    Search Results
  • bjornwebdesign
    Participant

    Ok, last time, I promise :p…

    I updated all my users with the above function, but I don’t want it to run every time on the init hook.
    So I changed it into:

    /*
     * 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 );

    Please note, it has some site specific code, like the wp_redirect.
    Any questions? Feel free to ask.


    @mod
    : Hoping my code snippet is not too long.

    Regards, Bjorn

    bjornwebdesign
    Participant

    OMG… We webdesigners are never finished ๐Ÿ˜›

    After some more testing I noticed that the function did not change all user_nicename.
    The DB type of user_nicename = VARCHAR(50) and the type of display_name = VARCHAR(250).
    If the updated user_nicename exceeds 50 chars the DB field will not update and nothing changes. So I added a substr to resolve this.
    Thankfully the wp_update_user() takes care off special characters like รซ.

    Updated 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 );					
    		}
    	}
    }
    bjornwebdesign
    Participant

    LoL, I thought i was finished, but i noticed the second loop isn’t necessary.
    So here’s my finished/tested code:

    /*
     * Change the user_nicename which is used as profile url, we do NOT want the username in url! Bad bad BP...
     * This conversion runs allways, 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 ( $user->data->user_nicename != $new_user_nicename ) {
    				$args = array(
    					'ID'            => $user->ID,
    					'user_nicename' => $new_user_nicename
    				);
    				wp_update_user( $args );					
    		}
    	}
    }

    Put this in a function and call it on an action hook, can be done in your theme’s functions.php just like the OP already explained here.

    The function will change something like this: ‘Mr. A.T. Testing123’ into ‘mr_at_testing123’.

    bjornwebdesign
    Participant

    Wanted to share my finished code:

    // Change the user_nicename which is used as profile url, we do NOT want the username in url! Bad bad BP...
    // Wheb using the 'init' action hook this will always run, 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( '_', '' );		
    foreach ( get_users() as $user ) {
    	if ( $user->data->user_status == 0 && $user->data->user_nicename != strtolower(str_replace( $search, $replace, $user->data->display_name)) ) {
    		$user_ids[] = $user->ID;
    	}
    }
    foreach( $user_ids as $uid ) {
    	$user_data = get_userdata( $uid );
    	$display_name = $user_data->data->display_name;
    	if ($display_name) {
    		$args = array(
    			'ID'            => $uid,
    			'user_nicename' => strtolower(str_replace( $search, $replace, $display_name))
    		);
    		wp_update_user( $args );
    	}
    }
    bjornwebdesign
    Participant

    Thanks for sharing this! WHAT was BP thinking when they decided to use the username as profile url… I know why (only mandatory userdata on register), but imho the first thing to develop next is a solution to change this..

    EDIT

    When implementing your solution i found something.
    Doing $user->data->user_nicename != $user->data->display_name in the first foreach loop will not work because when updating (second loop) the user_nicename you do a strtolower and str_replace.
    If you want the check to work use the same conversion on the first loop.

    danbp
    Participant

    WP 4.5.3 – BP 2.6 – bbP 2.6 alpha -2016

    I want to remove the 2 bbp related options (topics & replies) from BP’s site wide activity filter dropdown.

    I’m using this function, but it has no effect:

    function remove_activity_filters( $bbp_buddypress = null ) {
       if ( bp_is_active( 'activity' ) && bp_is_activity_component() ) {
          // Remove forum filters in site wide activity streams
          remove_action( 'bp_activity_filter_options', array( bbpress()->extend->buddypress->activity, 'activity_filter_options' ), 10 );
       }
    add_action( 'bbp_buddypress_loaded', 'remove_activity_filters' );
    #175915
    Stagger Lee
    Participant

    I dont get this logic, despite if it is only WP logic, not bbPress one.
    Maybe I missunderstool it all. New Users (Roles = Subscriber, Participant) have access to add new Posts, and attach them to taxonomies.

    Forum Users are forum USers, not Portal editors of Articles.

    This code should be in bbPress core. When you install bbPress you accept that whole platform is changed to something else, and old WP rules are not valid anymore.

    For all other things Users have buddyPress profile Pages.

    function splen_remove_admin_bar() {
    	if( !is_super_admin() ) 
    		add_filter( 'show_admin_bar', '__return_false' );
    }
    add_action('wp', 'splen_remove_admin_bar');
    
    //don't allow users to go wp-admin
    add_action( 'init', 'blockusers_init' );
    function blockusers_init() {
        if ( is_admin() && ! current_user_can( 'administrator' ) &&
           ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
            wp_redirect( home_url() );
            exit;
        }
    }
    #175913
    Robin W
    Moderator

    This code will do that

    //add profile link to forums
    add_action ( 'bbp_template_before_single_forum', 'rew_profile_link' ) ;
    add_action ( 'bbp_template_before_forums_index', 'rew_profile_link' ) ;
    
    function rew_profile_link () {
    	if (!is_user_logged_in())
    		return ;
    	$current_user = wp_get_current_user();
    	$user=$current_user->ID  ;
    	$profile = 'Profile' ;
    	$user_link = '<a href="' . esc_url( bbp_get_user_profile_url( $user) ) . '">' . $profile . '</a>';
    	echo '<div style="text-align: center;">'.$user_link.'</div>';
    }
    #175912
    Robin W
    Moderator

    ok

    On issue 1

    The code goes on then functions file of your child theme

    https://codex.bbpress.org/functions-files-and-child-themes-explained/

    on issue 2, pending 2.6 coming out containing a fix (neither currently has any timescales)

    the you can achieve this with my private groups plugin

    https://wordpress.org/plugins/bbp-private-groups/

    see the help page for how to set up

    #175905
    Robin W
    Moderator

    @robkk – I’m just trying to help someone, not trying to get the most efficient code ๐Ÿ™‚

    #175903
    Robkk
    Moderator

    Robin there is a few functions already in bbPress that might be useful to use, and it might cut some of your code some.

    http://hookr.io/plugins/bbpress/2.5.8/#index=u&search=bbp_user_profile

    #175902
    Robin W
    Moderator

    This should do what you want

    //add profile link to forums
    add_action ( 'bbp_template_before_single_forum', 'rew_profile_link' ) ;
    add_action ( 'bbp_template_before_forums_index', 'rew_profile_link' ) ;
    
    function rew_profile_link () {
    	if (!is_user_logged_in())
    		return ;
    	$current_user = wp_get_current_user();
    		$user=$current_user->user_nicename  ;
    		$user_slug =  get_option( '_bbp_user_slug' ) ;
    			if (get_option( '_bbp_include_root' ) == true  ) {	
    			$forum_slug = get_option( '_bbp_root_slug' ) ;
    			$slug = $forum_slug.'/'.$user_slug.'/' ;
    			}
    			else {
    			$slug=$user_slug . '/' ;
    			}
    			$edit_profile = __('Edit Profile', 'bbp-style-pack') ;
    			//get url
    			$url = get_site_url(); 
    			$profilelink = '<a href="'. $url .'/' .$slug. $user . '/edit">'.$edit_profile.'</a>';
    			echo '<div style="text-align: center;">'.$profilelink ;
    }

    add it to your functions file

    https://codex.bbpress.org/functions-files-and-child-themes-explained/

    #175899
    Robin W
    Moderator

    not tested but this code should allow editing at all times. Add it to your functions file

    add filter ('bbp_past_edit_lock' , 'rew_allow_editing' )
    
    function rew_allow_editing () {
    	$retval = false ;
    	Return $retval ;
    }

    on other posts, I’d wonder if the bbp_reply_id(); might be returning a null or the wrong id.

    As a test the easiest way would be to replace your Edit </a> with

    <?php echo esc_url( home_url( '/' ) ).'conversations/reply/'.bbp_reply_id().'/edit/' ?></a>
    

    That way you’ll see where it is going to send you and can find out what the problem is

    #175894
    EliFerreira
    Participant

    Thanks for your help, Robin W. It worked. I just delete the code of lines 60 and 68 and saved the file.

    #175893
    Robin W
    Moderator

    You will need to change a template, so if you can edit a file and know FTP then you can amend this

    create a directory on your theme called ‘bbpress’
    ie wp-content/themes/%your-theme-name%/bbpress

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

    find
    wp-content/plugins/bbpress/templates/default/bbpress/loop-single-topic.php
    Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
    wp-content/themes/%your-theme-name%/bbpress/loop-single-topic.phpbbPress will now use this template instead of the original and you can amend this.

    Now go to line 68, which says

    <span class="bbp-topic-started-in"><?php printf( __( 'in: <a href="%1$s">%2$s</a>', 'bbpress' ), bbp_get_forum_permalink( bbp_get_topic_forum_id() ), bbp_get_forum_title( bbp_get_topic_forum_id() ) ); ?></span>
    

    and delete this and save the file

    shablon
    Participant

    Since there is a time limit to editing post and no way to set it to unlimited (I wonder why, but that’s a question for another day), I’ve set the limit to maximum. There also was an issue, where original “edit” button wouldn’t show up. I did a little research, and turned out that most of the time, it was theme conflict. Changing theme was not an option. So, I’ve just added a custom “edit” link to template. It looks like this
    <a href="<?php echo esc_url( home_url( '/' ) ); ?>conversations/reply/<?php bbp_reply_id(); ?>/edit/" class="editbtn"> Edit</a>

    It works fine with newer posts. But when I tried editing one of older posts, I got following error:
    The mydomain.com page isnโ€™t working
    mydomain.com redirected you too many times.

    Robkk
    Moderator

    I don’t think there is a character limit when you post a reply or topic with more than 300 characters.

    Check to see if it could be some spam plugin with a feature for this, or a custom theme feature by doing the listed plugin and theme troubleshooting.

    https://codex.bbpress.org/getting-started/troubleshooting/

    #175880
    Robkk
    Moderator

    @stevecl

    The issue also does happen in TwentyFifteen.

    The issue is because in the bbPress default theme package, there is a template called content-search.php. In some newer themes there is also a template of the same name. And since the bbPress templates don’t necessarily need to be in a bbPress folder, the bbPress plugin is choosing the template from your theme before the template that is actually in bbPress.

    Copy content-search.php from the bbPress plugin templates and place it in a child theme in a folder called bbpress. This fixed the issue you are getting in a free version of your currently active theme.

    https://codex.bbpress.org/themes/theme-compatibility/

    Also just created a trac ticket for this issue.

    https://bbpress.trac.wordpress.org/ticket/2966

    #175879
    scootsafe
    Participant

    Heyy hi, it is working as it is now when i insert this code in! Thanks!

    #175870
    Robkk
    Moderator

    @scootsafe

    Since you enabled threaded replies, which has an issue with some mobile responsive styles because how they are by default. Try this custom CSS, or disable threaded replies and see if your forums have a better layout, though I am not sure how the mycred badges will react.

    #bbpress-forums div.bbp-reply-author a.bbp-author-name {
      display: block !important;
    }
    #175862

    Topic: What does Robkk do?

    in forum Showcase
    peter-hamilton
    Participant

    besides all the wonderful and appreciated help here on the bbpress forums, what do you do with bbpress?

    I would love to see more websites showcased and since you @robkk are leading the herd now I am in need to see the best bbpress forums online from you, I bet you made a few by now.

    I personally get a lot of inspiration looking at other forums and see how people make the code their own but can not find a descent showcase anywhere.

    Looking forward to be amazed
    Peter

    #175856
    Stephen Edgar
    Keymaster

    @jon-fergus I suggest you do not add edit_others_topics to user roles so they can add inline images, it *WILL* allow them to *edit others topics** for whatever reason users cannot edit other topics as you suggest might be a bug, it might not be and maybe a conflict with your *adminimize hide dashboard* plugin and is obfuscated and easily bypassed.

    #175854

    In reply to: logout page issue

    Robkk
    Moderator

    My bad it is called the (bbPress) login widget.

    I got confused of this custom widget I created that is a fork of the same code.

    #175853
    Robkk
    Moderator

    Something like this might work. In the post views plugin you will need to edit how it displays so it does not show “views” at the end of the number. If you do not want to mess with anymore files, or change the template view, just use the function in this post I created in this kind of similar topic.

    https://bbpress.org/forums/topic/new-feature-viewhit-counts/#post-161937
    loop-topics.php snippet

    <ul class="forum-titles">
    	<li class="bbp-topic-title"><?php _e( 'Topic', 'bbpress' ); ?></li>
    	<li class="bbp-topic-voice-count"><?php _e( 'Voices', 'bbpress' ); ?></li>
    	<li class="bbp-topic-views-count"><?php _e( 'Views', 'bbpress' ); ?></li>
    	<li class="bbp-topic-reply-count"><?php bbp_show_lead_topic() ? _e( 'Replies', 'bbpress' ) : _e( 'Posts', 'bbpress' ); ?></li>
    	<li class="bbp-topic-freshness"><?php _e( 'Freshness', 'bbpress' ); ?></li>
    </ul>

    loop-single-topic.php

    <li class="bbp-topic-voice-count"><?php bbp_topic_voice_count(); ?></li>
    
    <li class="bbp-topic-views-count"><?php if(function_exists('the_views')) { the_views(); } ?></li>
    
    <li class="bbp-topic-reply-count"><?php bbp_show_lead_topic() ? bbp_topic_reply_count() : bbp_topic_post_count(); ?></li>

    CSS

    #bbpress-forums li.bbp-topic-views-count {
      float: left;
      width: 15%;
      text-align: center;
    }
    
    #bbpress-forums li.bbp-topic-title {
      float: left;
      text-align: left;
      width: 43%;
    }

    Also make sure to surround your code with the backticks from the code button in the toolbar.

    These-> '' <-these

    #175851
    peter-hamilton
    Participant

    And I wish this forum did a bit more to sell BBPress, where are the showcases, the paid for professionals and why is this theme still sooooo boring.

    Why not integrate more with Buddypress forums, as I can not believe people only using BBPress on its own, I want a better profile.

    Why not have the option to test plugins on this site with live demos.

    Why not have a clear donation button on your site, or do anything to receive funds to spend time improving the BB line.

    Perhaps charge people 1 euro to download BBPress first time then free for life through account, perhaps the free model gives more awareness but BBPress is good enough to compete with expensive forum software.

    Why not compete with codecanyon and offer premium plugins that work without conflicts.

    Why not hire me as vice president of BBCorp and pay me lots, I accept jellybeans as currency.

    Anyway, as mentioned before loving BBPress.

    P.H.

Viewing 25 results - 6,226 through 6,250 (of 32,505 total)
Skip to toolbar