Plugin Directory

Changeset 2237967


Ignore:
Timestamp:
02/03/2020 09:55:22 PM (6 years ago)
Author:
jtroynousky
Message:

v1.1.0: Add default administrator capabilities

Location:
json-post-type/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • json-post-type/trunk/json-post-type.php

    r2237870 r2237967  
    1919     */
    2020    const POST_TYPE = 'json';
    21 
    2221    /**
    2322     * Initialize.
     
    2524    public static function init() {
    2625        add_action( 'init', [ __CLASS__, 'register_post_type' ] );
     26        add_action( 'admin_init', [ __CLASS__, 'add_caps' ] );
    2727        add_filter( sprintf( 'rest_prepare_%s', self::POST_TYPE ), [ __CLASS__, 'prepare_post' ], 99, 3 );
    2828    }
     
    7272
    7373    /**
     74     * Add capabilties to user roles.
     75     */
     76    public static function add_caps() {
     77
     78        /**
     79         * Allow roles to be filterable.
     80         *
     81         * Default to administrator only!.
     82         *
     83         * @param array $roles The default roles to add caps to.
     84         */
     85        $roles = apply_filters( 'json_post_type_roles', [ 'administrator' ] );
     86
     87        // Define the capabilities we're using.
     88        $capabilities = [
     89            'edit_json',
     90            'edit_others_json',
     91            'publish_json',
     92            'read_private_json'
     93        ];
     94
     95        // Add capabilities to permitted roles.
     96        foreach ( $roles as $role ) {
     97            $role = get_role( $role );
     98            if ( count( array_intersect( array_keys( $role->capabilities ), $capabilities ) ) !== count( $capabilities ) ) {
     99                foreach ( $capabilities as $capability ) {
     100                    $role->add_cap( $capability );
     101                }
     102            }
     103        }
     104    }
     105
     106    /**
    74107     * Register the JSON editor meta box and add JSONEditor assets.
    75108     */
  • json-post-type/trunk/package.json

    r2237870 r2237967  
    11{
    22  "name": "json-configuration-editor",
    3   "version": "1.0.0",
     3  "version": "1.1.0",
    44  "description": "Create a custom post type for the editing and publishing of arbitrary JSON configurations",
    55  "author": "",
  • json-post-type/trunk/readme.txt

    r2237870 r2237967  
    44Requires at least: 4.6
    55Tested up to: 5.3
    6 Stable tag: 1.0.0
     6Stable tag: 1.1.0
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    1919== Upgrade Notice ==
    2020
    21 = 1.0 =
     21= 1.1.0 =
     22* Add default administrator capabilities.
     23
     24= 1.0.0 =
    2225* Initial plugin version.
Note: See TracChangeset for help on using the changeset viewer.