admin
1 year ago
auto-insert
1 year ago
conditional-logic
1 year ago
execute
1 year ago
generator
2 years ago
lite
1 year ago
capabilities.php
2 years ago
class-wpcode-admin-bar-info.php
2 years ago
class-wpcode-auto-insert.php
1 year ago
class-wpcode-capabilities.php
3 years ago
class-wpcode-conditional-logic.php
1 year ago
class-wpcode-error.php
2 years ago
class-wpcode-file-cache.php
1 year ago
class-wpcode-file-logger.php
3 years ago
class-wpcode-generator.php
3 years ago
class-wpcode-install.php
2 years ago
class-wpcode-library-auth.php
1 year ago
class-wpcode-library.php
1 year ago
class-wpcode-settings.php
2 years ago
class-wpcode-smart-tags.php
2 years ago
class-wpcode-snippet-cache.php
2 years ago
class-wpcode-snippet-execute.php
1 year ago
class-wpcode-snippet.php
1 year ago
compat.php
2 years ago
global-output.php
2 years ago
helpers.php
1 year ago
icons.php
1 year ago
ihaf.php
3 years ago
legacy.php
3 years ago
pluggable.php
2 years ago
post-type.php
1 year ago
safe-mode.php
2 years ago
shortcode.php
2 years ago
capabilities.php
88 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Map capabilites with backwards compatibility. |
| 4 | * |
| 5 | * @package WPCode |
| 6 | */ |
| 7 | |
| 8 | // Prevent direct access. |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | add_filter( 'map_meta_cap', 'wpcode_map_meta_cap', 10, 4 ); |
| 14 | |
| 15 | /** |
| 16 | * Map capabilites with backwards compatibility. |
| 17 | * |
| 18 | * @param string[] $caps Primitive capabilities required of the user. |
| 19 | * @param string $cap Capability being checked. |
| 20 | * @param int $user_id The user ID. |
| 21 | * @param array $args Adds context to the capability check, typically |
| 22 | * starting with an object ID. |
| 23 | * |
| 24 | * @return array |
| 25 | */ |
| 26 | function wpcode_map_meta_cap( $caps, $cap, $user_id, $args ) { |
| 27 | |
| 28 | $custom_capabilities = array( |
| 29 | 'wpcode_edit_php_snippets', |
| 30 | 'wpcode_edit_html_snippets', |
| 31 | 'wpcode_manage_conversion_pixels', |
| 32 | 'wpcode_file_editor', |
| 33 | 'wpcode_manage_settings', |
| 34 | ); |
| 35 | |
| 36 | if ( in_array( $cap, $custom_capabilities, true ) ) { |
| 37 | return array( 'wpcode_edit_snippets' ); |
| 38 | } |
| 39 | |
| 40 | return $caps; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get an array of the custom capabilities that WPCode uses. |
| 45 | * |
| 46 | * @return array[] |
| 47 | */ |
| 48 | function wpcode_custom_capabilities() { |
| 49 | return array( |
| 50 | 'wpcode_edit_text_snippets' => array( |
| 51 | 'label' => __( 'Edit Text/Blocks Snippets', 'insert-headers-and-footers' ), |
| 52 | 'description' => __( 'This enables users to edit just text & blocks snippets, no HTML code is allowed.', 'insert-headers-and-footers' ), |
| 53 | ), |
| 54 | 'wpcode_edit_html_snippets' => array( |
| 55 | 'label' => __( 'Edit HTML, JavaScript & CSS Snippets', 'insert-headers-and-footers' ), |
| 56 | 'description' => __( 'This enables users to add and manage HTML, JavaScript & CSS snippets but also Text & Blocks snippets.', 'insert-headers-and-footers' ), |
| 57 | ), |
| 58 | 'wpcode_edit_php_snippets' => array( |
| 59 | 'label' => __( 'Edit PHP Snippets', 'insert-headers-and-footers' ), |
| 60 | 'description' => __( 'This enables users to add and manage PHP snippets and all the other types of snippets.', 'insert-headers-and-footers' ), |
| 61 | ), |
| 62 | 'wpcode_manage_conversion_pixels' => array( |
| 63 | 'label' => __( 'Manage Conversion Pixels Settings', 'insert-headers-and-footers' ), |
| 64 | 'description' => __( 'This enables users to manage the conversion pixels settings.', 'insert-headers-and-footers' ), |
| 65 | ), |
| 66 | 'wpcode_file_editor' => array( |
| 67 | 'label' => __( 'Use the File Editor', 'insert-headers-and-footers' ), |
| 68 | 'description' => __( 'This enables users to use the file editor.', 'insert-headers-and-footers' ), |
| 69 | ), |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Return just the keys to avoid a gettext call that causes an endless loop with TranslatePress. |
| 75 | * |
| 76 | * @return string[] |
| 77 | */ |
| 78 | function wpcode_custom_capabilities_keys() { |
| 79 | return array( |
| 80 | 'wpcode_edit_text_snippets', |
| 81 | 'wpcode_edit_html_snippets', |
| 82 | 'wpcode_edit_php_snippets', |
| 83 | 'wpcode_manage_conversion_pixels', |
| 84 | 'wpcode_file_editor', |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 |