แนวทางการพัฒนา theme / plugin และอัพขึ้น WordPress.org ใน 3 วัน
ทำไมถึงอยากอัพขึ้น WordPress.org
- พัฒนาตัวเอง
- อยากรู้การทำงานของ Open source ใหญ่ๆ แบบนี้ว่า flow ในการทำงานเขาเป็นยังไงกัน
- เป็นช่องทางใน การพัฒนาโค้ด และส่งต่อไปยังผู้ใช้งาน
ชื่อ ณัฐชัย ทองนิรันดร์ (โจ้), web developer
| type | name | start | submit | first review | approved | all |
|--------|------------------|----------|----------------|----------------|----------------|------|
| plugin | Auto Subpage Menu| 23/08/15 | 25/08/15 (+2d) | - | 27/08/15 (+2d) | 5d |
| theme | Koa | 24/05/16 | 31/07/16 (+2m) | 30/12/16 (+5m) | 16/01/17 (+2w) | 7.5m |
| plugin | Mobile Redirect..| 12/08/16 | 13/08/16 (+1d) | - | 16/08/16 (+3d) | 5d |
| plugin | Grayscale Body | 14/10/16 | 14/10/16 | - | 15/10/16 (+1d) | 2d |
| plugin | Black Ribbon | 24/10/16 | 24/10/16 | - | 25/10/16 (+1d) | 2d |
| theme | Mediumm | 11/01/16 | 13/04/17 (+15m)| 25/05/17 (+1m) | 19/06/17 (+1m) | 17m |
| plugin | PromptPay | 07/09/17 | 07/09/17 | - | 10/09/17 (+3d) | 4d |
| plugin | Mourning | 02/10/17 | 04/10/17 (+2d) | - | 05/10/17 (+1d) | 4d |
ข้อสังเกต และประสบการณ์ที่พบเจอตอน submit และ review
- plugin แรกๆ ใช้เวลา 2-3 วันในการรออนุมัติ แต่หลังๆ แค่ 1 วัน
- หลังๆจะพัฒนาได้ไว เพราะ copy ของเก่ามา
- อย่าง PromptPay ที่ใช้เวลา 3 วันเพราะปัญหาอื่น คือ เราไม่ได้เป็นตัวแทนของ PromptPay, เขาก็เลยแนะนำให้ ใส่ชื่อแบรนด์เพิ่มเข้าไปเช่น jojoee-promptpay
- การส่ง plugin, ส่งแล้วรอ feedback (ถ้าไม่มีปัญหาอะไรเขาก็จะส่ง email มาอนุมัติเลย)
ตัวอย่าง Plugins ที่พัฒนา
- Auto Subpage Menu: Automatically add/remove top-level page to/from menus, WordPress, GitHub, SVN
- Black Ribbon: Automatically add black ribbon into sites corner, WordPress, GitHub, SVN
- Grayscale Body: Automatically turn the site to grayscale, WordPress, GitHub, SVN
- Mobile Redirect With Slug: Redirect mobile’s user to mobile site, WordPress, GitHub, SVN
- Mourning: Add black ribbon and grey out the website, WordPress, GitHub, SVN
- PromptPay: PromptPay integration for WordPress, WordPress, GitHub, SVN
ตัวอย่าง Themes ที่พัฒนา
- Koa: Simple clean blog, WordPress, GitHub, Ticket
- Mediumm, theme that's very inspired by medium.com, WordPress, GitHub, Ticket 1, Ticket 2
- Web development standards, มาตรฐานการพัฒนาเว็บ ทั่วไป
- WordPress development standards, มาตรฐานการพัฒนาร่วมกับ WordPress (เหมือนเราทำอยู่บน Framework ตัวนึง) เช่นเราทำ React, Symfony เราก็จะใช้ท่านี้ ทำแบบนี้
- WordPress.org submitting standards, มาตรฐานในการอัพขึ้น WordPress.org, เหมือนกับเราส่งงาน ให้ Tester, PM หรือ ลูกค้า ตรวจสอบหรือดูคุณภาพของงาน
โดยใน session นี้จะเน้น 3 เป็นพิเศษ, เพราะว่าหัวข้อที่ 1 กับ 2 นั้นหาอ่านเอาในอินเทอร์เน็ตได้ง่ายกว่า
- Avoid common problem เช่น
- เราโหลด css ก่อน เพื่อให้เวลาเปิด page แล้ว layout มันแสดงผลได้ถูกต้อง
- เราใช้
wp_enqueue_script
ในการโหลดไฟล์ ทำให้เวลามันเรียกใช้ library เดียวกันมันก็จะไปเรียกตัวเดียวกัน แทนที่จะเป็นการ include เข้ามาซ้ำกัน
- Avoid future problem เช่น
- การหลีกเลี่ยง deprecated method, เวลาเขาไม่ support method พวกนี้แล้วเนี่ย เราก็จะได้ไม่มีปัญหา
- On the same page, เข้าใจไปในทิศทางเดียวกัน เช่น
- เรียกใช้ไฟล์ผ่าน
wp_enqueue_script
เพื่อลดการใช้งาน common library ที่ซ้ำซ้อน
- Save time
- etc.
- Coding standard
- DRY, อะไรที่ซ้ำๆกัน แยกออกมา เวลาจะเปลี่ยนแปลงจะได้เปลี่ยนแปลงที่เดียว
- Design pattern
- Test e.g. unit, acceptance, responsive, browser compatibility
- Others เช่น Git, Security, SEO, UX, CSS architecture, Software development life cycle, etc
จุดประสงค์ก็เพื่อให้ทำงานร่วมกับ Framework และ Plguin ตัวอื่นๆได้
- Template tags เช่น
get_header()
,get_footer()
- Template hierarchy
- Localization ช่วยสนันสนุนการทำแปลภาษา เช่น
__( 'Primary Navigation', 'mediumm' )
- Taxonomy
- Child Themes
- The Loop ใช้ในการ display posts
if ( have_posts() ) {
while ( have_posts() ) {
the_post(); ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
<div class="entry">
<?php the_content(); ?>
</div>
<?php
}
} else { ?>
<p>
<?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php
}
function hook_css() { ?>
<style>
.wp_head_example {
background-color : #f1f1f1;
}
</style>
<?php
}
add_action( 'wp_head', 'hook_css' )
Action, เป็นเหมือนทำอะไรสักอย่าง เช่นอันนี้จะเป็นการเพิ่ม <style>
เข้าไปที่ส่วน <head>
function custom_excerpt_more( $more ) {
return 'Read More';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );
เป็นเหมือนกรองหรือเปลี่ยนแปลง อะไรสักอย่าง เช่น อันนี้จะเป็นการเปลี่ยนส่วนของ excerpt (เวลาเนื้อหายาวเกินไปแล้วมักจะมี ... ต่อหลัง ซึ่งอาจจะเปลี่ยนเป็น "อ่านต่อ" หรืออะไรก็แล้วแต่)
- Settings API (Setting page)
- Shortcode มีประโยชน์ในหน้า content editor
- Login WordPress.org
readme.txt
validation, แนะนำให้เขียนละเอียดๆ, ตัวอย่าง readme.txt- Submit
- Wait (manually reviewed)
- Once approved, upload plugin to WordPress SVN
- Misc
- After, upload to SVN, automatically displayed in the plugins browser
- เคยเจอ user run บน PHP 5.4 ทำให้ syntax จากการใช้อาเรย์ (ต้องใช้
array()
แทน[]
) - แนะนำในการทำ zip file ก่อน submit, ตัวอย่าง gulpfile.js
const gulp = require('gulp');
const zip = require('gulp-zip');
const clean = require('gulp-clean');
const fs = require('fs');
const mainFile = 'mourning.php';
const mainFileContent = fs.readFileSync(mainFile, 'utf8');
const pluginVersion = /^Version.*$/igm.exec(mainFileContent)[0].substring(9).trim();
const pluginName = /^Plugin Name.*$/igm.exec(mainFileContent)[0].substring(13).trim().toLowerCase();
const packageFolderName = pluginName + '-' + pluginVersion;
gulp.task('clean', function () {
return gulp.src(pluginName + '-*', {read: false})
.pipe(clean());
});
gulp.task('pack', ['clean'], function () {
return gulp.src([
'css/**',
'image/**',
'mourning.php',
'readme.txt',
'screenshot-1.jpg',
'screenshot-2.jpg'
], {base: '.'})
.pipe(gulp.dest(packageFolderName));
});
gulp.task('pack.zip', ['pack'], function () {
return gulp.src(packageFolderName + '/**')
.pipe(zip(packageFolderName + '.zip'))
.pipe(gulp.dest('./'));
});
- License, GPLv2 or later, ตรวจสอบทุกไฟล์ (code, design, image, etc.)
- Code must be human readable, ป้องกันพวก malicious code เช่น backdoors หรือ tracking
- Trialware is not permitted, ห้าม plugin พวกทดลองใช้
- Upload
- Queue, wait for reviewer
- Reviewer check
- Reviewer create ticket and add add issues
- No 7 days feedback from author, ticket may be closed
- Once approved, reviewer will do the final review
- Reviewer found new issue, reopened ticket
- No issues found, ticket is marked live
- All updates to it from then on are done in the update queue
- Recommended (optional) เช่นพวก
readme.txt
,changelog.txt
- Accessibility (optional), แนวๆพวก web accessibility เช่น
- ควรใช้ header tag ให้ถูกต้อง
- ไม่ควรใช้สีที่หลากหลายเกินไป เพราะจะทำให้คนที่ตาบอดสีเข้าใจเนื้อหาได้ยากขึ้น
- Code
- No PHP or JS notices.
- Provide a unique prefix
- Pass Theme Check
- Core Functionality and Features
- WordPress functionality (if available) เช่น Sidebars, Navigation Menus, Post Thumbnails
- Child theme ready
- 3 major WordPress versions backwards compatible
- Language, Localization ready
- Licensing, 100% GPL-compatible licensed สำหรับทุกไฟล์เช่น code, design, image
- Plugins
- Cannot include plugins
- Cannot require plugins to work
- May use TGM Plugin Activation to recommend plugins
- Others
- Include
comments.php
- Dont block admin bar
- Any custom features, template should be explained
- Documentation, any custom features, template should be explained
- แนะนำการทดสอบ layout ด้วย Theme unit test เช่น Theme Unit Test, WP Test - The Best Tests for WordPress
- Include
เป้าหมายคือผมต้องการให้ได้รับอนุมัติไวๆ และด้วย reviewer เขาก็เป็นอาสาสมัคร ผมจึงคิดว่าถ้าทำ code ให้ อ่านง่าย, ได้มาตรฐาน และเขียนอธิบายละเอียดๆ จะทำให้เขา review ได้ง่าย จึงเกิดเป็นวิธีการซึ่งประกอบไปด้วย 3 หัวข้อหลักนี้
- Web development standards เช่น lint check, code style
- WordPress development standards เช่น เราอยากจะทำอย่างนี้เราต้องใช้อะไร ท่าไหนที่เหมาะสม
- WordPress.org submitting standards คล้ายๆการตรวจสอบและทำเอกสารส่งมอบไปยัง tester, PM, client เพื่อทำการตรวจสอบ
ท้ายนี้ผมเชื่อว่ามีหลายคนที่อยากจะอัพขึ้น WordPress.org แต่บางที ไม่แน่ใจว่า process เป็นยังไง, นานไหม, ต้องทำอะไรบ้าง คราวนี้ก็พอจะทราบกันแล้วว่าไม่ยากและขั้นตอนไม่นาน ก็อยากเชิญชวนให้มาลอง มาช่วยๆกันเยอะๆนะครับ, ขอบคุณครับ
- PHP Code Checker
- WP-CLI
- wp_cron
- ESLint สำหรับ Javascript
- PHP_CodeSniffer สำหรับ WordPress
- WordPress Plugin Boilerplate
- WordPress Plugin Boilerplate Generator
- WordPress Widget Boilerplate
- Underscores | A Starter Theme for WordPress
- Sage | WordPress Starter Theme