Need help with wp-dependency-installer?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

afragen
135 Stars 17 Forks MIT License 320 Commits 2 Opened issues

Description

A lightweight class to add to WordPress plugins/themes to automatically install plugin dependencies.

Services available

!
?

Need anything else?

Contributors list

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( '

[%2$s] %3$s

%4$s
', 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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.