My favorites | Sign in
Project Logo
                
Search
for
Updated Apr 02, 2007 by Tiago.Pocinho
Labels: Featured, Phase-Deploy
Instructions  
Installation and Configuration instructions

Installation

Simple Installation

After downloading this plugin, extract the directory "wp-group-restriction".

Go to the Wordpress back-office and activate the plugin. This will create the needed tables in the database.

Advanced Installation

To filter out access from the front office, update your theme to call:

  if(class_exists("userGroups")){
    $pagesToExclude = userGroups::getPagesToExclude();
  }

and add the returning value to

wp_list_pages("exclude=" . $pagesToExclude . "&sort_column=menu_order&depth=1&title_li=");

This allows to hide pages the user has no reading access. Notice that this code should be between PHP tags: <?php and ?>.

For Wordpress < 2.1

For Wordpress versions prior to 2.1, a hack is needed to filter out the pages the current user can edit from the pages list (Manage Pages) in the backoffice. In order to do so, replace the line:

wordpress\wp-admin\edit-pages.php Line 27

else
  $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static'");

by

else{
  /*plugin tables*/
  $table_groupsPage = $table_prefix . "ug_GroupsPage";
  $table_groups = $table_prefix . "ug_Groups";
  $table_groupsUsers = $table_prefix . "ug_GroupsUsers";
  
  $query = "SELECT * FROM $table_groupsUsers tgu
              WHERE tgu.id_user='$user_ID';";
              
  $results = $wpdb->get_results( $query );
  
  $stringGrupos;
  $cont = 0;
  if(isset($results))
  foreach ($results as $res){
    if($cont > 0){
      $stringGrupos .= " OR ";
    }
    $stringGrupos .= "gp.id_group='$res->id_group' ";
    $cont ++;
  }
  if($cont > 0){
    $stringGrupos ="SELECT p.* from ".$wpdb->posts." p, $table_groupsPage gp
              WHERE p.ID=gp.id_page and ( $stringGrupos )
              UNION
              ";
    
  }
  //if the user is not an administrator or if the table does not exist
  if($user_level < 8 && $wpdb->get_var("show tables like '$table_groupsPage'") != $table_groupsPage){ 
    
    $query = "$stringGrupos
              SELECT * from wp_posts
              WHERE post_status='static' and (ID NOT IN (
              	SELECT DISTINCT p.id from ".$wpdb->posts." p
              	INNER JOIN ($table_groupsPage gp )
              	ON (gp.id_page = p.ID and gp.exc_write='1')
              ) or post_author=$user_ID) ORDER BY post_title;";
  }else{
    //default query
    $query ="SELECT * FROM $wpdb->posts WHERE post_status = 'static'";
  
  }
  //$query ="SELECT * FROM $wpdb->posts WHERE post_status = 'static'";
  $posts = $wpdb->get_results($query);
}

and

