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

switch_to_blog() - flag for missing subsequent restore_current_blog() #1987

Open
rebeccahum opened this issue Apr 15, 2021 · 0 comments
Open

Comments

@rebeccahum
Copy link
Contributor

Describe the solution you'd like

Sometimes difficult to determine logic bugs occur when switch_to_blog() is called without a subsequent restoration. It would be worth flagging to the user that restore_current_blog() should be called after (if not already) after switch_to_blog().

This should be reported:

function switch_blog() {
	$id = get_current_blog_id();

	if ( $id === 2 ) {
		return;
	}

	switch_to_blog( 2 );
}

This should not be reported:

function switch_blog() {
	$id = get_current_blog_id();

	if ( $id === 2 ) {
		return;
	}

	switch_to_blog( 2 );
	restore_current_blog();
}

Additional context (optional)

Automattic/VIP-Coding-Standards#651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants