我正在wordpress网站上工作,在这里我可以动态生成目标网页。我在这些目标网页上使用了自定义字段,例如价格,背景图片等。现在,我想为这些页面创建一个自定义批量操作,在此我可以一次更新所有着陆页的价格字段。现在,我如何为此创建批量操作。
这是开始的代码:
add_action('admin_footer-edit.php', 'custom_bulk_admin_footer');
function custom_bulk_admin_footer() {
global $post_type;
if($post_type == 'post') {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('<option>').val('edit_custom_field...').text('<?php _e('Update custo....')?>').appendTo("select[name='udpate...action1']");
jQuery('<option>').val('edit_custom_field...').text('<?php _e('Update custo....')?>').appendTo("select[name='udpate...action2']");
});
</script>
<?php
}
}
add_action('load-edit.php', 'custom_bulk_action');
function custom_bulk_action() {
// ...
// 1. get the action
$wp_list_table = _get_list_table('WP_Posts_List_Table');
$action = $wp_list_table->current_action();
// ...
// 2. security check
check_admin_referer('bulk-posts');
// ...
switch($action) {
// 3. Perform the 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) )
// pp_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++;
}
// build the redirect url
$sendback = add_query_arg( array('exported' => $exported, 'ids' => join(',', $post_ids) ), $sendback );
break;
default: return;
}
// ...
// 4. Redirect client
wp_redirect($sendback);
exit();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句