Giter Site home page Giter Site logo

webdevstudios / generator-plugin-wp Goto Github PK

View Code? Open in Web Editor NEW
289.0 48.0 65.0 543 KB

Yeoman WordPress Plugin Generator

License: GNU General Public License v3.0

JavaScript 56.31% CSS 0.11% PHP 38.53% Shell 5.05%
wordpress wordpress-plugin yeoman generator

generator-plugin-wp's Introduction

generator-plugin-wp buddy pipeline

Yeoman generator for WordPress plugins.

WebDevStudios. WordPress for big brands.

Getting Started

Pre-requisites: You'll need node which comes with npm.

If you don't have Yeoman installed:

npm install -g yo

To install generator-plugin-wp from npm, run:

npm install -g generator-plugin-wp

To use generator-plugin-wp, cd to your WordPress plugins folder and:

yo plugin-wp

You'll be prompted with steps for creating your plugin.

Sub-generators

Once your nifty new plugin has been generated, cd into your new plugin's directory. While in the plugin directory, you can run additional commands called sub-generators to automatically generate files to enhance your plugin.

For the names of the include, cpt, options, and widget subgenerators remember that the plugin prefix will be added to the class name so no need to include the original plugin name there. Think of it as the file name for each instead.

Tests

By default the plugin generator adds some built in tests for you to add on to as you develop your plugin. To run these tests run the install-wp-tests.sh script in the bin folder with the proper database details for your local setup.

Once you've run the install-wp-tests.sh script you can run just phpunit in the main folder of your plugin.

If you don't want tests included in your plugin when it is generated run the main generator with the --notests option.

PHP 5.2

By default PHP 5.2 is not supported in the generated plugin. To generate a plugin with PHP 5.2 support, run the main generator with the --php52 option.

CMB2

CMB2 is included by default with the options sub-generator. It can also be a useful tool with CPT and taxonomy sub-generators using the --cmb2 flag.

Adding Packages with Composer

If you chose composer as the autoloader option during the plugin's initiation, you can use composer to add additional dependencies.

Let's cd into our new plugin's directory and add CMB2:

composer require cmb2/cmb2

CMB2 will now appear under vendor

-plugins
  -wds-foo-plugin
    -vendor
      -cmb2
        -cmb2

Contributors

The following humans contributed to this awesome generator:

CamdenSegal, jtsternberg, jazzsequence, binarygary, bradp, JeffreyNaval, gregrickaby, DevNIX, JPry, RC Lations, tnorthcutt, aubreypwd, JeffMatson

generator-plugin-wp's People

Contributors

asharirfan avatar aubreypwd avatar binarygary avatar blobaugh avatar bradp avatar camdensegal avatar daveromsey avatar devnix avatar gregrickaby avatar jazzsequence avatar jeffmatson avatar jeffreynaval avatar jpry avatar jtsternberg avatar kellenmace avatar phatsk avatar rclations avatar theericdevelops avatar tnorthcutt avatar websupergirl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

generator-plugin-wp's Issues

Add PageBuilder Support

Would be amazing to have auto-generating Page Builder support!

Camden wrote a pretty spiff plugin for a client today, which had well organized PB support (with custom fields even!). Would like to see this standardized going forward.

yo plugin-wp:page-builder

Translate custom post types is not possible

The constructor of the custom post type class is called before the plugin text domain is loaded. So it's impossible to translate the singular and plural of the CTP.
A solution whould be to load the plugin text domain in the plugin constructor instead in the init event.

Descriptions with "quotes" will break includes and throw errors

npm ERR! install Couldn't read dependencies
npm ERR! Darwin 14.3.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! file /Users/jazzsequence/vagrant-local/www/roadkill/htdocs/wp-content/plugins/roadkill-featured-articles/package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token 'e' at 5:73
npm ERR! escription": "A simple plugin that allows various post types to be "featured"."
npm ERR!                                                                      ^
npm ERR! File: /Users/jazzsequence/vagrant-local/www/roadkill/htdocs/wp-content/plugins/roadkill-featured-articles/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/jazzsequence/vagrant-local/www/roadkill/htdocs/wp-content/plugins/roadkill-featured-articles/npm-debug.log
bower EMALFORMED    Failed to read /Users/jazzsequence/vagrant-local/www/roadkill/htdocs/wp-content/plugins/roadkill-featured-articles/bower.json

