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

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/

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
86 [javascript] 압축(Minify) / 난독화(Uglify) 졸리운_곰 2020.07.01 293
85 InnerHTML 사용시 알 수 없는 런타임 오류 졸리운_곰 2020.03.13 505
84 How to Create an addChild() Function in JavaScript file 졸리운_곰 2020.03.09 437
83 JavaScript post request like a form submit 졸리운_곰 2020.03.09 474
82 [pure javascript] Vanilla JS equivalents of jQuery methods 졸리운_곰 2020.03.09 374
81 [Javascript] innerHTML 의 함정 졸리운_곰 2020.03.08 374
80 자바스크립트 헬로월드 javascrpt "hello world" file 졸리운_곰 2019.10.06 474
79 Awesome Wasm Awesome file 졸리운_곰 2019.05.18 785
78 이전 페이지의 주소 받기 졸리운_곰 2019.04.11 580
77 ADD/REMOVE CLASSES WITH RAW JAVASCRIPT 19 May 2010 2 min read By Jake Trent In Posts 졸리운_곰 2019.03.24 500
76 Merge and split table cells with JavaScript file 졸리운_곰 2019.03.23 501
75 How can I detect if a selector returns null? 졸리운_곰 2019.03.23 296
74 How do I test for an empty JavaScript object? 졸리운_곰 2019.03.19 617
73 Grouping Array Data — JSON file 졸리운_곰 2019.03.13 358
72 ECMAScript 6: maps and sets 졸리운_곰 2019.03.11 349
71 Comparing a Text Element and a String 졸리운_곰 2019.03.10 319
70 How to check whether a string contains a substring in JavaScript? 졸리운_곰 2019.03.10 366
69 자바스크립트 – 객체안에 값이 있는지 여부 졸리운_곰 2019.03.08 481
68 브라우저 현재 작업창 닫기 졸리운_곰 2019.03.07 477
67 [번역] 자바스크립트 클래스를 정의하는 3가지 방법 (3 ways to define a JavaScript class) 졸리운_곰 2019.03.06 477
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED