| 1 |
<?php |
| 2 |
/** |
| 3 |
* User Edit — the profile editor, as an OpenStation app. |
| 4 |
* |
| 5 |
* Claims the FROZEN id `desktop-mode-user-edit` (see AGENTS.md). A |
| 6 |
* singleton that opens on the person carried in its open-time params |
| 7 |
* (`{ userId }` — the `user-edit.php?user_id=N` remap, a Users row, |
| 8 |
* WP Explorer, the agents roster; `0`, or none, is the viewer's own |
| 9 |
* profile, how `profile.php` opens). A live window asked to open on |
| 10 |
* someone else retargets through the `reopen` lifecycle. The body is |
| 11 |
* `user-edit.os.ts`: `<os-user-profile>` on the state's id, from the |
| 12 |
* companion bundle the Users app registers, fed this app's facts. |
| 13 |
* |
| 14 |
* (Header kept short on purpose: Plugin Check's direct-access scan |
| 15 |
* reads only the first 50 raw lines, and the guard below must land |
| 16 |
* inside that window.) |
| 17 |
* |
| 18 |
* @package OpenStation |
| 19 |
*/ |
| 20 |
|
| 21 |
namespace OpenStation\Apps\UserEdit; |
| 22 |
|
| 23 |
use OpenStation\App; |
| 24 |
use OpenStation\App\Os; |
| 25 |
use OpenStation\App\State; |
| 26 |
|
| 27 |
// Direct access, unless a standalone host is booting on bare PHP. |
| 28 |
if ( ! defined( 'ABSPATH' ) ) { |
| 29 |
defined( 'OPENSTATION_STANDALONE' ) || exit; |
| 30 |
} |
| 31 |
|
| 32 |
require_once __DIR__ . '/parts/permissions.php'; |
| 33 |
require_once __DIR__ . '/parts/account.php'; |
| 34 |
require_once __DIR__ . '/parts/insights.php'; |
| 35 |
// The facts (roles, locales, colour schemes, contact methods) and the |
| 36 |
// profile bundle belong to the Users app; both windows share them. |
| 37 |
require_once dirname( __DIR__ ) . '/users/parts/permissions.php'; |
| 38 |
require_once dirname( __DIR__ ) . '/users/parts/color-schemes.php'; |
| 39 |
require_once dirname( __DIR__ ) . '/users/parts/fields.php'; |
| 40 |
require_once dirname( __DIR__ ) . '/users/parts/facts.php'; |
| 41 |
require_once dirname( __DIR__ ) . '/users/parts/profile-script.php'; |
| 42 |
|
| 43 |
/** |
| 44 |
* Point the window at the person the params name, or at the viewer. |
| 45 |
* |
| 46 |
* @param State $state State. |
| 47 |
* @param Os $os Host handle. |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
function retarget( State $state, Os $os ) { |
| 51 |
$user_id = (int) $os->param( 'userId', 0 ); |
| 52 |
$state->set( 'userId', $user_id > 0 ? $user_id : (int) get_current_user_id() ); |
| 53 |
} |
| 54 |
|
| 55 |
return App::define( 'desktop-mode-user-edit' ) |
| 56 |
->title( __( 'Edit user', 'desktop-mode' ) ) |
| 57 |
->icon( 'dashicons-admin-users' ) |
| 58 |
->size( 1100, 760 ) |
| 59 |
->min_size( 720, 520 ) |
| 60 |
->placement( 'none' ) |
| 61 |
// The profile surface is styled by the Users app's sheet — one set |
| 62 |
// of rules for the Profile tab and this window. Pointing here |
| 63 |
// registers the same file under this app's own handle, so the |
| 64 |
// window is dressed even when the Users window was never opened. |
| 65 |
->style( dirname( __DIR__ ) . '/users/users.css' ) |
| 66 |
->can( |
| 67 |
static function () { |
| 68 |
return openstation_user_edit_window_user_can_register(); |
| 69 |
} |
| 70 |
) |
| 71 |
// Resolved when the window registers, for the viewer registering it. |
| 72 |
->config( 'openstation_users_profile_facts' ) |
| 73 |
->state( array( 'userId' => 0 ) ) |
| 74 |
->mount( __NAMESPACE__ . '\retarget' ) |
| 75 |
// The singleton reopened on someone else — the shell wrote the new |
| 76 |
// params, the runtime dispatched this. |
| 77 |
->action( 'reopen', __NAMESPACE__ . '\retarget' ) |
| 78 |
->data( |
| 79 |
static function ( State $state ) { |
| 80 |
return array( 'userId' => (int) $state->get( 'userId' ) ); |
| 81 |
} |
| 82 |
); |
| 83 |
|