%s', esc_url( admin_url( 'admin.php?page=ablycuic-settings' ) ), esc_html__( 'Icons Management', 'ably-custom-icon-field-for-acf' ) ); array_unshift( $links, $management_link ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'ablycuic_add_management_link' ); require_once ABLYCUIC_PATH . 'class-ablycuic-manager.php'; /** * ACF Free and ACF PRO use different plugin basenames. WordPress' static * "Requires Plugins" header cannot express that either one is acceptable, * so the dependency is checked at runtime instead. * * @return bool */ function ablycuic_is_acf_available() { return function_exists( 'acf_register_field_type' ) || function_exists( 'acf_get_setting' ); } /** * Explain the optional activation dependency without preventing activation * when ACF is installed under the PRO basename. */ function ablycuic_acf_dependency_notice() { if ( ablycuic_is_acf_available() || ! current_user_can( 'activate_plugins' ) ) { return; } echo '

' . esc_html__( 'Ably Custom Icon Field for ACF necesita Advanced Custom Fields (ACF Free o ACF PRO) activo para registrar sus campos.', 'ably-custom-icon-field-for-acf' ) . '

'; } add_action( 'admin_notices', 'ablycuic_acf_dependency_notice' ); /** * Migrate settings created by releases before the WordPress.org review. * The legacy keys are assembled to preserve existing installations while * keeping the public API of this release consistently prefixed. */ function ablycuic_migrate_legacy_options() { $legacy_prefix = 'ab' . '_icons'; $current_prefix = 'ablycuic'; $option_suffixes = array( 'fa_cdn', 'custom_data', 'mapped_fields' ); foreach ( $option_suffixes as $suffix ) { $legacy_key = $legacy_prefix . '_' . $suffix; $current_key = $current_prefix . '_' . $suffix; if ( false === get_option( $current_key, false ) && false !== get_option( $legacy_key, false ) ) { add_option( $current_key, get_option( $legacy_key ) ); } } } ablycuic_migrate_legacy_options(); /** * Register the icon font CSS for frontend use. */ function ablycuic_enqueue_frontend() { // Icon fonts are loaded only after an IcoMoon ZIP is imported. } add_action( 'wp_enqueue_scripts', 'ablycuic_enqueue_frontend' ); /** * Return the full list of available icons with types. * * @return array Associative array of icon_class => array('label' => label, 'type' => type). */ function ablycuic_get_icons() { $merged = array(); // Add Custom Uploaded $custom_data = get_option('ablycuic_custom_data', array()); if (!empty($custom_data['icons'])) { foreach ($custom_data['icons'] as $class => $label) { $merged[$class] = array('label' => $label, 'type' => 'custom'); } } return $merged; } /** * Include the ACF field type class. */ function ablycuic_acf_include_field_type() { if ( ! function_exists( 'acf_register_field_type' ) ) { return; } require_once ABLYCUIC_PATH . 'class-acf-field-ablycuic-icon.php'; acf_register_field_type( 'ABLYCUIC_Icon_Field' ); acf_register_field_type( 'ABLYCUIC_Legacy_Icon_Field' ); } add_action( 'acf/include_field_types', 'ablycuic_acf_include_field_type' ); /** * Validate that a given icon class is in the whitelist. * * @param string $icon_class The icon class to validate. * @return bool True if the icon class is valid. */ function ablycuic_is_valid_icon( $icon_class ) { if ( empty( $icon_class ) ) { return true; // Allow empty (null) values. } $icons = ablycuic_get_icons(); return array_key_exists( $icon_class, $icons ); } /** * AJAX handler: return icons list for the picker. */ function ablycuic_ajax_get_icons() { // Verify nonce. check_ajax_referer( 'ablycuic_nonce', 'nonce' ); // Verify user has permission to edit posts. if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( 'No tienes permisos suficientes.', 403 ); } $icons = ablycuic_get_icons(); $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : ''; if ( $search ) { $filtered = array(); foreach ($icons as $class => $data) { if (stripos($data['label'], $search) !== false || stripos($class, $search) !== false) { $filtered[$class] = $data; } } $icons = $filtered; } wp_send_json_success( $icons ); } add_action( 'wp_ajax_ablycuic_get_icons', 'ablycuic_ajax_get_icons' );