Coder Social home page Coder Social logo

base-plugin's Introduction

Base Plugin

The beginnings of a Wordpress plugin. Please delete this README (after you have read it) and replace with the details of your plugin.

Dependency Container

This base plugin uses the Pimple dependency container. It's very simple and very powerful. Check it out.

To add a new service simply register a closure function against the $plugin variable.

$plugin['example'] = function ( $c ) {
	return new BasePlugin\Example( $c['service_or_variable_available_in_the_container'] );
};

If the registered class has a method called init, that method will be called after instantiation. This is where you would add your Wordpress hooks and filters.

public function init() {
    add_action( 'init', [ $this, 'doSomethingAwesome' ] );
}

Logging

The plugin includes the monolog logging package. To use call the static class with the matching log severity level method:

BasePlugin\Log::info("New user added.", ['extra_information' => 'the something that was done']);
BasePlugin\Log::emergency("It's all on fire, get out!", ['fire_started' => '10:00:00', 'death_toll' => 'unknown']);

See Monolog for more information.

Updater action

As Wordpress doesn't have a default way to handle when a plugin is updated this base plugin includes its own work around.

One of the default services listens for changes in the plugin version number stored against the $plugin['plugin_option_name'] and triggers an action with the title of $plugin['plugin_option_name'] followed by _updated.

eg. when 'BasePlugin_details' is updated the action 'BasePlugin_details_updated' will be called.

Furthermore the action is passed the new version number.

Testing

The initial setup for testing your plugin is included in the base plugin.

Simply add your tests in the Tests directory and run phpunit in the root directory.

base-plugin's People

Contributors

binarykitten avatar laverboy avatar

Watchers

 avatar

Forkers

binarykitten

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.