Giter Site home page Giter Site logo

plugin-scaffold's Introduction

10up Plugin Scaffold

DEPRECATED. Use https://github.com/10up/wp-scaffold

At 10up, we strive to provide digital products that yield a top-notch user experience. In order to improve both our efficiency and consistency, we need to standardize what we use and how we use it. This plugin scaffold allows us to share initial set up procedures to make sure all projects can get up and running as quickly as possible while closely adhering to 10up's high quality standards.

Support Level GPL-2.0-or-later License

Dependencies

  1. Node >= 8.11 & NPM - Build packages and 3rd party dependencies are managed through NPM, so you will need that installed globally.
  2. Webpack - Webpack is used to process the JavaScript, CSS, and other assets.
  3. Composer - Composer is used to manage PHP.

Getting Started

Quick Start

Install 10up's command line tool for scaffolding new projects. You can download it from the Project Scaffold repository. Setting up a new plugin is as easy as running create-10up plugin plugin-name-here in the terminal!

Browsersync requires a local development URL. This is currently set in the package.json, as proxyUrl.

Direct Install

  • Clone the repository
  • Rename folder plugin-scaffold -> your project's name
  • If copying files manually to an existing plugin directory instead of cloning directly from the repository, make sure to include the following files which may be hidden:
.babelrc
.browserslistrc
.editorconfig
.eslintignore
.eslintrc
.gitignore

The NPM commands will fail without these files present.

  • Do case-sensitive search/replace for the following:

    • TenUpScaffold
    • TENUP_SCAFFOLD
    • tenup-scaffold
    • tenup_scaffold
  • cd into the plugin folder

  • run npm run start to build the front-end assets

Webpack config

Webpack config files can be found in config folder:

  • webpack.config.dev.js
  • webpack.config.common.js
  • webpack.config.prod.js
  • webpack.settings.js

In most cases webpack.settings.js is the main file which would change from project to project. For example adding or removing entry points for JS and CSS.

NPM Commands

  • npm run test (runs phpunit)
  • npm run start (install dependencies)
  • npm run watch (watch)
  • npm run build (build all files)
  • npm run build-release (build all files for release)
  • npm run dev (build all files for development)
  • npm run lint-release (install dependencies and run linting)
  • npm run lint-css (lint CSS)
  • npm run lint-js (lint JS)
  • npm run lint-php (lint PHP)
  • npm run lint (run all lints)
  • npm run format-js (format JS using eslint)
  • npm run format (alias for npm run format-js)
  • npm run test-a11y (run accessibility tests)

Composer Commands

composer lint (lint PHP files)

composer lint-fix (lint PHP files and automatically correct coding standard violations)

Contributing

We don't know everything! We welcome pull requests and spirited, but respectful, debates. Please contribute via pull requests on GitHub.

  1. Fork it!
  2. Create your feature branch: git checkout -b feature/my-new-feature
  3. Commit your changes: git commit -am 'Added some great feature!'
  4. Push to the branch: git push origin feature/my-new-feature
  5. Submit a pull request

Learn more about the default packages used with this project

Frequently Asked Questions

A question that someone might have

An answer to that question.

WordPress Admin Dashboard

Support Level

Active: 10up is actively working on this, and we expect to continue work for the foreseeable future including keeping tested up to the most recent version of WordPress. Bug reports, feature requests, questions, and pull requests are welcome.

Like what you see?

Work with 10up, we create amazing websites and tools that make content management simple and fun using open source tools and platforms

plugin-scaffold's People

Contributors

aaemnnosttv avatar barryceelen avatar behzod avatar cmmarslender avatar colorful-tones avatar debabratakarfa avatar dependabot[bot] avatar firestorm980 avatar jaredrethman avatar jeffpaul avatar jodiwarren avatar joesnellpdx avatar jonathantneal avatar kopepasah avatar moraleida avatar nicholasio avatar oscarssanchezz avatar s3rgiosan avatar saltcod avatar samikeijonen avatar smy315 avatar timwright12 avatar tlovett1 avatar tylercherpak 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  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

plugin-scaffold's Issues

Import CSS

Hello,

I'm trying to use your plugin with Full Calendar JS (https://fullcalendar.io)

I'm following this guide : https://fullcalendar.io/docs/initialize-es6

For javascript part it's ok.

