I have developed a plugin for myself and was using it for a little and after decided to go public. But the plugin got declined after submission and code review with the reason ##Calling core loading files directly. I fixed already all issues they mentioned, but only one bothering me now. I have require_once( ABSPATH.'/wp-admin/includes/upgrade.php' );
in few places to use dbDelta(), but if I will remove require_once
declaration I won't be able to use dbDelta(). Do you think it will be an issue with second code review? Any developer who already did and released their plugins?
Wordpress自定义插件发布拒绝了“直接调用核心加载文件”的原因
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- doujie7346 2018-03-20 04:15关注
Short and simple:
It shouldn't be an issue.
Longer Answer:
dbDelta()
is a function that's kind of a special case, because the "core file" (upgrade.php) that defines it isn't always going to be loaded when it's needed by your plugin.If it's a simple query, you could probably just use a prepared statement with
$wpdb
. However ifdbDelta()
is indeed better for your needs (and it sounds like it is), it's absolutely okay to userequire_once
withupgrade.php
, despite it technically being a core file.Take a look at the official Creating Tables with Plugins codex page that literally tells you to go ahead and use it in this manner:
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql );
With the reasoning:
[...] we'll use the dbDelta function in wp-admin/includes/upgrade.php (we'll have to load this file, as it is not loaded by default) [...]
So,
require_once
away my friend!解决 无用评论 打赏 举报
悬赏问题
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料