WordPress sitem için eklenti klasöründeki bir xml veri dosyasından okuma/yazma özelliğine sahip bir özel eklenti yazdım. Ben dosya okuma/yazma için bu standart PHP kodunu test ettiğimde, her ikisi de okuyabiliyor olsa da, wp-admin/seviyesinde bulunan dosyalara/eklentilere, eklenti klasörü içindeki dosyaları oluşturmama/yazmama izin vereceğim.WordPress eklentimden bir dosyaya yazma
$file = 'test.xml'; (Can write to this file)
$file = plugins_url()."/my-plugin/test.xml"; (Can read but not write to this file)
// Open the file to get existing content
$current = file_get_contents($file);
echo $current;
// Append a new person to the file
$current .= "<person>John Smith</person>\n";
// Write the contents back to the file
file_put_contents($file, $current);
aşağıdaki hata ayıklama hatayı alıyorum: Şu anda kapalı bir yerel MAMP sunucusu bu koşuyorum
Warning: file_put_contents(http://localhost/wp_mysite/wp-content/plugins/my-plugin/test.xml) [function.file-put-contents]: failed to open stream: HTTP wrapper does not support writeable connections in /Applications/MAMP/htdocs/wp_mysite/wp-content/plugins/my-plugin/my-plugin.php on line 53
, ama bana paketlemek izin vermedi ve herhangi WordPress sunucuda eklentisi yayınlayacak çözüm istiyor . Doğru yaklaşım nedir? dosyaya yazmak isterseniz
@ Temalar için benzer bir şey var mı? WP_THEME_DIR' gibi bir şeyler> – Blowsie
@Blowsie: Hayır böyle bir SABİT değil ama benzer bir şey. "Büyük resim" için buraya bakın: http://codex.wordpress.org/Determining_Plugin_and_Content_Directories – hakre