Skip to content

Instantly share code, notes, and snippets.

Avatar

Evan Hildreth oddevan

View GitHub Profile
@oddevan
oddevan / challenge.md
Last active May 18, 2021 — forked from devinsays/challenge.md
WooCommerce MySQL Challenge
View challenge.md

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';
View deviant-art-proxy-javascript.js
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: {} });
}
View deviant-art-proxy-function.php
<?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 ],
);
}
View deviant-art-proxy-security.php
<?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' );
}
View deviant-art-embed-rest-api-init.php
<?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',
) );
} );
View Destiny.html
<!-- wp:paragraph -->
<p>The Fallen will continue to claw at the walls of our City, unless we strike them down. Beneath the ruins of the Cosmodrome, in the shadow of an old colony ship, we've located the House of Devils' Lair and the High Servitor feeding them their strength. We must destroy this machine god, and send their souls screaming back to hell.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Something dark stirs in the depths of the Hellmouth. We can feel it. A Hive abomination bred for unthinkable evil. We must pierce the veil of their Summoning Pits and destroy this creature before the Hive unleash it upon us all.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Far below the Ishtar Academy, the Vex have set something in motion, a world-eating machine transforming Venus into another link in their intergalactic chain. This Nexus must be stopped and the Mind that controls it, destroyed.</p>
View Spiderman.md

Alright, let’s do this one last time. My name is Peter Parker. I was bitten by a radioactive spider and for ten years I’ve been the one and only Spider-Man. I’m pretty sure you know the rest. I saved a bunch of people, fell in love, saved the city, and then I saved the city again and again and again... And uh... I did this. We don’t really talk about this.

Look, I’m a comic book, I’m a cereal, did a Christmas album. I have an excellent theme song. And a so-so popsicle. I mean, I’ve looked worse. But after everything, I still love being Spider-Man. I mean, who wouldn’t? So no matter how many hits I take, I always find a way to come back. Because the only thing standing between this city and oblivion is me. There’s only one Spider-Man. And you’re looking at him.

View CardImport.php
<?php
function import_cards() {
\WP_CLI::log( 'Querying pokemontcg.io...' );
$cards = Pokemon::Card( [ 'verify' => false ] )->where( [ 'setCode' => 'sm9', 'pageSize' => 1000 ] )->all();
foreach ( $cards as $card_obj ) {
$card = $card_obj->toArray();
$hash_text = $card['name'] . implode( ' ', $card['text'] );
View CardHash.php
<?php
namespace oddEvan\TrainerDB\Content\Taxonomy;
use WebDevStudios\OopsWP\Structure\Content\Taxonomy;
class CardHash extends Taxonomy {
protected $slug = 'card_hash';
protected $object_types = [ 'card' ];
protected function get_labels() : array {
View Card.php
<?php
namespace oddEvan\TrainerDB\Content\PostType;
use WebDevStudios\OopsWP\Structure\Content\PostType;
class Card extends PostType {
protected $slug = 'card';
protected function get_labels() : array {
return [