سلام و ارادت
دوستان من چندروز دنبال روشی برای ایجاد آواتار رندوم برای کاربران هستم. بدینصورت که من ۳۰ آواتار با سایز یکسان و فرمت یکسان روی سایت آپلود میکنم و برای کاربرانی که از Gravatar استفاده نمیکنند یکی از این ۳۰ آواتار رو بهصورت رندوم قرار بده.
من ابتدا روشی که توی این سایت گفته شده رو دنبال کردم اما متاسفانه پاسخ نداد، هم میخاد از گریواتار، آواتار رو لود کنه هم از دایرکتوری که من بهش میدم:
شما این روش رو تست کردید و درست بوده براتون؟ من تابع get_avatar() رو هم پیدا کردم اما نمیدونم چطور باید در قسمتی که میخاد عکس رو فراخوانی کنه یک تابع بهصورت رندوم براش معرفی کنم که از یک دایرکتوری مشخص عکسها رو برداره و به هر کاربر نسبت بده.
بسیار متشکرم از شما
دوستان من چندروز دنبال روشی برای ایجاد آواتار رندوم برای کاربران هستم. بدینصورت که من ۳۰ آواتار با سایز یکسان و فرمت یکسان روی سایت آپلود میکنم و برای کاربرانی که از Gravatar استفاده نمیکنند یکی از این ۳۰ آواتار رو بهصورت رندوم قرار بده.
من ابتدا روشی که توی این سایت گفته شده رو دنبال کردم اما متاسفانه پاسخ نداد، هم میخاد از گریواتار، آواتار رو لود کنه هم از دایرکتوری که من بهش میدم:
کد:
In order to achieve this, one can modify the behaviour of the function get_avatar(). There is two main ways:
You can add a filter to the avatar_defaults option, and modify the “avatars array” in order to get a new “Static” default avatar option in Discussion Settings. You can see an example here.
You can add the filter to pre_option_avatar_default , and return any URL you want.
I will use the second option, so the URL returned will be picked up randomly from a set.
// Random Chameleon Avatar
add_filter( 'pre_option_avatar_default', 'chameleon_default_avatar' );
function chameleon_default_avatar ( $value )
{
return admin_url( 'images' ) . '/cham_avatars/cham_avatar'.rand( 0 , 13 ).'.jpg';
}
// Random Chameleon Avatar
add_filter( 'pre_option_avatar_default', 'chameleon_default_avatar' );
function chameleon_default_avatar ( $value )
{
return admin_url( 'images' ) . '/cham_avatars/cham_avatar'.rand( 0 , 13 ).'.jpg';
}
This will modify the regular flow WordPress uses, and return a custom random avatar. I created 14 avatars, named them cham_avatar0.jpg to cham_avatar13.jpg , and copied them into my wp_admin/images/cham_avatars folder .
The problem is that modifying the source code of WordPress directly is not ideal, because will be messed up in WP updates.
بسیار متشکرم از شما