| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: PublishPress Permissions Free |
| 5 |
* Plugin URI: https://publishpress.com/presspermit |
| 6 |
* Description: PublishPress Permissions allows you to enable or deny access to posts, pages, categories, tags and more. |
| 7 |
* Version: 4.8.4 |
| 8 |
* Author: PublishPress |
| 9 |
* Author URI: https://publishpress.com/ |
| 10 |
* Text Domain: press-permit-core |
| 11 |
* Domain Path: /languages/ |
| 12 |
* Requires at least: 5.5 |
| 13 |
* Requires PHP: 7.2.5 |
| 14 |
* |
| 15 |
* Copyright (c) 2025 PublishPress |
| 16 |
* |
| 17 |
* GNU General Public License, Free Software Foundation <https://www.gnu.org/licenses/gpl-3.0.html> |
| 18 |
* |
| 19 |
* This program is free software: you can redistribute it and/or modify |
| 20 |
* it under the terms of the GNU General Public License as published by |
| 21 |
* the Free Software Foundation, either version 3 of the License, or |
| 22 |
* (at your option) any later version. |
| 23 |
* |
| 24 |
* This program is distributed in the hope that it will be useful, |
| 25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 |
* GNU General Public License for more details. |
| 28 |
* |
| 29 |
* You should have received a copy of the GNU General Public License |
| 30 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 31 |
* |
| 32 |
* @package PublishPress Permissions |
| 33 |
* @author PublishPress |
| 34 |
* @copyright Copyright (c) 2025 PublishPress. All rights reserved. |
| 35 |
* @license GNU General Public License version 3 |
| 36 |
* @link https://publishpress.com/ |
| 37 |
* |
| 38 |
**/ |
| 39 |
|
| 40 |
if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 41 |
|
| 42 |
global $wp_version; |
| 43 |
|
| 44 |
$min_php_version = '7.2.5'; |
| 45 |
$min_wp_version = '5.5'; |
| 46 |
|
| 47 |
$invalid_php_version = version_compare(phpversion(), $min_php_version, '<'); |
| 48 |
$invalid_wp_version = version_compare($wp_version, $min_wp_version, '<'); |
| 49 |
|
| 50 |
// If the PHP version is not compatible, terminate the plugin execution and show an admin notice. |
| 51 |
if (is_admin() && $invalid_php_version) { |
| 52 |
add_action( |
| 53 |
'admin_notices', |
| 54 |
function () use ($min_php_version) { |
| 55 |
if (current_user_can('activate_plugins')) { |
| 56 |
echo '<div class="notice notice-error"><p>'; |
| 57 |
printf( |
| 58 |
'PublishPress Permissions Pro requires PHP version %s or higher.', |
| 59 |
esc_html($min_php_version) |
| 60 |
); |
| 61 |
echo '</p></div>'; |
| 62 |
} |
| 63 |
} |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
// If the WP version is not compatible, terminate the plugin execution and show an admin notice. |
| 68 |
if (is_admin() && $invalid_wp_version) { |
| 69 |
add_action( |
| 70 |
'admin_notices', |
| 71 |
function () use ($min_wp_version) { |
| 72 |
if (current_user_can('activate_plugins')) { |
| 73 |
echo '<div class="notice notice-error"><p>'; |
| 74 |
printf( |
| 75 |
'PublishPress Permissions Pro requires WordPress version %s or higher.', |
| 76 |
esc_html($min_wp_version) |
| 77 |
); |
| 78 |
echo '</p></div>'; |
| 79 |
} |
| 80 |
} |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
if ($invalid_php_version || $invalid_wp_version) { |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
$pro_active = false; |
| 89 |
|
| 90 |
global $presspermit_loaded_by_pro; |
| 91 |
|
| 92 |
$presspermit_loaded_by_pro = strpos(str_replace('\\', '/', __FILE__), 'vendor/publishpress/'); |
| 93 |
|
| 94 |
// Detect separate Pro plugin activation, but not self-activation (this file loaded in vendor library by Pro) |
| 95 |
if (false === $presspermit_loaded_by_pro) { |
| 96 |
foreach ((array)get_option('active_plugins') as $plugin_file) { |
| 97 |
if (false !== strpos($plugin_file, 'presspermit-pro.php')) { |
| 98 |
$pro_active = true; |
| 99 |
break; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
if (!$pro_active && is_multisite()) { |
| 104 |
foreach (array_keys((array)get_site_option('active_sitewide_plugins')) as $plugin_file) { |
| 105 |
if (false !== strpos($plugin_file, 'presspermit-pro.php')) { |
| 106 |
$pro_active = true; |
| 107 |
break; |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
if ($pro_active) { |
| 113 |
add_filter( |
| 114 |
'plugin_row_meta', |
| 115 |
function ($links, $file) { |
| 116 |
if ($file == plugin_basename(__FILE__)) { |
| 117 |
$links[] = __('<strong>This plugin can be deleted.</strong>', 'press-permit-core'); |
| 118 |
} |
| 119 |
|
| 120 |
return $links; |
| 121 |
}, |
| 122 |
10, |
| 123 |
2 |
| 124 |
); |
| 125 |
return; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
if (! defined('PRESSPERMIT_INTERNAL_VENDORPATH')) { |
| 130 |
define('PRESSPERMIT_INTERNAL_VENDORPATH', __DIR__ . '/lib/vendor'); |
| 131 |
} |
| 132 |
|
| 133 |
if (! $presspermit_loaded_by_pro) { |
| 134 |
$includeFileRelativePath = '/publishpress/instance-protection/include.php'; |
| 135 |
if (file_exists(PRESSPERMIT_INTERNAL_VENDORPATH . $includeFileRelativePath)) { |
| 136 |
require_once PRESSPERMIT_INTERNAL_VENDORPATH . $includeFileRelativePath; |
| 137 |
} |
| 138 |
|
| 139 |
if (class_exists('PublishPressInstanceProtection\\Config')) { |
| 140 |
$pluginCheckerConfig = new PublishPressInstanceProtection\Config(); |
| 141 |
$pluginCheckerConfig->pluginSlug = 'press-permit-core'; |
| 142 |
$pluginCheckerConfig->pluginFolder = 'press-permit-core'; |
| 143 |
$pluginCheckerConfig->pluginName = 'PublishPress Permissions'; |
| 144 |
|
| 145 |
$pluginChecker = new PublishPressInstanceProtection\InstanceChecker($pluginCheckerConfig); |
| 146 |
} |
| 147 |
|
| 148 |
if ( |
| 149 |
! class_exists('ComposerAutoloaderInitPressPermit') |
| 150 |
&& file_exists(PRESSPERMIT_INTERNAL_VENDORPATH . '/autoload.php') |
| 151 |
) { |
| 152 |
require_once PRESSPERMIT_INTERNAL_VENDORPATH . '/autoload.php'; |
| 153 |
} |
| 154 |
|
| 155 |
include_once PRESSPERMIT_INTERNAL_VENDORPATH . '/publishpress/wordpress-version-notices/src/include.php'; |
| 156 |
} |
| 157 |
|
| 158 |
if ((!defined('PRESSPERMIT_FILE') && !$pro_active) || $presspermit_loaded_by_pro) { |
| 159 |
define('PRESSPERMIT_FILE', __FILE__); |
| 160 |
define('PRESSPERMIT_ABSPATH', __DIR__); |
| 161 |
define('PRESSPERMIT_CLASSPATH', __DIR__ . '/classes/PublishPress/Permissions'); |
| 162 |
|
| 163 |
if (!defined('PRESSPERMIT_CLASSPATH_COMMON')) { |
| 164 |
define('PRESSPERMIT_CLASSPATH_COMMON', __DIR__ . '/classes/PressShack'); |
| 165 |
} |
| 166 |
|
| 167 |
define('PRESSPERMIT_DB_VERSION', '2.0.1'); |
| 168 |
|
| 169 |
if (!defined('PRESSPERMIT_DEBUG')) { |
| 170 |
define('PRESSPERMIT_DEBUG', false); |
| 171 |
} |
| 172 |
|
| 173 |
include_once(constant('PRESSPERMIT_DEBUG') ? __DIR__ . '/library/debug.php' : __DIR__ . '/library/debug_shell.php'); |
| 174 |
|
| 175 |
if (!function_exists('presspermit_err')) { |
| 176 |
function presspermit_err($err_slug, $args = []) |
| 177 |
{ |
| 178 |
if (is_admin()) { |
| 179 |
require_once(PRESSPERMIT_CLASSPATH . '/ErrorNotice.php'); |
| 180 |
return new \PublishPress\Permissions\ErrorNotice($err_slug, $args); |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
function presspermit_load() |
| 186 |
{ |
| 187 |
global $presspermit_loaded_by_pro; |
| 188 |
|
| 189 |
$presspermit_loaded_by_pro = strpos(str_replace('\\', '/', __FILE__), 'vendor/publishpress/'); |
| 190 |
|
| 191 |
global $pagenow; |
| 192 |
|
| 193 |
if (is_admin() && isset($pagenow) && ('customize.php' == $pagenow) |
| 194 |
|| (is_admin() && isset($pagenow) && ('edit.php' == $pagenow) && !empty($_REQUEST['post_type']) && ('give_forms' == sanitize_key($_REQUEST['post_type']))) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 195 |
) { |
| 196 |
return; |
| 197 |
} |
| 198 |
|
| 199 |
if (!function_exists('presspermit')) { |
| 200 |
require_once(__DIR__ . '/functions.php'); |
| 201 |
} |
| 202 |
|
| 203 |
// Critical errors that prevent initialization |
| 204 |
if ((defined('PPC_FOLDER') && defined('PPC_BASENAME') && function_exists('ppc_deactivate') && presspermit_err('pp_core_active')) |
| 205 |
|| (defined('PP_VERSION') && function_exists('pp_get_otype_option') && presspermit_err('pp_legacy_active')) // Press Permit 1.x (circa 2012) active |
| 206 |
|| (defined('SCOPER_VERSION') && function_exists('rs_get_user') && presspermit_err('rs_active') && ! is_admin()) |
| 207 |
|| (constant('PRESSPERMIT_DEBUG') && is_admin() && presspermit_editing_plugin()) // avoid lockout in case of erroneous plugin edit via wp-admin |
| 208 |
) { |
| 209 |
return; |
| 210 |
} |
| 211 |
|
| 212 |
define('PRESSPERMIT_VERSION', '4.8.4'); |
| 213 |
|
| 214 |
if (!defined('PRESSPERMIT_READ_PUBLIC_CAP')) { |
| 215 |
define('PRESSPERMIT_READ_PUBLIC_CAP', 'read'); |
| 216 |
} |
| 217 |
|
| 218 |
if (!$presspermit_loaded_by_pro) { |
| 219 |
require_once(__DIR__ . '/includes/Core.php'); |
| 220 |
new \PublishPress\Permissions\Core(); |
| 221 |
|
| 222 |
if (is_admin()) { |
| 223 |
require_once(__DIR__ . '/includes/CoreAdmin.php'); |
| 224 |
new \PublishPress\Permissions\CoreAdmin(); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
if (!defined('PRESSPERMIT_LEGACY_HOOKS')) { |
| 229 |
define('PRESSPERMIT_LEGACY_HOOKS', false); |
| 230 |
} |
| 231 |
|
| 232 |
// Non-critical intialization errors (may prevent integration with module or external plugin, but continue with initialization) |
| 233 |
if (defined('RVY_VERSION') && !defined('REVISIONARY_VERSION')) { |
| 234 |
presspermit_err('old_extension', ['module_title' => 'Revisionary', 'min_version' => '1.3.5']); |
| 235 |
} |
| 236 |
|
| 237 |
require_once(PRESSPERMIT_CLASSPATH_COMMON . '/LibArray.php'); |
| 238 |
class_alias('\PressShack\LibArray', '\PublishPress\Arr'); |
| 239 |
class_alias('\PressShack\LibArray', '\PublishPress\Permissions\Arr'); |
| 240 |
class_alias('\PressShack\LibArray', '\PublishPress\Permissions\DB\Arr'); |
| 241 |
class_alias('\PressShack\LibArray', '\PublishPress\Permissions\UI\Arr'); |
| 242 |
class_alias('\PressShack\LibArray', '\PublishPress\Permissions\UI\Dashboard\Arr'); |
| 243 |
|
| 244 |
require_once(PRESSPERMIT_CLASSPATH_COMMON . '/LibWP.php'); |
| 245 |
class_alias('\PressShack\LibWP', '\PublishPress\PWP'); |
| 246 |
class_alias('\PressShack\LibWP', '\PublishPress\Permissions\PWP'); |
| 247 |
class_alias('\PressShack\LibWP', '\PublishPress\Permissions\DB\PWP'); |
| 248 |
class_alias('\PressShack\LibWP', '\PublishPress\Permissions\UI\PWP'); |
| 249 |
class_alias('\PressShack\LibWP', '\PublishPress\Permissions\UI\Dashboard\PWP'); |
| 250 |
class_alias('\PressShack\LibWP', '\PublishPress\Permissions\UI\Handlers\PWP'); |
| 251 |
|
| 252 |
require_once(PRESSPERMIT_CLASSPATH . '/API.php'); |
| 253 |
|
| 254 |
require_once(__DIR__ . '/db-config.php'); |
| 255 |
|
| 256 |
require_once(__DIR__ . '/classes/PublishPress/Permissions.php'); |
| 257 |
|
| 258 |
presspermit(); |
| 259 |
} |
| 260 |
|
| 261 |
// negative priority to precede any default WP action handlers |
| 262 |
if ($presspermit_loaded_by_pro) { |
| 263 |
presspermit_load(); // Pro support |
| 264 |
} else { |
| 265 |
add_action('plugins_loaded', 'presspermit_load', -10); |
| 266 |
} |
| 267 |
|
| 268 |
register_activation_hook( |
| 269 |
__FILE__, |
| 270 |
function () { |
| 271 |
require_once(__DIR__ . '/activation.php'); |
| 272 |
} |
| 273 |
); |
| 274 |
} |
| 275 |
|