函数文档

post_form_autocomplete_off()

💡 云策文档标注

概述

post_form_autocomplete_off() 是一个已弃用的 WordPress 函数,用于在 WebKit 浏览器(如 Safari 和 Chrome)的添加/编辑文章表单中禁用自动完成功能,以防止编辑器在使用浏览器后退按钮时出现问题。

关键要点

  • 该函数在 WordPress 4.6.0 版本中被弃用,建议使用 wp_page_reload_on_back_button_js() 替代。
  • 它仅针对 Safari 和 Chrome 浏览器输出 autocomplete="off" 属性,以解决这些浏览器忽略编辑器文本区域自动完成设置的问题。
  • 弃用原因是为了修复编辑器在用户使用浏览器后退按钮导航时可能崩溃的问题,相关讨论见 #28037。

代码示例

function post_form_autocomplete_off() {
	global $is_safari, $is_chrome;

	_deprecated_function( __FUNCTION__, '4.6.0' );

	if ( $is_safari || $is_chrome ) {
		echo ' autocomplete="off"';
	}
}

注意事项

  • 开发者应避免在新代码中使用此函数,转而使用 wp_page_reload_on_back_button_js() 来确保兼容性和修复问题。
  • 该函数仅适用于 WebKit 浏览器,其他浏览器不受影响。

📄 原文内容

Disables autocomplete on the ‘post’ form (Add/Edit Post screens) for WebKit browsers, as they disregard the autocomplete setting on the editor textarea. That can break the editor when the user navigates to it with the browser’s Back button. See #28037

Description

Replaced with wp_page_reload_on_back_button_js() that also fixes this problem.

Source

function post_form_autocomplete_off() {
	global $is_safari, $is_chrome;

	_deprecated_function( __FUNCTION__, '4.6.0' );

	if ( $is_safari || $is_chrome ) {
		echo ' autocomplete="off"';
	}
}

Changelog

Version Description
4.6.0 Deprecated.
4.0.0 Introduced.