Google APIs Client Library for PHP(https://github.com/google/google-api-php-client)のPHPでの実装方法が分かりません。
先月、でたばかりのものということですが、WPで実装したいと思っています。
コードが長くても良いので具体的な実装方法を教えていただけないでしょうか。
下記の場合ですと、WPのサーバーにアップロードしていますが下記を変更して実装していただかなくて結構です。
※$url等を画像のURLにして実装していただいて結構です。
PHP
1 if (preg_match('/.(jpg|png|PNG|jpeg|JPG|gif)$/', $node->nodeValue)) { 2 $upload_dir = wp_upload_dir(); 3 $arr = explode('.', $ank); 4 $ext = end($arr); 5 $filename = date('Ymdhis'); 6 static $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJLKMNOPQRSTUVWXYZ0123456789'; 7 8 $str = ''; 9 for ($i = 0; $i < 1; ++$i) { 10 $str .= $chars[mt_rand(0, 61)]; 11 } 12 $img_save = $upload_dir['baseurl'] . "/" . $filename . $str . "." . $ext; 13 $srcpath = $upload_dir['basedir'] . "/" . $filename . $str . "." . $ext; 14 $filename35 = basename($srcpath); 15 $filename35 = basename($srcpath); 16 $upload_file35 = wp_upload_bits($filename35, null, file_get_contents($ank)); 17 $wp_filetype35 = wp_check_filetype($filename35, null); 18 $upload_file35['file']; 19 $attachment = array( 20 'guid' => $upload_dir['url'] . '/' . basename( $filename35 ), 21 'post_mime_type' => $wp_filetype35['type'], 22 'post_title' => preg_replace('/.[^.]+$/', '', $filename35), 23 'post_content' => '', 24 'post_status' => 'inherit' 25 ); 26 $attach_id = wp_insert_attachment( $attachment, $upload_file35['file'], 0 ); 27 if($attach_id) { 28 require_once(ABSPATH . "wp-admin" . '/includes/image.php'); 29 30 $attach_data = wp_generate_attachment_metadata( $attach_id, $upload_file35['file'] ); 31 wp_update_attachment_metadata( $attach_id, $attach_data ); 32 } 33 global $src; 34 35 global $alin; 36 37 $src = $upload_dir['url'] . "/" . $filename . $str . "." . $ext; 38 $node->setAttribute('href', $src); 39 $img = $dom->createElement('img'); 40 $img->setAttribute('src', $src); 41 $node->nodeValue = null; 42 $node->appendChild($img); 43 }
あなたの回答
tips
プレビュー