Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Van Patten chrisvanpatten

View GitHub Profile
View akamai-errors.md

1.xx - ERR_READ_TIMEOUT (Generally the HTTP request/response timed out when Akamai tried fetching content from origin. Default read timeout is 120s)

3.xx - ERR_READ_ERROR (Generally the TCP connection from Akamai to origin was successful but the origin did not send any (valid) HTTP response headers back)

4.xx - ERR_WRITE_ERROR (Usually happens when connection is closed by origin before Akamai could send the complete request)

6.xx - ERR_CONNECT_FAIL (When Akamai is trying to connect to origin, the origin or a firewall is actively refusing the connection - e.g. it sent a TCP RST packet)

9.xx - ERR_INVALID_URL (The Akamai Edge server does not have a configuration file associated for the host/URL visited)

@chrisvanpatten
chrisvanpatten / useMetaSchema.js
Created Jun 25, 2021
React hook to retrieve the schema data for a set of meta keys in a WordPress post API request. Ideal for integrating libraries like React JSON Schema Form into a Gutenberg experience.
View useMetaSchema.js
import apiFetch from '@wordpress/api-fetch';
import { useSelect } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import { getPath } from '@wordpress/url';
import { pick } from 'lodash';
function useMetaSchema( metaKeys ) {
const { _links } = useSelect( ( select ) => {
return select( 'core/editor' ).getCurrentPost();
} );
View disable-gutenberg-code-editor.php
<?php
add_filter( 'block_editor_settings', function ( $settings ) {
$settings['codeEditingEnabled'] = false;
return $settings;
} );
@chrisvanpatten
chrisvanpatten / Composer.php
Last active Feb 3, 2021
Automatically symlink `object-cache.php` after installing `wp-redis`.
View Composer.php
<?php
declare(strict_types=1);
namespace Namespace\Scripts;
use Composer\Installer\PackageEvent;
class Composer
{
/**
View wp.prisma.schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model wp_commentmeta {
View panel.js
import { PluginPrePublishPanel } from '@wordpress/edit-post';
import { registerPlugin } from '@wordpress/plugins';
import Required from './required';
const Test = () => {
<PluginPrePublishPanel>
<Required.Fill>
{ ( fills ) => fills.length > 0 ? fills : null ) }
</Required.Fill>
View gist:7aa9fb17501bc154b71f8aa6ce15d089
{"skywordId":281474979915458,"type":"gallery","title":"Brendan Test 9\/17","author":"Author Byline Field","trackingTag":"true","publishAsDraft":false,"fields":[{"name":"seo_title","value":"Testing Revised Gallery - Feb 25th - Title Field","type":"META"},{"name":"toutImage","value":"84982","type":"IMAGE"},{"name":"toutImageCropOrientation","value":"Horizontal","type":"TAXONOMY"},{"name":"toutImageTitle","value":"Tout Image Title Field","type":"TEXT"},{"name":"toutImageCaption","value":"Tout Caption Field","type":"TEXT"},{"name":"toutImageAlt","value":"Tout Alternative Text Field","type":"TEXT"},{"name":"toutImageCredit","value":"Tout Credit Field","type":"TEXT"},{"name":"toutImageFocalPoint","value":"Tout Focal Point Field","type":"TEXT"},{"name":"toutImageRights","value":"restricted","type":"TAXONOMY"},{"name":"toutImageUsage","value":"Tout Image Rights Usage Field","type":"TEXT"},{"name":"socialTitle","value":"Social Title Field","type":"TEXT"},{"name":"socialDescription","value":"Social Description Field","
View 47684.php
<?php
// Filter search endpoint responses.
add_filter( 'rest_post_dispatch', 'wp_47684_filter_response', 10, 3 );
/**
* Resolves the behavior reported in WP Core Trac 47684.
*
* @see https://core.trac.wordpress.org/ticket/47684
*
View redirects.sh
#!/bin/bash
# Usage:
#
# ./redirects.sh dev marthastewart < sample.csv
while IFS=, read -r from to
do
wpcli @$1 onecms-srm add $from $to 301 --url=$2.$1.onecms.io
done
View gist:da7e3c72e2a008ed8a1a4ddc2f0a8c4a
/**
* Save term meta data.
*
* @param int $cat_id Category ID.
* @return void
*/
public static function create_category_page_data( $cat_id ) {
// Setup the values for the category page.
$author_id = get_current_user_id();
$post_type = 'category-page';