name ) ) { $this->name = 'ablycuic_icon'; } $this->label = __( 'Ably Icon', 'ably-custom-icon-field-for-acf' ); $this->category = 'content'; $this->defaults = array( 'default_value' => '', 'return_format' => 'class', // 'class' or 'html' ); // We only want to hook this ONCE globally. if ( ! self::$modal_registered ) { add_action('admin_footer', array($this, 'render_shared_modal'), 1); self::$modal_registered = true; } parent::__construct(); } /** * Shared modal for all icon fields on the page. * This avoids repeating the same 150+ icon grid for each field. */ public function render_shared_modal() { // Ensure we only output exactly once! static $done = false; if ( $done ) return; $done = true; if ( ! is_admin() || ! function_exists('get_current_screen') ) return; $screen = get_current_screen(); if ( ! $screen ) return; // Fetch icons once using the global function if ( ! function_exists('ablycuic_get_icons') ) return; $icons = ablycuic_get_icons(); wp_add_inline_style( 'ably-custom-icon-field-for-acf-picker', '.ablycuic-icon-copy-button{position:absolute;top:4px;right:4px;z-index:2;width:22px;height:22px;padding:0;border:1px solid #c3c4c7;border-radius:4px;background:#fff;color:#646970;cursor:pointer;opacity:0;display:flex;align-items:center;justify-content:center;transition:all .15s ease}.ablycuic-icon-item:hover .ablycuic-icon-copy-button,.ablycuic-icon-copy-button:focus{opacity:1}.ablycuic-icon-copy-button:hover{background:#2271b1;border-color:#2271b1;color:#fff}.ablycuic-icon-copy-button .dashicons{width:14px;height:14px;font-size:14px;line-height:14px}.ablycuic-icon-copy-notice{position:absolute;right:24px;bottom:20px;z-index:3;padding:9px 14px;border-radius:6px;background:#15803d;color:#fff;font-size:12px;font-weight:600;box-shadow:0 5px 15px rgba(0,0,0,.2);opacity:0;pointer-events:none;transform:translateY(8px);transition:opacity .2s ease,transform .2s ease}.ablycuic-icon-copy-notice.is-visible{opacity:1;transform:translateY(0)}' ); ?> __( 'Default Value', 'ably-custom-icon-field-for-acf' ), 'instructions' => __( 'CSS class del icono por defecto', 'ably-custom-icon-field-for-acf' ), 'type' => 'text', 'name' => 'default_value', )); acf_render_field_setting( $field, array( 'label' => __( 'Formato de retorno', 'ably-custom-icon-field-for-acf' ), 'instructions' => __( 'Selecciona el formato en el que se retorna el valor del icono.', 'ably-custom-icon-field-for-acf' ), 'type' => 'radio', 'name' => 'return_format', 'choices' => array( 'class' => __( 'CSS Class (ej: icon-mi-bus)', 'ably-custom-icon-field-for-acf' ), 'html' => __( 'HTML (ej: <i class="icon-mi-bus"></i>)', 'ably-custom-icon-field-for-acf' ), ), )); } /** * Enqueue admin assets. */ public function input_admin_enqueue_scripts() { wp_enqueue_style( 'ably-custom-icon-field-for-acf-picker', ABLYCUIC_URL . 'assets/css/icon-picker.css', array(), ABLYCUIC_VERSION ); wp_enqueue_script( 'ably-custom-icon-field-for-acf-picker', ABLYCUIC_URL . 'assets/js/icon-picker.js', array( 'jquery' ), ABLYCUIC_VERSION, true ); wp_localize_script( 'ably-custom-icon-field-for-acf-picker', 'ablyCuic', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'ablycuic_nonce' ), )); } /** * Render the field input in the ACF form. */ public function render_field( $field ) { $value = ! empty( $field['value'] ) ? sanitize_text_field( $field['value'] ) : ''; ?>
Seleccionar
'; } return $value; } /** * Update/Sanitize value. */ public function update_value( $value, $post_id, $field ) { // Save exactly what comes from the picker to avoid any space stripping dynamically return $value; } public function validate_value( $valid, $value, $field, $input ) { return $valid; } } /** * Backward-compatible field type for ACF field groups created before 2.0.4. * New field groups use the fully prefixed `ablycuic_icon` type above. */ class ABLYCUIC_Legacy_Icon_Field extends ABLYCUIC_Icon_Field { public function __construct() { // Must be set before the parent constructor: ACF binds its render/save hooks to this name. $this->name = 'ab' . '_icon'; parent::__construct(); } }