22
33/**
44 ** get_avatar.php
5- ** @version 1.2
5+ ** @version 1.2.1
66 ** @since 1.0
77 ** @author en0ndev
88 */
2929$ get__commenter__indx__bfr = null ;
3030$ get__commenter__indx__aft = null ;
3131$ get__commenter__indx__vrf = 0 ;
32- $ get__commenter__indx = 0 ;
32+ // $get__commenter__indx = 0;
3333
3434function cpa__start__values ()
3535{
3636 global $ current_user , $ get__commenter__indx ;
37- $ get__commenter__indx = (! get_user_meta ( $ current_user -> ID , ' custom_profile_avatar ' )[ 0 ]) ? ((! is_admin ()) ? - 1 : - 2 ) : 0 ;
37+ $ get__commenter__indx = 0 ;
3838}
3939add_action ("init " , "cpa__start__values " );
4040
@@ -89,6 +89,10 @@ function compare__comment__id($a, $b)
8989 require_once ABSPATH . '/wp-admin/includes/screen.php ' ;
9090}
9191
92+ if (!class_exists ('WP_Screen ' )) {
93+ require_once ABSPATH . '/wp-admin/includes/class-wp-screen.php ' ;
94+ }
95+
9296if (!function_exists ('get_avatar ' )) {
9397 function get_avatar ($ id_or_email , $ size = 96 , $ default = '' , $ alt = '' , $ args = null )
9498 {
@@ -159,22 +163,41 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
159163
160164 $ comments__author__id__array = array ();
161165 $ comments__id__array = array ();
166+ $ getCommentArr = array ();
167+
168+ if (is_admin () && isset ($ _GET ["p " ])) {
169+ $ getCommentArr ["post_id " ] = $ _GET ["p " ];
170+ }
162171
163172 if (is_single () || is_page () || is_singular ()) {
164- $ get__comments = get_comments (array ('post_id ' => $ post ->ID ));
173+ $ get__comments = get_comments (array ('post_id ' => $ post ->ID , " status " => " approve " ));
165174 usort ($ get__comments , 'compare__comment__id ' );
166175 } else if (is_admin () && isset ($ _GET ['user_id ' ])) {
167- $ get__comments = get_comments (array ('user_id ' => $ _GET ['user_id ' ]));
176+ $ get__comments = get_comments ($ getCommentArr = array ('user_id ' => $ _GET ['user_id ' ]));
177+ } else if (is_admin () && $ _GET ['comment_status ' ] == "moderated " ) {
178+ $ getCommentArr ["status " ] = "hold " ;
179+ $ get__comments = get_comments ($ getCommentArr );
180+ } else if (is_admin () && $ _GET ['comment_status ' ] == "trash " ) {
181+ $ getCommentArr ["status " ] = "trash " ;
182+ $ get__comments = get_comments ($ getCommentArr );
183+ } else if (is_admin () && $ _GET ['comment_status ' ] == "spam " ) {
184+ $ getCommentArr ["status " ] = "spam " ;
185+ $ get__comments = get_comments ($ getCommentArr );
186+ } else if (is_admin () && $ _GET ['comment_status ' ] == "approved " ) {
187+ $ getCommentArr ["status " ] = "approve " ;
188+ $ get__comments = get_comments ($ getCommentArr );
168189 } else {
169190 $ get__comments = get_comments ();
170191 }
171192
193+
172194 $ get__parent__id__arr = array ();
173195 foreach ($ get__comments as $ get__comment ) {
174196 array_push ($ get__parent__id__arr , $ get__comment ->comment_parent );
175197 }
176198 $ get__parent__id__arr__cln = $ get__parent__id__arr ;
177199
200+
178201 $ indx__getting__comments = 0 ;
179202 foreach ($ get__comments as $ get__comment ) {
180203
@@ -184,29 +207,42 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
184207 $ get__comment__parent_id = get_comment ($ comment__id )->comment_parent ;
185208 $ pos__for__arr = array_search ($ get__comment__parent_id , $ comments__id__array );
186209
187- if ($ get__comment__parent_id < 1 || (!is_single () && !is_page () && !is_singular ())) {
188210
189- array_push ($ comments__id__array , $ comment__id );
190- array_push ($ comments__author__id__array , $ comment__author__id );
191- } else {
211+ if ((($ get__comment__parent_id < 1 && $ get__comment ->comment_approved == "1 " ) || (!is_single () && !is_page () && !is_singular ()))) {
212+
213+
214+ if (get_option ("comment_order " ) === "asc " ) :
215+ array_push ($ comments__id__array , $ comment__id );
216+ array_push ($ comments__author__id__array , $ comment__author__id );
217+ elseif (get_option ("comment_order " ) === "desc " ) :
218+ array_unshift ($ comments__id__array , $ comment__id );
219+ array_unshift ($ comments__author__id__array , $ comment__author__id );
220+ endif ;
221+ } else if (get_comment ($ get__comment__parent_id )->comment_approved == "1 " && $ get__comment ->comment_approved == "1 " ) {
222+
192223
193224 if (is_single () || is_page () || is_singular ()) {
194225
195226 $ get__parent__id__arr__del = array_search ($ get__comment__parent_id , $ get__parent__id__arr );
196227 $ get__parent__id__arr__cnt = array_count_values ($ get__parent__id__arr )[$ get__comment__parent_id ];
197228 $ get__parent__id__arr__cln__cnt = array_count_values ($ get__parent__id__arr__cln )[$ get__comment__parent_id ];
198229
230+
231+
199232 if ($ get__parent__id__arr__cln__cnt > 1 ) {
200233
234+
201235 $ gttng__pos = $ get__parent__id__arr__cln__cnt - $ get__parent__id__arr__cnt + 1 ;
202236
237+
203238 $ comments__author__id__array = array_merge (array_slice ($ comments__author__id__array , 0 , $ pos__for__arr + $ gttng__pos ), array ($ comment__author__id ), array_slice ($ comments__author__id__array , $ pos__for__arr + $ gttng__pos ));
204239
205240 $ comments__id__array = array_merge (array_slice ($ comments__id__array , 0 , $ pos__for__arr + $ gttng__pos ), array ($ comment__id ), array_slice ($ comments__id__array , $ pos__for__arr + $ gttng__pos ));
206241
207242 unset($ get__parent__id__arr [$ get__parent__id__arr__del ]);
208243 } else {
209244
245+
210246 $ comments__author__id__array = array_merge (array_slice ($ comments__author__id__array , 0 , $ pos__for__arr + 1 ), array ($ comment__author__id ), array_slice ($ comments__author__id__array , $ pos__for__arr + 1 ));
211247
212248 $ comments__id__array = array_merge (array_slice ($ comments__id__array , 0 , $ pos__for__arr + 1 ), array ($ comment__id ), array_slice ($ comments__id__array , $ pos__for__arr + 1 ));
@@ -218,9 +254,18 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
218254 }
219255 }
220256
257+
221258 $ indx__getting__comments ++;
222259 }
223260
261+ if (preg_match ("/(comment-page-)([0-9])/i " , $ _SERVER ["REQUEST_URI " ], $ getUrlEl ) && get_option ('page_comments ' ) == 1 && $ get__commenter__indx == 0 && get_option ('default_comments_page ' ) === "oldest " ) {
262+ $ get__commenter__indx += (array_search (get_comment_ID (), $ comments__id__array ));
263+ } else if (get_option ('default_comments_page ' ) === "newest " ) {
264+ $ get__commenter__indx = 0 ;
265+ $ get__commenter__indx += (array_search (get_comment_ID (), $ comments__id__array ));
266+ }
267+
268+
224269 $ commenter__user = get_userdata ($ comments__author__id__array [$ get__commenter__indx ]);
225270 $ commenter__role = $ commenter__user ->roles ;
226271
@@ -230,26 +275,56 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
230275 $ spcfc__admn__pg = 1 ;
231276 }
232277
233- if (is_admin () && $ _GET ["paged " ] > 1 && get_current_screen ()->id === "edit-comments " && ($ _GET ["paged " ] - 1 ) * 20 > $ get__commenter__indx ) {
278+
279+ $ cpa__WPScreen = WP_Screen::get ();
280+
281+ $ option = $ cpa__WPScreen ->get_option ('per_page ' , 'option ' );
282+ if (!$ option ) {
283+ $ option = str_replace ('- ' , '_ ' , "{$ cpa__WPScreen ->id }_per_page " );
284+ }
285+ $ per_page = (int ) get_user_option ($ option );
286+ if (empty ($ per_page ) || $ per_page < 1 ) {
287+ $ per_page = $ cpa__WPScreen ->get_option ('per_page ' , 'default ' );
288+ if (!$ per_page ) {
289+ $ per_page = 20 ;
290+ }
291+ }
292+ $ comment_status = isset ($ _REQUEST ['comment_status ' ]) ? $ _REQUEST ['comment_status ' ] : 'all ' ;
293+ $ per_page = apply_filters ('comments_per_page ' , $ per_page , $ comment_status );
294+
295+
296+ if (is_admin () && $ _GET ["paged " ] > 1 && get_current_screen ()->id === "edit-comments " && ($ _GET ["paged " ] - 1 ) * $ per_page > $ get__commenter__indx ) {
234297 $ chng__pos = $ _GET ["paged " ];
235298 $ get__commenter__indx = 0 ;
236299 while ($ chng__pos > 1 ) {
237- $ get__commenter__indx += (! is_admin ()) ? 20 : 19 ;
300+ $ get__commenter__indx += (get_user_meta ( get_current_user_id (), ' custom_profile_avatar ' )[ 0 ]) ? $ per_page : ( $ per_page ) ;
238301 $ chng__pos --;
239302 }
240303 }
241304
305+
242306 if (get_user_meta ($ usr__id , 'custom_profile_avatar ' )[0 ] && (get_option ("custom_profile_avatar__options__permissions " )[$ roles [0 ]] == "on " || $ roles [0 ] == "administrator " )) {
243307 $ custom__avatar = get_user_meta ($ usr__id , 'custom_profile_avatar ' )[0 ];
244308 } else if (get_user_meta ($ id_or_email , 'custom_profile_avatar ' )[0 ] && (get_option ("custom_profile_avatar__options__permissions " )[$ roles [0 ]] == "on " || $ roles [0 ] == "administrator " )) {
245309 $ custom__avatar = get_user_meta ($ id_or_email , 'custom_profile_avatar ' )[0 ];
310+ } else if (!get_comment_ID ()) {
311+ $ url = $ args ['url ' ];
312+ if (!$ url || is_wp_error ($ url )) {
313+ return false ;
314+ }
315+ $ custom__avatar = $ url ;
246316 } else if (get_user_meta ($ comments__author__id__array [$ get__commenter__indx ], 'custom_profile_avatar ' )[0 ] && (get_option ("custom_profile_avatar__options__permissions " )[$ commenter__role [0 ]] == "on " || $ commenter__role [0 ] == "administrator " ) && (is_single () || is_page () || is_singular () || $ spcfc__admn__pg == 1 )) {
247317
318+ if (get_comment_ID () > 0 && $ get__commenter__indx < 0 ) {
319+ $ get__commenter__indx ++;
320+ }
321+
248322 $ custom__avatar = get_user_meta ($ comments__author__id__array [$ get__commenter__indx ], 'custom_profile_avatar ' )[0 ];
249323
250324 if (is_single () || is_page () || is_singular () || get_current_screen ()->id === "dashboard " ) {
251-
252- $ get__commenter__indx ++;
325+ if (get_comment_ID () > 0 ) {
326+ $ get__commenter__indx ++;
327+ }
253328 } else {
254329 $ get__commenter__indx__bfr = $ get__commenter__indx ;
255330
@@ -275,9 +350,14 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
275350 }
276351 $ custom__avatar = $ url ;
277352
278- if (is_single () || is_page () || is_singular () || get_current_screen ()->id === "dashboard " ) {
279-
353+ if (get_comment_ID () > 0 && $ get__commenter__indx < 0 ) {
280354 $ get__commenter__indx ++;
355+ }
356+
357+ if (is_single () || is_page () || is_singular () || get_current_screen ()->id === "dashboard " ) {
358+ if (get_comment_ID () > 0 ) {
359+ $ get__commenter__indx ++;
360+ }
281361 } else {
282362 $ get__commenter__indx__bfr = $ get__commenter__indx ;
283363
0 commit comments