워드프레스 마이크로서비스

Jeff Kubina - https://flic.kr/p/eACKE

How to Super Charge your WordPress with Microservices

Confession: I’m amazed at the authoring experience that WordPress provides. Users are productive from the first hour and UI doesn’t get in their way. The story is similar for developers, if you stay inside the world of theme development. Try to do anymore complex and with tests, and it gets complicated. That is where (micro)service oriented architecture can help us.

At the Open Education Consortium, we use a mix of all the different approaches.

1. Let the WordPress call external API’s

wp1

At OEC, we provide functionality of Course search. While I could build it inside WordPress, it wouldn’t be optimal. I’ve developed it in Django with REST Framework. We get API Documentation for free and our Main WordPress site is using the same calls as everyone else.

To call an external API, you’ll need to extend template_redirectinit,
and query_vars actions and filters.

  <?
   
  // init action
  add_rewrite_rule(
  'courses/view/(\w+)/?$',
  'index.php?course_id=$matches[1]',
  'top'
  );
   
  // template_redirect action
  if ( get_query_var( 'course_id' ) ) {
  $wp_query->is_404 = false;
  status_header( '200' );
   
  add_filter( 'template_include', function() {
  return get_template_directory() . '/courses/course_detail.php';
  });
  }
   
  // functions.php
  function get_course_detail() {
  $course_id = get_query_var('course_id');
  $url = DATA_API_URL."/courses/view/$course_id/?format=json";
  $result = wp_remote_get( $url );
  $response = wp_remote_retrieve_body( $result );
   
  return json_decode($response);
  }
   
  // course_detail.php
  $course = get_course_detail();
  ..
  echo $course->title;
  ..
view rawgistfile1.php hosted with ❤ by GitHub

This way, you can format output inside your WordPress theme.

2. Let the Javascript call external API’s

wp2

This is not strictly WordPress, but it solves the other half of the problems you might have. If you don’t need to have output visible to Search Engines, you can render it with JavaScript. In one example, we’re showing a map of where our members are. We have a separate portal, where members can edit their contact information.

On WordPress side, Leaflet library calls the GeoJSON endpoint and displays it on the map. The data is always up to date and we’re using the best tool for the job.
This portal then exposes GeoJSON API, that Leaflet then displays.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

3. Embed your WordPress output

wp3

For our Directory feature, I needed a flexible membership system. I ended writing it in Django with Solr. Django provides powerful form editing, that I didn’t want to replicate inside WordPress.

What I ended doing, is that I exposed API from WordPress with header and footer HTML. That way Django can just include 3rd party content. It also simplifies keeping the themes in sync.

I could do it using iframes, but then I would have problems with urls and the size of iframe content.

There is also a possibility for a future upgrade. Because we’re running on the same domain, we can read cookies from WordPress. This would allow us to check if user is logged into WP Dashboard and elevate their privilages inside Django app.

Conclusion

Modern Web applications are moving away from monolithic, one size fits all, solutions. While it’s common to see such infrastructure in the backend, it’s time that we start embracing it also on user facing sites. I wish some of the infrastructure inside WordPress, would make it easier, but I guess that’s an opportunity for a new library.

[출처] https://www.jurecuhalev.com/blog/2015/07/14/how-to-super-charge-your-wordpress-with-microservices/

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
174 HTML/CSS기초_drop down 메뉴 만들기 1 file 졸리운_곰 2020.01.11 381
173 자바스크립트 헬로월드 javascrpt "hello world" file 졸리운_곰 2019.10.06 474
172 Awesome Wasm Awesome file 졸리운_곰 2019.05.18 785
171 WebGL 기초 file 졸리운_곰 2019.04.16 346
170 javascript contains : JavaScript String includes() Method 졸리운_곰 2019.04.11 622
169 이전 페이지의 주소 받기 졸리운_곰 2019.04.11 580
168 table 태그 총정리 졸리운_곰 2019.04.09 1003
167 textarea 태그에 값을 넣고 뺄때 아니면 개행문자 '\n'이 혼란이 온다 졸리운_곰 2019.04.08 692
166 자바스크립트 뒤로가기 history.back() 메소드 졸리운_곰 2019.04.08 574
165 jQuery ready와 load의 차이 file 졸리운_곰 2019.03.29 733
164 [JavaScript] 시간 지연 함수, 일정 시간 뒤 실행시키기, SetTimeout() {} 졸리운_곰 2019.03.27 472
163 How can I detect if a selector returns null? 졸리운_곰 2019.03.25 454
162 ADD/REMOVE CLASSES WITH RAW JAVASCRIPT 19 May 2010 2 min read By Jake Trent In Posts 졸리운_곰 2019.03.24 500
161 How can I use jQuery to make an input readonly? 졸리운_곰 2019.03.24 320
160 jQuery.isEmptyObject() 졸리운_곰 2019.03.24 793
159 Merge and split table cells with JavaScript file 졸리운_곰 2019.03.23 502
158 How can I detect if a selector returns null? 졸리운_곰 2019.03.23 296
157 테이블 태그 셀 합치기 그리고, 테이블 안 테이블 file 졸리운_곰 2019.03.23 566
156 테이블 컬럼 너비 고정 : Fixed Table Cell Width 졸리운_곰 2019.03.21 767
155 DIV 가로 중앙정렬과 세로 중앙정렬 방법 file 졸리운_곰 2019.03.20 498
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED