我有以下代码:
function process_bulk_action() {
if (isset($_GET['locations'])) {
$location_ids = ( is_array( $_GET['locations'] ) ) ? $_GET['locations'] : array( $_GET['locations'] );
global $wpdb;
switch ( $this->current_action() ) {
case 'edit':
bulk_edit($location_ids);
break;
case 'delete':
bulk_delete($locations_ids);
break;
default:break;
}
}
}
function bulk_delete($ids) {
foreach ( $ids as $id ) {
$id = absint( $id );
$sql = "DELETE FROM wp_nc_location WHERE location_id = $id";
$delete = $wpdb->query( $sql );
}
}
function bulk_edit($ids) {
foreach ( $ids as $id ) {
$id = absint( $id );
$sql = "SELECT name FROM wp_nc_location WHERE location_id = $id";
$select = $wpdb->query( $sql );
echo 'select: '. $select. ',';
print_r($select);
}
}
但是当我尝试从上面的switch语句中调用bulk_edit或bulk_delete时,我收到以下错误消息:
Fatal error: Call to undefined function bulk_delete
我意识到我的范围有问题,但我不确定在哪里放置函数bulk_edit或bulk_delete ......
答案 0 :(得分:3)
我猜你在各个地方使用$this->
这些函数属于一个类吗?在这种情况下,您必须调用函数,如... $this->bulk_delete(..arguments..);