-
-
Save sergeyterr/4a90ad264052dbb8148468f55ab178b7 to your computer and use it in GitHub Desktop.
Advanced Custom Fields Seetings with ACF Builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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