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 '