WC_Notes_Run_Db_Update::update_needed_notice
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.
Метод класса: WC_Notes_Run_Db_Update{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = WC_Notes_Run_Db_Update::update_needed_notice( ?Note $note );
- ?Note $note
- .
По умолчанию:null
Код WC_Notes_Run_Db_Update::update_needed_notice() WC Notes Run Db Update::update needed notice WC 10.5.0
private static function update_needed_notice( ?Note $note = null ) {
if ( is_null( $note ) ) {
$note = new Note();
}
$update_url =
add_query_arg(
array(
'do_update_woocommerce' => 'true',
'return_url' => 'wc-admin-referer',
),
admin_url()
);
$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://woocommerce.com/document/how-to-update-woocommerce/',
'status' => 'unactioned',
'primary' => false,
),
);
// Check if the note needs to be updated (e.g. expired nonce or different note type stored in the previous run).
if ( Note::E_WC_ADMIN_NOTE_UNACTIONED === $note->get_status() && self::note_up_to_date( $note, $update_url, wp_list_pluck( $note_actions, 'name' ) ) ) {
return $note;
}
$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'] );
}
}
$note->save();
}