[WordPress] 外掛分享: Plugin Builder

WordPress 外掛 Plugin Builder 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Plugin Builder」是 2014-10-04 上架。
  • 目前有 20 個安裝啟用數。
  • 上一次更新是 2015-04-20,距離現在已有 3667 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 3.0.1 以上版本才可以安裝。
  • 尚未有人給過這款外掛評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

mrwiblog |

外掛標籤

boilerplate | development |

內容簡介

這是一個針對 WordPress 外掛開發人員的外掛。如果你不了解 PHP、HTML、CSS、add_action 和 apply_filters 是什麼,那麼這個外掛並不適合你!

WordPress 外掛範本 Boilerplate 是一個很棒的工具,可以標準化 WordPress 外掛並鼓勵開發人員採用最佳實踐。但手動編輯每個檔案,輸入外掛名稱、作者名稱和所有其他元數據,有點煩人。這個外掛自動化了這個過程,提供一個簡單的表單讓你輸入元數據,當你點擊「建立」按鈕時,你的新外掛將會帶有所有正確的元數據。

但這還不夠。你還可以定義自訂文章類型和甚至其他自訂類別,自動建立 .php 檔案,以及所有相關的程式碼,以把這些檔案納入你的外掛中。一旦你建立了你的外掛,當然可以編輯這些檔案以添加額外的方法。

如果你想要,外掛建立工具甚至會為你的自訂文章類型創建一個管理員類別,作為儲存與你的 CPT 相關方法的地方 – 例如一個 get_all() 方法。

還有更多。一些開發人員喜歡在他們的外掛中包含額外的項目,例如實用程式類別或框架,例如 WordPress 設定框架。外掛建立工具也自動化這個過程,透過下載和包含你所選擇的檔案在你的新外掛中。

外掛建立工具配備了一系列這些附加包含項目,你可以選擇使用它們,但如果有其他項目你想要包含,你可以很容易地把它們變成建立流程的一部分(透過擴展一個簡單的介面和使用過濾器)。

因此,讓我們來看看使用 WordPress 外掛範本來創建一個新外掛的傳統方法:

下載 Boilerplate 並解壓縮它
使用你的外掛名稱重新命名所有檔案(例如,把 ‘class-plugin-name.php’ 改為 ‘class-my-plugin.php’)
搜尋所有檔案,並用你的外掛詳細資訊(名稱、slug、作者、連結等)替換元數據
建立你的 CPT 類別和註冊碼
新增代碼以包含 CPT 檔案和在 WordPress 中註冊 CPT
創建一個自訂類別
新增代碼以包含你的自訂類別檔案
下載你最喜愛的實用程式檔案到你的外掛資料夾
新增代碼以在你的外掛中包含你的實用程式檔案

或者,使用外掛建立工具:

輸入你的外掛詳細資訊(名稱和描述 – slug 和類別名稱會自動建立)
輸入你的自訂文章類型詳細資訊(名稱和描述、是否要建立管理員類別)
輸入你的自訂類別詳細資訊(名稱和描述)
勾選你想要包含的任何實用程式檔案
按下「建立」

我猜想,外掛建立工具可以節省你 2-4 小時的工作時間,並讓你的外掛在架構上更加標準化。

當你的外掛建立完成後,它的設定將被儲存,以便你可以隨時重新建立你的外掛(這會覆蓋你手動做出的任何更改),或進行一些更改並創建一個新的外掛。

可選包含項目

外掛建立工具中可選的包含項目包括:

WordPress 設定框架

WordPress 設定框架 旨在減少設定頁面所需的程式碼。

原文外掛簡介

This is a plugin for WordPress plugin developers. If you don’t understand what PHP, HTML, CSS, add_action and apply_filters are then this plugin is not for you!
The WordPress Plugin Boilerplate is a fantastic tool for standardising WordPress plugins, and encouraging developers to use best practices. But manual editing of every file to enter the name of the plugin, the author name and all the other metadata is a bit of a chore. This plugin automates that process, giving you a simple form to enter your metadata, then when you hit the ‘Build’ button your new plugin is created with all the correct metadata.
But there’s more. You can also define Custom Post Types and even other custom classes which will have .php files created automatically, and all the relevant code to include those files in your plugin. Once your plugin is built you can, of course, edit the files in any way you want to add extra methods.
Plugin Builder will even create a manager class for your Custom Post Types if you want, as a place to store methods related to your CPTs – such as a get_all() method, for example.
And that’s not all. Some developers like to include extra items in their plugins, like utility classes or frameworks such as the WordPress Settings Framework. Plugin Builder automates that process, too, by downloading and including the files you choose in your new plugin.
Plugin Builder comes with a range of these additional includes you can choose from, but if there are other items you want to include you can make those part of the build process really easily (by extending a simple interface and using a filter).
So, let’s look at the traditional way of using the WordPress Plugin Boilerplate to create a new plugin:

Download the Boilerplate and extract it
Rename all the files using your plugin name (e.g. ‘class-plugin-name.php’ to ‘class-my-plugin.php’)
Go through all the files and replace the metadata with your plugin details (name, slug, author, URIs etc)
Create your CPT class and the registration code,
Add the code to include the CPT file and register the CPT with WordPress
Create a custom class
Add the code to include your custom class file
Download your favourite utility files to your plugin folder
Add the code to include your utility files in your plugin

Or, using Plugin Builder:

