Skip to content

Commit

Permalink
upgrade abs plugin base
Browse files Browse the repository at this point in the history
  • Loading branch information
scarstens committed Oct 26, 2021
1 parent 29dcc48 commit 360ae75
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 103 deletions.

This file was deleted.

17 changes: 11 additions & 6 deletions lib/wordpress-phoenix/abstract-plugin-base/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ jobs:
working_directory: ~/repo
steps:
- checkout
- run: sudo chmod 777 -R ~
- run: echo $PWD
- run: ls -lart
- run: env COMPOSER=composer-test.json composer install --prefer-source --no-interaction
- run: sudo ./bin/phpcs --config-set installed_paths $(readlink -f vendor/wp-coding-standards/wpcs/)
- run: env COMPOSER=composer-test.json composer test
- run:
name: Prepare CLI
command: sudo chmod 777 -R ~ ; echo $PWD ; ls -lart ;
- run:
name: Install Testing Dependencies
command: |
composer install --prefer-source --no-interaction
- run:
name: Running Tests
command: |
composer lint:check
notify:
docker:
- image: circleci/node:latest
Expand Down
47 changes: 47 additions & 0 deletions lib/wordpress-phoenix/abstract-plugin-base/.circleci/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0"?>
<ruleset name="wpphx">
<description>phpcs ruleset, based on WordPress Core and VIP standards.</description>

