Skip to content

Commit 69e093e

Browse files
committed
Bugs fixed.
1 parent ea9354e commit 69e093e

16 files changed

+114
-31
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.2
5+
** @version 1.2.1
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.2</p>";
28+
$template .= "<p>" . esc_html__('Version', 'custom-profile-avatar') . ": 1.2.1</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.2
3+
** Version: 1.2.1
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.2
3+
** Version: 1.2.1
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.2
7+
Version: 1.2.1
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.2
5+
** @version 1.2.1
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.2
5+
** @version 1.2.1
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.2
5+
** @version 1.2.1
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.2
5+
** @version 1.2.1
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.2
5+
** @version 1.2.1
66
** @since 1.1
77
** @author en0ndev
88
*/

modules/get_avatar.php

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

33
/**
44
** get_avatar.php
5-
** @version 1.2
5+
** @version 1.2.1
66
** @since 1.0
77
** @author en0ndev
88
*/
@@ -29,12 +29,12 @@
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

3434
function 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
}
3939
add_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+
9296
if (!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

Comments
 (0)