Pat Gilmour
asked 5 years ago

Hi,
I’m trying to install DW Question Answer on WP 3.8.1 on my WPEngine Staging server but I’m getting this error:

Fatal error: Call to a member function add_cap() on a non-object in /nas/wp/www/staging/*my-site-account-name*/wp-content/plugins/dw-question-answer/inc/roles.php on line 192

I disabled all plugins and still got the error. Any suggestions about what else I can try?
Thanks!

Pat Gilmour
replied 5 years ago

The code at line 192 is:

$role->add_cap( ‘dwqa_can_’ . $key . ‘_question’ );

Part of:

$role = get_role( $role_name );
foreach ($perms[‘question’] as $key => $val) {
if( isset($value[$role_name][‘question’][$key]) && $value[$role_name][‘question’][$key] ) {

$role->add_cap( ‘dwqa_can_’ . $key . ‘_question’ );

} else {
$role->remove_cap( ‘dwqa_can_’ . $key . ‘_question’ );
}
}

Looks like if I comment it out, then asking questions is going to get screwed up – right?

Pat Gilmour
replied 5 years ago

If I comment out the lines 191-211 in inc/roles.php it installs.

Theses are the lines that add capabilities with add_cap()

I don’t really understand it, but could it be a roles based issue?

1 Answers
BigHug
answered 5 years ago

Hi @patgillmour,
Please add these lines of code below line number 189:

 if( ! $role ) 
continue;

It will fix your problem, and we will add this fix on next version so you can install the update version normally.
Regards.

Pat Gilmour
replied 5 years ago

Many thanks, BigHug.

I had commented out those lines and got it to install then uncommented them. But good to know there is a more “official” hack.

Powered by DW Question & Answer Pro