我正在修改我在网上找到的一个脚本,将自定义批量操作添加到带有帖子列表的屏幕上。它有这样一行:
add_action(\'load-edit.php\', \'custom_bulk_action\');
我正在尝试将其改编为媒体库。我看到它代替了edit.php
我应该使用upload.php
, 这让我相信我需要找到load-edit.php
. 听起来很简单,但我甚至找不到load-edit.php
在我的可湿性粉剂安装,看看是否有机会,它可能是我正在寻找自己。我在网上找到了一些参考资料load-*.php
(例如。,Custom bulk_action), 但没什么能告诉我什么是价值观*
可以接受。(我试过了load-upload.php
但它不起作用——尽管我的代码中可能总是有其他东西把工作搞砸了。)
所以我的问题有两个:
什么是媒体模拟load-edit.php
?load-edit.php (和其他load-*.php
或者什么代码处理这些文件请求
你们这些专家能给我一些指导吗?我将非常感激。
编辑“不工作”我的意思不是它崩溃,而是它没有按预期的那样工作(更改媒体属性)。
我正在修改的代码可以在帖子底部下载“Add a WordPress Custom Bulk Action“作者:Fox Run Software的贾斯汀·斯特恩(Justin Stern)。回去验证代码的每一步,我得到了适合的版本,但前提是我注释掉了条件检查和安全检查(下面都用星号标出)。我应该使用什么样的媒体模拟来代替这些?
add_action(\'load-upload.php\', array(&$this, \'custom_bulk_action\'));
function custom_bulk_action() {
// ***if($post_type == \'attachment\') { REPLACE WITH:
if ( !isset( $_REQUEST[\'detached\'] ) ) {
// get the action
$wp_list_table = _get_list_table(\'WP_Media_List_Table\');
$action = $wp_list_table->current_action();
echo "\\naction = $action\\n</pre>";
$allowed_actions = array("export");
if(!in_array($action, $allowed_actions)) return;
// security check
// ***check_admin_referer(\'bulk-posts\'); REPLACE WITH:
check_admin_referer(\'bulk-media\');
// make sure ids are submitted. depending on the resource type, this may be \'media\' or \'ids\'
if(isset($_REQUEST[\'media\'])) {
$post_ids = array_map(\'intval\', $_REQUEST[\'media\']);
}
if(empty($post_ids)) return;
// this is based on wp-admin/edit.php
$sendback = remove_query_arg( array(\'exported\', \'untrashed\', \'deleted\', \'ids\'), wp_get_referer() );
if ( ! $sendback )
$sendback = admin_url( "upload.php?post_type=$post_type" );
$pagenum = $wp_list_table->get_pagenum();
$sendback = add_query_arg( \'paged\', $pagenum, $sendback );
switch($action) {
case \'export\':
// if we set up user permissions/capabilities, the code might look like:
//if ( !current_user_can($post_type_object->cap->export_post, $post_id) )
// wp_die( __(\'You are not allowed to export this post.\') );
$exported = 0;
foreach( $post_ids as $post_id ) {
if ( !$this->perform_export($post_id) )
wp_die( __(\'Error exporting post.\') );
$exported++;
}
$sendback = add_query_arg( array(\'exported\' => $exported, \'ids\' => join(\',\', $post_ids) ), $sendback );
break;
default: return;
}
$sendback = remove_query_arg( array(\'action\', \'action2\', \'tags_input\', \'post_author\', \'comment_status\', \'ping_status\', \'_status\', \'post\', \'bulk_edit\', \'post_view\'), $sendback );
wp_redirect($sendback);
exit();
}
}
我感谢你的帮助。