Skip to content

Instantly share code, notes, and snippets.

View danielpost's full-sized avatar

Daniel Post danielpost

View GitHub Profile
@danielpost
danielpost / index.js
Created February 26, 2024 16:13
Example ConversionWP controls
import { addFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import { createHigherOrderComponent } from '@wordpress/compose';
import { InspectorControls } from '@wordpress/block-editor';
import { PanelBody, ToggleControl, TextControl } from '@wordpress/components';
const addAttributes = ( settings, name ) => {
if ( name !== 'core/button' ) {
return settings;
}
@danielpost
danielpost / App.js
Created May 12, 2021 09:05
Super simple state management in a WordPress app
/**
* Internal dependencies
*/
import ChildComponent from './ChildComponent';
import StoreProvider from './utils/store';
const App = () => (
<StoreProvider>
<ChildComponent />
</StoreProvider>
@danielpost
danielpost / sig-custom-font.php
Created February 9, 2021 22:24
Social Image Generator - Custom font
<?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 March 25, 2021 20:12
Setting up a new local WordPress install
# 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 August 11, 2020 20:39
Eleventy: Purge CSS for each html file
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 June 15, 2020 13:00
Installing Xdebug on RunCloud server
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 September 10, 2023 23:16
WordPress SVG spinner. No more spinner.gif!
/**
* 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 13:09
WordPress API Importer
<?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 April 8, 2020 13:19
WordPress Block Editor: Enable custom block only for certain post type(s)
if (namespace.postType === 'post-type-slug') {
registerBlockType();
}
@danielpost
danielpost / contact-form-7.php
Last active May 21, 2019 09:33
WordPress Form Plugins: Get list of all available forms
<?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'));