disable_mo_loading = $disable_mo_loading; $this->queue = $queue; $this->notices = $notices; $this->wpml_wp_api = $wpml_ap_api; } public function init_notices() { if ( $this->disable_mo_loading ) { $this->handle_queue_notices(); } else { $this->remove_all_notices(); } } private function handle_queue_notices() { $data = array(); if ( $this->queue->is_completed() ) { $messages = array(); $display_second_notice = true; $processed_files = $this->queue->get_processed(); if ( $processed_files ) { $data[] = '
' . implode( '
', $messages ) . '
'; $notice = $this->notices->create_notice( self::NOTICES_MO_LOADING_DISABLED, $message, self::NOTICES_GROUP ); $notice->set_hide_if_notice_exists( self::NOTICES_MO_SCANNING, self::NOTICES_GROUP ); $this->add_notice( $notice ); return; } $message = vsprintf( '' . implode( '
', $messages ) . '
', $data ); $notice = $this->notices->create_notice( self::NOTICES_MO_SCANNING, $message, self::NOTICES_GROUP ); if ( $display_second_notice ) { $this->remove_first_notice(); $notice->reset_dismiss(); } $this->add_notice( $notice ); } /** * @param WPML_Notice $notice */ private function add_notice( WPML_Notice $notice ) { $restricted_pages = array( WPML_PLUGIN_FOLDER . '/menu/languages.php', WPML_PLUGIN_FOLDER . '/menu/theme-localization.php', ); foreach ( $restricted_pages as $restricted_page ) { $notice->add_restrict_to_page( $restricted_page ); } $notice->set_css_class_types( 'info' ); $notice->set_dismissible( true ); $notice->add_display_callback( array( __CLASS__, 'only_display_notice_if_this_class_exists' ) ); $this->notices->add_notice( $notice ); } private function remove_first_notice() { $first_notice = $this->notices->get_notice( self::NOTICES_MO_LOADING_DISABLED, self::NOTICES_GROUP ); if ( $first_notice && ! $this->notices->is_notice_dismissed( $first_notice ) ) { $this->notices->dismiss_notice( $first_notice, true ); } } private function remove_all_notices() { $notices_to_remove = array( self::NOTICES_MO_LOADING_DISABLED, self::NOTICES_MO_SCANNING, ); foreach ( $notices_to_remove as $notice_id ) { if ( $this->notices->get_notice( $notice_id, self::NOTICES_GROUP ) ) { $this->notices->remove_notice( self::NOTICES_GROUP, $notice_id ); } } } /** @return bool */ public static function only_display_notice_if_this_class_exists() { return true; } }