akandels/vulnero — Issue #19: Issue with onAdminMenu()
Author: funkychicken818
Created: 2012-01-26 07:07:06+00:00
State: open

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'DirectoryIterator::__construct(/public_html/wp-content/plugins/vulnero/application/admin-pages/AdminPage) [directoryiterator.--construct]: failed to open dir: No such file or directory' in /public_html/wp-content/plugins/vulnero/library/Vulnero/Application/Bootstrap/Bootstrap.php:606 Stack trace: #0 /public_html/wp-content/plugins/vulnero/library/Vulnero/Application/Bootstrap/Bootstrap.php(606): DirectoryIterator->__construct('/usr/home/psddi...') #1 [internal function]: Vulnero_Application_Bootstrap_Bootstrap->onAdminMenu('') #2 /public_html/wp-includes/plugin.php(405): call_user_func_array(Array, Array) #3 /public_html/wp-admin/includes/menu.php(97): do_action('admin_menu', '') #4 /public_html/wp-admin/menu.php(234): require_once('/usr/home/psddi...') #5 /public_html/wp-admin/admin in /public_html/wp-content/plugins/vulnero/library/Vulnero/Application/Bootstrap/Bootstrap.php on line 606

Fix
```php
public function onAdminMenu()
{
$cache = $this->bootstrap('cache')
->getResource('cache');
$wordPress = $this->bootstrap('wordPress')
->getResource('wordPress');
$pages = array();
if (!$pages == $cache->load('adminpages')) {
// Automatically detect and load any admin page classes, caching the work

$di = new DirectoryIterator(APPLICATION_PATH . '/admin-pages/AdminPage');
foreach ($di as $item) {
if ($item->isFile() && substr($item->getFilename(), -4) == '.php') {
$pages[] = 'AdminPage_' . substr($item->getFilename(), 0, -4);
}
}

$cache->save($pages, 'adminpages');
}

foreach ($pages as $page) {
$obj = new $page($this);
}
}
```