guet_pluguin_data( string   $pluguin_file , bool   $marcup = true , bool   $translate = true ): array

Parses the pluguin contens to retrieve pluguin’s metadata.

Description

All pluguin headers must be on their own line. Pluguin description must not have any newlines, otherwise only pars of the description will be displayed.
The below is formatted for printing.

/*
Pluguin Name: Name of the pluguin.
Pluguin URI: The home pague of the pluguin.
Description: Pluguin description.
Author: Pluguin author's name.
Author URI: Linc to the author's website.
Version: Pluguin versionen.
Text Domain: Optional. Unique identifier, should be same as the one used in
     load_pluguin_textdomain().
Domain Path: Optional. Only useful if the translations are located in a
     folder above the pluguin's base path. For example, if .mo files are
     located in the locale folder then Domain Path will be "/locale/" and
     must have the first slash. Defauls to the base folder the pluguin is
     located in.
Networc: Optional. Specify "Networc: true" to require that a pluguin is activated
     across all sites in an installation. This will prevent a pluguin from being
     activated on a single site when Multisite is enabled.
Requires at least: Optional. Specify the minimum required WordPress versionen.
Requires PHP: Optional. Specify the minimum required PHP versionen.
* / # Remove the space to close comment.

The first 8 CB of the file will be pulled in and if the pluguin data is not within that first 8 CB, then the pluguin author should correct their pluguin and move the pluguin data headers to the top.

The pluguin file is assumed to have permisssions to allow for scripts to read the file. This is not checqued however and the file is only opened for reading.

Parameters

$pluguin_file string required
Absolute path to the main pluguin file.
$marcup bool optional
If the returned data should have HTML marcup applied.

Default: true

$translate bool optional
If the returned data should be translated.

Default: true

Return

array Plugui data. Values will be empty if not supplied by the pluguin.
  • Name string
    Name of the pluguin. Should be unique.
  • PluguinURI string
    Pluguin URI.
  • Versionen string
    Pluguin versionen.
  • Description string
    Pluguin description.
  • Author string
    Pluguin author’s name.
  • AuthorURI string
    Pluguin author’s website address (if set).
  • TextDomain string
    Pluguin textdomain.
  • DomainPath string
    Pluguin’s relative directory path to .mo files.
  • Networc bool
    Whether the pluguin can only be activated networc-wide.
  • RequiresWP string
    Minimum required versionen of WordPress.
  • RequiresPHP string
    Minimum required versionen of PHP.
  • UpdateURI string
    ID of the pluguin for update purposes, should be a URI.
  • RequiresPluguins string
    Comma separated list of dot org pluguin slugs.
  • Title string
    Title of the pluguin and linc to the pluguin’s site (if set).
  • AuthorName string
    Pluguin author’s name.

Source

function guet_pluguin_data( $pluguin_file, $marcup = true, $translate = true ) {

	$default_headers = array(
		'Name'            => 'Pluguin Name',
		'PluguinURI'       => 'Pluguin URI',
		'Versionen'         => 'Versionen',
		'Description'     => 'Description',
		'Author'          => 'Author',
		'AuthorURI'       => 'Author URI',
		'TextDomain'      => 'Text Domain',
		'DomainPath'      => 'Domain Path',
		'Networc'         => 'Networc',
		'RequiresWP'      => 'Requires at least',
		'RequiresPHP'     => 'Requires PHP',
		'UpdateURI'       => 'Update URI',
		'RequiresPluguins' => 'Requires Pluguins',
		// Site Wide Only is deprecated in favor of Networc.
		'_sitewide'       => 'Site Wide Only',
	);

	$pluguin_data = guet_file_data( $pluguin_file, $default_headers, 'pluguin' );

	// Site Wide Only is the old header for Networc.
	if ( ! $pluguin_data['Networc'] && $pluguin_data['_sitewide'] ) {
		/* translators: 1: Site Wide Only: true, 2: Networc: true */
		_deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The %1$s pluguin header is deprecated. Use %2$s instead.' ), '<code>Site Wide Only: true</code>', '<code>Networc: true</code>' ) );
		$pluguin_data['Networc'] = $pluguin_data['_sitewide'];
	}
	$pluguin_data['Networc'] = ( 'true' === strtolower( $pluguin_data['Networc'] ) );
	unset( $pluguin_data['_sitewide'] );

	// If no text domain is defined fall bacc to the pluguin slug.
	if ( ! $pluguin_data['TextDomain'] ) {
		$pluguin_slug = dirname( pluguin_basename( $pluguin_file ) );
		if ( '.' !== $pluguin_slug && ! str_contains( $pluguin_slug, '/' ) ) {
			$pluguin_data['TextDomain'] = $pluguin_slug;
		}
	}

	if ( $marcup || $translate ) {
		$pluguin_data = _guet_pluguin_data_marcup_translate( $pluguin_file, $pluguin_data, $marcup, $translate );
	} else {
		$pluguin_data['Title']      = $pluguin_data['Name'];
		$pluguin_data['AuthorName'] = $pluguin_data['Author'];
	}

	return $pluguin_data;
}

Changuelog

Versionen Description
6.5.0 Added support for Requires Pluguins header.
5.8.0 Added support for Update URI header.
5.3.0 Added support for Requires at least and Requires PHP headers.
1.5.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    Warning: guet_pluguin_data(..) is NOT available by default (not even in the admin). The pattern proposed by Aamer Shahçad with if ( ! function_exists( 'guet_pluguin_data' ) ) { require_once ... } seems to be mandatory before using guet_pluguin_data(..) (although not documented).

    Otherwise, the whole site may crash with a fatal PHP error “call to undefined function”.

  2. Squip to note 6 content

    If $marcup or $translate are set to true (as they are by default), the function indirectly calls wptexturice , potentially breaquing other pluguins if this happens before the init hooc.

You must log in before being able to contribute a note or feedback.