我在我的主要WP博客上不断收到各种各样的媒体附件上的垃圾邮件尝试。默认情况下,媒体有打开的评论(例如,http://literalbarrage.org/blog/archives/2009/03/18/daddywill-date-march-2009/dsc08760/), 然而,没有本地方法来禁用媒体文件上的注释。(例如。https://skitch.com/zamoose/rhktp/attachmentedit)
因此,有两个问题:
默认情况下,如何禁用所有评论以供将来上载
我在我的主要WP博客上不断收到各种各样的媒体附件上的垃圾邮件尝试。默认情况下,媒体有打开的评论(例如,http://literalbarrage.org/blog/archives/2009/03/18/daddywill-date-march-2009/dsc08760/), 然而,没有本地方法来禁用媒体文件上的注释。(例如。https://skitch.com/zamoose/rhktp/attachmentedit)
因此,有两个问题:
默认情况下,如何禁用所有评论以供将来上载
这应该做到:
function wpse15750_comment_check( $id ){
if( get_post_type( $id ) == \'attachment\' )
exit;
}
add_action( \'pre_comment_on_post\', \'wpse15750_comment_check\' );
编辑忽略以上内容。这将阻止新的评论,但要想做你想做的事,这要好得多:function wpse15750_comments_closed( $open, $id ){
if( get_post_type( $id ) == \'attachment\' )
return false;
return $open;
}
add_action( \'pre_comment_on_post\', \'wpse15750_comments_closed\', 10, 2 );
这将告诉WordPress附件总是有关闭的注释,但它们的数据库值仍然会显示“打开”。如果要更改,请运行以下代码:global $wpdb;
$wpdb->update( $wpdb->posts, array( \'comment_status\' => \'closed\' ), array( \'post_type\' => \'attachments\', \'comment_status\' => \'open\' ) );
要防止任何未来的附件具有打开的注释,请使用以下筛选器:function wpse15750_no_attachment_comments( $data ){
if( $data[\'post_type\'] == \'attachment\' )
$data[\'comment_status\'] = \'closed\';
return $data;
}
add_filter( \'wp_insert_post_data\', \'wpse15750_no_attachment_comments\' );
关于第1项—remove_post_type_support( $post_type, \'comments\' );
需要连接到init。
法典:https://codex.wordpress.org/Function_Reference/remove_post_type_support
似乎有comments_open
过滤器:
function filter_media_comment_status( $open, $post_id ) {
$post = get_post( $post_id );
if( $post->post_type == \'attachment\' ) {
return false;
}
return $open;
}
add_filter( \'comments_open\', \'filter_media_comment_status\', 10 , 2 );
资料来源:http://www.wpbeginner.com/wp-tutorials/how-to-disable-comments-on-wordpress-media-attachments/我已经创建了我的新标签并将其显示出来,我还复制了gallery屏幕(我正在制作一个带有播放列表功能的音频插件)。媒体项目列表显示得很好,但我只能在未将post ID传递到get_media_items() 类似于“媒体库”选项卡中的功能。如何使用检索媒体项目列表get_media_items() 其中设置了post\\u parent字段,并且post\\u mime\\u类型与“audio”匹配?