id, array( 'jetpack_page_akismet-key-config', 'admin_page_jetpack_modules', ), true ) ) { return; } /* * phpcs:disable WordPress.Security.NonceVerification.Recommended * * This function is firing within wp-admin and checks (below) if it is in the midst of a deletion on the users * page. Nonce will be already checked by WordPress, so we do not need to check ourselves. */ 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(); if ( ! $connection_owner_id ) { return; } $connection_owner_userdata = get_userdata( $connection_owner_id ); // Bail if we're not trying to delete connection owner. $user_ids_to_delete = array(); if ( isset( $_REQUEST['users'] ) ) { $user_ids_to_delete = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['users'] ) ); } elseif ( isset( $_REQUEST['user'] ) ) { $user_ids_to_delete[] = sanitize_text_field( wp_unslash( $_REQUEST['user'] ) ); } // phpcs:enable $user_ids_to_delete = array_map( 'absint', $user_ids_to_delete ); $deleting_connection_owner = in_array( $connection_owner_id, (array) $user_ids_to_delete, true ); if ( ! $deleting_connection_owner ) { return; } // Bail if they're trying to delete themselves to avoid confusion. if ( get_current_user_id() === $connection_owner_id ) { return; } $tracking = new Tracking(); // Track it! if ( method_exists( $tracking, 'record_user_event' ) ) { $tracking->record_user_event( 'delete_connection_owner_notice_view' ); } $connected_admins = $connection_manager->get_connected_users( 'jetpack_disconnect' ); $user = is_a( $connection_owner_userdata, 'WP_User' ) ? esc_html( $connection_owner_userdata->data->user_login ) : ''; echo "
"; echo '

' . esc_html__( 'Important notice about your Jetpack connection:', 'jetpack-connection' ) . '

'; echo '

' . sprintf( /* translators: WordPress User, if available. */ esc_html__( 'Warning! You are about to delete the Jetpack connection owner (%s) for this site, which may cause some of your Jetpack features to stop working.', 'jetpack-connection' ), esc_html( $user ) ) . '

'; if ( ! empty( $connected_admins ) && count( $connected_admins ) > 1 ) { echo '
'; echo "'; $connected_admin_ids = array_map( function ( $connected_admin ) { return $connected_admin->ID; }, $connected_admins ); wp_dropdown_users( array( 'name' => 'owner', 'include' => array_diff( $connected_admin_ids, array( $connection_owner_id ) ), 'show' => 'display_name_with_login', ) ); echo '

'; submit_button( esc_html__( 'Set new connection owner', 'jetpack-connection' ), 'primary', 'jp-switch-connection-owner-submit', false ); echo '

'; echo "
"; echo '
'; ?> ' . esc_html__( 'Every Jetpack site needs at least one connected admin for the features to work properly. Please connect to your WordPress.com account via the button below. Once you connect, you may refresh this page to see an option to change the connection owner.', 'jetpack-connection' ) . '

'; $connect_url = $connection_manager->get_authorization_url(); $connect_url = add_query_arg( 'from', 'delete_connection_owner_notice', $connect_url ); echo "" . esc_html__( 'Connect to WordPress.com', 'jetpack-connection' ) . ''; } echo '

'; printf( wp_kses( /* translators: URL to Jetpack support doc regarding the primary user. */ __( "Learn more about the connection owner and what will break if you do not have one.", 'jetpack-connection' ), array( 'a' => array( 'href' => true, 'target' => true, 'rel' => true, ), ) ), esc_url( Redirect::get_url( 'jetpack-support-primary-user' ) ) ); echo '

'; echo '

'; printf( wp_kses( /* translators: URL to contact Jetpack support. */ __( 'As always, feel free to contact our support team if you have any questions.', 'jetpack-connection' ), array( 'a' => array( 'href' => true, 'target' => true, 'rel' => true, ), ) ), esc_url( Redirect::get_url( 'jetpack-contact-support' ) ) ); echo '

'; echo '
'; } }