Independent Development
How to solve problems as soon as possible?
There are countless problems, even in a tiny project.
They all can be resolved— but what did it cost?
If possible, the most effective way to deal with them, is to try to find a way to dodge them.
The prefix of multiple sites in WordPress
Error
While the plugin was initialized, a serial of tables were created, with the name of $wpdb->prefix.
It works well in a single WordPress site, and the value used to be wp_.
But if it was a multiple website, the prefix are different among the sites. The main site might get the prefix of wp_, but the child sites might get the prefix like wp_2_.
Solution
There is a way to check if the plugin was running in which site, and try to deal with it.
But it is kind of complex.
So I just simply changed all the $wpdb->prefix into $wpdb->base_prefix.
At least it works for me now, because my site was so tiny.
Related Platforms
(Github Issues) / (Notion) / (Blog)
Advertisement
(A website to optimize your resume and to boost your career: Nonpareil.me)
独立开发
如何快速解决问题
即使做个小项目,也是各种问题不断。
当然都能解决,可是成本,尤其是时间成本太高了。
所以如果有可能,最有效率的做法,是找一个办法绕开这些问题。
WordPress中启用多站点时的前缀问题
问题
我有一个插件,初始化时会寻一系列的表格。表格的名字里都有$wpdb->prefix作为前缀。
在单站点页面上没问题,一般来说这个前缀都是wp_。
但是对于多站点来说就不行了。可能主站是wp_,子站的前缀一般是wp_2_这种格式。
解决方案
当然是有一种方法可以让插件自行判断当前是在给哪个站点工作,不过有些复杂。
所以我就简单粗暴地把$wpdb->prefix都换成了$wpdb->base_prefix。
因为我的站点很小,还在起步阶段,所以没有问题。
相关平台
(Github Issues) / (Notion) / (Blog)