Download the PHP package timelsass/wp-php-version-check without Composer

On this page you can find all versions of the php package timelsass/wp-php-version-check. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-php-version-check

wp-php-version-check

Composer package to verify that WordPress and PHP versions satisfy a minimum version requirement.


Jump To Section


Why?

I haven't really seen any reliable packages that perform this functionality whenever I needed it, so I figured I might as well make my own for future use cases. Most of the ones I found don't deactivate the plugin if the version requirements aren't met, they leave the success admin notice up after activation with the error admin notice, they don't support WP-CLI activation cleanly, and only check either the PHP version or the WordPress version instead of both. A special thank you to Dan Bissonnet's wp-version-check as it was an inspiration for this, but unfortunately hasn't been updated for 3+ years. More than anything though - I wanted to create a package that does what I need, and assume someone else out there might be looking for the same! :)


What does it do?

If an environment does not meet the minimum PHP or WordPress version requirements, the plugin is deactivated and an error admin notice is shown in the admin dashboard. The notice informs the user of the minimum requirements, and their current versions of WordPress and PHP so they can change their environment to satisfy the plugin's version requirements. If the user activates the plugin through WP-CLI then a WP-CLI Warning is displayed informing them of the same information. The plugin is then able to run it's code in the WordPress init hook using the generated hook name, or it call a callable method to run it's initialization code if init is not desirable.


Installation

Using composer, you can get started quickly:


Usage

We aren't going to be using the autoloader for this package because WordPress supports PHP 5.2 as a minimum, and this is just a single class. In your code you would add to your main plugin file after the headers, something like this:

The init method accepts four parameters:

  1. $plugin - The main plugin file relative to the plugins directory. Usually you would use: plugin_basename( __FILE__ ).
  2. $wp_version - The minimum WordPress version required for your plugin to work.
  3. $php_version - The minimum PHP version required for your plugin to work.
  4. $callback - (Optional) A callable method. The format should be like all other callables.
  5. ...$args - (Optional) Any number of arguments to pass to the callable method. $arg1, $arg2, $arg3 etc.

You simply need to initialize the version checking with the necessary parameters, like this:

This will do the version checking portion of things for you, so your next step would be to add a hook telling WordPress what to do to initialize your plugin's actual code.

The hook name is dynamically generated based on $plugin. If you have a plugin called "example-plugin", then the hook generated would be "example-plugin:init".

This code shows how to initalize some code for a plugin called "example-plugin" in an anonymous function (anonymous function passed on a hook requires PHP 5.3+):

It may not be desirable to add your initialization code to the init hook, so an optional parameter, $callback, is provided. The callback expects a callable method to be used, or it will default back to adding the hook to init. The callable format is the same as other WordPress callbacks/callable methods in general, and additional arguments are passed by including them after the callback argument.

This example shows how you would implement a callback with 2 required arguments:


Example

Here's a full example that you can use showing a version check for WordPress 4.0 and PHP 5.6 and running the plugin initialization code on the WordPress init hook:


All versions of wp-php-version-check with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package timelsass/wp-php-version-check contains the following files

Loading the files please wait ....