app
5 months ago
assets
5 months ago
core
5 months ago
languages
5 months ago
vendor
5 months ago
plugin-cross-sell.php
5 months ago
plugin-cross-sell.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WPMUDEV Plugin Cross-Sell module for free plugins. |
| 4 | * |
| 5 | * Used in free plugins to get a glimpse of other plugins offered by WPMU DEV. |
| 6 | * |
| 7 | * @version 1.1.0 |
| 8 | * @author Panos Lyrakis |
| 9 | * @link https://wpmudev.com |
| 10 | * @package WPMUDEV\Plugin_Cross_Sell |
| 11 | */ |
| 12 | |
| 13 | namespace WPMUDEV\Modules; |
| 14 | |
| 15 | // If this file is called directly, abort. |
| 16 | if ( ! defined( 'WPINC' ) ) { |
| 17 | die; |
| 18 | } |
| 19 | |
| 20 | // Support for site-level autoloading. |
| 21 | if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 22 | require_once __DIR__ . '/vendor/autoload.php'; |
| 23 | } |
| 24 | |
| 25 | // Sub-module version. |
| 26 | if ( ! defined( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_VERSION' ) ) { |
| 27 | define( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_VERSION', '1.1.0' ); |
| 28 | } |
| 29 | |
| 30 | // Sub-module directory. |
| 31 | if ( ! defined( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_DIR' ) ) { |
| 32 | define( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_DIR', plugin_dir_path( __FILE__ ) ); |
| 33 | } |
| 34 | |
| 35 | // Sub-module url. |
| 36 | if ( ! defined( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_URL' ) ) { |
| 37 | define( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_URL', plugin_dir_url( __FILE__ ) ); |
| 38 | } |
| 39 | |
| 40 | // Sub-module Assets url. |
| 41 | if ( ! defined( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_ASSETS_URL' ) ) { |
| 42 | define( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_ASSETS_URL', untrailingslashit( WPMUDEV_MODULE_PLUGIN_CROSS_SELL_URL ) . '/assets' ); |
| 43 | } |
| 44 | |
| 45 | // Shared UI Version. |
| 46 | if ( ! defined( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_SUI_VERSION' ) ) { |
| 47 | define( 'WPMUDEV_MODULE_PLUGIN_CROSS_SELL_SUI_VERSION', '2.12.24' ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Sub-module Cross-Sell class. |
| 52 | * |
| 53 | * @since 1.0.0 |
| 54 | */ |
| 55 | if ( ! class_exists( 'WPMUDEV\Modules\Plugin_Cross_Sell' ) ) { |
| 56 | /** |
| 57 | * Module main class. |
| 58 | */ |
| 59 | final class Plugin_Cross_Sell { |
| 60 | /** |
| 61 | * The DI container. |
| 62 | * |
| 63 | * @var Plugin_Cross_Sell\Container |
| 64 | */ |
| 65 | private $container = null; |
| 66 | |
| 67 | /** |
| 68 | * Initialize the module. |
| 69 | * |
| 70 | * @param array $props Module properties. |
| 71 | * @since 1.0.0 |
| 72 | * |
| 73 | * @return void |
| 74 | */ |
| 75 | public function __construct( array $props = array() ) { |
| 76 | // Prepare the translation directory. |
| 77 | $dir = ! empty( $props['translation_dir'] ) ? realpath( $props['translation_dir'] ) : false; |
| 78 | $props['translation_dir'] = $dir ? wp_normalize_path( $dir ) : WPMUDEV_MODULE_PLUGIN_CROSS_SELL_DIR . 'languages/'; |
| 79 | |
| 80 | // Self-initialization of DI container. |
| 81 | $this->container = new Plugin_Cross_Sell\Container(); |
| 82 | $this->container->set( 'submenu_data', $props ); |
| 83 | $this->container->set( 'utilities', new Plugin_Cross_Sell\Utilities() ); |
| 84 | |
| 85 | $this->load(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Class initializer. |
| 90 | */ |
| 91 | public function load(): void { |
| 92 | $submenu_params = $this->container->get( 'submenu_data' ); |
| 93 | $translation_dir = ! empty( $submenu_params['translation_dir'] ) ? $submenu_params['translation_dir'] : WPMUDEV_MODULE_PLUGIN_CROSS_SELL_DIR . 'languages/'; |
| 94 | |
| 95 | load_plugin_textdomain( |
| 96 | 'plugin-cross-sell-textdomain', |
| 97 | false, |
| 98 | $translation_dir |
| 99 | ); |
| 100 | |
| 101 | // Create a new Loader instance and pass the DI container. |
| 102 | $loader = new Plugin_Cross_Sell\Loader( $this->container ); |
| 103 | $loader->init(); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 |