2016-03-23 17 views
0

.htaccessファイルを変更する必要のあるWordPressのプラグインを作成したいと思います。 PHPでどうすればいいですか?私は他のプラグインでこれが前に行われているのを見てきましたが、どうやって完了したのか分かりません。ありがとう!Wordpress Plugin APIを使用して.htaccessを編集しますか?

+0

これは悪い練習です – gmaniac

+0

私は許可を求めますが、それは変更されません。 – arodebaugh

+0

あなたは試したことの例がありますか? – gmaniac

答えて

3

.htaccessファイルを更新するwordpressの関数は、insert_with_markersです。これには3つのパラメータが必要です。ここでは、このtutorialあなた.htaccessファイルに次のようになり、この

// Get path to main .htaccess for WordPress 
$htaccess = get_home_path().".htaccess"; 

$lines = array(); 
$lines[] = "RewriteBase /foobar"; 

insert_with_markers($htaccess, "MyPlugin", $lines); 

ような何かを書くことができ

# BEGIN MyPlugin 
RewriteBase /foobar 
# END MyPlugin 

次の

insert_with_markers (string $filename, string $marker, array|string $insertion) 

はのWordPressのドキュメントへのリンクですその機能

https://developer.wordpress.org/reference/functions/insert_with_markers/

+0

ありがとうございました! – arodebaugh

関連する問題