Giter VIP home page Giter VIP logo

wp-dependencies's Introduction

WP Dependencies

A composer package for WordPress to autoload plugin dependencies.

Usage

For Themes and Plugins

Require the Dependencies and WP Dependencies Package

Add a reference to wp-dependencies to your theme's or plugin's composer.json along with any other plugins that need to be active.

{
    "name": "my-account/my-theme",
    "type": "wordpress-theme",
    "authors": [
        {
            "name": "John Doe",
            "email": "[email protected]"
        }
    ],
    "repositories": [
        {
            "type": "composer",
            "url" : "http://wp-plugins.packagist.voceconnect.com/"
        },
        ...
    ],
    "config": {
    	"vendor-dir": "vendor"
    },
    "require": {
        "voceconnect/wp-dependencies": "~0.1",
        "wpackagist/thermal-api: "~0.7"
        ...
    }
}

Add Composer's Autoload

For WordPress Projects

Because of the way WordPress loads, it is suggested that the mu-plugins directory be set as the vendor. This allows Composer's autoload.php to be loaded automatically after WordPress' plugin API has already been setup.

{
    ...
    "config": {
        "vendor-dir": "wp-content/mu-plugins"
    },
    ...
}

For WordPress Themes or Plugins

Include Composer's autoload.php in the theme's functions.php or in your plugin's main file. The below example assume's the plugin's or theme's vendor-dir setting composer.json is set to vendor.

// bootstrap composer autoload for dependencies
if(file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php' ) ) {
	include_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php' );
}

Load Dependencies

For dependencies or plugins that do not autoload through composer, you will need to load the dependency through one of two ways.

do_action( 'wp_load_dependency', 'some-plugin-name', 'main-plugin-file.php');

or

if (function_exists('wp_load_dependency')) {
	 wp_load_dependency('some-plugin-name', 'main-plugin-file.php');
}

The former action based loading is preferred as it provides more flexibility for future iterations.

wp-dependencies's People

Contributors

kevinlangleyjr avatar

Stargazers

Kevyworks avatar Goran Šerić avatar Kernel Jackson avatar Christian Foellmann avatar Nicolas Lemoine avatar

Watchers

Chris Scott avatar James Cloos avatar Nicolas Lemoine avatar  avatar

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.