Skip to content

Commit 532e52b

Browse files
committed
Fixed some bugs
Fixed bugs when the plugin was activated.
1 parent 36757e7 commit 532e52b

15 files changed

+50
-43
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.3
5+
** @version 1.3.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.3</p>";
28+
$template .= "<p>" . esc_html__('Version', 'custom-profile-avatar') . ": 1.3.1</p>";
2929
$template .= "<p>" . esc_html__('Developer', 'custom-profile-avatar') . ": <a class='about__author link' href='https://github.com/en0ndev' target='_blank'>en0ndev</a></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.3
3+
** Version: 1.3.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.3
3+
** Version: 1.3.1
44
** Since: 1.0
55
** Author: en0ndev
66
This file is part of Custom Profile Avatar.

assets/js/save_settings.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
** File: save_settings.js
3-
** Version: 1.3
3+
** Version: 1.3.1
44
** Since: 1.3
55
** Author: en0ndev
66
This file is part of Custom Profile Avatar.
@@ -26,26 +26,18 @@ jQuery(document).ready(function ($) {
2626
function getImgAfterUpdate(cpa__get__newavatar, avatar__disabled) {
2727
for (let getInd = 0; getInd < $("img").length; getInd++) {
2828
if (avatar__disabled == "" && $("img:eq("+getInd+")[class*=avatar][class*=photo]").length > 0 && cpa__get__oldavatar != cpa__get__newavatar && $("img")[getInd]["id"] != "old__avatar") {
29-
//console.log("1-1: "+$("img")[getInd]["currentSrc"]);
3029
$("img:eq("+getInd+")").attr("src", cpa__get__newavatar);
31-
//console.log("1-2: "+$("img")[getInd]["currentSrc"]);
3230
}
3331
else if (avatar__disabled != "" && ($("img")[getInd]["currentSrc"] == cpa__get__oldavatar || $("img")[getInd]["currentSrc"] == $("#old__avatar").attr("src") || $("img:eq("+getInd+")[src*='gravatar.com']").length > 0) && $("img")[getInd]["id"] != "old__avatar" && $("img:eq("+getInd+")").parent().attr("id") != "user__avatar") {
34-
//console.log("2-1: "+$("img")[getInd]["currentSrc"]);
3532
avatar__disabled == "1" ? $("img:eq("+getInd+")").attr("src", $("#user__avatar > img").attr("src")) : $("img:eq("+getInd+")").attr("src", $("#old__avatar").attr("src"));
36-
//console.log("2-2: "+$("img")[getInd]["currentSrc"]);
3733
}
3834
}
39-
//console.log("Old Avatar: "+cpa__get__oldavatar);
40-
//console.log("New Avatar: "+cpa__get__newavatar);
4135
cpa__get__oldavatar = $("#user__avatar > img").attr("src");
4236
}
4337

4438
$(document).submit("[name='cpa__save__avatar']", function (e) {
4539
e.preventDefault();
4640

47-
//var cpa__get__newavatar = $("#user__avatar > img").attr("src");
48-
4941
if ($("#cpa__change__avatar").length > 0) {
5042
var avatar__val = $("[name='avatar__val']").val();
5143
$.ajax({
@@ -56,7 +48,6 @@ jQuery(document).ready(function ($) {
5648
avatar__val: avatar__val,
5749
},
5850
success: function () {
59-
//alert("Success");
6051
var cpa__get__newavatar = $("#user__avatar > img").attr("src");
6152
getImgAfterUpdate(cpa__get__newavatar, avatar__disabled);
6253
if ($("#notf").length < 1) {
@@ -68,7 +59,6 @@ jQuery(document).ready(function ($) {
6859
}
6960
},
7061
error: function () {
71-
//alert("Error");
7262
if ($("#notf").length < 1) {
7363
$(".main__area").after("<div id='notf' class='err'>Avatar not updated!</div>");
7464
$("#notf").fadeIn(300).css("transform","translateY(12.5px)").delay(800).fadeOut(600);
@@ -103,7 +93,6 @@ jQuery(document).ready(function ($) {
10393
shopm__permission: shopm__permission,
10494
},
10595
success: function (response) {
106-
//alert("Success");
10796
disable__gravatar == "off" ? avatar__disabled = "0" : avatar__disabled = "1";
10897
var cpa__get__newavatar = avatar__disabled == "1" ? $("#user__avatar > img").attr("src") : $("#old__avatar").attr("src");
10998
getImgAfterUpdate(cpa__get__newavatar, avatar__disabled);
@@ -114,10 +103,8 @@ jQuery(document).ready(function ($) {
114103
$("#notf").remove();
115104
},1800);
116105
}
117-
//console.log(response);
118106
},
119107
error: function () {
120-
//alert("Error");
121108
if ($("#notf").length < 1) {
122109
$(".main__area").after("<div id='notf' class='err'>Permissions not updated!</div>");
123110
$("#notf").fadeIn(300).css("transform","translateY(12.5px)").delay(800).fadeOut(600);

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. Also you can disable Gravatar.
7-
Version: 1.3
7+
Version: 1.3.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.3
5+
** @version 1.3.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.3
5+
** @version 1.3.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.3
5+
** @version 1.3.1
66
** @since 1.0
77
** @author en0ndev
88
*/

modules/get_avatar.php

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

33
/**
44
** get_avatar.php
5-
** @version 1.3
5+
** @version 1.3.1
66
** @since 1.0
77
** @author en0ndev
88
*/
@@ -82,13 +82,13 @@ function cpa__get__avatar__new($getType)
8282
function cpa__get__value($getType)
8383
{
8484
global $current_user;
85-
if (get_user_meta($current_user->id, 'custom_profile_avatar')[0] && $getType == "custom__avatar")
85+
if (isset(get_user_meta($current_user->id, 'custom_profile_avatar')[0]) && get_user_meta($current_user->id, 'custom_profile_avatar')[0] && $getType == "custom__avatar")
8686
return get_user_meta($current_user->id, 'custom_profile_avatar')[0];
87-
elseif ($getType == "default__avatar") {
88-
$get__default__avatar = get_option('custom_profile_avatar__options__default__avatar') !== false ? get_option('custom_profile_avatar__options__default__avatar') : plugins_url() . "/custom-profile-avatar/assets/img/default-non-user-avatar.jpg";
87+
elseif (!empty(get_option('custom_profile_avatar__options__default__avatar')) && $getType == "default__avatar") {
88+
$get__default__avatar = get_option('custom_profile_avatar__options__default__avatar');
8989
return $get__default__avatar;
9090
} else
91-
return 0;
91+
return "";
9292
}
9393

9494
function compare__comment__id($a, $b)
@@ -204,12 +204,14 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
204204
$get__comments = get_comments();
205205
}
206206

207+
207208
$get__parent__id__arr = array();
208209
foreach ($get__comments as $get__comment) {
209210
array_push($get__parent__id__arr, $get__comment->comment_parent);
210211
}
211212
$get__parent__id__arr__cln = $get__parent__id__arr;
212213

214+
213215
$indx__getting__comments = 0;
214216
foreach ($get__comments as $get__comment) {
215217

@@ -242,8 +244,10 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
242244

243245
if ($get__parent__id__arr__cln__cnt > 1) {
244246

247+
245248
$gttng__pos = $get__parent__id__arr__cln__cnt - $get__parent__id__arr__cnt + 1;
246249

250+
247251
$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));
248252

249253
$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));
@@ -262,6 +266,7 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
262266
}
263267
}
264268

269+
265270
$indx__getting__comments++;
266271
}
267272

@@ -282,6 +287,7 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
282287
$spcfc__admn__pg = 1;
283288
}
284289

290+
285291
$cpa__WPScreen = WP_Screen::get();
286292

287293
$option = $cpa__WPScreen->get_option('per_page', 'option');
@@ -298,6 +304,7 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
298304
$comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
299305
$per_page = apply_filters('comments_per_page', $per_page, $comment_status);
300306

307+
301308
if (is_admin() && isset($_GET["paged"]) && ($_GET["paged"] > 1) && get_current_screen()->id === "edit-comments" && ($_GET["paged"] - 1) * $per_page > $get__commenter__indx) {
302309
$chng__pos = $_GET["paged"];
303310
$get__commenter__indx = 0;
@@ -307,10 +314,13 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
307314
}
308315
}
309316

317+
310318
if (isset(get_user_meta($usr__id, 'custom_profile_avatar')[0]) && (get_user_meta($usr__id, 'custom_profile_avatar')[0]) && (isset($roles[0]) && ((get_option("custom_profile_avatar__options__permissions")[$roles[0]] ?? 0) == "on" || $roles[0] == "administrator"))) {
311319
$custom__avatar = get_user_meta($usr__id, 'custom_profile_avatar')[0];
320+
//echo 1 . " " . $get__commenter__indx;
312321
} else if (isset(get_user_meta($id_or_email, 'custom_profile_avatar')[0]) && (get_user_meta($id_or_email, 'custom_profile_avatar')[0]) && (isset($roles[0]) && ((get_option("custom_profile_avatar__options__permissions")[$roles[0]] ?? 0) == "on" || $roles[0] == "administrator"))) {
313322
$custom__avatar = get_user_meta($id_or_email, 'custom_profile_avatar')[0];
323+
//echo 2 . " " . $get__commenter__indx;
314324
} else if (!get_comment_ID()) {
315325
if (get_option("custom_profile_avatar__options__disable__gravatar") == "on") {
316326
if (strlen(get_option("custom_profile_avatar__options__default__avatar")) > 0) {
@@ -327,12 +337,15 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args =
327337
}
328338
} else if (isset(get_user_meta($comments__author__id__array[$get__commenter__indx], 'custom_profile_avatar')[0]) && (get_user_meta($comments__author__id__array[$get__commenter__indx], 'custom_profile_avatar')[0]) && (isset($commenter__role[0]) && ((get_option("custom_profile_avatar__options__permissions")[$commenter__role[0]] ?? 0) == "on" || $commenter__role[0] == "administrator")) && (is_single() || is_page() || is_singular() || $spcfc__admn__pg == 1)) {
329339

340+
330341
if (get_comment_ID() > 0 && $get__commenter__indx < 0) {
331342
$get__commenter__indx++;
332343
}
333344

345+
334346
$custom__avatar = get_user_meta($comments__author__id__array[$get__commenter__indx], 'custom_profile_avatar')[0];
335347

348+
336349
if (is_single() || is_page() || is_singular() || get_current_screen()->id === "dashboard") {
337350
if (get_comment_ID() > 0) {
338351
$get__commenter__indx++;

modules/get_permissions.php

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

33
/**
44
** get_permissions.php
5-
** @version 1.3
5+
** @version 1.3.1
66
** @since 1.1
77
** @author en0ndev
88
*/
@@ -68,16 +68,18 @@ function cpa__set__permission()
6868
function cpa__allow__contributor__uploads()
6969
{
7070
$contributor = get_role('contributor');
71-
if (get_option("custom_profile_avatar__options__permissions")["contributor"] == "on" && !$contributor->has_cap("upload_files")) {
72-
$contributor->add_cap('upload_files');
73-
} else if (get_option("custom_profile_avatar__options__permissions")["contributor"] == "off" && $contributor->has_cap("upload_files")) {
74-
$contributor->remove_cap('upload_files');
75-
}
71+
if (isset(get_option("custom_profile_avatar__options__permissions")["contributor"])) :
72+
if (get_option("custom_profile_avatar__options__permissions")["contributor"] == "on" && !$contributor->has_cap("upload_files")) {
73+
$contributor->add_cap('upload_files');
74+
} else if (get_option("custom_profile_avatar__options__permissions")["contributor"] == "off" && $contributor->has_cap("upload_files")) {
75+
$contributor->remove_cap('upload_files');
76+
}
77+
endif;
7678
}
7779

7880
function cpa__get__check__box__permission($getDataNameForBox)
7981
{
80-
$getDataArrOption = get_option("custom_profile_avatar__options__permissions")[$getDataNameForBox];
82+
$getDataArrOption = get_option("custom_profile_avatar__options__permissions")[$getDataNameForBox] ?? 0;
8183
if ($getDataArrOption == "on") {
8284
return "checked='checked'";
8385
}
@@ -87,7 +89,7 @@ function cpa__get__check__box__permission($getDataNameForBox)
8789

8890
function cpa__get__check__box__disable__gravatar()
8991
{
90-
$getDataArrOption = get_option("custom_profile_avatar__options__disable__gravatar");
92+
$getDataArrOption = get_option("custom_profile_avatar__options__disable__gravatar") ?? 0;
9193
if ($getDataArrOption == "on") {
9294
return "checked='checked'";
9395
}

0 commit comments

Comments
 (0)