[wordpress插件] API Request CollectorAPI请求收集器

wordpress 插件 文章 2020-01-23 20:40 566 0 全屏看文

AI助手支持GPT4.0

评分

0

0

描述

This is a very simple plugin that creates a new adminbar menu with a list of pertinent API calls used on a page.

这是一个非常简单的插件,可以创建一个新的管理栏菜单,其中包含页面上使用的相关API调用的列表。

However, no good thing happens in a vacuum, and you good folks, are developers.

但是,没有什么事情是凭空发生的,你们好人都是开发人员。

In order to log API calls, you should invoke the log_api_call() method of the $ab_api_logger global object.

为了记录API调用,您应该调用 $ ab_api_logger 全局对象的 log_api_call()方法。

Of course, if you prefer, you can instantiate your own object using the AB_API_Logger class.

当然,如果愿意,可以使用 AB_API_Logger 类实例化自己的对象。

The log_api_call() method takes two properties.

log_api_call()方法具有两个属性。

The first is an array of URLs that will be included as menu items (easy access, easy click to see responses).

第一个是将包含为菜单项的URL数组(易于访问,单击查看响应)。

By default, the plugin maintains a property $api_calls with this array and uses it to parse out the menu items.

默认情况下,该插件使用此数组维护属性 $ api_calls ,并使用它来解析菜单项。

However, if you wish to maintain your own array, you can do that too.

但是,如果您希望维护自己的阵列,也可以这样做。

The plugin takes care of what it needs, and you can feel free to maintain what you need.

该插件会处理所需的内容,您可以随时维护所需的内容。

The second argument for the log_api_calls() method is the URL that will be added to the adminbar menu.

log_api_calls()方法的第二个参数是将添加到管理栏菜单的URL。

You can escape it if you want, but I will as well for security.

您可以根据需要进行转义,但是出于安全考虑,我也会这样做。

The reason I built this plugin is because I deal with APIs a lot.

构建此插件的原因是因为我经常处理API。

My normal approach to API integration is to use a pre-existing PHP library or, more commonly, build a library around the API so I can use it easily without having to remember everything.

我进行API集成的常规方法是使用预先存在的PHP库,或更常见的是围绕API构建库,这样我就可以轻松使用它,而不必记住所有内容。

Usually, this means I create a class and that class is filled with methods that construct a URL based on parameters and then use wp_remote_get() to retrieve the response from the API.

通常,这意味着我创建了一个类,该类中填充了基于参数构造URL的方法,然后使用 wp_remote_get()从API检索响应。

Anytime after the URL is created, invoke this plugin:

创建URL后的任何时间,只要调用此插件即可:

if( class_exists( 'AB_API_Logger' ) ) {     // Example API Call: $api_url (http://api.example.com?apikey=asdfASD234&post_id=213)     global $ab_api_logger;

  if(class_exists('AB_API_Logger')){//示例API调用:$ api_url(http://api.example.com?apikey=asdfASD234&post_id=213)全局$ ab_api_logger; 

$ab_api_logger->log_api_call( $ab_api_logger->api_calls, $api_url );

$ ab_api_logger-> log_api_call($ ab_api_logger-> api_calls,$ api_url);

}

}

Pull requests can be submitted via Github

可以通过 Github 提交拉取请求。

下载地址

https://downloads.wordpress.org/plugin/ab-api-call-logger.zip

https://downloads.wordpress.org/plugin/ab-api-call-logger.zip

-EOF-

AI助手支持GPT4.0