PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / classes / abstract-addon.php

abstract-addon.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/classes/abstract-addon.php

104 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstract Addon
4 *
5 * @version 1.0.0
6 * @since StoreEngine 0.0.4
7 */
8
9 namespace StoreEngine\Classes;
10
11 use StoreEngine\Interfaces\AddonInterface;
12 use StoreEngine\Utils\Helper;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 abstract class AbstractAddon implements AddonInterface {
19
20 /**
21 * Addon Name.
22 * Unique name for the addon. This will be used for identifying & loading the addon,
23 * and triggering its action & filter hooks.
24 *
25 * @var string
26 */
27 protected string $addon_name;
28
29 /**
30 * Trigger Initialization hooks.
31 */
32 protected function __construct() {
33 }
34
35 protected bool $running = false;
36
37 final public function run() {
38 if ( $this->running ) {
39 return;
40 }
41
42 $this->running = true;
43
44 if ( ! $this->addon_name ) {
45 $class = get_class( $this );
46 /* translators: %s: Addon abstraction class, usually a class extending AbstractAddon. */
47 _doing_it_wrong( esc_html( $class ), sprintf( esc_html__( '%s must redeclare addon_name property.', 'storeengine' ), esc_html( $class ) ), '0.0.4' );
48
49 return;
50 }
51
52 $this->define_constants();
53
54 add_action( "storeengine/addons/activated_{$this->addon_name}", [ $this, 'addon_activation_hook' ] );
55 add_action( "storeengine/addons/deactivated_{$this->addon_name}", [ $this, 'addon_deactivation_hook' ] );
56
57 // If disable then stop running addons
58 if ( ! Helper::get_addon_active_status( $this->addon_name ) ) {
59 return;
60 }
61
62 $this->init_addon();
63
64 /**
65 * Fires after specific addon loaded.
66 */
67 do_action( "storeengine/addons/$this->addon_name/loaded" );
68 }
69
70 public function addon_activation_hook() {
71 }
72
73 public function addon_deactivation_hook() {
74 }
75
76 /**
77 * Addons with their own tables override this to return a version string.
78 * Empty string means "no tables" — the central manager skips this addon.
79 */
80 public function get_db_version(): string {
81 return '';
82 }
83
84 /**
85 * Addons with their own tables override this to run their dbDelta calls.
86 */
87 public function install_tables(): void {
88 }
89
90 /**
91 * Cloning is forbidden.
92 */
93 public function __clone() {
94 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'storeengine' ), '0.0.4' );
95 }
96
97 /**
98 * Unserializing instances of this class is forbidden.
99 */
100 public function __wakeup() {
101 _doing_it_wrong( __FUNCTION__, esc_html__( 'Unserializing instances of this class is forbidden.', 'storeengine' ), '0.0.4' );
102 }
103 }
104