Selamlar, gönüllülük esasına dayalı bir proje geliştirdik ve bitmek üzere yani bu son problemi de çözersek proje bitiyor, sorun şu aşağıda ki kod fpdf ile hazırladığımız pdfleri post içinde önizlemeyi sağlıyor yayında olan bir postu güncellerken sorun yok ancak taslakta olan bir postu yada yeni bir postu eklerken yayımlarken kritik bir hata oluştur diyor kodlar aşağı da neyi gözden kaçırdığıma dair hiç bir fikrim yok çözebilecek delikanlı var mı
function setup_pdf_preview_and_cleanup_for_dua() {
// FPDF kütüphanesini dahil et
$fpdf_path = get_template_directory() . '/assets/lib/fpdf/fpdf.php';
require_once($fpdf_path); // FPDF kütüphanesinin yolunu doğru şekilde ayarlayın
// Meta box ekleme
add_action('add_meta_boxes', function() {
add_meta_box('pdf_preview', 'PDF Önizleme', function($post) {
// Buton ve önizleme alanı HTML
echo '<button id="pdf-preview-button" data-post-id="' . esc_attr($post->ID) . '">PDF Önizlemesi</button>';
echo '<div id="pdf-preview-container"></div>';
// JavaScript
?>
<script type="text/javascript">
document.getElementById('pdf-preview-button').addEventListener('click', function(event) {
event.preventDefault(); // Butonun varsayılan davranışını engelle
var postId = this.getAttribute('data-post-id');
jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'generate_pdf_preview',
post_id: postId
},
success: function(pdfUrl) {
document.getElementById('pdf-preview-container').innerHTML =
'<iframe src="' + pdfUrl + '" width="100%" height="500px"></iframe>';
}
});
});
</script>
<?php
}, 'dualar'); // Sadece 'dualar' post tipi için geçerli
});
// Ajax işleyici
add_action('wp_ajax_generate_pdf_preview', function() {
$post_id = intval($_POST['post_id']);
$post = get_post($post_id);
$isim = get_the_title($post_id);
$post_content = $post->post_content;
$olusturulma_tarihi = get_the_date('j F Y', $post_id); // Örneğin: "10 Mart 2021" formatında
// FPDF ile PDF oluşturma işlemi
$pdf = new FPDF('P', 'mm', array(1241, 1755));
$pdf->AddPage();
$pdf->AddFont('Ubuntu-Italic', '', 'Ubuntu-Italic.php');
$pdf->SetFont('Ubuntu-Italic', '', 200);
$pdf->SetTextColor(88, 88, 90);
$pdf->Image(get_template_directory() . '/assets/lib/fpdf/sertifika-03.jpg', 0, 0, 1241, 1755);
$pageWidth = $pdf->GetPageWidth();
$cellWidth = 0;
$cellWidthDua = 800;
// İsim için X ve Y koordinatlarını ayarla ve ortala
$pdf->SetXY(($pageWidth - $cellWidth) / 50, 600);
$pdf->Cell($cellWidth, 10, iconv('UTF-8', 'ISO-8859-9', $isim), 0, 1, 'C');
$pdf->SetFont('Ubuntu-Italic', '', 80);
// Post içeriği ve oluşturulma tarihi
$pdf->SetXY(($pageWidth - $cellWidth) / 6, $pdf->GetY() + 450);
$pdf->MultiCell($cellWidthDua, 50, iconv('UTF-8', 'ISO-8859-9', html_entity_decode(esc_html($post_content))), 0, 'C');
$pdf->SetXY(($pageWidth - $cellWidth) / 6, $pdf->GetY() + 150);
$pdf->MultiCell($cellWidthDua, 50, iconv('UTF-8', 'ISO-8859-9', esc_html($olusturulma_tarihi)), 0, 'C');
// Geçici PDF dosyası yolu
$temp_pdf_path = WP_CONTENT_DIR . '/uploads/temp_dua_preview_' . $post_id . '.pdf';
$pdf->Output($temp_pdf_path, 'F'); // Dosyayı sunucuda kaydet
// Geçici PDF URL'si
$temp_pdf_url = content_url('/uploads/temp_dua_preview_' . $post_id . '.pdf');
echo $temp_pdf_url;
wp_die();
});
}
setup_pdf_preview_and_cleanup_for_dua();