Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Wilkinson wpmark

View GitHub Profile
@wpmark
wpmark / readme.md
Last active Nov 5, 2021
An example of caching data using a WordPress transient
View readme.md

Caching WordPress data using Transients - Example

In this simple example we create a function for obtaining data from an external source and caching it for 24 hours. You can use the function hd_get_external_data() to get the data and work with it in your site.

If you want to force a refresh of the cache, you can pass a value of true into the function.

You can place the code into your themes functions.php file or better still in a plugin. If you are placing it in a plugin, remember to use function_exists() when using this. This ensures that the code will fail correctly if the plugin is not active.

@wpmark
wpmark / hd-just-in-time-css.php
Created Aug 13, 2021
A plugin to provide Just in Time CSS for WordPress blocks
View hd-just-in-time-css.php
<?php
/*
Plugin Name: Just in Time CSS
Plugin URI: https://highrise.digital/
Description: A plugin from Highrise Digital to provide just in time CSS functionality.
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital Ltd
Author URI: https://highrise.digital/
Text domain: hd-just-in-time-css
@wpmark
wpmark / wp-email-tweaks.php
Created Oct 12, 2021
Easily customise the name and email address of WordPress emails
View wp-email-tweaks.php
<?php
/**
* Used to filter email from 'address'
*/
function hd_email_send_wp_mail_address( $input ) {
// return a new from email address.
return 'no-reply@highrise.digital';
}
@wpmark
wpmark / alignment-options.js
Last active Oct 14, 2021
Add alignment options for WordPress core blocks.
View alignment-options.js
// set alignment options for cover, video, and paragraph blocks.
wp.hooks.addFilter(
'blocks.registerBlockType',
'hd-theme/hd-theme',
function( settings, name ) {
if ( name === 'core/cover' || name === 'core/video' || name === 'core/paragraph' || name === 'core/list' ) {
return lodash.assign( {}, settings, {
supports: lodash.assign( {}, settings.supports, {
// allow support for full and wide alignment.
align: ['full', 'wide'],
@wpmark
wpmark / post-type-support.php
Created Oct 8, 2021
Add post type support for the post excerpt
View post-type-support.php
<?php
/**
* Add support for the excerpt on pages.
*/
function hd_add_custom_post_type_excerpt_support() {
// add post type support for pages.
add_post_type_support( 'page', 'excerpt' );
// add post type support for case studies.
@wpmark
wpmark / using-media-handle-sideload.php
Created Jul 10, 2015
Using Media Handle Sideload
View using-media-handle-sideload.php
<?php
/* set the url of the file to sideload - probably be from $_POST or something */
$url = 'http://domain.com/image.jpg';
/**
* donwload the url into wordpress
* saved temporarly for now
*/
$tmp = download_url( $url );
@wpmark
wpmark / hd-user-categories.php
Created Jun 11, 2021
A WordPress plugin that adds categories to users. It allows you to assign categories to users which you could then use elsewhere in your site.
View hd-user-categories.php
<?php
/*
Plugin Name: User Categories
Plugin URI: https://highrise.digital/
Description: Adds categories to users. It allows you to assign categories to users which you could then use elsewhere in your site.
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital Ltd
Author URI: https://highrise.digital/
Text domain: hd-user-categories
@wpmark
wpmark / highrise-auto-updater.php
Created Mar 31, 2021
Allow WordPress to auto update eveything.
View highrise-auto-updater.php
<?php
/*
Plugin Name: Highrise Digital Auto Updater
Plugin URI: https://highrise.digital/
Description: A plugin to set WordPress to auto update everything.
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital
Author URI: https://highrise.digital/
Text domain: highrise-auto-updater
@wpmark
wpmark / gist:9d5d2395cb01a2de0179
Created Oct 8, 2014
Check If WordPress Post is Older than X Days
View gist:9d5d2395cb01a2de0179
<?php
/*******************************
* this will work in the loop
*******************************/
/* check if the posts publish date is older than 60 days */
if( strtotime( $post->post_date ) < strtotime('-60 days') ) {
/* post is older than 60 days - do something with it!! */
@wpmark
wpmark / editors-widget-menus.php
Created May 3, 2014
Allow WordPress Editors Access to Widgets and Menus
View editors-widget-menus.php
<?php
/***************************************************************
* Function pxlcore_give_edit_theme_options()
* Adds widgets and menus to editors.
***************************************************************/
function pxlcore_give_edit_theme_options( $caps ) {
/* check if the user has the edit_pages capability */
if( ! empty( $caps[ 'edit_pages' ] ) ) {