context = $context; $this->message = $message; $this->add_message(); } /** * Adds the message to an option. * This option will later be deleted as soon as it's displayed. * * @access private * @since 5.0.0 * @see Fusion_Patcher_Admin_Screen::form for the option deletion process. * @return void */ private function add_message() { // Get the option. $messages = self::get_messages(); // Add the message to the array of messages to display. if ( ! isset( $messages[ $this->context ] ) ) { $messages[ $this->context ] = $this->message; } // Update the option. update_site_option( self::$option_name, $messages ); } /** * Gets an array of all messages. * * @static * @access public * @return array */ public static function get_messages() { // Get the option. $messages = get_site_option( self::$option_name, [] ); // Make sure the option is formatted as an array. // If not an array, then return an empty array to avoid errors. if ( ! is_array( $messages ) ) { return []; } return $messages; } /** * Deletes the messages option. * * @static * @access public * @since 5.0.0 * @param string|false $context Since 5.0.2 the message to be removed. * @return void */ public static function remove_messages_option( $context = false ) { // If context is false, then delete everything. if ( false === $context ) { delete_site_option( self::$option_name ); return; } $options = get_site_option( self::$option_name, [] ); if ( is_array( $options ) && isset( $options[ $context ] ) ) { unset( $options[ $context ] ); } update_site_option( self::$option_name, $options ); } }