Skip to content

Instantly share code, notes, and snippets.

@hartliddell
Last active July 27, 2016 14:18
Show Gist options
  • Save hartliddell/53b067fd811d80f64b3bb2f39b4b0019 to your computer and use it in GitHub Desktop.
Save hartliddell/53b067fd811d80f64b3bb2f39b4b0019 to your computer and use it in GitHub Desktop.
Add ACF fields via php. Add notice in CMS that this is how ACF fields are being loaded.
<?php
// load custom fields
require_once 'custom-fields--layouts.php';
require_once 'custom-fields--meta.php';
require_once 'custom-fields--press.php';
require_once 'custom-fields--press-items.php';
require_once 'custom-fields--room.php';
// put message in ACF interface to warn people to edit custom fields here
function acf_warning( $hook ) {
if ('edit.php' != $hook) {
return;
}
$javascript = "
var acfFieldGroupEl = document.getElementById('acf-field-group-wrap');
if (acfFieldGroupEl) {
var warningEl = document.createElement('h3');
warningEl.innerHTML = 'WARNING: Custom Field definitions are in " . basename(__FILE__) . "';
warningEl.style.color = 'red';
acfFieldGroupEl.insertBefore(warningEl, acfFieldGroupEl.firstChild);
}
";
// needed because Wordpress is weird
wp_enqueue_script( 'acf-warning-js', '/iAmNotReal.js', array(), '1.0', true);
wp_add_inline_script( 'acf-warning-js', $javascript);
}
add_action('admin_enqueue_scripts', 'acf_warning');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment