Skip to content

Commit

Permalink
Merge pull request #816 from publishpress/release-v2.8.0
Browse files Browse the repository at this point in the history
Release v2.8.0
  • Loading branch information
olatechpro authored May 11, 2023
2 parents 83bb0f4 + cba4a40 commit 382b322
Show file tree
Hide file tree
Showing 35 changed files with 2,696 additions and 1,281 deletions.
4 changes: 2 additions & 2 deletions capsman-enhanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: PublishPress Capabilities
* Plugin URI: https://publishpress.com/capability-manager/
* Description: Manage WordPress role definitions, per-site or network-wide. Organizes post capabilities by post type and operation.
* Version: 2.7.1
* Version: 2.8.0
* Author: PublishPress
* Author URI: https://publishpress.com/
* Text Domain: capsman-enhanced
Expand Down Expand Up @@ -44,7 +44,7 @@
}

if (!defined('CAPSMAN_VERSION')) {
define('CAPSMAN_VERSION', '2.7.1');
define('CAPSMAN_VERSION', '2.8.0');
define('CAPSMAN_ENH_VERSION', CAPSMAN_VERSION);
define('PUBLISHPRESS_CAPS_VERSION', CAPSMAN_VERSION);
}
Expand Down
77 changes: 77 additions & 0 deletions classes/pp-capabilities-installer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace PublishPress\Capabilities\Classes;

class PP_Capabilities_Installer
{
/**
* Runs methods when the plugin is running for the first time.
*
* @param string $currentVersion
*/
public static function runInstallTasks($currentVersion)
{
self::addPluginCapabilities();

/**
* @param string $currentVersion
*/
do_action('pp_capabilities_installed', $currentVersion);
}

/**
* Runs methods when the plugin is being upgraded to a most recent version.
*
* @param string $currentVersions
*/
public static function runUpgradeTasks($currentVersions)
{
if (version_compare($currentVersions, '2.8.0', '<')) {
self::addPluginCapabilities();
}

/**
* @param string $previousVersion
*/
do_action('pp_capabilities_upgraded', $currentVersions);
}

private static function addPluginCapabilities()
{
$eligible_roles = [];
$pp_capabilities = apply_filters('cme_publishpress_capabilities_capabilities', []);

/**
* We're not saving installation version prior to 2.8.0.
* So, we need another way to know if this is an upgrade or
* new installs to add or upgrade role capabilities.
*/
foreach ( wp_roles()->roles as $role_name => $role ) {
$role_object = get_role($role_name);
if ($role_object->has_cap('manage_capabilities')) {
$eligible_roles[] = $role_name;
}
}

/**
* If it's a fresh installation, we're giving 'administrator' and 'editor'
* all capabilities
*/
if (empty($eligible_roles)) {
$eligible_roles = ['administrator', 'editor'];
}

/**
* Add capabilities to eligible roles
*/
foreach ($eligible_roles as $eligible_role) {
$role = get_role($eligible_role);
foreach ($pp_capabilities as $cap) {
if (!$role->has_cap($cap)) {
$role->add_cap($cap);
}
}
}
}

}
Loading

0 comments on commit 382b322

Please sign in to comment.