Skip to content

Instantly share code, notes, and snippets.

View vanaf1979's full-sized avatar

VA79 vanaf1979

View GitHub Profile
import React, { useState, useEffect } from "react";
import Axios from "axios";
import WpApiContent from "./WpApiContent.js";
export default function App() {
// ...
return (
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", "")} />)
import React, { useState, useEffect } from "react";
import Axios from "axios";
import parse from "html-react-parser";
export default function App() {
// ...
return (
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 => {
<?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/
<?php
$response = do_remote_post('https://jsonplaceholder.typicode.com/posts/', [
'userId' => 1,
'title' => 'foo',
'body' => 'bar'
]);
var_dump($response);
<?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/
<?php return json_decode(wp_remote_retrieve_body($response), true) ?: []; ?>
<?php
$posts = do_remote_get('https://jsonplaceholder.typicode.com/posts/');
foreach ($posts as $post) {
echo "<h2>{$post->title}</h2>";
}
<?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/