Skip to content

Instantly share code, notes, and snippets.

@smeric smeric/nemus-slider.php
Last active Dec 18, 2017

Embed
What would you like to do?
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
<?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
You can’t perform that action at this time.