npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eos_wordpress_api

v1.0.40

Published

A simple Wordpress REST API wrapper in javascript

Downloads

8

Readme

wordpress_api

A simple Wordpress REST API wraparound library for Javascript

Index

Usage

Installation:

npm install eos_wordpress_api

Initialising:

Change 'path_to_api' to the full URL of your wordpress rest route e.g. https://www.example.com/wp-json/

//import the WordpressApi library
import WordpressApi from 'eos_wordpress_api'

//for convenience you can make it available globally
window.WordpressApi = WordpressApi;
//where you want to use it
//Do not use this class globally 
const myapi = new WordpressApi('path_to_api');

Endpoints:

Endpoints are wrappers around axios calls and return a Promise with the axios returned response.

Custom Endpoints:

Need to be added to your Wordpress functions.php file see Wordpress API documentation on custom endpoints

frontPage()

Gets the page listed as the home or front page on the Wordpress control panel

myapi.frontPage()
.then(({data}) => {
    const myfrontpage = data;
})

headerImage()

Returns the image designated as the site header image

myapi.headerImage()

menu(slug)

Returns the menu identified by the slug (not ID) e.g. 'top-menu'

myapi.menu('top-menu')

sidebars()

Returns all the sidebars as an array of sidebars, this includes in each sidebar the html of any widget in the sidebar

myapi.sidebars()
.then(({data}) => {
    const sidebars = data;
    sidebars.forEach(sidebar => {
        const widgets = sidebar.widgets;
        //do something with the widgets
    })
})

siteLogo()

Returns the image url designated as the Site Logo, can be used in img src

Built In Endpoints:

These are the builtin endpoints in the Wordpress REST Api and do not require any configuration in Wordpress and can be used on any Wordpress site

mediaItem(id)

Returns the image url of media item identified by id

const featuredImage = mypost.featured_media;
myapi.mediaItem(featuredImage)
.then(({data}) => {
    const imgURL = data;
})

page(id)

Returns a specific page identified by id

pages()

Returns a collection of pages (all public pages unless filtered)

post(id)

Returns a specific post identified by id

posts()

Returns a collection of pages (all public pages unless filtered)

search(searchString)

Searchs the site for the searchString and returns any posts or pages matching the criteria. This is a wrapper around the Wordpress API search endpoint and therefore only returns a list of items with the following fields: ID, Title, URL, Type, Subtype. See Wordpress API documentation for further details. It does not return full posts or pages.

settings()

For Future use, currently this function does not work as it needs Authentication

Utility functions:

sort_menu(menu)

Takes the result of a call to menu() and sorts the results and creates a hierarchy according to parent and child menu items. Works to one sub level only

recentPosts(limit)

Returns a number of the most recent posts. The number returned is limited to limit, otherwise this is similar to posts()

Filter Search Functions:

All the following functions must be used with either posts() or pages(), they do not return results by themselves. Functions can be chained in any order but the post of page functions must be last. e.g.

tags([1,3]).fields(['title', 'content']).posts()

searchInPosts(searchString)

Unlike the search function above this is a filter function which can be chained with other filter functions and used before posts() or pages() to filter the results

myapi.searchInPosts('something to search for').posts()
.then(({data}) => {
    const my_search_for_posts = data;
})

tags(['array of tag IDs'])

A filter function used with posts() or pages() to limit results to the tags supplied, NB this function and Wordpress requires tag IDs and not the name of the tag e.g. tags(['popularTag']) will not work instead use tags(['1,2,3'])

categories(['array of category IDs'])

Similar to tags this function tages an array of numerical category IDs

fields(['array of fields to return'])

Limits the returns results to the fields supplied

orderby(field, order='desc')

Orders the returned results by the field supplied, the default order is decending, change to asc for ascending. NB if you use this with the fields function make sure you include the orderby field in the array of fields to return

limit(number)

Limits the number or rows to return to 'number'

sticky()

Filters the returned results to posts designated as sticky, NB this has not effect when returning pages

exclude_categorys()

Excludes from the results any posts or pages with a category of 'hidden'. This is not a Wordpress property or built in category but a category you need to create.