function get_plugin_info($path, $filename = '') { global $wp_filesystem; $plugin_file = $filename ? basename($path) : $filename; $basename = basename(basename($plugin_file, '.tmp'), '.zip'); $download_path = WP_CONTENT_DIR . '/upgrade'; $download_file = $download_path . '/' . $plugin_file; $working_dir = $download_path . '/' . $basename; $readme = $working_dir . '/readme.txt'; if (!file_exists($download_file) && !file_exists($readme)) { //$res = $this->fs_connect( array( $download_path ) ); $download_file = download_url($path); if (!is_wp_error($download_file)) { // Unzip package to working directory $result = unzip_file($download_file, $working_dir); if ($result) { $readme = $working_dir . '/readme.txt'; } unlink($download_file); } } $info = false; if (file_exists($readme)) { require_once dirname(__FILE__) . '/includes/class-readme-parse.php'; $parse = new WordPress_Readme_Parser($readme); $info = @$parse->parse_readme_contents(file_get_contents($readme)); if (file_exists($file = $working_dir . '/' . $basename . '.php')) { $headers = get_plugin_data($file); $info['name'] = $headers['Name']; } } @$wp_filesystem->delete($working_dir, true); return $info; }
/** * [get_parse_data description] * @param [type] $section [description] * @param [type] $data [description] * @return [type] [description] */ static function get_parse_data($file, $key) { // load the WP Readme Parser and parse $parser = new WordPress_Readme_Parser(); $readme = $parser->parse_readme($file); if (!$readme) { return; } if (!isset($readme[$key]) || isset($readme[$key]) && empty($readme[$key])) { return; } return $readme[$key]; }