| 1 |
<?php |
| 2 |
/** |
| 3 |
* CartFlows Abilities Loader. |
| 4 |
* |
| 5 |
* Bootstraps the CartFlows Abilities API integration. Defines constants, |
| 6 |
* checks for WordPress 6.9+ Abilities API availability, requires the config |
| 7 |
* and runtime classes, and wires the registration hooks. |
| 8 |
* |
| 9 |
* @package CartFlows |
| 10 |
* @since 2.2.2 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Class Cartflows_Abilities_Loader. |
| 20 |
*/ |
| 21 |
class Cartflows_Abilities_Loader { |
| 22 |
|
| 23 |
/** |
| 24 |
* Instance |
| 25 |
* |
| 26 |
* @access private |
| 27 |
* @var object Class object. |
| 28 |
* @since 2.2.2 |
| 29 |
*/ |
| 30 |
private static $instance; |
| 31 |
|
| 32 |
/** |
| 33 |
* Ability runtime instance. |
| 34 |
* |
| 35 |
* @var object|null |
| 36 |
* @since 2.2.2 |
| 37 |
*/ |
| 38 |
private $runtime = null; |
| 39 |
|
| 40 |
/** |
| 41 |
* Initiator |
| 42 |
* |
| 43 |
* @since 2.2.2 |
| 44 |
* @return object initialized object of class. |
| 45 |
*/ |
| 46 |
public static function get_instance() { |
| 47 |
if ( ! isset( self::$instance ) ) { |
| 48 |
self::$instance = new self(); |
| 49 |
} |
| 50 |
return self::$instance; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Constructor |
| 55 |
*/ |
| 56 |
public function __construct() { |
| 57 |
$this->define_constants(); |
| 58 |
$this->init_hooks(); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Define Abilities API constants. |
| 63 |
* |
| 64 |
* @since 2.2.2 |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
public function define_constants() { |
| 68 |
|
| 69 |
/** |
| 70 |
* Abilities API integration is present in this build. |
| 71 |
* |
| 72 |
* @since 2.2.2 |
| 73 |
*/ |
| 74 |
if ( ! defined( 'CARTFLOWS_ABILITY_API' ) ) { |
| 75 |
define( 'CARTFLOWS_ABILITY_API', true ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Namespace prefix used for all CartFlows ability identifiers. |
| 80 |
* |
| 81 |
* Every ability registered by this plugin is named |
| 82 |
* CARTFLOWS_ABILITY_API_NAMESPACE . '<slug>', e.g. 'cartflows/list-flows'. |
| 83 |
* |
| 84 |
* @since 2.2.2 |
| 85 |
*/ |
| 86 |
if ( ! defined( 'CARTFLOWS_ABILITY_API_NAMESPACE' ) ) { |
| 87 |
define( 'CARTFLOWS_ABILITY_API_NAMESPACE', 'cartflows/' ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Load required ability class files. |
| 93 |
* |
| 94 |
* @since 2.2.2 |
| 95 |
* @return void |
| 96 |
*/ |
| 97 |
public function load_files() { |
| 98 |
require_once CARTFLOWS_DIR . 'abilities/class-cartflows-ability-config.php'; |
| 99 |
require_once CARTFLOWS_DIR . 'abilities/class-cartflows-ability-runtime.php'; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Init Hooks. |
| 104 |
* |
| 105 |
* Graceful degradation: only loads when the WordPress Abilities API |
| 106 |
* (WordPress 6.9+) is available on this installation. |
| 107 |
* |
| 108 |
* @since 2.2.2 |
| 109 |
* @return void |
| 110 |
*/ |
| 111 |
public function init_hooks() { |
| 112 |
|
| 113 |
if ( ! function_exists( 'wp_register_ability' ) || ! class_exists( 'WP_Ability' ) ) { |
| 114 |
return; |
| 115 |
} |
| 116 |
|
| 117 |
$this->load_files(); |
| 118 |
|
| 119 |
$this->runtime = new Cartflows_Ability_Runtime(); |
| 120 |
|
| 121 |
/** |
| 122 |
* Register CartFlows ability categories. |
| 123 |
* |
| 124 |
* Fired by the WordPress Abilities API after category registration opens. |
| 125 |
* |
| 126 |
* @since 2.2.2 |
| 127 |
*/ |
| 128 |
add_action( 'wp_abilities_api_categories_init', array( $this->runtime, 'register_categories' ) ); |
| 129 |
|
| 130 |
/** |
| 131 |
* Register CartFlows abilities. |
| 132 |
* |
| 133 |
* Fired by the WordPress Abilities API after ability registration opens. |
| 134 |
* |
| 135 |
* @since 2.2.2 |
| 136 |
*/ |
| 137 |
add_action( 'wp_abilities_api_init', array( $this->runtime, 'register' ) ); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
Cartflows_Abilities_Loader::get_instance(); |
| 142 |
|