No description, website, or topics provided.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
build/tasks
dist
src
vendor
.editorconfig
.gitignore
.jscsrc
.jshintrc
Gruntfile.js
README.md
composer.json
license.txt
package.json

README.md

WP-JS

DO NOT USE THIS YET, IT IS UNDER HEAVY DEVELOPMENT.

This library brings essential parts of WordPress and a connection to its REST API to JavaScript. It makes building web apps and JS-based themes a lot easier to build. You can even build native mobile apps powered by the library if you use a framework like Ionic.

Why?

JavaScript is the future of the web, and now that WordPress has a REST API built in, we can start to leverage this powerful tool to create modern websites using established JavaScript frameworks, but at the same time powered by the solid core of WordPress for its admin interface and content management capabilities.

However, a lot of native WordPress functionality that we would also need for a JS-based app only exists in PHP, so we would need to rebuild many components every time we build a WordPress-powered web or mobile app. That's where WP-JS comes into place. This library offers an interface to all the important WordPress REST API endpoints, plus it includes useful components that we often need when working with WordPress data.

Getting Started

Before you start to use the library in any project, you need to install the WP-JS plugin to the instance of WordPress that you're going to connect your website to.

The following global JS variables should (or can) be set before including WP-JS:

  • WPJS_REST_URL (required)
  • WPJS_DISABLE_CACHE (optional)
  • WPJS_DEBUG (optional)

To start WP-JS, simply run wpjs.load() after including it. You can add a callback function to execute after the loading process by running wpjs.ready( callback ).

JavaScript Components

REST client

A client that offers access to the WordPress REST API.

Options

This allows retrieving WordPress options.

Plugin API

A JavaScript implementation of the WordPress Plugin API.

In addition to the typical action- and filter-related functions, actions and filters can also be run to have a specific callback function being run afterwards. Due to the asynchronous nature of JavaScript, this will probably be applied in more cases than the regular variants.

Cache

A JavaScript implementation of the WordPress cache which uses the HTML5 local storage. The WP-JS plugin will set transients which will (mostly) ensure that the cache is properly empied whenever changes have occurred.

Formatting

A group of formatting functions based on WordPress equivalents. For example, date and time are automatically formatted based on the site's settings.

Third-Party Libraries

  • RequireJS
  • Moment

Build Process

  • npm install
  • grunt npmcopy
  • grunt