Support » Plugins » Hacks » WP_List_Table Documentation vs Practice

  • Arevico

    (@arevico)


    Hey,

    I’ve a question regarding WP_List_Table

    I found that the following notice is listed:
    NOTICE: As of WordPress 3.5.1, in core $item is passed an Object, not an array.

    However, when I test it out in my code, it seems like $items is still passed as an array in the latest WordPress.

    /**
         * Retrieve the data associated with a specific column.
         * @param array $item The row
         * @param string $column_name The index of the column (internal name)
         */
        function column_default($item, $column_name){
            var_dump($item);
            switch ($column_name) {
    
                case 'when':
                    return isset($item['when']) ? date('Y-m-d h:i:s' ,trim( $item['when']) ) : '-';
                    break;
    
                default:
                    return isset($item[$column_name]) ? htmlentities($item[$column_name]) : '';
                    break;
            }
    
        }

    I also checked the source and the phpDoc also lists an object instead of an array, but var_dumping results in an array.

    Is the documentation correct or is this a bug or did I misunderstand it? If anyone knows, please let me know 🙂

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    WP_List_Table itself is agnostic regarding array or object, it’ll work either way. I believe what that note is alluding to is that all core extensions, such as WP_Posts_List_Table, are all passing objects.

    Since your extension is establishing the composition of $item, I don’t think it matters which is used. Whichever you use, your corresponding methods should be coded accordingly.

    However, if your are modifying a core extension via action or filter hooks, you should be aware that $item is going to be an object. I think that is all the note is trying to say.

Viewing 1 replies (of 1 total)
  • The topic ‘WP_List_Table Documentation vs Practice’ is closed to new replies.