質問するログイン新規登録

質問編集履歴

2

内容の簡略化

2018/05/20 01:42

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  しかしこれだとすべてのコメントで「identicon」が表示されてしまいます。
9
9
 
10
- そうではなく、管理人のコメントだけは【管理人アバターを表示したいのですけれど、次のような感じでそうする方法はありませんでしょうか?
10
+ そうではなく、管理人のコメントだけは``<?php echo get_avatar(),'100'); ?>``(普通に設定したアバターを表示したいのですけれど、次のような感じで条件分岐する方法はありませんでしょうか?
11
11
 
12
12
  ```php
13
13
  <div class="author_img">
@@ -17,77 +17,4 @@
17
17
  <?php echo get_avatar(),'100'); ?>
18
18
  }
19
19
  </div>
20
- ```
21
- ▼【管理人アバター】をfunctions.phpで登録
22
-
23
- ```php
24
- //プロフィール画面で設定したプロフィール画像
25
- if ( !function_exists( 'get_the_author_upladed_avatar_url_demo' ) ):
26
- function get_the_author_upladed_avatar_url_demo($user_id){
27
- if (!$user_id) {
28
- $user_id = get_the_posts_author_id();
29
- }
30
- return esc_html(get_the_author_meta('upladed_avatar', $user_id));
31
- }
32
- endif;
33
-
34
- //ユーザー情報追加
35
- add_action('show_user_profile', 'add_avatar_to_user_profile_demo');
36
- add_action('edit_user_profile', 'add_avatar_to_user_profile_demo');
37
- if ( !function_exists( 'add_avatar_to_user_profile_demo' ) ):
38
- function add_avatar_to_user_profile_demo($user) {
39
- ?>
40
- <h3>プロフィール画像</h3>
41
- <table class="form-table">
42
- <tr>
43
- <th>
44
- <label for="avatar">プロフィール画像URL</label>
45
- </th>
46
- <td>
47
- <input type="text" name="upladed_avatar" size="70" value="<?php echo get_the_author_upladed_avatar_url_demo($user->ID); ?>" placeholder="画像URLを入力してください">
48
- <p class="description">Gravatarよりこちらのプロフィール画像が優先されます。240×240pxの正方形の画像がお勧めです。</p>
49
- </td>
50
- </tr>
51
- </table>
52
- <?php
53
- }
54
- endif;
55
-
56
- //入力した値を保存する
57
- add_action('personal_options_update', 'update_avatar_to_user_profile_demo');
58
- if ( !function_exists( 'update_avatar_to_user_profile_demo' ) ):
59
- function update_avatar_to_user_profile_demo($user_id) {
60
- if ( current_user_can('edit_user',$user_id) ){
61
- update_user_meta($user_id, 'upladed_avatar', $_POST['upladed_avatar']);
62
- }
63
- }
64
- endif;
65
-
66
- //プロフィール画像を変更する
67
- add_filter( 'get_avatar' , 'get_uploaded_user_profile_avatar_demo' , 1 , 5 );
68
- if ( !function_exists( 'get_uploaded_user_profile_avatar_demo' ) ):
69
-
70
- function get_uploaded_user_profile_avatar_demo( $avatar, $id_or_email, $size, $default, $alt ) {
71
- if ( is_numeric( $id_or_email ) )
72
- $user_id = (int) $id_or_email;
73
- elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) )
74
- $user_id = $user->ID;
75
- elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) )
76
- $user_id = (int) $id_or_email->user_id;
77
-
78
- if ( empty( $user_id ) )
79
- return $avatar;
80
-
81
- if (get_the_author_upladed_avatar_url_demo($user_id)) {
82
- $alt = !empty($alt) ? $alt : get_the_author_meta( 'display_name', $user_id );;
83
- $author_class = is_author( $user_id ) ? ' current-author' : '' ;
84
- $avatar = "<img alt='" . esc_attr( $alt ) . "' src='" . esc_url( get_the_author_upladed_avatar_url_demo($user_id) ) . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";
85
- }
86
-
87
- return $avatar;
88
- }
89
- endif;
90
- ```
91
-
92
- 上のコードは「寝ログ」さんからのコピペですm(_ _)m
93
- [https://nelog.jp/wordpress-original-profile-image-custom](https://nelog.jp/wordpress-original-profile-image-custom)
20
+ ```

1

ごじ

2018/05/20 01:42

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -5,12 +5,13 @@
5
5
  </div>
6
6
  ```
7
7
 
8
- これを「管理人けは【管理人アバター】を表示したい」思っいるですが、次のードはうせんでした
8
+ しかしこれだとすべてのコメント「identicon」が表示されてしまいま
9
9
 
10
- たか正しい書き方を教えて頂けませんでしょうか?
10
+ そうではく、管理人のコメントだけは【管理人アバター】を表示のですれど、次のような感じでそうする方法はありませんでしょうか?
11
+
11
12
  ```php
12
13
  <div class="author_img">
13
- if ( !current_user_can( 'administrator' ) ) {
14
+ if ( 管理人以外のコメントなら ) {
14
15
  <?php echo gravatarToID($comment->comment_author, 100, 'identicon'); ?>
15
16
  } else {
16
17
  <?php echo get_avatar(),'100'); ?>