回答編集履歴
2
コメント加筆
answer
CHANGED
@@ -3,13 +3,18 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
```php
|
6
|
-
|
6
|
+
//入力項目をプロフィール画面に追加
|
7
|
+
//自分のプロフィール・他人のプロフィールの両方で走るようにフックを分岐する
|
7
8
|
add_action(($GLOBALS['pagenow']==='profile.php'?'show':'edit').'_user_profile',function($user){
|
9
|
+
//user_metaは$userオブジェクトのプロパティとして取得できるようになっている
|
10
|
+
//user_metaにはhtmlがエスケープされて入っているのでデコードしてからwp_editorに渡す
|
8
11
|
wp_editor(html_entity_decode($user->profile_html??''),'profile_html');
|
9
12
|
});
|
10
|
-
|
13
|
+
//プロフィール更新時にuser_metaを更新
|
11
14
|
add_action('profile_update',function($user_id){
|
15
|
+
//複数回profile_updateが走ることがあるので2回目以降は処理をスキップする
|
12
16
|
if(did_action('profile_update')>1){return;}
|
17
|
+
//profile_htmlが送られてきていたらuser_metaを更新
|
13
18
|
if(isset($_POST['profile_html'])){
|
14
19
|
update_user_meta($user_id,'profile_html',$_POST['profile_html']);
|
15
20
|
}
|
1
追記
answer
CHANGED
@@ -1,2 +1,22 @@
|
|
1
1
|
[edit_user_profile](https://developer.wordpress.org/reference/hooks/edit_user_profile/)のフィルタフックで[wp_editor](https://wpdocs.osdn.jp/関数リファレンス/wp_editor)を使ってユーザープロファイルページにtinymceの入力項目を追加
|
2
|
-
[profile_update](https://developer.wordpress.org/reference/hooks/profile_update/)で送信された値を受け取って[update_user_meta](https://wpdocs.osdn.jp/関数リファレンス/update_user_meta)
|
2
|
+
[profile_update](https://developer.wordpress.org/reference/hooks/profile_update/)で送信された値を受け取って[update_user_meta](https://wpdocs.osdn.jp/関数リファレンス/update_user_meta)
|
3
|
+
|
4
|
+
|
5
|
+
```php
|
6
|
+
|
7
|
+
add_action(($GLOBALS['pagenow']==='profile.php'?'show':'edit').'_user_profile',function($user){
|
8
|
+
wp_editor(html_entity_decode($user->profile_html??''),'profile_html');
|
9
|
+
});
|
10
|
+
|
11
|
+
add_action('profile_update',function($user_id){
|
12
|
+
if(did_action('profile_update')>1){return;}
|
13
|
+
if(isset($_POST['profile_html'])){
|
14
|
+
update_user_meta($user_id,'profile_html',$_POST['profile_html']);
|
15
|
+
}
|
16
|
+
});
|
17
|
+
```
|
18
|
+
|
19
|
+
とりあえず動くものレベルではこんな感じ
|
20
|
+
|
21
|
+
あとはnonceつけてCSRF対策とか
|
22
|
+
scriptタグstyleタグon〜属性style属性を除去してXSS対策とか
|