| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Agents: authentication guard. | |
| 3 | + * OpenStation — Agents: authentication guard. | |
| 4 | 4 | * |
| 5 | 5 | * Agents own a real `wp_users` row so capability checks, edit locks, |
| 6 | 6 | * comment attribution, and the standard WordPress audit trail work |
| 7 | 7 | * without a parallel ACL. The row is "synthetic" only in that no |
| @@ -31,9 +31,9 @@ | ||
| 31 | 31 | * runner: `wp_set_current_user()` sets the global directly and never |
| 32 | 32 | * re-runs the filter, so switching into an agent to evaluate ability |
| 33 | 33 | * permissions still works exactly as before. |
| 34 | 34 | * |
| 35 | - * @package WPDesktopMode | |
| 35 | + * @package OpenStation | |
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | 38 | defined( 'ABSPATH' ) || exit; |
| 39 | 39 | |
| @@ -39,25 +39,31 @@ | ||
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Marker meta key — the existence test for an agent. |
| 42 | 42 | * |
| 43 | - * Lives here rather than in store.php because `desktop_mode_agent_is_agent()` | |
| 43 | + * Lives here rather than in store.php because `openstation_agent_is_agent()` | |
| 44 | 44 | * must resolve even when the agents module itself is not loaded. |
| 45 | + * | |
| 46 | + * The VALUE keeps its pre-rebrand spelling on purpose: it is a | |
| 47 | + * persisted or externally-visible identifier, so renaming it would | |
| 48 | + * orphan data already written by live installs (or break a live | |
| 49 | + * URL). The mismatch between this constant's name and its value is | |
| 50 | + * deliberate — it is NOT a half-finished rename. | |
| 45 | 51 | */ |
| 46 | -const DESKTOP_MODE_AGENT_USER_MARKER_META = '_desktop_mode_agent'; | |
| 52 | +const OPENSTATION_AGENT_USER_MARKER_META = '_desktop_mode_agent'; | |
| 47 | 53 | |
| 48 | 54 | /** |
| 49 | - * Whether the given user is a Desktop Mode agent. | |
| 55 | + * Whether the given user is a OpenStation agent. | |
| 50 | 56 | * |
| 51 | 57 | * @param int|WP_User|null $user User id or object. |
| 52 | 58 | * @return bool |
| 53 | 59 | */ |
| 54 | -function desktop_mode_agent_is_agent( $user ) { | |
| 60 | +function openstation_agent_is_agent( $user ) { | |
| 55 | 61 | $user_id = $user instanceof WP_User ? $user->ID : (int) $user; |
| 56 | 62 | if ( $user_id <= 0 ) { |
| 57 | 63 | return false; |
| 58 | 64 | } |
| 59 | - return '1' === (string) get_user_meta( $user_id, DESKTOP_MODE_AGENT_USER_MARKER_META, true ); | |
| 65 | + return '1' === (string) get_user_meta( $user_id, OPENSTATION_AGENT_USER_MARKER_META, true ); | |
| 60 | 66 | } |
| 61 | 67 | |
| 62 | 68 | /** |
| 63 | 69 | * Block password authentication for agent users. |
| @@ -74,18 +80,18 @@ | ||
| 74 | 80 | * |
| 75 | 81 | * @param WP_User|WP_Error|null $user Current candidate from the chain. |
| 76 | 82 | * @return WP_User|WP_Error|null |
| 77 | 83 | */ |
| 78 | -function desktop_mode_agent_block_authentication( $user ) { | |
| 79 | - if ( $user instanceof WP_User && desktop_mode_agent_is_agent( $user ) ) { | |
| 84 | +function openstation_agent_block_authentication( $user ) { | |
| 85 | + if ( $user instanceof WP_User && openstation_agent_is_agent( $user ) ) { | |
| 80 | 86 | return new WP_Error( |
| 81 | - 'desktop_mode_agent_login_blocked', | |
| 82 | - __( 'This account is a Desktop Mode agent. Login is disabled.', 'desktop-mode' ) | |
| 87 | + 'openstation_agent_login_blocked', | |
| 88 | + __( 'This account is a OpenStation agent. Login is disabled.', 'desktop-mode' ) | |
| 83 | 89 | ); |
| 84 | 90 | } |
| 85 | 91 | return $user; |
| 86 | 92 | } |
| 87 | -add_filter( 'authenticate', 'desktop_mode_agent_block_authentication', 30 ); | |
| 93 | +add_filter( 'authenticate', 'openstation_agent_block_authentication', 30 ); | |
| 88 | 94 | |
| 89 | 95 | /** |
| 90 | 96 | * Refuse to resolve an agent as the current user for a request. |
| 91 | 97 | * |
| @@ -100,15 +106,15 @@ | ||
| 100 | 106 | * |
| 101 | 107 | * @param int|false $user_id User id resolved so far, or false. |
| 102 | 108 | * @return int|false |
| 103 | 109 | */ |
| 104 | -function desktop_mode_agent_block_session( $user_id ) { | |
| 105 | - if ( $user_id && desktop_mode_agent_is_agent( (int) $user_id ) ) { | |
| 110 | +function openstation_agent_block_session( $user_id ) { | |
| 111 | + if ( $user_id && openstation_agent_is_agent( (int) $user_id ) ) { | |
| 106 | 112 | return false; |
| 107 | 113 | } |
| 108 | 114 | return $user_id; |
| 109 | 115 | } |
| 110 | -add_filter( 'determine_current_user', 'desktop_mode_agent_block_session', PHP_INT_MAX ); | |
| 116 | +add_filter( 'determine_current_user', 'openstation_agent_block_session', PHP_INT_MAX ); | |
| 111 | 117 | |
| 112 | 118 | /** |
| 113 | 119 | * Block password-reset emails for agent users. |
| 114 | 120 | * |
| @@ -115,15 +121,15 @@ | ||
| 115 | 121 | * @param bool $allow Whether to allow the reset. |
| 116 | 122 | * @param int $user_id Target user id. |
| 117 | 123 | * @return bool |
| 118 | 124 | */ |
| 119 | -function desktop_mode_agent_block_password_reset( $allow, $user_id ) { | |
| 120 | - if ( desktop_mode_agent_is_agent( $user_id ) ) { | |
| 125 | +function openstation_agent_block_password_reset( $allow, $user_id ) { | |
| 126 | + if ( openstation_agent_is_agent( $user_id ) ) { | |
| 121 | 127 | return false; |
| 122 | 128 | } |
| 123 | 129 | return $allow; |
| 124 | 130 | } |
| 125 | -add_filter( 'allow_password_reset', 'desktop_mode_agent_block_password_reset', 10, 2 ); | |
| 131 | +add_filter( 'allow_password_reset', 'openstation_agent_block_password_reset', 10, 2 ); | |
| 126 | 132 | |
| 127 | 133 | /** |
| 128 | 134 | * Application passwords are the one credential that could authenticate |
| 129 | 135 | * a never-logs-in account over REST — refuse to make them available |
| @@ -128,9 +134,9 @@ | ||
| 128 | 134 | * Application passwords are the one credential that could authenticate |
| 129 | 135 | * a never-logs-in account over REST — refuse to make them available |
| 130 | 136 | * for agents, so the credential cannot be minted in the first place. |
| 131 | 137 | * |
| 132 | - * `desktop_mode_agent_block_authentication()` would reject it at use | |
| 138 | + * `openstation_agent_block_authentication()` would reject it at use | |
| 133 | 139 | * time anyway; this stops it existing. |
| 134 | 140 | * |
| 135 | 141 | * @param bool $available Whether application passwords are available. |
| 136 | 142 | * @param WP_User $user The user being checked. |
| @@ -135,15 +141,15 @@ | ||
| 135 | 141 | * @param bool $available Whether application passwords are available. |
| 136 | 142 | * @param WP_User $user The user being checked. |
| 137 | 143 | * @return bool |
| 138 | 144 | */ |
| 139 | -function desktop_mode_agent_block_application_passwords( $available, $user ) { | |
| 140 | - if ( $user instanceof WP_User && desktop_mode_agent_is_agent( $user ) ) { | |
| 145 | +function openstation_agent_block_application_passwords( $available, $user ) { | |
| 146 | + if ( $user instanceof WP_User && openstation_agent_is_agent( $user ) ) { | |
| 141 | 147 | return false; |
| 142 | 148 | } |
| 143 | 149 | return $available; |
| 144 | 150 | } |
| 145 | -add_filter( 'wp_is_application_passwords_available_for_user', 'desktop_mode_agent_block_application_passwords', 10, 2 ); | |
| 151 | +add_filter( 'wp_is_application_passwords_available_for_user', 'openstation_agent_block_application_passwords', 10, 2 ); | |
| 146 | 152 | |
| 147 | 153 | /** |
| 148 | 154 | * Suppress the password/email-changed notification emails for agents — |
| 149 | 155 | * the synthetic address is never delivered to, and a bounced |
| @@ -152,17 +158,17 @@ | ||
| 152 | 158 | * @param bool $send Whether to send the notification. |
| 153 | 159 | * @param array $user The original user array before changes. |
| 154 | 160 | * @return bool |
| 155 | 161 | */ |
| 156 | -function desktop_mode_agent_suppress_change_emails( $send, $user ) { | |
| 162 | +function openstation_agent_suppress_change_emails( $send, $user ) { | |
| 157 | 163 | $user_id = is_array( $user ) && isset( $user['ID'] ) ? (int) $user['ID'] : 0; |
| 158 | - if ( $user_id > 0 && desktop_mode_agent_is_agent( $user_id ) ) { | |
| 164 | + if ( $user_id > 0 && openstation_agent_is_agent( $user_id ) ) { | |
| 159 | 165 | return false; |
| 160 | 166 | } |
| 161 | 167 | return $send; |
| 162 | 168 | } |
| 163 | -add_filter( 'send_password_change_email', 'desktop_mode_agent_suppress_change_emails', 10, 2 ); | |
| 164 | -add_filter( 'send_email_change_email', 'desktop_mode_agent_suppress_change_emails', 10, 2 ); | |
| 169 | +add_filter( 'send_password_change_email', 'openstation_agent_suppress_change_emails', 10, 2 ); | |
| 170 | +add_filter( 'send_email_change_email', 'openstation_agent_suppress_change_emails', 10, 2 ); | |
| 165 | 171 | |
| 166 | 172 | /** |
| 167 | 173 | * Send front-end author archives for agents to a 404. |
| 168 | 174 | * |
| @@ -177,9 +183,9 @@ | ||
| 177 | 183 | * |
| 178 | 184 | * @param WP_Query $query The query about to run. |
| 179 | 185 | * @return void |
| 180 | 186 | */ |
| 181 | -function desktop_mode_agent_block_author_archive( $query ) { | |
| 187 | +function openstation_agent_block_author_archive( $query ) { | |
| 182 | 188 | if ( is_admin() || ! $query->is_main_query() || ! $query->is_author() ) { |
| 183 | 189 | return; |
| 184 | 190 | } |
| 185 | 191 | |
| @@ -191,11 +197,11 @@ | ||
| 191 | 197 | $author_id = $user ? (int) $user->ID : 0; |
| 192 | 198 | } |
| 193 | 199 | } |
| 194 | 200 | |
| 195 | - if ( $author_id > 0 && desktop_mode_agent_is_agent( $author_id ) ) { | |
| 201 | + if ( $author_id > 0 && openstation_agent_is_agent( $author_id ) ) { | |
| 196 | 202 | $query->set_404(); |
| 197 | 203 | status_header( 404 ); |
| 198 | 204 | nocache_headers(); |
| 199 | 205 | } |
| 200 | 206 | } |
| 201 | -add_action( 'pre_get_posts', 'desktop_mode_agent_block_author_archive' ); | |
| 207 | +add_action( 'pre_get_posts', 'openstation_agent_block_author_archive' ); | |