Untitled
unknown
php
3 years ago
2.5 kB
3
Indexable
function yazigonder($title, $article,$resimadres,$url,$username,$password) // { $new_post = array( 'title' => $title, // yazı başlığı 'content' => $article, // içerik 'status' => 'publish', // yayın durumu 'date' => date('Y-m-d H:i:s'), // yayın tarihi 'author' => 1, // yazar id 'type' => 'post', // post/page - yazı veya sayfa 'category' => array(0), // kategori id'leri ); try { $client = new GuzzleHttp\Client(['cookies' => true]); $response = $client->request('POST', $url . '/wp-json/wp/v2/posts', [ 'form_params' => $new_post, 'headers' => [ 'Authorization' => 'Basic ' . base64_encode($username . ':' . $password), 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36' ] ]); $source = $response->getBody(); $source = json_decode($source); $post_id = $source->id; $client = new GuzzleHttp\Client(); $response = $client->request('POST', $url . '/wp-json/wp/v2/media', [ 'form_params' => [ 'link' => $resimadres, 'source_url' => $resimadres ], 'headers' => [ 'Authorization' => 'Basic ' . base64_encode($username . ':' . $password), 'Content-Type' => 'image/jpeg', 'Content-Disposition' => 'attachment; filename="'.$title.'"' ] ]); } catch (Exception $e) { echo $e; } /* $src = $response->getBody(); $src = json_decode($src); $img_id = $src->id; $client = new GuzzleHttp\Client(['cookies' => true]); $response = $client->request('POST', $url . '/wp-json/wp/v2/posts/' . $post_id, [ 'form_params' => [ 'featured_media' => $img_id ], 'headers' => [ 'Authorization' => 'Basic ' . base64_encode($username . ':' . $password), 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36' ] ]);*/ }
Editor is loading...