当前位置:首页-文章-wordpress-正文

B2主题添加后台一键修改下载权限的代码

B2主题添加后台一键修改下载权限的代码

下面分享一段B2主题添加后台一键修改下载权限的代码,放入B2主题functions.php文件就可以了。

//下载权限批量设置.放入主题functions.php文件
add_filter( 'bulk_actions-edit-post', function($bulk_actions) {
$bulk_actions['download_permission'] = __( '下载权限批量设置', 'download_permission');
return $bulk_actions;
});
add_filter( 'handle_bulk_actions-edit-post', function( $redirect_to, $doaction, $post_ids ) {
$setting = 'all|free
lv1|free
lv2|comment
lv3|login
lv4|money=10
lv4|credit=30';//需要设置的对应下载权限,自行修改
 
 
if ( $doaction !== 'download_permission' ) {
return $redirect_to;
}
foreach ( $post_ids as $post_id ) {
$meta = get_post_meta($post_id,'b2_single_post_download_group',true) ? get_post_meta($post_id,'b2_single_post_download_group',true) : array();
foreach($meta as $k => $v){
$meta[$k]['rights'] = $setting;
}
update_post_meta($post_id,'b2_single_post_download_group',$meta);
}
$redirect_to = add_query_arg( 'download_setting', count( $post_ids ), $redirect_to );
return $redirect_to;
}, 10, 3 );
add_action( 'admin_notices', function() {
if ( ! empty( $_REQUEST['download_setting'] ) ) {
echo '设置成功';
}
} );
//设置结束
本文原创,作者:lixianguo,其版权均为鲜果博客所有。
如需转载,请注明出处:https://www.lixianguo.cn/archives/1424.html