get_permalink())); $link_normalized = trim(urldecode($item->get_permalink())); $enlaces_normalized = array_map(function($url){ return trim(urldecode($url)); }, $enlaces); $link_normalized = aife_normalizar_url($item->get_permalink()); $enlaces_normalized = array_map('aife_normalizar_url', $enlaces); if (! (in_array($link_normalized, $enlaces_normalized) || in_array(urlencode($link_normalized), $enlaces_normalized))) { continue; } $noticia = aife_Model::set_noticia_from_item( $item, $feed_url, $feed_id ); $post_date = gmdate('Y-m-d H:i:s', strtotime(current_time('mysql', true) . " +{$time_offset} seconds")); $post_id = wp_insert_post( [ 'post_type' => 'aife_original', 'post_title' => $noticia->title, 'post_excerpt'=> $noticia->description, 'post_content'=> $noticia->content, 'post_status' => 'draft', 'post_date' => $post_date, ] ); if ( $post_id && ! is_wp_error( $post_id ) ) { update_post_meta( $post_id, '_source_feed_id', $feed_id ); if ( ! empty( $noticia->original_url ) ) { update_post_meta( $post_id, '_original_url', esc_url_raw( $noticia->original_url ) ); } if ( ! empty( $noticia->pub_date ) ) { update_post_meta( $post_id, '_pub_date', sanitize_text_field( $noticia->pub_date ) ); } if ( ! empty( $noticia->guid ) ) { update_post_meta( $post_id, '_guid', urldecode( $noticia->guid ) ); } if ( ! empty( $noticia->author ) ) { update_post_meta( $post_id, '_author_name', sanitize_text_field( $noticia->author ) ); } if ( ! empty( $noticia->comments ) ) { update_post_meta( $post_id, '_comments_link', esc_url_raw( $noticia->comments ) ); } if ( ! empty( $noticia->enclosure ) ) { update_post_meta( $post_id, '_enclosure', esc_url_raw( $noticia->enclosure ) ); } if ( ! empty( $noticia->thumbnail ) ) { update_post_meta( $post_id, '_thumbnail_url', esc_url_raw( $noticia->thumbnail ) ); } if ( ! empty( $noticia->categories ) ) { $cat_names = wp_list_pluck( $noticia->categories, 'term' ); update_post_meta( $post_id, '_categories', $cat_names ); } } $time_offset++; } wp_redirect( admin_url( 'admin.php?page=aife_importar_noticias&feed_id=' . $feed_id . '&imported=1&_wpnonce=' . wp_create_nonce('importar_feed_' . $feed_id) ) ); exit; } function aife_normalizar_url($url) { $url = trim($url); $url = urldecode($url); $url = str_replace('&', '&', $url); // <--- clave $url = rtrim($url, '/'); $url = preg_replace('/[[:^print:]]/', '', $url); // elimina no imprimibles return $url; }