Skip to content

Commit

Permalink
Connection: optimize admin_notices owner delete warning (#39650)
Browse files Browse the repository at this point in the history
Optimize the `admin_notices` hook conditions to get rid of an excessive callback.

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/11220165897

Upstream-Ref: Automattic/jetpack@0d4d8a8
  • Loading branch information
sergeymitr authored and matticbot committed Oct 7, 2024
1 parent b765971 commit f00e9aa
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 125 deletions.
1 change: 1 addition & 0 deletions jetpack_vendor/automattic/jetpack-connection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This is an alpha version! The changes listed here are not final.

### Changed
- Adjust conditions to optimize admin notices callback.
- Initialize assets in wp-admin only.
- Updated package dependencies.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,16 @@ public function __construct() {
* @return void
*/
public function initialize_notices( $screen ) {
if ( ! in_array(
if ( in_array(
$screen->id,
array(
'jetpack_page_akismet-key-config',
'admin_page_jetpack_modules',
),
true
) ) {
add_action( 'admin_notices', array( $this, 'delete_user_update_connection_owner_notice' ) );
return;
}
}

/**
* This is an entire admin notice dedicated to messaging and handling of the case where a user is trying to delete
* the connection owner.
*/
public function delete_user_update_connection_owner_notice() {
global $current_screen;

/*
* phpcs:disable WordPress.Security.NonceVerification.Recommended
Expand All @@ -66,14 +58,18 @@ public function delete_user_update_connection_owner_notice() {
* page. Nonce will be already checked by WordPress, so we do not need to check ourselves.
*/

if ( ! isset( $current_screen->base ) || 'users' !== $current_screen->base ) {
return;
}

if ( ! isset( $_REQUEST['action'] ) || 'delete' !== $_REQUEST['action'] ) {
return;
if ( isset( $screen->base ) && 'users' === $screen->base
&& isset( $_REQUEST['action'] ) && 'delete' === $_REQUEST['action']
) {
add_action( 'admin_notices', array( $this, 'delete_user_update_connection_owner_notice' ) );
}
}

/**
* This is an entire admin notice dedicated to messaging and handling of the case where a user is trying to delete
* the connection owner.
*/
public function delete_user_update_connection_owner_notice() {
// Get connection owner or bail.
$connection_manager = new Manager();
$connection_owner_id = $connection_manager->get_connection_owner_id();
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
),
'jetpack-connection' => array(
'path' => 'jetpack_vendor/automattic/jetpack-connection',
'ver' => '5.1.2-alpha1727884694',
'ver' => '5.1.2-alpha1728319656',
),
'jetpack-explat' => array(
'path' => 'jetpack_vendor/automattic/jetpack-explat',
Expand Down
60 changes: 30 additions & 30 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-a8c-mc-stats",
"reference": "075e2979574898d164183bcccb44b5659888aed6"
"reference": "1f0844ec48809055882ea1f174d5333377a6f79a"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -60,7 +60,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-admin-ui",
"reference": "c17c2bbae051a5f4f9ebafc0a9bb0910ea7866d9"
"reference": "0503c20eda75ed9d153ac68dc445a5cae9e77f1f"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -125,7 +125,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-assets",
"reference": "164644fa6f89ad03a0295d1176de9540840ed82c"
"reference": "85706abeb9a8966d538c398664e21b8b40f792b5"
},
"require": {
"automattic/jetpack-constants": "^2.0.4",
Expand Down Expand Up @@ -194,7 +194,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-autoloader",
"reference": "5de9ddac1bbd479cdd95a8fbd89ae0c5e49d4329"
"reference": "e5c0e481f3cc2f28873abdb7598aaa41b5a15e9f"
},
"require": {
"composer-plugin-api": "^1.1 || ^2.0",
Expand Down Expand Up @@ -261,7 +261,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-boost-core",
"reference": "34d608e574c62d2bf95f7d271be567e7bd8e52f2"
"reference": "28ce9723baf84edb3965c366c526db51b8c6376f"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -329,7 +329,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-boost-speed-score",
"reference": "27ab37e40c2c5875a55c22ae95070c9165447fbc"
"reference": "89a2f6728bb4aecd56bb6a91752609aeab42fe55"
},
"require": {
"automattic/jetpack-boost-core": "^0.2.12",
Expand Down Expand Up @@ -405,7 +405,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-composer-plugin",
"reference": "b6e9079af2ed42f451f1706cae13900897bd606f"
"reference": "0c82aa62a0fdc469eaff7f3bf2b9e5f16e3f7528"
},
"require": {
"composer-plugin-api": "^2.1.0",
Expand Down Expand Up @@ -465,7 +465,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-config",
"reference": "89cd9d1454b21439594f4bebd04a393bb8d1b820"
"reference": "2b807a1a950528d503e0f8ddb1992c49eea840d5"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -535,12 +535,12 @@
},
{
"name": "automattic/jetpack-connection",
"version": "5.1.2-alpha.1727884694",
"version_normalized": "5.1.2.0-alpha1727884694",
"version": "5.1.2-alpha.1728319656",
"version_normalized": "5.1.2.0-alpha1728319656",
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-connection",
"reference": "8c70b8b6514108407e296edd2af1b85c9274a8c6"
"reference": "a214e8e5ecd296ca8baa67475afddb22581915eb"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^2.0.3",
Expand Down Expand Up @@ -630,7 +630,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-constants",
"reference": "cb9af9e8c6189fcc108ad9c0fc2669d4f8e599d1"
"reference": "71e48f0204910c22565369868d239bcd227dc8bd"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -684,7 +684,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-device-detection",
"reference": "2d2e38556b1962f0e78bd26ac608082d060f0466"
"reference": "3a668a796ad9d5afe81e7c5eb16ea1e7402e8e4d"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -737,7 +737,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-explat",
"reference": "e705d59548eb41c68c55a781687f334823835330"
"reference": "90a85f8a1000680d0ce238806eea7ecb9a366952"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -812,7 +812,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-ip",
"reference": "eaee759631a5109f3c6f87e985580d60054d4e26"
"reference": "842e3b253c1c5b992d1798ec930b6ca027b586f1"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -870,7 +870,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-jitm",
"reference": "240546f4434655a78c69c76b85dcdd41e97c75e6"
"reference": "1c11642e39cd24eeb0d9be91966c87abf19c300f"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^2.0.3",
Expand Down Expand Up @@ -945,7 +945,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-licensing",
"reference": "bfe59b2272e505731fc38a398abf747a6c0f52e9"
"reference": "256221a72110d1a180dc6942e35b898763781bc8"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -1007,7 +1007,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-logo",
"reference": "4b3051f91745847b6a061c0b877016b4cea640b7"
"reference": "fbd51ed6952bf7c659e51572187e442082b563ca"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1060,7 +1060,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-my-jetpack",
"reference": "63a15151f82389dbe99c456704469bf23dec63b5"
"reference": "83523a59fbe2c9d8ab1aac048a3d4592cfa91f1a"
},
"require": {
"automattic/jetpack-admin-ui": "^0.4.5",
Expand Down Expand Up @@ -1162,7 +1162,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-password-checker",
"reference": "74e4af490fbb4f54cd9d2c7d671b683df983a39a"
"reference": "4d264cef18dd62a56da0e507003863a7c748cb1e"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1223,7 +1223,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-plans",
"reference": "a93f6850103c86d4cb11c07e0444f3ed2d0738bb"
"reference": "9b0cb1953cad546aa309ba2ce16fddcd2972ce23"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -1291,7 +1291,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-plugins-installer",
"reference": "d752cb5ca865053d463bc83733c1afcf0ad795a6"
"reference": "6e1fcac9c636cfec4ae831de1ad81dc169465b7c"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^2.0.3",
Expand Down Expand Up @@ -1347,7 +1347,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-protect-models",
"reference": "681447d7e82f68890dca0f82bcb870dac09904eb"
"reference": "370b7fb8cbcf88b56ebb7beb53d55617395403df"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1417,7 +1417,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-protect-status",
"reference": "4285ae970da9d2f4aef2b9bef82dd4dd63a3f788"
"reference": "9cd271275500985eb724f2dd960d620aa071afe1"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -1492,7 +1492,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-redirect",
"reference": "2aaeb5d1bcab5953880ea0545544dc1a9a62c17b"
"reference": "ef0c16b03eedef0057798e950d39951974f1cd11"
},
"require": {
"automattic/jetpack-status": "^4.0.2",
Expand Down Expand Up @@ -1547,7 +1547,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-roles",
"reference": "0f1b0719e13e5dc1b8c0674a640f9a3a53d17372"
"reference": "06e163fbbfbc63f2934b00974f93e8c9262c6d65"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1601,7 +1601,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-search",
"reference": "e0e7e329dfc46a8b9689495eeeef274b0b6afde9"
"reference": "680188624a16590162935df3936d0aec427ebec4"
},
"require": {
"automattic/jetpack-assets": "^2.3.9-alpha",
Expand Down Expand Up @@ -1689,7 +1689,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-stats",
"reference": "e3feb7f4ba5c7b7796233c4fc54a940537f4e093"
"reference": "fc780aea1bb31b936299072145ee271f02859a08"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -1756,7 +1756,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-status",
"reference": "09dd84b9b7d2da8afc4126512c96d235ae226839"
"reference": "4f2c92bbfd1137f2e4f70450354deef0b119e3e7"
},
"require": {
"automattic/jetpack-constants": "^2.0.4",
Expand Down Expand Up @@ -1820,7 +1820,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-sync",
"reference": "e82bb90a34a5c0299c4cb6ba069f454f892dc6f4"
"reference": "a45705192f94ca98be409539b054e8bb1912baae"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down
Loading

0 comments on commit f00e9aa

Please sign in to comment.