Change WordPress user roles and capabilities Forums How to or FAQ How to change permission for multiple pages at once Reply To: How to change permission for multiple pages at once

#4587
Vladimir
Keymaster

Hi,

It’s not possible inside URE Pro. You have to use PHP code to make this update. Like this:


add_action('admin_init', 'ure_content_view_add_role');

function ure_content_view_add_role() {
    global $wpdb;
    
    $key = URE_Content_View_Restrictions::content_for_roles;
    $query = "SELECT meta_id
                FROM {$wpdb->postmeta}
                WHERE meta_key='{$key}' AND meta_value='level1'";
    $list = $wpdb->get_col($query);
    if (empty($list)) {
        return;
    }
    foreach ($list as $meta_id) {
        $query = "UPDATE {$wpdb->postmeta} SET meta_value='level1, level2' WHERE meta_id={$meta_id} LIMIT 1";
        $wpdb->query($query);
    }
        
}

This code takes all posts and pages for which content view access roles set to ‘level1’ and replaces ‘level1’ with the list of roles: ‘level1, level2’.

1. Create a fresh database backup
2. Place this code as a separate .php file into wp-content/mu-plugin/ folder as a Must Use plugin.
3. Open any page under yoursite/wp-admin
4. Remove this .php file from wp-content/mu-plugin/ folder.
5. Check the results.

Code will be more complex if you need to make changes for the pages only and do not touch any posts which can have the same role in view permissions.