Automattic / Automattic/VIP-Coding-Standards

switch_to_blog() - flag for missing subsequent restore_current_blog()

Open
#651 3 comments 0 reactions 0 assignees View on GitHub
Type: Enhancement
Dominant language
PHP
Stars
261
Forks
44
Avg merge
19m
Merged PRs (30d)
1

Description

## Describe the solution you'd like

From https://github.com/Automattic/VIP-Coding-Standards/pull/649#discussion_r606174833, it would be worth flagging that `restore_current_blog()` should be called subsequently (if not already).

## What code should be reported as a violation?

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

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

switch_to_blog( 2 );
}
```

## What code should *not* be reported as a violation?

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

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

switch_to_blog( 2 );
restore_current_blog();
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.