Cannot load media and I get “PHP Warning: Invalid argument supplied for foreach(”

if I don’t have active debug mode, I can’t see any media in back end (in Media menu or even as in created gallery in a post editor). When I turn on debug mode:

define('WP_DEBUG', true);

// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);

// Disable display of errors and warnings
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

I’ve got following error. But system file plugin.php ends at line 992 or so. Any ideas what can cause this problem and how to solve it? Thanks a lot, it’s my custom theme.

[29-Apr-2015 22:23:50 UTC] PHP Warning:  Invalid argument supplied for foreach() in /data/web/virtuals/51889/virtual/www/domains/demo.kybernaut.cz/detsky-svet-masa/wp-admin/includes/plugin.php on line 1422
[29-Apr-2015 22:23:50 UTC] PHP Warning:  Invalid argument supplied for foreach() in /data/web/virtuals/51889/virtual/www/domains/demo.kybernaut.cz/detsky-svet-masa/wp-admin/includes/plugin.php on line 1422
[29-Apr-2015 22:23:50 UTC] PHP Warning:  Invalid argument supplied for foreach() in /data/web/virtuals/51889/virtual/www/domains/demo.kybernaut.cz/detsky-svet-masa/wp-admin/includes/plugin.php on line 1422
[29-Apr-2015 22:23:51 UTC] PHP Warning:  Invalid argument supplied for foreach() in /data/web/virtuals/51889/virtual/www/domains/demo.kybernaut.cz/detsky-svet-masa/wp-admin/includes/plugin.php on line 1422
[29-Apr-2015 22:23:51 UTC] PHP Warning:  Invalid argument supplied for foreach() in /data/web/virtuals/51889/virtual/www/domains/demo.kybernaut.cz/detsky-svet-masa/wp-admin/includes/plugin.php on line 1422
[29-Apr-2015 22:23:51 UTC] PHP Warning:  Invalid argument supplied for foreach() in /data/web/virtuals/51889/virtual/www/domains/demo.kybernaut.cz/detsky-svet-masa/wp-admin/includes/plugin.php on line 1422

It looks like this part is causing troubles:

//remove from menu
function remove_posts_menu() {
    remove_menu_page('edit.php');
    remove_menu_page('edit.php?post_type=page');
    remove_menu_page('edit-comments.php' );
}
add_action('admin_init', 'remove_posts_menu');

Solutions Collecting From Web of "Cannot load media and I get “PHP Warning: Invalid argument supplied for foreach(”"

@TheDeadMedic was right, in my second code snippet, admin_init should be admin_menu. That solved my problem, thanks a lot to all of you!

Corrected code:

//remove from menu
function remove_posts_menu() {
    remove_menu_page('edit.php');
    remove_menu_page('edit.php?post_type=page');
    remove_menu_page('edit-comments.php' );
}
add_action('admin_menu', 'remove_posts_menu');