get_post_to_edit()
云策文档标注
概述
get_post_to_edit() 是一个已弃用的 WordPress 函数,用于获取现有文章并格式化为编辑状态。自 WordPress 3.5.0 起,建议使用 get_post() 替代。
关键要点
- 函数已弃用:自 WordPress 3.5.0 版本起,get_post_to_edit() 被标记为弃用,应改用 get_post()。
- 功能替代:该函数内部调用 get_post() 并传递 'edit' 上下文参数,以获取适合编辑的文章数据。
- 参数要求:接受一个必需的整数参数 $id,表示文章 ID。
- 返回值:返回一个 WP_Post 对象,包含文章数据。
代码示例
function get_post_to_edit( $id ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'get_post()' );
return get_post( $id, OBJECT, 'edit' );
}注意事项
- 弃用警告:使用此函数会触发 _deprecated_function() 警告,建议在开发中避免使用,以保持代码兼容性和最佳实践。
- 版本历史:该函数在 WordPress 2.0.0 中引入,在 3.5.0 中被弃用。
原文内容
Gets an existing post and format it for editing.
Description
See also
Parameters
$idintrequired
Source
function get_post_to_edit( $id ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'get_post()' );
return get_post( $id, OBJECT, 'edit' );
}
Changelog
| Version | Description |
|---|---|
| 3.5.0 | Deprecated. Use get_post() |
| 2.0.0 | Introduced. |