Skip to content

Commit

Permalink
changed super admin test permission
Browse files Browse the repository at this point in the history
  • Loading branch information
Hube2 committed Feb 6, 2020
1 parent 4dc079a commit c077413
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
36 changes: 20 additions & 16 deletions acf-user-role-field-setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: ACF User Role Field Setting
Plugin URI: https://wordpress.org/plugins/user-role-field-setting-for-acf/
Description: Set user types that should be allowed to edit fields
Version: 3.0.0
Version: 3.0.2
Author: John A. Huebner II
Author URI: https://github.com/Hube2/
License: GPL
Expand Down Expand Up @@ -42,38 +42,42 @@ public function after_setup_theme() {
}
} // end public function after_setup_theme

public function prepare_field($field) {
global $post;
if ($post) {
$post_type = get_post_type($post->ID);
if ($post_type == 'acf-field' || $post_type == 'acf-field-group') {
return $field;
}
}
//echo '<pre>'; print_r($field); echo '</pre>';
$return_field = false;
private function user_can_edit($field) {
$exclude = apply_filters('acf/user_role_setting/exclude_field_types', $this->exclude_field_types);
if (in_array($field['type'], $exclude)) {
$return_field = true;
return true;
}
if (isset($field['user_roles'])) {
if (!empty($field['user_roles']) && is_array($field['user_roles'])) {
foreach ($field['user_roles'] as $role) {
if ($role == 'all' || in_array($role, $this->current_user)) {
$return_field = true;
return true;
}
}
} else {
// no user roles have been selected for this field
// it will never be displayed, this is probably an error
return false;
}
} else {
// user roles not set for this field
// this field was created before this plugin was in use
// or user roles is otherwise disabled for this field
$return_field = true;
return true;
}
return false;
} // end private function user_can_edit

public function prepare_field($field) {
global $post;
if ($post) {
$post_type = get_post_type($post->ID);
if ($post_type == 'acf-field' || $post_type == 'acf-field-group') {
return $field;
}
}
if ($return_field) {
//echo '<pre>'; print_r($field); echo '</pre>';
if ($this->user_can_edit($field)) {
return $field;
}
$this->output_hidden_fields($field['name'], $field['value']);
Expand Down Expand Up @@ -128,7 +132,7 @@ private function current_user_roles() {
if (is_object($current_user) && isset($current_user->roles)) {
$this->current_user = $current_user->roles;
}
if (is_multisite() && current_user_can('update_core')) {
if (is_multisite() && current_user_can('manage_network')) {
$this->current_user[] = 'super_admin';
}
} // end private function current_user_roles
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: Hube2
Tags: acf, advanced custom fields, user role, setting, security, multisite
Requires at least: 4.0
Tested up to: 5.2
Stable tag: 3.0.1
Stable tag: 3.0.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -76,6 +76,9 @@ There is a filter so that you can adjust the types of fields that are excluded.

== Changelog ==

= 3.0.2 =
* Changed super admin test permission from "update_core" to "manage_network"

= 3.0.1 =
* Corrected issue with getting property of non object
* Corrected issues with fields that have array values
Expand Down

0 comments on commit c077413

Please sign in to comment.