But for CSS, i have problem :

In admin.js, I add the following code :

import '@fullcalendar/core/main.css';
import '@fullcalendar/daygrid/main.css';

And I have this error :

ERROR in ./node_modules/@fullcalendar/core/main.css 1:0
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
> @charset "UTF-8";
| .fc {
|   direction: ltr;
 @ ./assets/js/admin/admin.js 2:0-37

ERROR in ./node_modules/@fullcalendar/daygrid/main.css 4:0
Module parse failed: Unexpected token (4:0)
You may need an appropriate loader to handle this file type.
| --------------------------------------------------------------------------------------------------*/
| /* day row structure */
> .fc-dayGridWeek-view .fc-content-skeleton,
| .fc-dayGridDay-view .fc-content-skeleton {
|   /* there may be week numbers in these views, so no padding-top */
 @ ./assets/js/admin/admin.js 3:0-40

Do I need to do something ? I need to add a config ?

Thanks.

Missing path constant

Hi,

I noticed that in a recent commit (Port Webpack to the plugin) the path returned by the script_url() function in the core.php file is missing the TENUP_SCAFFOLD_URL prefix, which will prevent the scripts from being loaded.

return "dist/js/${script}.js";

Addind back the TENUP_SCAFFOLD_URL prefix fixed the issue. I hope this could be helpful and that I didn't miss anything in the webpack config.

Cryptic errors when get_enqueue_contexts 'fails'

Describe the bug
If you modify the array that the get_enqueue_contexts method returns, a new WP_Error object is created and returned when performing the in_array check in several methods. This causes a somewhat cryptic error being thrown as at that point you are attempting to enqueue a script or stylesheet with a WP_Error object as the style/script path string.

Steps to Reproduce

  1. Clone the repo
  2. Run npm run-script start, yarn start, etc.
  3. Remove admin from return [ 'admin', 'frontend', 'shared' ]; on line 86 of core.php
  4. Activate the plugin

Expected behavior
Display a WordPress warning/error on the back-end with the messages passed to the WP_Error constructors.

Screenshots

Catchable fatal error: Object of class WP_Error could not be converted to string in /var/www/html/wp-includes/http.php on line 681 
...

Deprecated WP_Mock calls

dave@DESKTOP-BT7RIFJ /mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test (master) $ vendor/bin/phpunit
PHPUnit 6.5.7 by Sebastian Bergmann and contributors.

.R.RR                                                               5 / 5 (100%)

Time: 3.03 seconds, Memory: 10.00MB

There were 3 risky tests:

1) TenUp\GeneratorTest\Core\Core_Tests::test_i18n
Deprecated WP Mock calls inside :
  WP_Mock::wpFunction ["get_locale","Array([3] ...)"]
                      ["load_textdomain","Array([2] ...)"]
                      ["plugin_basename","Array([3] ...)"]
                      ["load_plugin_textdomain","Array([2] ...)"]

/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/vendor/10up/wp_mock/php/WP_Mock/DeprecatedListener.php:33
/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/vendor/10up/wp_mock/php/WP_Mock/Tools/TestCase.php:314
/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/vendor/10up/wp_mock/php/WP_Mock/Tools/TestCase.php:307
/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/tests/phpunit/test-tools/TestCase.php:13

2) TenUp\GeneratorTest\Core\Core_Tests::test_activate
Deprecated WP Mock calls inside :
  WP_Mock::wpFunction ["flush_rewrite_rules","Array([1] ...)"]

/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/vendor/10up/wp_mock/php/WP_Mock/DeprecatedListener.php:33
/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/vendor/10up/wp_mock/php/WP_Mock/Tools/TestCase.php:314
/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/vendor/10up/wp_mock/php/WP_Mock/Tools/TestCase.php:307
/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/tests/phpunit/test-tools/TestCase.php:13

3) TenUp\GeneratorTest\Core\Core_Tests::test_deactivate
This test did not perform any assertions

/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/vendor/10up/wp_mock/php/WP_Mock/Tools/TestCase.php:307
/mnt/c/Users/dave/Code/wp-local-docker/wordpress/wp-content/plugins/generator-test/tests/phpunit/test-tools/TestCase.php:13

OK, but incomplete, skipped, or risky tests!
Tests: 5, Assertions: 4, Risky: 3.

