A library meant to be imported by the Pro version of WPFactory plugins to manage client product keys.
Installation via Composer. Instructions to setup the composer.json
.
- Add this object to the
repositories
array:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-key-manager"
},
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
]
- Require the library and its dependencies:
"require": {
"wpfactory/wpfactory-key-manager": "*",
"wpfactory/wpfactory-admin-menu": "*"
},
- Use
preferred-install
parameter set asdist
onconfig
.
"config": {
"preferred-install": "dist"
}
Full Example:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-key-manager"
},
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
],
"require": {
"wpfactory/wpfactory-key-manager": "*",
"wpfactory/wpfactory-admin-menu": "*"
},
"config": {
"preferred-install": "dist"
}
}
- Put the composer.json on the pro folder. In general it should be located in
includes/pro
, orsrc/php/pro
. Example:
src/
├── php/
│ ├── pro/
│ │ └── composer.json
└── ...
- Require the Composer
autoload.php
only on the pro version. Example:
require_once plugin_dir_path( $this->get_plugin_file_path() ) . '/src/php/pro/vendor/autoload.php';
- Then initialize the library with
wpfactory_key_manager()
from within the Pro class.
- Probably the best place is inside the hook
plugins_loaded
. If the Pro class is already being loaded with that hook, you can simply load the key manager in the class constructor. - Probably it's a good idea to run it after a
is_admin()
check.
add_action( 'plugins_loaded', function(){
$pro_plugin = new Pro_Plugin();
} );
class Pro_Plugin(){
function __construct() {
// Composer.
require_once plugin_dir_path( $this->get_plugin_file_path() ) . '/src/php/pro/vendor/autoload.php';
// Initializes WPFactory Key Manager library.
if ( is_admin() ) {
function_exists( 'wpfactory_key_manager' ) ? wpfactory_key_manager() : wpf_key_manager();
}
}
}
Note
For compatibility reasons, please check if wpfactory_key_manager()
function exists before calling it. If it does not, call wpf_key_manager()
. Full example: function_exists( 'wpfactory_key_manager' ) ? wpfactory_key_manager() : wpf_key_manager();