Giter VIP home page Giter VIP logo

requirements's Introduction

Latest Stable Version Total Downloads Latest Unstable Version

WordPress plugin requirements

A WordPress drop-in to check requirements.

Simple include the underDEV_Requirements.php file in your project or install and load it via Composer:

composer require underdev/requirements

Default checks:

  • PHP version
  • PHP extensions loaded
  • WordPress version
  • Active plugins and their versions
  • Active theme
  • Function collisions
  • Class collisions

You can add also your own custom checks. See the example below.

It doesn't break the user action, such as activating many plugins at once. It will simply display a notice in the admin area:

Requirements in WP Admin

Sample usage

<?php
/*
Plugin Name: My Test Plugin
Version: 1.0
*/

/**
 * If installed by download
 */
require_once( 'underDEV_Requirements.php' );

/**
 * If installed via Composer it's included in the autoloader
 */
require_once( 'vendor/autoload.php' );

$requirements = new underDEV_Requirements( 'My Test Plugin', array(
	'php'                => '5.3',
	'php_extensions'     => array( 'soap' ),
	'wp'                 => '4.8',
	'plugins'            => array(
		'akismet/akismet.php'   => array( 'name' => 'Akismet', 'version' => '3.0' ),
		'hello-dolly/hello.php' => array( 'name' => 'Hello Dolly', 'version' => '1.5' )
	),
	'theme'              => array(
		'slug' => 'twentysixteen',
		'name' => 'Twenty Sixteen'
	),
	'function_collision' => array( 'my_function_name', 'some_other_potential_collision' ),
	'class_collision'    => array( 'My_Test_Plugin', 'My_Test_Plugin_Other_Class' ),
	'custom_check'       => 'thing to check', // this is not default check and will have to be registered
) );

/**
 * Add your own check
 */
function my_plugin_custom_check( $comparsion, $r ) {
	if ( $comparsion != 'thing to check' ) {
		$r->add_error( 'this thing to be that' );
	}
}

$requirements->add_check( 'custom_check', 'my_plugin_custom_check' );

/**
 * Run all the checks and check if requirements has been satisfied
 * If not - display the admin notice and exit from the file
 */
if ( ! $requirements->satisfied() ) {

	add_action( 'admin_notices', array( $requirements, 'notice' ) );
	return;

}

/**
 * Checks passed - load the plugin
 */
new My_Test_Plugin();

requirements's People

Contributors

dmhendricks avatar jakubmikita 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.