Changeset 949008
- Timestamp:
- 07/15/2014 07:10:47 PM (12 years ago)
- Location:
- simple-permissions
- Files:
-
- 2 edited
- 3 copied
-
tags/1.1.0 (copied) (copied from simple-permissions/trunk)
-
tags/1.1.0/readme.txt (copied) (copied from simple-permissions/trunk/readme.txt) (3 diffs)
-
tags/1.1.0/simple-permissions.php (copied) (copied from simple-permissions/trunk/simple-permissions.php) (15 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/simple-permissions.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-permissions/tags/1.1.0/readme.txt
r925698 r949008 5 5 Requires at least: 3.5.2 6 6 Tested up to: 3.9.1 7 Stable tag: 1. 0.27 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 35 35 == Changelog == 36 36 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 37 43 = 1.0.2 = 38 44 * Fixed big bug that prevented editing of posts that had no permissions set. … … 46 52 == Upgrade Notice == 47 53 54 = 1.1.0 = 55 * New features and options based on feedback. Upgrade optional. 56 48 57 = 1.0.2 = 49 58 * Everyone should update. -
simple-permissions/tags/1.1.0/simple-permissions.php
r908442 r949008 2 2 /** 3 3 * @package Simple-Permissions 4 * @version 1. 0.24 * @version 1.1.0 5 5 */ 6 6 /* … … 9 9 Description: Create simple permission groups for reading or editing posts. 10 10 Author: Michael George 11 Version: 1. 0.211 Version: 1.1.0 12 12 13 13 This program is free software; you can redistribute it and/or modify … … 44 44 $simplePermissionsAdminOptions = array( 45 45 "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() ) 48 48 ) 49 49 ,"redirectPageID" => "" 50 ,"allowedRole" => "contributor" //as of 1.1.0 50 51 ); 51 52 $devOptions = get_option( $this->adminOptionsName ); … … 69 70 $simplePermissionsAdminOptions = array( 70 71 "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() ) 73 74 ) 74 75 ,"redirectPageID" => "" 76 ,"allowedRole" => "contributor" 75 77 ); 76 78 update_option( $this->adminOptionsName, $simplePermissionsAdminOptions ); … … 298 300 } 299 301 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 "- "; 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 300 364 //Gets the settings link to show on the plugin management page 301 365 //Thanks to "Floating Social Bar" plugin as the code is humbly taken from it … … 311 375 $devOptions = $this->spGetAdminOptions(); 312 376 $workingURL = $_SERVER["REQUEST_URI"]; 377 echo "<!-- " . print_r( $_POST, true ) . " -->\r"; 313 378 314 379 if ( isset( $_POST['update_simplePermissionsGroupSettings'] ) ) { … … 316 381 && ! isset( $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']] ) 317 382 ) { 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() ); 319 384 } 320 385 if ( isset( $_POST['simplePermissionsGroupID'] ) … … 334 399 if ( isset( $_POST['simplePermissionsGroupMembers'] ) ) { 335 400 $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'] ); 337 404 foreach ( $members as $member ) { 338 405 $wpUserData = get_user_by( 'login', $member ); … … 346 413 } 347 414 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 348 426 if ( isset( $_POST['spDeleteGroupConfirmed'] ) ) { 349 427 $devOptions['groups'][(int)$_POST['spDeleteGroupConfirmed']]['enabled'] = false; … … 354 432 $devOptions['redirectPageID'] = $_POST['simplePermissionsRedirectPageID']; 355 433 } 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 ); 357 439 } else if ( isset( $_GET['spDeleteItAll'] ) && $_GET['spDeleteItAll'] == 1 ) { 358 440 $updated = $this->spDeleteItAll(); … … 366 448 } else if ( isset( $updated ) && $updated === false && isset( $_GET['spDeleteItAll'] ) && $_GET['spDeleteItAll'] == 1 ) { 367 449 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"; 369 451 $workingURL = spDelArgFromURL( $_SERVER["REQUEST_URI"], array( 'spDeleteItAll' ) ); 370 452 unset( $_GET['spDeleteItAll'] ); … … 451 533 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"; 452 534 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"; 453 544 echo "<br><br>\r"; 454 545 echo "<input type='submit' value='Save'>\r"; … … 483 574 echo "</textarea>\r"; 484 575 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 485 583 echo "<input type='submit' value='Save'>\r"; 486 584 } else if ( isset( $_GET['spDeleteGroup'] ) ) { … … 563 661 564 662 function 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 } 573 695 } 574 696 … … 668 790 add_filter( 'posts_distinct', array ( &$svvsd_simplePermissions, 'spSearchDistinct' ) ); 669 791 add_filter( 'template_redirect', array ( &$svvsd_simplePermissions, 'spOverride404' ) ); 792 add_filter( 'list_terms_exclusions', array ( &$svvsd_simplePermissions, 'spExcludeCategories' ), 10, 2 ); 670 793 671 794 //Actions -
simple-permissions/trunk/readme.txt
r925698 r949008 5 5 Requires at least: 3.5.2 6 6 Tested up to: 3.9.1 7 Stable tag: 1. 0.27 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 35 35 == Changelog == 36 36 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 37 43 = 1.0.2 = 38 44 * Fixed big bug that prevented editing of posts that had no permissions set. … … 46 52 == Upgrade Notice == 47 53 54 = 1.1.0 = 55 * New features and options based on feedback. Upgrade optional. 56 48 57 = 1.0.2 = 49 58 * Everyone should update. -
simple-permissions/trunk/simple-permissions.php
r908442 r949008 2 2 /** 3 3 * @package Simple-Permissions 4 * @version 1. 0.24 * @version 1.1.0 5 5 */ 6 6 /* … … 9 9 Description: Create simple permission groups for reading or editing posts. 10 10 Author: Michael George 11 Version: 1. 0.211 Version: 1.1.0 12 12 13 13 This program is free software; you can redistribute it and/or modify … … 44 44 $simplePermissionsAdminOptions = array( 45 45 "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() ) 48 48 ) 49 49 ,"redirectPageID" => "" 50 ,"allowedRole" => "contributor" //as of 1.1.0 50 51 ); 51 52 $devOptions = get_option( $this->adminOptionsName ); … … 69 70 $simplePermissionsAdminOptions = array( 70 71 "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() ) 73 74 ) 74 75 ,"redirectPageID" => "" 76 ,"allowedRole" => "contributor" 75 77 ); 76 78 update_option( $this->adminOptionsName, $simplePermissionsAdminOptions ); … … 298 300 } 299 301 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 "- "; 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 300 364 //Gets the settings link to show on the plugin management page 301 365 //Thanks to "Floating Social Bar" plugin as the code is humbly taken from it … … 311 375 $devOptions = $this->spGetAdminOptions(); 312 376 $workingURL = $_SERVER["REQUEST_URI"]; 377 echo "<!-- " . print_r( $_POST, true ) . " -->\r"; 313 378 314 379 if ( isset( $_POST['update_simplePermissionsGroupSettings'] ) ) { … … 316 381 && ! isset( $devOptions['groups'][(int)$_POST['simplePermissionsGroupID']] ) 317 382 ) { 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() ); 319 384 } 320 385 if ( isset( $_POST['simplePermissionsGroupID'] ) … … 334 399 if ( isset( $_POST['simplePermissionsGroupMembers'] ) ) { 335 400 $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'] ); 337 404 foreach ( $members as $member ) { 338 405 $wpUserData = get_user_by( 'login', $member ); … … 346 413 } 347 414 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 348 426 if ( isset( $_POST['spDeleteGroupConfirmed'] ) ) { 349 427 $devOptions['groups'][(int)$_POST['spDeleteGroupConfirmed']]['enabled'] = false; … … 354 432 $devOptions['redirectPageID'] = $_POST['simplePermissionsRedirectPageID']; 355 433 } 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 ); 357 439 } else if ( isset( $_GET['spDeleteItAll'] ) && $_GET['spDeleteItAll'] == 1 ) { 358 440 $updated = $this->spDeleteItAll(); … … 366 448 } else if ( isset( $updated ) && $updated === false && isset( $_GET['spDeleteItAll'] ) && $_GET['spDeleteItAll'] == 1 ) { 367 449 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"; 369 451 $workingURL = spDelArgFromURL( $_SERVER["REQUEST_URI"], array( 'spDeleteItAll' ) ); 370 452 unset( $_GET['spDeleteItAll'] ); … … 451 533 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"; 452 534 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"; 453 544 echo "<br><br>\r"; 454 545 echo "<input type='submit' value='Save'>\r"; … … 483 574 echo "</textarea>\r"; 484 575 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 485 583 echo "<input type='submit' value='Save'>\r"; 486 584 } else if ( isset( $_GET['spDeleteGroup'] ) ) { … … 563 661 564 662 function 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 } 573 695 } 574 696 … … 668 790 add_filter( 'posts_distinct', array ( &$svvsd_simplePermissions, 'spSearchDistinct' ) ); 669 791 add_filter( 'template_redirect', array ( &$svvsd_simplePermissions, 'spOverride404' ) ); 792 add_filter( 'list_terms_exclusions', array ( &$svvsd_simplePermissions, 'spExcludeCategories' ), 10, 2 ); 670 793 671 794 //Actions
Note: See TracChangeset
for help on using the changeset viewer.