exists() ) { $functions = path_join( $theme->get_stylesheet_directory(), 'functions.php' ); if ( file_exists( $functions ) ) { $files[] = wp_normalize_path( $functions ); } } // Each active plugin's main file. $plugins_dir = self::plugins_directory(); $active = (array) get_option( 'active_plugins', array() ); foreach ( $active as $plugin ) { $path = path_join( $plugins_dir, $plugin ); if ( file_exists( $path ) ) { $files[] = wp_normalize_path( $path ); } } return APWPM_Compat::filter( 'apwpm_file_integrity_targets', 'ap_file_integrity_targets', array_values( array_unique( $files ) ) ); } public static function scan() { $prev = (array) get_option( self::OPTION, array() ); $now = array(); foreach ( self::targets() as $file ) { if ( ! is_readable( $file ) ) { continue; } $h = md5_file( $file ); if ( false === $h ) { continue; } $now[ $file ] = $h; if ( isset( $prev[ $file ] ) && $prev[ $file ] !== $h ) { APWPM_Logger::log( array( 'action_type' => 'file_changed', 'object_type' => 'file', 'object_title' => self::relative_path( $file ), 'description' => sprintf( /* translators: %s: file path */ __( 'File modified on disk: %s', 'activitypilot' ), self::relative_path( $file ) ), 'severity' => 'critical', 'context' => array( 'path' => $file, 'old_hash' => $prev[ $file ], 'new_hash' => $h, ), ) ); } elseif ( ! isset( $prev[ $file ] ) && ! empty( $prev ) ) { APWPM_Logger::log( array( 'action_type' => 'file_added', 'object_type' => 'file', 'object_title' => self::relative_path( $file ), 'description' => sprintf( /* translators: %s: file path */ __( 'New file appeared on disk: %s', 'activitypilot' ), self::relative_path( $file ) ), 'severity' => 'warning', ) ); } } // Detect deletions. foreach ( $prev as $file => $h ) { if ( ! isset( $now[ $file ] ) ) { APWPM_Logger::log( array( 'action_type' => 'file_deleted', 'object_type' => 'file', 'object_title' => self::relative_path( $file ), 'description' => sprintf( /* translators: %s: file path */ __( 'File deleted from disk: %s', 'activitypilot' ), self::relative_path( $file ) ), 'severity' => 'critical', ) ); } } update_option( self::OPTION, $now, false ); } }