How to create and add your library

Qoob is based on the libraries which consist of the blocks and media files (images, videos). We can add, delete the libraries using UI interface in the WP version of Qoob or add them in the code.

A simple library consists of the file lib.json and contains at least one block. We describe the library in the lib.json file, give it a name, identify groups, add blocks and js, css files.

The simple example of lib.json file

{
    "name": "qoobLib",
    "groups": [{
        "id": "main",
        "label": "Main Blocks",
        "position": 0
    }],
    "blocks": [{
        "name": "mainblock",
        "url": "mainblock/"
    }],
    "res": [
     {
         "name": "example_name_css",
         "type": "css",
         "src": "%theme_url%/blocks/name_block/assets/css/style.css"
     },
     {
       "name": "example_name_js",
       "type": "js",
       "src": "%theme_url%/blocks/name_block/assets/js/script.js"
     }
   ]
}

Adding the library via add_filter()

In order to integrate the library from a WP theme into the Qoob you need to add the path to the lib.json file into the array using the filter  qoob_libs.

/* Init qoob libs */
add_filter( 'qoob_libs', 'qoob_add_theme_lib', 10, 2 );

if ( ! function_exists( 'qoob_add_theme_lib' ) ) {
  /**
   * Adding lib in qoob libs
   *
   * @param array $qoob_libs Array with url to qoob lib.
   */
  function qoob_add_theme_lib( $qoob_libs ) {
    array_push( $qoob_libs, get_template_directory() . '/blocks/lib.json' );
    return $qoob_libs;
  }
}

Adding the library via UI interface

In the admin WP panel choose the menu Qoob – Manage libraries

You can find the list of the libraries, that have already been added, on the page. You can’t delete the library of the plugin and the libraries added from other themes.

There are two ways how to add a new library: 1) you can type in url into the field or 2) upload the file lib.json through the file uploading form. After adding the library it will appear in the list and you’ll be able to delete the libraries that had been added before.