htmlburger / carbon-field-icon
Carbon Fields 扩展,添加图标字段类型。
v3.1.0
2019-05-07 12:38 UTC
Requires
- htmlburger/carbon-fields: ^3.0
This package is auto-updated.
Last update: 2024-09-08 00:49:56 UTC
README
提供选择图标或符号的能力。
支持的符号
- Font Awesome (v5.8.1)
- Dashicons
- 自定义
用法
仅 Font Awesome (默认)
Field::make( 'icon', 'social_site_icon', __( 'Icon', 'crb' ) ),
仅 Dashicons
Field::make( 'icon', 'social_site_icon', __( 'Icon', 'crb' ) ) ->add_dashicons_options(),
Dashicons 和 Font Awesome
Field::make( 'icon', 'social_site_icon', __( 'Icon', 'crb' ) ) ->add_dashicons_options() ->add_fontawesome_options(),
自定义图标列表
Field::make( 'icon', 'social_site_icon', __( 'Icon', 'crb' ) ) ->set_options( array( // Minimal settings: 'my-custom-icon-1' => array( 'name' => __( 'My Custom Icon 1' ), 'icon' => get_template_directory() . '/icons/my-custom-icon-1.svg', ), // Full settings: 'my-custom-icon-2' => array( 'name' => __( 'My Custom Icon 2' ), 'icon' => get_template_directory() . '/icons/my-custom-icon-2.svg', 'id' => 'my-custom-icon-2', 'class' => 'my-custom-prefix-class', 'search_terms' => array( 'shop', 'checkout', 'product' ), ), ) ),
使用提供者的自定义图标列表
class Custom_Icon_Provider implements Carbon_Field_Icon\Providers\Icon_Provider_Interface { public function parse_options() { return array( // Minimal settings: 'custom-icon-1' => array( 'name' => __( 'Custom Icon 1' ), 'icon' => get_template_directory() . '/icons/custom-icon-1.svg', ), // Full settings: 'custom-icon-2' => array( 'name' => __( 'Custom Icon 2' ), 'icon' => get_template_directory() . '/icons/custom-icon-2.svg', 'id' => 'custom-icon-2', 'class' => 'custom-prefix-class', 'search_terms' => array( 'shop', 'checkout', 'product' ), ), ); } } add_action( 'carbon_fields_icon_field_loaded', 'crb_register_custom_icon_field_provider' ); function crb_register_custom_icon_field_provider() { $provider_id = 'custom'; \Carbon_Fields\Carbon_Fields::instance()->ioc['icon_field_providers'][ $provider_id ] = function( $container ) { return new Custom_Icon_Provider(); }; \Carbon_Field_Icon\Icon_Field::add_provider( [ $provider_id ] ); } Container::make( 'theme_options', __( 'Theme Options', 'crb' ) ) ->set_page_file( 'crbn-theme-options.php' ) ->add_fields( array( Field::make( 'icon', 'crb_custom_icon', __( 'Choose Custom Icon', 'crb' ) ) ->add_provider_options( 'custom' ), ) );