Last active
January 27, 2023 14:05
-
-
Save mehigh/9f9f5d8e3179176a4ac457b9f4ad7e0b to your computer and use it in GitHub Desktop.
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 | |
/** | |
* WP_Theme_Template\Components\ACF_Options_Page_Template class | |
* | |
* @package WP_Theme_Template | |
*/ | |
namespace WP_Theme_Template\Components; | |
/** | |
* Class ACF_Options_Page_Template. | |
*/ | |
class ACF_Options_Page_Template implements Component, Templater { | |
/** | |
* Field ID. | |
* | |
* @var string | |
*/ | |
const EXAMPLE_FIELD = 'example_field_id'; | |
/** | |
* Register any needed hooks/filters. | |
*/ | |
public function init() { | |
add_action( 'acf/init', [ $this, 'setup' ] ); | |
} | |
/** | |
* ACF initialization configuration. | |
* | |
* @return void | |
*/ | |
public function setup() { | |
acf_add_local_field_group( | |
[ | |
'key' => 'group_template_settings', | |
'title' => 'Template', | |
'fields' => [ | |
[ | |
'key' => 'field_' . self::EXAMPLE_FIELD, | |
'label' => __( 'Example Field', 'wp-theme-template' ), | |
'name' => self::EXAMPLE_FIELD, | |
'type' => 'text', | |
'required' => 0, | |
], | |
], | |
'location' => [ | |
[ | |
[ | |
'param' => 'options_page', | |
'operator' => '==', | |
'value' => ACF_Options_Page::OPTIONS_PAGE_MENU_SLUG, | |
], | |
], | |
], | |
], | |
); | |
} | |
/** | |
* Get Example field. | |
* | |
* @return string The value of the example field. | |
*/ | |
public function get_example_field() { | |
if ( ! function_exists( 'get_field' ) ) { | |
return ''; | |
} | |
return get_field( self::EXAMPLE_FIELD, 'option' ) ? get_field( self::EXAMPLE_FIELD, 'option' ) : ''; | |
} | |
/** | |
* Gets template tags to expose as methods on the Template_Tags class instance, accessible through `xwp_co_theme()`. | |
* | |
* @return array Associative array of $method_name => $callback_info pairs. Each $callback_info must either be | |
* a callable or an array with key 'callable'. This approach is used to reserve the possibility of | |
* adding support for further arguments in the future. | |
*/ | |
public function get_template_tags() { | |
return [ | |
'get_example_field' => [ $this, 'get_example_field' ], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment