Skip to content

Instantly share code, notes, and snippets.

View oddevan's full-sized avatar

Evan Hildreth oddevan

View GitHub Profile
@oddevan
oddevan / New Event Structure.mermaid
Created September 12, 2023 02:12
New Event Structure
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<?php
namespace EPH\DAEmbed;
function register_providers() {
$callback = __NAMESPACE__ . '\handle_deviantart';
wp_embed_register_handler( 'deviantart-main', '#https://www.deviantart.com/*+#', $callback, 10 );
// Include other handlers as needed
}
@oddevan
oddevan / centos-initial-lamp.sh
Last active September 30, 2021 08:00
Shell script to set up CentOS 7 server with LAMP. Must be run as root interactively.
#!/usr/bin/env bash
# This is designed to get a CentOS 7 system up and running
# from absolutely nothing. It will install the LAMP stack
# as well as RVM and Phusion Passenger
# Run this as root
yum update
@oddevan
oddevan / challenge.md
Last active May 18, 2021 00:59 — forked from devinsays/challenge.md
WooCommerce MySQL Challenge

1. Get the order ids for all orders that have a shipping state of "New Jersey".

SELECT orders.ID
FROM `wp_posts` orders
  INNER JOIN `wp_postmeta` meta ON meta.post_id = orders.ID
WHERE
  orders.post_type = 'shop_order' AND
  meta.meta_key = '_shipping_state' AND
  meta.meta_value = 'NJ';
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'oddevan/v1', '/devArtProxy/', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\proxy_deviantart_oembed',
'permission_callback' => __NAMESPACE__ . '\proxy_deviantart_oembed_security',
) );
} );
<?php
function proxy_deviantart_oembed_security() {
// Should only be used by logged-in users capable of using the editor.
return current_user_can( 'edit_posts' );
}
<?php
function proxy_deviantart_oembed( $data ) {
$url = $data->get_param( 'url' );
if ( ! is_valid_url( $url ) ) {
return new WP_Error(
'error',
'Error: not a DeviantArt URL',
[ 'input' => $data ],
);
}
async function fetchAndSetResponse(url, setAttributes) {
const oEmbedUrl = `oddevan/v1/devArtProxy?url=${encodeURIComponent(url)}`;
try {
const response = await apiFetch({ path: oEmbedUrl });
setAttributes({ embedData: response });
} catch(e) {
console.log('Error in DA block', { url: oEmbedUrl, error: e });
setAttributes({ embedData: {} });
}