Enter the details of your plugin (name and description – the slug and class name are automatically created)
Enter the details of your Custom Post Type (name and description, whether you want a manager class creating)
Enter the details of your custom class (name and description)
Check the box next to any utility files you want to be included
Press ‘Build’

My guess is Plugin Builder will save you 2-4 hours work, and make your plugins much more standard in their architecture.
When your plugin is built the settings for it will be saved so you can rebuild your plugin at any time (this will overwrite any changes you’ve made manually) or make a few changes and create a new plugin.
Optional includes
The optional includes available in Plugin Builder are:
WordPress Settings Framework
The WordPress Settings Framework aims to take the pain out of creating settings pages for your WordPress plugins by effectively creating a wrapper around the WordPress settings API and making it super simple to create and maintain settings pages.
util.php
util.php is a collection of useful functions and snippets that you need or could use every day, designed to avoid conflicts with existing projects.
Expect more includes to be bundled with future versions of Plugin Builder. If you have an idea for an include you want and you think it may be useful for other developers let me know. Or, add your own include (see the next section for details).
Adding your own includes
Adding your own includes to Plugin Builder is really easy. There’s an interface named Plugin_Builder_Include which you need to extend, it has a few methods that need to be implemented. Then you add a call to a method in your include class for the plugin_builder_includes filter. Here’s a simple example:
class My_Include implements Plugin_Builder_Include {

/**
* The method run when the user has selected this include.
*
* @since 1.0.0
* @var Plugin_Builder_Settings $settings The settings for the plugin being built.
*/
public function process_include( $settings ) {

// This is where you would do the work for your include; downloading files and saving them locally,
// creating folders, adding settings etc.

// Returns 'true' if your processing succeeds, and a string detailing the error if it fails.

// We ALWAYS use the WordPress Filesystem API for file operations, see this for details: https://codex.wordpress.org/Filesystem_API
global $wp_filesystem;
if ( ! isset( $wp_filesystem ) || null == $wp_filesystem ) {
return false;
}

// get the file we want to include in the new plugin from a local folder
// Note: it's tempting to get your files from somewhere on the Internet (such as Github or your own site) but
// this would be against the WordPress Plugin Guidelines: https://wordpress.org/plugins/about/guidelines/
// Also you can't include your files in a Zip or other archive, they have to be diff-able (i.e. text-based) files.
$cache_file = PLUGIN_BUILDER_DIR . 'cache/my-include.php';

// copy the file to the build folder
$wp_filesystem->copy( $cache_file, $settings->build_path . 'includes/my-include.php' );

return true;

}

/**
* Returns any code to be injected into the top of the load_dependencies() method.
*
* @since 1.0.0
*/
public function get_dependencies_code() {

// Be careful here: you're writing PHP code as a string to be injected into a .php file, so it must be valid.

return "
/**
* My Include
*
* My Include is an example include for the Plugin Builder plugin.
*
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/my-include.php';
";

}

/**
* Returns the unique slug for this include.
*
* @since 1.0.0
*/
public function get_slug(){

return 'my-include';

}

/**
* Returns the translated title for this include.
*
* @since 1.0.0
*/
public function get_title() {

return __( 'My Include' );

}

/**
* Returns the translated description (HTML allowed) for this include.
*
* @since 1.0.0
*/
public function get_description() {

return __( '

My Include is an example include for the Plugin Builder plugin.

' );

}

/**
* Returns the URL giving more information on this include.
*
* @since 1.0.0
*/
public function get_info_url() {

return 'https://some-website.com/my-include/';

}

/**
* The method that will be called when the add_includes filter runs.
*
* @since 1.0.0
* @var array $includes The array of includes.
*/
public function add_includes( $includes ) {

return $includes;

}

}

// add this include to Plugin Builder using the plugin_builder_includes filter
$my_include = new My_Include();
add_filter( 'plugin_builder_includes', array( $my_include, 'add_include' ) );

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Plugin Builder」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


最新版本

延伸相關外掛(你可能也想知道)

  • HTML5 Boilerplate 》站在巨人肩膀上(也就是 Paul Irish 和 Divya Manian,和他們所帶領的偉大同仁們,共同打造並推廣 HTML5 Boilerplate),我為大家呈現我第一個 WordPress 插...。
  • Simple Shortcodes 》Simple Shortcodes 提供了一個簡單易用的機制,用來創建和使用自訂短碼。, 安裝並啟用 Simple Shortcodes 後,會在您的設置菜單中新增一個 Simple Shortcodes...。
  • WP Boilerplate Shortcode 》這個外掛提供一個短碼,可顯示來自連結至特殊文章類型的「範本」的內容。「範本」是由此外掛定義的一個特殊文章類型。可以根據標題、路徑或 ID 來進行連結。...。
  • Skeletonisr 》這個外掛會將你的佈景主題與 Skeleton Responsive Framework 結合在一起,讓你不需要自己手動整合。。
  • ImgTurk 》WordPress 外掛 ImgTurk 可讓你在 WordPress 網站上查看 Instagram 上的任何非私人標籤或使用者檔案。它旨在簡潔且非常易於使用;您甚至不需要在 Instagram ...。
  • Ajax the metaboxes 》這是一個給開發人員使用的樣板外掛,旨在提供 WordPress metaboxes 的易於使用的 AJAX 存取方法。啟用外掛後,管理員用戶將會在 metabox 中注意到兩個名為「A...。

文章
Filter
Apply Filters
Mastodon