Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 25 replies - 1 through 25 (of 43 total)

  • landwire
    Participant

    @landwire

    Hi there,
    just listening in, as I also need to use the newly uploaded/changed avatar image to update it somewhere else in the DB.
    Any news on this?


    landwire
    Participant

    @landwire

    Hi there, does anyone have an answer to this question? Because I have no idea how to find that out otherwise.
    Thanks!


    landwire
    Participant

    @landwire

    Hi there,
    I narrowed the problem down:
    I am using: wp_enqueue_media() on the same page as the new avatar upload and that seems to be creating the conflict. I am not great with the whole backbone stuff, so I would need some help here.

    Could someone confirm that conflict and what can be done to avoid this conflict?
    Many thanks,
    Sascha


    landwire
    Participant

    @landwire

    ok, in the end I used this to solve the problem, as I ran into issues when trying to save an array of arrays with the bp functions. Just in case someone is looking for this as well:
    First: I stripped the slashes before saving serialized data to the DB with a filter
    Second: I had to copy/create a different xprofile_get_field_data() function, as it would not get complex serialized values (array of arrays). Single arrays it works ok, but not nested arrays. Basically I had to remove all those filters that were called during xprofile_get_field_data().
    It’s hacky, but I tried many options. This seems to be the one that worked in the end.

    /**
     * Fetches profile data for a specific field for the user.
     *
     * When the field value is serialized, this function unserializes and filters
     * each item in the array.
     *
     * @package BuddyPress Core
     * @param mixed $field         The ID of the field, or the $name of the field.
     * @param int $user_id         The ID of the user
     * @param string $multi_format How should array data be returned? 'comma' if you want a
     *                             comma-separated string; 'array' if you want an array
     * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed.
     * @return mixed The profile field data.
     */
    function lw_xprofile_get_field_data( $field, $user_id = 0, $multi_format = 'array' ) {
    
    	if ( empty( $user_id ) ) {
    		$user_id = bp_displayed_user_id();
    	}
    
    	if ( empty( $user_id ) ) {
    		return false;
    	}
    
    	if ( is_numeric( $field ) ) {
    		$field_id = $field;
    	} else {
    		$field_id = xprofile_get_field_id_from_name( $field );
    	}
    
    	//d($field_id, 'The field ID ><><><><><>><>>>>>>>_+++++++++++++');
    	if ( empty( $field_id ) ) {
    		return false;
    	}
    
    	$values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_id, $user_id ) );
    	//d($values, 'The values <><><>>><><><><><><><><>><');
    
    	return $values;
    }
    
    add_filter( 'xprofile_filtered_data_value_before_save', 'lw_strip_slashes_before_db', 10, 3);
    
    function lw_strip_slashes_before_db($filtered_value, $value, $data_obj ) {
    	//d($filtered_value, '$filtered_value');
    	//d($value, '$value');
    	//d($data_obj, '$data_obj');
    	if ( is_serialized($value) ) {
    		$filtered_value = stripslashes($filtered_value);
    	}
    	return $filtered_value;
    }

    landwire
    Participant

    @landwire

    Yes, I did not think of that. Well, a lesson hard learned 🙁


    landwire
    Participant

    @landwire

    Ok, passing in an array worked!
    Phew, was stuck for the past 4 hours on this…
    Thanks anyway,
    Sascha


    landwire
    Participant

    @landwire

    I am using this:
    xprofile_set_field_data($custom_field, $displayed_user_id, $entry[$field[‘id’]]);

    With $entry[$field[‘id’]] = a:1:{i:0;s:5:”Klaus”;}

    BUT in DB it is written as: a:1:{i:0;s:5:\”Klaus\”;}

    That is because of (in bp-xprofile-filter.php):

    add_filter( ‘xprofile_data_value_before_save’, ‘xprofile_sanitize_data_value_before_save’, 1, 4 );

    I will try passing in an array instead of a:1:{i:0;s:5:”Klaus”;}


    landwire
    Participant

    @landwire

    Ok, never know which place is best to ask a question like that.
    Thanks!


    landwire
    Participant

    @landwire

    Nope, is_page does not work in ajax call. See earlier comment:

    Ok, this explains the ajax is_page check not working:

    http://wordpress.stackexchange.com/questions/26472/is-page-conditional-not-working-inside-an-ajax-function

    Is that something that can be taken to core developers and asked if we can enhance the filter functionality? As said, it’s a pretty common thing to filter by different users I think.
    Thanks for all your help anyway again,
    Sascha


    landwire
    Participant

    @landwire

    Sorry, maybe I was not clear.

    I have the following pages loading directories:
    http://www.example.com/offices
    http://www.example.com/students
    http://www.example.com/professionals
    http://www.example.com/suppliers

    I then need to filter each ajax call to only show that particular user group currently shown in the directory. BUT if it is too difficult, I will just kick out that ajax filter.

    I can only see the ajax filter work if there would be the option for instance to include/create a “$sub_object” or pass some other data in from the page that the filter is called from. Is that right?


    landwire
    Participant

    @landwire

    Ok, I am dispairing on this one. Tried globals, but then I read that globals are not accessible in AJAX requests. I guess the only option is to pass some parameter where the call is coming from. Is there a way to do this?

    Is there a way to ask one of the core developers if what I am trying to achieve is at all possible? I guess it’s a common thing to group users by their role and then be able to resort them with ajax.

    My code looks like this right now: (lots of d($variable), which is just showing me the variables in the console)

    function lw_my_filter( $query = false, $object = false ) {
    	d($query, 'QUERY');
    	d($object, 'OBJECT');
    	$test = 'Before if call';
    	d($test);
    	global $lw_directory;
        d($lw_directory);
    	d($GLOBALS['lw_directory'], 'GLOBAL');
        if ( is_page( 'offices' ) ) {
    		$GLOBALS['lw_directory'] = 'office';
    		$test2 = 'inside if call';
    		d($test2);
           	$included_users = implode(',',get_users('role=office&fields=ID'));
    		d($included_users);
    		$querystring = 'include=' .$included_users;
    		d($GLOBALS['lw_directory'], 'GLOBAL');
        }
    	else if ( $GLOBALS['lw_directory'] == 'office') {
    		$included_users = implode(',',get_users('role=office&fields=ID'));
    		d($included_users);
    		$querystring = 'include=' .$included_users;
    		d($GLOBALS['lw_directory'], 'GLOBAL');
    	}
    	d($querystring);
        return $querystring;
    }
    add_filter( 'bp_ajax_querystring', 'lw_my_filter', 20, 2 );

    landwire
    Participant

    @landwire

    Looking at the code I would think it fires on all occasions. I will have at least 4 user roles that I need to filter: office, supplier, student, professional.

    Is there any way that I can pass a parameter with the ajax query?


    landwire
    Participant

    @landwire

    Ok, this explains the ajax is_page check not working:

    http://wordpress.stackexchange.com/questions/26472/is-page-conditional-not-working-inside-an-ajax-function

    Will try your last suggestion in a little while and report back.
    S


    landwire
    Participant

    @landwire

    Ok, will try that.

    BTW: what is the difference between the following filters:

    bp_legacy_theme_ajax_querystring and bp_ajax_querystring as per documentation here:

    bp_ajax_querystring()

    I guess I find the

    To filter ajax:

    bit odd. Maybe I should use that filter?


    landwire
    Participant

    @landwire

    Not sure where I can see if I have root profiles enabled?

    Anyway, the ajax filter get’s called, but the is_page (‘offices’) returns false I assume as it does not go into the if. On first load/page refresh the filter gets called and is_page(‘offices’) returns true. Then on ajax call the if returns false.

    Could I use another if call? Like setting a global variable or something? Or is maybe I do have root profiles enabled, but I do not think so….


    landwire
    Participant

    @landwire

    Yes, shortcode works great! Glad you like the approach!

    @Henry

    My problem now:

    How do I make sure the ajax call on changing “last active” “alphabetical” etc. only returns users of that role, that I am just looking at? As the ajax call seems to revert always to the roles chosen in members-loop.php. So if I restrict roles there, then the ajax call on “office” will respect that. So there must be some kind of “link” between the two, but I do not know how to change the ajax call.

    http://2013d.landwire.net/offices/ -> only offices at first, then all roles on ajax call
    http://2013d.landwire.net/members/ -> all roles
    Sascha


    landwire
    Participant

    @landwire

    Ok, Now I also learned about

    ob_start();
    echo 'hello world';
    echo 'This is a WordPress shortcode';
    $output_string = ob_get_contents();
    ob_end_clean();
    return $output_string;

    So I added this and it works great for me! Maybe that will help someone encoutering the same challenge.


    landwire
    Participant

    @landwire

    Henry, would just like your thought on the following.
    I went down a different route with the above, not sure if that is recommended though:

    I created a shortcode like so, basically putting the whole new office-index.php into it. Then just put the shortcode into a page called “office” and it looks great out of the box – all formatting etc intact!

    See: http://2013d.landwire.net/office/

    You can compare all three now. There still all live.

    Do you think it’s ok to do it like that?

    function lw_office_directory( $atts ) {
    	 do_action( 'bp_before_directory_members_page' ); ?>
    
    <div id="buddypress">
    
    	<?php do_action( 'bp_before_directory_members' ); ?>
    
    	<?php do_action( 'bp_before_directory_members_content' ); ?>
    
    	<div id="members-dir-search" class="dir-search" role="search">
    		<?php bp_directory_members_search_form(); ?>
    	</div><!-- #members-dir-search -->
    
    	<?php do_action( 'bp_before_directory_members_tabs' ); ?>
    
    	<form action="" method="post" id="members-directory-form" class="dir-form">
    
    		<div class="item-list-tabs" role="navigation">
    			<ul>
    				<li class="selected" id="members-all"><a href="<?php bp_members_directory_permalink(); ?>"><?php printf( __( 'All Members', 'buddypress' )); ?></a></li>
    
    				<?php if ( is_user_logged_in() && bp_is_active( 'friends' ) && bp_get_total_friend_count( bp_loggedin_user_id() ) ) : ?>
    					<li id="members-personal"><a href="<?php echo bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends/'; ?>"><?php printf( __( 'My Friends <span>%s</span>', 'buddypress' ), bp_get_total_friend_count( bp_loggedin_user_id() ) ); ?></a></li>
    				<?php endif; ?>
    
    				<?php do_action( 'bp_members_directory_member_types' ); ?>
    
    			</ul>
    		</div><!-- .item-list-tabs -->
    
    		<div class="item-list-tabs" id="subnav" role="navigation">
    			<ul>
    				<?php do_action( 'bp_members_directory_member_sub_types' ); ?>
    
    				<li id="members-order-select" class="last filter">
    					<label for="members-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label>
    					<select id="members-order-by">
    						<option value="active"><?php _e( 'Last Active', 'buddypress' ); ?></option>
    						<option value="newest"><?php _e( 'Newest Registered', 'buddypress' ); ?></option>
    
    						<?php if ( bp_is_active( 'xprofile' ) ) : ?>
    							<option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
    						<?php endif; ?>
    
    						<?php do_action( 'bp_members_directory_order_options' ); ?>
    					</select>
    				</li>
    			</ul>
    		</div>
    
    		<div id="members-dir-list" class="members dir-list">
    			<?php bp_get_template_part( 'members/offices/offices-loop' ); ?>
    		</div><!-- #members-dir-list -->
    
    		<?php do_action( 'bp_directory_members_content' ); ?>
    
    		<?php wp_nonce_field( 'directory_members', '_wpnonce-member-filter' ); ?>
    
    		<?php do_action( 'bp_after_directory_members_content' ); ?>
    
    	</form><!-- #members-directory-form -->
    
    	<?php do_action( 'bp_after_directory_members' ); ?>
    
    </div><!-- #buddypress -->
    
    <?php do_action( 'bp_after_directory_members_page' );
    }
    add_shortcode('lw_office_directory', 'lw_office_directory');

    landwire
    Participant

    @landwire

    Thanks Henry, was just looking into the structure of the page too. CSS is a good point and the body classes too! I will get there from here I think. Thanks for your valuable input!
    Sascha


    landwire
    Participant

    @landwire

    That works ok now. I basically used the page.php template and replaced the whole loop with the page-office-loop.php file contents and saved that as page-office-loop.php. Does still not look like the members page though.

    Maybe take a look if you have a minute. One also shows up a search box while the other does not. Strange. I did NOT use <?php get_footer( ‘buddypress’ ); ?> or <?php get_header( ‘buddypress’ ); ?> as the page template already loads some header/footer.

    Modified: http://2013d.landwire.net/offices-index/
    Original – though I took members count out of tab: http://2013d.landwire.net/members/
    S


    landwire
    Participant

    @landwire

    Hmm, that works the same as the page template approach I made earlier.

    The display is rather blank though, no footer/header etc. And I had a typo before in my code, so your approach highlighted that mistake!

    Is there a way that I could just use a standard template and “inject” the buddypress members content there. Basically just like a copy and paste of the page-offices-loop.php into the wordpress text editor?

    Sascha


    landwire
    Participant

    @landwire

    I thought it’s simple. Just had a block. Tried to create a page-template, but that just did not work…
    Will try that right now!
    Thanks for the fast reply,
    Sascha


    landwire
    Participant

    @landwire

    Did I say October time 1 1/2 years ago? Well, it took a bit longer! Has anything happened on the front of connection meta or “friendship” meta? Or other connection types?
    Thanks,
    Sascha


    landwire
    Participant

    @landwire

    Old threat, but did you solve this? I am looking for a solution too.
    Sascha


    landwire
    Participant

    @landwire

    Thanks Paul,
    the followers plugin is ok, but is not what I was looking for.
    Are you still looking to implement more types of relationship into BuddyPress?

    Would there be some workaround until then? Using some kind of metadata that can be stores with each connection I make? Anyway, I quite likely will not get to this until the October time…

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