WordPress实际上是如何在幕后工作的(Infographic)

Have you ever wondered how WordPress actually works behind the scenes? For most users, it seems simple because you type a URL and a page loads in few seconds, but there is a lot that happens behind the scenes. In this guide, we will walk you through how WordPress actually works behind the scenes, and we have created an easy to follow infographic as well.

您是否想过WordPress在幕后的实际运作方式? 对于大多数用户来说,这似乎很简单,因为您键入URL并在几秒钟内加载了页面,但是幕后发生了很多事情。 在本指南中,我们将引导您逐步了解WordPress在幕后的实际工作方式,并且我们还创建了易于遵循的信息图。

How WordPress Works Behind the Scenes
为什么要学习WordPress如何工作? (Why You Should Learn How WordPress Works?)

WordPress is an open source software, which means any one can study its code and write their own apps (plugins) and templates (themes) for it.

WordPress是一种开源软件,这意味着任何人都可以研究其代码并为其编写自己的应用程序(插件)和模板(主题)。

Learning how WordPress works and what goes on behind the scenes can help you understand what you can do with it. You can learn about improving WordPress performance and write better code for your own projects.

了解WordPress的工作原理以及幕后发生的事情可以帮助您理解WordPress可以做什么。 您可以了解有关提高WordPress性能的知识,并为自己的项目编写更好的代码。

This guide will walk you through the whole process step by step. We will start from when a user requests a page and end when that page is fully loaded.

本指南将逐步引导您完成整个过程。 我们将从用户请求页面开始,直到该页面完全加载为止。

Ready? Let’s get started.

准备? 让我们开始吧。

Click to View the Behind the Scenes WordPress Infographic

You can also follow our written tutorial below for more details.

您也可以按照下面的书面教程了解更多详细信息。

1.加载wp-config.php文件 (1. Load wp-config.php File)

The wp-config.php is the WordPress configuration file. It sets global variables for a WordPress site and contains your WordPress database information. This is the first file WordPress loads for obvious reasons. Learn more about wp-config.php file and how to edit it.

wp-config.php是WordPress配置文件。 它为WordPress网站设置全局变量,并包含您的WordPress数据库信息。 这是WordPress加载的第一个文件,原因很明显。 了解有关wp-config.php文件以及如何编辑它的更多信息

2.设置默认常量 (2. Setup Default Constants)

After loading wp-config.php file, WordPress will move on to set default constants. This includes information like default WordPress upload location, maximum file sizes, and other default constants set in wp-config.php file.

加载wp-config.php文件后,WordPress将继续设置默认常量。 其中包括诸如默认WordPress上传位置最大文件大小以及wp-config.php文件中设置的其他默认常量之类的信息。

3.加载advanced-cache.php文件 (3. Load advanced-cache.php File )

If advanced-cache.php file exists on your site, then WordPress will load it next. This file acts as a drop-in file and is used by several popular plugins particularly WordPress caching plugins. If your site is using this file, then you will see a new item on the plugins screen called Drop-ins.

如果您的站点上存在advanced-cache.php文件,则WordPress将在接下来加载该文件。 该文件充当一个插入文件,并由几个流行的插件(尤其是WordPress缓存插件)使用。 如果您的站点正在使用此文件,那么您将在插件屏幕上看到一个名为Drop-ins的新项目。

advanced-cache.php file appearing as drop-in
4.加载wp-content / db.php文件 (4. Load wp-content/db.php File)

WordPress allows developers to create their own database abstraction layers and load them in a db.php file placed inside the wp-content folder. It is commonly used by WordPress caching plugins to improve database performance. If your website has this file present, then WordPress will load it.

WordPress允许开发人员创建自己的数据库抽象层,并将其加载到wp-content文件夹中的db.php文件中。 WordPress缓存插件通常使用它来提高数据库性能。 如果您的网站上存在此文件,则WordPress将加载它。

5.连接MySQL并选择数据库 (5. Connect MySQL and Select Database)

WordPress now have enough information to proceed further. It will move on to connect to the MySQL server and select the database.

WordPress现在有足够的信息来进一步进行操作。 它将继续连接到MySQL服务器并选择数据库。

If WordPress is unable to connect to the database, then you will see the “Error establishing database connection” error and WordPress will quit right here.

如果WordPress无法连接到数据库,则您将看到“ 建立数据库连接错误”错误,并且WordPress将在此处退出。

If everything works fine, then it will move on to next steps.

如果一切正常,那么它将继续进行下一步。

6.加载object-cache.php或wp-includes / cache.php文件 (6. Load object-cache.php or wp-includes/cache.php File)

WordPress will now look for object-cache.php file. If it doesn’t exist, then WordPress will move on to load wp-includes/cache.php file.

WordPress现在将查找object-cache.php文件。 如果不存在,则WordPress将继续加载wp-includes / cache.php文件。

7.加载wp-content / sunrise.php文件 (7. Load wp-content/sunrise.php File)

