NextGEN Gallery – restore lost capabilities

If you accidentally lost capabilities created by NextGEN Gallery this post will give you the tool to restore them. Create restore-ng-caps.php file at the wp-content/mu-plugins/ folder. Insert code quoted below to that file.

function restore_lost_capabilities() {

    global $wp_roles;
    $caps_to_restore = array(
        'NextGEN Gallery overview',
        'NextGEN Use TinyMCE',
        'NextGEN Upload images',
        'NextGEN Manage gallery',
        'NextGEN Manage others gallery',
        'NextGEN Manage tags',
        'NextGEN Edit album',
        'NextGEN Change style',
        'NextGEN Change options',        
        'NextGEN Attach Interface'
    $role = $wp_roles->get_role('administrator');    
    foreach($caps_to_restore as $cap) {
        if (!$role->has_cap($cap)) {
            $role->add_cap($cap, true);

add_action('admin_init', 'restore_lost_capabilities');

Open your blog admin dashboard. Check with User Role Editor that capabilities were restored. That’s it. You may delete restore-ng-caps.php file now. It is the “one-time” but universal helper. You may use it easily, in case you need to add a lot of capabilities. Just replace the content of $caps_to_restore array.

Pay attention that in general WordPress capabilities are in lowercase letters and without spaces inside, e.g. 'edit_others_posts'. Thus, if you use “Show capabilities in human readable form” option, switch it off temporarily in order to see inner presentation of capabilities names valid for use in WordPress API.

P.S. Do not forget that any file with PHP code should start from <?php at the 1st line.
If you have a question – What is that ‘mu-plugins’ folder created for? – you may find the answer here.

You may download ready to use PHP file with code above here.