Class 'Pressbooks\\Book' not found

Hi,

I’m getting this error thrown in /var/log/apache2/error.log after using the admin panel on a fresh Pressbooks install with a handful of plugins and themes (including the pressbooks-books theme):

PHP Fatal error: Class 'Pressbooks\\Book' not found in /var/www/some/path/wordpress/wp-content/plugins/pressbooks-textbook/inc/admin/class-textbookadmin.php on line 46

Any ideas? Searching the forum doesn’t yield relevant topics.

Thanks,
Etienne

This appears to be a bug with Pressbooks Textbook. FYI @brad.

Etienne–I’m looking at the GitHub version of the file in question: https://github.com/BCcampus/pressbooks-textbook/blob/1838a9cb8dc4afb524afa17ec6f10d78a4445b6c/inc/admin/class-textbookadmin.php#L46. I’m wondering if the issue might not be the double forward slash in the class in your PHP error message? Where’s that coming from?

I assume the backslash gets escaped in the logs. The code is unchanged on our machine:

if ( \Pressbooks\Book::isBook() ) {

-Etienne

Oh sorry–I meant whatever was calling the class 'Pressbooks\\Book'. To my untrained eye, the PHP error seems to be indicating that something appears to be making a call for that undefined/nonexistent class, and the plugin appears to have a reference to ‘Pressbooks\Book’.

It’s a valid class and method…

Yes–sorry for more confusion. My post had two forward slashes in it:
Pressbooks\\Book but it got stripped out. My suspicion was that something in Etienne’s stack was calling Pressbooks\\Book which is an invalid class when it was supposed to be calling Pressbooks\Book which is a valid class.

Your autoloader file is missing? See Autoloader for more info: https://docs.pressbooks.org/upgrading/

Thanks, Dac. @etienne, possibly related issue on our Unizin-hosted production instance documented here: SASS Error with Luther. Happy to file a support ticket directly with you if helpful?

Because of timestamps, or some cosmic mystery. Pressbooks Textbook is being loaded before Pressbooks.

WordPress Plugins are loaded in random order.

Other plugins that depend on pressbooks (before pressbooks is loaded) should init the autoloader.

The function to do this is in in: https://github.com/pressbooks/pressbooks/blob/dev/compatibility.php

function pb_init_autoloader() {
	static $registered = false;
	if ( ! $registered ) {
		\HM\Autoloader\register_class_path( 'Pressbooks', __DIR__ . '/inc' );
		$registered = true;
	}
}

I believe the issue is the way the compatibility function is coded:

} elseif ( ! pb_meets_minimum_requirements() ) { /

I don’t think line 75 is ever called? If it were, it would trigger pb_init_autoloader

1 Like

Hi all, I just heard backchannel from Brad Payne. He’s our for a couple of weeks, but suggested that if we opened up a ticket in github in the pressbooks-textbook repo, his colleague Alex Paredes will be notified and should be able to help us. @etienne, is that something you’d be willing to do?

Yes, but before we do that we’re going to look at our server configs to make sure the dependencies are right as they should be. More soon!

Etienne