This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from "react"; | |
import Axios from "axios"; | |
import WpApiContent from "./WpApiContent.js"; | |
export default function App() { | |
// ... | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import parse from "html-react-parser"; | |
import Gist from "super-react-gist"; | |
export default function WpApiContent(props) { | |
return parse(props.content, { | |
replace: (domNode) => { | |
if(domNode.name === "script" && domNode.attribs.src.indexOf("/gist.github.com/") ) { | |
return (<Gist url={domNode.attribs.src.replace(".js", "")} />) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from "react"; | |
import Axios from "axios"; | |
import parse from "html-react-parser"; | |
export default function App() { | |
// ... | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from "react"; | |
import Axios from "axios"; | |
export default function App() { | |
const [post, setPost] = useState(null); | |
useEffect(() => { | |
Axios.get("https://since1979.dev/wp-json/wp/v2/posts/1627").then( | |
response => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* template_include_callback. | |
* | |
* Maybe redirect to a different template file | |
* | |
* @see https://since1979.dev/snippet-006-conditionally-loading-a-custom-template/ | |
* | |
* @uses is_page https://developer.wordpress.org/reference/functions/is_page/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$response = do_remote_post('https://jsonplaceholder.typicode.com/posts/', [ | |
'userId' => 1, | |
'title' => 'foo', | |
'body' => 'bar' | |
]); | |
var_dump($response); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* do_remote_post. | |
* | |
* Make a post request to a remote api, | |
* | |
* @see https://since1979.dev/snippet-007-get-and-post-to-remote-api-with-php/ | |
* | |
* @uses wp_remote_post() https://developer.wordpress.org/reference/functions/wp_remote_post/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php return json_decode(wp_remote_retrieve_body($response), true) ?: []; ?> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$posts = do_remote_get('https://jsonplaceholder.typicode.com/posts/'); | |
foreach ($posts as $post) { | |
echo "<h2>{$post->title}</h2>"; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* do_remote_get. | |
* | |
* Make a get request to a remote api, | |
* | |
* @see https://since1979.dev/snippet-007-get-and-post-to-remote-api-with-php/ | |
* | |
* @uses wp_remote_get() https://developer.wordpress.org/reference/functions/wp_remote_get/ |
NewerOlder