true, 'data-label' => true, 'data' => true]; $allowed['table'] = ['class' => true, 'id' => true, 'style' => true]; $allowed['thead'] = []; $allowed['tbody'] = []; $allowed['tfoot'] = []; $allowed['tr'] = []; $allowed['th'] = ['scope' => true, 'colspan' => true, 'rowspan' => true, 'style' => true]; $allowed['td'] = ['colspan' => true, 'rowspan' => true, 'style' => true]; $allowed['caption'] = []; return $allowed; } function aife_sanitize_html($value) { if (current_user_can('unfiltered_html')) return $value; // admins return is_string($value) ? wp_kses($value, aife_allowed_html()) : $value; } /** * ===== Metabox URL en CPT ai_feed ===== */ function aife_add_url_metabox() { add_meta_box( 'AIFE_URL_metabox', __('URL de la fuente', 'ai-feeds'), 'AIFE_URL_metabox_callback', 'ai_feed', 'normal', 'default' ); } add_action('add_meta_boxes', 'aife_add_url_metabox'); function AIFE_URL_metabox_callback($post) { wp_nonce_field('aife_save_url_metabox', 'AIFE_URL_metabox_nonce'); $url = get_post_meta($post->ID, '_ai_feed_url', true); ?> $columns['cb'], 'title' => __('Nombre de la fuente', 'ai-feeds'), 'url' => __('URL', 'ai-feeds'), ]; } add_filter('manage_ai_feed_posts_columns', 'aife_custom_columns'); function aife_custom_columns_content($column, $post_id) { switch ($column) { case 'url': $url = get_post_meta($post_id, '_ai_feed_url', true); echo esc_url($url); break; } } add_action('manage_ai_feed_posts_custom_column', 'aife_custom_columns_content', 10, 2); /** * ===== Limpiar metaboxes de ai_feed ===== */ function aife_remove_extra_metaboxes() { global $wp_meta_boxes; $screen = 'ai_feed'; $contexts = ['normal', 'advanced', 'side']; foreach ($contexts as $context) { if (isset($wp_meta_boxes[$screen][$context])) { foreach ($wp_meta_boxes[$screen][$context] as $priority => $boxes) { foreach ($boxes as $id => $box) { if ($id !== 'AIFE_URL_metabox' && $id !== 'submitdiv') { remove_meta_box($id, $screen, $context); } } } } } } add_action('do_meta_boxes', 'aife_remove_extra_metaboxes', 999); /** * ===== Metabox de Campos AI Feeds en post ===== */ function aife_add_custom_fields_metabox() { $settings = get_option('aife_settings', []); $campos = $settings['registrar_meta_keys'] ?? []; // Filtrar campos que NO estén en ACF $campos_a_mostrar = []; foreach ($campos as $key) { if (function_exists('get_field_object')) { $acf = get_field_object($key, 'post'); if (!$acf) $campos_a_mostrar[] = $key; } else { $campos_a_mostrar[] = $key; } } if (empty($campos_a_mostrar)) return; add_meta_box( 'aife_custom_fields', __('Campos AI Feeds', 'ai-feeds'), function($post) use ($campos_a_mostrar) { aife_custom_fields_metabox_callback($post, $campos_a_mostrar); }, 'post', 'normal', 'default' ); } add_action('add_meta_boxes', 'aife_add_custom_fields_metabox'); function aife_custom_fields_metabox_callback($post, $campos) { wp_nonce_field('aife_save_custom_fields', 'aife_custom_fields_nonce'); $html_fields = aife_html_fields(); foreach ($campos as $key) { $value = get_post_meta($post->ID, $key, true); $label = esc_html(ucfirst($key)); echo '

'; echo '
'; if (in_array($key, aife_html_fields(), true)) { // Editor WYSIWYG $editor_id = 'aife_' . sanitize_key($key) . '_' . (int) $post->ID; $settings = [ 'textarea_name' => $key, // nombre real del meta 'editor_height' => 240, 'media_buttons' => false, // pon true si quieres botón “Añadir medio” 'teeny' => false, // barra completa 'quicktags' => true, // pestaña Texto 'tinymce' => [ // Activa tablas y botones útiles 'plugins' => 'lists link paste', 'toolbar1' => 'formatselect,bold,italic,underline,|,bullist,numlist,blockquote,|,alignleft,aligncenter,alignright,|,link,unlink,|,table,|,undo,redo,removeformat', ], ]; wp_editor($value, $editor_id, $settings); echo '' . esc_html__('Este campo admite HTML (tablas).', 'ai-feeds') . ''; } else { echo ''; } echo '

'; } } add_action('save_post_post', 'aife_save_custom_fields_metabox'); function aife_save_custom_fields_metabox($post_id) { if ( ! isset($_POST['aife_custom_fields_nonce']) || ! wp_verify_nonce(wp_unslash($_POST['aife_custom_fields_nonce']), 'aife_save_custom_fields') ) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; if (! current_user_can('edit_post', $post_id)) return; $settings = get_option('aife_settings', []); $campos = $settings['registrar_meta_keys'] ?? []; $html_fields = aife_html_fields(); foreach ($campos as $key) { if (! isset($_POST[$key])) continue; $raw = wp_unslash($_POST[$key]); if (in_array($key, $html_fields, true)) { // Guardar preservando HTML permitido $clean = aife_sanitize_html($raw); } else { // Texto plano para el resto $clean = sanitize_text_field($raw); } update_post_meta($post_id, $key, $clean); } } /** * ===== Columnas extra en ai_feed ===== */ add_filter('manage_ai_feed_posts_columns', 'aife_customize_columns'); function aife_customize_columns($columns) { return [ 'cb' => $columns['cb'], 'title' => __('Nombre de la fuente', 'ai-feeds'), 'url' => __('URL', 'ai-feeds'), 'importar_noticias' => __('Importar noticias', 'ai-feeds'), 'aife_ajustes' => __('Ajustes', 'ai-feeds'), 'hereda_ajustes' => __('Hereda ajustes', 'ai-feeds'), ]; } add_action('manage_ai_feed_posts_custom_column', 'aife_render_custom_columns', 10, 2); function aife_render_custom_columns($column, $post_id) { if ($column === 'hereda_ajustes') { $hereda = get_post_meta($post_id, '_aife_hereda_ajustes', true) === '1'; echo '
'; echo ''; echo '
'; } if ($column === 'importar_noticias') { $nonce = wp_create_nonce('importar_feed_' . $post_id); $url = admin_url('admin.php?page=aife_importar_noticias&feed_id=' . $post_id . '&_wpnonce=' . $nonce); echo ''; echo esc_html__('Importar ahora', 'ai-feeds'); echo ''; } if ($column === 'aife_ajustes') { $url = wp_nonce_url( admin_url('admin.php?page=aife_feed_settings&feed_id=' . $post_id), 'editar_ajustes_feed_' . $post_id ); echo '' . esc_html__('Ajustes del feed', 'ai-feeds') . ''; } }