From dbb5f262cf54f0d279e7399eb68ed8605efb0be3 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Tue, 23 Jun 2020 10:50:32 -0400 Subject: [PATCH 01/40] Compat: Divi front end editor - non-Admins can't edit new page --- classes/PublishPress/Permissions/PostFilters.php | 2 +- functions.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/PublishPress/Permissions/PostFilters.php b/classes/PublishPress/Permissions/PostFilters.php index 0a195e11..a2d7aef4 100644 --- a/classes/PublishPress/Permissions/PostFilters.php +++ b/classes/PublishPress/Permissions/PostFilters.php @@ -511,7 +511,7 @@ public function getPostsWhere($args) if (isset($_REQUEST['context']) && ('edit' == $_REQUEST['context'])) { $required_operation = (!empty($_REQUEST['parent_exclude'])) ? 'associate' : 'edit'; // @todo: better criteria } else { - $required_operation = 'read'; + $required_operation = (presspermit_is_preview()) ? 'edit' : 'read'; } } else { $required_operation = (PWP::isFront() && !presspermit_is_preview()) ? 'read' : 'edit'; diff --git a/functions.php b/functions.php index 57940b7e..650aeaea 100644 --- a/functions.php +++ b/functions.php @@ -21,6 +21,8 @@ function presspermit_is_preview() { if (!$is_preview = is_preview()) { if (defined('ELEMENTOR_VERSION')) { $is_preview = !empty($_REQUEST['elementor-preview']); + } elseif (defined('ET_CORE')) { + $is_preview = !empty($_REQUEST['et_fb']); } } From 339bcb1253faa636d3c58b7c8fb84ea9b8c19ed8 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Tue, 23 Jun 2020 11:01:38 -0400 Subject: [PATCH 02/40] If post editing is limited by term selection, default new posts to an allowed term --- .../Permissions/Collab/AdminFilters.php | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/presspermit-collaboration/classes/Permissions/Collab/AdminFilters.php b/modules/presspermit-collaboration/classes/Permissions/Collab/AdminFilters.php index d4be1bd1..ce07afcd 100644 --- a/modules/presspermit-collaboration/classes/Permissions/Collab/AdminFilters.php +++ b/modules/presspermit-collaboration/classes/Permissions/Collab/AdminFilters.php @@ -42,7 +42,7 @@ function __construct() add_filter('presspermit_add_exception', [$this, 'fltAddException']); // Track autodrafts by postmeta in case WP sets their post_status to draft - add_action('save_post', [$this, 'actSavePost'], 10, 2); + add_action('save_post', [$this, 'actSavePost'], 10, 3); add_filter('wp_insert_post_empty_content', [$this, 'fltLogInsertPost'], 10, 2); add_filter('save_post', [$this, 'fltUnloadCurrentUserExceptions']); @@ -51,14 +51,29 @@ function __construct() add_filter('editable_roles', [$this, 'fltEditableRoles'], 99); } - function actSavePost($post_id, $post) + function actSavePost($post_id, $post, $update) { if (!empty(presspermit()->flags['ignore_save_post'])) { return; } - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { update_post_meta($post_id, '_pp_is_autodraft', true); + + } elseif (!$update) { + // For configurations that limit access by term selection, need to default to an allowed term + if (!presspermit()->isAdministrator()) { + require_once(PRESSPERMIT_COLLAB_CLASSPATH . '/PostTermsSave.php'); + + foreach(get_object_taxonomies($post->post_type) as $taxonomy) { + if (!$terms = wp_get_object_terms($post->ID, $taxonomy, ['fields' => 'ids'])) { + if ($terms = PostTermsSave::fltPreObjectTerms($terms, $taxonomy)) { + wp_set_post_terms($post->ID, $terms, $taxonomy); + } + } + } + } + } } function fltUnloadCurrentUserExceptions($item_id) From 060a52db45106e81c4cda78d9a6ce32bcba33127 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Tue, 23 Jun 2020 11:03:44 -0400 Subject: [PATCH 03/40] Support listing of uneditable posts on Posts / Pages screen Support capabilities list_posts, list_others_posts, list_pitch_pages, etc. for inclusion in Posts / Pages listing without ability to edit --- .../PublishPress/Permissions/PostFilters.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/classes/PublishPress/Permissions/PostFilters.php b/classes/PublishPress/Permissions/PostFilters.php index a2d7aef4..db1dfbe1 100644 --- a/classes/PublishPress/Permissions/PostFilters.php +++ b/classes/PublishPress/Permissions/PostFilters.php @@ -628,13 +628,30 @@ public function getPostsWhere($args) } if ($reqd_caps) { // note: this function is called only for listing query filters (not for user_has_cap filter) - if (apply_filters( + if ($missing_caps = apply_filters( 'presspermit_query_missing_caps', array_diff($reqd_caps, array_keys($user->allcaps)), $reqd_caps, $post_type, $meta_cap )) { + // Support list_posts, list_others_posts, list_pitch_pages etc. for listing uneditable posts on Posts screen + if (('edit' == $required_operation) && empty($args['has_cap_check']) && empty(presspermit()->flags['cap_filter_in_process'])) { + foreach($reqd_caps as $key => $cap) { + if (in_array($cap, $missing_caps)) { + $list_cap = str_replace('edit_', 'list_', $cap); + + if (!empty($user->allcaps[$list_cap])) { + $reqd_caps[$key] = $list_cap; + } + } + } + + if (!array_diff($reqd_caps, array_keys($user->allcaps))) { + $have_site_caps['user'][] = $status; + } + } + // remove "others" and "private" cap requirements for post author $owner_reqd_caps = self::getBaseCaps($reqd_caps, $post_type); From 63b6f67853ade3885dd2ce3e4461fa55af666701 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Tue, 23 Jun 2020 11:05:17 -0400 Subject: [PATCH 04/40] Tag version 3.2.2-beta --- press-permit-core.php | 4 ++-- readme.txt | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/press-permit-core.php b/press-permit-core.php index 30914ce4..60b38031 100644 --- a/press-permit-core.php +++ b/press-permit-core.php @@ -5,7 +5,7 @@ * Description: Advanced yet accessible content permissions. Give users or groups type-specific roles. Enable or block access for specific posts or terms. * Author: PublishPress * Author URI: https://publishpress.com/ - * Version: 3.2.1 + * Version: 3.2.2-rc * Text Domain: press-permit-core * Domain Path: /languages/ * Min WP Version: 4.9.7 @@ -98,7 +98,7 @@ function presspermit_load() { return; } - define('PRESSPERMIT_VERSION', '3.2.1'); + define('PRESSPERMIT_VERSION', '3.2.2-rc'); if (!$presspermit_loaded_by_pro) { require_once(__DIR__ . '/includes/Core.php'); diff --git a/readme.txt b/readme.txt index dc2766e4..9620699f 100644 --- a/readme.txt +++ b/readme.txt @@ -128,6 +128,11 @@ Press Permit Core + PP extension users: download PublishPress Permissions Pro fr == Changelog == += 3.2.2-rc = +* Fixed : New post creation locked author out of further editing if editing permission restricted by term and necessary term was not selected (now auto-select allowed term if none selected) +* Feature : Support capabilities list_posts, list_others_posts, list_pitch_pages, etc. for inclusion in Posts / Pages listing without ability to edit +* Compat : Divi - non-Administrators could not edit new page on front end + = 3.2.1 - 1 Jun 2020 = * Fixed : Supplemental roles were not effective on some sites * Fixed : Menu management limitations were not applied From f00f7809632e776250615213741f0359725fbd3b Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Wed, 24 Jun 2020 13:08:16 -0400 Subject: [PATCH 05/40] Fixed: false positive for detection of Press Permit Pro <= 2.6 On Permissions > Settings > Install, the following caption was displayed even without a previous installation of Press Permit Pro: 'To temporarily restore Pro features before migrating to a publishpress.com account, delete this version and install Press Permit Core 2.6.x' This occurred because of the move of the Collaborative Publishing module into the free plugin. --- includes/SettingsTabInstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/SettingsTabInstall.php b/includes/SettingsTabInstall.php index 44f12477..6470ceb5 100644 --- a/includes/SettingsTabInstall.php +++ b/includes/SettingsTabInstall.php @@ -163,7 +163,7 @@ public function optionsUI() ); } - $downgrade_note = (is_array($opt_val) && count($opt_val) > 1) || get_option('ppce_version') || get_option('pps_version') || get_option('ppp_version'); + $downgrade_note = (is_array($opt_val) && count($opt_val) > 1); if ($msg || $downgrade_note || $key_string) : $section = 'key'; // --- UPDATE KEY SECTION --- From 1e064ae1794cee596a6fec88c0eb512db7747b97 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Wed, 24 Jun 2020 13:11:20 -0400 Subject: [PATCH 06/40] Tag version 3.2.2-rc2 --- press-permit-core.php | 4 ++-- readme.txt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/press-permit-core.php b/press-permit-core.php index 60b38031..cd265d32 100644 --- a/press-permit-core.php +++ b/press-permit-core.php @@ -5,7 +5,7 @@ * Description: Advanced yet accessible content permissions. Give users or groups type-specific roles. Enable or block access for specific posts or terms. * Author: PublishPress * Author URI: https://publishpress.com/ - * Version: 3.2.2-rc + * Version: 3.2.2-rc2 * Text Domain: press-permit-core * Domain Path: /languages/ * Min WP Version: 4.9.7 @@ -98,7 +98,7 @@ function presspermit_load() { return; } - define('PRESSPERMIT_VERSION', '3.2.2-rc'); + define('PRESSPERMIT_VERSION', '3.2.2-rc2'); if (!$presspermit_loaded_by_pro) { require_once(__DIR__ . '/includes/Core.php'); diff --git a/readme.txt b/readme.txt index 9620699f..cc33fc7e 100644 --- a/readme.txt +++ b/readme.txt @@ -128,9 +128,10 @@ Press Permit Core + PP extension users: download PublishPress Permissions Pro fr == Changelog == -= 3.2.2-rc = += 3.2.2-rc2 = * Fixed : New post creation locked author out of further editing if editing permission restricted by term and necessary term was not selected (now auto-select allowed term if none selected) * Feature : Support capabilities list_posts, list_others_posts, list_pitch_pages, etc. for inclusion in Posts / Pages listing without ability to edit +* Fixed : Permissions > Settings > Install displayed instructions for restoring a Press Permit Pro 2.6.x installation, even if none was installed (since 3.0) * Compat : Divi - non-Administrators could not edit new page on front end = 3.2.1 - 1 Jun 2020 = From 7232777d559764d5ca0ea4b59be96ae987c6ede9 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Thu, 25 Jun 2020 15:47:38 -0400 Subject: [PATCH 07/40] Settings screen: Install tab used invalid logic to detect PP Pro 2.6.x Permissions > Settings > Install displayed instructions for restoring a Press Permit Pro 2.6.x installation, even if none was installed (since 3.0) --- includes/SettingsTabInstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/SettingsTabInstall.php b/includes/SettingsTabInstall.php index 6470ceb5..44f12477 100644 --- a/includes/SettingsTabInstall.php +++ b/includes/SettingsTabInstall.php @@ -163,7 +163,7 @@ public function optionsUI() ); } - $downgrade_note = (is_array($opt_val) && count($opt_val) > 1); + $downgrade_note = (is_array($opt_val) && count($opt_val) > 1) || get_option('ppce_version') || get_option('pps_version') || get_option('ppp_version'); if ($msg || $downgrade_note || $key_string) : $section = 'key'; // --- UPDATE KEY SECTION --- From b6e6bf2e2e33356a7217a09e0c3f53710867e4c6 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Thu, 25 Jun 2020 15:51:39 -0400 Subject: [PATCH 08/40] Settings UI: remove "Hide non-editable posts" checkbox, add new captions Deprecation of this workaround corresponds to new capabilities support: list_posts, list_others_pages, etc. --- .../PublishPress/Permissions/PostFilters.php | 6 ++++- .../Permissions/UI/SettingsTabCore.php | 24 +++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/classes/PublishPress/Permissions/PostFilters.php b/classes/PublishPress/Permissions/PostFilters.php index db1dfbe1..f96a8d7e 100644 --- a/classes/PublishPress/Permissions/PostFilters.php +++ b/classes/PublishPress/Permissions/PostFilters.php @@ -153,8 +153,12 @@ public function fltPostsClauses($clauses, $_wp_query = false, $args = []) } if ( + // This solution is deprecated in favor of capability support for list_posts, list_others_pages, etc. + // But with removal of settings checkbox, need to maintain support for sites that rely on this previous workaround, which was enabled by constant PP_ADMIN_READONLY_LISTABLE + // (1) Sites that have the admin_hide_uneditable_posts option stored with false value + // (2) Sites that inadvertantly set options to defaults but want to restore this workaround. Now supporting an additional constant definition (disclosed by support as needed) rather than the checkbox UI. is_admin() && (!$pp->moduleActive('collaboration') || defined('PP_ADMIN_READONLY_LISTABLE')) - && !$pp->getOption('admin_hide_uneditable_posts') + && (!$pp->getOption('admin_hide_uneditable_posts') || defined('PP_ADMIN_NO_FILTER')) ) { return $clauses; } diff --git a/classes/PublishPress/Permissions/UI/SettingsTabCore.php b/classes/PublishPress/Permissions/UI/SettingsTabCore.php index 5eaf44e8..0cb3248d 100644 --- a/classes/PublishPress/Permissions/UI/SettingsTabCore.php +++ b/classes/PublishPress/Permissions/UI/SettingsTabCore.php @@ -52,7 +52,6 @@ public function optionCaptions($captions) 'display_user_profile_groups' => __('Permission Groups on User Profile', 'press-permit-core'), 'display_user_profile_roles' => __('Supplemental Roles on User Profile', 'press-permit-core'), 'new_user_groups_ui' => __('Select Permission Groups at User creation', 'press-permit-core'), - 'admin_hide_uneditable_posts' => __('Hide non-editable posts', 'press-permit-core'), 'post_blockage_priority' => __('Post-specific Permissions take priority', 'press-permit-core'), ]; @@ -301,18 +300,19 @@ public function optionsUI() optionCheckbox('display_branding', $tab, $section, ''); - $listable = defined('PP_ADMIN_READONLY_LISTABLE'); - - $hint = ($pp->moduleExists('collaboration') && !$listable) - ? __('Note: To allow listing of uneditable posts in wp-admin, define constant PP_ADMIN_READONLY_LISTABLE', 'press-permit-core') - : ''; - - $args = ($pp->moduleActive('collaboration') && !$listable) - ? ['val' => 1, 'disabled' => true, 'no_storage' => true] - : []; - - $ui->optionCheckbox('admin_hide_uneditable_posts', $tab, $section, $hint, '', $args); + if (defined('PP_ADMIN_READONLY_LISTABLE') && (!$pp->getOption('admin_hide_uneditable_posts') || defined('PP_ADMIN_POSTS_NO_FILTER'))) { + $hint = __('Unmodified from WordPress default behavior. To enable filtering, remove constant definition PP_ADMIN_READONLY_LISTABLE.', 'press-permit-core'); + } else { + $hint = (!$pp->moduleActive('collaboration')) + ? __('Uneditable posts are hidden from wp-admin listings. To expose them, use a role editor to add desired capabilities: list_posts, list_other_pages etc.', 'press-permit-core') + : __('To customize editing permissions, enable the Collaborative Publishing module.', 'press-permit-core'); + } + ?> +

