Skip to content

Commit ea9354e

Browse files
committed
Some bugs fixed.
1 parent 4977b55 commit ea9354e

16 files changed

+176
-19
lines changed

about.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
** about.php
5-
** @version 1.1
5+
** @version 1.2
66
** @since 1.0
77
** @author en0ndev
88
*/
@@ -25,7 +25,7 @@
2525
defined('ABSPATH') || exit; // Exit if accessed directly
2626

2727
$template = "<div class='about'><img src='" . plugin_dir_url(__FILE__) . "/assets/img/icon-128x128.png' alt='Custom Profile Avatar' /><p class='big'>Custom Profile Avatar</p>";
28-
$template .= "<p>" . esc_html__('Version', 'custom-profile-avatar') . ": 1.1</p>";
28+
$template .= "<p>" . esc_html__('Version', 'custom-profile-avatar') . ": 1.2</p>";
2929
$template .= "<p>" . esc_html__('Developer', 'custom-profile-avatar') . ": en0ndev</p>";
3030
$template .= "<a class='link' target='_blank' href='https://www.youtube.com/channel/UC3CSOAThanO-LvYKFwJ24RQ'>" . esc_html__('My YouTube Channel', 'custom-profile-avatar') . "</a></div>";
3131

assets/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
** File: style.css
3-
** Version: 1.1
3+
** Version: 1.2
44
** Since: 1.0
55
** Author: en0ndev
66

assets/js/modules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
** File: modules.js
3-
** Version: 1.1
3+
** Version: 1.2
44
** Since: 1.0
55
** Author: en0ndev
66
This file is part of Custom Profile Avatar.

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: Custom Profile Avatar
55
Plugin URI: https://wordpress.org/plugins/custom-profile-avatar
66
Description: Change profile avatar to your custom avatar.
7-
Version: 1.1
7+
Version: 1.2
88
Author: en0ndev
99
Author URI: https://github.com/en0ndev
1010
Text Domain: custom-profile-avatar

main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
** main.php
5-
** @version 1.1
5+
** @version 1.2
66
** @since 1.0
77
** @author en0ndev
88
*/

modules/admin_footer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
** admin_footer.php
5-
** @version 1.1
5+
** @version 1.2
66
** @since 1.0
77
** @author en0ndev
88
*/

modules/admin_menu_join.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
** admin_menu_join.php
5-
** @version 1.1
5+
** @version 1.2
66
** @since 1.0
77
** @author en0ndev
88
*/

modules/change_avatar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
** change_avatar.php
5-
** @version 1.1
5+
** @version 1.2
66
** @since 1.0
77
** @author en0ndev
88
*/

modules/change_permissions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
** change_permissions.php
5-
** @version 1.1
5+
** @version 1.2
66
** @since 1.1
77
** @author en0ndev
88
*/

modules/get_avatar.php

Lines changed: 156 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
** get_avatar.php
5-
** @version 1.1
5+
** @version 1.2
66
** @since 1.0
77
** @author en0ndev
88
*/
@@ -26,6 +26,17 @@
2626

2727
$usr = new WP_User;
2828
$current_user = $usr->wp_get_current_user();
29+
$get__commenter__indx__bfr = null;
30+
$get__commenter__indx__aft = null;
31+
$get__commenter__indx__vrf = 0;
32+
$get__commenter__indx = 0;
33+
34+
function cpa__start__values()
35+
{
36+
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;
38+
}
39+
add_action("init", "cpa__start__values");
2940

3041
function cpa__get__old($id)
3142
{
@@ -65,6 +76,19 @@ function cpa__get__value()
6576
return 0;
6677
}
6778

