Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wordpress-query-media

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wordpress-query-media

A component for fetching WordPress media data from the REST API.

  • 2.0.0-beta.1
  • next
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

WordPress Query Media

This package contains a query component, along with redux state & selectors for media pulled from a WordPress site. This uses the node-wpapi package to get your site's data via Query Components (inspired by calypso). The Query Components call the API, which via actions set your site's data into the state.

To use any of these helpers, you'll need to set your Site URL in a global (SiteSettings), so that the API knows what site to connect to. For example:

window.SiteSettings = {
	endpoint: 'url.com/path-to-wordpress',
};

Query Media

Query Media is a React component used in managing the fetching of media items.

Usage

Render the component, passing in the attachmentId. It does not accept any children, nor does it render any elements to the page. You can use it adjacent to other sibling components which make use of the fetched data made available through the global application state.

import React from 'react';
import QueryMedia from 'wordpress-query-media';
import MyMediaItem from './media-item';

export default function MyMediaComponent( { media } ) {
	return (
		<div>
			<QueryMedia attachmentId={ 32 } />
			<MyMediaItem media={ media } />
		</div>
	);
}

Props

attachmentId

TypeNumber
RequiredYes
Defaultnull

The attachment ID of the requested media item

Media Selectors

You can import these into your project by grabbing them from the selectors file:

import { getMedia, isRequestingMedia } from 'wordpress-query-media/lib/selectors';
getMedia( state, globalId )
isRequestingMedia( state, path )

Media State

If you need access to the reducers, action types, or action creators, you can import these from the state file. For example, to use this in your global redux state, mix it into your reducer tree like this:

import media from 'wordpress-query-media/lib/state';

let reducer = combineReducers( { ...otherReducers, media } );

If you need to call an action (the query component should take care of this most of the time), you can pull the action out specifically:

import { requestMedia } from 'wordpress-query-media/lib/state';

View the file itself to see what else is available.

Keywords

FAQs

Package last updated on 28 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc