A library designed for WPFactory plugins, aimed at cross-selling by offering WPFactory product recommendations
Installation via Composer. Instructions to setup the composer.json
.
- Add these objects to the
repositories
array:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-cross-selling"
},
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
]
- Require the library and its dependencies:
"require": {
"wpfactory/wpfactory-cross-selling": "*",
"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-cross-selling"
},
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
],
"require": {
"wpfactory/wpfactory-cross-selling": "*",
"wpfactory/wpfactory-admin-menu": "*"
},
"config": {
"preferred-install": "dist"
}
}
-
Create/Put the composer.json on the root folder.
-
Then initialize the library with
new \WPFactory\WPFactory_Cross_Selling\WPFactory_Cross_Selling()
from within the main plugin class. Probably the best place is inside the hookplugins_loaded
. If the main class is already being loaded with that hook, you can simply load the library in the class constructor.
Note
Try to remember to only run it inside a is_admin()
check.
Example:
add_action( 'plugins_loaded', function(){
$main_plugin_class = new Main_Plugin_Class();
} );
class Main_Plugin_Class(){
function __construct() {
$this->init_cross_selling_library();
}
function init_cross_selling_library(){
if ( ! is_admin() ) {
return;
}
// Composer.
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
// Initializes WPFactory Key Manager library.
$cross_selling = new \WPFactory\WPFactory_Cross_Selling\WPFactory_Cross_Selling();
$cross_selling->setup( array( 'plugin_file_path' => __FILE__ ) );
$cross_selling->init()
}
}
Setups the library.
Parameters:
plugin_file_path
(string) - Plugin file path.plugin_action_link
(array)enabled
(boolean) - Enables/Disabled the plugin action link. Default value:true
.label
(string) - Label for the plugin action link. Default value:'Recommendations'
.
Initializes the library.
$cross_selling = new \WPFactory\WPFactory_Cross_Selling\WPFactory_Cross_Selling();
$cross_selling->setup( array(
'plugin_file_path' => $this->get_filesystem_path(),
'plugin_action_link' => array(
'enabled' => true,
'label' => 'More plugins'
),
) );
$cross_selling->init();