Skip to content

Commit aa88c2b

Browse files
committed
adding README.md
1 parent b7caa2f commit aa88c2b

File tree

3 files changed

+170
-2
lines changed

3 files changed

+170
-2
lines changed

wp-react-lib/README.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
2+
# WordPress React Lib
3+
An easy way to integrate your react application with the world's **most popular** content management system. **wp-react-lib** uses the [Wordpress REST API](https://developer.wordpress.org/rest-api/) to load content into your classic React.js stack, it also allows embedding your own React.js components within pages and posts.
4+
5+
# Dependecies
6+
7+
[email protected] uses Redux and Immutable , you need to configure your store as the following example:
8+
9+
import {applyMiddleware, compose, createStore} from 'redux'
10+
import {combineReducers} from 'redux-immutable';
11+
import {Map} from 'immutable'
12+
import thunk from 'redux-thunk'
13+
import {wordpress} from "wp-react-lib";
14+
15+
const initialState = Map()
16+
const getRootReducer = () => combineReducers({
17+
wordpress,
18+
})
19+
const store = createStore(
20+
getRootReducer(), // root reducer with router state
21+
initialState,
22+
compose(applyMiddleware(thunk))
23+
)
24+
25+
26+
27+
## Preparing WordPress
28+
29+
- Run dev_services.sh to start docker container using development enviroment
30+
- Open localhost
31+
- Follow WordPress setup wizard
32+
- Go to settings/permalinks, then choose day and name
33+
- *This configuration depends of your react routes setup*
34+
- Go to appearance/themes and activate wp-react-theme
35+
- *By activating this theme WordPress will disable its front-end*
36+
- Go to plugins and activate the following plugins
37+
- WP Multilang
38+
- WP-REST-API V2 Menus
39+
- **WP React Lib Components**
40+
- Update .env file accordingly
41+
- run npm install
42+
- run npm start
43+
44+
## Loading pages
45+
46+
<Provider store={store}>
47+
<div className="App">
48+
<PageProvider slug={"home"}>
49+
<PageConsumer>
50+
<Page/>
51+
</PageConsumer>
52+
</PageProvider>
53+
</div>
54+
</Provider>
55+
56+
57+
58+
## Loading Posts
59+
60+
<Provider store={store}>
61+
<div className="App">
62+
<PostProvider slug={"my-post-slug"}>
63+
<PostConsumer>
64+
<Post/>
65+
</PostConsumer>
66+
</PostProvider>
67+
</div>
68+
</Provider>
69+
70+
## Loading List of Posts
71+
72+
const List = ({posts}) => {
73+
return
74+
<ul>
75+
{posts.map(post =>(<li> <h1 dangerouslySetInnerHTML={{__html: post.title.rendered}}/> </li>))}
76+
</ul>
77+
}
78+
79+
function ShowPosts() {
80+
return (
81+
<Provider store={store}>
82+
<div className="App">
83+
<PostProvider>
84+
<PostConsumer>
85+
<List></List>
86+
</PostConsumer>
87+
</PostProvider>
88+
</div>
89+
</Provider> );
90+
}
91+
92+
### Post Provider Properties
93+
94+
- type: You can specify your custom post type.
95+
- taxonomy: Taxonomy used for filtering posts, categories is used by default.
96+
- categories: Array of categories ids for filtering the post by the taxonomy.
97+
- before : ISO date used to filter posts by date before
98+
- perPage: Number of post loaded per page
99+
- page: Number of page that has to be returned.
100+
- fields: Specify which field will be returned in the post object.
101+
- slug: Filter by post slug.
102+
- store: Specify the immutable path where returned posts will be stored, useful when having multiple components loading different posts
103+
- locale: Specify the post language (multiLang plugin required)
104+
105+
106+
107+
## Routing
108+
109+
*Using router for loading pages*
110+
111+
<Route exact path="/:slug" render={(props)=>{
112+
return (<div className="App">
113+
<PageProvider slug={props.match.params.slug}>
114+
<PageConsumer>
115+
<Page></Page>
116+
</PageConsumer>
117+
</PageProvider>
118+
</div>
119+
}}>
120+
</Route>
121+
122+
*Using router for loading posts*
123+
124+
<Route path="/:lan/:year/:month/:day/:slug/" exact render=
125+
{props => (
126+
<PostProvider slug={props.match.params.slug} >
127+
<PostConsumer>
128+
<Post></Post>
129+
</PostConsumer>
130+
</PostProvider>
131+
)}>
132+
</Route>
133+
134+
135+
## Embedded Components
136+
137+
You can create and embed your own React components in WordPress editor, configure them, save its metadata, and render them in your React UI as part of your react application.
138+
139+
### Embedded Components Workflow
140+
141+
![](docs/flow1.png)
142+
143+
![](docs/flow2.png)
144+
### Embeddable Components
145+
To create an embeddable component you need
146+
- Create your React component
147+
- Add a route that exposes your component without your ui layout
148+
- Create a wordpress plugin that wraps your component and put it available as a wordpress block.
149+
150+
Please look at **wp-react-example-advanced** and **wp-react-blocks-plugin**
151+
152+
## Contributing
153+
154+
For details about how to send pull requests, please read [CONTRIBUTING.md](https://github.com/devgateway/wp-react-lib/blob/main/CONTRIBUTING.md).
155+
156+
## Autor
157+
158+
* **Sebastian Dimunzio** - *Architecture and code* - [sdimunzio](https://github.com/sdimunzio)
159+
160+
The list of all contributors to this project can be read at [contributors](https://github.com/devgateway/wp-react-lib/graphs/contributors).
161+
162+
## License
163+
164+
This project is under - Apache License 2.0 - for more details please check [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)
165+
166+
## Contact information
167+
168+
[For any comments or suggestions, please contact us](mailto:[email protected] "Development Gateway's Email")

wp-react-lib/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp-react-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devgateway/wp-react-lib",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"author": "Sebastian Dimunzio <[email protected]/>",
55
"private": false,
66
"main": "dist/index.js",

0 commit comments

Comments
 (0)