• Resolved drh192

    (@drh192)


    Hi,

    I wanted to use this on multisite for logged in users only. Made the following changes

    /app/entities/user/userrepository.php
    
    public function getFavorites($user_id = null)
    	{
    		$saveType = $this->settings_repo->saveType();
    
    		if ( is_user_logged_in() ) {
    			$user_id = ( isset($user_id) ) ? $user_id : get_current_user_id();
    			$key = (is_multisite() ? 'simplefavorites_' . get_current_blog_id() : 'simplefavorites');
    			$favorites = get_user_meta($user_id, $key);
    
    			if ( empty($favorites) ) return array();
    			return $favorites[0];
    		}
    		$favorites = ( $saveType == 'cookie' ) ? $this->getCookieFavorites() : $this->getSessionFavorites();
    		return $favorites;
    	}

    And

    app/entities/favorite/syncuserfavorite.php
    
    	public function updateUserMeta($favorites)
    	{
    		if ( !is_user_logged_in() ) return false;
    		$key = (is_multisite() ? 'simplefavorites_' . get_current_blog_id() : 'simplefavorites');
    		return update_user_meta( get_current_user_id(), $key, $this->array_flatten($favorites) );
    
    	}

    By adding a site_id $key to the user meta I have the functionality I want, could you support this in a future release?

    https://wordpress.org/plugins/favorites/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Kyle Phillips

    (@kylephillips)

    Thanks for the suggestion. I’m currently updating the plugin to be multisite compatible. It’ll be implemented a bit different than the method you’ve used (in order to provide more flexibility in the plugin API). So… once it’s released please be aware that in your case, updating will cause favorite counts to essentially be reset.

    Since your user meta will be saved in separate rows, I’m sure you could combine the counts fairly quickly and resave.

    Plugin Author Kyle Phillips

    (@kylephillips)

    As of v1.1.0 (just released), Favorites is multisite compatible. Additional (optional) parameters have been added to the template functions and shortcodes.

    RightBeatRadio

    (@rightbeatradio)

    Hi Kyle, I noticed you mentioned favorite counts being reset in drh192’s case.

    Will this affect our website as well or only in this case?

    Thanks

    Plugin Author Kyle Phillips

    (@kylephillips)

    Favorite counts (number of times a post has been favorited) shouldn’t be effected at all (not even in drh192’s case above).

    The code above alters the way logged-in users’ favorites are saved. Favorite “counts” are saved as post meta for the associated post.

    RightBeatRadio

    (@rightbeatradio)

    Cool thanks!

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

The topic ‘Multisite’ is closed to new replies.