Last active
December 18, 2017 09:10
-
-
Save smeric/21bc774caaef1d47014de877849085a7 to your computer and use it in GitHub Desktop.
WordPress Nemus Slider : PHP Fatal error: Call to a member function add_cap() on a non-object in /PATH/TO/SITE/FOLDER/wp-content/plugins/nemus-slider/nemus-slider.php on line 97
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Nemus Slider | |
* https://wordpress.org/plugins/nemus-slider/ | |
* nemus-slider.php line 75 | |
* Reported issue : https://wordpress.org/support/topic/php-fatal-error-call-to-a-member-function-add_cap-on-a-non-object/ | |
*/ | |
//Capabilities | |
function nemus_slider_add_caps_to_admin() { | |
$caps = array( | |
'read', | |
'read_nemus-slider', | |
'read_private_nemus-sliders', | |
'edit_nemus-sliders', | |
'edit_private_nemus-sliders', | |
'edit_published_nemus-sliders', | |
'edit_others_nemus-sliders', | |
'publish_nemus-sliders', | |
'delete_nemus-sliders', | |
'delete_private_nemus-sliders', | |
'delete_published_nemus-sliders', | |
'delete_others_nemus-sliders', | |
); | |
$roles = array( | |
get_role( 'administrator' ), | |
get_role( 'editor' ), | |
); | |
foreach ($roles as $role) { | |
// If there is no editor role you've got a : | |
// PHP Fatal error: Call to a member function add_cap() on a non-object in /PATH/TO/SITE/FOLDER/wp-content/plugins/nemus-slider/nemus-slider.php on line 97 | |
// So you've got to check before triying to add_cap to an unexisting role : | |
if ( $role ) { | |
foreach ($caps as $cap) { | |
$role->add_cap( $cap ); | |
} | |
} | |
} | |
} | |
add_action( 'after_setup_theme', 'nemus_slider_add_caps_to_admin' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment