PluginProbe
User Access Manager / 1.2.14
User Access Manager v1.2.14
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | user-access-manager.php +316 -52 2.3.17 → 1.2.14 View file →
@@ -2,80 +2,344 @@
2 2 /**
3 3 * Plugin Name: User Access Manager
4 4 * Plugin URI: https://wordpress.org/plugins/user-access-manager/
5 5 * Author URI: https://twitter.com/GM_Alex
6 - * Version: 2.3.17
7 - * Requires PHP: 8.0
6 + * Version: 1.2.14
8 7 * Author: Alexander Schneider
9 8 * Description: Manage the access to your posts, pages, categories and files.
10 - * Text Domain: user-access-manager
11 - *
9 + *
12 10 * user-access-manager.php
13 11 *
14 - * The user access manager main file.
15 - *
16 12 * PHP versions 5
17 - *
13 + *
14 + * @category UserAccessManager
15 + * @package UserAccessManager
18 16 * @author Alexander Schneider <[email protected]>
19 - * @copyright 2008-2017 Alexander Schneider
17 + * @copyright 2008-2016 Alexander Schneider
20 18 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
21 - * @version SVN: $id$
19 + * @version SVN: $Id$
22 20 * @link http://wordpress.org/extend/plugins/user-access-manager/
23 - */
21 +*/
24 22
25 -function initUam() {
26 - $basePath = __DIR__ . DIRECTORY_SEPARATOR;
23 +//Paths
24 +load_plugin_textdomain('user-access-manager', false, 'user-access-manager/lang');
25 +define('UAM_URLPATH', plugins_url('', __FILE__).'/');
26 +define('UAM_REALPATH', WP_PLUGIN_DIR.'/'.plugin_basename(dirname(__FILE__)).'/');
27 27
28 - //Load language
29 - require_once $basePath . 'includes' . DIRECTORY_SEPARATOR . 'language.php';
30 - $locale = apply_filters('plugin_locale', get_locale(), 'user-access-manager');
31 - load_textdomain(
32 - 'user-access-manager',
33 - WP_LANG_DIR . DIRECTORY_SEPARATOR . 'user-access-manager' . DIRECTORY_SEPARATOR . 'user-access-manager-' . $locale . '.mo'
28 +
29 +//Defines
30 +require_once 'includes/database.define.php';
31 +require_once 'includes/language.define.php';
32 +
33 +
34 +//Check requirements
35 +$blStop = false;
36 +
37 +//Check php version
38 +$sPhpVersion = phpversion();
39 +
40 +if (version_compare($sPhpVersion, '5.3') === -1) {
41 + add_action(
42 + 'admin_notices',
43 + create_function(
44 + '',
45 + 'echo \'<div id="message" class="error"><p><strong>'.
46 + sprintf(TXT_UAM_PHP_VERSION_TO_LOW, $sPhpVersion).
47 + '</strong></p></div>\';'
48 + )
34 49 );
35 - load_plugin_textdomain(
36 - 'user-access-manager',
37 - false,
38 - plugin_basename(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'languages'
50 +
51 + $blStop = true;
52 +}
53 +
54 +//Check wordpress version
55 +global $wp_version;
56 +
57 +if (version_compare($wp_version, '3.4') === -1) {
58 + add_action(
59 + 'admin_notices',
60 + create_function(
61 + '',
62 + 'echo \'<div id="message" class="error"><p><strong>'.
63 + sprintf(TXT_UAM_WORDPRESS_VERSION_TO_LOW, $wp_version).
64 + '</strong></p></div>\';'
65 + )
39 66 );
67 +
68 + $blStop = true;
69 +}
40 70
41 - //--- Check requirements ---
71 +//If we have a error stop plugin.
72 +if ($blStop) {
73 + return;
74 +}
42 75
43 - //Check php version
44 - if (version_compare((string)phpversion(), '7.2') === -1) {
45 - add_action(
46 - 'admin_notices',
47 - function () {
48 - echo '<div id="message" class="error"><p><strong>'
49 - . sprintf(TXT_UAM_PHP_VERSION_TO_LOW, phpversion())
50 - . '</strong></p></div>';
76 +
77 +//Classes
78 +require_once 'class/UamConfig.php';
79 +require_once 'class/UserAccessManager.php';
80 +require_once 'class/UamUserGroup.php';
81 +require_once 'class/UamAccessHandler.php';
82 +
83 +if (class_exists("UserAccessManager")) {
84 + $oUserAccessManager = new UserAccessManager();
85 +}
86 +
87 +//Initialize the admin panel
88 +if (!function_exists("userAccessManagerAP")) {
89 + /**
90 + * Creates the filters and actions for the admin panel
91 + */
92 + function userAccessManagerAP()
93 + {
94 + /**
95 + * @var UserAccessManager $oUserAccessManager
96 + */
97 + global $oUserAccessManager;
98 + $oCurrentUser = $oUserAccessManager->getCurrentUser();
99 +
100 + if (!isset($oUserAccessManager)) {
101 + return;
102 + }
103 +
104 + $oUserAccessManager->setAtAdminPanel();
105 + $oConfig = $oUserAccessManager->getConfig();
106 +
107 + if ($oUserAccessManager->isDatabaseUpdateNecessary()) {
108 + $sLink = 'admin.php?page=uam_setup';
109 +
110 + add_action(
111 + 'admin_notices',
112 + create_function(
113 + '',
114 + 'echo \'<div id="message" class="error"><p><strong>'.
115 + sprintf(TXT_UAM_NEED_DATABASE_UPDATE, $sLink).
116 + '</strong></p></div>\';'
117 + )
118 + );
119 + }
120 +
121 + $oUamAccessHandler = $oUserAccessManager->getAccessHandler();
122 + $aTaxonomies = $oUserAccessManager->getPostTypes();
123 +
124 + if (isset($_POST['taxonomy'])) {
125 + $aTaxonomies[$_POST['taxonomy']] = $_POST['taxonomy'];
126 + } elseif (isset($_GET['taxonomy'])) {
127 + $aTaxonomies[$_GET['taxonomy']] = $_GET['taxonomy'];
128 + }
129 +
130 + if ($oUamAccessHandler->checkUserAccess()
131 + || $oConfig->authorsCanAddPostsToGroups() === true
132 + ) {
133 + //Admin actions
134 + if (function_exists('add_action')) {
135 + add_action('admin_print_styles', array($oUserAccessManager, 'addStyles'));
136 + add_action('wp_print_scripts', array($oUserAccessManager, 'addScripts'));
137 +
138 + add_action('manage_posts_custom_column', array($oUserAccessManager, 'addPostColumn'), 10, 2);
139 + add_action('manage_pages_custom_column', array($oUserAccessManager, 'addPostColumn'), 10, 2);
140 + add_action('save_post', array($oUserAccessManager, 'savePostData'));
141 +
142 + add_action('manage_media_custom_column', array($oUserAccessManager, 'addPostColumn'), 10, 2);
143 +
144 + //Actions are only called when the attachment content is modified so we can't use it.
145 + //add_action('add_attachment', array($oUserAccessManager, 'savePostData'));
146 + //add_action('edit_attachment', array($oUserAccessManager, 'savePostData'));
147 +
148 + add_action('edit_user_profile', array($oUserAccessManager, 'showUserProfile'));
149 + add_action('profile_update', array($oUserAccessManager, 'saveUserData'));
150 +
151 + add_action('bulk_edit_custom_box', array($oUserAccessManager, 'addBulkAction'));
152 + add_action('create_term', array($oUserAccessManager, 'saveTermData'));
153 + add_action('edit_term', array($oUserAccessManager, 'saveTermData'));
154 +
155 + //Taxonomies
156 + foreach ($aTaxonomies as $sTaxonomy) {
157 + add_action('manage_'.$sTaxonomy.'_custom_column', array($oUserAccessManager, 'addTermColumn'), 10, 3);
158 + add_action($sTaxonomy.'_add_form_fields', array($oUserAccessManager, 'showTermEditForm'));
159 + add_action($sTaxonomy.'_edit_form_fields', array($oUserAccessManager, 'showTermEditForm'));
160 + }
51 161 }
52 - );
53 162
54 - return;
163 + //Admin filters
164 + if (function_exists('add_filter')) {
165 + //The filter we use instead of add|edit_attachment action, reason see top
166 + add_filter('attachment_fields_to_save', array($oUserAccessManager, 'saveAttachmentData'));
167 +
168 + add_filter('manage_posts_columns', array($oUserAccessManager, 'addPostColumnsHeader'));
169 + add_filter('manage_pages_columns', array($oUserAccessManager, 'addPostColumnsHeader'));
170 +
171 + add_filter('manage_users_columns', array($oUserAccessManager, 'addUserColumnsHeader'), 10);
172 + add_filter('manage_users_custom_column', array($oUserAccessManager, 'addUserColumn'), 10, 3);
173 +
174 + foreach ($aTaxonomies as $sTaxonomy) {
175 + add_filter('manage_edit-'.$sTaxonomy.'_columns', array($oUserAccessManager, 'addTermColumnsHeader'));
176 + }
177 + }
178 +
179 + if ($oConfig->lockFile() === true) {
180 + add_action('media_meta', array($oUserAccessManager, 'showMediaFile'), 10, 2);
181 + add_filter('manage_media_columns', array($oUserAccessManager, 'addPostColumnsHeader'));
182 + }
183 + }
184 +
185 + //Clean up at deleting should always be done.
186 + if (function_exists('add_action')) {
187 + add_action('update_option_permalink_structure', array($oUserAccessManager, 'updatePermalink'));
188 + add_action('wp_dashboard_setup', array($oUserAccessManager, 'setupAdminDashboard'));
189 + add_action('delete_post', array($oUserAccessManager, 'removePostData'));
190 + add_action('delete_attachment', array($oUserAccessManager, 'removePostData'));
191 + add_action('delete_user', array($oUserAccessManager, 'removeUserData'));
192 + add_action('delete_term', array($oUserAccessManager, 'removeTermData'));
193 + }
194 +
195 + $oUserAccessManager->noRightsToEditContent();
55 196 }
197 +}
56 198
57 - //Check WordPress version
58 - global $wp_version;
199 +if (!function_exists("userAccessManagerAPMenu")) {
200 + /**
201 + * Creates the menu at the admin panel
202 + */
203 + function userAccessManagerAPMenu()
204 + {
205 + /**
206 + * @var UserAccessManager $oUserAccessManager
207 + */
208 + global $oUserAccessManager;
209 + $oCurrentUser = $oUserAccessManager->getCurrentUser();
210 +
211 + if (!isset($oUserAccessManager)) {
212 + return;
213 + }
214 +
215 + $oConfig = $oUserAccessManager->getConfig();
216 +
217 + if (ini_get('safe_mode')
218 + && $oConfig->getDownloadType() === 'fopen'
219 + ) {
220 + add_action(
221 + 'admin_notices',
222 + create_function(
223 + '',
224 + 'echo \'<div id="message" class="error"><p><strong>'.
225 + TXT_UAM_FOPEN_WITHOUT_SAVEMODE_OFF.
226 + '</strong></p></div>\';'
227 + )
228 + );
229 + }
230 +
231 + get_userdata($oCurrentUser->ID);
232 + $oUamAccessHandler = $oUserAccessManager->getAccessHandler();
233 +
234 + if ($oUamAccessHandler->checkUserAccess()) {
235 + //TODO
236 + /**
237 + * --- BOF ---
238 + * Not the best way to handle full user access capabilities seems
239 + * to be the right way, but it is way difficult.
240 + */
241 +
242 + //Admin main menu
243 + if (function_exists('add_menu_page')) {
244 + add_menu_page('User Access Manager', 'UAM', 'manage_options', 'uam_usergroup', array($oUserAccessManager, 'printAdminPage'), 'div');
245 + }
246 +
247 + //Admin sub menus
248 + if (function_exists('add_submenu_page')) {
249 + add_submenu_page('uam_usergroup', TXT_UAM_MANAGE_GROUP, TXT_UAM_MANAGE_GROUP, 'read', 'uam_usergroup', array($oUserAccessManager, 'printAdminPage'));
250 + add_submenu_page('uam_usergroup', TXT_UAM_SETTINGS, TXT_UAM_SETTINGS, 'read', 'uam_settings', array($oUserAccessManager, 'printAdminPage'));
251 + add_submenu_page('uam_usergroup', TXT_UAM_SETUP, TXT_UAM_SETUP, 'read', 'uam_setup', array($oUserAccessManager, 'printAdminPage'));
252 + add_submenu_page('uam_usergroup', TXT_UAM_ABOUT, TXT_UAM_ABOUT, 'read', 'uam_about', array($oUserAccessManager, 'printAdminPage'));
253 +
254 + do_action('uam_add_submenu');
255 + }
256 + /**
257 + * --- EOF ---
258 + */
259 + }
260 +
261 + if ($oUamAccessHandler->checkUserAccess()
262 + || $oConfig->authorsCanAddPostsToGroups() === true
263 + ) {
264 + //Admin meta boxes
265 + if (function_exists('add_meta_box')) {
266 + $aPostableTypes = $oUamAccessHandler->getPostableTypes();
267 +
268 + foreach ($aPostableTypes as $sPostableType) {
269 + add_meta_box('uma_post_access', 'Access', array($oUserAccessManager, 'editPostContent'), $sPostableType, 'side');
270 + }
271 + }
272 + }
273 + }
274 +}
59 275
60 - if (version_compare((string)$wp_version, '4.6') === -1) {
61 - add_action(
62 - 'admin_notices',
63 - function () use ($wp_version) {
64 - echo '<div id="message" class="error"><p><strong>'
65 - . sprintf(TXT_UAM_WORDPRESS_VERSION_TO_LOW, $wp_version)
66 - . '</strong></p></div>';
67 - }
68 - );
276 +if (!function_exists("userAccessManagerUninstall")) {
277 + function userAccessManagerUninstall() {
278 + $oUserAccessManager = new UserAccessManager();
279 + $oUserAccessManager->uninstall();
280 + }
281 +}
69 282
70 - return;
283 +if (isset($oUserAccessManager)) {
284 + //install
285 + if (function_exists('register_activation_hook')) {
286 + register_activation_hook(__FILE__, array($oUserAccessManager, 'install'));
71 287 }
288 +
289 + //uninstall
290 + if (function_exists('register_uninstall_hook')) {
291 + register_uninstall_hook(__FILE__, 'userAccessManagerUninstall');
292 + } elseif (function_exists('register_deactivation_hook')) {
293 + //Fallback
294 + register_deactivation_hook(__FILE__, array($oUserAccessManager, 'uninstall'));
295 + }
296 +
297 + //deactivation
298 + if (function_exists('register_deactivation_hook')) {
299 + register_deactivation_hook(__FILE__, array($oUserAccessManager, 'deactivate'));
300 + }
301 +
302 + //Redirect
303 + $oConfig = $oUserAccessManager->getConfig();
304 +
305 + if ($oConfig->getRedirect() !== 'false' || isset($_GET['uamgetfile'])) {
306 + add_filter('wp_headers', array($oUserAccessManager, 'redirect'), 10, 2);
307 + }
72 308
73 - //Defines
74 - require_once $basePath . 'includes' . DIRECTORY_SEPARATOR . 'version.php';
75 - require_once $basePath.'vendor/autoload.php';
76 - require_once $basePath.'init.php';
77 - global $userAccessManager;
78 - $userAccessManager = initUserAccessManger();
309 + //Actions
310 + if (function_exists('add_action')) {
311 + add_action('wp_print_scripts', array($oUserAccessManager, 'addScripts'));
312 + add_action('wp_print_styles', array($oUserAccessManager, 'addStyles'));
313 + add_action('admin_init', 'userAccessManagerAP');
314 + add_action('admin_menu', 'userAccessManagerAPMenu');
315 + }
316 +
317 + //Filters
318 + if (function_exists('add_filter')) {
319 + add_filter('wp_get_attachment_thumb_url', array($oUserAccessManager, 'getFileUrl'), 10, 2);
320 + add_filter('wp_get_attachment_url', array($oUserAccessManager, 'getFileUrl'), 10, 2);
321 + add_filter('the_posts', array($oUserAccessManager, 'showPosts'));
322 + add_filter('posts_where_paged', array($oUserAccessManager, 'showPostSql'));
323 + add_filter('get_terms_args', array($oUserAccessManager, 'getTermArguments'));
324 + add_filter('wp_get_nav_menu_items', array($oUserAccessManager, 'showCustomMenu'));
325 + add_filter('comments_array', array($oUserAccessManager, 'showComment'));
326 + add_filter('the_comments', array($oUserAccessManager, 'showComment'));
327 + add_filter('get_pages', array($oUserAccessManager, 'showPages'), 20);
328 + add_filter('get_terms', array($oUserAccessManager, 'showTerms'), 20, 2);
329 + add_filter('get_term', array($oUserAccessManager, 'showTerm'), 20, 2);
330 + add_filter('get_ancestors', array($oUserAccessManager, 'showAncestors'), 20, 4);
331 + add_filter('get_next_post_where', array($oUserAccessManager, 'showNextPreviousPost'));
332 + add_filter('get_previous_post_where', array($oUserAccessManager, 'showNextPreviousPost'));
333 + add_filter('post_link', array($oUserAccessManager, 'cachePostLinks'), 10, 2);
334 + add_filter('edit_post_link', array($oUserAccessManager, 'showGroupMembership'), 10, 2);
335 + add_filter('parse_query', array($oUserAccessManager, 'parseQuery'));
336 + add_filter('getarchives_where', array($oUserAccessManager, 'showPostSql'));
337 + add_filter('wp_count_posts', array($oUserAccessManager, 'showPostCount'), 10, 2);
338 + add_filter('wpseo_sitemap_entry', array($oUserAccessManager, 'wpSeoUrl'), 1, 3); // Yaost Sitemap Plugin
339 + }
79 340 }
80 341
81 -add_action('init', 'initUam', 0);
342 +//Add the cli interface to the known commands
343 +if (defined('WP_CLI') && WP_CLI) {
344 + include __DIR__.'/includes/wp-cli.php';
345 +}