Editor stylesheet is loaded on `enqueue_block_editor_assets`; WordPress warns "fork-editor-css was added to the iframe incorrectly"

未关闭 适合新手
#120 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
css, php, wordpress
领域
frontend

调研方向

从 inc/Core.php 中第 107 行附近的 add_editor_styles() 方法开始,该方法会在 enqueue_block_editor_assets 上入队 assets/css/build/editor.css;也请阅读 setup(),其中声明了对 editor-styles 的支持。在以下两种做法中选择:用 add_editor_style() 注册样式表,或将入队操作移到带管理员检查的 enqueue_block_assets,同时留意 RTL 文件。完成意味着在开启 SCRIPT_DEBUG 时控制台警告消失,并且编辑器的画布在标题、按钮、引用、搜索和最新文章方面仍与前端一致。

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

描述

What's wrong

Every time the post editor or the Site Editor opens, with SCRIPT_DEBUG on, the browser console shows:

fork-editor-css was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.

Today WordPress still copies the stylesheet into the editor iframe, so Fork's editor styling works. The warning means that copying is a compatibility fallback. If WordPress removes it, the editor canvas loses Fork's editor styles (fonts, buttons, latest posts and the rest of assets/css/build/editor.css).

Cause

inc/Core.php enqueues the editor stylesheet with wp_enqueue_style() on enqueue_block_editor_assets (add_editor_styles(), line 107). That hook is meant for the editor's own UI, outside the iframe.

Steps to reproduce
  1. On a site with SCRIPT_DEBUG on and Fork active, open any page in the editor, or open Appearance → Editor.
  2. Open the browser console.

Expected: no warning about fork-editor-css.
Actual: the warning above, once per editor load. Seen on WordPress 6.7.12, 6.8, 7.1.5 and 7.2-RC2.

Suggested fix

Either:

  • register it as an editor style: add_editor_style( 'assets/css/build/editor.css' ) in setup() (Fork already declares add_theme_support( 'editor-styles' )), keeping the RTL file in mind; or
  • enqueue it on enqueue_block_assets with an is_admin() check, so it goes into the iframe the supported way.

Afterwards, check that the editor canvas still matches the front end (headings, list items, table cells, quotes, buttons, search and latest posts).

主要语言
PHP
星标
0
派生
0
平均合并
1 小时 2 分钟
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Codeinwp/fork 的其他 Issue

查看 Codeinwp/fork 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

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