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