dongwen2896 2015-04-02 08:50
浏览 46
已采纳

更新用户配置文件时执行插件功能

I wrote a Wordpress plugin with several functions in it. This plugin works as expected and all functions do their job. Now I need to call one of the plugin's functions when a user updates his profile.

I tried the following piece of code within my plugin, but it didn't work.

add_action( 'profile_update', 'myfunction');

What is the best practice to use Wordpress hooks? How can I call the function from my plugin when a user profile is updated?

here the strucure of my little plugin:

<?php
/*
Plugin Name: myplugin
*/
add_action( 'admin_menu', 'myplugin' );

function myplugin() {
add_options_page( 'myplugin', 'myplugin', 'manage_options', 'myplugin_id', 'myplugin_options' );
}
function myplugin() {
if ( !current_user_can( 'manage_options' ) )  {
    wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
?>
<div class="wrap">
<?php    echo "<h2>" . 'Galette users sync' . "</h2>"; ?>

<form name="galette" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
    <input type="submit" name="Submit" value="Mise à jour" />
</form>
<?php
function function1() {
    stuff
}
function function2() {
    stuff
}
function function3() {
    stuff
}
function function4() {
    stuff
}
if($_SERVER['REQUEST_METHOD']=='POST')
{
       function4();
} 
echo '</div>';
}

?>

And I want to call function2() when a user update a profile

Any Help someone?

  • 写回答

1条回答 默认 最新

  • douzhoulei8959 2015-04-02 09:00
    关注

    You have too hook into one or two hooks:

    //is run when you edit YOUR profile, and save it
    add_action( 'personal_options_update', 'function2' );
    //is run when you edit ANY OTHER profile and save it
    add_action( 'edit_user_profile_update', 'function2' );
    

    Read more about hooks here: http://codex.wordpress.org/Plugin_API/Hooks

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题