WordPress wp-load.php [英] Wordpress wp-load.php

查看:26
本文介绍了WordPress wp-load.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对插件进行逆向工程:http://wordpress.org/extend/plugins/wordpress-social-login/

I'm trying to reverse-engineer a plugin : http://wordpress.org/extend/plugins/wordpress-social-login/

在其中的一部分,有这样一行:
(我很难理解第一个,如果他们有事情要做,其余的只是作为参考.)

In a part of it, there's this line:
(I'm having a hard time understanding the first one, the rest are simply there for reference if they have something to do it.)

require_once( dirname( dirname( dirname( dirname( __FILE__ )))) . '/wp-load.php' );

define( 'WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL', plugins_url() . '/' . basename( dirname( __FILE__ ) ) ); 
define( 'WORDPRESS_SOCIAL_LOGIN_HYBRIDAUTH_ENDPOINT_URL', WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL . '/hybridauth/' ); 

我的问题是...在这个 wp-load.php 文件中到底有什么代码需要它?通过查看它,我所理解的是它加载了使网站正确运行的关键核心 wordpress 文件(functions.phpwp-settings.phpwp-config.php 等等...)
插件运行的事实是否意味着 wp-load.php 已加载?
这也是一种资源的完全浪费,因为它包含了很多可能还包含其他文件的文件,就像一个无限循环的所需文件,每个文件都在另一个文件中,被加载两次..(如果其他插件使用这个,甚至更多也是一种方法)

My question is... what exactly is in this wp-load.php file that it needs to be required by the code? By looking at it, all I understand is that it loads crucial core wordpress files for the site to be running correctly (functions.php, wp-settings.php, wp-config.php etc...)
Doesn't the fact that the plugin runs already means wp-load.php is loaded?
Also it's a complete waste of resources since it includes so many files that may include other files as well and it's like an endless loop of required files, each within another, which are being loaded twice.. (or even more if other plugins use this kind of method too)

那么它到底是做什么的?

So what exactly does it do?

附:我通过 Google-ing 发现的只是如何正确包含它(因为路径是可变的) - 但这不是我的问题/问题.

P.S; All I found by Google-ing is HOW to include it correctly (since paths are change-able) - but that's not my problem/question.

推荐答案

我的问题是...在这个 wp-load.php 文件中到底有什么代码需要它?

My question is... what exactly is in this wp-load.php file that it needs to be required by the code?

WordPress 的所有核心功能.这包括主题文件、活动插件的所有文件等.但是以这种方式加载 WordPress 不会解析请求的 URL 并且不会运行 WordPress 查询(通过初始化 WP 对象,也不是 WP_Query 对象).

All of the core WordPress functionality. This includes the theme files, all the files of active plugins, etc. BUT loading WordPress in this way doesn't parse the requested URL and doesn't run the WordPress query(by initializing the WP object, nor the WP_Query objects).

通过查看它,我所了解的是它加载了使网站正确运行的关键核心 wordpress 文件(functions.phpwp-settings.php, wp-config.php 等等...)

By looking at it, all I understand is that it loads crucial core wordpress files for the site to be running correctly (functions.php, wp-settings.php, wp-config.php etc...)

是的,你理解正确.

插件运行不就意味着wp-load.php已经加载了吗?

Doesn't the fact that the plugin runs already means wp-load.php is loaded?

如果插件代码是由 WordPress 调用的(例如为了显示管理页面,或者它包含在最初加载的插件文件中) - 那么是的,这意味着 wp-load.php已加载.

If the plugin code was invoked by WordPress(for instance in order to display an admin page, or it was included by the initially loaded plugin file) - then yes, it means that wp-load.php has already been loaded.

有时,插件会将请求定向到单个文件(例如 http://example.com/wp-content/plugins/my-plugin/sample.php),而不是某些 WordPress-Powered 页面(例如 http://example.com/?my_plugin_action=samplehttp://example.com/wp-admin/admin-ajax.php).

Sometimes though, plugins direct requests to single files(for instance http://example.com/wp-content/plugins/my-plugin/sample.php), instead of to some WordPress-powered page(for instance http://example.com/?my_plugin_action=sample or http://example.com/wp-admin/admin-ajax.php).

查看第一个 URL 如何引用 my-plugin 插件目录中的特定文件,第二个 URL 如何转到添加了特定查询参数的站点主页,或者第三个示例,其中引用的文件是 wp-admin 目录中的 admin-ajax.php - 这是一个特殊文件,它使插件可以轻松地进行 AJAX 请求(此文件还加载 WordPress 核心并触发一些动作钩子).

See how the first URL references a specific file in the my-plugin plugin directory and the second one goes to the home page of the site with a specific query argument added, or the third example, where the referenced file is admin-ajax.php in the wp-admin directory - this is a special file, which makes it easy for plugins to make AJAX request(this file also loads the WordPress core and fires some action hooks).

在第一次引用的情况下,如果插件想要使用一些 WordPress 功能(用于引用数据库、操作帖子等),它需要通过包含 wp-load.php 来加载 WordPress 核心文件.

In the case of the first reference, if the plugin wants to use some WordPress functionality(for referencing the database, manipulating posts, etc), it needs to load the WordPress core files by including wp-load.php.

此外,这完全是在浪费资源,因为它包含了很多可能还包含其他文件的文件,就像一个无限循环的所需文件,每个文件都在另一个文件中,被加载了两次..(或者甚至更多,如果其他插件也用这种方法)

Also it's a complete waste of resources since it includes so many files that may include other files as well and it's like an endless loop of required files, each within another, which are being loaded twice.. (or even more if other plugins use this kind of method too)

注意 require_once(... 中的 _once 部分 - 这告诉 PHP 包含文件,如果它没有被包含已经.因此不会发生冲突,并且 PHP 不会使用太多内存.尽管 - 如果您处于 WordPress 已经启动的上下文中,则不应调用 require 函数.

Note the _once part in require_once(... - this tells PHP to include the file only if it hasn't been included already. Therefore no conflicts will occur, and not too much memory will be used by PHP. Although - if you are in a context where WordPress has already been started, you shouldn't call the require function.

因此,基本上插件作者希望对您在其中找到此代码的插件文件提出一些请求.由于作者想在这个文件中使用 WordPress 功能,他调用了 wp-load.php 文件来加载核心功能.

So, basically the plugin author expects some requests to be made to the plugin file in which you found this code. Since the author wants to use WordPress functionality in this file, he invokes the wp-load.php file in order to load the core functions.

我假设这样做是为了减少服务器上的负载,尽管有几个运行在 plugins_loaded 动作钩子上的钩子和一个自定义的 $_GET 参数添加到 home url,结果应该还是很接近的.

I assume, that this is done in order to reduce load on the server, although with a couple of hooks that run on the plugins_loaded action hook and a custom $_GET parameter added to the home url, the result should still be pretty close.

我个人更喜欢第二个选项,但就像我说的,包括 wp-load.php 阻止 WordPress 运行一些复杂的东西(URL 解析和数据库查询/就是).

I personally prefer the second option, but like I said, including wp-load.php will prevent WordPress from running some complex stuff(URL parsing and database query/ies).

如果您还有什么不明白的地方 - 请在此处发表评论,我会尝试进一步解释.

If there is still something, that you don't quite understand about that - post a comment here and I'll try to explain further.

这篇关于WordPress wp-load.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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