Automattic / Automattic/VIP-Coding-Standards

switch_to_blog() - flag for missing subsequent restore_current_blog()

未关闭
#651 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Type: Enhancement
主要语言
PHP
星标
261
派生
44
平均合并
19 分钟
30 天内合并 PR
1

描述

## 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();
}
```

贡献指南

打开贡献指南

调研方向

找到处理 switch_to_blog() 的现有规则或 sniff,然后检查它如何确定一次调用是否成对。为 issue 中的两个示例添加覆盖:报告没有后续 restore_current_blog() 的 switch,不要报告已恢复的情况。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
tooling
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。