wordpress本地开发_终极WordPress开发环境

wordpress本地开发

WordPress development has come a very long way in recent years when it comes to tooling. In the past, developing a WordPress website required some sort of MAMP/WAMP localhost setup and almost always, a rather painful headache. Maybe you’re even one of those developers who developed their website on a live environment – I was.

近年来,在工具方面,WordPress的开发已经走了很长一段路。 过去,开发WordPress网站需要某种MAMP / WAMP本地主机设置,而且几乎总是需要相当痛苦的头痛。 也许您甚至是在实时环境下开发其网站的那些开发人员之一-我曾经是。

Luckily, times have changed and there are now tools that help take the headache and repetitiveness out of building WordPress sites on your computer.

幸运的是,时代已经改变,现在有工具可以帮助您减轻在计算机上构建WordPress网站的麻烦和重复性。

wordpress本地开发_终极WordPress开发环境

In December last year, after 3 years of being almost completely devoid of any WordPress development, I became a full time WordPress developer again. Before that 3 year stint in the payments industry, I was a full time WordPress contractor.

去年12月,在几乎完全没有任何WordPress开发的3年之后,我再次成为了专职WordPress开发人员。 在支付行业工作了3年之前,我是一名全职WordPress承包商。

Being out of an industry for 3 years, gave me a unique perspective on how fast things change in computing and more specifically, web development. WordPress development is no exception.

离开该行业已有3年,这给了我关于计算领域(尤其是Web开发)如何快速变化的独特视角。 WordPress开发也不例外。

You see, when I returned to WordPress development in December last year, I decided to look at setting up the perfect WordPress development environment. I was pleasantly surprised to see that the tooling around WordPress had advanced so much that it was much like trading in a Ford for a Ferrari.

您会看到,去年12月重返WordPress开发时,我决定考虑建立一个完美的WordPress开发环境。 我惊讶地发现围绕WordPress的工具取得了如此巨大的进步,以至于就像用福特汽车换成法拉利一样。

I was excited, and still am of course, to explore all the tools and in today’s article I’m going to share with you a summary of what I have learned. Hopefully it will help you tweak your current environment and implement some of the tools that are available to you.

我很兴奋,而且当然仍然会探索所有工具,在今天的文章中,我将与您分享我所学到的摘要。 希望它将帮助您调整当前环境并实施一些可用的工具。

从服务器开始 (It Starts with the Server)

To begin with, the most important piece in the WordPress development environment puzzle is the server. Without a server, we can’t do anything.

首先,WordPress开发环境难题中最重要的部分是服务器。 没有服务器,我们将无能为力。

There are so many different options available today to host WordPress websites on your local environment that it gets tricky to know which one to use.

今天有很多不同的选项可以在您的本地环境中托管WordPress网站,以至于很难知道要使用哪个。

I’m going to suggest that you drop MAMP/WAMP/XAMP and start using a virtualized development environment.

我建议您删除MAMP / WAMP / XAMP并开始使用虚拟化开发环境。

Why? There are so many reasons:

为什么? 原因有很多:

  1. It’s an isolated environment. By using a virtualized environment you’re creating a development server that is isolated from your host operating system. You can install whatever operating system you like on the virtual machine and start/stop/restart it without affecting your host. It’s easy to tear down once you’re done with development and no longer need it.

    这是一个孤立的环境。 通过使用虚拟化环境,您正在创建与主机操作系统隔离的开发服务器。 您可以在虚拟机上安装所需的任何操作系统,然后启动/停止/重新启动它,而不会影响主机。 一旦完成开发并且不再需要它,很容易将其拆除。
  2. Messed something up? No problem! Just rebuild the environment. I’m sure we’ve all been in the sticky situation where we’ve tinkered with our server settings and blew stuff up. This is easily fixed by rebuilding the virtual environment or simply using snapshots. So now you can play around and tweak your settings without fear of failure.

    搞砸了吗? 没问题! 只是重建环境。 我敢肯定,我们都处在棘手的情况下,我们修改了服务器设置并炸了东西。 通过重建虚拟环境或仅使用快照即可轻松解决此问题。 因此,现在您可以进行游戏并调整设置,而不必担心失败。
  3. As close to live as you can get. You can literally replicate your live environment on your localhost if you wanted. Having these two environments exactly the same helps with debugging, tweaking and even deployment.

    尽可能地接近生活。 如果需要,您可以在本地主机上实际复制您的实时环境。 这两个环境完全相同有助于调试,调整甚至部署。
  4. You can run multiple different server environments, on a single computer. Have one client using Apache and another Nginx? No problem, create those two different environments in virtual machines and you’re good to go.

    您可以在一台计算机上运行多个不同的服务器环境。 是否有一个客户端使用Apache而另一个使用Nginx? 没问题,在虚拟机中创建这两个不同的环境,一切顺利。
  5. Unified environment across development teams. If everyone on a development team uses the exact same setup, it speeds up development time and there are less questions about why something is not working on x person’s machine.

    跨开发团队的统一环境。 如果开发团队中的每个人都使用完全相同的设置,那么它会加快开发时间,并且对为什么某人无法在xperson的计算机上正常工作提出了更少的疑问。

