Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* ... */
}
);
// Namespaces can be saved out to variables:
const myplugin = site.namespace("myplugin/v1");
myplugin
.authors()
.id(7)
.then((author: any) => {
/* ... */
});
});
// Authenticating with Auto-Discovery
const apiPromise2 = WPAPI.discover("http://my-site.com").then(site => {
return site.auth({
username: "admin",
password: "always use secure passwords"
});
});
apiPromise2.then(site => {
// site is now configured to use authentication
});
// You must authenticate to be able to POST (create) a post
const wp2 = new WPAPI({
endpoint: "http://your-site.com/wp-json",
// This assumes you are using basic auth, as described further below
username: "someusername",
password: "password"
}
// do something with the returned posts
});
// Promises
wp
.posts()
.then((data: any) => {
// do something with the returned posts
})
.catch((err: Error) => {
// handle error
});
// Auto-discover
const apiPromise = WPAPI.discover("http://my-site.com");
apiPromise.then(site => {
// If default routes were detected, they are now available
site.posts().then((posts: any[]) => {}); // etc
// If custom routes were detected, they can be accessed via .namespace()
// Custom routes have different methods to generate requests, so .authors()
// does not necessarily exist. You have use force type or 'as
// Request'
(site.namespace("myplugin/v1").authors() as WPAPI.WPRequest).then(
(authors: any[]) => {
/* ... */
}
);
// Namespaces can be saved out to variables:
const myplugin = site.namespace("myplugin/v1");
Vue.use(Vuex);
// Mixins
Vue.mixin({
methods: mixins,
});
// Lodash
window._ = require('lodash');
/**
* WP API
* https://github.com/WP-API/node-wpapi
*/
window.wp = new WPAPI({ endpoint: config.root });
window.apiPromise = WPAPI.discover(config.base_url);
/**
* Standard UI components
*/
Vue.component('menu-location', require('@/components/partials/menu-location'));
Vue.component('gallery', require('@/components/partials/gallery'));
Vue.component('lightbox', require('@/components/partials/lightbox'));
Vue.component('theme-header', require('@/components/partials/theme-header'));
// Running in dev mode, load routes from API
if (process.env.NODE_ENV !== 'production') {
WPConfig.getConfig(data => {
window.config = data;
EventBus.$emit('config', window.config);
router.addRoutes(setComponentsToRoutes(window.config.routes));
});