WordPress at Your Fingertips
function is not described

WC_Notes_Run_Db_Update::update_needed_notice() private WC 1.0

Create and set up the first (out of 3) 'Database update needed' notice and store it in the database.

If a $note_id is given, the method updates the note instead of creating a new one.

{} It's a method of the class: WC_Notes_Run_Db_Update{}

No Hooks.

Return

Int. Created/Updated note id

Usage

$result = WC_Notes_Run_Db_Update::update_needed_notice( $note_id );
$note_id(int)
Note db record to update.
Default: null

Code of WC_Notes_Run_Db_Update::update_needed_notice() WC 5.9.0

private static function update_needed_notice( $note_id = null ) {
	$update_url =
		add_query_arg(
			array(
				'do_update_woocommerce' => 'true',
			),
			wc_get_current_admin_url() ? wc_get_current_admin_url() : admin_url( 'admin.php?page=wc-settings' )
		);

	$note_actions = array(
		array(
			'name'         => 'update-db_run',
			'label'        => __( 'Update WooCommerce Database', 'woocommerce' ),
			'url'          => $update_url,
			'status'       => 'unactioned',
			'primary'      => true,
			'nonce_action' => 'wc_db_update',
			'nonce_name'   => 'wc_db_update_nonce',
		),
		array(
			'name'    => 'update-db_learn-more',
			'label'   => __( 'Learn more about updates', 'woocommerce' ),
			'url'     => 'https://docs.woocommerce.com/document/how-to-update-woocommerce/',
			'status'  => 'unactioned',
			'primary' => false,
		),
	);

	if ( $note_id ) {
		$note = new Note( $note_id );
	} else {
		$note = new Note();
	}

	// Check if the note needs to be updated (e.g. expired nonce or different note type stored in the previous run).
	if ( self::note_up_to_date( $note, $update_url, wp_list_pluck( $note_actions, 'name' ) ) ) {
		return $note_id;
	}

	$note->set_title( __( 'WooCommerce database update required', 'woocommerce' ) );
	$note->set_content(
		__( 'WooCommerce has been updated! To keep things running smoothly, we have to update your database to the newest version.', 'woocommerce' )
		/* translators: %1$s: opening <a> tag %2$s: closing </a> tag*/
		. sprintf( ' ' . esc_html__( 'The database update process runs in the background and may take a little while, so please be patient. Advanced users can alternatively update via %1$sWP CLI%2$s.', 'woocommerce' ), '<a href="https://github.com/woocommerce/woocommerce/wiki/Upgrading-the-database-using-WP-CLI">', '</a>' )
	);
	$note->set_type( Note::E_WC_ADMIN_NOTE_UPDATE );
	$note->set_name( self::NOTE_NAME );
	$note->set_content_data( (object) array() );
	$note->set_source( 'woocommerce-core' );
	// In case db version is out of sync with WC version or during the next update, the notice needs to show up again,
	// so set it to unactioned.
	$note->set_status( Note::E_WC_ADMIN_NOTE_UNACTIONED );

	// Set new actions.
	$note->clear_actions();
	foreach ( $note_actions as $note_action ) {
		$note->add_action( ...array_values( $note_action ) );

		if ( isset( $note_action['nonce_action'] ) ) {
			$note->add_nonce_to_action( $note_action['name'], $note_action['nonce_action'], $note_action['nonce_name'] );
		}
	}

	return $note->save();
}