LoginSignup
2
2

More than 5 years have passed since last update.

Wordpress用フレームワーク「Herbert」プラグイン名の設定

Last updated at Posted at 2016-05-01

はじめに

前回に引き続き,Wordpress用フレームワーク「Herbert」の導入を行っていこう
前記事→Wordpress用フレームワーク「Herbert」を試してみる

環境

ホストOS:Windows 10
ゲストOS:CentOS 6.7
Vagrant(ローカル開発環境)
vccw(Wordpress導入用)
Wordpress 4.5.1–ja
PHP 5.4.45←5.4だと動きませんでした.
==>5.6.21

Getting Started

プラグイン名を指定(Naming your Plugin)

プラグイン名を設定する.合わせてAuthorなどの情報を変えておこう

plugin.php
/**
* @wordpress-plugin
* Plugin Name:       My Plugin ←ここをオリジナルにする
* Plugin URI:        http://plugin-name.com/
* Description:       A plugin.
* Version:           1.0.0
* Author:            Author
* Author URI:        http://author.com/
* License:           MIT
*/

名前空間の指定(Namespacing your Plugin)

他のプラグインやWordPressコアシステムとの競合を避けるため,名前空間を設定する必要がある.

composer.jsonの変更

composer.json内のautoloadと記載された部分を変えていく.
下記において「MyPlugin」と書かれた部分を自作プラグイン名に修正
ただしスペースや括弧は使用禁止とのこと
(サンプルではSocial Icons (pro)→SocialIconsPro)

composer.json
"autoload": {
    "psr-4": {
      "SocialIconsPro\\": "app/"
    }
  }

以上のように修正できたらコマンドラインでcomposer dump-autoloadを実行

Helper.phpの修正

composer dump-autoloadが実行できたら,app/Helper.phpが生成されるだろう.
Helper.phpの一行目にも名前空間を指定しているので修正

app/Helper.php
<?php namespace SocialIconsPro;

herbert.config.phpの修正

最後にherbert.config.php内にあるプラグインも修正しちゃおう
修正箇所は全部で4箇所(検索か置換機能で「MyPlugin」を探すと早い)

herbert.config.php
/**
* The routes to auto-load.
*/
'routes' => [
  'SocialIconsPro' => __DIR__ . '/app/routes.php'
],

/**
* The panels to auto-load.
*/
'panels' => [
  'SocialIconsPro' => __DIR__ . '/app/panels.php'
],

/**
* The APIs to auto-load.
*/
'apis' => [
  'SocialIconsPro' => __DIR__ . '/app/api.php'
],

/**
* The view paths to register.
*
* E.G: 'MyPlugin' => __DIR__ . '/views'
* can be referenced via @MyPlugin/
* when rendering a view in twig.
*/
'views' => [
    'SocialIconsPro' => __DIR__ . '/resources/views'
],

おさらい

各々プラグイン名を考え,各設定ファイルに反映させる地味な作業
ただ,意外と大事であるので漏れなきよう.

  • composer.json
  • Helper.php
  • herbert.config.php

以上3つのファイルを修正した.

今回はここまで
次回はConfig
より詳しい設定ファイルを読み解いていきましょう

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2