$highlight ) { if ( isset( $storage['muted'][ $slug ] ) ) { continue; } $filters = $highlight; if ( isset( $storage['markers'][ $slug ] ) ) { $filters['__min_timestamp'] = $storage['markers'][ $slug ]; } if ( $entries = ITSEC_Log::get_entries( $filters, 1, 1, 'id', 'DESC', 'all' ) ) { $items[ $slug ] = $entries[0]; } } if ( $storage['highlighted'] ) { $entries = ITSEC_Log::get_entries( array( 'id' => array_flip( $storage['highlighted'] ) ) ); $items = array_merge( $items, $entries ); } return $items; } /** * Dismiss a highlighted log item. * * @param int|string $id_or_slug Either the log id or the dynamic highlight slug. * * @return bool */ public static function dismiss_highlight( $id_or_slug ) { $storage = self::get_storage(); if ( is_int( $id_or_slug ) ) { if ( isset( $storage['highlighted'][ $id_or_slug ] ) ) { unset( $storage['highlighted'][ $id_or_slug ] ); return self::save_storage( $storage ); } return true; } $storage['markers'][ $id_or_slug ] = ITSEC_Core::get_current_time_gmt(); return self::save_storage( $storage ); } /** * Mute a dynamic highlighted log. * * Muted items won't ever be returned in {@see ITSEC_Lib_Highlighted_Logs::get_highlights()}. * * @param string $slug Dynamic highlight slug. * * @return bool */ public static function mute( $slug ) { $storage = self::get_storage(); $storage['muted'][ $slug ] = ITSEC_Core::get_current_time_gmt(); return self::save_storage( $storage ); } /** * Unmute a dynamic highlighted log. * * @param string $slug Dynamic highlight slug. * * @return bool */ public static function unmute( $slug ) { $storage = self::get_storage(); unset( $storage['muted'][ $slug ] ); return self::save_storage( $storage ); } /** * Is the given dynamic highlight muted. * * @param string $slug * * @return bool */ public static function is_muted( $slug ) { $storage = self::get_storage(); return ! empty( $storage['muted'][ $slug ] ); } /** * Get a list of all the registered dynamic highlights. * * On first call, this will fire an action to register the highlights. * * @return array */ public static function get_dynamics() { if ( ! self::$initialized ) { do_action( 'itsec_register_highlighted_logs' ); self::$initialized = true; } return self::$dynamics; } /** * Get the storage data. * * @return array */ private static function get_storage() { return get_site_option( self::OPTION, array( 'highlighted' => array(), 'markers' => array(), 'muted' => array(), ) ); } /** * Update the storage data. * * @param array $storage * * @return bool */ private static function save_storage( array $storage ) { return update_site_option( self::OPTION, $storage ); } }