If it is a multisite network, then WordPress will now look for sunrise.php file if it exists in the wp-content folder.

如果它是一个多站点网络 ,则WordPress现在将查找wp-content文件夹中的Sunrise.php文件。

8.加载本地化库 (8. Load Localization Library)

WordPress will now load l10n.php library in the wp-includes folder. This file loads WordPress localization system, loads translations, sets locales, etc. See our guide on how to use WordPress in other languages.

WordPress现在将在wp-includes文件夹中加载l10n.php库。 此文件加载WordPress本地化系统,加载翻译,设置语言环境等。请参阅我们的指南, 了解如何以其他语言使用WordPress

9.加载多站点插件 (9. Load Multisite Plugins)

If it is a multisite network, then WordPress will now load the multisite plugins. Learn more about how plugins work on WordPress multisite network.

如果是多站点网络,那么WordPress现在将加载多站点插件。 了解有关插件如何在WordPress多站点网络上工作的更多信息。

Network activated plugins
10.做动作'muplugins_loaded' (10. Do Action ‘muplugins_loaded’)

The action muplugins_loaded is now run by WordPress. This action is available only to network activated plugins on a WordPress multisite.

行动 muplugins_loaded现在由WordPress的运行。 此操作仅适用于WordPress多站点上的网络激活的插件。

11.加载活动插件 (11. Load Active Plugins)

WordPress will now load all active plugins on the site. It does that by looking in the active_plugins entry in the options table of your WordPress database. This allows WordPress to ignore plugins that are installed on your site but not activated.

WordPress现在将在网站上加载所有活动的插件。 它通过在WordPress数据库的选项表中的active_plugins条目中进行查找。 这使WordPress可以忽略在您的网站上安装但未激活的插件。

12.加载pluggable.php文件 (12. Load pluggable.php File)

The pluggable.php file contains functions that can be redefined by WordPress plugins. WordPress will now see if the functions inside this file are already defined by another plugin. Otherwise, it will define those functions itself.

pluggable.php文件包含可由WordPress插件重新定义的功能。 WordPress现在将查看此文件中的功能是否已由另一个插件定义。 否则,它将定义这些功能本身。

13.做动作'plugins_loaded' (13. Do Action ‘plugins_loaded’)

WordPress will now run the action ‘plugins_loaded’. It allows developers to hook their functions to run after all active plugins have been loaded.

WordPress现在将运行操作“ plugins_loaded”。 它允许开发人员在加载所有活动插件后挂钩其功能以运行。

14.加载重写规则 (14. Load Rewrite Rules)

WordPress will now load the rewrite rules. These rewrite rules help WordPress use SEO friendly URLs.

WordPress现在将加载重写规则。 这些重写规则可帮助WordPress使用SEO友好的URL

15.实例化$ wp_query,$ wp_rewrite,$ wp (15. Instantiate $wp_query, $wp_rewrite, $wp)

At this point WordPress loads the following objects:

此时,WordPress将加载以下对象:

$wp_query: The global instance that holds WP_Query class. It tells WordPress what content is requested in a typical WordPress query format.

$ wp_query:包含WP_Query类的全局实例。 它告诉WordPress以典型的WordPress查询格式请求什么内容。

$wp_rewrite: The global instance that holds your WP_Rewrite class. It contains your rewrite rules and functions which tell WordPress which URL to use to display the requested content.

$ wp_rewrite:保存WP_Rewrite类的全局实例。 它包含您的重写规则和函数,这些规则和函数告诉WordPress使用哪个URL来显示所请求的内容。

$wp: The global instance of the WP class which contains functions that will parse your request and perform the main query.

$ wp: WP类的全局实例,该实例包含将解析您的请求并执行主查询的函数。

16.执行“ setup_theme”操作 (16. Do Action ‘setup_theme’)

WordPress will now move on to run ‘setup_theme’ action. This action runs before your WordPress theme is loaded.

WordPress现在将继续运行“ setup_theme”操作。 此操作在加载WordPress主题之前运行。

17.加载子主题的functions.php文件 (17. Load Child Theme’s functions.php File)

The functions.php file acts as plugin and is used in WordPress themes to add theme specific features to your website. If you are using a child theme, then WordPress will now load your child theme’s functions.php file.

functions.php文件充当插件,并在WordPress主题中用于将主题特定的功能添加到您的网站。 如果您使用的是子主题 ,那么WordPress现在将加载子主题的functions.php文件。

Otherwise, it will go on and load your current active theme’s functions.php file.

否则,它将继续并加载当前活动主题的functions.php文件。

18.加载父主题的functions.php文件 (18. Load Parent Theme’s functions.php File)

If you are using a child theme, then WordPress will now load your parent theme’s functions.php file.

如果您使用的是子主题,则WordPress现在将加载父主题的functions.php文件。

19.执行“ after_setup_theme”操作 (19. Do Action ‘after_setup_theme’)

This action runs after WordPress has setup the theme and loaded theme functions. It is the first action available to themes.

