| 1 |
<?php |
| 2 |
/* |
| 3 |
* License: GPLv3 |
| 4 |
* License URI: https://www.gnu.org/licenses/gpl.txt |
| 5 |
* Copyright 2014-2026 Jean-Sebastien Morisset (https://surniaulula.com/) |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
|
| 10 |
die( 'These aren\'t the droids you\'re looking for.' ); |
| 11 |
} |
| 12 |
|
| 13 |
if ( ! class_exists( 'SucomAbstractAddOn' ) ) { |
| 14 |
|
| 15 |
require_once dirname( __FILE__ ) . '/com/add-on.php'; // SucomAbstractAddOn class. |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! class_exists( 'WpssoAbstractAddOn' ) ) { |
| 19 |
|
| 20 |
abstract class WpssoAbstractAddOn extends SucomAbstractAddOn { |
| 21 |
|
| 22 |
protected $p; // Wpsso class object. |
| 23 |
protected $ext = ''; // Add-on lowercase classname. |
| 24 |
protected $p_ext = ''; // Add-on lowercase acronym. |
| 25 |
protected $cf = array(); // Add-on config array. |
| 26 |
|
| 27 |
public $reg; // Add-on register class object. |
| 28 |
|
| 29 |
/* |
| 30 |
* Called from the child class as parent::__construct( __FILE__, __CLASS__ ). |
| 31 |
*/ |
| 32 |
public function __construct( $plugin_file, $classname ) { |
| 33 |
|
| 34 |
$plugin_dir = trailingslashit( dirname( $plugin_file ) ); |
| 35 |
$config_class = $classname . 'Config'; |
| 36 |
$register_class = $classname . 'Register'; |
| 37 |
$this->ext = strtolower( $classname ); |
| 38 |
$this->p_ext = str_replace( 'wpsso', '', $this->ext ); |
| 39 |
|
| 40 |
require_once $plugin_dir . '/lib/config.php'; |
| 41 |
|
| 42 |
$config_class::set_constants( $plugin_file ); |
| 43 |
$config_class::require_libs( $plugin_file ); // Includes the register.php class library. |
| 44 |
|
| 45 |
$this->cf =& $config_class::$cf; |
| 46 |
|
| 47 |
$this->reg = new $register_class(); // Activate, deactivate, uninstall hooks. |
| 48 |
|
| 49 |
$this->add_hooks( $plugin_file ); |
| 50 |
} |
| 51 |
|
| 52 |
protected function add_hooks( $plugin_file ) { |
| 53 |
|
| 54 |
/* |
| 55 |
* WPSSO filter hooks. |
| 56 |
*/ |
| 57 |
add_filter( 'wpsso_get_config', array( $this, 'get_config' ), 10, 1 ); |
| 58 |
|
| 59 |
add_filter( 'wpsso_get_avail', array( $this, 'get_avail' ), 10, 1 ); |
| 60 |
|
| 61 |
/* |
| 62 |
* WPSSO action hooks. |
| 63 |
*/ |
| 64 |
foreach ( array( |
| 65 |
'init_textdomain' => 0, |
| 66 |
'init_objects_preloader' => 0, |
| 67 |
'init_objects' => 0, |
| 68 |
'init_check_options' => 0, |
| 69 |
) as $method => $args_num ) { |
| 70 |
|
| 71 |
if ( method_exists( $this, $method ) ) { |
| 72 |
|
| 73 |
add_action( 'wpsso_' . $method, array( $this, $method ), 10, $args_num ); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
/* |
| 78 |
* The SucomAbstractAddOn->init_plugin_notices() method adds toolbar notices for any missing requirements. |
| 79 |
*/ |
| 80 |
add_action( 'wpsso_init_plugin', array( $this, 'init_plugin_notices' ), 100, 0 ); |
| 81 |
|
| 82 |
/* |
| 83 |
* If SucomAbstractAddOn->init_plugin_notices() is not executed, then show any missing requirements using |
| 84 |
* the standard WordPress admin notices action. |
| 85 |
*/ |
| 86 |
add_action( 'all_admin_notices', array( $this, 'show_admin_notices' ), 100, 0 ); |
| 87 |
|
| 88 |
/* |
| 89 |
* Declare compatibility with WooCommerce features. |
| 90 |
*/ |
| 91 |
if ( ! empty( $this->cf[ 'plugin' ][ $this->ext ][ 'wc_compat' ] ) ) { |
| 92 |
|
| 93 |
$wc_compat = $this->cf[ 'plugin' ][ $this->ext ][ 'wc_compat' ]; |
| 94 |
|
| 95 |
add_action( 'before_woocommerce_init', function () use ( $plugin_file, $wc_compat ) { |
| 96 |
|
| 97 |
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 98 |
|
| 99 |
foreach ( $wc_compat as $feature ) { |
| 100 |
|
| 101 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( $feature, $plugin_file, true ); |
| 102 |
} |
| 103 |
} |
| 104 |
}, 10, 0 ); |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|