我希望自定义“有一个新版本的XYZ可用”插件列表页面上的文本。我知道密码在里面wp-admin/includes/update.php, 然而,我不确定如何调用它或在过滤器/回调中拉出它。基本上,我希望能够在插件中自定义此消息。感谢您的帮助或指导!
自定义插件更新“新版本可用”文本
2 个回复
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
因为文本由_()
当然,您可以使用gettext
滤器
function change_update_notification_msg( $translated_text, $untranslated_text, $domain )
{
if ( is_admin() ) {
$texts = array(
\'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.\' => \'My custom notification. There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.\',
\'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>\' => \'My custom notification. There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>\',
\'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.\' => \'My custom notification. There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.\'
);
if ( array_key_exists( $untranslated_text, $texts ) ) {
return $texts[$untranslated_text];
}
}
return $translated_text;
}
add_filter( \'gettext\', \'change_update_notification_msg\', 20, 3 );
SO网友:Jory Hogeveen
无法立即筛选此文本。您可以通过以下方式附加文本:https://developer.wordpress.org/reference/hooks/in_plugin_update_message-file/