Skip to content

Instantly share code, notes, and snippets.

View chrisvanpatten's full-sized avatar

Chris Van Patten chrisvanpatten

View GitHub Profile
@chrisvanpatten
chrisvanpatten / README.md
Created March 7, 2012 16:27
WordPress Admin Tabs

Huh?

Believe it or not, WordPress doesn't have a fully-fleshed out common tab style for plugins or theme authors to use in metaboxes.

The style exists for categories, but it hasn't been fully adapted for the half-complete wp-tab setup. Trac ticket #17959 has a solution that not only fleshes the style but it also adds a global JavaScript file to give the wp-tab HTML some action. Until that ticket is accepted into core, this Gist adapts that code so it's available to use independently in your theme or plugin.

How?

Just enqueue the CSS and JavaScript in the admin_enqueue_scripts script hook and drop the tab HTML in a metabox. It will automatically adapt to the normal and side column widths, much like category tabs.

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 June 25, 2021 20:58
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.
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();
} );
<?php
add_filter( 'block_editor_settings', function ( $settings ) {
$settings['codeEditingEnabled'] = false;
return $settings;
} );
@chrisvanpatten
chrisvanpatten / Composer.php
Last active February 3, 2021 19:05
Automatically symlink `object-cache.php` after installing `wp-redis`.
<?php
declare(strict_types=1);
namespace Namespace\Scripts;
use Composer\Installer\PackageEvent;
class Composer
{
/**
@chrisvanpatten
chrisvanpatten / readme.md
Last active September 18, 2020 14:16
Super-simple way to grab a few Instagram images and cache them w/ WordPress

This is an easy way to integrate a basic Instagram feed into a WordPress site.

Setup

First, register with Instagram's developer program, then register a client. Set the client ID they provide you in line 4.

Second, get your Instagram user ID by running this in your terminal:

curl -X GET https://api.instagram.com/v1/users/search\?q\=USERNAME\&client_id\=CLIENT_ID
<?php
/**
* vpm_default_hidden_meta_boxes
*/
function vpm_default_hidden_meta_boxes( $hidden, $screen ) {
// Grab the current post type
$post_type = $screen->post_type;
// If we're on a 'post'...
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model wp_commentmeta {
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>
@chrisvanpatten
chrisvanpatten / order_has_trial.php
Created November 18, 2015 15:00
Function to check if a WooCommerce order contains a free trial (via the Subscriptions extension)
<?php
/**
* Loop through an order's items and see if there's a free trial set
*
* @param WC_Order $order
* @return bool|WP_Error
*/
function custom_order_has_trial( $order ) {
if ( ! $order instanceof WC_Order )