Php fatal error

I am getting this error when I am running the PHP code:

Fatal error: Call to a member function getAttribute() on a non-object in /home/polar/public_html/wp-content/plugins/wpgplus/gplus.php on line 68

Here is the block of code:

 // return array (string postdata, string postaction)
	$my_form = $doc->getElementsByTagName('form');
	if($my_form) {
		$my_action_url = $my_form->item(5)->getAttribute('action');
		return array(wpgplus_tidy($toreturn), $doc->getElementsByTagName('form')->item(0)->getAttribute('action'));
	} else {
		wpgplus_debug(date("Y-m-d H:i:s",time())." : Did not get a form to post login to\
");
		wp_die('WPGPlus did not get a form in the response from google+'); 
	}	

This is the exact line #68:

$my_action_url = $my_form->item(5)->getAttribute('action');

This is the full code:

http://pastebin.com/E7f2EW7b

Can anyone please help me as to why this is going on? How to fix it?

@boobymonster

Try this:



// line 67
   echo '</pre>';
      var_dump( $my_form );
   echo '</pre>';
die;

   $my_action_url = $my_form->item(5)->getAttribute('action');


…and let us know the results.

Still testing out the code. Will let you know soon.

Looks to me like the form does not exist.

$buf = wp_remote_get('https://plus.google.com/',$my_args);

Upon navigating to: https://plus.google.com

There is no sign of a form in the mark-up.


$my_form = $doc->getElementsByTagName('form');
if($my_form) {
} else { // this will never happen
}

Also, the conditional here is always going to evaluate to true. The method being called returns an instance of DOMNodeList, which will evaluate to true even when empty.

Off Topic:

Good example how people who use/write WP plugins have no idea what the hell they doing.

Putting that aside what should be done is to check the amount of items in the DOMNodeList.

One should avoid modifying contributed code but you should submit a patch to fix that issue. Which would be:


$my_form = $doc->getElementsByTagName('form');
if($my_form->length > 5) {
  ...
} else {
  ...
}

Which doesn’t entirely fix your problem considering you will now see the error for no form is present. So debugging process at that point is determining why the form doesn’t exist. It could be entirely feasible that google has updated that page and no longer has a form. In that case the plugin is out of date. You would need to go in and make the necessary changes to have it function. Though at that point who knows what other demons might exist.

First step I would take is asking around on the WP forum about why a form wouldn’t be showing up. It is likely other people have ran into the issue.

Works only with Google 2-step auth turned off AND mobile terms of service accepted

Does that mean anything to you. That might be the problem.

Does google+ not have an API like Facebook? What I’m seeing there is very unideal if an API exists of some type. If not than the general concept fits the bill.

@John_Betong: So far no problems.

@oddz: I asked around in the Wordpress forums already but no response and the author of the plugin isn’t around anymore neither. Google most likely already updated everything because they support pages for businesses now.

Does that mean anything to you. That might be the problem.

Yeah the plugin works by emulating the mobile connection to Google Plus to post to the stream.

Does google+ not have an API like Facebook?

No they didn’t have it, only very recently was there an API release but this is an unofficial one but it allows posting to stream:

The author of the plugin is gone, I been trying to get this to work but it is difficult.

John_Betong I get this error now when posting:

object(DOMNodeList)#113 (0) { }