Now that you’re sold on a virtualized environment. What should you use?

现在您已在虚拟环境中出售。 你应该用什么?

I’m using VVV. For me it was extremely straight-forward to get up and running, has a good support system around and it is used by many of the big WordPress development agencies, including the one I work for, XWP.

我正在使用VVV 。 对我来说,启动和运行非常简单,并具有良好的支持系统,许多大型WordPress开发机构都使用了它,包括我所工作的XWP机构

Some of the other options for a virtualized WordPress development environment include: HGV, Wocker, VIP Quickstart.

虚拟化WordPress开发环境的其他一些选项包括: HGVWockerVIP Quickstart

If you decide to go with VVV, then I definitely recommend the following plugins and tools to take VVV to the next level of awesome.

如果您决定使用VVV,那么我绝对建议您使用以下插件和工具将VVV提升到一个新的高度。

  • vagrant-hostsupdater – This plugin allows your vagrant installation to update the entries in your computer’s hosts file for adding domain mappings to an IP address. This means you don’t have to manually add entries to your hosts file.

    vagrant-hostsupdater –此插件可让您的vagrant安装更新计算机的hosts文件中的条目,以将域映射添加到IP地址。 这意味着您不必手动将条目添加到主机文件。

  • Variable VVV – By far the most useful tool for VVV is called Variable VVV and what it does is gives you the ability to quickly and easily create new VVV WordPress installations using the command line. Definitely check this one out

    Variable VVV –到目前为止,VVV最有用的工具称为Variable VVV,它的作用是使您能够使用命令行快速轻松地创建新的VVV WordPress安装。 绝对检查一下

Aleksander Koko has previously written about VVV, and I’ve also recently recorded a video on how to setup VVV on your own computer.

Aleksander Koko 以前曾写过有关VVV的文章 ,最近我还录制了一段视频, 介绍如何在自己的计算机上设置VVV

命令行的力量 (The Power of the Command Line)

Who doesn’t like a bit of command line fu, right? WP-CLI is the answer to your inner command line desire.

谁不喜欢命令行命令行,对吗? WP-CLI是您内部命令行需求的答案。

wordpress本地开发_终极WordPress开发环境

WP-CLI let’s you manage a WordPress installation from the command line (it ships with VVV by the way).

WP-CLI让您从命令行管理WordPress安装(顺便说一下,它随VVV一起提供)。

Let’s look at some practical examples of how you can use WP-CLI in your local development environment.