在WordPress设置了主题并加载了主题功能之后,将执行此操作。 这是可用于主题的第一个动作。

20.设置当前用户对象 (20. Setup Current User Object)

At this point, WordPress loads the current user object. It allows WordPress to manage the request in accordance with the user’s role and capabilities.

此时,WordPress将加载当前的用户对象。 它允许WordPress根据用户的角色和功能来管理请求。

21.做动作“初始化” (21. Do Action ‘init’)

WordPress has so far loaded all the crucial information it needs. Now it fires the ‘init’ action.

到目前为止,WordPress已经加载了它所需的所有关键信息。 现在,它触发“ init”动作。

This action allows developers to add code that needs to be executed after WordPress has loaded all previously mentioned information.

此操作使开发人员可以添加需要在WordPress加载所有前面提到的信息之后执行的代码。

22.执行“ widget_init”操作 (22. Do Action ‘widget_init’)

The widget_init action allows developers to register widgets and run code they needed to run at this time.

widget_init操作允许开发人员注册小部件并运行此时需要运行的代码。

23.运行wp() (23. Run wp())

WordPress now calls wp() function which is located in wp-includes/functions.php file. It sets up the WordPress query globals $wp, $wp_query, $wp_the_query and then calls $wp->main.

WordPress现在调用wp() wp-includes/functions.php文件中的wp()函数。 它设置WordPress查询全局变量$ wp,$ wp_query,$ wp_the_query,然后调用$ wp-> main。

24.解析请求 (24. Parse Request)

Now WordPress has all the information it needs to parse the user request. It starts by checking the rewrite rules to match the user’s request.

现在,WordPress具有解析用户请求所需的所有信息。 它首先检查重写规则以匹配用户的请求。

And then runs query variable filters, request action hook, and sends header request.

然后运行查询变量过滤器,请求动作挂钩,并发送标头请求。

25.运行查询 (25. Run Query)

If no content matches the query, then WordPress will set is_404 variable.

如果没有内容与查询匹配,则WordPress将设置is_404变量。

Otherwise, WordPress will go on to load query variables.

否则,WordPress将继续加载查询变量。

It will then run WP_Query->get_posts().

然后它将运行WP_Query-> get_posts()。

Next, it fires DO_ACTION_REF_ARRAY ‘pre_get_posts’ action with WP_Query object.

接下来,它使用WP_Query对象触发DO_ACTION_REF_ARRAY'pre_get_posts'操作。

WordPress will now run apply_filters to clean up query and run some final checks.

WordPress现在将运行apply_filters来清理查询并运行一些最终检查。

Now it fetches posts from the database and applies posts_results and the_posts filters.

现在,它从数据库中获取帖子,并应用posts_results和the_posts过滤器。

The query part ends with WordPress returning the posts.

查询部分以WordPress返回帖子结尾。

26.做动作'template_redirect' (26. Do Action ‘template_redirect’)

WordPress will now run the template_redirect action. This hook runs just before WordPress determines which template page to load.

WordPress现在将运行template_redirect操作。 该挂钩将在WordPress确定要加载的模板页面之前运行。

27.加载提要模板 (27. Load Feed Template)

If the requested content is a RSS feed, then WordPress loads the feed template.

如果请求的内容是RSS feed ,则WordPress将加载feed模板。

28.加载模板 (28. Load Template)

WordPress will now look for the template file based on WordPress template hierarchy. It then loads the template which usually contains a WordPress loop.

WordPress现在将基于WordPress模板层次结构查找模板文件。 然后加载通常包含WordPress循环的模板。

29.采取行动“关机” (29. Do Action ‘shutdown’)

Just before ending all PHP execution, WordPress fires the last action called shutdown.

在结束所有PHP执行之前,WordPress会触发最后一个名为shutdown的操作。

WordPress stops working here. It has run the code and generated user’s requested web page.

WordPress在这里停止工作。 它已经运行了代码并生成了用户请求的网页。

Now, your web hosting server replies to user’s request by sending them the web page generated by WordPress. This page contains HTML, CSS, and Javascript code, which tells user’s browser how to display it on screen.

现在,您的网络托管服务器通过向用户发送WordPress生成的网页来回复用户的请求。 该页面包含HTML,CSS和Javascript代码,它告诉用户的浏览器如何在屏幕上显示它。

Amazing isn’t it? All these things happen within milliseconds. If you are using one of these best WordPress hosting services, then ideally your page will load in a couple of seconds.

是不是很神奇? 所有这些事情都在几毫秒内发生。 如果您使用的是这些最佳的WordPress托管服务之一 ,那么理想情况下,您的页面将在几秒钟内加载。

We hope this article helped you learn how WordPress works behind the scenes. You may also want to see our step by step guide on how to boost WordPress speed and performance for beginners.

我们希望本文能帮助您了解WordPress在幕后的工作方式。 您可能还希望查看有关如何为初学者提高WordPress速度和性能的分步指南。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-wordpress-actually-works-behind-the-scenes-infographic/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值