Php scope question (referencing a function inside of another function)
I have the following code:
function process_bulk_action() {
if (isset($_GET['locations'])) {
$location_ids = ( is_array( $_GET['locations'] ) ) ? $_GET['locations'] : array( $_GE开发者_如何学运维T['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);
}
}
However I am getting the following error message when I try to call either bulk_edit or bulk_delete from inside that switch statement above:
Fatal error: Call to undefined function bulk_delete
I realize I am getting something wrong with the scope but I'm not sure where to put the functions bulk_edit or bulk_delete...
I'm guessing from your use of $this->
in various places that those functions belong to a class? In this case, you have to call the function like... $this->bulk_delete(..arguments..);
精彩评论