我正在努力发展一下我的WordPress技能。我之前移动了一些功能。我一次又一次使用的php变成了一个必须使用的插件。我现在正试图实现面向对象,但收效甚微。下面的代码是我全部代码的摘录。第一部分工作得很好,减少了摘录的长度,但仪表板却没有。这两部分以前都是作为过程代码使用的。
如果您能帮我解决这个问题,我们将不胜感激。此外,我很难理解为什么建议使用init而不是将我的操作和过滤器放入构造函数中。有人能给我解释一下吗?
class OOtest
{
public function __construct()
{
add_action( \'wp\', array( $this, \'init\' ) );
}
public function init()
{
//Tidy up the dashboard
add_action(\'wp_dashboard_setup\', array( $this, \'tidy_dashboard\') );
//Edit excerpt length
add_filter(\'excerpt_length\', array( $this, \'custom_excerpt_length\') );
}
public function tidy_dashboard()
{
global $wp_meta_boxes, $current_user;
// remove incoming links info for authors or editors
if(in_array(\'author\', $current_user->roles) || in_array(\'editor\', $current_user->roles))
{
unset($wp_meta_boxes[\'dashboard\'][\'normal \'][\'core\'][\'dashboard_incoming_links\']);
}
// remove the plugins info and news feeds for everyone
//Wordpress Development Blog Feed
unset($wp_meta_boxes[\'dashboard\'][\'side\'][\'core\'][\'dashboard_primary\']);
//Other WordPress News Feed
unset($wp_meta_boxes[\'dashboard\'][\'side\'][\'core\'][\'dashboard_secondary\']);
//Quick Press Form
unset($wp_meta_boxes[\'dashboard\'][\'side\'][\'core\'][\'dashboard_quick_press\']);
//Plugins - Popular, New and Recently updated WordPress Plugins
unset($wp_meta_boxes[\'dashboard\'][\'normal\'][\'core\'][\'dashboard_plugins\']);
}
// Add custom excerpt length
public function custom_excerpt_length($length)
{ return 55; }
}
$foo = new OOtest;
?>