| 437 | $plugins_dir = @opendir( $dir ); |
| 438 | $plugin_files = array(); |
| 439 | if ( $plugins_dir ) { |
| 440 | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
| 441 | if ( substr($file, 0, 1) == '.' ) |
| 442 | continue; |
| 443 | |
| 444 | if ( substr($file, -4) == '.php' ) |
| 445 | $plugin_files[] = $file; |
| 446 | } |
| 447 | closedir( $plugins_dir ); |
| 448 | } |
| 449 | |
| 450 | if ( empty( $plugin_files ) ) |
| 451 | return false; |
| 452 | |
| 453 | $main_file = ''; |
| 454 | foreach ( $plugin_files as $plugin_file ) { |
| 455 | if ( !is_readable( "$dir/$plugin_file" ) ) |
| 456 | continue; |
| 457 | |
| 458 | $source = $this->get_first_lines( "$dir/$plugin_file", $this->max_header_lines ); |
| 459 | |
| 460 | // stop when we find a file with a plugin name header in it |
| 461 | if ( $this->get_addon_header( 'Plugin Name', $source ) != false ) { |
| 462 | $main_file = "$dir/$plugin_file"; |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | if ( empty( $main_file ) ) |
| 468 | return false; |
| 469 | |