函数文档

_local_storage_notice()

💡 云策文档标注

概述

_local_storage_notice() 函数用于输出一个 HTML 通知,提示用户浏览器中存储的帖子备份与当前版本不同,并提供恢复选项。该函数通过 wp_admin_notice() 生成一个可关闭的管理员通知。

关键要点

  • 函数输出一个关于帖子备份恢复的 HTML 通知,包含消息和恢复链接。
  • 使用 wp_admin_notice() 函数来生成管理员通知,并设置相关参数如 id、类、可关闭性等。
  • 消息内容通过 __() 函数进行国际化翻译,支持多语言。
  • 该函数自 WordPress 3.6.0 版本引入。

代码示例

function _local_storage_notice() {
    $local_storage_message  = '';
    $local_storage_message .= __( 'The backup of this post in your browser is different from the version below.' );
    $local_storage_message .= '' . __( 'Restore the backup' ) . '';
    $local_storage_message .= '';
    $local_storage_message .= __( 'This will replace the current editor content with the last backup version. You can use undo and redo in the editor to get the old content back or to return to the restored version.' );
    $local_storage_message .= '';

    wp_admin_notice(
        $local_storage_message,
        array(
            'id'                 => 'local-storage-notice',
            'additional_classes' => array( 'hidden' ),
            'dismissible'        => true,
            'paragraph_wrap'     => false,
        )
    );
}

注意事项

  • 通知默认设置为隐藏(通过 'additional_classes' => array( 'hidden' )),可能需要 JavaScript 或其他逻辑来显示。
  • 使用 __() 函数确保消息可翻译,适合国际化开发。
  • 该函数与 wp_admin_notice() 紧密集成,需确保 wp_admin_notice() 函数可用。

📄 原文内容

Outputs the HTML for restoring the post data from DOM storage

Source

function _local_storage_notice() {
	$local_storage_message  = '<p class="local-restore">';
	$local_storage_message .= __( 'The backup of this post in your browser is different from the version below.' );
	$local_storage_message .= '<button type="button" class="button restore-backup">' . __( 'Restore the backup' ) . '</button></p>';
	$local_storage_message .= '<p class="help">';
	$local_storage_message .= __( 'This will replace the current editor content with the last backup version. You can use undo and redo in the editor to get the old content back or to return to the restored version.' );
	$local_storage_message .= '</p>';

	wp_admin_notice(
		$local_storage_message,
		array(
			'id'                 => 'local-storage-notice',
			'additional_classes' => array( 'hidden' ),
			'dismissible'        => true,
			'paragraph_wrap'     => false,
		)
	);
}

Changelog

Version Description
3.6.0 Introduced.