(function() { const { registerPlugin } = wp.plugins; const { PluginSidebar, PluginSidebarMoreMenuItem } = wp.editPost; const { PanelBody, Button, Spinner, Notice } = wp.components; const { Fragment, useState, useEffect } = wp.element; const { useSelect, useDispatch } = wp.data; const { __ } = wp.i18n; const HumanizerSidebar = () => { const [isHumanizing, setIsHumanizing] = useState(false); const [isHumanized, setIsHumanized] = useState(false); const [humanizationDate, setHumanizationDate] = useState(''); const [notice, setNotice] = useState(null); const postId = useSelect(select => select('core/editor').getCurrentPostId()); const postTitle = useSelect(select => select('core/editor').getEditedPostAttribute('title')); const postContent = useSelect(select => select('core/editor').getEditedPostAttribute('content')); const { editPost } = useDispatch('core/editor'); // Verificar estado de humanización al cargar useEffect(() => { if (postId) { checkHumanizationStatus(); } }, [postId]); const checkHumanizationStatus = async () => { try { const response = await fetch(humanizer_ajax.ajax_url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ action: 'get_humanization_status', post_id: postId, nonce: humanizer_ajax.nonce }) }); const data = await response.json(); if (data.success) { setIsHumanized(data.data.is_humanized); setHumanizationDate(data.data.humanization_date || ''); } } catch (error) { console.error('Error checking humanization status:', error); } }; const humanizePost = async () => { if (!confirm(__('¿Estás seguro de que quieres humanizar este post?', 'post-humanizer'))) { return; } setIsHumanizing(true); setNotice(null); try { const response = await fetch(humanizer_ajax.ajax_url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ action: 'humanize_post', post_id: postId, nonce: humanizer_ajax.nonce }) }); const data = await response.json(); if (data.success) { setNotice({ type: 'success', message: data.data || __('Post humanizado exitosamente', 'post-humanizer') }); setIsHumanized(true); setHumanizationDate(new Date().toISOString()); // Recargar el editor para mostrar el contenido actualizado window.location.reload(); } else { setNotice({ type: 'error', message: data.data || __('Error al humanizar el post', 'post-humanizer') }); } } catch (error) { setNotice({ type: 'error', message: __('Error de conexión', 'post-humanizer') }); } finally { setIsHumanizing(false); } }; const formatDate = (dateString) => { if (!dateString) return ''; const date = new Date(dateString); return date.toLocaleString(); }; const getStatusIcon = () => { if (isHumanized) { return '✅'; } return '❌'; }; const getStatusText = () => { if (isHumanized) { return __('Humanizado', 'post-humanizer'); } return __('No humanizado', 'post-humanizer'); }; const getButtonText = () => { if (isHumanizing) { return __('Humanizando...', 'post-humanizer'); } if (isHumanized) { return __('Re-humanizar', 'post-humanizer'); } return __('Humanizar Post', 'post-humanizer'); }; return (
{__('Estado actual:', 'post-humanizer')}
{getStatusIcon()} {getStatusText()}
{isHumanized && humanizationDate && (
{__('Fecha:', 'post-humanizer')} {formatDate(humanizationDate)}
)}
{notice && ( setNotice(null)} > {notice.message} )}
{!postContent && (
{__('El post debe tener contenido para ser humanizado', 'post-humanizer')}
)}
{__('ID:', 'post-humanizer')} {postId}
{__('Título:', 'post-humanizer')} {postTitle || __('Sin título', 'post-humanizer')}
{__('Longitud del contenido:', 'post-humanizer')} {postContent ? postContent.length : 0} caracteres
{__('Palabras aprox:', 'post-humanizer')} {postContent ? Math.round(postContent.split(' ').length) : 0}
{__('Funciones adicionales de SEO y optimización', 'post-humanizer')}
); }; const HumanizerPlugin = () => { return ( {__('Post Humanizer', 'post-humanizer')} ); }; // Registrar el plugin registerPlugin('post-humanizer', { render: HumanizerPlugin, }); // Agregar indicador en la barra superior del editor const { createHigherOrderComponent } = wp.compose; const { Fragment: FragmentComponent } = wp.element; const withHumanizerIndicator = createHigherOrderComponent((BlockEdit) => { return (props) => { const postId = useSelect(select => select('core/editor').getCurrentPostId()); const [isHumanized, setIsHumanized] = useState(false); useEffect(() => { if (postId) { checkStatus(); } }, [postId]); const checkStatus = async () => { try { const response = await fetch(humanizer_ajax.ajax_url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ action: 'get_humanization_status', post_id: postId, nonce: humanizer_ajax.nonce }) }); const data = await response.json(); if (data.success) { setIsHumanized(data.data.is_humanized); } } catch (error) { console.error('Error checking status:', error); } }; return ( {props.isSelected && (
{isHumanized ? '✅ Humanizado' : '❌ No humanizado'}
)}
); }; }, 'withHumanizerIndicator'); // Aplicar el HOC solo al bloque de párrafo como ejemplo wp.hooks.addFilter( 'editor.BlockEdit', 'humanizer/with-indicator', withHumanizerIndicator ); })(); https://atmanme.com/sitemap-1.xml 2025-06-13T03:34:02Z https://atmanme.com/image-sitemap-1.xml 2025-04-22T01:32:02Z https://atmanme.com/video-sitemap-1.xml 2025-02-13T00:42:39Z