Ticket #2781 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

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

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

Description

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

Attachments

2781.diff (1.0 kB) - added by westi on 03/31/07 11:39:27.
Fix for get_plugin_data

Change History

06/03/06 19:16:16 changed by Denis-de-Bernardy

should likely be:

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

06/03/06 19:17:47 changed by Denis-de-Bernardy

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

06/03/06 19:27:02 changed by Denis-de-Bernardy

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);
}

06/03/06 19:31:40 changed by Denis-de-Bernardy

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);
}

03/31/07 10:44:16 changed by Nazgul

  • status changed from new to closed.
  • resolution set to worksforme.

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

Feel free to reopen this if you have additional information.

03/31/07 11:37:50 changed by westi

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone set to 2.2.

03/31/07 11:39:06 changed by westi

  • 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.

03/31/07 11:39:27 changed by westi

  • attachment 2781.diff added.

Fix for get_plugin_data

03/31/07 11:42:23 changed by westi

  • keywords set to has-patch commit.

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.

04/12/07 21:43:11 changed by rob1n

  • owner changed from westi to rob1n.

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

04/12/07 21:43:40 changed by rob1n

  • status changed from new to closed.
  • resolution set to fixed.

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