+ ', '', $hint); ?> +

Date: Thu, 25 Jun 2020 15:59:11 -0400 Subject: [PATCH 09/40] Tag version 3.2.2 --- press-permit-core.php | 4 ++-- readme.txt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/press-permit-core.php b/press-permit-core.php index cd265d32..5a5ba899 100644 --- a/press-permit-core.php +++ b/press-permit-core.php @@ -5,7 +5,7 @@ * Description: Advanced yet accessible content permissions. Give users or groups type-specific roles. Enable or block access for specific posts or terms. * Author: PublishPress * Author URI: https://publishpress.com/ - * Version: 3.2.2-rc2 + * Version: 3.2.2 * Text Domain: press-permit-core * Domain Path: /languages/ * Min WP Version: 4.9.7 @@ -98,7 +98,7 @@ function presspermit_load() { return; } - define('PRESSPERMIT_VERSION', '3.2.2-rc2'); + define('PRESSPERMIT_VERSION', '3.2.2'); if (!$presspermit_loaded_by_pro) { require_once(__DIR__ . '/includes/Core.php'); diff --git a/readme.txt b/readme.txt index cc33fc7e..3f221ffc 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: restrict, access, permissions, cms, user, private, category, pages, privac Requires at least: 4.9.7 Tested up to: 5.4 Requires PHP: 5.6.20 -Stable tag: 3.2.1 +Stable tag: 3.2.2 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -123,12 +123,12 @@ PublishPress Permissions creates and uses the following tables: pp_groups, pp_gr == Upgrade Notice == -= 3.2.1 = += 3.2.2 = Press Permit Core + PP extension users: download PublishPress Permissions Pro from publishpress.com instead of upgrading to this version. == Changelog == -= 3.2.2-rc2 = += 3.2.2 - 29 Jun 2020 = * Fixed : New post creation locked author out of further editing if editing permission restricted by term and necessary term was not selected (now auto-select allowed term if none selected) * Feature : Support capabilities list_posts, list_others_posts, list_pitch_pages, etc. for inclusion in Posts / Pages listing without ability to edit * Fixed : Permissions > Settings > Install displayed instructions for restoring a Press Permit Pro 2.6.x installation, even if none was installed (since 3.0) From 72810af5a4f7c60c9e358e963d501f313c67d612 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Fri, 26 Jun 2020 15:50:09 -0400 Subject: [PATCH 10/40] Settings UI: reversed logic for Collaborative Publishing activation check --- classes/PublishPress/Permissions/UI/SettingsTabCore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/PublishPress/Permissions/UI/SettingsTabCore.php b/classes/PublishPress/Permissions/UI/SettingsTabCore.php index 0cb3248d..f4b0a045 100644 --- a/classes/PublishPress/Permissions/UI/SettingsTabCore.php +++ b/classes/PublishPress/Permissions/UI/SettingsTabCore.php @@ -303,7 +303,7 @@ public function optionsUI() if (defined('PP_ADMIN_READONLY_LISTABLE') && (!$pp->getOption('admin_hide_uneditable_posts') || defined('PP_ADMIN_POSTS_NO_FILTER'))) { $hint = __('Unmodified from WordPress default behavior. To enable filtering, remove constant definition PP_ADMIN_READONLY_LISTABLE.', 'press-permit-core'); } else { - $hint = (!$pp->moduleActive('collaboration')) + $hint = ($pp->moduleActive('collaboration')) ? __('Uneditable posts are hidden from wp-admin listings. To expose them, use a role editor to add desired capabilities: list_posts, list_other_pages etc.', 'press-permit-core') : __('To customize editing permissions, enable the Collaborative Publishing module.', 'press-permit-core'); } From 4cecdc4baeaee76ec10b0887504f4d1d76921239 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Fri, 26 Jun 2020 15:52:00 -0400 Subject: [PATCH 11/40] Fix invalid get_post_stati() call Final two function arguments were outside closing parenthesis --- .../classes/Permissions/Collab/Revisionary/Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php b/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php index 9e38a332..74f9b2de 100644 --- a/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php +++ b/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php @@ -148,7 +148,7 @@ public function flt_additions_clause($clause, $operation, $post_type, $args) } if ( $revise_ids ) { - $status_csv = "'" . implode("','", get_post_stati(['public' => true, 'private' => true]), 'names', 'or') . "'"; + $status_csv = "'" . implode("','", get_post_stati(['public' => true, 'private' => true], 'names', 'or')) . "'"; $parent_clause []= "( {$args['src_table']}.post_author = $user->ID" . " AND {$args['src_table']}.comment_count IN ('" . implode("','", $revise_ids) . "') AND {$args['src_table']}.post_status IN ($status_csv) )"; From a236f490b8e8c3e69888c0acb27578bb1d1c3936 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Fri, 26 Jun 2020 16:09:03 -0400 Subject: [PATCH 12/40] Revision Permissions for specific terms didn't enable editing existing revisions --- .../Permissions/Collab/Revisionary/Admin.php | 115 +++++++++--------- 1 file changed, 55 insertions(+), 60 deletions(-) diff --git a/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php b/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php index 74f9b2de..26580819 100644 --- a/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php +++ b/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php @@ -94,80 +94,75 @@ public function flt_additions_clause($clause, $operation, $post_type, $args) && !in_array($post_type, apply_filters('presspermit_unrevisable_types', []), true)) { $user = presspermit()->getUser(); - if ( isset($args['ids']) ) { // PressPermit Core >= 2.6.2 @todo: eliminate else case? + if ('post' == $args['via_item_source']) { $hide_others_revisions = rvy_get_option('revisor_lock_others_revisions') && ( - (!empty($type_obj->cap->edit_others_posts) && empty($type_obj->cap->edit_others_posts)) + (!empty($type_obj->cap->edit_posts) && empty($type_obj->cap->edit_others_posts)) || (!empty($type_obj->cap->edit_others_posts) && empty($user->allcaps[$type_obj->cap->edit_others_posts])) ); - // If we are hiding other revisions from revisors, need to distinguish - // between 'edit' exceptions and 'revise' exceptions (which are merged upstream for other reasons). - if ($hide_others_revisions && empty($user->allcaps['edit_others_revisions'])) { + // If we are hiding other revisions from revisors, need to distinguish + // between 'edit' exceptions and 'revise' exceptions (which are merged upstream for other reasons). + if ($hide_others_revisions && empty($user->allcaps['edit_others_revisions'])) { $revise_ids = []; + + $via_item_type = (isset($args['via_item_type'])) ? $args['via_item_type'] : $post_type; + $revise_ids = $user->getExceptionPosts( + 'revise', + 'additional', + $via_item_type, + ['status' => $args['status']] + ); + + $edit_ids = ($revise_ids) ? array_diff($args['ids'], $revise_ids) : $args['ids']; - switch ($args['via_item_source']) { - case 'post': - $via_item_type = (isset($args['via_item_type'])) ? $args['via_item_type'] : $post_type; - $revise_ids = $user->getExceptionPosts( - 'revise', - 'additional', - $via_item_type, - ['status' => $args['status']] - ); - - break; - - case 'term': - // @todo - - /* - foreach(presspermit()->getEnabledTaxonomies(['object_type' => $post_type]) as $taxonomy) { - $tt_ids = $user->getExceptionTerms( - 'revise', - 'additional', - $post_type, - $taxonomy, - ['status' => $args['status'], 'merge_universals' => true] - ); - - $revise_ids = array_merge($revise_ids, $tt_ids); - } -*/ - - break; - } - - $edit_ids = ($revise_ids) ? array_diff($args['ids'], $revise_ids) : $args['ids']; - - if ( $edit_ids || $revise_ids ) { - $parent_clause = array(); - - if ( $edit_ids ) { - $parent_clause []= "( {$args['src_table']}.comment_count IN ('" . implode("','", $edit_ids) . "') )"; - } - - if ( $revise_ids ) { + if ( $edit_ids || $revise_ids ) { + $parent_clause = []; + + if ( $edit_ids ) { + $parent_clause []= "( {$args['src_table']}.comment_count IN ('" . implode("','", $edit_ids) . "') )"; + } + + if ( $revise_ids ) { $status_csv = "'" . implode("','", get_post_stati(['public' => true, 'private' => true], 'names', 'or')) . "'"; $parent_clause []= "( {$args['src_table']}.post_author = $user->ID" . " AND {$args['src_table']}.comment_count IN ('" . implode("','", $revise_ids) . "') AND {$args['src_table']}.post_status IN ($status_csv) )"; - } - - $parent_clause = 'AND (' . Arr::implode(' OR ', $parent_clause) . ' )'; - + } + + $parent_clause = 'AND (' . Arr::implode(' OR ', $parent_clause) . ' )'; + $append_clause .= " OR ( {$args['src_table']}.post_status IN ('pending-revision', 'future-revision') $parent_clause )"; - } - } else { - // Not hiding other users' revisions from Revisors, so list all posts with 'edit' or 'revise' exceptions regardless of author. + } + } else { + // Not hiding other users' revisions from Revisors, so list all posts with 'edit' or 'revise' exceptions regardless of author. $append_clause .= " OR ( {$args['src_table']}.post_status IN ('pending-revision', 'future-revision')" . " AND {$args['src_table']}.comment_count {$args['in_clause']} )"; - } - } else { - // Older PP Core version doesn't pass ids, so can't distinguish between 'edit' and 'revise' exceptions; retain previous behavior. - $append_clause .= " OR ( {$args['src_table']}.post_status IN ('pending-revision', 'future-revision')" - . " AND {$args['src_table']}.post_author = " . presspermit()->getUser()->ID - . " AND {$args['src_table']}.comment_count {$args['in_clause']} )"; + } + } elseif ('term' == $args['via_item_source']) { + $revise_tt_ids = []; + + foreach(presspermit()->getEnabledTaxonomies(['object_type' => $post_type]) as $taxonomy) { + $tt_ids = $user->getExceptionTerms( + 'revise', + 'additional', + $post_type, + $taxonomy, + ['status' => $args['status'], 'merge_universals' => true] + ); + + $revise_tt_ids = array_merge($revise_tt_ids, $tt_ids); + } + + if ($revise_tt_ids) { + global $wpdb; + + $status_csv = "'" . implode("','", get_post_stati(['public' => true, 'private' => true], 'names', 'or')) . "'"; + + $parent_tt_clause = "( {$args['src_table']}.comment_count IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ('" . implode("','", $revise_tt_ids) . "') ) )"; + + $append_clause .= " OR ( {$args['src_table']}.post_status IN ('pending-revision', 'future-revision') AND $parent_tt_clause )"; + } } } From ccb170db2403ffd589fbc55bdb5bf1c5802698d0 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Fri, 3 Jul 2020 15:57:49 -0400 Subject: [PATCH 13/40] getPostStatuses(): add context parameter This supports Status Control usage in Pro. --- classes/PressShack/LibWP.php | 4 ++-- classes/PublishPress/Permissions/PostFilters.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/PressShack/LibWP.php b/classes/PressShack/LibWP.php index 1361fef5..78c35dfc 100644 --- a/classes/PressShack/LibWP.php +++ b/classes/PressShack/LibWP.php @@ -157,7 +157,7 @@ public static function doingCron() } // support array matching for post type - public static function getPostStatuses($args, $return = 'names', $operator = 'and') + public static function getPostStatuses($args, $return = 'names', $operator = 'and', $params = []) { if (isset($args['post_type'])) { $post_type = $args['post_type']; @@ -174,7 +174,7 @@ public static function getPostStatuses($args, $return = 'names', $operator = 'an $statuses = get_post_stati($args, $return, $operator); } - return apply_filters('presspermit_get_post_statuses', $statuses, $args, $return, $operator); + return apply_filters('presspermit_get_post_statuses', $statuses, $args, $return, $operator, $params); } public static function findPostType($post_id = 0, $return_default = true) diff --git a/classes/PublishPress/Permissions/PostFilters.php b/classes/PublishPress/Permissions/PostFilters.php index f96a8d7e..1f7d3e2c 100644 --- a/classes/PublishPress/Permissions/PostFilters.php +++ b/classes/PublishPress/Permissions/PostFilters.php @@ -386,7 +386,7 @@ public function fltPostsWhere($where, $args = []) $valid_stati['future'] = 'future'; } } else { - $valid_stati = PWP::getPostStatuses(['internal' => false, 'post_type' => $post_types], 'names'); + $valid_stati = PWP::getPostStatuses(['internal' => false, 'post_type' => $post_types], 'names', '', ['context' => 'edit']); } if (in_array('attachment', $post_types, true)) { @@ -551,7 +551,7 @@ public function getPostsWhere($args) $use_statuses = array_merge($use_statuses, $limit_statuses); } } else { - $use_statuses = PWP::getPostStatuses(['internal' => false, 'post_type' => $post_types], 'object'); + $use_statuses = PWP::getPostStatuses(['internal' => false, 'post_type' => $post_types], '', 'object', ['context' => 'edit']); } $use_statuses = apply_filters('presspermit_query_post_statuses', $use_statuses, $args ); From 6b6d920fd683a37ab1777f4e52efce347a26772e Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Fri, 3 Jul 2020 16:18:57 -0400 Subject: [PATCH 14/40] Remove obsolete commented code This code was commented out when PublishPress Revisions was updated to support page parent revisioning. --- .../Permissions/Collab/Revisionary/Admin.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php b/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php index 26580819..0bcd93c8 100644 --- a/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php +++ b/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php @@ -12,7 +12,7 @@ function __construct() { } add_filter('map_meta_cap', [$this, 'flt_mapMetaCap'], 1, 4); - //add_filter('pre_post_parent', [$this, 'fltPageParent']); + add_filter('presspermit_get_exception_items', [$this, 'flt_get_exception_items'], 10, 5); add_filter('presspermit_additions_clause', [$this, 'flt_additions_clause'], 10, 4); @@ -72,18 +72,6 @@ public function flt_term_include_clause($clause, $args = []) return $clause; } - /* - public function fltPageParent($parent_id) - { - global $revisionary; - if (!empty($revisionary->admin->revision_save_in_progress)) { - do_action('presspermit_disable_page_parent_filter'); - } - - return $parent_id; - } - */ - public function flt_additions_clause($clause, $operation, $post_type, $args) { //$args = compact( 'status', 'in_clause', 'src_table' ) From 05735ddab7409339e268e980d2d225a12e372663 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Fri, 3 Jul 2020 17:06:59 -0400 Subject: [PATCH 15/40] Settings > Install: invalid Press Permit Pro 2.6.x migration caption Settings > Install caption about restoring a Press Permit Pro 2.6.x installation, even if none was installed. Since version 3.0. This occurred due to the Collaborative Publishing module being moved into Free. --- includes/SettingsTabInstall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/SettingsTabInstall.php b/includes/SettingsTabInstall.php index 44f12477..b92794e1 100644 --- a/includes/SettingsTabInstall.php +++ b/includes/SettingsTabInstall.php @@ -163,7 +163,7 @@ public function optionsUI() ); } - $downgrade_note = (is_array($opt_val) && count($opt_val) > 1) || get_option('ppce_version') || get_option('pps_version') || get_option('ppp_version'); + $downgrade_note = (is_array($opt_val) && count($opt_val) > 1) || get_option('pps_version') || get_option('ppp_version'); if ($msg || $downgrade_note || $key_string) : $section = 'key'; // --- UPDATE KEY SECTION --- From fa85f3e9e42b771c6e2f44ec51f4d0102721e4d3 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Fri, 3 Jul 2020 17:55:33 -0400 Subject: [PATCH 16/40] Term-specific Permissions ineffective in some configurations Fixes #107 * Fixed : Restrictive term-specific Permissions were not correctly negated by permissive term-specific restrictions assigned to another role or group for the same user * Compat : Revisions - Revision Permissions assigned for specific categories did not enable editing of existing revisions --- .../Permissions/DB/Permissions.php | 20 ++++- .../Permissions/Collab/Revisionary/Admin.php | 83 +++++++++++++++++++ 2 files changed, 99 insertions(+), 4 deletions(-) diff --git a/classes/PublishPress/Permissions/DB/Permissions.php b/classes/PublishPress/Permissions/DB/Permissions.php index 23e1a585..21c13836 100644 --- a/classes/PublishPress/Permissions/DB/Permissions.php +++ b/classes/PublishPress/Permissions/DB/Permissions.php @@ -395,10 +395,7 @@ public static function addExceptionClauses($where, $required_operation, $post_ty if ('edit' == $required_operation) { if (!empty($user->except['revise_post']['term'][$taxonomy]['additional'][$post_type][''])) { - if (!empty($tt_ids[''])) { $revise_ttids['{published}'] = array_merge($revise_ttids['{published}'], $user->except['revise_post']['term'][$taxonomy]['additional'][$post_type]['']); - $tt_ids[''] = array_diff($tt_ids[''], $revise_ttids['{published}']); - } } } @@ -626,7 +623,22 @@ public static function addTermRestrictionsClause($required_operation, $post_type . "') ) $type_exemption_clause ) $term_additions_clause $post_additions_clause )"; } - return $where; + $args = compact( + 'required_operation', + 'post_type', + 'src_table', + 'merge_additions', + 'exempt_post_types', + 'mod_types', + 'tx_args', + 'additional_ttids', + 'apply_object_additions', + 'term_additions_clause', + 'post_additions_clause', + 'type_exemption_clause' + ); + + return apply_filters('presspermit_term_restrictions_clause', $where, $args); } // returns propagated exceptions items for which (a) the base eitem no longer exists, or (b) the base eitem was changed to "item only" diff --git a/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php b/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php index 0bcd93c8..535a4b32 100644 --- a/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php +++ b/modules/presspermit-collaboration/classes/Permissions/Collab/Revisionary/Admin.php @@ -15,6 +15,8 @@ function __construct() { add_filter('presspermit_get_exception_items', [$this, 'flt_get_exception_items'], 10, 5); + add_filter('presspermit_term_restrictions_clause', [$this, 'fltTermRestrictionsClause'], 10, 2); + add_filter('presspermit_additions_clause', [$this, 'flt_additions_clause'], 10, 4); add_filter('presspermit_administrator_caps', [$this, 'flt_pp_administrator_caps'], 5); @@ -229,6 +231,11 @@ public function flt_get_exception_items($exception_items, $operation, $mod_type, $$var = $args[$var]; } + if ('term' == $via_item_source) { + // Don't implement term exceptions by merging with edit_post exceptions, due to complication of applying revision exceptions for published posts only + return $exception_items; + } + $user = presspermit()->getUser(); if (!isset($user->except['revise_post'])) { @@ -262,6 +269,82 @@ public function flt_get_exception_items($exception_items, $operation, $mod_type, return $exception_items; } + // Apply term revision restrictions separately with status clause to avoid removing unpublished posts from the listing + function fltTermRestrictionsClause($where, $args) { + global $wpdb; + + $defaults = array_fill_keys( + ['required_operation', + 'post_type', + 'src_table', + 'merge_additions', + 'exempt_post_types', + 'mod_types', + 'tx_args', + 'additional_ttids', + 'apply_object_additions', + 'term_additions_clause', + 'post_additions_clause', + 'type_exemption_clause' + ], '' + ); + + $args = array_merge($defaults, $args); + foreach (array_keys($defaults) as $var) { + $$var = $args[$var]; + } + + $user = presspermit()->getUser(); + + $excluded_ttids_published = []; + + foreach (presspermit()->getEnabledTaxonomies($tx_args) as $taxonomy) { + $tx_additional_ids = ($merge_additions) + ? $user->getExceptionTerms($required_operation, 'additional', $post_type, $taxonomy, ['status' => '', 'merge_universals' => true]) + : []; + + foreach ($mod_types as $mod) { + if ($tt_ids = $user->getExceptionTerms('revise', $mod, $post_type, $taxonomy, ['status' => '', 'merge_universals' => true])) { + $tx_additional_ids = ($merge_additions) + ? $user->getExceptionTerms('revise', 'additional', $post_type, $taxonomy, ['status' => '', 'merge_universals' => true]) + : []; + + $published_stati_csv = implode("','", get_post_stati(['public' => true, 'private' => true], 'names', 'OR' )); + + if ('include' == $mod) { + if ($tx_additional_ids) { + $tt_ids = array_merge($tt_ids, $tx_additional_ids); + } + + $term_include_clause = apply_filters( + 'presspermit_term_include_clause', + "( $src_table.post_status NOT IN ('$published_stati_csv') OR $src_table.ID IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ('" . implode("','", $tt_ids) . "') ) )", + compact('tt_ids', 'src_table') + ); + + $where .= " AND ( $term_include_clause $term_additions_clause $post_additions_clause $type_exemption_clause )"; + continue 2; + + } else { + if ($tx_additional_ids) { + $tt_ids = array_diff($tt_ids, $tx_additional_ids); + } + + $excluded_ttids_published = array_merge($excluded_ttids_published, $tt_ids); + } + } + } + } + + if ($excluded_ttids_published) { + $where .= " AND ( ($src_table.post_status NOT IN ('$published_stati_csv') OR $src_table.ID NOT IN ( SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ('" + . implode("','", $excluded_ttids_published) + . "') ) $type_exemption_clause ) $term_additions_clause $post_additions_clause )"; + } + + return $where; + } + public static function adjust_revision_reqd_caps($reqd_caps, $object_type) { global $revisionary; From e981e1250ffefd20f54ba14f4046f727d4d93f0c Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Fri, 3 Jul 2020 17:59:40 -0400 Subject: [PATCH 17/40] Update change log --- readme.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index 3f221ffc..e0870002 100644 --- a/readme.txt +++ b/readme.txt @@ -128,11 +128,15 @@ Press Permit Core + PP extension users: download PublishPress Permissions Pro fr == Changelog == -= 3.2.2 - 29 Jun 2020 = += 3.2.2 - 6 Jul 2020 = * Fixed : New post creation locked author out of further editing if editing permission restricted by term and necessary term was not selected (now auto-select allowed term if none selected) +* Fixed : Term-specific Permissions were not applied correctly in some configurations +* Fixed : Restrictive term-specific Permissions were not correctly negated by permissive term-specific restrictions assigned to another role or group for the same user +* Compat : Revisions - Revision Permissions assigned for specific categories did not enable editing of existing revisions +* Compat : Divi - non-Administrators could not edit new page on front end +* Compat : PublishPress Authors - invalid error message for minimum PressPermit Pro version (note: Permissions is still not fully compatible with PublishPress Authors) * Feature : Support capabilities list_posts, list_others_posts, list_pitch_pages, etc. for inclusion in Posts / Pages listing without ability to edit * Fixed : Permissions > Settings > Install displayed instructions for restoring a Press Permit Pro 2.6.x installation, even if none was installed (since 3.0) -* Compat : Divi - non-Administrators could not edit new page on front end = 3.2.1 - 1 Jun 2020 = * Fixed : Supplemental roles were not effective on some sites From 1d14dd0b75e88284693ab514c2ac0027db867637 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Mon, 6 Jul 2020 18:09:59 -0400 Subject: [PATCH 18/40] Call is_main_site() instead of checking for $blog_id equal to 1 Some networks have a main site with ID not equal to 1. --- .../classes/Permissions/Import/DB/SourceConfig.php | 11 +++++------ .../classes/Permissions/Import/Importer.php | 4 ++-- .../Permissions/Import/UI/SettingsTabImport.php | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/presspermit-import/classes/Permissions/Import/DB/SourceConfig.php b/modules/presspermit-import/classes/Permissions/Import/DB/SourceConfig.php index a9f1fb44..dbec3a07 100644 --- a/modules/presspermit-import/classes/Permissions/Import/DB/SourceConfig.php +++ b/modules/presspermit-import/classes/Permissions/Import/DB/SourceConfig.php @@ -89,7 +89,7 @@ function hasUnimported($install_code) { switch ($install_code) { case 'rs' : if (!$this->hasTable($wpdb->role_scope_rs)) { - if (!MULTISITE || (1 != $blog_id)) + if (!MULTISITE || !is_main_site()) return false; } @@ -97,8 +97,9 @@ function hasUnimported($install_code) { $importer = RoleScoper::instance(); if (MULTISITE) { - if (1 == $blog_id) + if (is_main_site()) { return true; + } $groups = []; // will deal with netwide groups in import function } else { @@ -127,10 +128,8 @@ function hasUnimported($install_code) { if (!$wpdb->get_results("SHOW TABLES LIKE '$wpdb->pp_roles'")) return false; - if (MULTISITE) { - global $blog_id; - if (1 == $blog_id) - return true; + if (MULTISITE && is_main_site()) { + return true; } require_once(PRESSPERMIT_IMPORT_CLASSPATH . '/DB/PressPermitBeta.php'); diff --git a/modules/presspermit-import/classes/Permissions/Import/Importer.php b/modules/presspermit-import/classes/Permissions/Import/Importer.php index 58ba11f2..d4933a20 100644 --- a/modules/presspermit-import/classes/Permissions/Import/Importer.php +++ b/modules/presspermit-import/classes/Permissions/Import/Importer.php @@ -149,7 +149,7 @@ private function undoImport($run_id) { global $wpdb, $blog_id; - if (is_multisite() && (1 === intval($blog_id))) { + if (is_multisite() && is_main_site()) { $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id"); $orig_blog_id = $blog_id; } else { @@ -196,7 +196,7 @@ private function undoAllImports() global $wpdb, $blog_id; if (is_multisite()) - $site_clause = (1 === intval($blog_id)) ? "AND site > 0" : "AND site = '$blog_id'"; // if on main site, will undo import for all sites + $site_clause = (is_main_site()) ? "AND site > 0" : "AND site = '$blog_id'"; // if on main site, will undo import for all sites else $site_clause = ''; diff --git a/modules/presspermit-import/classes/Permissions/Import/UI/SettingsTabImport.php b/modules/presspermit-import/classes/Permissions/Import/UI/SettingsTabImport.php index 946dae1f..7ef56604 100644 --- a/modules/presspermit-import/classes/Permissions/Import/UI/SettingsTabImport.php +++ b/modules/presspermit-import/classes/Permissions/Import/UI/SettingsTabImport.php @@ -266,7 +266,7 @@ function actOptionsUI() global $wpdb, $blog_id; if (is_multisite()) - $site_clause = (1 === intval($blog_id)) ? "AND site > 0" : "AND site = '$blog_id'"; // if on main site, will undo import for all sites + $site_clause = (is_main_site()) ? "AND site > 0" : "AND site = '$blog_id'"; // if on main site, will undo import for all sites else $site_clause = ''; From ff962f2c9fe784d89beec0dbccd002293a9e5013 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Mon, 6 Jul 2020 18:14:48 -0400 Subject: [PATCH 19/40] Call is_multisite() instead of checking MULTISITE constant directly This avoids a PHP warning if the constant is not defined and provides better forward compatibility. --- .../classes/Permissions/Import/DB/RoleScoper.php | 10 +++++----- .../classes/Permissions/Import/DB/SourceConfig.php | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php b/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php index a14eac13..f98575b9 100644 --- a/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php +++ b/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php @@ -41,7 +41,7 @@ function doImport($import_type = 'rs') $this->tt_ids_by_taxonomy[$row->taxonomy][$row->term_id] = $row->term_taxonomy_id; } - if (MULTISITE && (1 === intval($blog_id))) { + if (is_multisite() && is_main_site()) { $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id"); $orig_blog_id = $blog_id; $this->sites_examined = 0; @@ -559,9 +559,9 @@ private function import_rs_item_roles() $log_eitem_ids = []; /*--------- group config and mapping setup ---------*/ - $rs_groups_table = (MULTISITE && get_site_option('scoper_mu_sitewide_groups')) ? $wpdb->base_prefix . 'groups_rs' : $wpdb->groups_rs; - $pp_groups_table = (MULTISITE && get_site_option('presspermit_netwide_groups')) ? $wpdb->base_prefix . 'pp_groups' : $wpdb->pp_groups; - $group_agent_type = (MULTISITE && get_site_option('presspermit_netwide_groups')) ? 'pp_net_group' : 'pp_group'; + $rs_groups_table = (is_multisite() && get_site_option('scoper_mu_sitewide_groups')) ? $wpdb->base_prefix . 'groups_rs' : $wpdb->groups_rs; + $pp_groups_table = (is_multisite() && get_site_option('presspermit_netwide_groups')) ? $wpdb->base_prefix . 'pp_groups' : $wpdb->pp_groups; + $group_agent_type = (is_multisite() && get_site_option('presspermit_netwide_groups')) ? 'pp_net_group' : 'pp_group'; $imported_pp_groups = $wpdb->get_results($wpdb->prepare("SELECT source_id, import_id FROM $wpdb->ppi_imported WHERE run_id > 0 AND source_tbl = %d AND import_tbl = %d", $this->getTableCode($rs_groups_table), $this->getTableCode($pp_groups_table)), OBJECT_K); $role_metagroups_rs = $wpdb->get_results("SELECT ID, group_meta_id FROM $rs_groups_table WHERE group_meta_id LIKE 'wp_role_%' OR group_meta_id = 'wp_anon'", OBJECT_K); // TODO: review role metagroup storage with netwide groups $role_metagroups_pp = $wpdb->get_results("SELECT metagroup_id, ID FROM $wpdb->pp_groups WHERE metagroup_type = 'wp_role'", OBJECT_K); @@ -886,7 +886,7 @@ private function import_rs_options() } - if (MULTISITE) { + if (is_multisite()) { $rs_netwide = (int)get_site_option('scoper_mu_sitewide_groups'); $pp_netwide = (int)get_site_option('presspermit_netwide_groups'); diff --git a/modules/presspermit-import/classes/Permissions/Import/DB/SourceConfig.php b/modules/presspermit-import/classes/Permissions/Import/DB/SourceConfig.php index dbec3a07..32eeeaa2 100644 --- a/modules/presspermit-import/classes/Permissions/Import/DB/SourceConfig.php +++ b/modules/presspermit-import/classes/Permissions/Import/DB/SourceConfig.php @@ -78,10 +78,10 @@ function hasInstallation($install_code) } function hasUnimported($install_code) { - global $wpdb, $blog_id; + global $wpdb; if (!$this->hasInstallation($install_code)) { - if (!MULTISITE || (1 != $blog_id)) { + if (!is_multisite() || !is_main_site()) { return false; } } @@ -89,14 +89,15 @@ function hasUnimported($install_code) { switch ($install_code) { case 'rs' : if (!$this->hasTable($wpdb->role_scope_rs)) { - if (!MULTISITE || !is_main_site()) + if (!is_multisite() || !is_main_site()) { return false; } + } require_once(PRESSPERMIT_IMPORT_CLASSPATH . '/DB/RoleScoper.php'); $importer = RoleScoper::instance(); - if (MULTISITE) { + if (is_multisite()) { if (is_main_site()) { return true; } @@ -128,7 +129,7 @@ function hasUnimported($install_code) { if (!$wpdb->get_results("SHOW TABLES LIKE '$wpdb->pp_roles'")) return false; - if (MULTISITE && is_main_site()) { + if (is_multisite() && is_main_site()) { return true; } From 6b764abfc5387661be8e3a5614895feb1888c54d Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Mon, 6 Jul 2020 18:18:58 -0400 Subject: [PATCH 20/40] Call get_current_blog_id() instead of accessing global $blog_id directly This eliminates a global variable reference and provides better forward compatibility. --- .../Permissions/UI/GroupsQuery.php | 4 +-- .../Permissions/Collab/UI/RoleUsageQuery.php | 7 +---- .../Permissions/Import/DB/RoleScoper.php | 28 +++++++++++++------ .../classes/Permissions/Import/Importer.php | 21 +++++++++----- .../Import/UI/SettingsTabImport.php | 17 +++++++---- 5 files changed, 47 insertions(+), 30 deletions(-) diff --git a/classes/PublishPress/Permissions/UI/GroupsQuery.php b/classes/PublishPress/Permissions/UI/GroupsQuery.php index 301bcd97..76987bc4 100644 --- a/classes/PublishPress/Permissions/UI/GroupsQuery.php +++ b/classes/PublishPress/Permissions/UI/GroupsQuery.php @@ -39,10 +39,8 @@ class GroupQuery public function __construct($query = null) { if (!empty($query)) { - global $blog_id; - $this->query_vars = wp_parse_args($query, [ - 'blog_id' => $blog_id, + 'blog_id' => get_current_blog_id(), 'include' => [], 'exclude' => [], 'search' => '', diff --git a/modules/presspermit-collaboration/classes/Permissions/Collab/UI/RoleUsageQuery.php b/modules/presspermit-collaboration/classes/Permissions/Collab/UI/RoleUsageQuery.php index ecc4b6d4..30af69a7 100644 --- a/modules/presspermit-collaboration/classes/Permissions/Collab/UI/RoleUsageQuery.php +++ b/modules/presspermit-collaboration/classes/Permissions/Collab/UI/RoleUsageQuery.php @@ -20,18 +20,14 @@ class RoleUsageQuery var $total_roles = 0; /** - * PHP5 constructor * * @param string|array $args The query variables * @return WP_Group_Query */ function __construct($query = null) { - //if ( !empty( $query ) ) { - global $blog_id; - $this->query_vars = wp_parse_args($query, [ - 'blog_id' => $blog_id, + 'blog_id' => get_current_blog_id(), 'include' => [], 'exclude' => [], 'search' => '', @@ -44,7 +40,6 @@ function __construct($query = null) $this->prepare_query(); $this->query(); - //} } function prepare_query() diff --git a/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php b/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php index f98575b9..373a0603 100644 --- a/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php +++ b/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php @@ -27,7 +27,9 @@ public function __construct() // some PHP versions do not allow subclass constru function doImport($import_type = 'rs') { - global $wpdb, $blog_id; + global $wpdb; + + $blog_id = get_current_blog_id(); parent::doImport('rs'); @@ -95,7 +97,9 @@ function doImport($import_type = 'rs') private function import_rs_groups() { - global $wpdb, $blog_id; + global $wpdb; + + $blog_id = get_current_blog_id(); // if groups were set to netwide, sites may not have their own RS groups/members tables if (!$wpdb->get_results("SHOW TABLES LIKE '$wpdb->groups_rs'") || !$wpdb->get_results("SHOW TABLES LIKE '$wpdb->user2group_rs'")) @@ -176,7 +180,9 @@ private function import_rs_groups() private function import_rs_site_roles() { - global $wpdb, $blog_id; + global $wpdb; + + $blog_id = get_current_blog_id(); /*--------- group config and mapping setup ---------*/ $rs_groups_table = (MULTISITE && get_site_option('scoper_mu_sitewide_groups')) ? $wpdb->base_prefix . 'groups_rs' : $wpdb->groups_rs; @@ -284,7 +290,9 @@ private function import_rs_site_roles() private function import_rs_restrictions() { - global $wpdb, $wp_roles, $blog_id; + global $wpdb, $wp_roles; + + $blog_id = get_current_blog_id(); $post_types = get_post_types(['public' => true, 'show_ui' => true], 'object', 'or'); $log_eitem_ids = []; // conversion of role_scope_rs.requirement_id to pp_conditions.assignment_id @@ -547,7 +555,9 @@ private function import_rs_restrictions() private function import_rs_item_roles() { - global $wpdb, $wp_roles, $blog_id; + global $wpdb, $wp_roles; + + $blog_id = get_current_blog_id(); $cap_caster = presspermit()->capCaster(); @@ -897,7 +907,9 @@ private function import_rs_options() private function import_option($opt_name, $opt_value, $source_opt_name, $imported_options) { - global $wpdb, $blog_id; + global $wpdb; + + $blog_id = get_current_blog_id(); if ($row = $wpdb->get_row("SELECT option_id, option_value FROM $wpdb->options WHERE option_name = '$source_opt_name' LIMIT 1")) { $source_id = $row->option_id; @@ -1081,8 +1093,6 @@ private function get_exception_fields($rs_obj, $extra_data = []) private function get_exception_id(&$stored_exceptions, $data, $restriction_id = 0) { - global $blog_id; - $exception_id = 0; // safeguard against invalid exception specs @@ -1110,7 +1120,7 @@ private function get_exception_id(&$stored_exceptions, $data, $restriction_id = $stored_exceptions[] = (object)$data; if ($restriction_id) { - $log_data = ['run_id' => $this->run_id, 'source_tbl' => $this->getTableCode($wpdb->role_scope_rs), 'source_id' => $restriction_id, 'import_tbl' => $this->getTableCode($wpdb->ppc_exceptions), 'import_id' => $exception_id, 'site' => $blog_id]; + $log_data = ['run_id' => $this->run_id, 'source_tbl' => $this->getTableCode($wpdb->role_scope_rs), 'source_id' => $restriction_id, 'import_tbl' => $this->getTableCode($wpdb->ppc_exceptions), 'import_id' => $exception_id, 'site' => get_current_blog_id()]; $wpdb->insert($wpdb->ppi_imported, $log_data); } } diff --git a/modules/presspermit-import/classes/Permissions/Import/Importer.php b/modules/presspermit-import/classes/Permissions/Import/Importer.php index d4933a20..b882d1f8 100644 --- a/modules/presspermit-import/classes/Permissions/Import/Importer.php +++ b/modules/presspermit-import/classes/Permissions/Import/Importer.php @@ -147,11 +147,11 @@ private function getTable($code) private function undoImport($run_id) { - global $wpdb, $blog_id; + global $wpdb; if (is_multisite() && is_main_site()) { $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id"); - $orig_blog_id = $blog_id; + $orig_blog_id = get_current_blog_id(); } else { $blog_ids = ['1']; } @@ -193,14 +193,21 @@ private function undoImport($run_id) private function undoAllImports() { - global $wpdb, $blog_id; + global $wpdb; - if (is_multisite()) - $site_clause = (is_main_site()) ? "AND site > 0" : "AND site = '$blog_id'"; // if on main site, will undo import for all sites - else + if (is_multisite()) { + $site_clause = (is_main_site()) ? "AND site > 0" : "AND site = %d"; // if on main site, will undo import for all sites + } else { $site_clause = ''; + } + + $run_ids = $wpdb->get_col( + $wpdb->prepare( + "SELECT run_id FROM $wpdb->ppi_imported WHERE run_id > 0 $site_clause", + get_current_blog_id() + ) + ); - $run_ids = $wpdb->get_col("SELECT run_id FROM $wpdb->ppi_imported WHERE run_id > 0 $site_clause"); foreach ($run_ids as $run_id) { $this->undoImport($run_id); } diff --git a/modules/presspermit-import/classes/Permissions/Import/UI/SettingsTabImport.php b/modules/presspermit-import/classes/Permissions/Import/UI/SettingsTabImport.php index 7ef56604..a04db6fe 100644 --- a/modules/presspermit-import/classes/Permissions/Import/UI/SettingsTabImport.php +++ b/modules/presspermit-import/classes/Permissions/Import/UI/SettingsTabImport.php @@ -263,14 +263,21 @@ function actOptionsUI() 0" : "AND site = '$blog_id'"; // if on main site, will undo import for all sites - else + if (is_multisite()) { + $site_clause = (is_main_site()) ? "AND site > 0" : "AND site = %d"; // if on main site, will undo import for all sites + } else { $site_clause = ''; + } - if ($wpdb->get_col("SELECT run_id FROM $wpdb->ppi_imported WHERE run_id > 0 $site_clause")) : ?> + if ($wpdb->get_col( + $wpdb->prepare( + "SELECT run_id FROM $wpdb->ppi_imported WHERE run_id > 0 $site_clause", + get_current_blog_id() + ) + ) + ) : ?> From 4bdeb6bc88d179cf8b113e8f3b7130eb1b964c62 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Mon, 6 Jul 2020 18:20:19 -0400 Subject: [PATCH 21/40] is_multisite() instead of MULTISITE constant - another instance --- .../classes/Permissions/Import/DB/RoleScoper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php b/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php index 373a0603..4939010f 100644 --- a/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php +++ b/modules/presspermit-import/classes/Permissions/Import/DB/RoleScoper.php @@ -185,9 +185,9 @@ private function import_rs_site_roles() $blog_id = get_current_blog_id(); /*--------- group config and mapping setup ---------*/ - $rs_groups_table = (MULTISITE && get_site_option('scoper_mu_sitewide_groups')) ? $wpdb->base_prefix . 'groups_rs' : $wpdb->groups_rs; - $pp_groups_table = (MULTISITE && get_site_option('presspermit_netwide_groups')) ? $wpdb->base_prefix . 'pp_groups' : $wpdb->pp_groups; - $group_agent_type = (MULTISITE && get_site_option('presspermit_netwide_groups')) ? 'pp_net_group' : 'pp_group'; + $rs_groups_table = (is_multisite() && get_site_option('scoper_mu_sitewide_groups')) ? $wpdb->base_prefix . 'groups_rs' : $wpdb->groups_rs; + $pp_groups_table = (is_multisite() && get_site_option('presspermit_netwide_groups')) ? $wpdb->base_prefix . 'pp_groups' : $wpdb->pp_groups; + $group_agent_type = (is_multisite() && get_site_option('presspermit_netwide_groups')) ? 'pp_net_group' : 'pp_group'; $imported_pp_groups = $wpdb->get_results($wpdb->prepare("SELECT source_id, import_id FROM $wpdb->ppi_imported WHERE run_id > 0 AND source_tbl = %d AND import_tbl = %d", $this->getTableCode($rs_groups_table), $this->getTableCode($pp_groups_table)), OBJECT_K); $role_metagroups_rs = $wpdb->get_results("SELECT ID, group_meta_id FROM $rs_groups_table WHERE group_meta_id LIKE 'wp_role_%' OR group_meta_id = 'wp_anon'", OBJECT_K); From 197d586c15ba177f830f28ef667f1697fa7b8ed7 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Mon, 6 Jul 2020 18:21:20 -0400 Subject: [PATCH 22/40] Call get_main_site_id() instead of hardcoding side ID 1 Some networks have a main site with ID not equal to 1. --- .../presspermit-import/classes/Permissions/Import/Importer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/presspermit-import/classes/Permissions/Import/Importer.php b/modules/presspermit-import/classes/Permissions/Import/Importer.php index b882d1f8..cdcb752b 100644 --- a/modules/presspermit-import/classes/Permissions/Import/Importer.php +++ b/modules/presspermit-import/classes/Permissions/Import/Importer.php @@ -153,7 +153,7 @@ private function undoImport($run_id) $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id"); $orig_blog_id = get_current_blog_id(); } else { - $blog_ids = ['1']; + $blog_ids = [get_main_site_id()]; } foreach ($blog_ids as $id) { From 5ee7ff1a13fbb05b8865d7a0b9ea2ca9c11331f7 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Mon, 6 Jul 2020 19:51:10 -0400 Subject: [PATCH 23/40] is_multisite() instead of MULTISITE constant - additional instance --- .../classes/Permissions/Import/DB/DatabaseSetup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/presspermit-import/classes/Permissions/Import/DB/DatabaseSetup.php b/modules/presspermit-import/classes/Permissions/Import/DB/DatabaseSetup.php index 02e69270..de030fd2 100644 --- a/modules/presspermit-import/classes/Permissions/Import/DB/DatabaseSetup.php +++ b/modules/presspermit-import/classes/Permissions/Import/DB/DatabaseSetup.php @@ -6,7 +6,7 @@ class DatabaseSetup function __construct($last_db_ver) { require_once(PRESSPERMIT_IMPORT_ABSPATH . '/db-config.php'); - if (MULTISITE) { + if (is_multisite()) { add_action('switch_blog', [$this, 'actMultisiteSupport']); } From a67bb53c9dc872fd6ef00a05ec62ec0a5b4f1b56 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Mon, 6 Jul 2020 20:14:04 -0400 Subject: [PATCH 24/40] Remove PressPermit logo from Pro promo on Settings > Install --- .../PublishPress/Permissions/UI/HintsPro.php | 11 +++++++---- common/img/pp-logo.png | Bin 17608 -> 0 bytes 2 files changed, 7 insertions(+), 4 deletions(-) delete mode 100644 common/img/pp-logo.png diff --git a/classes/PublishPress/Permissions/UI/HintsPro.php b/classes/PublishPress/Permissions/UI/HintsPro.php index 1c62b191..49bd8b18 100644 --- a/classes/PublishPress/Permissions/UI/HintsPro.php +++ b/classes/PublishPress/Permissions/UI/HintsPro.php @@ -41,6 +41,10 @@ public static function proPromo() background-color: white } +div.pp-logo { + padding-top:20px; +} + div.pp-logo, div.pp-logo img { text-align: left; @@ -51,7 +55,7 @@ public static function proPromo() list-style: none; padding-top: 10px; text-align: left; - margin-left: 50px; + margin-left: 25px; margin-top: 0; } @@ -85,9 +89,8 @@ public static function proPromo()