Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed docs, naming, missing gettext template, base path/url methods. #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# WordPress Plugin Yeoman Generator
With this Yeoman Generator, it is possible to easily scaffolding a WordPress plugin
With this Yeoman Generator, it is possible to easily scaffold a WordPress plugin
following the netzstrategen coding standards.

## Installation
- `npm install -g yo`
- `npm install -g generator-netz-wordpress-plugin`
```
$ npm install -g yo generator-netz-wordpress-plugin
```

## Use
- `yo netz-wordpress-plugin`
## Usage
```
$ cd wp-content/plugins
$ mkdir custom
$ cd custom
$ yo netz-wordpress-plugin
```
The files are generated in the current working directory.

## Features
- The generated plugin can optionally have assets. In that case, [gulp-task-collection](https://github.com/netzstrategen/gulp-task-collection)
NPM package is installed. Also, netzstrategen ESLint and Stylelint standards are included.
- It's possible to automatically create frequently used PHP Classes (e.g. `Admin`, `WooCommerce`, `CliCommand`).
- A Travis configuration file is automatically generated. It makes the plugin ready to be tested.
- If the generated plugin supports assets, the [gulp-task-collection](https://github.com/netzstrategen/gulp-task-collection)
package is installed and the netzstrategen ESLint and Stylelint rules are included.
- Frequently used PHP classes can be automatically created (e.g. `Admin`, `WooCommerce`, `CliCommand`).
- The automatically genereated Travis configuration file makes the plugin ready to be tested.
8 changes: 7 additions & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = yeoman.generators.Base.extend({
function camelize (string) {
return string.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
return word.toUpperCase();
}).replace(/\s+/g, '');
}).replace(/\s+_-/g, '');
}
this.namespace = camelize(answers.name);
}.bind(this));
Expand Down Expand Up @@ -220,6 +220,12 @@ module.exports = yeoman.generators.Base.extend({
includeAdmin: this.includeAdmin
}
);
this.fs.copyTpl(
this.templatePath('languages/_plugin.pot'),
this.destinationPath('languages/' + this.props.name.replace(/\s+/g, '-').toLowerCase() + '.pot'), {
name: this.props.name.replace(/\s+/g, '-').toLowerCase()
}
);
this.fs.copyTpl(
this.templatePath('src/_Plugin.php'),
this.destinationPath('src/Plugin.php'), {
Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/_plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function classloader($class) {
register_uninstall_hook(__FILE__, __NAMESPACE__ . '\Schema::uninstall');

add_action('plugins_loaded', __NAMESPACE__ . '\Plugin::loadTextdomain');
add_action('init', __NAMESPACE__ . '\Plugin::init', 20);
add_action('init', __NAMESPACE__ . '\Plugin::init');
<% if (includeAdmin) { %>add_action('admin_init', __NAMESPACE__ . '\Admin::init');<% } %><% if (includeAdmin) { %>

if (defined('WP_CLI') && WP_CLI) {
Expand Down
17 changes: 17 additions & 0 deletions generators/app/templates/languages/_plugin.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: <%= name %>\n"
"POT-Creation-Date: 2010-02-10 09:00+0200\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.2.1\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_ex:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: .sass-cache\n"
"X-Poedit-SearchPathExcluded-1: node_modules\n"
"X-Poedit-SearchPathExcluded-2: vendor\n"
1 change: 0 additions & 1 deletion generators/app/templates/src/_Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Admin {
* @implements admin_init
*/
public static function init() {

}

}
6 changes: 4 additions & 2 deletions generators/app/templates/src/_CliCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

namespace Netzstrategen\<%= namespace %>;

use WP_CLI_Command;

/**
* WP CLI commands.
* WP-CLI commands.
*/
class CliCommand {
class CliCommand extends WP_CLI_Command {


}
26 changes: 26 additions & 0 deletions generators/app/templates/src/_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Plugin {
*/
const L10N = self::PREFIX;

/**
* @var string
*/
private static $baseUrl;

/**
* Plugin initialization method.
*
Expand All @@ -44,4 +49,25 @@ public static function loadTextdomain() {
load_plugin_textdomain(static::L10N, FALSE, static::L10N . '/languages/');
}

/**
* The absolute filesystem base path of this plugin.
*
* @return string
*/
public static function getBasePath() {
return dirname(__DIR__);
}

/**
* The base URL path to this plugin's folder.
*
* Uses plugins_url() instead of plugin_dir_url() to avoid a trailing slash.
*/
public static function getBaseUrl() {
if (!isset(static::$baseUrl)) {
static::$baseUrl = plugins_url('', static::getBasePath() . '/plugin.php');
}
return static::$baseUrl;
}

}