質問編集履歴

2

内容の簡略化

2018/05/20 01:42

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- そうではなく、管理人のコメントだけは【管理人アバターを表示したいのですけれど、次のような感じでそうする方法はありませんでしょうか?
19
+ そうではなく、管理人のコメントだけは``<?php echo get_avatar(),'100'); ?>``(普通に設定したアバターを表示したいのですけれど、次のような感じで条件分岐する方法はありませんでしょうか?
20
20
 
21
21
 
22
22
 
@@ -37,149 +37,3 @@
37
37
  </div>
38
38
 
39
39
  ```
40
-
41
- ▼【管理人アバター】をfunctions.phpで登録
42
-
43
-
44
-
45
- ```php
46
-
47
- //プロフィール画面で設定したプロフィール画像
48
-
49
- if ( !function_exists( 'get_the_author_upladed_avatar_url_demo' ) ):
50
-
51
- function get_the_author_upladed_avatar_url_demo($user_id){
52
-
53
- if (!$user_id) {
54
-
55
- $user_id = get_the_posts_author_id();
56
-
57
- }
58
-
59
- return esc_html(get_the_author_meta('upladed_avatar', $user_id));
60
-
61
- }
62
-
63
- endif;
64
-
65
-
66
-
67
- //ユーザー情報追加
68
-
69
- add_action('show_user_profile', 'add_avatar_to_user_profile_demo');
70
-
71
- add_action('edit_user_profile', 'add_avatar_to_user_profile_demo');
72
-
73
- if ( !function_exists( 'add_avatar_to_user_profile_demo' ) ):
74
-
75
- function add_avatar_to_user_profile_demo($user) {
76
-
77
- ?>
78
-
79
- <h3>プロフィール画像</h3>
80
-
81
- <table class="form-table">
82
-
83
- <tr>
84
-
85
- <th>
86
-
87
- <label for="avatar">プロフィール画像URL</label>
88
-
89
- </th>
90
-
91
- <td>
92
-
93
- <input type="text" name="upladed_avatar" size="70" value="<?php echo get_the_author_upladed_avatar_url_demo($user->ID); ?>" placeholder="画像URLを入力してください">
94
-
95
- <p class="description">Gravatarよりこちらのプロフィール画像が優先されます。240×240pxの正方形の画像がお勧めです。</p>
96
-
97
- </td>
98
-
99
- </tr>
100
-
101
- </table>
102
-
103
- <?php
104
-
105
- }
106
-
107
- endif;
108
-
109
-
110
-
111
- //入力した値を保存する
112
-
113
- add_action('personal_options_update', 'update_avatar_to_user_profile_demo');
114
-
115
- if ( !function_exists( 'update_avatar_to_user_profile_demo' ) ):
116
-
117
- function update_avatar_to_user_profile_demo($user_id) {
118
-
119
- if ( current_user_can('edit_user',$user_id) ){
120
-
121
- update_user_meta($user_id, 'upladed_avatar', $_POST['upladed_avatar']);
122
-
123
- }
124
-
125
- }
126
-
127
- endif;
128
-
129
-
130
-
131
- //プロフィール画像を変更する
132
-
133
- add_filter( 'get_avatar' , 'get_uploaded_user_profile_avatar_demo' , 1 , 5 );
134
-
135
- if ( !function_exists( 'get_uploaded_user_profile_avatar_demo' ) ):
136
-
137
-
138
-
139
- function get_uploaded_user_profile_avatar_demo( $avatar, $id_or_email, $size, $default, $alt ) {
140
-
141
- if ( is_numeric( $id_or_email ) )
142
-
143
- $user_id = (int) $id_or_email;
144
-
145
- elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) )
146
-
147
- $user_id = $user->ID;
148
-
149
- elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) )
150
-
151
- $user_id = (int) $id_or_email->user_id;
152
-
153
-
154
-
155
- if ( empty( $user_id ) )
156
-
157
- return $avatar;
158
-
159
-
160
-
161
- if (get_the_author_upladed_avatar_url_demo($user_id)) {
162
-
163
- $alt = !empty($alt) ? $alt : get_the_author_meta( 'display_name', $user_id );;
164
-
165
- $author_class = is_author( $user_id ) ? ' current-author' : '' ;
166
-
167
- $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}' />";
168
-
169
- }
170
-
171
-
172
-
173
- return $avatar;
174
-
175
- }
176
-
177
- endif;
178
-
179
- ```
180
-
181
-
182
-
183
- 上のコードは「寝ログ」さんからのコピペですm(_ _)m
184
-
185
- [https://nelog.jp/wordpress-original-profile-image-custom](https://nelog.jp/wordpress-original-profile-image-custom)

1

ごじ

2018/05/20 01:42

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -12,17 +12,19 @@
12
12
 
13
13
 
14
14
 
15
- これを「管理人けは【管理人アバター】を表示したい」思っいるので、次のコードではうせんでした
15
+ しかしこれだとすべてのコメント「identicon」表示されてしまいま
16
16
 
17
17
 
18
18
 
19
- なたか正し書きを教えて頂けませんでしょうか?
19
+ そうではく、管理人のコメントだけは【管理人アバター】を表示したいのですけれど、次のような感じでそうする法はありませんでしょうか?
20
+
21
+
20
22
 
21
23
  ```php
22
24
 
23
25
  <div class="author_img">
24
26
 
25
- if ( !current_user_can( 'administrator' ) ) {
27
+ if ( 管理人以外のコメントなら ) {
26
28
 
27
29
  <?php echo gravatarToID($comment->comment_author, 100, 'identicon'); ?>
28
30