让我们看一些实际示例,说明如何在本地开发环境中使用WP-CLI。

  • Install WordPress. SSH’d into your server and need to install WordPress quickly? Simply use WP-CLI to create a new WordPress installation.

    安装WordPress。 SSH已进入您的服务器,需要快速安装WordPress吗? 只需使用WP-CLI即可创建新的WordPress安装。
  • Update WordPress. There’s not much more painful than updating tons of WordPress websites by visiting each one, logging in, clicking around and then updating. You can do this straight from the command line with a single command.

    更新WordPress。 通过访问每个WordPress网站,登录,单击四周然后进行更新来更新大量WordPress网站,没有比这更痛苦的事情了。 您可以使用单个命令直接从命令行执行此操作。
  • Installing plugins. If you’ve found a great plugin that you want to install across multiple sites, again, do it with one command using WP-CLI.

    安装插件。 如果您找到了要在多个站点上安装的出色插件,请再次使用WP-CLI使用一个命令来完成。
  • Resetting a WordPress database. Messed something up and want to start off fresh? Easy, one command (this is getting a little repetitive isn’t it?)

    重置WordPress数据库。 搞砸了,想重新开始吗? 简单,一个命令(这有点重复了吗?)
  • Import content. Yep you guessed it, you can import content into your WordPress install or multiple installs with one command.

    导入内容。 是的,您可以猜到,您可以使用一个命令将内容导入WordPress安装或多个安装中。
  • And so much more

    还有更多

That’s all quite handy stuff that you can do from the command line. Best yet, in the next section we’ll talk about an IDE and you can run all these commands directly from that IDE.

您可以从命令行完成所有非常方便的工作。 最好的是,在下一节中,我们将讨论一个IDE,您可以直接从该IDE运行所有这些命令。

If you’re interested in learning more, check out this article on WP-CLI by Ahsan Parwez.

如果您想了解更多信息,请查看Ahsan Parwez撰写的有关WP-CLI的文章

发挥作用的IDE (An IDE That Makes a Difference)

Out of all the tools I am talking about today, I have a feeling that this is going to be the most contentious. When it comes to IDEs and editors it’s almost as if you’re invading personal space, and a lot of people don’t like that.

在我今天谈论的所有工具中,我感觉这将是最有争议的。 当涉及到IDE和编辑器时,几乎就像您要入侵个人空间一样,很多人都不喜欢。

I’m not going to try and tell you an IDE is better than a text editor or vice versa. What I’m going to do is tell you my experience of switching to an IDE and how it worked for me.

我不会尝试告诉您IDE优于文本编辑器,反之亦然。 我要做的是告诉您我切换到IDE的经验以及它对我的工作方式。

I have always been someone who has disliked IDEs. Dislike is probably being kind, I hated them. I felt they were bloated, slow and cluttered.

我一直都是不喜欢IDE的人。 我可能不喜欢我,因此讨厌他们。 我觉得他们were肿,缓慢而混乱。

I was a big Sublime Text fan (and still am by the way, I use it daily).

我是Sublime Text的忠实粉丝(顺便说一句,我每天都在使用它)。

So in December, as I was getting back into WordPress development, I checked out what editors were available to write WordPress code. I was quite surprised when an IDE by the name of PhpStorm kept getting a mention.

因此,在12月,当我重新开始WordPress开发时,我检查了哪些编辑器可用于编写WordPress代码。 当一个以PhpStorm为名的IDE不断被提及时,我感到非常惊讶。

Reluctantly, I took a look and boy am I glad that I did!

我很不情愿地看了一眼,男孩很高兴我做到了!

PhpStorm is the best IDE for PHP and WordPress development, in my opinion. It offers everything you need to build WordPress websites, plugins and themes all in one place and it has incredible WordPress integration (you really need to check it out).

我认为,PhpStorm是用于PHP和WordPress开发的最佳IDE。 它提供了在一个地方构建WordPress网站,插件和主题所需的一切,并且具有不可思议的WordPress集成(您确实需要检查一下)。

Here are three reasons why you should consider PhpStorm this year for WordPress development:

以下是您今年应考虑使用PhpStorm进行WordPress开发的三个原因:

  1. Everything you need, in one place. FTP – check, database support – check, terminal – check, version control – check, debugging – check, refactoring – check, great intellisense and autocomplete – double check! And so much more.

    您需要的一切都在一个地方。 FTP –检查,数据库支持–检查,终端–检查,版本控制–检查,调试–检查,重构–检查,出色的智能和自动完成–仔细检查! 还有更多。
  2. WordPress integration within PhpStorm is second to none. PhpStorm understands WordPress deeply. Once it’s hooked up to a WordPress project it knows how everything ties together. It autocompletes on WordPress functions and even on actions and filters.

    PhpStorm中的WordPress集成是首屈一指的。 PhpStorm深刻理解WordPress。 一旦连接到WordPress项目,它就会知道一切如何联系在一起。 它会自动完成WordPress功能,甚至是动作和过滤器。
  3. Many of the top WordPress developers and agencies are now developing their code with PhpStorm. That to me is a clear sign that it’s one of the best IDEs for WordPress development available.

    许多*WordPress开发人员和代理机构现在都在使用PhpStorm开发其代码。 对我来说,这是一个明确的信号,它是可用于WordPress开发的最佳IDE之一。

