features
2 years ago
roles
3 years ago
admin-load.php
2 years ago
admin.php
3 years ago
backup-handler.php
3 years ago
backup.php
3 years ago
cap-helper.php
4 years ago
dashboard.php
3 years ago
filters-admin.php
4 years ago
filters-woocommerce.php
4 years ago
filters-wp_rest_workarounds.php
4 years ago
filters.php
4 years ago
functions-admin.php
2 years ago
functions.php
2 years ago
handler.php
4 years ago
inflect-cme.php
4 years ago
manager.php
2 years ago
network.php
4 years ago
pp-handler.php
4 years ago
pp-ui.php
3 years ago
publishpress-roles.php
4 years ago
settings-handler.php
3 years ago
settings-ui.php
3 years ago
settings.php
3 years ago
test-user-ui.php
3 years ago
test-user.php
3 years ago
pp-handler.php
103 lines
| 1 | <?php |
| 2 | /* |
| 3 | * PublishPress Capabilities [Free] |
| 4 | * |
| 5 | * Process updates to Type-Specific Types / Taxonomies, Detailed Taxonomies |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | function _cme_update_pp_usage() { |
| 10 | static $updated; |
| 11 | if ( ! empty($updated) ) { return true; } |
| 12 | |
| 13 | check_admin_referer('capsman-general-manager'); |
| 14 | |
| 15 | if (!current_user_can( 'manage_capabilities' )) { |
| 16 | return false; |
| 17 | } |
| 18 | |
| 19 | if ( ! empty( $_REQUEST['update_filtered_types']) || ! empty( $_REQUEST['update_filtered_taxonomies']) || ! empty($_REQUEST['update_detailed_taxonomies']) || ! empty( $_REQUEST['SaveRole']) ) { |
| 20 | // update Press Permit "Filtered Post Types". This determines whether type-specific capability definitions are forced |
| 21 | $options = array( 'enabled_post_types', 'enabled_taxonomies', 'detailed_taxonomies' ); |
| 22 | |
| 23 | $posted = $_POST; |
| 24 | |
| 25 | $pp_prefix = (defined('PPC_VERSION') && !defined('PRESSPERMIT_VERSION')) ? 'pp' : 'presspermit'; |
| 26 | |
| 27 | foreach( $options as $option_basename ) { |
| 28 | if ( ! isset( $posted["{$option_basename}-options"] ) ) |
| 29 | continue; |
| 30 | |
| 31 | $unselected = array(); |
| 32 | $value = array(); |
| 33 | |
| 34 | foreach( $posted["{$option_basename}-options"] as $key ) { |
| 35 | if ( ( 'enabled_taxonomies' == $option_basename ) && ! empty( $posted["detailed_taxonomies-{$key}"] ) && ! empty( $posted['update_detailed_taxonomies']) ) { |
| 36 | // if Detailed is selected, also select Type-Specific |
| 37 | $posted["enabled_taxonomies-{$key}"] = true; |
| 38 | $value[$key] = true; |
| 39 | } elseif ( ( 'detailed_taxonomies' == $option_basename ) && empty( $posted["enabled_taxonomies-{$key}"] ) && ! empty( $posted['update_filtered_taxonomies']) ) { |
| 40 | // if Enabled is deselected, also deselect Type-Specific |
| 41 | $unselected[$key] = true; |
| 42 | } elseif ( empty( $posted["{$option_basename}-$key"] ) ) { |
| 43 | $unselected[$key] = true; |
| 44 | } else { |
| 45 | $value[$key] = true; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | $option_name = ( 'detailed_taxonomies' == $option_basename ) ? 'cme_' . $option_basename : $pp_prefix . '_' . $option_basename; |
| 50 | |
| 51 | if ( $current = get_option( $option_name ) ) { |
| 52 | if ( $current = array_diff_key( $current, $unselected ) ) |
| 53 | $value = array_merge( $current, $value ); // retain setting for any types which were previously enabled for filtering but are currently not registered |
| 54 | } |
| 55 | |
| 56 | $value = array_map('sanitize_key', $value); |
| 57 | |
| 58 | update_option( $option_name, $value ); |
| 59 | |
| 60 | if (in_array($option_name, ['presspermit_enabled_post_types', 'pp_enabled_post_types'])) { |
| 61 | // ensure smooth transition if Press Permit Core is deactivated |
| 62 | update_option( 'cme_enabled_post_types', $value ); |
| 63 | } |
| 64 | |
| 65 | if (defined('PRESSPERMIT_ACTIVE') && in_array($option_basename, ['enabled_post_types', 'enabled_taxonomies'])) { |
| 66 | pp_capabilities_update_permissions_option($option_basename, $value); |
| 67 | } |
| 68 | |
| 69 | $updated = true; |
| 70 | } |
| 71 | |
| 72 | if ( ! empty( $_REQUEST['update_filtered_types']) ) { |
| 73 | update_option( $pp_prefix . '_define_create_posts_cap', ! empty($_REQUEST['pp_define_create_posts_cap']) ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if ( defined( 'PRESSPERMIT_ACTIVE' ) ) { |
| 78 | if ( ! empty( $_REQUEST['SaveRole']) ) { |
| 79 | if ( ! empty( $_REQUEST['role'] ) ) { |
| 80 | $pp_only = (array) pp_capabilities_get_permissions_option( 'supplemental_role_defs' ); |
| 81 | |
| 82 | $role = sanitize_key($_REQUEST['role']); |
| 83 | |
| 84 | if (empty($_REQUEST['pp_only_role'])) { |
| 85 | $pp_only = array_diff($pp_only, [$role]); |
| 86 | } else { |
| 87 | $pp_only[]= $role; |
| 88 | } |
| 89 | |
| 90 | pp_capabilities_update_permissions_option('supplemental_role_defs', array_unique($pp_only)); |
| 91 | |
| 92 | _cme_pp_default_pattern_role($role); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if ( $updated ) { |
| 97 | pp_refresh_options(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return $updated; |
| 102 | } |
| 103 |