Ticket #3047: get_plugininfo.diff

File get_plugininfo.diff, 3.0 KB (added by forceagainstsomething, 6 years ago)

get_plugininfo() patch

  • wp-includes/functions.php

     
    11731173        die(); 
    11741174} 
    11751175 
     1176/** 
     1177 * Get information about a plugin 
     1178 * 
     1179 * Function called by plugins to get information about themselves.  Currently 
     1180 * plugins can get the following information: 
     1181 * 'base' To get the base directory the plugin is in, releative to the /plugins directory 
     1182 * 'path' To get the absolute path to the plugins base directory 
     1183 * 'url' To get the full URL to the plugin's base directory 
     1184 * 'version' To get the version number for the plugin 
     1185 * Returns FALSE if the information isn't set for the plugin. 
     1186 * 
     1187 * @param       string  $info   The information to get 
     1188 * @return      mixed 
     1189 */ 
     1190function get_plugininfo($info) { 
     1191        global $pluginInfos; 
     1192        $backtrace = debug_backtrace(); 
     1193        if (empty($backtrace[0])) { 
     1194                return false; 
     1195        } 
     1196 
     1197        $ds = DIRECTORY_SEPARATOR; 
     1198        if ('\\' == $ds) { 
     1199                $ds = '\\\\'; 
     1200        } 
     1201         
     1202        // If there is no sub directory, use the plugin's filename instead 
     1203        if (!preg_match('@wp-content' . $ds . 'plugins' . $ds . '(.*)' . $ds . '@U', $backtrace[0]['file'], $matches)) { 
     1204                $plugin = basename($backtrace[0]['file']); 
     1205        } else { 
     1206                $plugin = $matches[1]; 
     1207        } 
     1208 
     1209        if (!isset($pluginInfos[$plugin][$info])) { 
     1210                return false; 
     1211        } 
     1212        return $pluginInfos[$plugin][$info]; 
     1213} 
     1214 
     1215/** 
     1216 * Adds information about a plugin to the $pluginsInfos global variable 
     1217 * 
     1218 * Function that is called prior to including the plugin, which fills up the 
     1219 * $pluginInfos global variable with information about the plugin to be 
     1220 * retrieved with the get_plugininfo() function.  Always returns TRUE. 
     1221 * 
     1222 * @param       string  $plugin The base name of the plugin file 
     1223 * @return      bool 
     1224 */ 
     1225function add_plugininfo($plugin) { 
     1226        global $pluginInfos; 
     1227        $dir_name = dirname($plugin); 
     1228         
     1229        // If the plugin is in it's own sub directory, we'll use that directory 
     1230        // name as the index for the $pluginInfos array.  Otherwise use the 
     1231        // plugin file name. 
     1232        if ($dir_name == '.') { 
     1233                $dir_name = ''; 
     1234                $plugin_base = basename($plugin); 
     1235        } else { 
     1236                $plugin_base = $dir_name; 
     1237        } 
     1238         
     1239        $pluginInfos[$plugin_base]['base'] = $dir_name; 
     1240        $pluginInfos[$plugin_base]['path'] = ABSPATH . 'wp-content/plugins/' . $dir_name; 
     1241        $pluginInfos[$plugin_base]['url'] = get_bloginfo('wpurl') . '/wp-content/plugins/' . $dir_name; 
     1242        preg_match('/version\s?:(.*)/i', file_get_contents(ABSPATH . 'wp-content/plugins/' . $plugin), $matches); 
     1243        $pluginInfos[$plugin_base]['version'] = trim($matches[1]); 
     1244        return true; 
     1245} 
    11761246?> 
  • wp-settings.php

     
    169169        if ( is_array($current_plugins) ) { 
    170170                foreach ($current_plugins as $plugin) { 
    171171                        if ('' != $plugin && file_exists(ABSPATH . 'wp-content/plugins/' . $plugin)) 
     172                                add_plugininfo($plugin); 
    172173                                include_once(ABSPATH . 'wp-content/plugins/' . $plugin); 
    173174                } 
    174175        }