| @@ 39-61 (lines=23) @@ | ||
| 36 | //@todo retry on failure |
|
| 37 | ||
| 38 | //try to choose a new master if we're demoting the current one |
|
| 39 | if ( $user_id == $master_user_id && 'administrator' != $role ) { |
|
| 40 | $query = new WP_User_Query( |
|
| 41 | array( |
|
| 42 | 'fields' => array( 'id' ), |
|
| 43 | 'role' => 'administrator', |
|
| 44 | 'orderby' => 'id', |
|
| 45 | 'exclude' => array( $master_user_id ), |
|
| 46 | ) |
|
| 47 | ); |
|
| 48 | $new_master = false; |
|
| 49 | foreach ( $query->results as $result ) { |
|
| 50 | $uid = absint( $result->id ); |
|
| 51 | if ( $uid && Jetpack::is_user_connected( $uid ) ) { |
|
| 52 | $new_master = $uid; |
|
| 53 | break; |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||
| 57 | if ( $new_master ) { |
|
| 58 | Jetpack_Options::update_option( 'master_user', $new_master ); |
|
| 59 | } |
|
| 60 | // else disconnect..? |
|
| 61 | } |
|
| 62 | } |
|
| 63 | } |
|
| 64 | } |
|
| @@ 1264-1286 (lines=23) @@ | ||
| 1261 | //@todo retry on failure |
|
| 1262 | ||
| 1263 | //try to choose a new master if we're demoting the current one |
|
| 1264 | if ( $user_id == $master_user_id && 'administrator' != $role ) { |
|
| 1265 | $query = new WP_User_Query( |
|
| 1266 | array( |
|
| 1267 | 'fields' => array( 'id' ), |
|
| 1268 | 'role' => 'administrator', |
|
| 1269 | 'orderby' => 'id', |
|
| 1270 | 'exclude' => array( $master_user_id ), |
|
| 1271 | ) |
|
| 1272 | ); |
|
| 1273 | $new_master = false; |
|
| 1274 | foreach ( $query->results as $result ) { |
|
| 1275 | $uid = absint( $result->id ); |
|
| 1276 | if ( $uid && Jetpack::is_user_connected( $uid ) ) { |
|
| 1277 | $new_master = $uid; |
|
| 1278 | break; |
|
| 1279 | } |
|
| 1280 | } |
|
| 1281 | ||
| 1282 | if ( $new_master ) { |
|
| 1283 | Jetpack_Options::update_option( 'master_user', $new_master ); |
|
| 1284 | } |
|
| 1285 | // else disconnect..? |
|
| 1286 | } |
|
| 1287 | } |
|
| 1288 | } |
|
| 1289 | ||