Additional error details:
Unexpected token f

plugin is actually generated at this point, but trying to include additional classes or running other subgenerators will throw an error and fail:

 yo plugin-wp:include cmb
undefined:3
escription": "A simple plugin that allows various post types to be "featured".
                                                                    ^
SyntaxError: Unexpected token f
    at Object.parse (native)
    at EditionInterface.module.exports [as readJSON] (/Users/jazzsequence/.node/lib/node_modules/generator-plugin-wp/node_modules/yeoman-generator/node_modules/mem-fs-editor/actions/read-json.js:5:17)
    at Base.determineAppname (/Users/jazzsequence/.node/lib/node_modules/generator-plugin-wp/node_modules/yeoman-generator/lib/base.js:735:25)
    at Base (/Users/jazzsequence/.node/lib/node_modules/generator-plugin-wp/node_modules/yeoman-generator/lib/base.js:150:23)
    at new module.exports.base.extend.constructor (/Users/jazzsequence/.node/lib/node_modules/generator-plugin-wp/include/index.js:8:28)
    at Environment.instantiate (/Users/jazzsequence/.node/lib/node_modules/yo/node_modules/yeoman-environment/lib/environment.js:282:10)
    at Environment.create (/Users/jazzsequence/.node/lib/node_modules/yo/node_modules/yeoman-environment/lib/environment.js:259:15)
    at Environment.run (/Users/jazzsequence/.node/lib/node_modules/yo/node_modules/yeoman-environment/lib/environment.js:318:24)
    at /Users/jazzsequence/.node/lib/node_modules/yo/lib/cli.js:99:9
    at Environment.resolver.lookup (/Users/jazzsequence/.node/lib/node_modules/yo/node_modules/yeoman-environment/lib/resolver.js:50:12)

Error plugin-wp:taxonomy test-taxonomy

Error plugin-wp:taxonomy test-taxonomy 

You don't seem to have a generator with the name plugin-wp:taxonomy installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 7 registered generators run yo with the `--help` option.

