Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[PHP] XMLRPC를 이용한 WordPress 포스트 등록

2018-01-30 by 편리

xmlrpc를 이용한 워드프레스 포스트 등록 기능이다. 공개된 xmlrpc client를 사용했으며 UI는  Bootstrap을 이용했다. 첨부파일을 다운로드 후 웹서에 업로드한 후 브라우저에서 접속하면 아래와 같은 화면이 표시된다. 각 필드를 직접 입력하고 Post 버튼을 클릭하면 워드프레스 블로그에 포스트가 등록된다.

  • https://codex.wordpress.org/XML-RPC_WordPress_API
  • https://github.com/letrunghieu/wordpress-xmlrpc-client

wp-poster : wp-poster.zip

워드프레스 블로그에 포스트를 등록하는 코드는 아래와 같다. 개발은 PHP 7.2.x 버전에서 진행됐다.

<?php
require './_autoload.php';
require './lib/functions.php';

$endpoint = trim($_POST['wp']);
$id       = trim($_POST['id']);
$pass     = trim($_POST['pass']);
$title    = trim($_POST['title']);
$content  = trim($_POST['content']);
$category = trim($_POST['category']);
$tag      = trim($_POST['tag']);

if(!$endpoint || !$id || !$pass || !$title || !$content)
    die_json('XMLRPC URL, User ID, User Password, Title, Content를 확인해 주십시오.');

$wpClient = new \HieuLe\WordpressXmlrpcClient\WordpressClient();

$wpClient->setCredentials($endpoint, $id, $pass);

try {
    $blogs = $wpClient->getUsersBlogs();
}
catch(Exception $e) {
    die_json($e->getMessage());
}

unset($blogs);

$postContent = $content;

$_category = array_map('trim', explode(',', $category));
$_tag      = array_map('trim', explode(',', $tag));

$content = array(
    'terms_names' => array(
        'category' => $_category,
        'post_tag' => $_tag                                    
    ),
    /*
    'custom_fields' => array(
        array('key' => '_yoast_wpseo_focuskw_text_input', 'value' => '테스트 포커스')
    )
    */
);

try {
    $post_id = $wpClient->newPost((string)$title, $postContent, $content);
}
catch(Exception $e) {
    die_json($e->getMessage());
}

if(!$post_id)
    die_json('Posting failed.');
else
    die_json('OK');

기능을 좀 더 발전시키면 아래와 같은 것도 가능하다. 아마존 API를 이용해 ASIN 코드를 입력하면 자동으로 상품정보를 가져와 포스트로 등록한다.

Post navigation

Previous Post:

[WP] XMLRPC를 이용한 WordPress(워드프레스) 포스트 등록 #2

Next Post:

[PHP] Papago NMT API 이용을 위한 Class

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes