Skip to content

Commit

Permalink
Merge pull request #376 from GM-Alex/next
Browse files Browse the repository at this point in the history
Bump version 2.2.21
GM-Alex authored May 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents abefe6f + 2c0b6e2 commit f2881ac
Showing 24 changed files with 89 additions and 48 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"description": "User Access Manager plugin for Wordpress",
"type": "wordpress-plugin",
"license": "GPL-2.0",
"version": "2.2.20",
"version": "2.2.21",
"authors": [
{
"name": "Alexander Schneider",
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "user-access-manager",
"version": "2.2.20",
"version": "2.2.21",
"description": "[![Build Status](https://travis-ci.org/GM-Alex/user-access-manager.svg)](https://travis-ci.org/GM-Alex/user-access-manager)",
"main": "index.js",
"directories": {
4 changes: 3 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ Contributors: GM_Alex
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=1947052
Tags: admin, access, member area, members, member, member access, page, pages, post, posts, private, privacy, restrict, user, user access manager, user management
Requires at least: 4.7
Tested up to: 6.1
Tested up to: 6.2
Stable tag: 2.2.20

With the "User Access Manager"-plugin you can manage the access to your posts, pages and files.
@@ -63,6 +63,8 @@ Here you found the changes in each version.

Version Date Changes

2.2.21 2023/05/25 Adjust database compatibility #368

2.2.20 2023/03/08 Fix warning

2.2.19 2022/11/18 Add try out link
7 changes: 3 additions & 4 deletions src/Access/AccessHandler.php
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
use UserAccessManager\Object\ObjectHandler;
use UserAccessManager\User\UserHandler;
use UserAccessManager\UserGroup\AbstractUserGroup;
use UserAccessManager\UserGroup\DynamicUserGroup;
use UserAccessManager\UserGroup\UserGroupHandler;
use UserAccessManager\UserGroup\UserGroupTypeException;
use UserAccessManager\Wrapper\Wordpress;
@@ -140,11 +139,11 @@ private function isAdmin(?bool $isAdmin): bool

/**
* Returns the user user groups filtered by the write access.
* @param null|bool $isAdmin If set we force the admin mode.
* @param bool|null $isAdmin If set we force the admin mode.
* @return AbstractUserGroup[]
* @throws UserGroupTypeException
*/
private function getUserUserGroupsForObjectAccess($isAdmin = null): array
private function getUserUserGroupsForObjectAccess(?bool $isAdmin = null): array
{
$userUserGroups = $this->userGroupHandler->getUserGroupsForUser();

@@ -169,7 +168,7 @@ function (AbstractUserGroup $userGroup) {
* @throws UserGroupTypeException
* @throws Exception
*/
public function checkObjectAccess(?string $objectType, $objectId, $isAdmin = null): bool
public function checkObjectAccess(?string $objectType, $objectId, ?bool $isAdmin = null): bool
{
$isAdmin = $this->isAdmin($isAdmin);

2 changes: 1 addition & 1 deletion src/Command/ObjectCommand.php
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ function (UserGroup $userGroup) {
private function getUserGroupIdAndType(array $namesMap, string $identifier, ?string &$type = '')
{
$type = (is_numeric($identifier) === true) ? 'id' : 'name';
return isset($namesMap[$identifier]) ? $namesMap[$identifier] : $identifier;
return $namesMap[$identifier] ?? $identifier;
}

/**
8 changes: 0 additions & 8 deletions src/Controller/Backend/BackendController.php
Original file line number Diff line number Diff line change
@@ -44,11 +44,6 @@ class BackendController extends Controller
*/
private $userHandler;

/**
* @var FileHandler
*/
private $fileHandler;

/**
* @var SetupHandler
*/
@@ -65,20 +60,17 @@ class BackendController extends Controller
* @param Wordpress $wordpress
* @param WordpressConfig $wordpressConfig
* @param UserHandler $userHandler
* @param FileHandler $fileHandler
* @param SetupHandler $setupHandler
*/
public function __construct(
Php $php,
Wordpress $wordpress,
WordpressConfig $wordpressConfig,
UserHandler $userHandler,
FileHandler $fileHandler,
SetupHandler $setupHandler
) {
parent::__construct($php, $wordpress, $wordpressConfig);
$this->userHandler = $userHandler;
$this->fileHandler = $fileHandler;
$this->setupHandler = $setupHandler;
}

1 change: 0 additions & 1 deletion src/Controller/ControllerFactory.php
Original file line number Diff line number Diff line change
@@ -248,7 +248,6 @@ public function createBackendController(): BackendController
$this->wordpress,
$this->wordpressConfig,
$this->userHandler,
$this->fileHandler,
$this->setupHandler
);
}
2 changes: 1 addition & 1 deletion src/Controller/Frontend/TermController.php
Original file line number Diff line number Diff line change
@@ -309,7 +309,7 @@ private function processPostMenuItem(object $item): bool
* @return bool
* @throws UserGroupTypeException
*/
private function processTermMenuItem(&$item): bool
private function processTermMenuItem($item): bool
{
$rawTerm = $this->objectHandler->getTerm($item->object_id);
$term = $this->processTerm($rawTerm, $isEmpty);
4 changes: 1 addition & 3 deletions src/File/ApacheFileProtection.php
Original file line number Diff line number Diff line change
@@ -130,9 +130,7 @@ private function getPermalinkFileContent(?string $objectType, ?bool $isSubSite =
$content .= "RewriteRule ^(.*)\\?(.*)$ {$homeRoot}index.php?uamgetfile=$1&$2 [QSA,L]\n";
$content = $this->applyFilters($content);

$content = "<IfModule mod_rewrite.c>\n$content</IfModule>\n";

return $content;
return "<IfModule mod_rewrite.c>\n$content</IfModule>\n";
}

/**
2 changes: 1 addition & 1 deletion src/Form/FormHelper.php
Original file line number Diff line number Diff line change
@@ -256,7 +256,7 @@ public function getSettingsForm(array $parameters, $objectKey = null): Form
if (is_array($parameter) === true) {
$overwrittenValues = array_map(
function ($parameterKey) use ($configParameters) {
return isset($configParameters[$parameterKey]) ? $configParameters[$parameterKey] : null;
return $configParameters[$parameterKey] ?? null;
},
$parameter
);
6 changes: 2 additions & 4 deletions src/ObjectMembership/ObjectMembershipWithMapHandler.php
Original file line number Diff line number Diff line change
@@ -55,8 +55,7 @@ protected function getMembershipByMap(

if ($lockRecursive === true) {
$map = $this->getMap();
$generalMap = isset($map[ObjectMapHandler::TREE_MAP_PARENTS][$this->generalObjectType]) ?
$map[ObjectMapHandler::TREE_MAP_PARENTS][$this->generalObjectType] : [];
$generalMap = $map[ObjectMapHandler::TREE_MAP_PARENTS][$this->generalObjectType] ?? [];

if (isset($generalMap[$objectId]) === true) {
foreach ($generalMap[$objectId] as $parentId => $type) {
@@ -91,8 +90,7 @@ protected function getFullObjectsByMap(AbstractUserGroup $userGroup, bool $lockR

if ($lockRecursive === true) {
$map = $this->getMap();
$map = isset($map[ObjectMapHandler::TREE_MAP_CHILDREN][$objectType]) ?
$map[ObjectMapHandler::TREE_MAP_CHILDREN][$objectType] : [];
$map = $map[ObjectMapHandler::TREE_MAP_CHILDREN][$objectType] ?? [];
$map = array_intersect_key($map, $objects);

foreach ($map as $childrenIds) {
3 changes: 2 additions & 1 deletion src/Setup/Database/Column.php
Original file line number Diff line number Diff line change
@@ -134,7 +134,8 @@ public function isAutoIncrement(): bool
public function __toString(): string
{
$nullConstraint = ($this->isNull) ? 'NULL' : 'NOT NULL';
$column = "`{$this->name}` {$this->type} {$nullConstraint}";
$type = $this->type === 'INT(11)' ? 'INT' : $this->type;
$column = "`{$this->name}` {$type} {$nullConstraint}";

if ($this->default === null && $this->isNull) {
$column .= ' DEFAULT NULL';
3 changes: 1 addition & 2 deletions src/Setup/Database/DatabaseHandler.php
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ private function getTables(): array
$this->database->getUserGroupTable(),
$charsetCollate,
[
$this->databaseObjectFactory->createColumn('ID', 'INT(11)', false, null, true, true),
$this->databaseObjectFactory->createColumn('ID', 'INT', false, null, true, true),
$this->databaseObjectFactory->createColumn('groupname', 'TINYTEXT'),
$this->databaseObjectFactory->createColumn('groupdesc', 'TEXT'),
$this->databaseObjectFactory->createColumn('read_access', 'TINYTEXT'),
@@ -195,7 +195,6 @@ private function addCorruptedRows(Table $table, array &$information)

if ((string) $column !== (string) $existingColumn) {
$information[self::MODIFIED_COLUMNS][] = [$table, $column];
continue;
}
}

51 changes: 51 additions & 0 deletions src/Setup/Update/DatabaseUpdate7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* DatabaseUpdate6.php
*
* The DatabaseUpdate6 class file.
*
* PHP versions 5
*
* @author Alexander Schneider <[email protected]>
* @copyright 2008-2017 Alexander Schneider
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
* @version SVN: $id$
* @link http://wordpress.org/extend/plugins/user-access-manager/
*/

declare(strict_types=1);

namespace UserAccessManager\Setup\Update;

use UserAccessManager\Setup\Database\DatabaseUpdate;
use UserAccessManager\UserGroup\UserGroup;

/**
* Class DatabaseUpdate6
*
* @package UserAccessManager\Setup\Update
*/
class DatabaseUpdate7 extends DatabaseUpdate
{
/**
* Returns the version.
* @return string
*/
public function getVersion(): string
{
return '1.6.2';
}

/**
* Executes the update.
* @return bool
*/
public function update(): bool
{
$userGroupTable = $this->database->getUserGroupTable();
$alterQuery = "ALTER TABLE {$userGroupTable}
MODIFY ID INT NOT NULL";

return $this->database->query($alterQuery) !== false;
}
}
14 changes: 11 additions & 3 deletions src/User/UserHandler.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
use UserAccessManager\Config\MainConfig;
use UserAccessManager\Database\Database;
use UserAccessManager\Object\ObjectHandler;
use UserAccessManager\UserGroup\AbstractUserGroup;
use UserAccessManager\UserGroup\UserGroup;
use UserAccessManager\Wrapper\Wordpress;
use WP_User;
@@ -106,7 +107,7 @@ private function getCalculatedRange(string $ipRange): array
{
$ipRange = explode('-', $ipRange);
$rangeBegin = $ipRange[0];
$rangeEnd = isset($ipRange[1]) ? $ipRange[1] : $ipRange[0];
$rangeEnd = $ipRange[1] ?? $ipRange[0];

return [
$this->calculateIp($rangeBegin),
@@ -152,7 +153,7 @@ public function getUserRole($user): array
$capabilities = [];
}

return (count($capabilities) > 0) ? array_keys($capabilities) : [UserGroup::NONE_ROLE];
return (count($capabilities) > 0) ? array_keys($capabilities) : [AbstractUserGroup::NONE_ROLE];
}

/**
@@ -173,7 +174,14 @@ public function checkUserAccess($allowedCapability = false): bool
$roles = $this->getUserRole($currentUser);
$rolesMap = array_flip($roles);

$orderedRoles = [UserGroup::NONE_ROLE, 'subscriber', 'contributor', 'author', 'editor', 'administrator'];
$orderedRoles = [
AbstractUserGroup::NONE_ROLE,
'subscriber',
'contributor',
'author',
'editor',
'administrator'
];
$orderedRolesMap = array_flip($orderedRoles);

$userRoles = array_intersect_key($orderedRolesMap, $rolesMap);
4 changes: 2 additions & 2 deletions src/UserAccessManager.php
Original file line number Diff line number Diff line change
@@ -50,8 +50,8 @@
*/
class UserAccessManager
{
const VERSION = '2.2.20';
const DB_VERSION = '1.6.1';
const VERSION = '2.2.21';
const DB_VERSION = '1.6.2';

/**
* @var Php
2 changes: 1 addition & 1 deletion src/UserGroup/UserGroupAssignmentHandler.php
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ private function getDateParameter(array $data, string $name): ?string
$isValid = isset($data[$name]['date']) === true && isset($data[$name]['time']) === true
&& (string) $data[$name]['date'] !== '' && (string) $data[$name]['time'] !== '';

return ($isValid === true) ? (string) $data[$name]['date'] . 'T' . $data[$name]['time'] : null;
return ($isValid === true) ? ((string) $data[$name]['date']) . 'T' . $data[$name]['time'] : null;
}

/**
2 changes: 1 addition & 1 deletion src/View/AdminSettings.php
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@
<?php
$currentSectionKey = $controller->getCurrentTabGroupSection();
$groupForms = $controller->getCurrentGroupForms();
$form = isset($groupForms[$currentSectionKey]) ? $groupForms[$currentSectionKey] : reset($groupForms);
$form = $groupForms[$currentSectionKey] ?? reset($groupForms);
$cssClass = ($currentGroupKey === 'post_types') ? " uam_settings_group_post_type $currentSectionKey" : '';
$cssClass .= ($currentGroupKey === 'taxonomies') ? " uam_settings_group_taxonomies $currentSectionKey" : '';
?>
2 changes: 1 addition & 1 deletion src/View/GroupInfo.php
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@
$cleanGroupRoles = [];

foreach ($groupRoles as $key => $role) {
$cleanGroupRoles[] = isset($roleNames[$key]) ? $roleNames[$key] : $key;
$cleanGroupRoles[] = $roleNames[$key] ?? $key;
}

$content .= implode(', ', $cleanGroupRoles);
2 changes: 1 addition & 1 deletion src/View/UserGroups/UserGroupList.php
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@
<?php
foreach ($groupRoles as $key => $role) {
?>
<li><?php echo isset($roleNames[$key]) ? $roleNames[$key] : $key; ?></li>
<li><?php echo $roleNames[$key] ?? $key; ?></li>
<?php
}
?>
4 changes: 0 additions & 4 deletions tests/Unit/Controller/Backend/BackendControllerTest.php
Original file line number Diff line number Diff line change
@@ -79,7 +79,6 @@ public function testCanCreateInstance()
$this->getWordpress(),
$this->getWordpressConfig(),
$this->getUserHandler(),
$this->getFileHandler(),
$this->getSetupHandler()
);

@@ -118,7 +117,6 @@ public function testShowAdminNotice(): BackendController
$this->getWordpress(),
$wordpressConfig,
$this->getUserHandler(),
$this->getFileHandler(),
$setupHandler
);

@@ -239,7 +237,6 @@ public function testStylesAndScripts()
$wordpress,
$wordpressConfig,
$this->getUserHandler(),
$this->getFileHandler(),
$this->getSetupHandler()
);

@@ -290,7 +287,6 @@ public function testSetupAdminDashboard()
$wordpress,
$this->getWordpressConfig(),
$userHandler,
$this->getFileHandler(),
$this->getSetupHandler()
);

4 changes: 1 addition & 3 deletions tests/Unit/Controller/ControllerTest.php
Original file line number Diff line number Diff line change
@@ -63,9 +63,7 @@ private function getStub()
Controller::class,
[],
'',
false,
true,
true
false
);
}

4 changes: 2 additions & 2 deletions tests/Unit/Setup/Database/DatabaseHandlerTest.php
Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ public function testInstall()
$databaseObjectFactory->expects($this->exactly(13))
->method('createColumn')
->withConsecutive(
['ID', 'INT(11)', false, null, true, true],
['ID', 'INT', false, null, true, true],
['groupname', 'TINYTEXT'],
['groupdesc', 'TEXT'],
['read_access', 'TINYTEXT'],
@@ -252,7 +252,7 @@ public function testGetCorruptedDatabaseInformation()
$databaseObjectFactory->expects($this->exactly(16))
->method('createColumn')
->withConsecutive(
['ID', 'INT(11)', false, null, true, true],
['ID', 'INT', false, null, true, true],
['groupname', 'TINYTEXT'],
['groupdesc', 'TEXT'],
['read_access', 'TINYTEXT'],
2 changes: 1 addition & 1 deletion user-access-manager.php
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
* Plugin Name: User Access Manager
* Plugin URI: https://wordpress.org/plugins/user-access-manager/
* Author URI: https://twitter.com/GM_Alex
* Version: 2.2.20
* Version: 2.2.21
* Requires PHP: 7.2
* Author: Alexander Schneider
* Description: Manage the access to your posts, pages, categories and files.

0 comments on commit f2881ac

Please sign in to comment.