Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)

  • ositive
    Participant

    @ositive

    This is the function i’ve used, with a random function to create unique username. I hope can help.
    Ositive

    add_action( 'bp_core_validate_user_signup', 'custom_validate_user_signup' );
    
    function custom_validate_user_signup($result){
    		
      unset($result['errors']->errors['user_name']);
    
      if(!empty($_POST['field_1']))
      {
        $result['user_name'] =  $_POST['field_1'] . '_' . rand(1, 9999);
    	$_POST['signup_username'] = $result['user_name'];
    	$result['user'] =  $_POST['field_1'];
    	$_POST['signup_password_confirm']=$_POST['signup_password'];
      }
      return $result;
    }

    ositive
    Participant

    @ositive

    update:
    I obtained it just adding
    $_POST[‘signup_password_confirm’]=$_POST[‘signup_password’];
    in my function.php


    ositive
    Participant

    @ositive

    Hi aaronthomas1979
    Thanks for yuor answer
    Absolutely yes! please share your code!
    I would like to do something a bit different, but I think that I should start from your code adapting it to my scope.
    What I exactly want to achieve: something like facebook do, that is to copy the full name (that is the only name the user will digit in the registration form) in the username (that must be automatically generated). The problem with this solution is that the username must be unique so I could insert a code like the following to insert a number at the end of the name making it unique:

    function username( $username){
    	$username = $username[0];
    	$j = 1;
    	while ( username_exists( $username ) ){
    		$username = $username . '_' . $j;
    		$j++;
    	}
    
    	return $username;
    }

    I think this is the cleanest solution: the users will insert the real name in the registration form, (without asking to change the full name inserted if another user with the same name is already registered) but a unique username is created silently anyway.
    Please share, hope to find a solution with yours o any other contribute
    Thanks
    Ositive


    ositive
    Participant

    @ositive

    Anyone?
    Something bad/wrong in My post?
    Thanks


    ositive
    Participant

    @ositive

    Thank you Shanebp
    I tried the following steps (below is the final code):
    -I started from the basic random code
    -I introduced the function to create and pass #sql (like Ninja Warrior trick code)
    but it seems not working.. Can you help me please (I’m really trying everithing..)?
    Thanks

    <?php
     
    // Exit if accessed directly
    if ( !defined( 'ABSPATH' ) ) exit;
     
    class BP_Loop_Filters {
     
        
        public function __construct() {
            $this->setup_actions();
        }
     
        private function setup_actions() {
            /**
             * Adds the Rating order to the select boxes of the Members directory pages
             */
            // Members component is core, so it will be available
            add_action( 'bp_members_directory_order_options', array( $this, 'rating_order' ) );
     
        }
     
        public function rating_order() {
           
    	global $wpdb;
    
    	$sql = "SELECT
                     a.ID as id, a.user_nicename AS name, a.display_name AS displayname, AVG(star) AS rating, COUNT(star) AS reviews
                 FROM {$wpdb->prefix}users AS a
                 LEFT JOIN {$wpdb->prefix}bp_activity AS b ON a.ID = b.usercheck
                 WHERE (b.is_activated is null or b.is_activated=1)
                 GROUP BY id
                 ORDER BY rating DESC";
        var_dump( $sql );
    
    	return $sql;
    
        }
     
    }
     
    function bp_loop_filters() {
        return new BP_Loop_Filters();
    }
     
    add_action( 'bp_include', 'bp_loop_filters' );

    ositive
    Participant

    @ositive

    Yes, it worked for me!
    I have some other doubts that I posted in a separated post as they are not related with the template:

    Buddypress email language selection in multilanguage web site

    Thank you Paul!


    ositive
    Participant

    @ositive

    I tryed to work also with this solution (provided by @shanebp too):
    https://buddypress.org/support/topic/creating-a-new-order-by-filter-in-groups-loop-with-custom-sql/
    but I do not obtain to order members by rating.. is this the right approach??

    function antares_members_filter_options() {
        echo '<option value="rating">rating</option>';
    }
    add_action( 'bp_members_directory_order_options', 'antares_members_filter_options' );
    
    function antares_ajax_querystring( $query_string, $object ) {
    
    	if ( 'members' != $object ) 
    		return $query_string;
    
    	if ( ! bp_is_members_directory() ) 
    		return $query_string;
    	
    	$query_args = wp_parse_args( $query_string, array() );
    
            $page = $query_args['page'];
    
    	if( isset( $query_args['action'] ) && $query_args['action'] == 'rating' ) {
    	
    		$query_args = array();
    		$query_args['page'] = $page;
    		$query_args['orderby'] = 'rating';		
    		$query_args['order'] = 'ASC';			
    		$query_args['include'] = antares_get_members(); 
    		$query_string = http_build_query( $query_args );
    
    	}
    
    	return $query_string;
    
    }
    add_filter( 'bp_ajax_querystring', 'antares_ajax_querystring', 32, 2 );
    
    function antares_get_members() {
        global $wpdb;
    
            $sql = "SELECT 
    					a.ID as id, a.user_login AS name, a.display_name AS displayname, AVG(star) AS rating, COUNT(star) AS reviews
    				FROM 
    					{$wpdb->prefix}users AS a
    				LEFT JOIN 
    					{$wpdb->prefix}bp_activity AS b ON a.ID = b.usercheck
    				WHERE 
    					(b.is_activated is null or b.is_activated=1)
    				GROUP BY 
    					id
    				ORDER BY 
    					rating DESC";
        
    $buff = array();
    
    $result = $wpdb->get_results( $sql , OBJECT );
    
    		foreach ($result as $row) {
    			$buff[]= $row->id ;
    		}
    		
    $query_str= implode (',', $buff);
    return $query_str;
    }

    ositive
    Participant

    @ositive

    Thank you for the answer.
    Can be appplicable to use a wp email plugin to create wp html email (such us wp better email) and copy the bp email html (with care)in The html of The plugin or is there something I’m not considering?
    Thank you again!


    ositive
    Participant

    @ositive

    *to find the solution


    ositive
    Participant

    @ositive

    In other words, looking to the database, I basically need to add a “sort by” function that sorts users by The avg of a field of the avtivity table. That is, I don’t sort by a x profile field but by the avg of a value of The activity table of my DB. Any idea on how Can i do that, or any piece of code from which i can start to fine The soluto?
    Thanks!!

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