Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal when using rua_get_level_caps() #15

Closed
JoryHogeveen opened this issue Sep 20, 2017 · 10 comments
Closed

Fatal when using rua_get_level_caps() #15

JoryHogeveen opened this issue Sep 20, 2017 · 10 comments

Comments

@JoryHogeveen
Copy link
Contributor

JoryHogeveen commented Sep 20, 2017

Hi Joachim,

I get this error when using rua_get_level_caps():

Fatal error: Uncaught Error: Class 'WPCAObjectManager' not found in /wp-content/plugins/restrict-user-access/level.php:219

Stack trace:
#0 /wp-content/plugins/restrict-user-access/level.php(206): RUA_Level_Manager->_init_metadata() 
#1 /wp-content/plugins/restrict-user-access/level.php(724): RUA_Level_Manager->metadata() 
#2 /wp-content/plugins/restrict-user-access/api/level.php(138): RUA_Level_Manager->get_levels_caps(Array) 
#3 /wp-content/plugins/view-admin-as/modules/class-restrict-user-access.php(551): rua_get_level_caps(495, true) 
#4 /wp-content/plugins/view-admin-as/modules/class-restrict-user-access.php(155): VAA_View_Admin_As_RUA->get_level_caps(495, true) 
#5 /wp-includes/ in /wp-content/plugins/restrict-user-access/level.php on line 219

It has to be a new error since I never encountered it before. It currently happens when I switch to an access level. View Admin As fetches the level caps to set the proper view.

@JoryHogeveen JoryHogeveen changed the title Fatal Fatal when using rua_get_level_caps() Sep 20, 2017
@intoxstudio
Copy link
Owner

Thanks for reporting this!

The wp-content-aware-engine library is loaded pretty early in a page request (plugins_loaded, priority -1). Is there a reason switching levels is done before this?

The problem with calling WPCALoader directly is that it might then load an older version of the library if 2 plugins use it (right now Restrict User Access and Content Aware Sidebars both rely on it).

The "wpca/loaded" action is run immediately after the library has been loaded in "plugins_loaded". Could that hook be used when switching levels?

@JoryHogeveen
Copy link
Contributor Author

JoryHogeveen commented Sep 20, 2017

Actually, I call rua_get_level_caps() after plugins_loaded as aswell, only at a lower priority so I doubt there will be any problem.
I could add a check but I doubt that will be needed:

if ( ! did_action( 'plugins_loaded' ) {
    return;
}

@intoxstudio
Copy link
Owner

intoxstudio commented Sep 20, 2017

Lower than -1? I think a better option would be to just load WPCALoader even before that then, instead of loading it on demand in specific functions. It's actually best to make it load as early as possible (PHP_INT_MIN perhaps?)

Edit: The only reason the library is loaded in a hook is to make sure that it's always the latest version of it that's being used. And plugins_loaded is the first possible hook to use for that.

@JoryHogeveen
Copy link
Contributor Author

JoryHogeveen commented Sep 20, 2017

PHP_INT_MIN is PHP 7.0+ only so that can't be used in WP.
I don't think there would be a problem in loading it in _init_metadata() since this function will only be called once.
Also, WPCALoader::load(); will return if it's already reloaded.

Why would it load an earlier version if it's loaded before plugins_loaded ?

EDIT:
To answer your question. I hook into plugins_loaded at priority -99999 because if a user is switched to another view I need to make sure any plugins and tools use the "switched" user data, not the original user data.

@intoxstudio
Copy link
Owner

intoxstudio commented Sep 22, 2017

I see that now, that's a bummer. I think the problem still is that if another plugin defines a newer version of wp-content-aware-engine but its code is executed after Restrict User Access (I think plugins are executed in alphabetical order?), that plugin might not work properly if it relies on a newer version of the library.

Would it solve it to load the library before -99999? It basically just registers a new post type, and sets up modules to handle conditional logic later (in Restrict User Access used for restrictions). It doesn't do anything outside hooks.

@JoryHogeveen
Copy link
Contributor Author

JoryHogeveen commented Sep 22, 2017

Hmmm, could be a fix, as long as it doesn't do any current_user_can() checks etc.
I could also just include the WPCALoader::load() call in my plugin RUA class and just close this issue, what do you think?

JoryHogeveen added a commit to JoryHogeveen/view-admin-as that referenced this issue Sep 23, 2017
@JoryHogeveen
Copy link
Contributor Author

Added the fix in View Admin As for now since I'm planning to release soon.

@intoxstudio
Copy link
Owner

Sorry for the delay here. No capability checks are made outside any hooks, so it should be safe to load it earlier than View Admin As.

I think that is the only robust solution, as calling WPCALoader::load() directly might cause an earlier version to be loaded if 2 plugins rely on it, and then we will run into other problems later.

@JoryHogeveen
Copy link
Contributor Author

Okidoki!

@intoxstudio
Copy link
Owner

intoxstudio commented Nov 7, 2017

Fixed in d6c09ab, now wp-content-aware-engine is loaded much earlier, priority -999999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants