'ai_feed', 'meta_key' => '_ai_feed_url', 'meta_value' => $feed_url, 'posts_per_page' => 1, 'post_status' => 'publish' ]); if (!empty($existing_feed)) { wp_send_json_error(__('Este feed ya está guardado.', 'ai-feeds')); wp_die(); } // Crear entrada CPT "ai_feed". $post_id = wp_insert_post([ 'post_title' => $feed_nombre, 'post_type' => 'ai_feed', 'post_status' => 'publish', ]); if (is_wp_error($post_id)) { wp_send_json_error(__('Error al crear la fuente.', 'ai-feeds')); wp_die(); } // Guardar URL en post_meta. update_post_meta($post_id, '_ai_feed_url', $feed_url); wp_send_json_success(__('Fuente agregada correctamente.', 'ai-feeds')); wp_die(); } add_action( 'wp_ajax_aife_toggle_herencia', 'aife_toggle_herencia' ); function aife_toggle_herencia() { // Verifica permisos if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'No autorizado.', 'ai-feeds' ) ); } // Verifica nonce if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'aife_toggle_herencia_nonce' ) ) { wp_send_json_error( __( 'Verificación de seguridad fallida.', 'ai-feeds' ) ); } $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0; $estado = isset( $_POST['estado'] ) && $_POST['estado'] === '1' ? '1' : '0'; if ( get_post_type( $post_id ) !== 'ai_feed' ) { wp_send_json_error( __( 'Feed no válido.', 'ai-feeds' ) ); } update_post_meta( $post_id, '_aife_hereda_ajustes', $estado ); wp_send_json_success( [ 'estado' => $estado ] ); }