w00t. I've double checked that I'm using the 0.15.0 version :(

Gulp version?

Could be possible to generate a Gulp version of this project instead of Grunt?

Travis

Looks like Travis was set up for this repo when it was on your Github account, @CamdenSegal.

Fatal error upon activating plugin

I'm receiving a fatal error upon activating the plugin. There is an undefined variable $instance being used in __construct. I changed it to $this. Not sure if you were meaning to call these methods differently.

screen shot 2015-05-01 at 1 24 17 pm

register_activation_hook can't be called in plugins_loaded

Hi and thanks for this generator.
I've found and issue tough. In the Wordpress documentation they say that register_activation_hook can't be called in plugins_loaded which is what you do in fact it is not called. I guess register_activation_hook and register_deactivation_hook can be moved in the __construct function? At least that's what I did.

js sub generator yields undefined.js file

See below image:

When running the sub generator with the Basic setup ( just uglify ) the file it creates is undefined.js and does not follow the task that is created when it edits the gruntfile.

plugin_classes() loaded before check_requirements()

Hey, I'm really loving this generator. One thing I've noticed: the plugin_classes method is run in the constructor. I wonder if it would make more sense to run this from the init method, after check_requirements is run. If anyone really needs to hook earlier than init they still could manually, but right now the generator defaults to instantiating all includes before the requirements are checked.

Use new class naming standards

Currently the include subgenerator(s) and autoloader assume your include files are named file-name.php but our current coding standards recommend classes should be named class-file-name.php. Subgenerators need to be updated to correct class- prefixed include files and the autoloader needs to be updated to support file name change when the file name and the class name don't necessarily match, e.g.: file name: class-options.php, class name: WDS_Prefix_Options.

CPT Init didn't work because of init

Add to the main final class priority zero to the init action to avoid problems with CPT init.

add_action( 'init', array( $this, 'init' ), 0 );

Make an autoloader prompt

Add an additional prompt which asks the user if they want to use an Autoloder. The choices would be composer, php, or no autoloader

Limit CPT name from CPT generator to 20 characters

CPTs can only be 20 characters or else you'll get an error. The generator appends the plugin slug to the CPT name which can very easily get over 20 characters. Perhaps the plugin slug shouldn't be added and maybe there could be a check to see if what the user enters is 20 characters or less.

load_textdomain does not need to be used

the load_textdomain function does not need to e used here: https://github.com/WebDevStudios/generator-plugin-wp/blob/master/app/templates/plugin.php#L146

If we are trying to use language pack files, load_plugin_textdomain will be able to do that. See Otto's article here: http://ottopress.com/2013/language-packs-101-prepwork/

If you want to use language packs exclusively (note: WP will still check the base /wp-content/plugins directory for language files, just in case):

Text Domain: plugin-slug
load_plugin_textdomain( 'plugin-slug' );

I submitted a plugin to the repo using the generator, and although Mika said none of this will prevent the plugin from being accepted she wanted to let me know about it. She also mentioned in the area where we are using load_textdomain, it should not be using hard coded folders, as someone's weird setup may not have what we expect.

Include Sub-Generator - Automatically Appending to __get()

This can become quite large on some projects. I mean do we really need 20+ magic get properties? Maybe consider making this an option during the creation process in the sub generator, or remove it entirely and rely upon the dev to do this if he/she needs to.

Example Scenario:
b045680249877877e19280cf5cd5cf98

Include Sub-Generator - Lacking Parental Reference ( Docblock )

When we create an include class, the doc-block on the newly created class $plugin property is improper.

    /**
     * Parent plugin class
     *
     * @var   class
     * @since NEXT
     */
    protected $plugin = null;

Is it possible to get the main plugin's class and replace class with the right class?

Class extending WP_REST_Controller: Cannot call constructor

This happened to me using the yo plugin-wp:endpoint generator, the generated file seems to have some kind of problem.

I have to remove the parent::__construct(); line because it seems like WP_REST_Controller does not have a defined constructor.

/**
 * Constructor
 *
 * @since  NEXT
 * @param  object $plugin Main plugin object.
 * @return void
 */
public function __construct( $plugin ) {
    parent::__construct();
    $this->plugin = $plugin;
}

When generating frontend.php, it generates "undefinedFrontend" as the class name

I feel like this should take on the name of my plugin? Or at least ask me what I want to name it?

<?php
/**
 * undefined Frontend
 * @version 2.0
 * @package 
 */

class undefinedFrontend {
    /**
     * Parent plugin class
     * @var class
     */
    protected $plugin = null;

    /**
     * Constructor
     * @since 2.0
     */
    public function __construct( $plugin ) {
        $this->plugin = $plugin;
        $this->hooks();
    }

    /**
     * Initiate our hooks
     * @since 2.0
     */
    public function hooks() {
    }
}

Based on new developments, we should use TGMPA to bring in CMB2

Based on developments here and here, I think we should avoid using composer or directly including CMB2 bundled into the plugin and instead depend on TGM Plugin Activation.

The TLDR of the links above:

  • New frameworks are no longer allowed in the repo. CMB2 will be allowed to stay however.
  • since CMB2 will be staying in the repo, other plugins cannot bundle it within their own plugins (to be accepted to the WP plugin repo), because plugins are not (any longer) allowed to bundle other plugins that exist in the repo.
  • As such, the recommended practice is to require the plugin via TGMPA.

I didn't create a PR yet because I want to make sure we're all on the same page, and hear any feedback.

Update readme

Items to cover:

  • CD to plugins dir, the yo generator creates its own plugin folder
  • Document the generator prompts
  • Has additional sub-generators
    • Need to document each and parameters they accept
    • Document the prompts for them
  • Update documentation about composer.. move to a sub-section. Composer will no longer be an automatic-add

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.