Skip to content

Instantly share code, notes, and snippets.

@DimaMinka
Created September 25, 2019 09:11
Show Gist options
  • Save DimaMinka/5cb95b31088921517c25e5f879549b2f to your computer and use it in GitHub Desktop.
Save DimaMinka/5cb95b31088921517c25e5f879549b2f to your computer and use it in GitHub Desktop.
Advanced Custom Fields Seetings with ACF Builder
<?php
/**
* Module name: Custom Settings
*
* @package ACF
* @see README.md for details
*/
use StoutLogic\AcfBuilder\FieldsBuilder;
/**
* Register the needed fields for events.
*/
if ( function_exists( 'acf_add_local_field_group' ) ) {
$acf_module = new FieldsBuilder( 'custom_settings', [
'title' => __( 'Custom Settings', 'acf_plus' ),
'position' => 'side'
] );
$acf_module
->addSelect( 'acf_settings_header_style', [
'label' => __( 'Header Style', 'acf_plus' ),
'choices' => [
'default',
'light'
]
] )
->setLocation( 'post_type', '==', 'page' )
->or('post_type', '==', 'post');
acf_add_local_field_group( $acf_module->build() );
}
/**
* Include partial of module
*
* @param mixed $content WordPress post content.
*
* @return mixed
*/
function acf_plus_custom_settings_body_class( $classes ) {
if ( is_page() or is_single() ) {
$acf = get_field('acf_settings_header_style');
$classes[] = $acf ? 'is-' . $acf : '';
}
return $classes;
}
add_filter( 'body_class', 'acf_plus_custom_settings_body_class', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment