您可以编写自定义插件,使用核心功能更改注释、trackback的状态。使用以下代码示例,将其添加到自定义插件(一个小类)中,并将其作为插件激活。该类使用两个过滤器挂钩来关闭注释和trackback,第二个是停用的,但位于源代码内部,以便更好地理解或满足其他需求。
add_action( \'plugins_loaded\', array( \'FbCloseComments\', \'get_object\' ) );
class FbCloseComments {
/**
* Class object.
*
* @var null
*/
static private $classobj;
/**
* Handler for the action \'init\'. Instantiates this class.
*
* @access public
* @return null|Remove_Comments_Absolute $classobj object
*/
public static function get_object() {
if ( NULL === self::$classobj ) {
self::$classobj = new self;
}
return self::$classobj;
}
public function __construct() {
add_filter( \'comments_open\', array( $this, \'close_comments\' ), 20, 2 );
//add_filter( \'pings_open\', array( $this, \'close_comments\' ), 20, 2 );
}
/**
* Close comments, if open.
*
* @access public
*
* @param string|boolean $open
* @param string|integer $post_id
*
* @return bool|string $open
*/
public function close_comments( $open, $post_id ) {
// If not open, than back.
if ( ! $open ) {
return $open;
}
$post = get_post( $post_id );
// For all post types.
if ( $post->post_type ) {
return FALSE;
} // \'closed\' don`t work; @see http://codex.wordpress.org/Option_Reference#Discussion
return $open;
}
}
作者的变更应通过
save_post
钩您可以在下面的示例中找到答案
answer.