Skip to content

Instantly share code, notes, and snippets.

View schutzsmith's full-sized avatar

Daniel Schutzsmith schutzsmith

View GitHub Profile
<?php
// The field accepts a value with this structure
$value = [
'address' => '123 Example St, Townsville XYZ 1234, Country',
'lat' => - 38.1486228,
'lng' => 144.360414,
'zoom' => 14,
'place_id' => 'Ei0xMjMgTW9vcmFib29sIFN0LCBHZWVsb25nIFZJQyAzMjIwLCBBdXN0cmFsaWEiMBIuChQKEgmX0JaIHBTUahFyH_LC9sYD8hB7KhQKEglDz-DYDxTUahECZY8QisCjzg',
'street_number' => 123,
@schutzsmith
schutzsmith / register-acf-options-page.php
Created June 3, 2022 20:33 — forked from mishterk/register-acf-options-page.php
How to register options pages in Advanced Custom Fields for WordPress (ACF). See https://www.awesomeacf.com/snippets/register-options-page/ for more details.
<?php
// register a top-level options page
if ( function_exists( 'acf_add_options_page' ) ) {
acf_add_options_page( [
'page_title' => 'My Options Page',
'menu_title' => 'My Options Page',
'menu_slug' => 'my-options-page',
'capability' => 'edit_posts',
'parent_slug' => '',
<?php
// In a post/page template, loop over the ACF flexible field layouts and load the partial
// responsible for rendering the layout.
while ( the_flexible_field('my_flexi_field') ) {
get_template_part( 'components/'. get_row_layout() );
}
<?php
// Define this in the site's wp-config.php file.
define('GOOGLE_API_KEY', 'your-google-api-key-here');
// Add this to your functions.php file, or a config plugin/MU plugin.
add_filter( 'acf/fields/google_map/api', function ( $api ) {
$api['key'] = GOOGLE_API_KEY;
return $api;
@schutzsmith
schutzsmith / control-acf-menu-visibility.php
Created June 3, 2022 20:32 — forked from mishterk/control-acf-menu-visibility.php
Hide the ACF admin menu dynamically based on site domain
<?php
add_filter( 'acf/settings/show_admin', function () {
// Get the current site url.
$site_url = get_bloginfo( 'url' );
// Define an array of protected site urls.
$protected_urls = array(
'https://www.example.com',
'http://staging.example.com'
@schutzsmith
schutzsmith / disable-core-meta-metabox.php
Created June 3, 2022 19:33 — forked from mishterk/disable-core-meta-metabox.php
Speed up ACF backend loading time
<?php
add_filter('acf/settings/remove_wp_meta_box', '__return_true');
@schutzsmith
schutzsmith / acf-php-license-config.php
Created June 3, 2022 19:33 — forked from mishterk/acf-php-license-config.php
How to define the ACF PRO license key in code rather than storing it in the WordPress database. This Gist accompanies the article: https://www.awesomeacf.com/snippets/store-acf-pro-license-key-in-wordpress-php-configuration/
<?php
// Add this in your wp-config.php file
define('ACF_PRO_LICENSE', '{YOUR LICENSE KEY HERE}' );
@schutzsmith
schutzsmith / acf-field-group-php-to-json.php
Created June 3, 2022 19:32 — forked from mishterk/acf-field-group-php-to-json.php
Convert an ACF Field Group from PHP to ACF-JSON
<?php
// Get all the local field groups and loop through them for processing.
$field_groups = acf_get_local_field_groups();
foreach ( $field_groups as $group ) {
// If the field group has fields, load them into the 'fields' key.
if ( acf_have_local_fields( $group['key'] ) ) {
$group['fields'] = acf_get_local_fields( $group['key'] );
}
<?php
add_filter( 'acf/settings/load_json', function ( $paths ) {
$paths[] = get_template_directory() . '/some/custom/dir';
return $paths;
} );
@schutzsmith
schutzsmith / custom-provision.sh
Created April 24, 2016 00:50 — forked from neilgee/custom-provision.sh
Custom VVV Variable Provisioning for WordPress sites
# #!/bin/bash
# #
# # provision.sh
# #
# # This file is specified in Vagrantfile and is loaded by Vagrant as the primary
# # provisioning script whenever the commands `vagrant up`, `vagrant provision`,
# # or `vagrant reload` are used. It provides all of the default packages and
# # configurations included with Varying Vagrant Vagrants.
# # By storing the date now, we can calculate the duration of provisioning at the