version = 'v' . ACFFA_MAJOR_VERSION; $this->name = 'font-awesome'; $this->label = __( 'Font Awesome Icon', 'acf-font-awesome'); $this->category = 'content'; $this->defaults = [ 'enqueue_fa' => 0, 'allow_null' => 0, 'show_preview' => 1, 'save_format' => 'element', 'default_value' => '', 'default_label' => '', 'fa_live_preview' => '', 'choices' => [] ]; parent::__construct(); if ( apply_filters( 'ACFFA_always_enqueue_fa', false ) ) { add_action( 'wp_enqueue_scripts', [ $this, 'frontend_enqueue_scripts' ] ); } else { add_filter( 'acf/load_field', [ $this, 'maybe_enqueue_font_awesome' ] ); } add_filter( 'ACFFA_v5_upgrade_compat_selected_field_sets', [ $this, 'v5_upgrade_compat_selected_field_sets' ], 5, 1 ); add_filter( 'ACFFA_v5_upgrade_compat_format_value', [ $this, 'v5_upgrade_compat_format_value' ], 5, 2 ); } public function render_field_settings( $field ) { if ( apply_filters( 'ACFFA_show_fontawesome_pro_blurbs', true ) ) { acf_render_field_setting( $field, [ 'label' => __( 'Get FontAwesome Pro', 'acf-font-awesome' ), 'message' => '
' . __( 'Support this plugin and get more icons across more styles plus helpful services, regular updates, a lifetime license, and actual human support.', 'acf-font-awesome' ) . '
' . '' . __( 'Upgrade to Font Awesome Pro!', 'acf-font-awesome' ) . '', 'type' => 'message', 'name' => 'get-fontawesome-pro', 'class' => 'get-fontawesome-pro' ] ); } $icon_sets_args = [ 'label' => __( 'Icon Sets', 'acf-font-awesome' ), 'instructions' => __( 'Specify which icon set(s) to load', 'acf-font-awesome' ), 'type' => 'select', 'name' => 'icon_sets', 'multiple' => 1, 'ui' => 1, ]; $icon_sets_args['choices'] = [ 'classic_solid' => __('Classic (Solid)', 'acf-font-awesome'), 'classic_regular' => __('Classic (Regular)', 'acf-font-awesome'), 'classic_light' => __('Classic (Light)', 'acf-font-awesome'), 'classic_thin' => __('Classic (Thin)', 'acf-font-awesome'), 'sharp_solid' => __('Sharp (Solid)', 'acf-font-awesome'), 'sharp_regular' => __('Sharp (Regular)', 'acf-font-awesome'), 'sharp_light' => __('Sharp (Light)', 'acf-font-awesome'), 'sharp_thin' => __('Sharp (Thin)', 'acf-font-awesome'), 'duotone_solid' => __('Duotone (Solid)', 'acf-font-awesome'), 'duotone_regular' => __('Duotone (Regular)', 'acf-font-awesome'), 'duotone_light' => __('Duotone (Light)', 'acf-font-awesome'), 'duotone_thin' => __('Duotone (Thin)', 'acf-font-awesome'), 'sharp-duotone_solid' => __('Sharp Duotone (Solid)', 'acf-font-awesome'), 'sharp-duotone_regular' => __('Sharp Duotone (Regular)', 'acf-font-awesome'), 'sharp-duotone_light' => __('Sharp Duotone (Light)', 'acf-font-awesome'), 'sharp-duotone_thin' => __('Sharp Duotone (Thin)', 'acf-font-awesome'), 'whiteboard_semibold' => __('Whiteboard (Semibold)', 'acf-font-awesome'), 'etch_solid' => __('Etch (Solid)', 'acf-font-awesome'), 'slab_regular' => __('Slab (Regular)', 'acf-font-awesome'), 'slab-press_regular' => __('Slab Press (Regular)', 'acf-font-awesome'), 'thumbprint_light' => __('Thumbprint (Light)', 'acf-font-awesome'), 'jelly_regular' => __('Jelly (Regular)', 'acf-font-awesome'), 'jelly-duo_regular' => __('Jelly Duo (Regular)', 'acf-font-awesome'), 'jelly-fill_regular' => __('Jelly Fill (Regular)', 'acf-font-awesome'), 'chisel_regular' => __('Chisel (Regular)', 'acf-font-awesome'), 'notdog_solid' => __('Notdog (Solid)', 'acf-font-awesome'), 'notdog-duo_solid' => __('Notdog Duo (Solid)', 'acf-font-awesome'), 'utility_semisolid' => __('Utility (Solid)', 'acf-font-awesome'), 'utility-duo_semisolid' => __('Utility Duo (Solid)', 'acf-font-awesome'), 'utility-fill_semisolid' => __('Utility Fill (Solid)', 'acf-font-awesome'), 'fak' => __( 'Uploaded Icons', 'acf-font-awesome' ), 'brands' => __('Brands', 'acf-font-awesome'), 'custom' => __('Custom Icon Set', 'acf-font-awesome') ]; // Fix duotone family previously saved with no style if ( isset( $field['icon_sets'] ) && is_array( $field['icon_sets'] ) ) { if ( ( $key = array_search( 'duotone', $field['icon_sets'] ) ) !== FALSE ) { $field['icon_sets'][ $key ] = 'duotone_solid'; } } $selected_field_sets = ! empty( $field['icon_sets'] ) ? $field['icon_sets'] : [ 'classic_solid', 'classic_regular', 'brands' ]; $selected_field_sets = apply_filters( 'ACFFA_v5_upgrade_compat_selected_field_sets', $selected_field_sets ); $icon_sets_args['value'] = $selected_field_sets; acf_render_field_setting( $field, $icon_sets_args ); $custom_icon_set_choices = get_option( 'ACFFA_custom_icon_sets_list' ); if ( isset( $custom_icon_set_choices[ $this->version ] ) && ! empty( $custom_icon_set_choices[ $this->version ] ) ) { $custom_icon_set_choices = $custom_icon_set_choices[ $this->version ]; } else { $custom_icon_set_choices = [ __( 'No custom icon set(s) found', 'acf-font-awesome' ) ]; } acf_render_field_setting( $field, [ 'label' => __( 'Custom Icon Set', 'acf-font-awesome' ), 'instructions' => sprintf( __( 'Create custom icon sets in the FontAwesome Settings page.', 'acf-font-awesome' ), admin_url( '/edit.php?post_type=acf-field-group&page=fontawesome-settings' ) ), 'type' => 'select', 'name' => 'custom_icon_set', 'class' => 'custom-icon-set', 'choices' => $custom_icon_set_choices, 'value' => isset( $field['custom_icon_set'] ) ? $field['custom_icon_set'] : false, 'placeholder' => 'Choose an icon set', 'allow_null' => 1 ] ); acf_render_field_setting( $field, [ 'label' => __( 'Icon Preview', 'acf-font-awesome' ), 'instructions' => '', 'type' => 'message', 'name' => 'fa_live_preview', 'class' => 'live-preview' ] ); acf_render_field_setting( $field, [ 'label' => __( 'Default Label', 'acf-font-awesome' ), 'instructions' => 'Used internally to store the select label for the default icon. For performance reasons.', 'type' => 'text', 'name' => 'default_label', 'value' => ! empty ( $field['default_label'] ) ? $field['default_label'] : $field['default_value'], 'class' => 'default_value' ] ); acf_render_field_setting( $field, [ 'label' => __( 'Default Icon', 'acf-font-awesome' ), 'instructions' => '', 'type' => 'select', 'name' => 'default_value', 'class' => 'select2-fontawesome fontawesome-create', 'choices' => ! empty( $field['default_label'] ) ? [ $field['default_value'] => html_entity_decode( $field['default_label'] ) ] : [ $field['default_value'] => $field['default_value'] ], 'value' => $field['default_value'], 'placeholder' => 'Choose a default icon (optional)', 'ui' => 1, 'allow_null' => 1, 'ajax' => 1, 'ajax_action' => 'acf/fields/font-awesome/query' ] ); acf_render_field_setting( $field, [ 'label' => __( 'Return Value', 'acf-font-awesome' ), 'instructions' => __( 'Specify the returned value on front end', 'acf-font-awesome' ), 'type' => 'radio', 'name' => 'save_format', 'choices' => [ 'element' => __( 'Icon Element', 'acf-font-awesome' ), 'class' => __( 'Icon Class', 'acf-font-awesome' ), 'unicode' => __( 'Icon Unicode', 'acf-font-awesome' ), 'object' => __( 'Icon Object', 'acf-font-awesome' ), ] ] ); acf_render_field_setting( $field, [ 'label' => __( 'Allow Null?', 'acf-font-awesome' ), 'instructions' => '', 'type' => 'radio', 'name' => 'allow_null', 'choices' => [ 1 => __( 'Yes', 'acf-font-awesome' ), 0 => __( 'No', 'acf-font-awesome' ) ] ] ); acf_render_field_setting( $field, [ 'label' => __( 'Show Icon Preview', 'acf-font-awesome' ), 'instructions' => __( 'Set to \'Yes\' to include a larger icon preview on any admin pages using this field.', 'acf-font-awesome' ), 'type' => 'radio', 'name' => 'show_preview', 'choices' => [ 1 => __( 'Yes', 'acf-font-awesome' ), 0 => __( 'No', 'acf-font-awesome' ) ] ] ); if ( ! apply_filters( 'ACFFA_always_enqueue_fa', false ) ) { acf_render_field_setting( $field, [ 'label' => __( 'Enqueue FontAwesome?', 'acf-font-awesome' ), 'instructions' => __( 'Set to \'Yes\' to enqueue FA in the footer on any pages using this field.', 'acf-font-awesome' ), 'type' => 'radio', 'name' => 'enqueue_fa', 'choices' => [ 1 => __( 'Yes', 'acf-font-awesome' ), 0 => __( 'No', 'acf-font-awesome' ) ] ] ); } } public function render_field( $field ) { if ( $field['allow_null'] ) { $select_value = $field['value']; } else { $select_value = ( 'null' != $field['value'] ) ? $field['value'] : $field['default_value']; } $v5_icon_preselected = false; $field['type'] = 'select'; $field['ui'] = 1; $field['ajax'] = 1; $field['choices'] = []; $field['multiple'] = false; $field['class'] = $v5_icon_preselected ? 'v5_icon_preselected' : ''; if ( ! empty( $field['icon_sets'] ) && in_array( 'custom', $field['icon_sets'] ) && ! empty( $field['custom_icon_set'] ) ) { $field['class'] .= ' fa6 select2-fontawesome fontawesome-edit custom-icon-set'; } else { $field['class'] .= ' fa6 select2-fontawesome fontawesome-edit'; } if ( $select_value ) : $icon_info = json_decode( $select_value ); if ( is_object( $icon_info ) ) { $family = isset( $icon_info->family ) ? $icon_info->family : apply_filters( 'ACFFA_default_family_by_style', 'classic', $icon_info->style ); $style = isset( $icon_info->style ) ? $icon_info->style : ''; $classes = []; if ( 'classic' !== $family ) { $classes[] = 'fa-' . str_replace( '_', '-', $family ); } if ( $style ) { $classes[] = 'fa-' . $style; } $classes[] = 'fa-' . $icon_info->id; $field['choices'][ $select_value ] = ' ' . $icon_info->label; } else { $v5_icon_preselected = true; $options = get_option( 'acffa_settings' ); $label = isset( $options['acffa_v5_compatibility_mode'] ) && $options['acffa_v5_compatibility_mode'] ? '[v5-compat-lookup]' : false; $field['choices'][ $select_value ] = $label; } endif; if ( $field['show_preview'] ) : if ( $v5_icon_preselected ) : ?>