$unit, 'via' => 'updater', 'rows' => $forgotten, ) ); } return $response; } /** * Whether there is a baseline to keep: the site has scanned at least * once. Before that there is nothing to reset, and no row to write. */ private static function enabled(): bool { return Scanner::established() || Scanner::is_running(); } /** * The unit an upgrader package is, or null for one that is not a plugin * or theme directory (core, translations, a single-file plugin). * * @param array $hook_extra Upgrader context. * @param array $result Install result. */ public static function unit_for( array $hook_extra, array $result ): ?string { $type = ''; $slug = ''; if ( isset( $hook_extra['plugin'] ) && is_string( $hook_extra['plugin'] ) ) { $type = 'plugin'; $slug = false !== strpos( $hook_extra['plugin'], '/' ) ? dirname( $hook_extra['plugin'] ) : ''; } elseif ( isset( $hook_extra['theme'] ) && is_string( $hook_extra['theme'] ) ) { $type = 'theme'; $slug = $hook_extra['theme']; } elseif ( isset( $hook_extra['type'] ) && in_array( $hook_extra['type'], array( 'plugin', 'theme' ), true ) ) { // A fresh install names its package only in the result. $type = (string) $hook_extra['type']; $slug = isset( $result['destination_name'] ) && is_string( $result['destination_name'] ) ? $result['destination_name'] : ''; } if ( '' === $type || '' === $slug || ! Comparison::is_safe_relative( $slug ) || false !== strpos( $slug, '/' ) ) { return null; } return $type . ':' . $slug; } }