Php 如何使用评论发布表单获取评论ID
我正在寻找一种方法来连接到Php 如何使用评论发布表单获取评论ID,php,wordpress,hook,Php,Wordpress,Hook,我正在寻找一种方法来连接到comment\u post\u表单和update\u comment\u meta,如果有的话,但我不知道如何获取comment-ID 该函数位于functions.php中 function add_comment_drawing() { $drawingsave = $_POST['drawinginput']; if ($drawingsave == 'Das Bild wird gespeichert'){ update_commen
comment\u post\u表单
和update\u comment\u meta
,如果有的话,但我不知道如何获取comment-ID
该函数位于functions.php中
function add_comment_drawing() {
$drawingsave = $_POST['drawinginput'];
if ($drawingsave == 'Das Bild wird gespeichert'){
update_comment_meta( $comment->ID, 'drawingurl', 'Brad' );
}
}
add_action('comment_post', 'add_comment_drawing');
提前感谢:
评论文章在数据库中保存注释后立即运行操作函数参数:注释ID、批准状态(“垃圾邮件”,或0/1表示未批准/批准) : 评论文章
在数据库中保存注释后立即运行操作函数参数:注释ID、批准状态(“垃圾邮件”,或0/1表示未批准/批准)
函数中缺少参数
function add_comment_drawing( $comment_id, $approval_status ) {
$drawingsave = $_POST['drawinginput'];
if ($drawingsave == 'Das Bild wird gespeichert'){
update_comment_meta( $comment_id, 'drawingurl', 'Brad' );
}
}
add_action( 'comment_post', 'add_comment_drawing', 10, 2 );
函数中缺少参数
function add_comment_drawing( $comment_id, $approval_status ) {
$drawingsave = $_POST['drawinginput'];
if ($drawingsave == 'Das Bild wird gespeichert'){
update_comment_meta( $comment_id, 'drawingurl', 'Brad' );
}
}
add_action( 'comment_post', 'add_comment_drawing', 10, 2 );
“我不知道如何获取评论ID”
- 添加操作:将操作添加到队列中
- do_action:在执行排队操作的代码中的某个地方(找到它!)
$comment_ID = wp_insert_comment($commentdata);
if ( ! $comment_ID ) {
return false;
}
因此,您的注释ID是“添加”操作(在本例中是通过wp_insert_comment方法/函数)提供的,以便您可以在函数中使用它,而不是相反。例如,将注释ID记录到文件或其他内容中
“添加动作/参数是如何工作的?”
打开/wp includes/plugin.php,搜索“add_action”并在第400行附近看到:
**
* Hooks a function on to a specific action.
*
* Actions are the hooks that the WordPress core launches at specific points
* during execution, or when specific events occur. Plugins can specify that
* one or more of its PHP functions are executed at these points, using the
* Action API.
*
* @uses add_filter() Adds an action. Parameter list and functionality are the same.
*
* @since 1.2.0
*
* @param string $tag The name of the action to which the $function_to_add is hooked.
* @param callback $function_to_add The name of the function you wish to be called.
* @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
* @param int $accepted_args optional. The number of arguments the function accept (default 1).
*/
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filter($tag, $function_to_add, $priority, $accepted_args);
}
“动作/参数是如何工作的?”
idem.Look-in-wp includes/plugin.php并查看第427行:
/**
* Execute functions hooked on a specific action hook.
*
* This function invokes all functions attached to action hook $tag. It is
* possible to create new action hooks by simply calling this function,
* specifying the name of the new hook using the <tt>$tag</tt> parameter.
*
* You can pass extra arguments to the hooks, much like you can with
* apply_filters().
*
* @see apply_filters() This function works similar with the exception that
* nothing is returned and only the functions or methods are called.
*
* @since 1.2.0
*
* @global array $wp_filter Stores all of the filters
* @global array $wp_actions Increments the amount of times action was triggered.
*
* @param string $tag The name of the action to be executed.
* @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
* @return null Will return null if $tag does not exist in $wp_filter array
*/
function do_action($tag, $arg = '') {
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
if ( ! isset($wp_actions[$tag]) )
$wp_actions[$tag] = 1;
else
++$wp_actions[$tag];
// Do 'all' actions first
if ( isset($wp_filter['all']) ) {
$wp_current_filter[] = $tag;
$all_args = func_get_args();
_wp_call_all_hook($all_args);
}
if ( !isset($wp_filter[$tag]) ) {
if ( isset($wp_filter['all']) )
array_pop($wp_current_filter);
return;
}
if ( !isset($wp_filter['all']) )
$wp_current_filter[] = $tag;
$args = array();
if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this)
$args[] =& $arg[0];
else
$args[] = $arg;
for ( $a = 2; $a < func_num_args(); $a++ )
$args[] = func_get_arg($a);
// Sort
if ( !isset( $merged_filters[ $tag ] ) ) {
ksort($wp_filter[$tag]);
$merged_filters[ $tag ] = true;
}
reset( $wp_filter[ $tag ] );
do {
foreach ( (array) current($wp_filter[$tag]) as $the_ )
if ( !is_null($the_['function']) )
call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
} while ( next($wp_filter[$tag]) !== false );
array_pop($wp_current_filter);
}
/**
*执行挂接在特定操作挂钩上的函数。
*
*此函数调用附加到action hook$tag的所有函数
*只需调用此函数即可创建新的动作挂钩,
*使用$tag参数指定新挂钩的名称。
*
*您可以将额外的参数传递给钩子,就像使用
*应用过滤器()。
*
*@see apply_filters()此函数的工作原理与以下类似
*不返回任何内容,只调用函数或方法。
*
*@自1.2.0以来
*
*@global array$wp_filter存储所有过滤器
*@global array$wp_actions递增操作触发的次数。
*
*@param string$标记要执行的操作的名称。
*@param mixed$arg,…可选的附加参数,这些参数传递给连接到操作的函数。
*如果$wp_过滤器数组中不存在$tag,@return null将返回null
*/
函数do_action($tag,$arg=''){
全局$wp_filter、$wp_actions、$merged_filters、$wp_current_filter;
如果(!isset($wp_actions[$tag]))
$wp_actions[$tag]=1;
其他的
++$wp_actions[$tag];
//先做“所有”动作
如果(isset($wp_filter['all'])){
$wp_当前_过滤器[]=$tag;
$all_args=func_get_args();
_wp_call_all_hook($all_args);
}
如果(!isset($wp_filter[$tag])){
如果(isset($wp_filter['all']))
数组_pop($wp_current_filter);
返回;
}
如果(!isset($wp_filter['all']))
$wp_当前_过滤器[]=$tag;
$args=array();
if(is_数组($arg)&&1==count($arg)&&isset($arg[0])&&is_对象($arg[0])//数组(&$this)
$args[]=&$arg[0];
其他的
$args[]=$arg;
对于($a=2;$a
因此,添加动作/执行动作/过滤器的主要“窍门”是调用用户函数数组():,一旦您了解了该函数,您就了解了WP中这些函数的功能
“如何工作”
一般来说,只要看看WordPress的源代码(这就是它的开源优势)
另一个技巧是使用IDE,比如Eclipse或Netbeans:它们可以在IDE中向您显示大量信息,最重要的是:在“运行时”期间,您可以通过调试器获得大量信息。“我不知道如何获取注释ID”
- 添加操作:将操作添加到队列中
- do_action:在执行排队操作的代码中的某个地方(找到它!)
$comment_ID = wp_insert_comment($commentdata);
if ( ! $comment_ID ) {
return false;
}
因此,您的注释ID是“添加”操作(在本例中是通过wp_insert_comment方法/函数)提供的,以便您可以在函数中使用它,而不是相反。例如,将注释ID记录到文件或其他内容中
“添加动作/参数是如何工作的?”
打开/wp includes/plugin.php,搜索“add_action”并在第400行附近看到:
**
* Hooks a function on to a specific action.
*
* Actions are the hooks that the WordPress core launches at specific points
* during execution, or when specific events occur. Plugins can specify that
* one or more of its PHP functions are executed at these points, using the
* Action API.
*
* @uses add_filter() Adds an action. Parameter list and functionality are the same.
*
* @since 1.2.0
*
* @param string $tag The name of the action to which the $function_to_add is hooked.
* @param callback $function_to_add The name of the function you wish to be called.
* @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
* @param int $accepted_args optional. The number of arguments the function accept (default 1).
*/
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filter($tag, $function_to_add, $priority, $accepted_args);
}
“动作/参数是如何工作的?”
idem.Look-in-wp includes/plugin.php并查看第427行:
/**
* Execute functions hooked on a specific action hook.
*
* This function invokes all functions attached to action hook $tag. It is
* possible to create new action hooks by simply calling this function,
* specifying the name of the new hook using the <tt>$tag</tt> parameter.
*
* You can pass extra arguments to the hooks, much like you can with
* apply_filters().
*
* @see apply_filters() This function works similar with the exception that
* nothing is returned and only the functions or methods are called.
*
* @since 1.2.0
*
* @global array $wp_filter Stores all of the filters
* @global array $wp_actions Increments the amount of times action was triggered.
*
* @param string $tag The name of the action to be executed.
* @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
* @return null Will return null if $tag does not exist in $wp_filter array
*/
function do_action($tag, $arg = '') {
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
if ( ! isset($wp_actions[$tag]) )
$wp_actions[$tag] = 1;
else
++$wp_actions[$tag];
// Do 'all' actions first
if ( isset($wp_filter['all']) ) {
$wp_current_filter[] = $tag;
$all_args = func_get_args();
_wp_call_all_hook($all_args);
}
if ( !isset($wp_filter[$tag]) ) {
if ( isset($wp_filter['all']) )
array_pop($wp_current_filter);
return;
}
if ( !isset($wp_filter['all']) )
$wp_current_filter[] = $tag;
$args = array();
if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this)
$args[] =& $arg[0];
else
$args[] = $arg;
for ( $a = 2; $a < func_num_args(); $a++ )
$args[] = func_get_arg($a);
// Sort
if ( !isset( $merged_filters[ $tag ] ) ) {
ksort($wp_filter[$tag]);
$merged_filters[ $tag ] = true;
}
reset( $wp_filter[ $tag ] );
do {
foreach ( (array) current($wp_filter[$tag]) as $the_ )
if ( !is_null($the_['function']) )
call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
} while ( next($wp_filter[$tag]) !== false );
array_pop($wp_current_filter);
}
/**
*执行挂接在特定操作挂钩上的函数。
*
*此函数调用附加到action hook$tag的所有函数
*只需调用此函数即可创建新的动作挂钩,
*使用$tag参数指定新挂钩的名称。
*
*您可以将额外的参数传递给钩子,就像使用
*应用过滤器()。
*
*@see apply_filters()此函数的工作原理与以下类似
*不返回任何内容,只调用函数或方法。
*
*@自1.2.0以来
*
*