只是想知道使用匿名函数的首选方法是什么。
首先,我有一些这样的代码:
function page_columns( $columns ) {
$columns = array(
\'cb\' => \'<input type="checkbox" />\',
\'title\' => \'Title\',
\'author\' => \'Author\',
\'template\' => \'Template\',
\'date\' => \'Date\'
);
return $columns;
}
add_filter(\'manage_edit-page_columns\', \'page_columns\');
但我知道WordPress不鼓励在只能使用一次的事情上使用变量,所以我把它改为
function page_columns( $columns ) {
return array(
\'cb\' => \'<input type="checkbox" />\',
\'title\' => \'Title\',
\'author\' => \'Author\',
\'template\' => \'Template\',
\'date\' => \'Date\'
);
}
add_filter(\'manage_edit-page_columns\', \'page_columns\');
但现在我在想,为什么还要使用函数呢?
add_filter(\'manage_edit-page_columns\', function(){
return array(
\'cb\' => \'<input type="checkbox" />\',
\'title\' => \'Title\',
\'author\' => \'Author\',
\'template\' => \'Template\',
\'date\' => \'Date\'
);
});
首选的方法是什么?有什么原因吗?可能会更新
WordPress Coding Standards?