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 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题