WordPress.org

Make WordPress Core

Ticket #5651: 5651.r6603.diff

File 5651.r6603.diff, 2.5 KB (added by darkdragon, 10 years ago)

Adds phpdoc comments along with new function to get plugin contents

  • plugin.php

     
    11<?php
     2/**
     3 * WordPress Plugin Administration API
     4 *
     5 * @package WordPress
     6 * @subpackage Administration
     7 */
    28
     9/**
     10 * plugin_get_contents() - Pull in the plugin file contents to get the retrieve just the Plugin Data
     11 *
     12 * Uses file_get_contents() if available, else implements file_get_contents()
     13 * for plugins.
     14 *
     15 * There is a filter hook for getting the amount of bytes to retrieve. In the
     16 * event that the plugins aren't working, please create a plugin which sets
     17 * the hook contents to a higher range until all of the plugins' information
     18 * come up, then report back to the link below, so that the change can be made
     19 * for everyone else. Make sure to reopen.
     20 *
     21 * @link http://trac.wordpress.org/ticket/5651 Ticket for this functions being.
     22 *
     23 * @since 2.5.0
     24 * @uses apply_filters() Calls 'plugin_get_contents' hook to get the bytes
     25 *              to retrieve from the file.
     26 *
     27 * @param string $plugin_file Path to plugin file
     28 * @return string File contents retrieved
     29 */
     30function plugin_get_contents($plugin_file) {
     31        $bytes = apply_filters('plugin_get_contents', 1024);
     32        if( function_exists( 'file_get_contents' ) )
     33                return file_get_contents($plugin_file, null, null, 0, $bytes);
     34
     35        $fp = fopen($plugin_file);
     36        $contents = fread( $fp, $bytes );
     37        fclose($fp);
     38        return $contents;
     39}
     40
     41/**
     42 * get_plugin_data() - Parse the plugin contents to retrieve the plugin's data
     43 *
     44 * While this function has only existed since WordPress 2.5, the functionality has
     45 * existed in WordPress for longer.
     46 *
     47 * Plugin data contains the following:
     48 *              'Name' - Name of the plugin, should be unique.
     49 *              'Title' - Title of the plugin and the link to the plugin's web site.
     50 *              'Description' - Description of what the plugin does and/or notes from the author.
     51 *              'Author' - The author's web site and name.
     52 *              'Version' - The version of the plugin in the file.
     53 *
     54 * @since 2.5.0
     55 *
     56 * @param string $plugin_file Full Plugin Path
     57 * @return array Plugin's data
     58 */
    359function get_plugin_data( $plugin_file ) {
    4         $plugin_data = implode( '', file( $plugin_file ));
     60        $plugin_data = plugin_get_contents($plugin_file);
    561        preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $plugin_name );
    662        preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $plugin_uri );
    763        preg_match( '|Description:(.*)$|mi', $plugin_data, $description );