WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#2781 closed defect (bug) (fixed)

Notice: Undefined variable: template in c:\Inetpub\wwwroot\wp\wp-admin\admin-functions.php on line 1504

Reported by: Denis-de-Bernardy Owned by: rob1n
Milestone: 2.2 Priority: normal
Severity: normal Version: 2.0.2
Component: Administration Keywords: has-patch commit
Focuses: Cc:

Description

Notice: Undefined variable: template in c:\Inetpub\wwwroot\wp\wp-admin\admin-functions.php on line 1504

Attachments (1)

2781.diff (1.0 KB) - added by westi 7 years ago.
Fix for get_plugin_data

Download all attachments as: .zip

Change History (11)

comment:1 Denis-de-Bernardy8 years ago

should likely be:

	return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version);

comment:2 Denis-de-Bernardy8 years ago

also of interest, in the same area:

Notice: Undefined offset: 1 in c:\Inetpub\wwwroot\wp\wp-admin\admin-functions.php on line 1489

Notice: Undefined offset: 1 in c:\Inetpub\wwwroot\wp\wp-admin\admin-functions.php on line 1491

Notice: Undefined offset: 1 in c:\Inetpub\wwwroot\wp\wp-admin\admin-functions.php on line 1494

Notice: Undefined offset: 1 in c:\Inetpub\wwwroot\wp\wp-admin\admin-functions.php on line 1498

Notice: Undefined offset: 1 in c:\Inetpub\wwwroot\wp\wp-admin\admin-functions.php on line 1499

Notice: Undefined offset: 1 in c:\Inetpub\wwwroot\wp\wp-admin\admin-functions.php on line 1494

comment:3 Denis-de-Bernardy8 years ago

function get_plugin_data($plugin_file) {
	$plugin_data = implode('', file($plugin_file));
	preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);
	preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);
	preg_match("|Description:(.*)|i", $plugin_data, $description);
	preg_match("|Author:(.*)|i", $plugin_data, $author_name);
	preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
	if (preg_match("|Version:(.*)|i", $plugin_data, $version))
		$version = $version[1];
	else
		$version = '';

	$description = isset($description[1]) ? wptexturize($description[1]) : '';

	$name = isset($plugin_name[1]) ? $plugin_name[1] : '';
	$name = trim($name);
	$plugin = $name;
	if (isset($plugin_uri[1]) && '' != $plugin_uri[1] && '' != $name) {
		$plugin = '<a href="'.$plugin_uri[1].'" title="'.__('Visit plugin homepage').'">'.$plugin.'</a>';
	}

	if (isset($author_name[1]) && isset($author_uri[1]) && '' == $author_uri[1]) {
		$author = $author_name[1];
	} elseif (isset($author_name[1]) && isset($author_uri[1])) {
		$author = '<a href="'.$author_uri[1].'" title="'.__('Visit author homepage').'">'.$author_name[1].'</a>';
	} else {
		$author = '';
	}

	return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version);
}

comment:4 Denis-de-Bernardy8 years ago

likewise:

function get_theme_data($theme_file) {
	$theme_data = implode('', file($theme_file));
	preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name);
	preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri);
	preg_match("|Description:(.*)|i", $theme_data, $description);
	preg_match("|Author:(.*)|i", $theme_data, $author_name);
	preg_match("|Author URI:(.*)|i", $theme_data, $author_uri);
	preg_match("|Template:(.*)|i", $theme_data, $template);
	if ( preg_match("|Version:(.*)|i", $theme_data, $version) )
		$version = $version[1];
	else
		$version ='';
	if ( preg_match("|Status:(.*)|i", $theme_data, $status) )
		$status = $status[1];
	else
		$status ='publish';

	$description = isset($description[1]) ? wptexturize($description[1]) : '';

	$name = isset($theme_name[1]) ? $theme_name[1] : '';
	$name = trim($name);
	$theme = $name;

	if ( isset($author_name[1]) && isset($author_uri[1]) && '' == $author_uri[1] ) {
		$author = $author_name[1];
	} elseif (isset($author_name[1]) && isset($author_uri[1])) {
		$author = '<a href="' . $author_uri[1] . '" title="' . __('Visit author homepage') . '">' . $author_name[1] . '</a>';
	} else {
		$author = '';
	}

	$template = isset($template[1]) ? $template[1] : '';

	return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Status' => $status);
}

comment:5 Nazgul7 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

I'm unable to reproduce this on my 2.0.x blog.

Feel free to reopen this if you have additional information.

comment:6 westi7 years ago

  • Milestone set to 2.2
  • Resolution worksforme deleted
  • Status changed from closed to reopened

comment:7 westi7 years ago

  • Owner changed from anonymous to westi
  • Status changed from reopened to new

I can see this.

get_plugin_data has dodgy vars as it looks very like a copy and paste error from loading template_data.

Attaching a patch to fix this and make it return a few extra bits of usefull info for plugin authors to be able to use.

westi7 years ago

Fix for get_plugin_data

comment:8 westi7 years ago

  • Keywords has-patch commit added

Attached patch removes the use of an undefined variable from the return of get_plugin_data and brings in some of the smaller changes from #3047

Basically you can now easily access off of the plugin info the following extra data:

[PluginURI] => Straight from the comment in the plugin file.
[AuthorURI] => Straight from the comment in the plugin file.
[URL] => URL of the folder containing the plugin - to make creating urls to suborinate files easy
[Path] => Absolute path of the folder containing the plugin - to make including easy etc.

comment:9 rob1n7 years ago

  • Owner changed from westi to rob1n

I'm only going to commit the undefined variable fix -- the rest can go along with #3047.

comment:10 rob1n7 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [5259]) Take out undefined variable. fixes #2781

Note: See TracTickets for help on using tickets.