如何保护自己的PHP代码免受WordPress更新的影响

时间:2015-07-26 作者:nokul

我已经写了几个自己的短代码脚本,我把它们放在短代码中。php文件。我的Wordpress安装设置为自动更新到新的Wordpress版本,这是一件好事。

但是Wordpress的更新不断覆盖短代码。php文件,所以每次更新后我都必须手动添加我的短代码php代码(我可能会离开几天左右)。

对于不会被覆盖的短代码,哪一个是放置PHP代码的首选位置?

谢天谢地,好的

1 个回复
最合适的回答,由SO网友:Pieter Goosen 整理而成

NEVER EVER alter any template or file in a theme or plugin that you did not author, and this goes for any core file as well. There is no way to protect the code that you alter or add in any of those files, except maybe changing file permissions, but then again, you will run into other issues

ALL customizations should and must be made in either a child theme or a custom plugin. Code like shortcodes as in your question must always go into a custom made plugin as shortcodes add functionality to your site and not your theme.

You should definitely go and read the following post

This is one of the most important things that you need to consider when customizing anything for a site

结束

相关推荐

什么可能导致对wp-admin/async-pload.php的POST返回JSON>和<Html?

在“媒体”选项卡中,上载有效的图像文件会显示“HTTP错误”。不过,重新加载“媒体”选项卡显示图像确实上载并调整了大小。浏览器调试工具显示,在上载时,浏览器正在向wp admin/async upload发送帖子。php。服务器响应500错误。不过,回应的主体是可疑的。第一部分是JSON结构。JSON结构后面紧跟着一个标题为“Wordpress Error”但正文为空的HTML文档。进入webserver(apache)错误日志和WP调试模式以及增加的PHP错误/警告详细程度都没有帮助。禁用所有插件对错误