せっかく作ったので

デスクトップにtest.phpってファイル名で置いてたら、消して後悔しそうだったのでここに書いておこうと思う。

id属性”_wp_unfiltered_html_comment”の先頭のアンダーバーを除去するプラグイン。(ただし、手動)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
$initdir    = "/wordpress/";
$ext        = ".php";
$find       = "_wp_unfiltered_html_comment";
$replace    = "wp_unfiltered_html_comment";
 
 
$filelist = get_filelist($initdir, $ext);
foreach($filelist as $key => $filename) {
    // ファイルを読み込む
    $fcontents = @file_get_contents($filename);
 
    // 検索
    $pos = strpos($fcontents, "_wp_unfiltered_html_comment");
    if($pos !== FALSE) {
        // 文字列が存在した場合
        // 置換
        $fout = fopen($filename, "w");
        fwrite($fout, str_replace($find, $replace, $fcontents));
        fclose($fout);
        echo "replace : " . $filename . "\n";
    }
}
 
 
// $initdir以下の$extファイルのリストを取得する
function get_filelist($startDir, $ext) {
    $dir      = $startDir;
    $dirs     = array();
    $filename = array();
    $next     = 0;
    foreach(glob($dir."*".$ext) as $_filename) {
        $filename[] = $_filename;
    }
    while(true) {
        $_dirs = glob($dir."*", GLOB_ONLYDIR | GLOB_MARK);
        if(count($_dirs)) {
            foreach ($_dirs as $key => $_dir) {
                foreach(glob($_dir."*".$ext) as $_filename) {
                    $filename[] = $_filename;
                }
                $dirs[] = $_dir;
            }
        } else {
            break;
        }
        $dir = $dirs[$next++];
    }
    return $filename;
}
?>

_wp_unfiltered_html_comment replacer v0.1

上へ参ります。