Git Product home page Git Product logo

wp-dependency-installer's Introduction

WP Dependency Installer

This is a drop in class for developers to optionally or automatically install plugin dependencies for their own plugins or themes. It can install a plugin from wp.org, GitHub, Bitbucket, GitLab, Gitea, or a direct URL.

Comprehensive information regarding WP Dependency Installer is available on the wiki.

See also: example plugin.

Description

You can use composer to install this package within your WordPress plugin / theme.

  1. Within your plugin or theme root folder, run the following command:
composer require afragen/wp-dependency-installer
  1. Then create a sample wp-dependencies.json file
[
  {
    "name": "GitHub Updater",
    "host": "github",
    "slug": "github-updater/github-updater.php",
    "uri": "afragen/github-updater",
    "branch": "develop",
    "required": true,
    "token": null
  },
  {
    "name": "Query Monitor",
    "host": "wordpress",
    "slug": "query-monitor/query-monitor.php",
    "uri": "https://wordpress.org/plugins/query-monitor/",
    "optional": true
  },
  {
    "name": "Local Development",
    "host": "WordPress",
    "slug": "local-development/local-development.php",
    "uri": "https://wordpress.org/plugins/local-development/",
    "required": true
  }
]

You will then need to update wp-dependencies.json to suit your requirements.

  1. Finally add the following lines to your plugin or theme's functions.php file:
require_once __DIR__ . '/vendor/autoload.php';
WP_Dependency_Installer::instance( __DIR__ )->run();

// Needed in theme's functions.php file.
add_filter( 'pand_theme_loader', '__return_true' );
  1. (optional) Take a look at some of built in Hooks and Functions to further customize your plugin look and behaviour:
/**
 * Display your plugin or theme name in dismissable notices.
 */
add_filter(
  'wp_dependency_dismiss_label',
  function( $label, $source ) {
    $label = basename( __DIR__ ) !== $source ? $label : __( 'Group Plugin Installer', 'group-plugin-installer' );
    return $label;
  }, 10, 2
);
  1. Sanity Check
// Sanity check for WPDI v3.0.0.
if ( ! method_exists( 'WP_Dependency_Installer', 'json_file_decode' ) ) {
 add_action(
   'admin_notices',
   function() {
     $class   = 'notice notice-error is-dismissible';
     $label   = __( 'Your Plugin Name', 'your-plugin' );
     $file    = ( new ReflectionClass( 'WP_Dependency_Installer' ) )->getFilename();
     $message = __( 'Another theme or plugin is using a previous version of the WP Dependency Installer library, please update this file and try again:', 'group-plugin-installer' );
     printf( '<div class="%1$s"><p><strong>[%2$s]</strong> %3$s</p><pre>%4$s</pre></div>', esc_attr( $class ), esc_html( $label ), esc_html( $message ), esc_html( $file ) );
   },
   1
 );
 return false; // Exit early.
}

That's it, happy blogging!

Development

PRs are welcome against the develop branch.

wp-dependency-installer's People

Contributors

afragen avatar raruto avatar sc0ttkclark avatar paulgoodchild 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.