Skip to content

Instantly share code, notes, and snippets.

View php-alternative-syntax-example.php
<?php
get_header();
?>
<div class="Main">
<?php if ( have_posts() ): ?>
<?php while ( have_posts() ): ?>
<?php the_post(); ?>
View class-view.php
<?php
class View {
public static $view_dir = '';
/**
* Render View Template With Data
@mishterk
mishterk / clone-gutenberg-reusable-block.php
Last active May 3, 2021
A function that clones an existing reusable block a given number of times.
View clone-gutenberg-reusable-block.php
<?php
/**
* Clone a given reusable block a given number of times.
*
* @param int $block_id The ID of an existing reusable block to clone.
* @param int $n_clones The number of clones to create.
*/
function clone_reusable_block( $block_id, $n_clones ) {
$post = get_post( $block_id );
@mishterk
mishterk / change-the-response-type-to-a-redirect.js
Last active Apr 30, 2021
AJAX functionality examples for Advanced Forms Pro version 1.8.0
View change-the-response-type-to-a-redirect.js
jQuery(function ($) {
// Changing the response type to a redirect on the fly.
acf.addAction('af/form/ajax/submission', function (data, form) {
if (form.key === 'form_5f8f987654e0') {
data.type = 'redirect';
data.redirect_url = 'https://example.com';
}
});
});
@mishterk
mishterk / LocalValetDriver.php
Last active Apr 19, 2021
A local Valet driver for proxying images to a remote host
View LocalValetDriver.php
<?php
/**
* Class LocalValetDriver
*
* This class demonstrates how we might go about proxying any missing local images to a remote host. i.e; the production
* site. This has been created with WordPress in mind but could be adjusted to work with any other system.
*/
class LocalValetDriver extends WordPressValetDriver {
@mishterk
mishterk / acfcdt-relevanssi-support.php
Created Mar 11, 2019
How to add custom table data to Relevanssi's search index
View acfcdt-relevanssi-support.php
<?php
add_filter( 'relevanssi_content_to_index', 'acfcdt_relevanssi_support', 10, 2 );
add_filter( 'relevanssi_excerpt_content', 'acfcdt_relevanssi_support', 10, 2 );
function acfcdt_relevanssi_support( $content, $post ) {
/**
* Approach A (recommended): Using SQL to minimise database queries during Relevanssi's indexing process.
*/
global $wpdb;
@mishterk
mishterk / bypass-elementors-maintenance-mode.php
Last active Mar 11, 2021
Using this snippet, you can bypass Elementor's maintenance mode by adding ?bypass_maintenance=1 to the query string
View bypass-elementors-maintenance-mode.php
<?php
add_filter( 'pre_option_elementor_maintenance_mode_mode', function ( $option ) {
$parameter = 'bypass_maintenance'; // change this to whatever you like
if ( isset( $_GET['bypass_maintenance'] ) and $_GET['bypass_maintenance'] ) {
return 0; // needs to be falsy but not FALSE
}
@mishterk
mishterk / 0-readme.md
Last active Dec 30, 2020
Dynamically set the ACF JSON directory so that each sub-site in a WordPress multisite network has a separate acf-json dir. This maximises compatibility with ACF Custom Database Tables.
View 0-readme.md

Using ACF JSON on WordPress multisite installations

ACF JSON can get a little messy where you need different field groups across your sub-sites. If you are using separate themes or separate child themes for each sub-site, you'll be fine as long as each theme/child-theme has its own /acf-json directory.

If, however, you want to enforce unique acf-json directories for each sub-site, you can do so using one of the following snippets.

  1. Dynamic ACF JSON directory
@mishterk
mishterk / PostTypeTaxonomyMirror.php
Created Dec 17, 2020
Post type/taxonomy mirror.
View PostTypeTaxonomyMirror.php
<?php
class PostTypeTaxonomyMirror {
private $post_type;
private $taxonomy;
@mishterk
mishterk / wplk-get-current-domain-id.php
Last active Dec 12, 2020
An example of getting the current domain post ID in WP Landing Kit. Might be of use if you are loading up ACF fields on a domain post or something similar.
View wplk-get-current-domain-id.php
<?php
// e.g; 'mydomain.com'
$current_host = $_SERVER['HTTP_HOST'];
// This will return a WPLK_Domain object, if the domain can be found. Otherwise, NULL.
$domain = wplk_get_domain( );
if($domain){
$domain_id = $domain->post_id();