繁体   English   中英

在简单本地化WordPress插件中成功上传后,如何重新加载页面?

[英]How to reload the page after successful upload in the Simple Local Avatars WordPress plugin?

我正在使用“ 简单本地头像”来允许我的博客作者上传头像。

我的目的是在成功上传后刷新页面。 我的第一个想法是查看simple-local-avatars.php源代码中的动作挂钩。 我希望在edit_user_profile_update方法的末尾有一个钩子,例如avatar_upload_success ,但是没有类似的东西可用。 因此,我需要找到另一种刷新页面的方法。

成功上传后,我还能如何刷新页面?

更新:为了使我的问题更清楚一点,我的问题不是如何重新加载页面,我的问题是仅在成功上传后如何重新加载页面。 例如:在上传失败时,我不想重新加载。

更新2:所以我的下一个尝试是做这样的事情:

function simple_local_avatar_reload() {
    $url = 'whatever the current page is';
    wp_redirect( $url );
    exit();
}
add_action( 'edit_user_profile_update', 'simple_local_avatar_reload', 99 );

但这会导致可怕的“已发送标题”错误。

我的解决方案是有条件地启用输出缓冲,然后在edit_user_profile_update完成后执行页面刷新。 例如:

/**
 * Enable output buffering.
*/
function output_buffer() {
    if ( isset ( $_POST['submit'] ) )
        ob_start();
}
add_action( 'init', 'output_buffer' );

/**
 * Refresh page after avatar upload.
*/
function simple_local_avatar_reload() {
    header( 'Location: ' . $_SERVER['REQUEST_URI'] );
}
add_action( 'edit_user_profile_update', 'simple_local_avatar_reload', 99 );

注意:即使上传失败,此操作也会重新加载。 但这是一个解决方法,除非我修改插件的核心(我不想这样做),否则我将不得不使用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM