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:/Automattic/jetpack/actions/runs/11220165897

Upstream-Ref: Automattic/jetpack@0d4d8a8
  • Loading branch information
sergeymitr authored and matticbot committed Oct 7, 2024
1 parent 0eaaf9e commit fa6a13f
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 @@ -30,7 +30,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": "eafa28e13a340257e7c3b61c715f0490c6e21337"
"reference": "c79eee0317a6c240903e00a64a485b4d5e8536f1"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -60,7 +60,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-admin-ui",
"reference": "0eb9fbf1cd3aa6bc54339a210a21b7fa4547d799"
"reference": "03f9f4b614137fac0b321453cf1db0c0ac4483ad"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -125,7 +125,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-assets",
"reference": "19892fe1ad71039a2ebb52e0c49f5b26e0b24d55"
"reference": "7504a729d11d1850e6d780a5ef5148e377fac2ee"
},
"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": "293eb5af7fd943c8bc0ad504371a32a0fb901567"
"reference": "41b860825a25211894f86b05029aab337dafa9be"
},
"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-backup",
"reference": "e8bac971f2a919cebf6520739569ae0e012d36e5"
"reference": "ad5557d319f2636257a1a466ec2df09d3b1cb170"
},
"require": {
"automattic/jetpack-admin-ui": "^0.4.5",
Expand Down Expand Up @@ -351,7 +351,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-backup-helper-script-manager",
"reference": "45cdc060f27f7f4d75ece389b72bc0447571958f"
"reference": "165509f4fd4e95e1cf3d5b4877e5c56e50ea5943"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -411,7 +411,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-boost-core",
"reference": "a2bb2d11a63810a2fa80ce443b0eb7d7868f276a"
"reference": "a07d33f99887106ef88e5d0999b6133cc1930499"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -479,7 +479,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-boost-speed-score",
"reference": "41d46fdf0e4673d72a98e16bb65d553bfcd9b252"
"reference": "c79da8daa5c7e06c2f1dde212bb51335145c35b2"
},
"require": {
"automattic/jetpack-boost-core": "^0.2.12",
Expand Down Expand Up @@ -555,7 +555,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-composer-plugin",
"reference": "e7729c3c29c7215d75e955528dd06f2f3ba6d98b"
"reference": "d5c70e9df216abfa1cc16f40d1eaf9488da7589f"
},
"require": {
"composer-plugin-api": "^2.1.0",
Expand Down Expand Up @@ -615,7 +615,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-config",
"reference": "b69f723a2121daa8219f3c6f0a2f4beed0f8b25e"
"reference": "706626bca2b4a2b297fe6c5d470b2ddcbc7af81e"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -685,12 +685,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": "4f2bdb5fa3832748a7f01b0d5a84cca5e9d0656f"
"reference": "08b2c60431134bf956eb8da0e3c24f60975a5301"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^2.0.3",
Expand Down Expand Up @@ -780,7 +780,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-constants",
"reference": "74507955788506097686cc639acbaf23fe9cc636"
"reference": "e1767ae0cd0a144c33a18cc2edf11945066f6110"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -834,7 +834,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-device-detection",
"reference": "2f41d55731d09cc6ed3821eea08a1cb9bdef8cdd"
"reference": "def3bdb18446da5eb81019fbe90b5de218c44a7a"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -887,7 +887,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-explat",
"reference": "6262468f941d76d74ab7d0a25b2a73581371e91b"
"reference": "b19b9e3390a47cd85f4a51f95956ae31307c5898"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -962,7 +962,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-ip",
"reference": "29f3797f588050347305fdc04ba36b87022239c5"
"reference": "1d53da27f2d21886e752777c2b0d9f68934992b5"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1020,7 +1020,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-jitm",
"reference": "96f6c08fcaaa6caf3de5e99353677203f0f06d00"
"reference": "633c59700413224926b6408f7939ca57d247bc6f"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^2.0.3",
Expand Down Expand Up @@ -1095,7 +1095,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-licensing",
"reference": "71f791cf3bbbf5ed81b7e427c9509ddb83be131a"
"reference": "84a0cfd9a0816855fbb7120bc1f2aeefa4816264"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -1157,7 +1157,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-logo",
"reference": "b00be05c6034554e47b0d7c45541ac82253be6d7"
"reference": "347264975f067bb70a75019c98cf23458e62f574"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1210,7 +1210,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-my-jetpack",
"reference": "a3936899dd0038a2e68875a773f97f4d9bdbb35a"
"reference": "c39b7b78859ac5429ae925918940c29821478079"
},
"require": {
"automattic/jetpack-admin-ui": "^0.4.5",
Expand Down Expand Up @@ -1312,7 +1312,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-password-checker",
"reference": "b2c871a7dca7b2ea465d954dc43352394b8a170f"
"reference": "509f01f9d7c12f2e8e61bbcaab478160cb0afc81"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1373,7 +1373,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-plans",
"reference": "a43e40d89163ef30328cab172ede9a76a8a03d51"
"reference": "24dcdbc33b136f325b4ae160fdf19cb4f694535c"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -1441,7 +1441,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-plugins-installer",
"reference": "5a9006986fc769c025b23ed0399a64e1c08813b6"
"reference": "2459682f6b560a4e67fb351aae2b82177cec61d5"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^2.0.3",
Expand Down Expand Up @@ -1497,7 +1497,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-protect-models",
"reference": "52db1226faa713ff86ff835d3c44dfd91029ec12"
"reference": "f29f188f49e7330967bc6503bec8be279104223c"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1567,7 +1567,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-protect-status",
"reference": "563abec3b00997fa8aa0854161b803f449cb2dbe"
"reference": "e226c4310b32f3e63c59fe8cc5ad6bfe645d0b43"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down Expand Up @@ -1642,7 +1642,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-redirect",
"reference": "65e26125b0a7fe5f491120534e02db4d59d0d2eb"
"reference": "731d57a3280b5da6b4fb156c8d0dfb1d71bc8c9f"
},
"require": {
"automattic/jetpack-status": "^4.0.2",
Expand Down Expand Up @@ -1697,7 +1697,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-roles",
"reference": "7150e60fe86f27aa8472fca48b6b237de3ee1ae6"
"reference": "66928c655ee207452b5007823327fb6feaf913f5"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -1751,7 +1751,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-status",
"reference": "0be7439775c5e284e201ad924e0b22193a7f8066"
"reference": "e13bc7a606c205398e6547a1900157556e0570e8"
},
"require": {
"automattic/jetpack-constants": "^2.0.4",
Expand Down Expand Up @@ -1815,7 +1815,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-sync",
"reference": "39c78bee8eb276e8eccc3b1c6d526c7b54f7ee95"
"reference": "047c13e02398d78985ef24994872a1fb978a9131"
},
"require": {
"automattic/jetpack-connection": "^5.1.2-alpha",
Expand Down
Loading

0 comments on commit fa6a13f

Please sign in to comment.