79+
function compare__comment__id($a, $b)
80+
{
81+
//echo $a->comment_ID . " " . $b->comment_ID;
82+
if ($a->comment_ID == $b->comment_ID) {
83+
return 0;
84+
}
85+
return ($a->comment_ID < $b->comment_ID) ? -1 : 1;
86+
}
87+
88+
if (!function_exists('get_current_screen')) {
89+
require_once ABSPATH . '/wp-admin/includes/screen.php';
90+
}
91+
6892
if (!function_exists('get_avatar')) {
6993
function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args = null)
7094
{
@@ -130,18 +154,148 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
130154
$usr = get_userdata($user);
131155
$roles = $usr->roles;
132156

133-
//echo $roles[0];
157+
global $post;
158+
global $get__commenter__indx, $get__commenter__indx__bfr, $get__commenter__indx__aft, $get__commenter__indx__vrf;
159+
160+
$comments__author__id__array = array();
161+
$comments__id__array = array();
162+
163+
if (is_single() || is_page() || is_singular()) {
164+
$get__comments = get_comments(array('post_id' => $post->ID));
165+
usort($get__comments, 'compare__comment__id');
166+
} else if (is_admin() && isset($_GET['user_id'])) {
167+
$get__comments = get_comments(array('user_id' => $_GET['user_id']));
168+
} else {
169+
$get__comments = get_comments();
170+
}
171+
172+
$get__parent__id__arr = array();
173+
foreach ($get__comments as $get__comment) {
174+
array_push($get__parent__id__arr, $get__comment->comment_parent);
175+
}
176+
$get__parent__id__arr__cln = $get__parent__id__arr;
177+
178+
$indx__getting__comments = 0;
179+
foreach ($get__comments as $get__comment) {
180+
181+
$comment__id = $get__comment->comment_ID;
182+
$comment__author__id = get_comment($comment__id)->user_id;
183+
184+
$get__comment__parent_id = get_comment($comment__id)->comment_parent;
185+
$pos__for__arr = array_search($get__comment__parent_id, $comments__id__array);
186+
187+
if ($get__comment__parent_id < 1 || (!is_single() && !is_page() && !is_singular())) {
188+
189+
array_push($comments__id__array, $comment__id);
190+
array_push($comments__author__id__array, $comment__author__id);
191+
} else {
192+
193+
if (is_single() || is_page() || is_singular()) {
194+
195+
$get__parent__id__arr__del = array_search($get__comment__parent_id, $get__parent__id__arr);
196+
$get__parent__id__arr__cnt = array_count_values($get__parent__id__arr)[$get__comment__parent_id];
197+
$get__parent__id__arr__cln__cnt = array_count_values($get__parent__id__arr__cln)[$get__comment__parent_id];
198+
199+
if ($get__parent__id__arr__cln__cnt > 1) {
200+
201+
$gttng__pos = $get__parent__id__arr__cln__cnt - $get__parent__id__arr__cnt + 1;
202+
203+
$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));
204+
205+
$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));
206+
207+
unset($get__parent__id__arr[$get__parent__id__arr__del]);
208+
} else {
209+
210+
$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));
211+
212+
$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));
213+
}
214+
} else {
215+
$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));
216+
217+
$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+
}
219+
}
220+
221+
$indx__getting__comments++;
222+
}
223+
224+
$commenter__user = get_userdata($comments__author__id__array[$get__commenter__indx]);
225+
$commenter__role = $commenter__user->roles;
226+
227+
228+
$spcfc__admn__pg = 0;
229+
if (is_admin() && (get_current_screen()->id === "edit-comments" || get_current_screen()->id === "dashboard")) {
230+
$spcfc__admn__pg = 1;
231+
}
232+
233+
if (is_admin() && $_GET["paged"] > 1 && get_current_screen()->id === "edit-comments" && ($_GET["paged"] - 1) * 20 > $get__commenter__indx) {
234+
$chng__pos = $_GET["paged"];
235+
$get__commenter__indx = 0;
236+
while ($chng__pos > 1) {
237+
$get__commenter__indx += (!is_admin()) ? 20 : 19;
238+
$chng__pos--;
239+
}
240+
}
134241

135242
if (get_user_meta($usr__id, 'custom_profile_avatar')[0] && (get_option("custom_profile_avatar__options__permissions")[$roles[0]] == "on" || $roles[0] == "administrator")) {
136243
$custom__avatar = get_user_meta($usr__id, 'custom_profile_avatar')[0];
137244
} 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")) {
138245
$custom__avatar = get_user_meta($id_or_email, 'custom_profile_avatar')[0];
246+
} 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)) {
247+
248+
$custom__avatar = get_user_meta($comments__author__id__array[$get__commenter__indx], 'custom_profile_avatar')[0];
249+
250+
if (is_single() || is_page() || is_singular() || get_current_screen()->id === "dashboard") {
251+
252+
$get__commenter__indx++;
253+
} else {
254+
$get__commenter__indx__bfr = $get__commenter__indx;
255+
256+
if ($get__commenter__indx > 0) {
257+
258+
if (($get__commenter__indx__bfr % 2 != 0 && $get__commenter__indx__aft % 2 == 0) || $get__commenter__indx__vrf == 0) {
259+
$get__commenter__indx__vrf = 1;
260+
} else {
261+
$get__commenter__indx__vrf = 0;
262+
}
263+
}
264+
265+
if ($get__commenter__indx__vrf != 1) {
266+
$get__commenter__indx++;
267+
}
268+
269+
$get__commenter__indx__aft = $get__commenter__indx;
270+
}
139271
} else {
140272
$url = $args['url'];
141273
if (!$url || is_wp_error($url)) {
142274
return false;
143275
}
144276
$custom__avatar = $url;
277+
278+
if (is_single() || is_page() || is_singular() || get_current_screen()->id === "dashboard") {
279+
280+
$get__commenter__indx++;
281+
} else {
282+
$get__commenter__indx__bfr = $get__commenter__indx;
283+
284+
if ($get__commenter__indx > 0) {
285+
286+
if (($get__commenter__indx__bfr % 2 != 0 && $get__commenter__indx__aft % 2 == 0) || $get__commenter__indx__vrf == 0) {
287+
$get__commenter__indx__vrf = 1;
288+
} else {
289+
$get__commenter__indx__vrf = 0;
290+
}
291+
}
292+
293+
if ($get__commenter__indx__vrf != 1) {
294+
$get__commenter__indx++;
295+
}
296+
297+
$get__commenter__indx__aft = $get__commenter__indx;
298+
}
145299
}
146300

147301
$class = array('avatar', 'avatar-' . (int) $args['size'], 'photo');

0 commit comments

Comments
 (0)