<!-- Exclude specific Composer-related directories from linting. -->
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/lib/index.php</exclude-pattern>
<exclude-pattern>*/lib/autoload.php</exclude-pattern>
<exclude-pattern>*/lib/bin/*</exclude-pattern>
<exclude-pattern>*/lib/composer/*</exclude-pattern>

<!-- Exclude static assets from linting. -->
<exclude-pattern>*/assets/*</exclude-pattern>
<exclude-pattern>*\.(css|js|xml)</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>

<!-- Don't fail in CI if there are warnings. -->
<config name="ignore_warnings_on_exit" value="1" />

<!-- Only worry about WordPress 5.0+. -->
<config name="minimum_supported_wp_version" value="5.0" />

<rule ref="WordPress">
<exclude name="WordPress.WhiteSpace.PrecisionAlignment.Found" />
</rule>

<rule ref="WordPress-Core"></rule>

<rule ref="WordPress-VIP">
<exclude name="WordPress.VIP.SuperGlobalInputUsage" />
<exclude name="WordPress.VIP.RestrictedFunctions.switch_to_blog" />
<exclude name="WordPress.VIP.RestrictedFunctions.get_page_by_title" />
<exclude name="WordPress.VIP.RestrictedFunctions.get_page_by_title_get_page_by_title" />
</rule>

<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>/lib/*</exclude-pattern>
<exclude-pattern>/src/*</exclude-pattern>
</rule>

<!-- Prevent empty lines at the start or end of control structures. -->
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<properties>
<property name="blank_line_check" value="true" />
</properties>
</rule>
</ruleset>
9 changes: 9 additions & 0 deletions lib/wordpress-phoenix/abstract-plugin-base/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_size = 4
indent_style = tab

[*.{json,yml}]
indent_size = 2
indent_style = space
1 change: 1 addition & 0 deletions lib/wordpress-phoenix/abstract-plugin-base/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
vendor/
144 changes: 78 additions & 66 deletions lib/wordpress-phoenix/abstract-plugin-base/README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,121 @@
# Abstract Plugin Base

Used as a base class to help standardize the way we build WordPress plugins.

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

# WordPress Options Builder Class Library

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!
## Table of Contents

## Table of Contents:
- [Installation](#installation)
- [Usage](#usage)
* [Installation](#installation)
* [Usage](#usage)

# Installation
## Installation

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.

## Composer style (recommended)
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`.
2. Set CLI working directory to wp-content/plugins/{your-plugin-name}
3. Install Abstract_Plugin class via composer command line like
```bash
composer require WordPress-Phoenix/abstract-plugin-base && composer install
```
4. Look at sample code below to see how to include this library in your plugin.
### Composer style (recommended)

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/).
2. Set CLI working directory to wp-content/plugins/{your-plugin-name}
3. Install Abstract_Plugin class via composer command line like
```bash
composer require wordpress-phoenix/abstract-plugin-base
```
4. Look at sample code below to see how to include this library in your plugin.

### Manual Installation

1. Download the most updated copy of this repository from `https://api.github.com/repos/WordPress-Phoenix/abstract-plugin-base/zipball`
2. Extract the zip file, and copy the PHP file into your plugin project.
3. Include the file in your plugin.

## Usage

## Manual Installation
1. Download the most updated copy of this repository from `https://api.github.com/repos/WordPress-Phoenix/abstract-plugin-base/zipball`
2. Extract the zip file, and copy the PHP file into your plugin project.
3. Use SSI (Server Side Includes) to include the file into your plugin.
### Why should you use this library when building your plugin?
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.

# Usage
Immediate features include:

## Why should you use this library when building your plugin?
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. Immediate
features include:
- Built in SPL Autoload for your includes folder, should you follow WordPress codex naming standards for class files.
- Template class provides you all the best practices for standard plugin initialization
- Minimizes code needed / maintenance of your main plugin file.
- Assists developers new to WordPress plugin development in file / folder architecture.
- By starting all your plugins with the same architecture, we create a standard that is better for the dev community.
* Built in SPL Autoload for your includes folder, should you follow WordPress codex naming standards for class files.
* Template class provides you all the best practices for standard plugin initialization
* Minimizes code needed / maintenance of your main plugin file.
* Assists developers new to WordPress plugin development in file / folder architecture.
* By starting all your plugins with the same architecture, we create a standard that is better for the dev community.

## Simplest example of the main plugin file, and required plugin class file
### Simplest example of the main plugin file, and required plugin class file

`custom-my-plugin.php`:

custom-my-plugin.php
```php
<?php
/**
* Plugin Name: Custom My Plugin
* Plugin URI: https://github.com/
*/
//avoid direct calls to this file, because now WP core and framework has been used
// Avoid direct calls to this file, because now WP core and framework has been used
if ( ! function_exists( 'add_filter' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
// Create plugin instance on plugins_loaded action to maximize flexibility of wp hooks and filters system.
include_once 'vendor/autoload.php';
include_once 'app/class-my-plugin.php';
Custom\My_Plugin\App::run( __FILE__ );
Custom\My_Plugin\App::run( __FILE__ );
```
app/class-app.php
`app/class-app.php`:
```php
<?php
namespace Custom\My_Plugin;
use WPAZ_Plugin_Base\V_2_5\Abstract_Plugin;
use WPAZ_Plugin_Base\V_2_6\Abstract_Plugin;
/**
* Class App
*/
class App extends Abstract_Plugin {

public static $autoload_class_prefix = __NAMESPACE__;
protected static $current_file = __FILE__;
public static $autoload_type = 'psr-4';
// Set to 2 when you use 2 namespaces in the main app file
public static $autoload_ns_match_depth = 2;

public function onload( $instance ) {
// Nothing yet
} // END public function __construct

public function init() {
do_action( get_called_class() . '_before_init' );
// Do plugin stuff usually looks something like
// $subclass = new OptionalAppSubfolder/Custom_Class_Subclass();
// $subclass->custom_plugin_function();
do_action( get_called_class() . '_after_init' );
}

public function authenticated_init() {
if ( is_user_logged_in() ) {
// Ready for wp-admin - but not required
//$this->admin = new Admin/App( $this );
}
}

protected function defines_and_globals() {
// None yet.
}

} // END class
public static $autoload_class_prefix = __NAMESPACE__;
protected static $current_file = __FILE__;
public static $autoload_type = 'psr-4';
// Set to 2 when you use 2 namespaces in the main app file
public static $autoload_ns_match_depth = 2;
public function onload( $instance ) {
// Nothing yet
}
public function init() {
do_action( static::class . '_before_init' );
// Do plugin stuff usually looks something like
// $subclass = new OptionalAppSubfolder\Custom_Class_Subclass();
// $subclass->custom_plugin_function();
do_action( static::class . '_after_init' );
}
public function authenticated_init() {
if ( ! is_user_logged_in() ) {
return;
}
// Ready for wp-admin - but not required
//$this->admin = new Admin\App( $this );
}
protected function defines_and_globals() {
// None yet.
}
}
```
12 changes: 0 additions & 12 deletions lib/wordpress-phoenix/abstract-plugin-base/composer-test.json

This file was deleted.

23 changes: 19 additions & 4 deletions lib/wordpress-phoenix/abstract-plugin-base/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"name": "wordpress-phoenix/abstract-plugin-base",
"type": "library",
"description": "PHP class to extend when building a WordPress plugin allowing you to follow smart plugin setup standards.",
"keywords": ["wordpress","plugin","abstract","standardize","boilerplate"],
"keywords": [
"wordpress",
"plugin",
"abstract",
"standardize",
"boilerplate"
],
"homepage": "https://github.com/WordPress-Phoenix/abstract-plugin-base",
"license": "GPL-3.0-or-later",
"authors": [
Expand All @@ -13,9 +19,18 @@
"role": "Developer"
}
],
"require-dev": {
"automattic/vipwpcs": "^0.4.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"wp-coding-standards/wpcs": "^1.2.0"
},
"scripts": {
"lint:check": "phpcs --standard=./.circleci/phpcs.xml .",
"lint:fix": "phpcbf --standard=./.circleci/phpcs.xml ."
},
"autoload": {
"classmap": {
"classmap": ["src/abstract-plugin.php"]
}
"classmap": [
"src/abstract-plugin.php"
]
}
}
Loading

0 comments on commit 360ae75

Please sign in to comment.