如何确保在插件更新时不会丢失对 Wordpress 插件的更改? [英] How to make sure changes to a Wordpress plugin won't be lost on plugin update?

查看:28
本文介绍了如何确保在插件更新时不会丢失对 Wordpress 插件的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很确定我在某处读到过,您实际上可以将主插件 *.php 文件移动到其他地方(我假设在您的主题目录下)以确保安全,以防您对它和您的插件进行更改更新.我试过谷歌,但我找不到任何东西.具有良好结果的 Google 页面就足够了.

I'm pretty sure I've read somewhere that you can actually move the main plugin *.php file to somewhere else (I assume under your theme directory) to have it safe in case you made changes to it and your plugin updates. I tried Google but I can't find anything. Google page with good results will suffice.

我刚刚经历过这样一种情况,我的 2 个插件的布局发生了变化并满足了我的需求,我想确保它不会再次发生.除了将主文件放在另一个位置之外,还有什么方法可以同时移动任何 CSS 和 JS 文件?

I've just experienced a situation where my 2 plugins which had its layout changed and accommodated my needs and I want to make sure it doesn't happen again. Apart from having the main file in another location, is there a way to move along any CSS and JS files as well?

在 Concrete5 CMS 中,有一种很好的方法可以做到这一点,通过在插件块(可以视为 WP 插件)中创建一个新文件夹,您可以在其中创建主文件、任何 CSS 和JS 文件,然后您可以简单地编辑它们并为您正在使用该块的页面位置选择该模板.

In Concrete5 CMS there is a nice way of doing this, by creating a new folder inside a block of an addon (may be regarded as a WP plugin), inside of which you can create copies of main file, any CSS and JS files and then you can simply edit them and choose that template for a page location you are using that block in.

我认为 Wordpress 中没有这样的东西,但我能接近多远?

I assume there is no such thing in Wordpress but how close can I get?

更新:我发现我在哪里应用了该建议来创建文件的新实例,然后将其移动到主题目录.有问题的插件是 HL-Twitter.这些是插件文件:

UPDATE: I found where I applied that advice on creating a new instance of the file then moving it to the theme directory. The plugin in question was HL-Twitter. These are the plugin files:

admin.php
archive.php
functions.php
hl_twitter.php
hl_twitter_archive.php
hl_twitter_widget.php
import.php
widget.php

现在,这是 hl_twitter_widget.php 的顶级内容(注释掉):

Now, this is the top contents (commented out) of the hl_twitter_widget.php:

Widget Theme for HL Twitter
To change this theme, copy hl_twitter_widget.php
to your current theme folder, do not edit this
file directly.

Available Properties:
$before_widget
$after_widget
$before_title
$after_title
$widget_title
$show_avatars
$show_powered_by
$num_tweets: how many tweets to show
$tweets: array of $tweet
$tweet: object representing a tweet
$tweet->twitter_tweet_id
$tweet->tweet
$tweet->lat
$tweet->lon
$tweet->created
$tweet->reply_tweet_id
$tweet->reply_screen_name
$tweet->source
$tweet->screen_name
$tweet->name
$tweet->avatar
$user: represents the Twitter user (ONLY SET IF SHOWING A SINGLE USERS TWEETS!)
$user->twitter_user_id
$user->screen_name
$user->name
$user->num_friends
$user->num_followers
$user->num_tweets
$user->registered
$user->url
$user->description
$user->location
$user->avatar       

所以我复制主文件(在本例中为 hl_twitter.php)是错误的,但仍然 - 这使我能够在插件目录外编辑文件,系统以某种方式检查它的存在并在存在时将其拾取.如果此行为是 Wordpress 原生支持的,或者已集成到插件本身中?

So I was wrong about copying the main file (in this case hl_twitter.php), but still - this enabled me to edit the file outside the plugin directory and the system somehow checks for its existence and picks it up if exists. If this behavior something that is natively supported by Wordpress or it has been integrated in the plugin itself?

推荐答案

对于主题,Wordpress 有一个子主题"的概念,它允许:将更改与主主题分开,以防发生更改.

With themes, Wordpress has a concept of "child themes" which allows exactly that: to keep changes separate from main theme, in case it changes.

我还没有找到用插件来做到这一点的方法.

I haven't yet found a way to do this with plugins.

我自己使用了一些策略:

I'm using a few tactics myself:

  • 我将插件版本提高到非常高的数字,例如 99.9.这样 Wordpress 将永远不会更新插件.
  • 将我的插件存储在版本控制中(我使用 git,但这并不重要),这允许您更新插件,运行 'diff' 工具并查看发生了什么变化.如果你不喜欢你就回复,就像你写的代码不好一样.但这种方法需要一点技巧.

这篇关于如何确保在插件更新时不会丢失对 Wordpress 插件的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