SuperAPI AI 工具集

wordpress-core

编程与开发

查看项目

更新于 10-16 01:15

技能介绍

用途:提供 WordPress 插件开发的基础知识与标准模式,聚焦文件结构、安全实践与常用 API,适用于从零编写或维护插件、需要遵循官方规范的开发者。

主要能力: 一、插件结构。标准目录含主插件文件、uninstall.php、includes、admin、public、languages;主文件只放头部与初始化,分离前后台功能,使用类组织代码。主文件头部必须含 Plugin Name,建议补充 Description、Version、Author、License、Text Domain,并阻止直接文件访问。 二、安全模式。输入清理(sanitize_text_field、sanitize_email、sanitize_key、sanitize_title、esc_url_raw、absint、intval);输出转义(esc_html、esc_attr、esc_url、esc_js、esc_textarea、wp_kses_post);nonce(wp_nonce_field、wp_verify_nonce、wp_nonce_url);权限检查(current_user_can、wp_die)。 三、钩子系统。action 用 add_action、do_action;filter 用 add_filter、apply_filters,支持优先级与参数数量。 四、数据库。通过全局 $wpdb 执行查询,必须使用 $wpdb->prepare(),占位符 %s、%d、%f;插入、更新、删除用 $wpdb->insert/update/delete;自定义表使用 $wpdb->prefix。 五、编码标准。函数小写加下划线、类名首字母大写加下划线、常量全大写、文件小写连字符、制表符缩进、Yoda 条件。 六、常用辅助函数:plugin_dir_path/url、plugin_basename、get_option/update_option/delete_option、post meta 系列、transient 缓存系列。

使用方式:作为开发技能参考,在编写插件时按上述模式组织代码与处理数据流;进阶内容见 references 下 security-patterns.md、hooks-api.md、database-patterns.md。相关技能为 wordpress-blocks 与 wordpress-modern。

限制:资料针对 WordPress 6.8+,未提供具体版本兼容范围、性能指标或收费信息。