| @@ -30,8 +30,16 @@ | ||
| 30 | 30 | * Admin class. |
| 31 | 31 | */ |
| 32 | 32 | class Admin { |
| 33 | 33 | /** |
| 34 | + * Script handle for the api-fetch `_method` shim (assets/js/api-fetch-method-param.js). | |
| 35 | + * | |
| 36 | + * Pro references this handle by its string value, guarded by | |
| 37 | + * wp_script_is( ..., 'registered' ), so the value is a compatibility contract. | |
| 38 | + */ | |
| 39 | + public const API_FETCH_METHOD_PARAM_HANDLE = 'wcpos-api-fetch-method-param'; | |
| 40 | + | |
| 41 | + /** | |
| 34 | 42 | * POS Menu IDs. |
| 35 | 43 | * |
| 36 | 44 | * @var string[] Unique menu identifier. |
| 37 | 45 | */ |
| @@ -56,8 +64,9 @@ | ||
| 56 | 64 | */ |
| 57 | 65 | public function __construct() { |
| 58 | 66 | add_action( 'admin_menu', array( $this, 'admin_menu' ), 5 ); |
| 59 | 67 | add_action( 'admin_init', array( $this, 'init' ) ); |
| 68 | + add_action( 'admin_init', array( $this, 'register_scripts' ) ); | |
| 60 | 69 | add_action( 'current_screen', array( $this, 'current_screen' ) ); |
| 61 | 70 | |
| 62 | 71 | // register the screen handlers. |
| 63 | 72 | $this->screen_handlers = array( |
| @@ -77,8 +86,27 @@ | ||
| 77 | 86 | * Load admin subclasses. |
| 78 | 87 | */ |
| 79 | 88 | public function init(): void { |
| 80 | 89 | new Notices(); |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * Register the shared admin scripts that WCPOS bundles depend on. | |
| 94 | + * | |
| 95 | + * The api-fetch shim routes PUT/PATCH/DELETE through POST + `?_method=` | |
| 96 | + * so wp-admin mutations survive hosts that 403 the bare verbs or the | |
| 97 | + * `X-HTTP-Method-Override` header (see the shim's header comment). It is | |
| 98 | + * only registered here; each bundle that uses `wp.apiFetch` enqueues it | |
| 99 | + * by listing self::API_FETCH_METHOD_PARAM_HANDLE as a dependency. | |
| 100 | + */ | |
| 101 | + public function register_scripts(): void { | |
| 102 | + wp_register_script( | |
| 103 | + self::API_FETCH_METHOD_PARAM_HANDLE, | |
| 104 | + PLUGIN_URL . 'assets/js/api-fetch-method-param.js', | |
| 105 | + array( 'wp-api-fetch' ), | |
| 106 | + VERSION, | |
| 107 | + true | |
| 108 | + ); | |
| 81 | 109 | } |
| 82 | 110 | |
| 83 | 111 | /** |
| 84 | 112 | * Fires before the administration menu loads in the admin. |