| 1 |
<?php |
| 2 |
/** |
| 3 |
* Cross_Sell class. |
| 4 |
* |
| 5 |
* @package WP_Defender\Component |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Component; |
| 9 |
|
| 10 |
use Calotes\Base\Component; |
| 11 |
use WP_Defender\Behavior\WPMUDEV; |
| 12 |
|
| 13 |
/** |
| 14 |
* Handles the functionality related to the Cross-Sell module. |
| 15 |
* |
| 16 |
* @since 5.2.1 |
| 17 |
*/ |
| 18 |
class Cross_Sell extends Component { |
| 19 |
|
| 20 |
/** |
| 21 |
* Checks if the Cross-Sell should render its UI. |
| 22 |
* |
| 23 |
* Should load only for a free version and non-hosted sites. |
| 24 |
* |
| 25 |
* @return bool |
| 26 |
*/ |
| 27 |
protected function should_render(): bool { |
| 28 |
return defender_is_wp_org_version() && ! wd_di()->get( WPMUDEV::class )->is_wpmu_hosting(); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Initialize the Cross-Sell module and set its options. |
| 33 |
* |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
public function init() { |
| 37 |
$cross_sell_path = defender_path( 'extra/plugins-cross-sell-page/plugin-cross-sell.php' ); |
| 38 |
if ( ! $this->should_render() || ! file_exists( $cross_sell_path ) ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
static $cross_sell = null; |
| 43 |
if ( is_null( $cross_sell ) ) { |
| 44 |
if ( ! class_exists( '\WPMUDEV\Modules\Plugin_Cross_Sell' ) ) { |
| 45 |
require_once $cross_sell_path; |
| 46 |
} |
| 47 |
|
| 48 |
$submenu_params = array( |
| 49 |
'slug' => 'defender-security', // Required. |
| 50 |
'parent_slug' => 'wp-defender', // Required. |
| 51 |
'menu_slug' => 'defender_cross_sell', // Optional - Strongly recommended to set in order to avoid admin page conflicts with other WPMU DEV plugins. |
| 52 |
'position' => 17, // Optional – Usually a specific position will be required. |
| 53 |
'translation_dir' => defender_path( 'languages' ), // Optional – The directory where the translation files are located. |
| 54 |
); |
| 55 |
$cross_sell = new \WPMUDEV\Modules\Plugin_Cross_Sell( $submenu_params ); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|