WC_Notes_Run_Db_Update::get_current_notice()private staticWC 1.0

Get current notice id from the database.

Retrieves the first notice of this type.

Метод класса: WC_Notes_Run_Db_Update{}

Хуков нет.

Возвращает

int|null. Note id or null in case no note was found.

Использование

$result = WC_Notes_Run_Db_Update::get_current_notice();

Код WC_Notes_Run_Db_Update::get_current_notice() WC 8.7.0

private static function get_current_notice() {
	try {
		$data_store = \WC_Data_Store::load( 'admin-note' );
	} catch ( Exception $e ) {
		return;
	}
	$note_ids = $data_store->get_notes_with_name( self::NOTE_NAME );

	if ( empty( $note_ids ) ) {
		return;
	}

	if ( count( $note_ids ) > 1 ) {
		// Remove weird duplicates. Leave the first one.
		$current_notice = array_shift( $note_ids );
		foreach ( $note_ids as $note_id ) {
			$note = new Note( $note_id );
			$data_store->delete( $note );
		}
		return $current_notice;
	}

	return current( $note_ids );
}