Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Text Boxes Creating Unwanted Random Links


  • ma3ry
    Participant

    @ma3ry

    WP 4.3.1
    BP 2.3.4
    https://christiangayschat.com
    Problem happens in my current theme “GeneratePress Child” and also in “Twenty-Fifteen”.

    I am just starting to build this site. A Beta Tester pointed out the problem to me on his Profile.

    I am only using one text box in Basic Profile Questions (About Me). It looks fine in the back end but when viewing someone’s profile in the front end, unwanted links occur. They take me back to Members Area page.

    Example: My profile is at https://christiangayschat.com/members-area/mary/profile/

    About Me: Retired X-Ray Tech, mom of four daughters and five grandchildren. My companion is my dog Tasha. My interests include photography, technology and building websites.

    <u>Retired X-Ray Tech</u> and <u>Technology And Building Websites</u> are both made into links.

    The member who pointed it out to me has a much longer content and it is full of these unwanted links. How do I get rid of them please.

    Thank you!

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

  • danbp
    Participant

    @danbp

    Hi @ma3ry,

    unable to visit the indicated page due to redirection… BP’s xProfile text box contains are autolinked by default for the 5 first words.
    This is handy when you use a field called city for example. The city name is autolinked and let each user click on it to find other who may entered the same name.

    Of course, an about me box with a long description, which several autolinked words has less interrest. Fortunately, you can deactivate xprofile autolinking.
    Two options for this: all or selected.

    Here 3 snippets. The first can be used if you want to completely remove autolink from all field values.
    The second is a new filter to let you choose the field(s) you want to deactivate. This need two snippet. The first to rewrite a filter and the second to remove / replace the existing BP filter.

    Add the snippet to bp-custom.php.

    // remove any autolink from profile
    function remove_xprofile_links() {
    remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    }
    add_action( 'bp_init', 'remove_xprofile_links' ); 
    
    // custom filter to selectively remove autolink
    function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
    
        // Access the field you are going to display value.
        global $field;
    
        // In this array you write the ids (separated by comma) of the fields you want to hide the link.
        $excluded_field_ids = array(2);
    
        // If the id of this $field is in the array, we return the value only and not the link.
        if (in_array($field->id, $excluded_field_ids))
    	return $field_value;
    	
    	if ( 'datebox' == $field_type )
    	return $field_value;
    	
    	if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) )
    	return $field_value;
    	
    	$values = explode( ',', $field_value );
    	
    	if ( !empty( $values ) ) {
    		foreach ( (array) $values as $value ) {
    			$value = trim( $value );
    			
    			// If the value is a URL, skip it and just make it clickable.
    			if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) {
    				$new_values[] = make_clickable( $value );
    				
    				// Is not clickable
    			} else {
    				
    				// More than 5 spaces
    				if ( count( explode( ' ', $value ) ) > 5 ) {
    					$new_values[] = $value;
    					
    					// Less than 5 spaces
    				} else {
    					$search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
    					$new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>';
    				}
    			}
    		}
    		
    		$values = implode( ', ', $new_values );
    	}
    	
    	return $values;
    }
    
    /**
     * We remove the buddypress filter and add our custom filter.
     */
    function remove_xprofile_links() {
        // Remove the old filter.
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
        // Add your custom filter.
        add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2);
    }
    add_action('bp_setup_globals', 'remove_xprofile_links');

    ma3ry
    Participant

    @ma3ry

    Perfect!!!! Thank you so very much!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Text Boxes Creating Unwanted Random Links’ is closed to new replies.
Skip to toolbar