Fatal Error: Cannot redeclare style_url() within mce_css()

PHP is throwing a fatal error on L:227 of functions/core.php when mce_css filter is being run. On the post edit screen for example.

Steps to reproduce

  1. Scaffold a new plugin: create-10up plugin my-fancy-plugin
  2. Activate the plugin: wp plugin activate my-fancy-plugin
  3. Attempt to create a new post or page.

Environment

  • WP 4.9.5
  • PHP 7.2.1
  • Chrome

Front-end styles in a plugin?

I'm probably missing something but why are we using front-end styles like normalize.css from the plugin? For all use cases I can think of these should be in a theme only.

Clean Up the Root

With the new webpack conversion we have a /config directory set up. Any config files, linting, processing, etc that can be moved out of the root and into the /config directory should be to clean up the root of the project.

Related theme issue: 10up/theme-scaffold#137

Examples of autoloading and namespacing classes?

The example composer.json has

"autoload": { "psr-4": { "TenUpScaffold\\": "includes/classes/" } }

But then there is no example inside the includes/classes/ folder of how to namespace different classes, nor differet example namespaces in the composer.json file, and have them all autoloaded with psr-4.

Would it be possible to include a simple example of how to include classes under different namespaces like, eg,

TenUpScaffold\ClassOne, TenUpScaffold\AnotherClass, TenUpScaffold\AnotherOne\Helper ?

Would be great to see in the sample class how it is initialized, etc.

Thank you for your scaffold repos!

Using error_log in production

We are using error log to indicate when trying to load a script or style with a context that is not recognized. Usually, error_log would be flagged in a code review as not belonging in production.

I am wondering the reasoning behind this decision and wondering if there is not another way to indicate this as this will only be used during development and only appear if adding another context or typoing the existing ones.

Understanding the above, that this won't be fired in production, I am wondering if we should wrap this in a WP_DEBUG check with a comment for any engineers using this as a learning resource.

Add header fields to plugin.php and readme.txt files

Is your enhancement related to a problem? Please describe.
The WordPress.org plugin headers and readme.txt standards appear to have evolved a bit and our scaffold files should likely include some additional fields.

Describe the solution you'd like

  • add Requires PHP, License, License URI to readme.txt
  • add sample FAQ question+answer to readme.txt as the .org format is not intuitive
  • add 10up logo as a sample for banner, icon, and screenshot to avoid null view on .org
  • add 10up sample screenshot to readme.txt as the .org format is not intuitive
  • add Requires at least, Requires PHP, License, License URI to plugin.php

Designs

n/a

Describe alternatives you've considered

Maybe we consider the fuller list of PHPDoc DoclBlock's as noted here as well?: https://developer.wordpress.org/plugins/plugin-basics/header-requirements/#header-fields

Additional context

Plugin Readmes: https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/
Header Requirements: https://developer.wordpress.org/plugins/plugin-basics/header-requirements/

Standardize the enqueue contexts

Keeping the script and style enqueue contexts inside of the helper methods used to generate the URL requires updating code in multiple places when adding a new item. This can be simplified by adding a helper function.

readme updates

It's not obvious the level of support provided for this repo, so let's add some clarification.

  • add support level section and badge
  • add license file and badge

Error Activating Plugin

Noting this here for later review (i.e. so I can close this browser tab):

`( ! ) Fatal error: Uncaught Error: Call to undefined function TenUp\GeneratorTest\Core\setup() in /var/www/html/wp-content/plugins/generator-test/plugin.php on line 28
( ! ) Error: Call to undefined function TenUp\GeneratorTest\Core\setup() in /var/www/html/wp-content/plugins/generator-test/plugin.php on line 28
Call Stack

Time Memory Function Location

1 0.0069 481480 {main}( ) .../plugins.php:0
2 3.8195 22619264 plugin_sandbox_scrape( ) .../plugins.php:172
3 3.8238 22623408 include( '/var/www/html/wp-content/plugins/generator-test/plugin.php' ) .../plugin.php:1897
`

NPM install: found 705 vulnerabilities (692 low, 13 high)

When I run npm install, I get this message:

found 705 vulnerabilities (692 low, 13 high)
  run `npm audit fix` to fix them, or `npm audit` for details

Is your enhancement related to a problem? Please describe.

Describe the solution you'd like

update packages.

