get_results("select ID from $wpdb->posts;", ARRAY_A);
$new_ids = array();
foreach($db_ids as $db_id) {
// set them all to 0
$new_ids[$db_id[ID]] = 0;
}
$keys = array_keys($_POST);
foreach ($keys as $key) {
// set only the ones in the $_POST to 1 (restricted)
$new_ids[$key] = 1;
}
$keys = null;
$keys = array_keys($new_ids);
foreach ($keys as $key) {
// update all the posts (pages)
$wpdb->query("update $wpdb->posts set restricted=".$new_ids[$key]." where ID=$key");
}
?>
Preferences Updated
Page Restriction Options
}
// writes out the pages table
// stolen from the 'manage pages' section in the admin section
// I rearranged the code below but only added the part about page restriction
function page_rows2( $parent = 0, $level = 0, $pages = 0 ) {
global $wpdb, $class, $user_level, $post;
if (!$pages)
$pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static' ORDER BY menu_order");
if ($pages) {
foreach ($pages as $post) { start_wp();
if ($post->post_parent == $parent) {
$post->post_title = wp_specialchars($post->post_title);
$pad = str_repeat('— ', $level);
$id = $post->ID;
$class = ('alternate' == $class) ? '' : 'alternate';
?>
ID; ?>
post_modified); ?>
$authordata->user_level) or ($user_login == $authordata->user_login)) { ?>
" />
get_var("select restricted from $wpdb->posts where ID=".$wp_query->post->ID);
// is this a restricted page?
// if it's not, we don't care
if ($isrestricted == 1) {
global $user_ID;
get_currentuserinfo();
// is user already logged in?
if ('' == $user_ID) {
auth_redirect();
} else {
// This is checking to see if the Page Access plugin is installed
$page_access = 0;
foreach(get_settings('active_plugins') as $k => $plugin) {
if (strcmp(strtolower($plugin), "page-access.php") == 0) {
$page_access = 1;
break;
}
}
// This code will only be used if the Page Access plugin is installed.
if($page_access) {
global $wpdb, $table_prefix, $wp_query;
// get the unique pages that this user is allowed to access from all the
// groups that they belong to
$pages = $wpdb->get_results("
select distinct page
from wp_page_access_group_line_item
inner join wp_page_access_user_line_item
using(group_id)
where wp_page_access_user_line_item.user_id = $user_ID
order by page;
", ARRAY_A);
$access = 0;
$this_page = $wp_query->post->ID;;
// is this page one of the allowed pages?
foreach ($pages as $k => $v) {
if($this_page == $v['page']) { $access = 1; break; }
}
// if no access, redirect to the "you have no access" page
if(!$access) {
$no_access_page = get_option('no_access_page');
// if you have a redirect page saved in the Page Access settings, then redirect there
if ($no_access_page) {
wp_redirect($no_access_page);
// if not, redirect to the main page
// must redirect somewhere, otherwise it would just let you into the page!
} else {
wp_redirect(get_bloginfo('url'));
}
}
}
}
}
}
}
// only update the db if it's the first activation of the plugin
if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
add_action('init', 'page_restriction_db_install');
}
add_action('wp_head', 'check_the_user');
add_action('admin_menu', 'page_restriction');
?>