0

I have the following code:

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);
        }
    }

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...

4
  • 2
    Are you inside a class with this? Commented Aug 22, 2011 at 17:30
  • 1
    @Matt it's being called from within another function, so all are defined before called, unless there's code or includes we aren't seeing Commented Aug 22, 2011 at 17:32
  • Is this all of your code? You likely have a missing or additional bracket somewhere. @Matt - Functions can be defined below the actual reference to them in the file. The code is compiled before execution Commented Aug 22, 2011 at 17:33
  • Also the functions won't actually be declared in the local scope. Commented Aug 22, 2011 at 17:36

1 Answer 1

3

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..);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.