abilities
1 month ago
abilities-api
1 month ago
assets
1 month ago
rest-api
1 month ago
abilities-api.php
1 month ago
bootstrap.php
1 month ago
bootstrap.php
78 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Bootstraps the Abilities API classes and global functions. |
| 4 | * |
| 5 | * This file is autoloaded by Composer when the package is installed via the |
| 6 | * "files" autoload mechanism. It ensures the procedural functions defined in |
| 7 | * `includes/abilities-api.php` are available without requiring namespaces. |
| 8 | * |
| 9 | * @package WordPress |
| 10 | * @subpackage Abilities_API |
| 11 | * @since 0.1.0 |
| 12 | */ |
| 13 | |
| 14 | declare( strict_types = 1 ); |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | return; // Not in WordPress context |
| 18 | } |
| 19 | |
| 20 | // Version of the plugin. |
| 21 | if ( ! defined( 'WP_ABILITIES_API_VERSION' ) ) { |
| 22 | define( 'WP_ABILITIES_API_VERSION', '0.4.0' ); |
| 23 | } |
| 24 | |
| 25 | // Load core classes if they are not already defined (for non-Composer installs or direct includes). |
| 26 | if ( ! class_exists( 'WP_Ability_Category' ) ) { |
| 27 | require_once __DIR__ . '/abilities-api/class-wp-ability-category.php'; |
| 28 | } |
| 29 | if ( ! class_exists( 'WP_Ability_Categories_Registry' ) ) { |
| 30 | require_once __DIR__ . '/abilities-api/class-wp-ability-categories-registry.php'; |
| 31 | } |
| 32 | if ( ! class_exists( 'WP_Ability' ) ) { |
| 33 | require_once __DIR__ . '/abilities-api/class-wp-ability.php'; |
| 34 | } |
| 35 | if ( ! class_exists( 'WP_Abilities_Registry' ) ) { |
| 36 | require_once __DIR__ . '/abilities-api/class-wp-abilities-registry.php'; |
| 37 | } |
| 38 | |
| 39 | // Ensure procedural functions are available, too. |
| 40 | if ( ! function_exists( 'wp_register_ability' ) ) { |
| 41 | require_once __DIR__ . '/abilities-api.php'; |
| 42 | } |
| 43 | |
| 44 | // Load core abilities registration functions. |
| 45 | if ( ! function_exists( 'wp_register_core_abilities' ) ) { |
| 46 | require_once __DIR__ . '/abilities/wp-core-abilities.php'; |
| 47 | } |
| 48 | |
| 49 | // Register core abilities category and abilities when requested via filter or when not in test environment. |
| 50 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Plugin-specific hook for feature plugin context. |
| 51 | if ( ! ( defined( 'WP_RUN_CORE_TESTS' ) || defined( 'WP_TESTS_CONFIG_FILE_PATH' ) || ( function_exists( 'getenv' ) && false !== getenv( 'WP_PHPUNIT__DIR' ) ) ) || apply_filters( 'abilities_api_register_core_abilities', false ) ) { |
| 52 | if ( function_exists( 'add_action' ) ) { |
| 53 | add_action( 'wp_abilities_api_categories_init', 'wp_register_core_ability_categories' ); |
| 54 | add_action( 'wp_abilities_api_init', 'wp_register_core_abilities' ); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // Load REST API init class for plugin bootstrap. |
| 59 | if ( ! class_exists( 'WP_REST_Abilities_Init' ) ) { |
| 60 | require_once __DIR__ . '/rest-api/class-wp-rest-abilities-init.php'; |
| 61 | |
| 62 | // Initialize REST API routes when WordPress is available. |
| 63 | if ( function_exists( 'add_action' ) ) { |
| 64 | add_action( 'rest_api_init', array( 'WP_REST_Abilities_Init', 'register_routes' ), 11 ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // Load assets init class for plugin bootstrap. |
| 69 | if ( ! class_exists( 'WP_Abilities_Assets_Init' ) ) { |
| 70 | require_once __DIR__ . '/assets/class-wp-abilities-assets-init.php'; |
| 71 | |
| 72 | // Initialize client assets when WordPress is available. |
| 73 | if ( function_exists( 'add_action' ) ) { |
| 74 | add_action( 'init', array( 'WP_Abilities_Assets_Init', 'register_assets' ) ); |
| 75 | add_action( 'admin_enqueue_scripts', array( 'WP_Abilities_Assets_Init', 'admin_enqueue_scripts' ) ); |
| 76 | } |
| 77 | } |
| 78 |