Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Post danielpost

View GitHub Profile
@danielpost
danielpost / App.js
Created May 12, 2021
Super simple state management in a WordPress app
View App.js
/**
* Internal dependencies
*/
import ChildComponent from './ChildComponent';
import StoreProvider from './utils/store';
const App = () => (
<StoreProvider>
<ChildComponent />
</StoreProvider>
@danielpost
danielpost / sig-custom-font.php
Created Feb 9, 2021
Social Image Generator - Custom font
View sig-custom-font.php
<?php
add_filter( 'sig_template_font_file', function ( $path, $context ) {
if ( $context !== 'title' ) {
return $path;
}
return 'path/to/font.ttf';
}, 10, 2 );
@danielpost
danielpost / commands.sh
Last active Mar 25, 2021
Setting up a new local WordPress install
View commands.sh
# Replace all instances of 'theme-name' with the name of your project.
# Create a new repo for the theme
# Uses https://github.com/aaemnnosttv/wp-cli-valet-command/
cd ~/Dev/posty/
gh repo create posty-studio/theme-name --template="posty-studio/posty-starter-theme"
cd theme-name
git pull origin master
git checkout -b dev
@danielpost
danielpost / .eleventy.config.js
Created Aug 11, 2020
Eleventy: Purge CSS for each html file
View .eleventy.config.js
const { PurgeCSS } = require('purgecss');
/**
* Remove any CSS not used on the page and inline the remaining CSS in the
* <head>.
*
* @see {@link https://github.com/FullHuman/purgecss}
*/
eleventyConfig.addTransform('purge-and-inline-css', async (content, outputPath) => {
if (process.env.ELEVENTY_ENV !== 'production' || !outputPath.endsWith('.html')) {
@danielpost
danielpost / gist:a7232c18ee541017184a7d23e20ede01
Created Jun 15, 2020
Installing Xdebug on RunCloud server
View gist:a7232c18ee541017184a7d23e20ede01
apt-get install autoconf libpcre3-dev
MODULE_NAME="xdebug"
MODULE_VERSION="2.9.6"
cd ~
wget https://xdebug.org/files/xdebug-2.9.6.tgz
@danielpost
danielpost / spinner.js
Last active May 13, 2021
WordPress SVG spinner. No more spinner.gif!
View spinner.js
/**
* WordPress dependencies
*/
import { SVG, Circle } from '@wordpress/primitives';
const spinner = (
<SVG fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36">
<Circle cx="18" cy="18" r="18" fill="#a2a2a2" />
<Circle cx="18" cy="8" r="4" fill="#f1f1f1">
<animateTransform
@danielpost
danielpost / class-importer.php
Last active May 28, 2020
WordPress API Importer
View class-importer.php
<?php
/**
* This class is an example of how to reliably fetch items from an external API
* using background processing. Make sure Action Scheduler is installed before
* instantiating this class.
*
* @link https://actionscheduler.org/
*/
class Importer {
const API_URL = 'https://api.openbrewerydb.org/breweries';
@danielpost
danielpost / blocks.js
Created Apr 8, 2020
WordPress Block Editor: Enable custom block only for certain post type(s)
View blocks.js
if (namespace.postType === 'post-type-slug') {
registerBlockType();
}
@danielpost
danielpost / contact-form-7.php
Last active May 21, 2019
WordPress Form Plugins: Get list of all available forms
View contact-form-7.php
<?php
$forms = get_posts(['post_type' => 'wpcf7_contact_form', 'posts_per_page' => -1]);
if (empty($forms)) {
return [];
}
return array_combine(wp_list_pluck($forms, 'ID'), wp_list_pluck($forms, 'post_title'));
@danielpost
danielpost / footnotesHighlight.scss
Last active Jan 10, 2019
Highlight focused footnotes
View footnotesHighlight.scss
@keyframes highlight {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
.footnotes li,