Leave a Reply

2 comments

  1. This appears to be a general PHP warning, you’re supplying an incorrect argument in a foreach loop.

    $_POST['list_id'] is expected to be an array or any other (iteratable object), when no checkboxes are checked I assume $_POST['list_id'] is completely undefined.

    $_POST['list_id'] = isset( $_POST['list_id'] ) ? (array) $_POST['list_id'] : array();
    

    Adding this before you iterate over everything should help you get rid of the warning altogether.

  2. Never assume anything about $_POST. It is user input and could contain anything. First check if $_POST['list_id'] exists, using isset() or empty(). Then make sure it is an array. You may simply cast it to an array if you wish. Finally, make sure the array values are actually absolute integers.

    $ids = (isset($_POST['list_id'])) ? array_map('absint', (array) $_POST['list_id']) : array();
    

    All post IDs not found in the submitted list should be unfeatured.