[wordpress插件] Commentcode APIAPI代码注释

wordpress 插件 文章 2020-03-29 02:50 526 0 全屏看文

AI助手支持GPT4.0

评分
0
描述

Generate Custom Outputs with HTML Comments

使用HTML注释生成自定义输出

Commentcode API lets you generate custom outputs with HTML comment-like codes.

Commentcode API使您可以使用类似HTML注释的代码生成自定义输出。

It is similar to the Shortcode API except it takes a form of HTML comments and some few features.

它与 Shortcode API 类似,不同之处在于它采用了HTML注释的形式和一些功能。

Since it takes a form of HTML comments, even the user disables your plugin, the embedded code will not be visible, on contrary to shortcodes that remain in posts when their plugins are deactivated.

由于采用HTML注释的形式,即使用户禁用了插件,嵌入的代码也将不可见,这与停用插件时帖子中保留的短代码相反。

Does not leave a mess in posts

不要在帖子中乱七八糟

Say, you have been using a plugin that converts a plugin specific shortcode into custom outputs.

说,您一直在使用将插件特定的短代码转换为自定义输出的插件。

Later you found something else that is more useful and uninstalled it.

后来,您发现了其他更有用的东西并将其卸载。

But the shortcodes used by that plugin remained in hundreds of posts and it was too much work to manually delete them so you have to ask somebody to run SQL commands.

但是该插件使用的短代码仍然存在于数百篇文章中,手动删除它们的工作量太大,因此您必须要求某人运行SQL命令。

That’s a problem.

这是一个问题。

What if the shortcode takes a form of an HTML comment?

如果简码采用HTML注释形式怎么办?

It won’t leave such a mess.

不会留下这样的混乱。

Syntax

语法

It looks like this.

看起来像这样。

  <!---标签foo =“ bar” --->

Some outputs.

<!--- tag color =“#333” --->

某些输出。 <!--- / tag --->

Notice that tripe dashes are used in the both opening and closing part.

请注意,在打开和关闭部分都使用了破折号。

So it won’t hardly conflict with generic HTML comments.

因此,它几乎不会与通用HTML注释冲突。

Supports Multi-dimensional Array Arguments

支持多维数组参数

The shortcode cannot pass multi-dimensional arguments to the callback function.

简码不能将多维参数传递给回调函数。

The below attributes won’t be parsed.

以下属性将不会被解析。

[my_shortcode foo[1]="one" foo[2]="two"]

  [my_shortcode foo [1] =“ one” foo [2] =“ two”]

However, commentcode can handle it.

但是,注释代码可以处理它。

  <!--- my_shortcode foo [1] =“ one” foo [2] =“ two” --->

The attributes are interpreted as

属性被解释为

array(    

  array(    

'foo' => array(        

'foo'=>数组(        

1 => 'one',        

1 =>'一个',        

2 => 'two',    

2 =>'两个',    

)

)

Preserved Letter Cases

保留信件的情况

The shortcode does not allow capitalized attribute names.

简码不允许使用大写的属性名称。

[my_shortcode CapitalName="I need it to be capitalized"]

  [my_shortcode CapitalName =“我需要将其大写”]

The attribute is interpreted as

该属性被解释为

array(    

  array(    

'capitalname' => 'I need it to be capitalized',

'capitalname'=>'我需要将其大写',

)

This is not useful when you need to perform remote API requests which require argument names with capital letters.

当您需要执行需要使用大写字母作为参数名称的远程API请求时,此功能没有用。

However, the commentcode API preserves those argument names.

但是,commentcode API保留了这些参数名称。

->

will be

将是

array(    

  array(    

'CapitalName' => 'Please keep capitalization!',

'CapitalName'=>'请保持大写!',

)

Register a Commentcode

注册评论代码

Use the add_commentcode() function.

使用 add_commentcode()函数。

It accepts two parameters.

它接受两个参数。

1. (string) the commentcode tag.

1.(字符串)commentcode标签。

2. (callable) a callback function which gets called when the commentcode of the specified tag is processed.

2.(可调用)一个回调函数,当处理指定标签的注释代码时将调用该函数。

The callback function receives three parameters.

回调函数接收三个参数。

1. (string) The filtered text, usually an empty string.

1.(字符串)过滤后的文本,通常为空字符串。

2. (array) The attributes set in the commentcode.

2.(数组)在注释代码中设置的属性。

3. (string) The commentcode tag name.

3.(字符串)注释代码标记名称。

function get_my_commentcode( $text, $arguments, $tag ) {    

  function get_my_commentcode($ text,$ arguments,$ tag){    

return "

" .

返回“

”。 

htmlspecialchars( print_r( $arguments, true ) ) .

htmlspecialchars(print_r($ arguments,true))。

"

";

”;

}

}

add_commentcode( 'my_commentcode', 'get_my_commentcode' );

add_commentcode('my_commentcode','get_my_commentcode');

For a test, while running the above code, try inserting <

要进行测试,请在运行上述代码时尝试插入 <!--- my_commentcode Foo =“ bar”数字[1] =“ one”数字[2] =“ two” ---> <

/code> in a post.

/ code>在帖子中。

It will produce this output,

它将产生此输出,

Array

 数组

(    

(    

[Foo] => bar    

[Foo] =>栏    

[numbers] => Array        

[数字] =>数组        

(            

(            

[1] => one            

[1] =>一个            

[2] => two        

[2] =>两个        

)

)

安装步骤

    1. Upload commentcode-api.php and other files compressed in the zip folder to the /wp-content/plugins/

    2. commentcode-api.php 和其他在zip文件夹中压缩的文件上传到 / wp-content / plugins /

      directory.

    3. 目录。

    4. Activate the plugin through the ‘Plugins’ menu in WordPress.
    5. 通过WordPress中的“插件”菜单激活插件。

下载地址
https://downloads.wordpress.org/plugin/commentcode-api.1.0.0.zip
-EOF-

AI助手支持GPT4.0