PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / wordpress / abilities-api / includes / assets / class-wp-abilities-assets-init.php
ameliabooking / vendor / wordpress / abilities-api / includes / assets Last commit date
class-wp-abilities-assets-init.php 1 month ago
class-wp-abilities-assets-init.php
96 lines
1 <?php
2 /**
3 * Assets initialization for Abilities API.
4 *
5 * @package WordPress
6 * @subpackage Abilities_API
7 * @since 0.1.0
8 */
9
10 declare( strict_types = 1 );
11
12 /**
13 * Handles initialization of Abilities API client assets.
14 *
15 * @since 0.1.0
16 */
17 class WP_Abilities_Assets_Init {
18
19 /**
20 * Registers the Abilities API JavaScript client.
21 *
22 * Auto-detects whether running as a plugin or Composer package and registers
23 * the client script accordingly.
24 *
25 * @since 0.1.0
26 *
27 * @return void
28 */
29 public static function register_assets(): void {
30 if ( wp_script_is( 'wp-abilities', 'registered' ) ) {
31 return;
32 }
33
34 $base_path = '';
35 $base_url = '';
36
37 if ( defined( 'WP_ABILITIES_API_DIR' ) ) {
38 // Running as a plugin
39 $base_path = wp_normalize_path( (string) WP_ABILITIES_API_DIR );
40 $base_url = plugins_url( '', dirname( __DIR__, 2 ) . '/abilities-api.php' );
41 } else {
42 // Running as a Composer package
43 $base_path = dirname( __DIR__, 2 );
44
45 $base_path = wp_normalize_path( (string) $base_path );
46 $plugin_dir = wp_normalize_path( (string) WP_PLUGIN_DIR );
47
48 // For Composer, we need to determine the URL based on the installation location
49 if ( 0 === strpos( $base_path, $plugin_dir ) ) {
50 // Inside a plugin directory
51 $relative_path = str_replace( $plugin_dir, '', $base_path );
52 $base_url = plugins_url( $relative_path );
53 } else {
54 // Assume standard Composer vendor structure
55 $base_url = plugins_url( 'vendor/wordpress/abilities-api', dirname( $base_path, 2 ) );
56 }
57 }
58
59 /** @var string $base_path PHPStan type assertion - base_path is always set above */
60 $client_path = trailingslashit( $base_path ) . 'packages/client/build/';
61
62 if ( ! file_exists( $client_path . 'index.js' ) ) {
63 return;
64 }
65
66 // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- asset file path can be variable based on plugin or Composer install
67 $asset = require_once $client_path . 'index.asset.php';
68
69 $client_url = trailingslashit( $base_url ) . 'packages/client/build/index.js';
70
71 wp_register_script(
72 'wp-abilities',
73 $client_url,
74 $asset['dependencies'],
75 $asset['version'],
76 true
77 );
78 }
79
80 /**
81 * Auto-enqueue Abilities API client on admin pages.
82 *
83 * This is primarily for development and testing purposes.
84 *
85 * @since 0.1.0
86 * @return void
87 */
88 public static function admin_enqueue_scripts(): void {
89 if ( ! wp_script_is( 'wp-abilities', 'registered' ) ) {
90 return;
91 }
92
93 wp_enqueue_script( 'wp-abilities' );
94 }
95 }
96