Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error due to missing switch_to_blog() function when switching from multisite to single site #221

Closed
1 task done
ocean90 opened this issue Jul 18, 2023 · 0 comments · Fixed by #222
Closed
1 task done
Assignees
Labels
type:bug Something isn’t working.
Milestone

Comments

@ocean90
Copy link
Contributor

ocean90 commented Jul 18, 2023

Describe the bug

When the plugin is used on a multisite an option to share avatars is available. This is used in

public function is_avatar_shared() {
if (
is_multisite() // Are we on multisite.
&& ! isset( $this->options['shared'] ) // And our shared option doesn't exist.
|| (
isset( $this->options['shared'] ) // Or our shared option is set.
&& 1 === $this->options['shared']
)
) {
return true;
}
return false;
}

But this check will also return true in a single site installation when the option still exists. This will cause a fatal error because switch_to_blog() doesn't exist.

if ( $this->is_avatar_shared() ) {
$origin_blog_id = isset( $local_avatars['blog_id'] ) && ! empty( $local_avatars['blog_id'] ) ? $local_avatars['blog_id'] : get_main_site_id();
switch_to_blog( $origin_blog_id );
}

Steps to Reproduce

  1. Create a multisite
  2. Activate plugin, change plugin settings
  3. Upload custom avatars
  4. Convert the site back to a single site
  5. Go to a screen like Users where the custom avatars are rendered
  6. Notice the fatal error

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ocean90 ocean90 added the type:bug Something isn’t working. label Jul 18, 2023
@vikrampm1 vikrampm1 moved this from Incoming to To Do in Open Source Practice Jul 18, 2023
@ravinderk ravinderk moved this from To Do to Review Approved in Open Source Practice Jul 19, 2023
@github-project-automation github-project-automation bot moved this from Review Approved to Merged in Open Source Practice Aug 3, 2023
@jeffpaul jeffpaul added this to the 2.7.6 milestone Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn’t working.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants