Skip to content

Commit b021bd5

Browse files
Update phpcs (#21)
* Rename codesniffer ruleset and use new standard * Delete legacy composer-test * Use new composer.json with dependency lock * Use new commands to run linting * Ignore vendor files * Linting fixes * Enforce tab/spacing rules * Update readme * Incorrectly copied paragraph
1 parent 8c08aa2 commit b021bd5

File tree

10 files changed

+382
-99
lines changed

10 files changed

+382
-99
lines changed

.circleci/codesniffer.ruleset.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ jobs:
77
working_directory: ~/repo
88
steps:
99
- checkout
10-
- run: sudo chmod 777 -R ~
11-
- run: echo $PWD
12-
- run: ls -lart
13-
- run: env COMPOSER=composer-test.json composer install --prefer-source --no-interaction
14-
- run: sudo ./bin/phpcs --config-set installed_paths $(readlink -f vendor/wp-coding-standards/wpcs/)
15-
- run: env COMPOSER=composer-test.json composer test
10+
- run:
11+
name: Prepare CLI
12+
command: sudo chmod 777 -R ~ ; echo $PWD ; ls -lart ;
13+
- run:
14+
name: Install Testing Dependencies
15+
command: |
16+
composer install --prefer-source --no-interaction
17+
- run:
18+
name: Running Tests
19+
command: |
20+
composer lint:check
1621
notify:
1722
docker:
1823
- image: circleci/node:latest

.circleci/phpcs.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="wpphx">
3+
<description>phpcs ruleset, based on WordPress Core and VIP standards.</description>
4+
5+
<!-- Exclude specific Composer-related directories from linting. -->
6+
<exclude-pattern>*/vendor/*</exclude-pattern>
7+
<exclude-pattern>*/lib/index.php</exclude-pattern>
8+
<exclude-pattern>*/lib/autoload.php</exclude-pattern>
9+
<exclude-pattern>*/lib/bin/*</exclude-pattern>
10+
<exclude-pattern>*/lib/composer/*</exclude-pattern>
11+
12+
<!-- Exclude static assets from linting. -->
13+
<exclude-pattern>*/assets/*</exclude-pattern>
14+
<exclude-pattern>*\.(css|js|xml)</exclude-pattern>
15+
<exclude-pattern>*/node_modules/*</exclude-pattern>
16+
17+
<!-- Don't fail in CI if there are warnings. -->
18+
<config name="ignore_warnings_on_exit" value="1" />
19+
20+
<!-- Only worry about WordPress 5.0+. -->
21+
<config name="minimum_supported_wp_version" value="5.0" />
22+
23+
<rule ref="WordPress">
24+
<exclude name="WordPress.WhiteSpace.PrecisionAlignment.Found" />
25+
</rule>
26+
27+
<rule ref="WordPress-Core"></rule>
28+
29+
<rule ref="WordPress-VIP">
30+
<exclude name="WordPress.VIP.SuperGlobalInputUsage" />
31+
<exclude name="WordPress.VIP.RestrictedFunctions.switch_to_blog" />
32+
<exclude name="WordPress.VIP.RestrictedFunctions.get_page_by_title" />
33+
<exclude name="WordPress.VIP.RestrictedFunctions.get_page_by_title_get_page_by_title" />
34+
</rule>
35+
36+
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
37+
<exclude-pattern>/lib/*</exclude-pattern>
38+
<exclude-pattern>/src/*</exclude-pattern>
39+
</rule>
40+
</ruleset>

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_size = 4
5+
indent_style = tab
6+
7+
[*.{json,yml}]
8+
indent_size = 2
9+
indent_style = space

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.idea/
2+
vendor/

README.md

Lines changed: 77 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,121 @@
11
# Abstract Plugin Base
2+
23
Used as a base class to help standardize the way we build WordPress plugins.
34

45
CircleCI Build: [![CircleCI](https://circleci.com/gh/WordPress-Phoenix/abstract-plugin-base.svg?style=svg)](https://circleci.com/gh/WordPress-Phoenix/abstract-plugin-base)
56

6-
# WordPress Options Builder Class Library
7-
8-
WordPress options builder class is a library that helps you setup theme or plugin options that store data in the database with just a line or two of code!
7+
## Table of Contents
98

10-
## Table of Contents:
11-
- [Installation](#installation)
12-
- [Usage](#usage)
9+
* [Installation](#installation)
10+
* [Usage](#usage)
1311

14-
# Installation
12+
## Installation
1513

1614
You can use this library to start a new plugin from scratch, or you can enhance your existing plugins with this library. Once you have read over the installation instructions it should make sense which direction to go.
1715

18-
## Composer style (recommended)
19-
1. Confirm that composer is installed in your development environment using `which composer`. If CLI does not print any path, you need to install composer like `brew install composer`.
20-
2. Set CLI working directory to wp-content/plugins/{your-plugin-name}
21-
3. Install Abstract_Plugin class via composer command line like
22-
```bash
23-
composer require WordPress-Phoenix/abstract-plugin-base && composer install
24-
```
25-
4. Look at sample code below to see how to include this library in your plugin.
16+
### Composer style (recommended)
17+
18+
1. Confirm that composer is installed in your development environment using `which composer`. If CLI does not print any path, you need to [install Composer](https://getcomposer.org/download/).
19+
2. Set CLI working directory to wp-content/plugins/{your-plugin-name}
20+
3. Install Abstract_Plugin class via composer command line like
21+
```bash
22+
composer require wordpress-phoenix/abstract-plugin-base
23+
```
24+
4. Look at sample code below to see how to include this library in your plugin.
25+
26+
### Manual Installation
27+
28+
1. Download the most updated copy of this repository from `https://api.github.com/repos/WordPress-Phoenix/abstract-plugin-base/zipball`
29+
2. Extract the zip file, and copy the PHP file into your plugin project.
30+
3. Include the file in your plugin.
31+
32+
## Usage
2633

27-
## Manual Installation
28-
1. Download the most updated copy of this repository from `https://api.github.com/repos/WordPress-Phoenix/abstract-plugin-base/zipball`
29-
2. Extract the zip file, and copy the PHP file into your plugin project.
30-
3. Use SSI (Server Side Includes) to include the file into your plugin.
34+
### Why should you use this library when building your plugin?
35+
By building your plugin using OOP principals, and extending this Plugin_Base class object, you will be able to quickly and efficiently build your plugin, allowing it to be simple to start, but giving it the ability to grow complex without changing its architecture.
3136

32-
# Usage
37+
Immediate features include:
3338

34-
## Why should you use this library when building your plugin?
35-
By building your plugin using OOP principals, and extending this Plugin_Base class object, you will be able to quickly and efficiently build
36-
your plugin, allowing it to be simple to start, but giving it the ability to grow complex without changing its architecture. Immediate
37-
features include:
38-
- Built in SPL Autoload for your includes folder, should you follow WordPress codex naming standards for class files.
39-
- Template class provides you all the best practices for standard plugin initialization
40-
- Minimizes code needed / maintenance of your main plugin file.
41-
- Assists developers new to WordPress plugin development in file / folder architecture.
42-
- By starting all your plugins with the same architecture, we create a standard that is better for the dev community.
39+
* Built in SPL Autoload for your includes folder, should you follow WordPress codex naming standards for class files.
40+
* Template class provides you all the best practices for standard plugin initialization
41+
* Minimizes code needed / maintenance of your main plugin file.
42+
* Assists developers new to WordPress plugin development in file / folder architecture.
43+
* By starting all your plugins with the same architecture, we create a standard that is better for the dev community.
4344

44-
## Simplest example of the main plugin file, and required plugin class file
45+
### Simplest example of the main plugin file, and required plugin class file
46+
47+
`custom-my-plugin.php`:
4548

46-
custom-my-plugin.php
4749
```php
4850
<?php
4951
/**
5052
* Plugin Name: Custom My Plugin
5153
* Plugin URI: https://github.com/
5254
*/
5355
54-
//avoid direct calls to this file, because now WP core and framework has been used
56+
// Avoid direct calls to this file, because now WP core and framework has been used
5557
if ( ! function_exists( 'add_filter' ) ) {
5658
header( 'Status: 403 Forbidden' );
5759
header( 'HTTP/1.1 403 Forbidden' );
5860
exit();
5961
}
62+
6063
// Create plugin instance on plugins_loaded action to maximize flexibility of wp hooks and filters system.
6164
include_once 'vendor/autoload.php';
6265
include_once 'app/class-my-plugin.php';
63-
Custom\My_Plugin\App::run( __FILE__ );
6466
67+
Custom\My_Plugin\App::run( __FILE__ );
6568
```
6669
67-
app/class-app.php
70+
`app/class-app.php`:
71+
6872
```php
6973
<?php
74+
7075
namespace Custom\My_Plugin;
76+
7177
use WPAZ_Plugin_Base\V_2_6\Abstract_Plugin;
7278
7379
/**
7480
* Class App
7581
*/
7682
class App extends Abstract_Plugin {
77-
78-
public static $autoload_class_prefix = __NAMESPACE__;
79-
protected static $current_file = __FILE__;
80-
public static $autoload_type = 'psr-4';
81-
// Set to 2 when you use 2 namespaces in the main app file
82-
public static $autoload_ns_match_depth = 2;
83-
84-
public function onload( $instance ) {
85-
// Nothing yet
86-
} // END public function __construct
87-
88-
public function init() {
89-
do_action( get_called_class() . '_before_init' );
90-
// Do plugin stuff usually looks something like
91-
// $subclass = new OptionalAppSubfolder/Custom_Class_Subclass();
92-
// $subclass->custom_plugin_function();
93-
do_action( get_called_class() . '_after_init' );
94-
}
95-
96-
public function authenticated_init() {
97-
if ( is_user_logged_in() ) {
98-
// Ready for wp-admin - but not required
99-
//$this->admin = new Admin/App( $this );
100-
}
101-
}
102-
103-
protected function defines_and_globals() {
104-
// None yet.
105-
}
106-
107-
} // END class
10883
84+
public static $autoload_class_prefix = __NAMESPACE__;
85+
86+
protected static $current_file = __FILE__;
87+
88+
public static $autoload_type = 'psr-4';
89+
90+
// Set to 2 when you use 2 namespaces in the main app file
91+
public static $autoload_ns_match_depth = 2;
92+
93+
public function onload( $instance ) {
94+
// Nothing yet
95+
}
96+
97+
public function init() {
98+
do_action( static::class . '_before_init' );
99+
100+
// Do plugin stuff usually looks something like
101+
// $subclass = new OptionalAppSubfolder\Custom_Class_Subclass();
102+
// $subclass->custom_plugin_function();
103+
104+
do_action( static::class . '_after_init' );
105+
}
106+
107+
public function authenticated_init() {
108+
if ( ! is_user_logged_in() ) {
109+
return;
110+
}
111+
112+
// Ready for wp-admin - but not required
113+
//$this->admin = new Admin\App( $this );
114+
}
115+
116+
protected function defines_and_globals() {
117+
// None yet.
118+
}
119+
120+
}
109121
```

composer-test.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

composer.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"name": "wordpress-phoenix/abstract-plugin-base",
33
"type": "library",
44
"description": "PHP class to extend when building a WordPress plugin allowing you to follow smart plugin setup standards.",
5-
"keywords": ["wordpress","plugin","abstract","standardize","boilerplate"],
5+
"keywords": [
6+
"wordpress",
7+
"plugin",
8+
"abstract",
9+
"standardize",
10+
"boilerplate"
11+
],
612
"homepage": "https://github.com/WordPress-Phoenix/abstract-plugin-base",
713
"license": "GPL-3.0-or-later",
814
"authors": [
@@ -13,9 +19,18 @@
1319
"role": "Developer"
1420
}
1521
],
22+
"require-dev": {
23+
"automattic/vipwpcs": "^0.4.0",
24+
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
25+
"wp-coding-standards/wpcs": "^1.2.0"
26+
},
27+
"scripts": {
28+
"lint:check": "phpcs --standard=./.circleci/phpcs.xml .",
29+
"lint:fix": "phpcbf --standard=./.circleci/phpcs.xml ."
30+
},
1631
"autoload": {
17-
"classmap": {
18-
"classmap": ["src/abstract-plugin.php"]
19-
}
32+
"classmap": [
33+
"src/abstract-plugin.php"
34+
]
2035
}
2136
}

0 commit comments

Comments
 (0)