Error on using __FILE__ for add_menu_page() Function

Your code should work (not how you expect but it should work), and probably the error was in something that you didn’t post.

However…

__FILE__ is a constant: you don’t have to use quotes when write it.

Remove them like so:

add_menu_page('Item Display','Item Display','administrator', __FILE__, function(){  });

If you use the quotes, '__FILE__' became a string and so with your code the menu page should be shown when you visit an url similar to:

'http://yoursite.com/wp-admin/admin.php?page=__FILE__'

If you remove the quotes as I’ve done above, your page will respond to an url similar to:

'http://yoursite.com/wp-admin/admin.php?page=/the/full/path/to/your/file.php'

Also note that when you pass a function as 5th param for add_menu_page (just like you do) that function is used for render the page content whatever you use for $menu_slug (4th) param.

If you want use a file to render the page content, this file must be in the WP plugin folder and you have to pass the url of this file relative to the WP plugin folder. E.G.:

add_menu_page('Item Display','Item Display','administrator', 'myplugin/myplugin-admin.php', '');

Using the code above, the content of the admin page is rendered by a file named myplugin-admin.php located in the folder myplugin under the WP plugin folder.

tech