wordpress\wp-admin\edit-pages.php around line 60

  if ( isset($_GET['s']) ) {
	...
     endforeach;
  } else {

replace page_rows(); by page_rows(0,0,$posts); getting something like

  if ( isset($_GET['s']) ) {
	...
     endforeach;
  } else {
     page_rows(0,0,$posts);
  }

Configuration

Group Management

Access "Groups" from the main menu in order to manage the groups:

Note: "Pages with free access" are pages without a group.

User Management

Access "Users > Authors & Users" and edit a user to add or remove users from a group.

Page Edit

While editing or creating a page, the user can choose the groups with access to the page, by checking/unchecking the groups after the page edit panel.

Keep in mind that administrators can always read and write pages even if restricted.


Comment by boullery, Jul 24, 2007

Pages with free access

Erreur de la base de données de WordPress? : have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Select p.id from wp_posts p INNER JOIN (wp_ug_G? Select from wp_posts WHERE (post_status='static' OR post_type='page') and ID NOT IN ( Select p.id from wp_posts p INNER JOIN (wp_ug_GroupsPage? gp ) ON (gp.id_page = p.ID ) ) ORDER BY post_title;

Comment by boullery, Jul 24, 2007

Pages with free access

Erreur de la base de données de WordPress? : have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Select p.id from wp_posts p INNER JOIN (wp_ug_G? Select from wp_posts WHERE (post_status='static' OR post_type='page') and ID NOT IN ( Select p.id from wp_posts p INNER JOIN (wp_ug_GroupsPage? gp ) ON (gp.id_page = p.ID ) ) ORDER BY post_title;

Comment by manxa1901, Aug 09, 2007

Hi!

Congratulations for this great plugin!

I have a question...

when a non identificated user try to access a page with group restrictions he looks a page with this text: "You don't have access to this content", I would like to add a link after this text for user login, and after be redirected to last page.

for example...

I have two groups: man & woman

Only users in man group can access to http://www.mysite.com/?page_id=10 Only users in woman group can access to http://www.mysite.com/?page_id=11

If i'm a not logged users and try to go to mens group restricted page http://www.mysite.com/?page_id=10, I see... "You don't have access to this content", ok, my intention is add a link for login and return to man group page.

The same for woman.

I tried with this...

where originally find:

$content = "<h2>You don't have access to this content</h2>

} return $content;

I put:

$content = "<h2>You don't have access to this content</h2> You can login <a href=http://www.mysite.com/web/wp-login.php?redirect_to=http://www.mysite.com/web/index.php><b>here </b></a>";

} return $content;

But I like to put a variable instead index.php for redirect to mans or womens page, depending on where the user tried to access previously.

I hope you can understand me, and sorry for my poor and dirty english ;)

Comment by taobrad, Sep 27, 2007

WP 2.2.1 Groups Access error: Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of function name?(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in wp-group-manage-pages.php on line 62 Same for lines 68 & 112

Same error in Pages Access: wp-group-manage-page-groups.php on line 93

Comment by taobrad, Sep 27, 2007

WP 2.2.1 Groups Access error: Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of function name?(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in wp-group-manage-pages.php on line 62 Same for lines 68 & 112

Same error in Pages Access: wp-group-manage-page-groups.php on line 93

Comment by taobrad, Sep 27, 2007

WP 2.2.1 Groups Access error: Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of function name?(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in wp-group-manage-pages.php on line 62 Same for lines 68 & 112

Same error in Pages Access: wp-group-manage-page-groups.php on line 93

Comment by r.zinkel, Oct 18, 2007

Thanks to all contributors of this clever plugin.

Here is a little contribution from me: I don't want to exclude rstricted pages from the navigation / menu. I've found it usefull to have NOT-logged-in users redirected to the WP-Login-Form automatically, when they click on a menu item from a group-restricted page.

It's really simple to do that as the plugin serves us with a method to get a list of pages to exclude: Put the following code at the VERY BEGINNING of your header-template (header.php) before the "<!doctype ....>":

<?php
    $closedPages= explode(',',userGroups::getPagesToExclude());
    //print_r ($closedPages);
    if (in_array($post->ID, $closedPages)){
    wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
    exit();
    }
?>

That's it.

Comment by 3DPeruna, Nov 13, 2007

Posts are being filtered by group access. I want posts to be available to everyone, but pages based on groups.

Right now, my posts are being filtered and I can't figure out how to turn off the filtering of posts. Pages are working out just fine.

Comment by hostetlerm, Dec 08, 2007

I got a query error using this plugin with MySql? 4.0 when the user does not have permission for the page. But it works with MySql? 4.1 and 5.0.

Comment by stu_m...@hotmail.com, Jul 11, 2008

Compliments on an excellent function!

One question...

I have the page exclusion working happily. However, I would like to write a statement such as:

if(current user is member of particular group) { } else { }

Is this possible?


Sign in to add a comment
Hosted by Google Code