Forum Replies Created

Viewing 15 replies - 61 through 75 (of 202 total)
  • Ignore previous post. jjones7 made his own custom user_can_for_blog. Combined with the1path’s code I think this works for my case:

    function user_can_for_blog($user_id, $blog_id, $capability ) {
    
            $user = new WP_User( $user_id) ;
            $user->for_blog( $blog_id );
            $args = array_slice( func_get_args(), 2 );
            $args = array_merge( array( $capability ), $args );
            return call_user_func_array( array( &$user, 'has_cap' ), $args );
           }
    
    $user_id = $curauth->ID;
    $key = 'primary_blog';
    $single = true;
    $primary_blog = get_user_meta( $user_id, $key, $single);
    
    if ($primary_blog == "") {
    echo '<p>No site yet</p>';
    } else if (user_can_for_blog($user_id, $primary_blog, edit_posts )) {
    echo '<p>Member has site</p>';
    } else {
    echo '<p>No site yet</p>';
    }

    Got things very confused. Spending too long on this…

    Any suggestions to tighten this up further? What is the primary_blog anyway?

    What is the primary_blog? There’s nothing about it in the codex.

    A solution here relies on it.

    There is a user_can_for_blog() patch.

    Looks like this:

    function user_can_for_blog( $user, $blog_id, $capability) {
    	if ( ! is_object( $user ) )
    	$user = new WP_User( $user );
    
    	if ( ! $user || ! $user->ID )
    	return false;
    
    // Set the blog id.  @todo add blog id arg to WP_User constructor?
    	$user->for_blog( $blog_id );
    
    	$args = array_slice( func_get_args(), 3 );
    	die(print_r($args));
    	$args = array_merge( array( $capability ), $args );
    
    	return call_user_func_array( array( &$user, 'has_cap' ), $args );
    }

    But if I add that to author.php with the previous code, I get:

    Array ( ) 1

    user_can probably assumes we want to know the user’s capabilities for the main blog or blog ID 1.

    Stuck…

    This produces several syntax errors:

    $user_blogs = get_blogs_of_user( $user_id ));
    if !$user_blogs {
    echo 'User has no blog';
    }
    else {
    echo 'User has a blog';
    }

    unexpected ‘)’ and ‘!’.

    It also still does not check if the user it the Administrator/Owner of a blog. This would still say the ‘User has a blog’ if he is only a Subscriber.

    Where would you get that $blog_id to do the second check? Is there no way to check if a user is Admin anywhere?

    Is there any way to incorporate a user_can_for_blog() check in the1path’s solution? Is $primary_blog the $blog_id?

    This works without server errors:

    $user_id = $curauth->ID;
    $key = 'primary_blog';
    $single = true;
    $primary_blog = get_user_meta( $user_id, $key, $single);
    
    if ($primary_blog == "") {
    echo '<p>No site yet</p>';
    } else if (user_can( $user_id, edit_posts )) {
    echo '<p>Member has site</p>';
    }

    But ‘Member has site’ only shows up for super admins. Nothing is echoed for regular members who definitely have sites.

    Based on jjones7’s suggestions this could work:

    $user_id = $curauth->ID;
    $key = 'primary_blog';
    $single = true;
    $primary_blog = get_user_meta( $user_id, $key, $single);
    
    if ($primary_blog == "") {
    echo '<p>No site yet</p>';
    } else if (user_can_for_blog($user_id, $primary_blog, edit_posts )) {
    echo '<p>Member has site</p>';
    }

    But user_can_for_blog() is an ‘undefined function’.

    So that user_can check does not work. Any alternatives?

    jjones7, thanks for the suggestion, but I have no clue what is going on in your code. the1path’s code looks a lot simpler.

    Why does subscribing to someone else’s blog count as having a primary_blog? What is the point of having a key like that if it is not restricted to the user’s own blogs?

    Is there any way to incorporate user_can() into the1path’s code? Would ‘user can not’ be like this, like regular PHP:

    !user_can( $user, $capability )

    And then just use a random Administrator capability, like activate_plugins or manage_options?

    jjones7, what would $capability be in your code?

    This produces a server error (‘unexpected T_ELSE’):

    $user_id = $curauth->ID;
    $key = 'primary_blog';
    $single = true;
    $primary_blog = get_user_meta( $user_id, $key, $single);
    
    if ($primary_blog == "") {
    echo '<p>No site yet</p>';
    } else if (!user_can( $user_id, manage_options )) {
    echo '<p>No site yet</p>';
    else {
    echo '<p>Member has site</p>';
    }

    This causes the same error:

    if (!user_can( $user_id, manage_options )) {
    echo '<p>No site yet</p>';
    else {
    echo '<p>Member has site</p>';
    }

    So I guess !user_can( $user_id, manage_options ) is wrong.

    Can someone please help me figure out the right syntax etc?

    One issue with the1path’s code; it still doesn’t check if the user is the administrator of the primary blog.

    Even if the user is only a subscriber on someone else’s blog, the code will still show ‘Member has site’.

    So for my case I have to add a check AND is not Administrator to this condition:

    if ($primary_blog == "")

    How can I do that? Probably something with user_can()?

    Searching for solution. Will report back…

    The best way of checking who the site owner is of a specific site …

    That is not what the1path is trying to do!

    He/she wanted to check if a user has a blog. I have been looking for the same thing.

    The code the1path provided works great. Thanks for posting!

    I put this in my author.php:

    $user_id = $curauth->ID;
    $key = 'primary_blog';
    $single = true;
    $primary_blog = get_user_meta( $user_id, $key, $single);
    
    if ($primary_blog == "") {?>
                        <p>No site yet</p>
              <?php } else { ?>
                   	<p>Member has site</p>
    <?php
    }

    $user_id depends on your specific case, but this seems like a pretty straightforward, solid solution.

    Is it? Am I missing something? Is there a more standard way to do this?

    but I dont think its that pretty

    Seems to do exactly what I needed with only a few lines!

    Found this somewhere:

    add_filter('author_link', 'no_author_base', 1000, 2);
    function no_author_base($link, $author_id) {
        $link_base = trailingslashit(get_option('home'));
        $link = preg_replace("|^{$link_base}author/|", '', $link);
        return $link_base . $link;
    }

    Doesn’t seem to do anything in my site – my old /profile/… slug keeps working after replacing the filter – so provided here for comments etc.

    I have three multisite installations with the exact same theme. get_avatar() works great in two of them, but shows nothing in the third.

    You can easily test if your code can find the correct email or user_id, by just doing echo get_the_author_meta(‘user_email’) etc.

    In my installation that is not the problem. There really seems to be something weird going on with get_avatar().

    Stuck as well. Anyone else have any ideas?

    I don’t see any error files on the server with more clues. get_avatar() works on other pages in the same installation.

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    Thanks Mika Epstein!

    (wp-signup.php is by-passed in my theme, but now I know where to find the code to reintegrate in my process.)

    @circlecube, I’m trying to figure this out as well.

    I suspect it doesn’t work because ID is defined differently in the plugin and in the front-end profile edit page – in my case at least.

    My front-end template file has $current_user->id, the plugin has $user_id. Should I replace those? Or replace $profileuser?

    By changing that in certain places you can make a back-end uploaded avatar show up in the front-end, but I still can’t make front-end upload work.

    I think adding the code that pekmez gave by itself won’t work anyway. Don’t you also need some PHP at the top of the template that processes the input?

    I only have a very vague idea what I’m doing. Can anyone point me in the right direction?

    No, basic functionality like this that every user will expect is in Automattic’s view still the domain of half-baked plugins that break with every new release.

    Automattic meanwhile focuses on adding more Ajax to admin bars in the back-end and other super important priorities. Code is poetry! WordPress is not for actual use in the real world.

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    Thanks!

    > Sort of interesting that multisite can’t cope more gracefully…

    MultiSite is designed for blog farms; completely separate blogs side by side. To do anything useful with it, like a community hub for an organization or company, you have to restructure the whole thing.

    Edit:

    The solution still doesn’t work for another site that has the default wp_ prefix. Ugh… Some obscure WP bug again? Will have to keep it hardcoded there.

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    Yes, this is for multisite. The $blog variable stands for different blogs on the network, so default wp shortcuts are useless in this case.

    $wpdb->prefix would probably work if I could figure out the right php syntax, the right combination of dots and apostrophes or whatever.

    That is just basic PHP, so if anyone has a clue, please share.

    Thread Starter Modifiedcontent

    (@modifiedcontent)

    Thanks s_ha_dum (was aplijdi)!

    This works in one site, but not in another that has the regular wp_ prefix:

    $blogPostsTable = $wpdb->prefix.''.$blog.'_posts';

    The syntax is probably wrong. What would be the correct way?

Viewing 15 replies - 61 through 75 (of 202 total)