Skip to content

Instantly share code, notes, and snippets.

@Oscar-Abad-Folgueira
Created November 16, 2022 12:50
Show Gist options
  • Save Oscar-Abad-Folgueira/7a35a4ba8526d3053175640d95f25b20 to your computer and use it in GitHub Desktop.
Save Oscar-Abad-Folgueira/7a35a4ba8526d3053175640d95f25b20 to your computer and use it in GitHub Desktop.
WordPress Snippet: Incluir ACF en un plugin
<?php
/**
* @snippet WordPress Snippet: Incluir ACF en un plugin
* @author Oscar Abad Folgueira
* @author_url https://www.oscarabadfolgueira.com
* @snippet_url https://oscarabadfolgueira.com/
*/
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/** Detect ACF plugin. Include if not present. */
if ( !class_exists('acf') ) { // if ACF plugin does not currently exist
/** Customize ACF path */
add_filter('acf/settings/path', 'oaf_acf_settings_path');
function oaf_acf_settings_path( $path ) {
$path = plugin_dir_path( __FILE__ ) . 'acf/';
return $path;
}
/** Customize ACF dir */
add_filter('acf/settings/dir', 'oaf_acf_settings_dir');
function oaf_acf_settings_dir( $path ) {
$dir = plugin_dir_url( __FILE__ ) . 'acf/';
return $dir;
}
/** Hide ACF field group menu item */
add_filter('acf/settings/show_admin', '__return_false');
/** Include ACF */
include_once( plugin_dir_path( __FILE__ ) . 'acf/acf.php' );
/** Create JSON save point */
add_filter('acf/settings/save_json', 'oaf_acf_json_save_point');
function oaf_acf_json_save_point( $path ) {
$path = plugin_dir_path( __FILE__ ) . 'acf-json/';
return $path;
}
/** Create JSON load point */
add_filter('acf/settings/load_json', 'oaf_acf_json_load_point');
/** Stop ACF upgrade notifications */
add_filter( 'site_transient_update_plugins', 'oaf_stop_acf_update_notifications', 11 );
function oaf_stop_acf_update_notifications( $value ) {
unset( $value->response[ plugin_dir_path( __FILE__ ) . 'acf/acf.php' ] );
return $value;
}
} else { // else ACF plugin does exist
/** Start: Create JSON load point */
add_filter('acf/settings/load_json', 'oaf_acf_json_load_point');
} // end-if ACF Pro plugin does not currently exist
/** Function to create JSON load point */
function oaf_acf_json_load_point( $paths ) {
$paths[] = plugin_dir_path( __FILE__ ) . 'acf-json-load';
return $paths;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment