Skip to content

Manifest features

Damien Senger edited this page Feb 21, 2016 · 6 revisions

You can find in this article all features supported by the Raccoon WordPress plugin and some manifest.json content examples.

Summary

  1. WordPress theme namespace
  2. Theme supports
  3. Raccoon theme features
  4. Navigations
  5. Post Types
  6. Post Status
  7. Sidebars
  8. Widgets

WordPress theme namespace

With the Raccoon WordPress plugin, you can define a specific namespace for your WordPress theme. This namespace will be mainly used by string translation methods like __() or _e() or _x() or _n().

To define a specific namespace, you have to update manifest.json like that:

{
  "namespace": "raccoon"
}

If empty or undefined, the plugin check if a previous THEME_NAMESPACE is already defined.

If you want to use this namespace in your theme's files, you just have to use the PHP constant THEME_NAMESPACE. If you prefer global variable usage, you can also use global $namespace;. For example :

_e('Hello World!', THEME_NAMESPACE);

// -- OR -- 

global $namespace; // in the first lines of your current file
_e('Hello World!', $namespace);

Theme supports

With the Raccoon WordPress plugin, you can easily set up all theme features with the manifest.json file.

All features described in the WordPress documentation can be registered with or without arguments. Considering the JSON format, a feature requires a least a boolean.

Here is the kind of statements that you can set up in your manifest:

{
  "theme-support": {
    "title-tag": true,
    "post-thumbnail": true,
    "automatic-feed-links": true,
    "post-formats": [
      "link",
      "quote",
      "audio",
      "video"
    ],
    "html5": [
      "caption",
      "comment-form",
      "comment-list",
      "gallery",
      "search-form"
    ]
  }
}

Raccoon theme features

The Raccoon WordPress plugin has a feature which allows you to (dis)able some Wordpress features like widgets or comments. In the manifest.json file you can easily (de-)activate these features with:

{
  "theme-features": {
    "comments": false,
    "widget": false,
    "js-detection": true,
    "cleanup": true
  }
}
  • "js-detection": true: add a vanilla-JavaScript script in wp_footer(); and add a .no-js class into body classes to test if JavaScript is enabled (if true, .no-js body class is removed by the vanilla JavaScript script).
  • "comments": false: remove the comments feature globally for this theme
  • "widgets": false: remove the widgets feature globally for this theme
  • "all-settings": true: activate a new option page in the admin panel with all options from the wp-options table in the database.
  • "cleanup": true: activate a serie of scripts to cleanup all WordPress mess
  • "svg-upload": true: enable SVG file upload in the WordPress medias library

Navigations

With the Raccoon WordPress plugin, you can easily set up navigations with the manifest file.

Each navigation must have a location and a readable description like in the WordPress documentation.

For example if you want to register two navigations (a primary navigation and a list of social networks), you have to update your manifest like:

{
  "navigations": {
    "primary": "Main navigation",
    "social": "Social links"
  }
}

Post Types

Create a custom post type

With the Raccoon WordPress plugin, you can easily set up custom post types with the manifest file.

Each custom post type must have a title and an array of arguments. All arguments described in the WordPress documentation can be used in the manifest file.

For example if you want to register the same post type as the WordPress documentation, you have to update your manifest like:

{
  "post-types": {
    "books": {
      "labels": {
        "name": "Books",
        "singular_name": "Book",
        "menu_name": "Books",
        "name_admin_bar": "Book",
        "add_new": "Add New",
        "add_new_item": "Add New Book",
        "new_item": "New Book",
        "edit_item": "Edit Book",
        "view_item": "View Book",
        "all_items": "All Books",
        "search_items": "Search Books",
        "parent_item_colon": "Parent Books:",
        "not_found": "No books found.",
        "not_found_in_trash": "No books found in Trash."
      },
      "description": "Description.",
      "public": "true",
      "publicly_queryable": "true",
      "query_var": "true",
      "rewrite": {
        "slug": "book"
      },
      "menu_icon": "dashicons-editor-paragraph",
      "supports": [
        "title",
        "editor",
        "author",
        "thumbnail",
        "excerpt",
        "custom-fields",
        "revisions",
        "post-formats"
      ]
    }
  }
}

Good to know, you can't declare in your manifest a custom post type called remove.

Post type unregistration

With the Raccoon WordPress plugin, you can alse easily unregister an existing post type with your manifest file.

Each existing post type, even post or pages, can be unregister with this functionality. For example, if you want to unregister the post post type, you have to add in your manifest:

{
  "post-types": {
    "remove": ["post"]
  }
}

Post Status

With the Raccoon WordPress plugin, you can easily set up custom post status with your manifest file. Each custom post status will be automatically added into each admin panel page inside post status selectboxes.

Each custom post status can have all arguments described for the WordPress register_post_status() method.

For example, if you want to register a new custom post status, you have to update your manifest like:

{
  "post-status": {
    "archive": {
      "label": "Archive",
      "exclude_from_search": false,
      "public": false,
      "internal": false,
      "protected": true,
      "private": false,
      "publicly_queryable": false,
      "show_in_admin_all_list": true,
      "show_in_admin_status_list": true,
      "_builtin": true,
      "label_count": [
        "Archive <span class=\"count\">(%s)</span>",
        "Archives <span class=\"count\">(%s)</span>"
      ]
    }
  }
}

Good to know, you can't declare in your manifest a custom post status called remove.

Sidebars

With the Raccoon WordPress plugin, you can easily set up sidebars with the manifest.json file.

Each sidebar must have an array of arguments. All arguments described in the WordPress documentation can be used in the manifest file.

For example if you want to register the same sidebar as the WordPress documentation, you have to update your manifest like:

{
  "sidebars": [
    {
      "name": "Sidebar name",
      "id": "unique-sidebar-id",
      "description": "Description.",
      "class": "sidebarClassName",
      "before_widget": "<li id=\"%1$s\" class=\"widget %2$s\">",
      "after_widget": "</li>",
      "before_title": "<h2 class=\"widget__title\">",
      "after_title": "</h2>"
    }
  ]
}

Widgets

With the Raccoon WordPress plugin, you can easily set up widgets with the manifest file.

Each widget must consist of a specific OOP PHP Class like described in the WordPress documentation. So, for a widget registration you just have to add the widget classname in the manifest with its complete namespace like:

{
  "widgets": [
    "Hiwelo\\Raccoon\\Theme\\WidgetExample"
  ]
}