If you’re interested in getting started with PhpStorm, then check out a series of 7 PhpStorm videos that I recorded to get your started with the IDE.

如果您有兴趣开始使用PhpStorm,请查看我录制的一系列7个PhpStorm视频 ,以开始使用IDE。

确保您的代码如丝般干净 (Making Sure Your Code Is Silky Clean)

The last tool that I am going to write about today is a doozy! I’m particularly pedantic when it comes to writing code. I like it to be silky clean and follow the WordPress coding standards to a tee.

我今天要写的最后一个工具是傻瓜! 在编写代码时,我特别着迷。 我喜欢它柔滑干净并且遵循WordPress编码标准。

But even being that pedantic, we’re all humans. And very often I find myself going through the code that I have written and cringing about a missed space or extra new line.

但是即使是那种学究的人,我们都是人类。 很多时候,我发现自己遍历了我编写的代码,并对丢失的空间或多余的新行感到恐惧。

Being in the Open Source world, it’s extremely important that developers stick to coding standards that are defined by the projects otherwise a codebase degrades extremely quickly, especially on a popular Open Source project like WordPress.

在开源世界中,开发人员必须坚持由项目定义的编码标准,否则代码库会Swift降级,尤其是在流行的开源项目(如WordPress)上,这非常重要。

In fact, the WordPress core team is particularly strict about coding standards and that they’re followed.

实际上,WordPress核心团队对编码标准特别严格,并且必须遵守。

So how can we make sure that our code follows the WordPress coding standards? The answer is simple and it is a tool called PHP CodeSniffer with the WordPress coding standards ruleset.

那么我们如何确保我们的代码遵循WordPress编码标准? 答案很简单,它是一个带有WordPress编码标准规则集的名为PHP CodeSniffer的工具。

wordpress本地开发_终极WordPress开发环境

These two utilities will scan your code, find any discrepancies between your code and how it is expected to be written by the WordPress project and inform you of what is wrong. Magic!

这两个实用程序将扫描您的代码,查找您的代码与WordPress项目应如何编写的代码之间的任何差异,并告知您出了什么问题。 魔法!

Best of all, they will also notify you of any high level security issues that it encounters. Now it won’t catch every single security issue so make sure you’re always thinking about security when you’re writing your code but it is a good first line of defense.

最重要的是,他们还将在遇到任何高级安全问题时通知您。 现在它不会解决每个安全问题,因此请确保在编写代码时始终考虑安全性,但这是很好的第一道防线。

Of course, I wouldn’t be able to complete this section without mentioning that PhpStorm has baked in support for PHP CodeSniffer. I’ve released a video on how to tie PhpStorm, PHPCS and the WordPress coding standards ruleset together.

当然,如果不提到PhpStorm已经支持PHP CodeSniffer,就无法完成本节。 我已经发布了有关如何将PhpStorm,PHPCS和WordPress编码标准规则集结合在一起的视频。

收盘时 (In Closing)

There are many alternatives to the tools above and my hope is that at the very least everything I have spoken about today gets you interested in exploring some of the awesome tooling around WordPress development.

上面的工具有很多替代品,我希望至少我今天所说的所有内容都使您有兴趣探索一些有关WordPress开发的出色工具。

The above tools, should you chose to use them, will give you a great foundation for getting started with a more streamlined and automated approached to WordPress development.

如果您选择使用上述工具,它们将为您入门,为使用更简化和更自动化的WordPress开发方法打下坚实的基础。

If you have other tools that you use, I would love to hear about them in the comments below!

如果您还有其他工具在使用,请在下面的评论中了解它们!

翻译自: https://www.sitepoint.com/ultimate-wordpress-development-environment/

wordpress本地开发