Designs

Describe alternatives you've considered

Additional context

I use windows 10 pro.
nvm using node v.12.17.0

SVGs are cropped upon deployment

Describe the bug
When npm run build is run, SVGs have their "viewbox" attribute removed which causes cropping:

image

This is caused in plugin-scaffold/config/webpack.config.common.js. ImageminPlugin can be updated to this to correct it:

		// Compress images
		// Must happen after CopyWebpackPlugin
		new ImageminPlugin({
			disable: !isProduction,
			test: settings.ImageminPlugin.test,
			svgo: {
				plugins: [
					{
						removeViewBox: false,
					},
				],
			},
		}),

Steps to Reproduce

  1. If you site has SVGs, run npm run build to see the cropping
  2. npm run watch does not include the cropping because ImageminPlugin is disabled on non-production environments,.

Expected behavior
No cropping

Add static analysis

Is your enhancement related to a problem? Please describe.
Many problems in the PHP code could not be discovered by humans.

Describe the solution you'd like
Introduce @phpstan (as Automattic and Google already did)

Describe alternatives you've considered
There is no better static analysis then PHPStan.

Additional context
It needs a WordPress Extension.

composer.lock should not be in .gitignore

composer.lock file should be committed to our projects so that when we deploy them, we can run composer install and get a very specific set of package versions installed.

I could see maybe not wanting a composer.lock file in the scaffold repo, but we definitely want it in the repos that are generated as part of the scaffolding.

Fatal error in post editor

Action:

Edit a page in wp-admin

Expected:

No php errors

Instead:

I see this error:

Fatal error: Cannot redeclare Facebook\Elearning\Plugin\Core\style_url() 
(previously declared in /srv/www/fbelearning/public_html/wp-content/plugins/fb-elearning/includes/functions/core.php:115) 
in /srv/www/fbelearning/public_html/wp-content/plugins/fb-elearning/includes/functions/core.php 
on line 261

core.php contains these two snippets:

https://github.com/10up/plugin-scaffold/blob/master/includes/functions/core.php#L98

function style_url( $stylesheet, $context ) {
	if( !in_array( $context, ['admin', 'frontend', 'shared'], true) ) {
		error_log('Invalid $context specfied in TenUpScaffold stylesheet loader.');
		return '';
	}
	return ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ?
		TENUP_SCAFFOLD_URL . "assets/css/${context}/{$stylesheet}.css" :
		TENUP_SCAFFOLD_URL . "dist/css/${stylesheet}.min.css" ;
}

https://github.com/10up/plugin-scaffold/blob/master/includes/functions/core.php#L225

function mce_css( $stylesheets ) {

	function style_url() {

		return FB_ELEARNING_PLUGIN_URL . ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ?
			"assets/css/frontend/editor-style.css" :
			"dist/css/editor-style.min.css" );

	}

	return $stylesheets . ',' . style_url();
}

Suggested fix

Possibly the second instance of style_url() should be an anonymous function?

PHPUnit test not working

Getting this error

Fatal error: Declaration of WP_Mock\Tools\TestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp():

Add assets for WordPress.org deployment via GitHub Actions

Is your enhancement related to a problem? Please describe.
We are seeing increased usage of our GitHub Actions for deploying plugins to WordPress.org, and with the GA for Actions slated for mid-November and this being a “template” repo, I think it makes sense to go ahead and add what’s necessary for GitHub Actions to this repo so we’re ready from the jump. See 10up/action-wordpress-plugin-deploy#11 as well.

Describe the solution you'd like
Add .github/workflows/tag-deploy.yml, .github/workflows/asset-readme-update.yml, .distignore, and .wordpress-org/README.md. The last one should contain the image types, sizes, and naming that WordPress.org looks for, which I think makes more sense than bundling images that might unwittingly be deployed and avoids the empty directory in Git issue.

Designs
n/a

Describe alternatives you've considered
n/a

Additional context
I will work on a PR here within the next couple weeks unless somebody else wants to claim it first.

Require vendor/autoload by default

After playing around with the plugin scaffold a little bit, and asking Darshan for some insight, it became apparent that using require_once 'vendor/autoload.php'; is detrimental to autoloading classes. This ticket may just be a lack of experience from my side, but is there any reason why the requiring of autoload.php is not added to the plugin architecture by default?

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.