Plugin Directory

Changeset 949008


Ignore:
Timestamp:
07/15/2014 07:10:47 PM (12 years ago)
Author:
george_michael
Message:

added v 1.1.0

Location:
simple-permissions
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • simple-permissions/tags/1.1.0/readme.txt

    r925698 r949008  
    55Requires at least: 3.5.2
    66Tested up to: 3.9.1
    7 Stable tag: 1.0.2
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Changelog ==
    3636
     37= 1.1.0 =
     38* Added option to limit changing permissions to certain WP roles.
     39* Added ability to prevent posting in categories by SP group.
     40* Changed the regular express used to find usernames when added users to a group. This will allow spaces in usernames, though WP may have to be changed to allow it.
     41* above changes per http://wordpress.org/support/topic/couple-issues-3
     42
    3743= 1.0.2 =
    3844* Fixed big bug that prevented editing of posts that had no permissions set.
     
    4652== Upgrade Notice ==
    4753
     54= 1.1.0 =
     55* New features and options based on feedback. Upgrade optional.
     56
    4857= 1.0.2 =
    4958* Everyone should update.
  • simple-permissions/tags/1.1.0/simple-permissions.php

    r908442 r949008  
    22/**
    33 * @package Simple-Permissions
    4  * @version 1.0.2
     4 * @version 1.1.0
    55 */
    66/*
     
    99Description: Create simple permission groups for reading or editing posts.
    1010Author: Michael George
    11 Version: 1.0.2
     11Version: 1.1.0
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    4444            $simplePermissionsAdminOptions = array(
    4545                                "groups" => array(
    46                                                 array( "id" => 0, "name" => "Public", "enabled" => true, "members" => array() )
    47                                                 ,array( "id" => 1, "name" => "Logged In Users", "enabled" => true, "members" => array() )
     46                                                array( "id" => 0, "name" => "Public", "enabled" => true, "members" => array(), "limitCats" => array() )
     47                                                ,array( "id" => 1, "name" => "Logged In Users", "enabled" => true, "members" => array(), "limitCats" => array() )
    4848                                                )
    4949                                ,"redirectPageID" => ""
     50                                ,"allowedRole" => "contributor" //as of 1.1.0
    5051                                );
    5152            $devOptions = get_option( $this->adminOptionsName );
     
    6970            $simplePermissionsAdminOptions = array(
    7071                                "groups" => array(
    71                                                 array( "id" => 0, "name" => "Public", "enabled" => true, "members" => array() )
    72                                                 ,array( "id" => 1, "name" => "Logged In Users", "enabled" => true, "members" => array() )
     72                                                array( "id" => 0, "name" => "Public", "enabled" => true, "members" => array(), "limitCats" => array() )
     73                                                ,array( "id" => 1, "name" => "Logged In Users", "enabled" => true, "members" => array(), "limitCats" => array() )
    7374                                                )
    7475                                ,"redirectPageID" => ""
     76                                ,"allowedRole" => "contributor"
    7577                                );
    7678            update_option( $this->adminOptionsName, $simplePermissionsAdminOptions );
     
    298300        }
    299301
     302        //Nabbed from http://wordpress.stackexchange.com/questions/41548/get-categories-hierarchical-order-like-wp-list-categories-with-name-slug-li
     303        //as of 1.1.0
     304        function spHierarchicalCategoryTree( $cat, $group, $depth = 0 ) {
     305            $devOptions = $this->spGetAdminOptions();
     306            //echo "<!-- $cat, $depth -->\r";
     307            $next = get_categories( 'hide_empty=0&orderby=name&order=ASC&parent=' . $cat );
     308            if( $next ) {
     309                for ( $i = 0; $i < $depth; $i++ ) {
     310                    echo "\t";
     311                }
     312                echo "<ul>\r";
     313                foreach( $next as $cat ) {
     314                    $inArr = in_array( $cat->term_id, $group['limitCats'] );
     315                    for ( $i = 0; $i <= $depth; $i++ ) {
     316                        echo "\t";
     317                    }
     318                    echo "<li><input type='checkbox' name='simplePermissionsLimitCats[]' value='" . $cat->term_id . "'" . ( $inArr ? " checked" : "" ) . " /><strong>";
     319                    for ( $i = 0; $i < $depth; $i++ ) {
     320                        echo "-&nbsp;";
     321                    }
     322                    echo $cat->name . "</strong>";
     323                    $this->spHierarchicalCategoryTree( $cat->term_id, $group, $depth + 1 );
     324                    for ( $i = 0; $i <= $depth; $i++ ) {
     325                        echo "\t";
     326                    }
     327                    echo "</li>\r";
     328                }
     329                for ( $i = 0; $i < $depth; $i++ ) {
     330                    echo "\t";
     331                }
     332                echo "</ul>\r";
     333            }
     334        }
     335
     336        //Exclude categories from edit page
     337        //as of 1.1.0
     338        function spExcludeCategories( $exclusions, $args ) {
     339            //see if we are on edit screen, if so, bail out
     340            global $pagenow;
     341            if ( $pagenow != 'post.php' ) {
     342                return $exclusions;
     343            }
     344            $devOptions = $this->spGetAdminOptions();
     345            $user = wp_get_current_user();
     346
     347            $excludedCats = array();
     348            foreach ( $devOptions['groups'] as $group ) {
     349                if ( in_array( $user->ID, $group['members'] ) ) {
     350                    foreach ( $group['limitCats'] as $cat ) {
     351                        $excludedCats[] = $cat;
     352                    }
     353                }
     354            }
     355            // if the exclude list is empty, we send everything back the way it came in
     356            if ( empty( $excludedCats ) ) {
     357                return $exclusions;
     358            }
     359
     360            $exclusions .= " AND ( t.term_id NOT IN (" . implode( ",", $excludedCats ) . ") )";
     361            return $exclusions;
     362        }
     363
    300364        //Gets the settings link to show on the plugin management page
    301365        //Thanks to "Floating Social Bar" plugin as the code is humbly taken from it
     
    311375            $devOptions = $this->spGetAdminOptions();
    312376            $workingURL = $_SERVER["REQUEST_URI"];
     377            echo "<!-- " . print_r( $_POST, true ) . " -->\r";
    313378
    314379            if ( isset( $_POST['update_simplePermissionsGroupSettings'] ) ) {
     
    316381                        && ! isset( $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']] )
    317382                    ) {
    318                         $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']] = array( "id" => (int)$_POST['simplePermissionsGroupID'], "name" => "", "enabled" => true, "members" => array() );
     383                        $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']] = array( "id" => (int)$_POST['simplePermissionsGroupID'], "name" => "", "enabled" => true, "members" => array(), "limitCats" => array() );
    319384                }
    320385                if ( isset( $_POST['simplePermissionsGroupID'] )
     
    334399                if ( isset( $_POST['simplePermissionsGroupMembers'] ) ) {
    335400                    $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']]['members'] = array();
    336                     $members = preg_split( '/[\s,]+/', $_POST['simplePermissionsGroupMembers'] ); //explode didn't work so good
     401                    //Changed regex on following from /[\s,]+/ to /[\n\r\f]+/ to allow spaces to be used in usernames
     402                    //as of 1.1.0
     403                    $members = preg_split( '/[\n\r\f]+/', $_POST['simplePermissionsGroupMembers'] );
    337404                    foreach ( $members as $member ) {
    338405                        $wpUserData = get_user_by( 'login', $member );
     
    346413                }
    347414
     415                if ( isset( $_POST['simplePermissionsLimitCats'] ) ) {
     416                    foreach ( $_POST['simplePermissionsLimitCats'] as $cat ) {
     417                        echo "<!-- found cat $cat -->\r";
     418                        if ( ! in_array( $cat, $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']]['limitCats'] ) ) {
     419                            $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']]['limitCats'][] = (int)$cat;
     420                        }
     421                    }
     422                } else if ( isset( $_POST['simplePermissionsGroupID'] ) && $_POST['simplePermissionsGroupID'] != 'new' ) {
     423                    $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']]['limitCats'] = array();
     424                }
     425
    348426                if ( isset( $_POST['spDeleteGroupConfirmed'] ) ) {
    349427                    $devOptions['groups'][(int)$_POST['spDeleteGroupConfirmed']]['enabled'] = false;
     
    354432                    $devOptions['redirectPageID'] = $_POST['simplePermissionsRedirectPageID'];
    355433                }
    356                 $updated = update_option($this->adminOptionsName, $devOptions);
     434
     435                if ( isset( $_POST['simplePermissionsAllowedRole'] ) ) {
     436                    $devOptions['allowedRole'] = $_POST['simplePermissionsAllowedRole'];
     437                }
     438                $updated = update_option( $this->adminOptionsName, $devOptions );
    357439            } else if ( isset( $_GET['spDeleteItAll'] ) && $_GET['spDeleteItAll'] == 1 ) {
    358440                $updated = $this->spDeleteItAll();
     
    366448            } else if ( isset( $updated ) && $updated === false && isset( $_GET['spDeleteItAll'] ) && $_GET['spDeleteItAll'] == 1 ) {
    367449                global $wpdb;
    368                 echo "<div class='updated'><p><strong>Settings where delete, but post permissions were NOT reset.</strong></p><p>You can try again or run this sql manually.</p><pre>DELETE FROM " . $wpdb->postmeta . " WHERE meta_key IN ('simplePermissions_readGroupIDs', 'simplePermissions_writeGroupIDs')</pre></div>\r";
     450                echo "<div class='updated'><p><strong>Settings where deleted, but post permissions were NOT reset.</strong></p><p>You can try again or run this sql manually.</p><pre>DELETE FROM " . $wpdb->postmeta . " WHERE meta_key IN ('simplePermissions_readGroupIDs', 'simplePermissions_writeGroupIDs')</pre></div>\r";
    369451                $workingURL = spDelArgFromURL( $_SERVER["REQUEST_URI"], array( 'spDeleteItAll' ) );
    370452                unset( $_GET['spDeleteItAll'] );
     
    451533                echo "<p>This is the page/post ID of the page/post users will be redirected to when they don't have permission to view a page.</p>\r";
    452534                echo "<input id='simplePermissionsRedirectPageID' type='text' name='simplePermissionsRedirectPageID' value='" . $devOptions['redirectPageID'] . "' style='width: 100px;'>\r";
     535                echo "<br>\r";
     536                echo "<h2>Limit permission changes</h2>\r";
     537                echo "<p>By default, anyone who can edit a post can change the permissions. Choose another role here to limit changes to users who have that role or higher.</p>\r";
     538                echo "<select id='simplePermissionsAllowedRole' name='simplePermissionsAllowedRole'>\r";
     539                echo "\t<option value='administrator'" . ( $devOptions['allowedRole'] == 'administrator' ? " selected" : "" ) . ">Administrators</option>\r";
     540                echo "\t<option value='editor'" . ( $devOptions['allowedRole'] == 'editor' ? " selected" : "" ) . ">Editors</option>\r";
     541                echo "\t<option value='author'" . ( $devOptions['allowedRole'] == 'author' ? " selected" : "" ) . ">Authors</option>\r";
     542                echo "\t<option value='contributor'" . ( $devOptions['allowedRole'] == 'contributor' ? " selected" : "" ) . ">Contributors</option>\r";
     543                echo "</select>\r";
    453544                echo "<br><br>\r";
    454545                echo "<input type='submit' value='Save'>\r";
     
    483574                echo "</textarea>\r";
    484575                echo "<br><br>\r";
     576
     577                //Category limiting
     578                //as of 1.1.0
     579                echo "<h2>Prevent posting in these categories</h2>\r";
     580                $this->spHierarchicalCategoryTree( 0, $devOptions['groups'][$_GET['spEditGroup']], 0 );
     581                echo "<br><br>\r";
     582
    485583                echo "<input type='submit' value='Save'>\r";
    486584            } else if ( isset( $_GET['spDeleteGroup'] ) ) {
     
    563661
    564662function spAddMetaBox() {
    565     add_meta_box(
    566             'simplepermissions_meta_box'
    567             ,__( 'Simple Permissions' )
    568             ,'spRenderMetaBox'
    569             ,get_post_type( get_the_ID() )
    570             ,'normal'
    571             ,'high'
    572         );
     663    global $svvsd_simplePermissions;
     664    $devOptions = $svvsd_simplePermissions->spGetAdminOptions();
     665    if ( ! isset( $devOptions['allowedRole'] ) ) {
     666        return;
     667    }
     668    $user = wp_get_current_user();
     669    if ( current_user_can( 'activate_plugins' ) ) {
     670        $user->roles[] = 'administrator';
     671    }
     672    if ( count( $user->roles ) == 1 ) {
     673        switch ( $user->roles[0] ) {
     674            case 'administrator':
     675            case 'editor':
     676                $user->roles[] = 'editor';
     677            case 'author':
     678                $user->roles[] = 'author';
     679            case 'contributor':
     680                $user->roles[] = 'contributor';
     681                break;
     682        }
     683    }
     684    //echo "<!-- " . print_r( $user->roles, true ) . " -->\r";
     685    if ( in_array( $devOptions['allowedRole'], (array) $user->roles ) ) {
     686        add_meta_box(
     687                'simplepermissions_meta_box'
     688                ,__( 'Simple Permissions' )
     689                ,'spRenderMetaBox'
     690                ,get_post_type( get_the_ID() )
     691                ,'normal'
     692                ,'high'
     693            );
     694    }
    573695}
    574696
     
    668790    add_filter( 'posts_distinct', array ( &$svvsd_simplePermissions, 'spSearchDistinct' ) );
    669791    add_filter( 'template_redirect', array ( &$svvsd_simplePermissions, 'spOverride404' ) );
     792    add_filter( 'list_terms_exclusions', array ( &$svvsd_simplePermissions, 'spExcludeCategories' ), 10, 2 );
    670793
    671794    //Actions
  • simple-permissions/trunk/readme.txt

    r925698 r949008  
    55Requires at least: 3.5.2
    66Tested up to: 3.9.1
    7 Stable tag: 1.0.2
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Changelog ==
    3636
     37= 1.1.0 =
     38* Added option to limit changing permissions to certain WP roles.
     39* Added ability to prevent posting in categories by SP group.
     40* Changed the regular express used to find usernames when added users to a group. This will allow spaces in usernames, though WP may have to be changed to allow it.
     41* above changes per http://wordpress.org/support/topic/couple-issues-3
     42
    3743= 1.0.2 =
    3844* Fixed big bug that prevented editing of posts that had no permissions set.
     
    4652== Upgrade Notice ==
    4753
     54= 1.1.0 =
     55* New features and options based on feedback. Upgrade optional.
     56
    4857= 1.0.2 =
    4958* Everyone should update.
  • simple-permissions/trunk/simple-permissions.php

    r908442 r949008  
    22/**
    33 * @package Simple-Permissions
    4  * @version 1.0.2
     4 * @version 1.1.0
    55 */
    66/*
     
    99Description: Create simple permission groups for reading or editing posts.
    1010Author: Michael George
    11 Version: 1.0.2
     11Version: 1.1.0
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    4444            $simplePermissionsAdminOptions = array(
    4545                                "groups" => array(
    46                                                 array( "id" => 0, "name" => "Public", "enabled" => true, "members" => array() )
    47                                                 ,array( "id" => 1, "name" => "Logged In Users", "enabled" => true, "members" => array() )
     46                                                array( "id" => 0, "name" => "Public", "enabled" => true, "members" => array(), "limitCats" => array() )
     47                                                ,array( "id" => 1, "name" => "Logged In Users", "enabled" => true, "members" => array(), "limitCats" => array() )
    4848                                                )
    4949                                ,"redirectPageID" => ""
     50                                ,"allowedRole" => "contributor" //as of 1.1.0
    5051                                );
    5152            $devOptions = get_option( $this->adminOptionsName );
     
    6970            $simplePermissionsAdminOptions = array(
    7071                                "groups" => array(
    71                                                 array( "id" => 0, "name" => "Public", "enabled" => true, "members" => array() )
    72                                                 ,array( "id" => 1, "name" => "Logged In Users", "enabled" => true, "members" => array() )
     72                                                array( "id" => 0, "name" => "Public", "enabled" => true, "members" => array(), "limitCats" => array() )
     73                                                ,array( "id" => 1, "name" => "Logged In Users", "enabled" => true, "members" => array(), "limitCats" => array() )
    7374                                                )
    7475                                ,"redirectPageID" => ""
     76                                ,"allowedRole" => "contributor"
    7577                                );
    7678            update_option( $this->adminOptionsName, $simplePermissionsAdminOptions );
     
    298300        }
    299301
     302        //Nabbed from http://wordpress.stackexchange.com/questions/41548/get-categories-hierarchical-order-like-wp-list-categories-with-name-slug-li
     303        //as of 1.1.0
     304        function spHierarchicalCategoryTree( $cat, $group, $depth = 0 ) {
     305            $devOptions = $this->spGetAdminOptions();
     306            //echo "<!-- $cat, $depth -->\r";
     307            $next = get_categories( 'hide_empty=0&orderby=name&order=ASC&parent=' . $cat );
     308            if( $next ) {
     309                for ( $i = 0; $i < $depth; $i++ ) {
     310                    echo "\t";
     311                }
     312                echo "<ul>\r";
     313                foreach( $next as $cat ) {
     314                    $inArr = in_array( $cat->term_id, $group['limitCats'] );
     315                    for ( $i = 0; $i <= $depth; $i++ ) {
     316                        echo "\t";
     317                    }
     318                    echo "<li><input type='checkbox' name='simplePermissionsLimitCats[]' value='" . $cat->term_id . "'" . ( $inArr ? " checked" : "" ) . " /><strong>";
     319                    for ( $i = 0; $i < $depth; $i++ ) {
     320                        echo "-&nbsp;";
     321                    }
     322                    echo $cat->name . "</strong>";
     323                    $this->spHierarchicalCategoryTree( $cat->term_id, $group, $depth + 1 );
     324                    for ( $i = 0; $i <= $depth; $i++ ) {
     325                        echo "\t";
     326                    }
     327                    echo "</li>\r";
     328                }
     329                for ( $i = 0; $i < $depth; $i++ ) {
     330                    echo "\t";
     331                }
     332                echo "</ul>\r";
     333            }
     334        }
     335
     336        //Exclude categories from edit page
     337        //as of 1.1.0
     338        function spExcludeCategories( $exclusions, $args ) {
     339            //see if we are on edit screen, if so, bail out
     340            global $pagenow;
     341            if ( $pagenow != 'post.php' ) {
     342                return $exclusions;
     343            }
     344            $devOptions = $this->spGetAdminOptions();
     345            $user = wp_get_current_user();
     346
     347            $excludedCats = array();
     348            foreach ( $devOptions['groups'] as $group ) {
     349                if ( in_array( $user->ID, $group['members'] ) ) {
     350                    foreach ( $group['limitCats'] as $cat ) {
     351                        $excludedCats[] = $cat;
     352                    }
     353                }
     354            }
     355            // if the exclude list is empty, we send everything back the way it came in
     356            if ( empty( $excludedCats ) ) {
     357                return $exclusions;
     358            }
     359
     360            $exclusions .= " AND ( t.term_id NOT IN (" . implode( ",", $excludedCats ) . ") )";
     361            return $exclusions;
     362        }
     363
    300364        //Gets the settings link to show on the plugin management page
    301365        //Thanks to "Floating Social Bar" plugin as the code is humbly taken from it
     
    311375            $devOptions = $this->spGetAdminOptions();
    312376            $workingURL = $_SERVER["REQUEST_URI"];
     377            echo "<!-- " . print_r( $_POST, true ) . " -->\r";
    313378
    314379            if ( isset( $_POST['update_simplePermissionsGroupSettings'] ) ) {
     
    316381                        && ! isset( $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']] )
    317382                    ) {
    318                         $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']] = array( "id" => (int)$_POST['simplePermissionsGroupID'], "name" => "", "enabled" => true, "members" => array() );
     383                        $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']] = array( "id" => (int)$_POST['simplePermissionsGroupID'], "name" => "", "enabled" => true, "members" => array(), "limitCats" => array() );
    319384                }
    320385                if ( isset( $_POST['simplePermissionsGroupID'] )
     
    334399                if ( isset( $_POST['simplePermissionsGroupMembers'] ) ) {
    335400                    $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']]['members'] = array();
    336                     $members = preg_split( '/[\s,]+/', $_POST['simplePermissionsGroupMembers'] ); //explode didn't work so good
     401                    //Changed regex on following from /[\s,]+/ to /[\n\r\f]+/ to allow spaces to be used in usernames
     402                    //as of 1.1.0
     403                    $members = preg_split( '/[\n\r\f]+/', $_POST['simplePermissionsGroupMembers'] );
    337404                    foreach ( $members as $member ) {
    338405                        $wpUserData = get_user_by( 'login', $member );
     
    346413                }
    347414
     415                if ( isset( $_POST['simplePermissionsLimitCats'] ) ) {
     416                    foreach ( $_POST['simplePermissionsLimitCats'] as $cat ) {
     417                        echo "<!-- found cat $cat -->\r";
     418                        if ( ! in_array( $cat, $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']]['limitCats'] ) ) {
     419                            $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']]['limitCats'][] = (int)$cat;
     420                        }
     421                    }
     422                } else if ( isset( $_POST['simplePermissionsGroupID'] ) && $_POST['simplePermissionsGroupID'] != 'new' ) {
     423                    $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']]['limitCats'] = array();
     424                }
     425
    348426                if ( isset( $_POST['spDeleteGroupConfirmed'] ) ) {
    349427                    $devOptions['groups'][(int)$_POST['spDeleteGroupConfirmed']]['enabled'] = false;
     
    354432                    $devOptions['redirectPageID'] = $_POST['simplePermissionsRedirectPageID'];
    355433                }
    356                 $updated = update_option($this->adminOptionsName, $devOptions);
     434
     435                if ( isset( $_POST['simplePermissionsAllowedRole'] ) ) {
     436                    $devOptions['allowedRole'] = $_POST['simplePermissionsAllowedRole'];
     437                }
     438                $updated = update_option( $this->adminOptionsName, $devOptions );
    357439            } else if ( isset( $_GET['spDeleteItAll'] ) && $_GET['spDeleteItAll'] == 1 ) {
    358440                $updated = $this->spDeleteItAll();
     
    366448            } else if ( isset( $updated ) && $updated === false && isset( $_GET['spDeleteItAll'] ) && $_GET['spDeleteItAll'] == 1 ) {
    367449                global $wpdb;
    368                 echo "<div class='updated'><p><strong>Settings where delete, but post permissions were NOT reset.</strong></p><p>You can try again or run this sql manually.</p><pre>DELETE FROM " . $wpdb->postmeta . " WHERE meta_key IN ('simplePermissions_readGroupIDs', 'simplePermissions_writeGroupIDs')</pre></div>\r";
     450                echo "<div class='updated'><p><strong>Settings where deleted, but post permissions were NOT reset.</strong></p><p>You can try again or run this sql manually.</p><pre>DELETE FROM " . $wpdb->postmeta . " WHERE meta_key IN ('simplePermissions_readGroupIDs', 'simplePermissions_writeGroupIDs')</pre></div>\r";
    369451                $workingURL = spDelArgFromURL( $_SERVER["REQUEST_URI"], array( 'spDeleteItAll' ) );
    370452                unset( $_GET['spDeleteItAll'] );
     
    451533                echo "<p>This is the page/post ID of the page/post users will be redirected to when they don't have permission to view a page.</p>\r";
    452534                echo "<input id='simplePermissionsRedirectPageID' type='text' name='simplePermissionsRedirectPageID' value='" . $devOptions['redirectPageID'] . "' style='width: 100px;'>\r";
     535                echo "<br>\r";
     536                echo "<h2>Limit permission changes</h2>\r";
     537                echo "<p>By default, anyone who can edit a post can change the permissions. Choose another role here to limit changes to users who have that role or higher.</p>\r";
     538                echo "<select id='simplePermissionsAllowedRole' name='simplePermissionsAllowedRole'>\r";
     539                echo "\t<option value='administrator'" . ( $devOptions['allowedRole'] == 'administrator' ? " selected" : "" ) . ">Administrators</option>\r";
     540                echo "\t<option value='editor'" . ( $devOptions['allowedRole'] == 'editor' ? " selected" : "" ) . ">Editors</option>\r";
     541                echo "\t<option value='author'" . ( $devOptions['allowedRole'] == 'author' ? " selected" : "" ) . ">Authors</option>\r";
     542                echo "\t<option value='contributor'" . ( $devOptions['allowedRole'] == 'contributor' ? " selected" : "" ) . ">Contributors</option>\r";
     543                echo "</select>\r";
    453544                echo "<br><br>\r";
    454545                echo "<input type='submit' value='Save'>\r";
     
    483574                echo "</textarea>\r";
    484575                echo "<br><br>\r";
     576
     577                //Category limiting
     578                //as of 1.1.0
     579                echo "<h2>Prevent posting in these categories</h2>\r";
     580                $this->spHierarchicalCategoryTree( 0, $devOptions['groups'][$_GET['spEditGroup']], 0 );
     581                echo "<br><br>\r";
     582
    485583                echo "<input type='submit' value='Save'>\r";
    486584            } else if ( isset( $_GET['spDeleteGroup'] ) ) {
     
    563661
    564662function spAddMetaBox() {
    565     add_meta_box(
    566             'simplepermissions_meta_box'
    567             ,__( 'Simple Permissions' )
    568             ,'spRenderMetaBox'
    569             ,get_post_type( get_the_ID() )
    570             ,'normal'
    571             ,'high'
    572         );
     663    global $svvsd_simplePermissions;
     664    $devOptions = $svvsd_simplePermissions->spGetAdminOptions();
     665    if ( ! isset( $devOptions['allowedRole'] ) ) {
     666        return;
     667    }
     668    $user = wp_get_current_user();
     669    if ( current_user_can( 'activate_plugins' ) ) {
     670        $user->roles[] = 'administrator';
     671    }
     672    if ( count( $user->roles ) == 1 ) {
     673        switch ( $user->roles[0] ) {
     674            case 'administrator':
     675            case 'editor':
     676                $user->roles[] = 'editor';
     677            case 'author':
     678                $user->roles[] = 'author';
     679            case 'contributor':
     680                $user->roles[] = 'contributor';
     681                break;
     682        }
     683    }
     684    //echo "<!-- " . print_r( $user->roles, true ) . " -->\r";
     685    if ( in_array( $devOptions['allowedRole'], (array) $user->roles ) ) {
     686        add_meta_box(
     687                'simplepermissions_meta_box'
     688                ,__( 'Simple Permissions' )
     689                ,'spRenderMetaBox'
     690                ,get_post_type( get_the_ID() )
     691                ,'normal'
     692                ,'high'
     693            );
     694    }
    573695}
    574696
     
    668790    add_filter( 'posts_distinct', array ( &$svvsd_simplePermissions, 'spSearchDistinct' ) );
    669791    add_filter( 'template_redirect', array ( &$svvsd_simplePermissions, 'spOverride404' ) );
     792    add_filter( 'list_terms_exclusions', array ( &$svvsd_simplePermissions, 'spExcludeCategories' ), 10, 2 );
    670793
    671794    //Actions
Note: See TracChangeset for help on using the changeset viewer.