PHP code example of cloakwp / media-categories

1. Go to this page and download the library: Download cloakwp/media-categories library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cloakwp / media-categories example snippets



// wp-content/mu-plugins/media-categories-loader.php

use CloakWP\MediaCategories\MediaCategories;

MediaCategories::make()
  ->manageRoles(['administrator', 'editor'])
  ->assignRoles(['administrator', 'editor', 'author'])
  ->register();

MediaCategories::make()
  ->slug('category_media')              // default
  ->restBase('media-categories')
  ->labels('Media Category', 'Media Categories')
  ->hierarchical()                      // default true
  ->rewrite('media-category')           // or ->rewrite(false)
  ->showInRest()                        // default true
  ->manageRoles(['administrator'])      // create / edit / delete terms
  ->assignRoles(['administrator', 'editor', 'author']) // attach terms to media
  ->defaultTerm(null)                   // optional auto-assign slug on upload
  ->register();

add_filter('cloakwp/media-categories/config', function ($config) {
  return $config->withManageRoles(['administrator', 'editor']);
});