Skip to content

Instantly share code, notes, and snippets.

Mark Howells-Mead markhowellsmead

Block or report user

Report or block markhowellsmead

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@markhowellsmead
markhowellsmead / serverside.php
Created Oct 29, 2019
Hello Roots ServerSideRender: use LazyImage for frontend and static generation in backend
View serverside.php
<?php
if (array_key_exists('context', $_GET) && $_GET['context'] === 'edit') {
$featured_image = wp_get_attachment_image(get_post_thumbnail_id($post->ID), $size, false, ['class' => 'b-articles-latest__entryimage']);
if (!empty($featured_image)) {
$featured_image = '<figure class="b-articles-latest__entryfigure">'.$featured_image.'</figure>';
}
} else {
$featured_image = sht_theme()->Package->Lazysizes->getLazyImage(get_post_thumbnail_id($post->ID), $size, 'b-articles-latest__entryfigure', 'b-articles-latest__entryimage');
}
@markhowellsmead
markhowellsmead / getTemplatePart.php
Last active Oct 24, 2019
Alternative to WordPress' get_template_part function , which allows you to pass data to the template part. Requires PHP 7+ because of the coalescing operator. Info at https://permanenttourist.ch/2019/10/passing-data-to-wordpress-template-parts/
View getTemplatePart.php
<?php
public function getTemplatePart(string $file_path, ...$arguments)
{
$data = [];
// Array containing possible paths to the template part
$parts = (array) $file_path;
if (is_array($arguments)) {
@markhowellsmead
markhowellsmead / event_query.php
Last active Oct 22, 2019
Complex WordPress meta query by start and end date (custom meta fields)
View event_query.php
<?php
/**
* Complex WordPress meta query by start and end date (custom meta fields)
* Intended for use on the `pre_get_posts` hook.
* Caution; this makes the query very slow - several seconds - so should be
* implemented with some form of caching.
*
* mark@sayhello.ch 22.10.2019, based on code from 201 onwards
*/
@markhowellsmead
markhowellsmead / add-wordpress-settings-page.php
Created Oct 3, 2019 — forked from DavidWells/add-wordpress-settings-page.php
WordPress :: Add Settings Page with All Fields
View add-wordpress-settings-page.php
<?php
/*
Plugin Name: Homepage Settings for BigBang
Plugin URI: http://www.inboundnow.com/
Description: Adds additional functionality to the big bang theme.
Author: David Wells
Author URI: http://www.inboundnow.com
*/
// Specify Hooks/Filters
@markhowellsmead
markhowellsmead / date_comparison.php
Last active Sep 25, 2019
Convert one or two dates (date from and date to) into a sensible, legible date string
View date_comparison.php
/**
* Convert one or two dates (date from and date to) into a sensible, legible date string
* @param array $dates Array containing 'date_from' and (optionally) 'date_to'
* @return string Human-readable date text
*/
public function courseEntryDate(array $dates)
{
$dates['date_from'] = $dates['day'];
$dates['date_to'] = $dates['day_to'];
@markhowellsmead
markhowellsmead / gulpfile.babel.js
Created Sep 16, 2019
Gulp set for JavaScript only in a plugin
View gulpfile.babel.js
import gulp from 'gulp';
import livereload from 'gulp-livereload';
const config = {
name: 'Say Hello - Plugin X',
key: 'shp_plugin_x',
distDir: './dist/',
gulpDir: './gulp/',
assetsBuild: './source/',
errorLog: function(error) {
@markhowellsmead
markhowellsmead / Vendor_ImageSelector.jsx
Created Aug 26, 2019
Media selector for Say Hello components
View Vendor_ImageSelector.jsx
/**
* Media selector for Say Hello components
* mark@sayhello.ch 26.8.2019
*
* Usage: <ImageSelector
className="c-block__figure"
image={this.props.attributes.image}
image_format="full"
allowed_types={['image/jpg', 'image/jpeg', 'image/png']}
setAttributes={this.props.setAttributes}
@markhowellsmead
markhowellsmead / block.jsx
Created Aug 22, 2019
Gutenberg: Starter Block Code
View block.jsx
const { RichText } = wp.blockEditor;
const { _x } = wp.i18n;
wp.blocks.registerBlockType('sht/starter-block', {
title: _x('Starter Block', 'Block title', 'sha'),
icon: 'heading',
category: 'sht/theme',
attributes: {
title: {
type: 'string',
@markhowellsmead
markhowellsmead / block.jsx
Last active Oct 2, 2019
Gutenberg: MediaUpload Component (add to InspectorControls)
View block.jsx
const {MediaUpload, MediaUploadCheck} = wp.blockEditor;
<MediaUploadCheck>
<MediaUpload
onSelect={clienticon => {
getLazySrcs(clienticon.id, 'smallsquare').then(clienticon => this.props.setAttributes({clienticon}));
}}
allowedTypes={['image/jpg', 'image/jpeg', 'image/png']}
@markhowellsmead
markhowellsmead / gutenberg-content.txt
Last active Aug 14, 2019
Dummy content for Gutenberg Theme development (from permanenttourist.ch)
View gutenberg-content.txt
<!-- wp:cover {"url":"https://permanenttourist.ch/wp-content/uploads/2019/05/20190502-DSCF7619.jpg","id":45071,"hasParallax":true,"align":"full"} -->
<div class="wp-block-cover alignfull has-background-dim has-parallax" style="background-image:url(https://permanenttourist.ch/wp-content/uploads/2019/05/20190502-DSCF7619.jpg)"><div class="wp-block-cover__inner-container"><!-- wp:heading {"level":1} -->
<h1>WordPress Gutenberg</h1>
<!-- /wp:heading -->
<!-- wp:paragraph {"align":"left","customFontSize":15} -->
<p style="font-size:15px;text-align:left">The Block Unit Tests provide a trial page, which allows you to test the active WordPress Theme and make sure that all of the Gutenberg Blocks work as expected.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
You can’t perform that action at this time.