PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / apps / users / parts / profile-script.php

profile-script.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.10, at apps/users/parts/profile-script.php

66 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Users — the `<os-user-profile>` companion bundle.
4 *
5 * The profile surface (`apps/users/profile/`) is one bundle,
6 * `assets/js/apps/user-profile[.min].js`, registered under the handle
7 * `openstation-user-profile` and loaded as a first-open companion of
8 * BOTH windows that host the element — the Users app (its Profile
9 * tab) and the User Edit app — instead of a copy compiled into each
10 * app's client view. The element takes its facts, its REST access
11 * and its toast from properties the hosting app sets from
12 * `updated()`, so the bundle carries no config of its own.
13 *
14 * @package OpenStation
15 */
16
17 defined( 'ABSPATH' ) || exit;
18
19 /** The companion script handle. */
20 const OPENSTATION_USER_PROFILE_HANDLE = 'openstation-user-profile';
21
22 /**
23 * Register the bundle. Hooked after the framework has loaded the apps
24 * (the parts load DURING `init` @10, so a hook at 10 would never fire).
25 */
26 function openstation_users_profile_register_script() {
27 $suffix = openstation_asset_suffix();
28 $path = OPENSTATION_DIR . 'assets/js/apps/user-profile' . $suffix . '.js';
29 wp_register_script(
30 OPENSTATION_USER_PROFILE_HANDLE,
31 OPENSTATION_URL . 'assets/js/apps/user-profile' . $suffix . '.js',
32 array( 'wp-i18n' ),
33 file_exists( $path ) ? (string) filemtime( $path ) : OPENSTATION_VERSION,
34 true
35 );
36 wp_set_script_translations( OPENSTATION_USER_PROFILE_HANDLE, 'desktop-mode', OPENSTATION_DIR . 'languages' );
37 }
38 add_action( 'init', 'openstation_users_profile_register_script', 11 );
39
40 /**
41 * Ride the two app windows: append the bundle to their companion
42 * scripts, so it is in the tab before the runtime mounts either.
43 *
44 * @param array<string,mixed> $window_args `openstation_register_window()` args.
45 * @param string $app_id App id.
46 * @return array<string,mixed>
47 */
48 function openstation_users_profile_window_args( $window_args, $app_id ) {
49 if ( ! is_array( $window_args ) || ! in_array( (string) $app_id, array( 'desktop-mode-users', 'desktop-mode-user-edit' ), true ) ) {
50 return $window_args;
51 }
52 // The handle registers on `init`; a caller that rebuilt `$wp_scripts`
53 // since (a script manager, a test) would otherwise hand the window
54 // a handle nothing resolves.
55 if ( ! wp_script_is( OPENSTATION_USER_PROFILE_HANDLE, 'registered' ) ) {
56 openstation_users_profile_register_script();
57 }
58 $scripts = isset( $window_args['scripts'] ) ? (array) $window_args['scripts'] : array();
59 if ( ! in_array( OPENSTATION_USER_PROFILE_HANDLE, $scripts, true ) ) {
60 $scripts[] = OPENSTATION_USER_PROFILE_HANDLE;
61 }
62 $window_args['scripts'] = $scripts;
63 return $window_args;
64 }
65 add_filter( 'openstation_app_window_args', 'openstation_users_profile_window_args', 10, 2 );
66