質問

ブログをブロガーからWPに変換し、スクリプトを実行してホスティング用のホットリンク画像を入手する過程で、私は最終的にファンキーな画像名になりました

act%252Bapandas-210x290.png

これらの画像名は、ファイル名自体で終了するURLエンコードがあるため、画像がWebページに表示されるのを防ぎます(尋ねないでください!)。ファイルサーバーでそれらを変更しましたが、問題はありませんが、名前は各投稿の添付メタデータにも含まれています。

wp_postmetaテーブルのすべての画像参照から「%」を削除するにはどうすればよいですか? *それらのほとんどは、_wp_attachment_metadata*のmeta_keysのmeta_valuesのシリアル化された配列で発生します。プラグインを見つける運がありませんでしたが、純粋なSQL/PHPソリューションをどのように制定するかがわかりません。

以下は、シリアル化された配列エントリの例を示します(Smush.itプラグイン、うーん、さらにガムになります):

a:7:{s:5:"width";s:3:"210";s:6:"height";s:3:"339";s:14:"hwstring_small";s:22:"height='96' width='59'";s:4:"file";s:27:"2011/02/act%252Bapandas.png";s:5:"sizes";a:6:{s:9:"thumbnail";a:4:{s:4:"file";s:27:"act%252Bapandas-210x290.png";s:5:"width";s:3:"210";s:6:"height";s:3:"290";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x290.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x290.png)";}s:14:"soft-thumbnail";a:4:{s:4:"file";s:27:"act%252Bapandas-179x290.png";s:5:"width";s:3:"179";s:6:"height";s:3:"290";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-179x290.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-179x290.png)";}s:14:"mini-thumbnail";a:4:{s:4:"file";s:25:"act%252Bapandas-60x60.png";s:5:"width";s:2:"60";s:6:"height";s:2:"60";s:10:"wp_smushit";s:267:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-60x60.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-60x60.png)";}s:5:"slide";a:4:{s:4:"file";s:27:"act%252Bapandas-210x290.png";s:5:"width";s:3:"210";s:6:"height";s:3:"290";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x290.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x290.png)";}s:10:"soft-slide";a:4:{s:4:"file";s:27:"act%252Bapandas-179x290.png";s:5:"width";s:3:"179";s:6:"height";s:3:"290";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-179x290.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-179x290.png)";}s:10:"mini-slide";a:4:{s:4:"file";s:27:"act%252Bapandas-210x145.png";s:5:"width";s:3:"210";s:6:"height";s:3:"145";s:10:"wp_smushit";s:271:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x145.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas-210x145.png)";}}s:10:"image_meta";a:10:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";}s:10:"wp_smushit";s:255:"Smush.it error: Could not get the image while processing http://new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas.png (/home/xxxxxxxxx/new.xxxxx.com/wp-content/uploads/2011/02/act%252Bapandas.png)";}

問題は「%」文字を変更または削除し、配列を更新するため、正しい数の文字数を報告します(つまり、s:13はyoursite.comが13 char []を示します)私もPHPソリューションを使用することができます。 !この混乱を修正するのに役立つものは何でも。

最終的解決

以下の私の答えを参照してください。

役に立ちましたか?

解決

一般的なアイデアは、すべての添付ファイルをループして、メタを取得、変更、書き戻すことです。

このようなもの(重要なものを使用する前に徹底的にテスト):

$posts = get_posts(array(
    'post_type' => 'attachment',
    'numberposts' => -1,
));

foreach( $posts as $post ) {

    // retrieve data, unserialized automatically
    $meta = get_post_meta($post->ID,'_wp_attachment_metadata', true);

    // do stuff with $meta array

    // write it back
    update_post_meta($post->ID, '_wp_attachment_metadata', $meta);
}

他のヒント

  $posts = get_posts(array(
                'post_type' => 'attachment',
                'numberposts' => -1,
            ));

    // Recursive String Replace - recursive_array_replace(mixed, mixed, array);
    function recursive_array_replace($find, $replace, $array){
    if (!is_array($array)) {
    return str_replace($find, $replace, $array);
    }
    $newArray = array();
    foreach ($array as $key => $value) {
    $newArray[$key] = recursive_array_replace($find, $replace, $value);
    }
    return $newArray;
    }

    foreach ($posts as $post) {
        // retrieve data, unserialized automatically
        $meta = get_post_meta($post->ID, '_wp_attachment_metadata', true);
        // see if file name has "%" in it
        if (strpos($meta[file], "%")) {
        //recursively scrub "%"
        $meta = recursive_array_replace('%', '', $meta);
        }

        // write it back
        update_post_meta($post->ID, '_wp_attachment_metadata', $meta);
    }
ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top