Support » Fixing WordPress » Broken Plugin, unexpected T_function

  • Resolved bouncebackdata1


    There is only one plugin I can find for an airport or flight school to display the current weather conditions and I would love to get it working. The developer seems to not exist anymore, so maybe someone on here can help. I get the following error whenever I try to activate the plugin: “Parse error: syntax error, unexpected T_FUNCTION in /home/content/63/8624163/html/wp-content/plugins/metar-widget/metar-widget.php on line 62” Line 62 is the last line. It’s a very simple plugin that uses a single php page. Here’s the entire code for the plugin:

    Plugin Name: METAR plugin
    Plugin URI:
    Description: Plugin to include the latest METAR information from NOAA database for any Airport
    Version: 0.1
    Author: Luther Blissett
    Author URI:
    License: GPL3
    class MetarWidget extends WP_Widget
        public function __construct() {
            parent::__construct("metar_widget", "METAR Widget",
                array("description" => "Plugin to inlclude the latest METAR information from NOAA database for any Airport"));
        public function form($instance) {
            $icao = "";
            // if instance is defined, populate the fields
            if (!empty($instance)) {
                $icao = $instance["icao"];
            $tableId = $this->get_field_id("icao");
            $tableName = $this->get_field_name("icao");
            echo '<label for="' . $tableId . '">ICAO</label>';
            echo '<input id="' . $tableId . '" type="text" name="' .
                $tableName . '" value="' . $icao . '"/>';
        public function update($newInstance, $oldInstance) {
            $values = array();
            $values["icao"] = htmlentities($newInstance["icao"]);
            return $values;
        public function widget($args, $instance) {
            $icao = $instance["icao"];
            $fileName = "$icao.TXT";
            $metar = '';
            $fileData = @file($fileName) or die('METAR not available');
            if ($fileData != false) {
            	list($i, $date) = each($fileData);
            	$utc = strtotime(trim($date));
            	$time = date("D, F jS Y g:i A",$utc);
            	while (list($i, $line) = each($fileData)) {
            		$metar .= ' ' . trim($line);
            	$metar = trim(str_replace('  ', ' ', $metar));
    	echo '<div class="widget widget-wrapper" id="' . $args['widget_id'] . '-container">';
    	echo '<div class="widget-title"><b>Current METAR for ' . $icao . '</b></div>';
    	echo $metar . '</div>';
    add_action("widgets_init", function () { register_widget("MetarWidget"); });

    Any help is greatly appreciated,

Viewing 15 replies - 1 through 15 (of 15 total)
  • Drew Jaynes


    WordPress Core Developer

    Hi bouncebackdata1,

    >> Please use if you’re going to post blocks of code in the forums.

    I just activated it without issue on a WordPress 3.4.2. I also noticed the plugin page says it requires a minimum of version 3.4.

    What version of WordPress are you running?

    Hey, I’m running 3.4.2 as well. Is in conflicting with Jquery or something like that?

    I gave you [mod redacted password] so you can take a look if you don’t mind. I tried changing line 62 a few times, it broke my site once and I had to go into the SQL database and disable all the plugins for the site to work again.

    NOTE: Support given through this site is free and voluntary. As such, we usually do not want the burden/liability of being given access to a site. Even more so, PLEASE do not post unsolicited and public login credentials out in the open! Kthx!

    Moderator bcworkz


    How about PHP version? Anonymous functions are only supported with v5.3. If earlier, name the function and reference it in add_action().

    I was running 5.2, but I upgraded to 5.3 and I get the same error. I’m using the Karma theme, I’m guessing there must be some conflict with something in there. Anyone have any troubleshooting tips?

    I just tried activating it on another karma theme site and I get the same error. I tried activating it on an avada theme site and it worked. I’m not sure how to hunt down the problem.

    Moderator bcworkz


    You should probably still ditch the anonymous function for the sake of broader compatibility. That could get it working, you can worry about why anonymous functions aren’t working later.

    How do I do that?

    I’m sorry, I don’t know a lot about programming, but I can usually figure things out with some direction.

    Can anyone tell me how to “ditch the anonymous function”?

    The last line of your code…

    add_action(“widgets_init”, function () { register_widget(“MetarWidget”); });

    see the “function () {}” that is an anonymous function, it’s not named.

    try using…

    add_action( ‘widgets_init’, create_function( ”, ‘register_widget( “MetarWidget” );’ ) );

    Finally! it works! Thank you very much for the help.

    you’re quite welcome =)

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Broken Plugin, unexpected T_function’ is closed to new replies.