我很难成功地使用wp\\u add\\u dashboard\\u小部件的$callback\\u args参数。
以下代码在转储$args时始终显示字符串(0)“”:
add_action( \'wp_dashboard_setup\', \'sample_widget_setup\' );
function sample_widget_setup() {
wp_add_dashboard_widget(
\'sample_dashboard_widget\',
\'Sample Widget\',
\'sample_dashboard_widget_callback\',
null,
\'sample_string\'
);
}
function sample_dashboard_widget_callback($args) {
var_dump($args);
}
如何将变量传递给sample\\u dashboard\\u widget\\u回调?
最合适的回答,由SO网友:Chris_O 整理而成
参数存储在传递给回调函数的第二个变量中。
add_action( \'wp_dashboard_setup\', \'sample_widget_setup\' );
function sample_widget_setup() {
wp_add_dashboard_widget(
\'sample_dashboard_widget\',
\'Sample Widget\',
\'sample_dashboard_widget_callback\',
null,
\'sample_string\'
);
}
function sample_dashboard_widget_callback( $var, $args ) {
var_dump( $args );
}
以上输出:
array
\'id\' => string \'sample_dashboard_widget\' (length=23)
\'title\' => string \'Sample Widget\' (length=13)
\'callback\' => string \'sample_dashboard_widget_callback\' (length=32)
\'args\' => string \'sample_string\' (length=13)