フィルターを追加します('content_save_pre', 'auto_save_image'); 関数 auto_save_image($content) { $アップロードパス = "; $upload_url_path = get_bloginfo('url'); //アップロードディレクトリ (($var = get_option('upload_path')) != "){の場合 $upload_path = $var; } それ以外 { $upload_path = 'wp-content/uploads'; } if(get_option('uploads_use_yearmonth_folders')) { $upload_path .= '/'.date("Y",time()).'/'.date("m",time()); } //ファイルアドレス if(($var = get_option('upload_url_path')) != '') { $upload_url_path = $var; } それ以外 { $upload_url_path = bloginfo('url'); } if(get_option('uploads_use_yearmonth_folders')) { $upload_url_path .= '/'.date("Y",time()).'/'.date("m",time()); } require_once("../wp-includes/class-snoopy.php"); $snoopy_Auto_Save_Image = 新しいスヌーピー; $img = 配列(); //記事のタイトルを画像のタイトルとして使用します if ( !empty( $_REQUEST['post_title'] ) ) $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] )); $text = スラッシュを削除します($content); get_magic_quotes_gpc() の場合、$text は stripslashes($text); preg_match_all(“/ src=("|'){0,}(http://(.+?))("|'|s)/is”,$text,$img); $img = array_unique(dhtmlspecialchars($img[2])); foreach ($img を $key => $value として){ set_time_limit(180); //各画像に許可される最大ダウンロード時間(秒) if(str_replace(get_bloginfo('url'),"",$value)==$value&&str_replace(get_bloginfo('home'),"",$value)==$value){ //ローカル画像かどうか判断し、そうでない場合はサーバーに保存します $fileext = substr(strrchr($value,'.'),1); $fileext = strtolower($fileext); $fileext==""||strlen($fileext)>4の場合 $fileext = "jpg"; $savefiletype = 配列('jpg','gif','png','bmp'); if (in_array($fileext, $savefiletype)){ if($snoopy_Auto_Save_Image->fetch($value)){ $get_file = $snoopy_Auto_Save_Image->結果; }それ以外{ echo "ファイルの取得中にエラーが発生しました: ".$snoopy_Auto_Save_Image->error.""; echo “エラー url: “.$value; 死ぬ(); } $filetime = 時間(); $filepath = "/".$upload_path; //画像が保存されるディレクトリのパス !is_dir("..".$filepath) ? mkdirs("..".$filepath) : null; //$filename = date("His",$filetime).random(3); $filename = substr($value,strrpos($value,'/'),strrpos($value,'.')-strrpos($value,'/')); //$e = '../'.$filepath.$filename.'.'.$fileext; //if(!is_file($e)) { // コピー(htmlspecialchars_decode($value),$e); // $fp = @fopen(「..」.$ファイルパス.$ファイル名「..」.$ファイル拡張子「w」); $fp に $get_file を書き込みます。 fclose($fp); $wp_filetype = wp_check_filetype( $filename.".".$fileext, false ); $type = $wp_filetype['type']; $post_id = (int)$_POST['temp_ID2']; $title = $post_title; $url = $upload_url_path.$filename.".".$fileext; $file = $_SERVER['DOCUMENT_ROOT'].$filepath.$filename.".".$fileext; //データベースレコードを追加 $添付ファイル = 配列( 'post_type' => '添付ファイル'、 'post_mime_type' => $type、 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, '投稿コンテンツ' => ', ); $id = wp_insert_attachment($attachment、$file、$post_parent); $text = str_replace($value,$url,$text); //記事内の画像アドレスを置き換えます } } } $content = スラッシュを追加します($text); フィルターを削除します('content_save_pre', 'auto_save_image'); $content を返します。 } 関数 mkdirs($dir) { if(!is_dir($dir)) { mkdirs(dirname($dir)); mkdir($dir); } 戻る ; } 関数 dhtmlspecialchars($string) { if(is_array($string)) { foreach($文字列を$key => $valとして) { $文字列[$キー] = dhtmlspecialchars($val); } }それ以外{ $文字列 = str_replace('&', '&', $文字列); $文字列 = str_replace('"', '"', $文字列); $文字列 = str_replace(”, $文字列); $string = preg_replace('/&(#\d;)/', '&\1', $string); } $文字列を返します。 } テーマの functions.php ファイルまたは functions.php のインポート ファイルに追加するだけです。WordPress で記事を公開するたびに、記事に外部リンク画像が含まれている場合は自動的にローカライズされます。設定なしで非常に便利です。 出典: http://y-cy.cn/86.html |